import { useCallback, type ReactElement } from 'react';
import { Trash } from 'lucide-react';
import { useDeleteDepreciationRecord } from '../../../hooks/use-delete-depreciation-record.js';
import { Button } from '../../ui/button.js';
import { Tooltip } from '../index.js';
import { ConfirmationModal } from '../modals/confirmation-modal.js';

export function DeleteDepreciationRecord(props: {
  depreciationRecordId: string;
  onDelete?: () => void;
}): ReactElement {
  const { fetching, deleteDepreciationRecord } = useDeleteDepreciationRecord();

  const onExecute = useCallback(() => {
    deleteDepreciationRecord({
      depreciationRecordId: props.depreciationRecordId,
    }).then(() => {
      props.onDelete?.();
    });
  }, [props, deleteDepreciationRecord]);

  return (
    <Tooltip content="Remove Depreciation">
      <ConfirmationModal
        onConfirm={onExecute}
        title="Are you sure you want to delete the depreciation record?"
      >
        <Button variant="outline" size="icon" className="size-7.5 text-red-500" disabled={fetching}>
          <Trash className="size-5" />
        </Button>
      </ConfirmationModal>
    </Tooltip>
  );
}
