import { useState } from "react"; import { Pencil, Target, Trash } from "@phosphor-icons/react"; import type { AgentRecord, GoalRecord } from "@shared/types"; import { ActionButton, Input, Select, TextArea } from "../../ui"; import { ConfirmDelete } from "../helpers"; import { useT } from "../../../i18n"; type CreateProps = { mode: "create"; companyId: string; agents: AgentRecord[]; goals: GoalRecord[]; onSaved: () => Promise; }; type EditProps = { mode: "edit"; companyId: string; agents: AgentRecord[]; goals: GoalRecord[]; goal: GoalRecord; onSaved: () => Promise; onDeleted: () => Promise; }; export type GoalFormProps = CreateProps | EditProps; export function GoalForm(props: GoalFormProps) { const t = useT(); const isEdit = props.mode === "edit"; const editGoal = isEdit ? props.goal : null; const [title, setTitle] = useState(editGoal?.title ?? ""); const [description, setDescription] = useState(editGoal?.description ?? ""); const [status, setStatus] = useState(editGoal?.status ?? "active"); const [ownerAgentId, setOwnerAgentId] = useState( editGoal ? (editGoal.ownerAgentId ?? "") : (props.agents[0]?.id ?? ""), ); const [parentId, setParentId] = useState(editGoal?.parentId ?? ""); const [confirmingDelete, setConfirmingDelete] = useState(false); const parentCandidates = editGoal ? props.goals.filter((g) => g.id !== editGoal.id) : props.goals; return (