#ifndef OverbyteIcsHttpPost1H
#define OverbyteIcsHttpPost1H

#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.Buttons.hpp>
#include <Vcl.Dialogs.hpp>

#include "OverbyteIcsWndControl.hpp"
#include "OverbyteIcsHttpProt.hpp"
#include "OverbyteIcsMimeUtils.hpp"
#include "OverbyteIcsTypes.hpp"

#include <memory>

class THttpPostForm : public TForm
{
__published:
    TPanel *ToolsPanel;
    TMemo *DisplayMemo;
    TLabel *Label1;
    TLabel *Label2;
    TEdit *FirstNameEdit;
    TEdit *LastNameEdit;
    TLabel *Label3;
    TEdit *ActionURLEdit;
    TButton *PostButton;
    TLabel *Label4;
    THttpCli *HttpCli1;
    TLabel *Label5;
    TEdit *FileNameEdit;
    TButton *UploadButton;
    TShape *Shape1;
    TLabel *Label6;
    TEdit *UploadURLEdit;
    TLabel *Label10;
    TEdit *BandwidthLimitEdit;
    TRadioGroup *UploadMethod;
    TOpenDialog *OpenDialog;
    TBitBtn *SelectFile;
    TLabel *Label7;
    TEdit *FileDescr;
    TMimeTypesList *MimeTypesList1;
    void __fastcall FormShow(TObject *Sender);
    void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
    void __fastcall FormCreate(TObject *Sender);
    void __fastcall PostButtonClick(TObject *Sender);
    void __fastcall HttpCli1RequestDone(TObject *Sender, THttpRequest RqType, System::Word ErrCode);
    void __fastcall UploadButtonClick(TObject *Sender);
    void __fastcall SelectFileClick(TObject *Sender);

private:
    String FIniFileName;
    bool FInitialized;
    DWORD FStartTime;
    bool FBusy = false;
    std::unique_ptr<TStream> FSendStream;
    std::unique_ptr<TStream> FRcvdStream;

    void StartRequest(std::unique_ptr<TStream> Send, bool Put);
    void DetachStreams();

public:
    __fastcall THttpPostForm(TComponent *Owner);
    __fastcall ~THttpPostForm();
    void Display(const String &Msg);
};

extern PACKAGE THttpPostForm *HttpPostForm;

#endif
