"use client"; import { useState } from "react"; import { toast } from "sonner"; import { MoneyInput } from "@/components/money-input"; import { ResponsiveDialog } from "@/components/responsive-dialog"; import { Button } from "@/components/ui/button"; import { Checkbox } from "@/components/ui/checkbox"; import { Field, FieldDescription, FieldError, FieldGroup, FieldLabel } from "@/components/ui/field"; import { Input } from "@/components/ui/input"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { useAccounts } from "@/features/in-kind/components/in-kind-section"; import { tr } from "@/i18n/tr"; import { ASSET_KEYS, ASSETS, formatAssetQuantity, type AssetKey } from "@/shared/assets"; import { todayIstanbul } from "@/shared/dates"; import { MOVEMENT_KINDS, type MovementKind } from "@/shared/portfolio"; import { addMovementAction, saveAssetAction } from "../actions"; import type { AssetView } from "../service"; const t = tr.assets; type Errors = Record; const NONE = "__none__"; function Footer({ busy, formId, onClose }: { busy: boolean; formId: string; onClose: () => void }) { return ( <> ); } /** Yeni varlık / varlığı düzenle. */ export function AssetFormDialog({ item, onClose, onCreated, }: { item: AssetView | null; onClose: () => void; onCreated?: (id: string) => void; }) { const [v, setV] = useState({ assetKey: (item?.assetKey ?? "gram_gold") as AssetKey, name: item?.name ?? "", note: item?.note ?? "", isPrivate: item?.isPrivate ?? false, }); const [errors, setErrors] = useState({}); const [busy, setBusy] = useState(false); const set = (k: K, x: (typeof v)[K]) => setV((s) => ({ ...s, [k]: x })); const locked = Boolean(item?.movementCount); async function submit(e: React.FormEvent) { e.preventDefault(); setBusy(true); const r = await saveAssetAction(item?.id ?? null, { ...v, name: v.name.trim() || ASSETS[v.assetKey].label, }); setBusy(false); if (r.ok) { toast.success(t.toast.saved); onClose(); if (!item) onCreated?.((r.data as { id: string }).id); } else setErrors({ ...r.fieldErrors, root: r.fieldErrors ? undefined : r.error }); } const f = t.fields; return ( !o && onClose()} title={item ? t.editTitle : t.createTitle} footer={