unit AddCustomer;

interface

uses
  System.SysUtils, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls,
  WEBLib.Forms, WEBLib.Dialogs, Vcl.Controls, Vcl.StdCtrls, WEBLib.StdCtrls,
  WEBLib.DBCtrls, WEBLib.ExtCtrls;

type
  TFViewAddCustomer = class(TWebForm)
    dtpStartDate: TWebDateTimePicker;
    dtpEndDate: TWebDateTimePicker;
    edtShortName: TWebDBEdit;
    edtName: TWebDBEdit;
    edtBillAddress: TWebDBEdit;
    edtBillCity: TWebDBEdit;
    edtBillState: TWebDBEdit;
    edtBillZip: TWebDBEdit;
    edtBillContact: TWebDBEdit;
    edtPhone: TWebDBEdit;
    edtFax: TWebDBEdit;
    edtRep: TWebDBEdit;
    btnSave: TWebButton;
    btnCancel: TWebButton;
    btnDelete: TWebButton;
    btnClose: TWebButton;
    btnEdit: TWebButton;
    pnlMessage: TWebPanel;
    lblMessage: TWebLabel;
    btnCloseNotification: TWebButton;
    procedure WebFormShow(Sender: TObject);
  private
    { Private declarations }

    procedure HideNotification();
    procedure ShowNotification(Notification: string);
  var
    customerID: string;
    notification: string;
  public
    { Public declarations }
     class function CreateForm(AElementID, customerInfo, info: string): TWebForm;
  end;

var
  FViewAddCustomer: TFViewAddCustomer;

implementation

{$R *.dfm}

uses View.Main;

class function TFViewAddCustomer.CreateForm(AElementID: string; customerInfo: string; info: string): TWebForm;
begin
  Application.CreateForm(TFViewAddCustomer, AElementID, Result,
    procedure(AForm: TObject)
    begin
      with TFViewAddCustomer(AForm) do
      begin
        TFViewAddCustomer(AForm).customerID := customerInfo;
        TFViewAddCustomer(AForm).notification := info;
      end;
    end
  );

end;

procedure TFViewAddCustomer.WebFormShow(Sender: TObject);
begin
  dtpStartDate.Date := 0;
  dtpEndDate.Date := 0;
end;

procedure TFViewAddCustomer.HideNotification;
begin
  pnlMessage.ElementHandle.hidden := True;
end;

procedure TFViewAddCustomer.ShowNotification(Notification: string);
var
  splitNotification: TArray<string>;
begin
  console.log(notification);
  if Notification <> '' then
  begin
    splitNotification := Notification.Split([':']);
    if(splitNotification[0] = 'Success') then
    begin
      asm
        var messageDiv = document.getElementById('view.login.message');
        messageDiv.classList.remove('alert-danger');
        messageDiv.classList.add('alert-success');
      end;
    end
    else
    begin
      asm
        var messageDiv = document.getElementById('view.login.message');
        messageDiv.classList.remove('alert-success');
        messageDiv.classList.add('alert-danger');
      end;
    end;
    console.log(splitNotification[1]) ;
    lblMessage.Caption := splitNotification[1];
    pnlMessage.ElementHandle.hidden := False;
  end;
end;

end.