"use client";

import { otherAssetsFormConfig } from "@/components/form/transaction-workspace/module-configs";
import { CustomerStandardAssetListTable } from "@/app/customer/_components/customer-standard-asset-list-table";

import { saveOtherAssetColumnPrefsClient } from "../../_lib/other-assets-api";
import { useOtherAssetList } from "../../_lib/use-other-asset-list";
import {
  buildOtherAssetPageSearchParams,
  DEFAULT_OTHER_ASSET_PAGE_SIZE,
  DEFAULT_OTHER_ASSET_SORTING,
  EMPTY_OTHER_ASSET_FILTERS,
  getOtherAssetFilterColumnValue,
  parseOtherAssetPageStateFromSearchParams,
  placementDateRangeToOtherAssetFilters,
  setOtherAssetFilterColumnValue,
} from "../../_lib/other-assets-filters";
import {
  createOtherAssetColumns,
  FALLBACK_OTHER_ASSET_GRID_COLUMNS,
  OTHER_ASSET_OPTIONS_COLUMN_ID,
} from "./columns";
import { OtherAssetDetailSheet } from "./other-assets-detail-sheet";

export function ListOtherAssetsTable() {
  return (
    <CustomerStandardAssetListTable
      title="List Other Assets"
      emptyMessage="No other assets found."
      rowsPerPageId="other-assets-rows-per-page"
      moduleId="other-assets"
      singularName="Other asset"
      formConfig={otherAssetsFormConfig}
      optionsColumnId={OTHER_ASSET_OPTIONS_COLUMN_ID}
      fallbackColumns={FALLBACK_OTHER_ASSET_GRID_COLUMNS}
      defaultPageSize={DEFAULT_OTHER_ASSET_PAGE_SIZE}
      defaultSorting={DEFAULT_OTHER_ASSET_SORTING}
      emptyFilters={EMPTY_OTHER_ASSET_FILTERS}
      useList={useOtherAssetList}
      saveColumnPrefs={saveOtherAssetColumnPrefsClient}
      parsePageState={parseOtherAssetPageStateFromSearchParams}
      buildPageSearchParams={buildOtherAssetPageSearchParams}
      getFilterColumnValue={getOtherAssetFilterColumnValue}
      setFilterColumnValue={setOtherAssetFilterColumnValue}
      placementDateRangeToFilters={placementDateRangeToOtherAssetFilters}
      createColumns={(catalog, onView, onEdit, options) =>
        createOtherAssetColumns(catalog, onView, onEdit, {
          listPath: options.listPath,
          pagePermissions: options.pagePermissions,
        })
      }
      DetailSheet={OtherAssetDetailSheet}
    />
  );
}
