unit View.Home;

interface

uses
  System.SysUtils, System.Classes, WEBLib.Graphics, WEBLib.Forms, Vcl.StdCtrls,
  WEBLib.StdCtrls, Vcl.Controls, WEBLib.Dialogs, Vcl.Imaging.pngimage,
  WEBLib.ExtCtrls, WEBLib.Controls, Web, JS, WEBLib.Menus, WEBLib.WebCtrls;

type
  TFHome = class(TWebForm)
      btnHome: TWebButton;
      btnCompliance: TWebButton;
      btnContactUs: TWebButton;
    [async]
    procedure WebFormCreate(Sender: TObject);
    procedure btnComplianceClick(Sender: TObject);
    procedure WebFormClose(Sender: TObject; var Action: TCloseAction);
    procedure btnContactUsClick(Sender: TObject);
  public
    procedure NavScrollSizing;
  end;

var
  FHome: TFHome;

implementation

{$R *.dfm}

uses
  View.Compliance, View.ContactUs;

procedure TFHome.btnComplianceClick(Sender: TObject);
begin
  Close;
  Application.CreateForm(TFCompliance, FCompliance);
end;

procedure TFHome.btnContactUsClick(Sender: TObject);
begin
  Close;
  Application.CreateForm(TFContactUs, FContactUs);
end;

procedure TFHome.WebFormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

procedure TFHome.WebFormCreate(Sender: TObject);
begin
  Application.ThemeColor := clTMSWEB;
  NavScrollSizing;
end;

procedure TFHome.NavScrollSizing;
begin
  asm
    window.addEventListener('scroll', function() {
      var navbar = document.querySelector('.em-navbar-wrap .navbar');
      var logo = document.querySelector('.em-brand img');
      var scrollDistance = 50; // Adjust based on your preference

      if (window.scrollY > scrollDistance) {
        navbar.classList.add('scrolled');
        logo.classList.add('scrolled-logo');
      } else {
        navbar.classList.remove('scrolled');
        logo.classList.remove('scrolled-logo');
      }
    });
  end;
end;

initialization
  RegisterClass(TFHome);

end.
