/* eslint-disable @typescript-eslint/no-explicit-any */
import AdvancedSearch from "./Components/AdvancedSearch/AdvancedSearch";
import GlobalSearch from "./Components/GlobalSearch/GlobalSearch";
import QuickFilter from "./Components/QuickFilter";
import GroupBy from "./Components/GroupBy";
import Reset from "./Components/Reset";
import Setting from "./Components/Setting/Setting";
import Export from "./Components/Export/Export";
import UserView from "./Components/ScreenView/UserView";
import { ToolbarOptions } from "./type";


interface GridToolBarViewProps {
  widgetStyle?: {
    id?: string;
    className?: string;
    inline?: React.CSSProperties;
  };
  toolBarOptions: ToolbarOptions;
  config: { uiElementGroupId: string };
  uiElementGroupData: Record<string, any>;
  loadTemplateSupportiveData?: (
    callBack: (args: any) => void,
    supportiveKeys: any,
  ) => Promise<any>;
  onModelUpdate: (
    callBack: ((args: any) => void) | null,
    fieldName: string,
    value: any,
  ) => void;
  onExport?: (
    callBack: ((args: any) => void) | null,
    exportViewModel: any,
  ) => void;
  onExportDelete: (callBack: ((args: any) => void) | null, id: string) => void;
  onExportList: (callBack: ((args: any) => void) | null) => void;
  onExportDownload: (
    callBack: ((args: any) => void) | null,
    id: string,
  ) => void;
  getUniqueViewId?: (callBack: (response: string) => void) => void;
  eventService?: any;
}

const GridToolBarView = ({
  widgetStyle,
  toolBarOptions,
  config,
  uiElementGroupData,
  loadTemplateSupportiveData,
  onModelUpdate,
  onExport,
  onExportDelete,
  onExportList,
  onExportDownload,
  getUniqueViewId,
  eventService,
}: GridToolBarViewProps) => {
  return (
    <div
      id={widgetStyle?.id || ""}
      className={`tmpl-grid-toolbar-container ${widgetStyle?.className || ""}`}
      data-prc-col-important={(widgetStyle as any)?.important ? widgetStyle?.className || undefined : undefined}
      style={{ ...(widgetStyle?.inline || {}) }}
    >
      <GlobalSearch
        visible={toolBarOptions.globalSearch.visible}
        disabled={toolBarOptions.globalSearch.disabled}
        config={config}
        uiElementGroupData={uiElementGroupData}
        onModelUpdate={onModelUpdate}
      />
      <AdvancedSearch
        visible={toolBarOptions.advancedSearch.visible}
        disabled={toolBarOptions.advancedSearch.disabled}
        filterableFields={toolBarOptions.advancedSearch.filterableFields}
        enableCustomView={toolBarOptions.advancedSearch.enableCustomView}
        config={config}
        uiElementGroupData={uiElementGroupData}
        onModelUpdate={onModelUpdate}
        loadTemplateSupportiveData={loadTemplateSupportiveData}
      />
      <QuickFilter
        visible={toolBarOptions.quickFilter.visible}
        disabled={toolBarOptions.quickFilter.disabled}
        enableCustomView={toolBarOptions.quickFilter.enableCustomView}
        config={config}
        uiElementGroupData={uiElementGroupData}
        onModelUpdate={onModelUpdate}
        loadTemplateSupportiveData={loadTemplateSupportiveData}
      />
      <GroupBy
        visible={toolBarOptions.groupBy.visible}
        disabled={toolBarOptions.groupBy.disabled}
        enableCustomView={toolBarOptions.groupBy.enableCustomView}
        groupableFields={toolBarOptions.groupBy.groupableFields}
        config={config}
        uiElementGroupData={uiElementGroupData}
        onModelUpdate={onModelUpdate}
      />
      <Reset
        visible={toolBarOptions.reset.visible}
        disabled={toolBarOptions.reset.disabled}
        config={config}
        uiElementGroupData={uiElementGroupData}
        onModelUpdate={onModelUpdate}
        getUniqueViewId={getUniqueViewId}
      />
      <Setting
        visible={toolBarOptions.setting.visible}
        disabled={toolBarOptions.setting.disabled}
        disableColumnChooser={toolBarOptions.setting.disableColumnChooser}
        columns={toolBarOptions.setting.columns}
        disabledDisplayWidgetType={
          toolBarOptions.setting.disabledDisplayWidgetType
        }
        enableCustomView={toolBarOptions.setting.enableCustomView}
        defaultActiveDataWidgetType={toolBarOptions.setting.activeDataWidgetType}
        config={config}
        uiElementGroupData={uiElementGroupData}
        onModelUpdate={onModelUpdate}
      />
      <UserView
        visible={toolBarOptions.userView.visible}
        disabled={toolBarOptions.userView.disabled}
        enableDefaultSaveInSession={
          toolBarOptions.userView.enableDefaultSaveInSession
        }
        advancedFilterableFields={
          toolBarOptions.advancedSearch.filterableFields
        }
        quickFilterRows={toolBarOptions.quickFilter.filterRows}
        activeDataWidgetType={toolBarOptions.setting.activeDataWidgetType}
        columns={toolBarOptions.setting.columns}
        config={config}
        uiElementGroupData={uiElementGroupData}
        onModelUpdate={onModelUpdate}
        getUniqueViewId={getUniqueViewId}
        eventService={eventService}
        toolBarOptions={toolBarOptions}
      />
      <Export
        visible={toolBarOptions.export.visible}
        disabled={toolBarOptions.export.disabled}
        exportTypes={toolBarOptions.export.exportTypes}
        dataScopes={toolBarOptions.export.dataScopes}
        config={config}
        onExport={onExport}
        onExportDelete={onExportDelete}
        onExportList={onExportList}
        onExportDownload={onExportDownload}
      />
    </div>
  );
};

export default GridToolBarView;
