"use client"; import { Building2, Check, ChevronsUpDown, Globe, RefreshCcw, Share2, TrendingUp, } from "lucide-react"; import { useState } from "react"; import { Tags, TagsContent, TagsEmpty, TagsGroup, TagsInput, TagsItem, TagsList, TagsTrigger, TagsValue, } from "@/components/kibo-ui/tags"; import { Button } from "@/components/ui/button"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "@/components/ui/command"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { cn } from "@/lib/utils"; interface ComboboxOption { label: string; value: string; } interface FormComboboxProps { value: string; onChange: (value: string) => void; options: ComboboxOption[]; name?: string; searchPlaceholder?: string; emptyMessage?: string; required?: boolean; } interface FormTagsProps { value: string[]; onChange: (value: string[]) => void; options: ComboboxOption[]; name?: string; searchPlaceholder?: string; emptyMessage?: string; required?: boolean; } const FormCombobox = ({ value, onChange, options, name, searchPlaceholder = "جستجو بر اساس نام...", emptyMessage = "موردی یافت نشد.", required = false, }: FormComboboxProps) => { const [open, setOpen] = useState(false); const selectedOption = options.find((option) => option.value === value); const displayValue = selectedOption ? selectedOption.label : ""; return (
{}} onClick={() => setOpen(true)} className={cn( "cursor-pointer bg-background pe-6", !value && "text-muted-foreground", )} />
{emptyMessage} {options.map((option) => ( { onChange(currentValue === value ? "" : currentValue); setOpen(false); }} > {option.label} ))}
); }; const FormTags = ({ value = [], onChange, options, name, searchPlaceholder = "جستجوی دسته‌بندی...", emptyMessage = "دسته‌بندی‌ای یافت نشد.", required = false, }: FormTagsProps) => { const [open, setOpen] = useState(false); const handleSelect = (selectedValue: string) => { const newValue = value.includes(selectedValue) ? value.filter((v) => v !== selectedValue) : [...value, selectedValue]; onChange(newValue); }; const handleRemove = (tagToRemove: string) => { onChange(value.filter((v) => v !== tagToRemove)); }; return ( {value.length > 0 ? value.map((tagValue) => { const option = options.find((opt) => opt.value === tagValue); return ( handleRemove(tagValue)} > {option?.label || tagValue} ); }) : null} {emptyMessage} {options.map((option) => ( handleSelect(option.value)} > {option.label} ))} {required && value.length === 0 && ( )} {value.map((tagValue) => ( ))} ); }; interface CompaniesCreate1Props { title?: string; className?: string; } const CompaniesCreate1 = ({ title = "ایجاد پروفایل شرکت", className, }: CompaniesCreate1Props) => { const [formData, setFormData] = useState>( {}, ); const FIELD_SECTIONS = [ { title: "اطلاعات پایه", icon: Building2, fields: [ { name: "name", label: "نام شرکت", required: true, }, { name: "description", label: "معرفی شرکت", }, { name: "team", label: "تیم", type: "combobox", searchPlaceholder: "جستجوی اعضا...", emptyMessage: "عضوی یافت نشد.", required: true, options: [ { label: "علی", value: "alex", }, { label: "محمد", value: "john", }, { label: "سارا", value: "jane", }, ], }, { name: "categories", label: "دسته‌بندی‌ها", type: "tags", searchPlaceholder: "جستجوی دسته‌بندی...", emptyMessage: "دسته‌بندی یافت نشد.", options: [ { label: "SaaS", value: "saas", }, { label: "تجارت الکترونیک", value: "ecommerce", }, { label: "فین‌تک", value: "fintech", }, { label: "بهداشت و درمان", value: "healthcare", }, { label: "آموزش", value: "education", }, { label: "سازمانی", value: "enterprise", }, { label: "B2B", value: "b2b", }, { label: "B2C", value: "b2c", }, ], }, ], }, { title: "موقعیت جغرافیایی", icon: Globe, fields: [ { name: "location", label: "موقعیت جغرافیایی", }, ], }, { title: "وب‌سایت و شبکه‌های اجتماعی", icon: Share2, fields: [ { name: "angellist", label: "AngelList", }, { name: "facebook", label: "Facebook", }, { name: "instagram", label: "Instagram", }, { name: "linkedin", label: "LinkedIn", }, { name: "twitter", label: "Twitter", }, ], }, { title: "شاخص‌های شرکت", icon: TrendingUp, fields: [ { name: "arr", label: "برآورد درآمد تکرارشونده سالانه (ARR)", }, { name: "funding", label: "سرمایه جذب‌شده", }, { name: "founded_date", label: "تاریخ تأسیس", }, { name: "employee_range", label: "محدوده تعداد کارکنان", }, ], }, { title: "اطلاعات تکمیلی", icon: RefreshCcw, fields: [ { name: "workspaces", label: "فضاهای کاری و پروژه‌های مرتبط", }, ], }, ]; const handleInputChange = (name: string, value: string | string[]) => { setFormData((prev) => ({ ...prev, [name]: value })); }; return (

{title}

اطلاعات شرکت را تکمیل کنید تا پروفایل آن در سامانه ایجاد و آماده استفاده شود.

e.preventDefault()} autoComplete="off" className="flex flex-col gap-8 rounded-lg border bg-muted/50 p-8 shadow-sm" > {FIELD_SECTIONS.map((section, sectionIndex) => (

{section.title}

{section.fields.map((field, i) => { const isCombobox = field.type === "combobox"; const isTags = field.type === "tags"; return (
{isCombobox && field.options ? ( handleInputChange(field.name, value) } options={field.options} searchPlaceholder={field.searchPlaceholder} emptyMessage={field.emptyMessage} required={field.required} /> ) : isTags && field.options ? ( handleInputChange(field.name, value) } options={field.options} searchPlaceholder={field.searchPlaceholder} emptyMessage={field.emptyMessage} required={field.required} /> ) : ( handleInputChange(field.name, e.target.value) } required={field.required} className="bg-background" /> )}
); })}
))}
); }; export { CompaniesCreate1 };