import { useMemo } from 'react';
import { IconSettings } from '@tabler/icons-react';
import { DataTableColumn } from 'mantine-datatable';
import { Center } from '@mantine/core';
import BaseTableActions from '@/components/Tables/Actions/BaseTableActions';
import { MarketplaceSchema } from '@/lib/client';
import { zMarketplaceSchema } from '@/lib/client/zod.gen';
import BaseMarketplaceColumnRender from '@/pages/marketplaces/components/BaseMarketplaceColumnRender/BaseMarketplaceColumnRender';

const useMarketplacesTableColumns = () => {
  return useMemo(
    () =>
      [
        {
          accessor: 'id',
          title: 'ID',
          width: '0%',
        },
        {
          accessor: 'baseMarketplace',
          title: 'Базовый маркетплейс',
          render: ({ baseMarketplace }: MarketplaceSchema) => (
            <BaseMarketplaceColumnRender object={baseMarketplace} />
          ),
          width: '0%',
        },
        {
          accessor: 'name',
          title: 'Название',
        },
        {
          width: '0%',
          accessor: 'actions',
          title: (
            <Center>
              <IconSettings size={16} />
            </Center>
          ),
          render: (element) => (
            <BaseTableActions
              element={element}
              onChange={async () => {
                // const zodSchema = await zMarketplaceSchema.parseAsync(element)
                Object.entries(zMarketplaceSchema.shape).forEach(([key, val], index, arr) => {
                  console.log(val.type);
                });
              }}
              onDelete={async () => {}}
            />
          ),
        },
      ] as DataTableColumn<MarketplaceSchema>[],
    []
  );
};

export default useMarketplacesTableColumns;
