import { Button, Classes } from '@blueprintjs/core'; import { useCallback, useMemo } from 'react'; import { useFormContext, useWatch } from 'react-hook-form'; import { FaRegTrashAlt } from 'react-icons/fa'; import { NumberInput2Controller } from '../../elements/NumberInput2Controller.js'; import { TanStackTable, createTanStackColumnHelper, } from '../../elements/tanstack_table/index.ts'; export function ExclusionsZonesTable() { const { setValue, control, getValues } = useFormContext(); const exclusionsZones = useWatch({ name: 'exclusionsZones' }); const handleDelete = useCallback( (index: number) => { setValue( 'exclusionsZones', getValues('exclusionsZones').filter((_: any, i: number) => i !== index), ); }, [getValues, setValue], ); const exclusionsZonesColumns = useMemo(() => { const columnHelper = createTanStackColumnHelper(); return columnHelper.columns([ { header: '#', meta: { style: { width: '50px' } }, accessorFn: (_, index) => index + 1, }, { header: 'From', cell: ({ row }) => ( ), }, { header: 'To', cell: ({ row }) => ( ), }, { header: '', meta: { style: { width: '70px' } }, id: 'actions', cell: ({ row }) => { return ( ); }, }, ]); }, [control, handleDelete]); if (!exclusionsZones || !Array.isArray(exclusionsZones)) { return null; } return ( ); }