unit main;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
  ComCtrls, ExtendedTabControls, fphttpclient, opensslsockets, fpjson,
  jsonparser, ThreadUnit;

type

  { TForm1 }

  TForm1 = class(TForm)
    BtnSearch: TButton;
    ExtendedTabControl1: TExtendedTabControl;
    ExtendedTabToolbar1: TExtendedTabToolbar;
    Label1: TLabel;
    Label2: TLabel;
    memoTest: TMemo;
    TxtBoxSearch: TEdit;
    lblSearch: TLabel;
    TabControl1: TTabControl;
    procedure BtnSearchClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure TabControl1Change(Sender: TObject);
    procedure TxtBoxSearchChange(Sender: TObject);
  private

  public

  end;

var
  Form1: TForm1;
  Client: TFPHTTPClient;
  Response: string;
  PackageName: string;
  jData: TJSONData;
  packageData: TJSONObject;
  test1: ThreadClass;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin
  BtnSearch.Enabled := False;

end;

procedure TForm1.BtnSearchClick(Sender: TObject);
begin
  PackageName := TxtBoxSearch.Text;
  Client := TFPHTTPClient.Create(nil);
  try
    test1 := ThreadClass.create();
    Response := Client.Get(Concat('https://registry.npmjs.org/', PackageName));
    jData := GetJSON(Response);
    packageData := jData as TJSONObject;

    memoTest.Lines.Text := jData.FormatJSON;
  finally
    Client.Free;
  end;
end;

procedure TForm1.TabControl1Change(Sender: TObject);
begin

end;

procedure TForm1.TxtBoxSearchChange(Sender: TObject);
begin
  if Length(TxtBoxSearch.Text) > 1 then
    BtnSearch.Enabled := True
  else
    BtnSearch.Enabled := False;
end;

end.
