'use client';

import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogHeader,
  DialogTitle,
} from '@repo/shadcn/dialog';
// import { AccountPlan } from '@/feactures/users/schemas/account-plan.schema';
import { EditInventory, InventoryTable } from '../../schemas/inventory';
import { CreateForm } from './create-product-form';
import { UpdateForm } from './update-product-form';

interface ModalProps {
  open: boolean;
  onOpenChange: (open: boolean) => void;
  defaultValues?: Partial<InventoryTable>;
}

export function AccountPlanModal({
  open,
  onOpenChange,
  defaultValues,
}: ModalProps) {
  const handleSuccess = () => {
    onOpenChange(false);
  };

  const handleCancel = () => {
    onOpenChange(false);
  };

  return (
    <Dialog
      open={open}
      onOpenChange={(open) => {
        if (!open) {
          onOpenChange(false);
        }
      }}
    >
      <DialogContent className="sm:max-w-[600px] z-50 backdrop-blur-lg bg-background/80">
        <DialogHeader>
          <DialogTitle>
            {defaultValues?.id
              ? 'Actualizar producto'
              : 'Registrar producto'}
          </DialogTitle>
          <DialogDescription>
            Complete los campos para {defaultValues?.id ? 'actualizar' : 'registrar'} un producto
          </DialogDescription>
        </DialogHeader>
        {defaultValues?.id ? ( 
          <UpdateForm
            onSuccess={handleSuccess}
            onCancel={handleCancel}
            defaultValues={defaultValues}
          />
        ): (
          <CreateForm
            onSuccess={handleSuccess}
            onCancel={handleCancel}
          />
        )}
      </DialogContent>
    </Dialog>
  );
}
