"use client" import type React from "react" import { useState } from "react" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Textarea } from "@/components/ui/textarea" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import type { Supplier } from "@/types/business" interface SupplierFormProps { supplier?: Supplier open: boolean onOpenChange: (open: boolean) => void onSubmit: (supplier: Omit) => void } const paymentTerms = ["Net 15", "Net 30", "Net 45", "Net 60", "COD", "Prepaid", "Custom"] export function SupplierForm({ supplier, open, onOpenChange, onSubmit }: SupplierFormProps) { const [formData, setFormData] = useState({ name: supplier?.name || "", email: supplier?.email || "", phone: supplier?.phone || "", address: supplier?.address || "", paymentTerms: supplier?.paymentTerms || "Net 30", notes: supplier?.notes || "", contactPerson: supplier?.contactPerson || "", businessType: supplier?.businessType || "", taxId: supplier?.taxId || "", }) const handleSubmit = (e: React.FormEvent) => { e.preventDefault() onSubmit({ ...formData, amountOwed: supplier?.amountOwed || 0, }) onOpenChange(false) // Reset form if it's a new supplier if (!supplier) { setFormData({ name: "", email: "", phone: "", address: "", paymentTerms: "Net 30", notes: "", contactPerson: "", businessType: "", taxId: "", }) } } return ( {supplier ? "Edit Supplier" : "Add New Supplier"} {supplier ? "Update supplier information" : "Enter the details for the new supplier"}
setFormData({ ...formData, name: e.target.value })} placeholder="Enter company name" required />
setFormData({ ...formData, contactPerson: e.target.value })} placeholder="Primary contact name" />
setFormData({ ...formData, email: e.target.value })} placeholder="supplier@example.com" />
setFormData({ ...formData, phone: e.target.value })} placeholder="(555) 123-4567" />