import { useActionMutation } from "@agent-native/core/client/hooks"; import { useT } from "@agent-native/core/client/i18n"; import { ASPECT_RATIOS, IMAGE_CATEGORIES, type AspectRatio, type ImageCategory, } from "@shared/api"; import { IconTrash } from "@tabler/icons-react"; import { useState } from "react"; import { Link } from "react-router"; import { toast } from "sonner"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Checkbox } from "@/components/ui/checkbox"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Textarea } from "@/components/ui/textarea"; export function GenerationPresetsPanel({ libraryId, presets, }: { libraryId: string; presets: any[]; }) { const t = useT(); const createPreset = useActionMutation("create-generation-preset"); const deletePreset = useActionMutation("delete-generation-preset"); const [open, setOpen] = useState(false); const [confirmPresetId, setConfirmPresetId] = useState(null); const [title, setTitle] = useState(""); const [category, setCategory] = useState("social"); const [aspectRatio, setAspectRatio] = useState("1:1"); const [promptTemplate, setPromptTemplate] = useState(""); const [textPolicy, setTextPolicy] = useState(t("library.defaultTextPolicy")); const [includeLogo, setIncludeLogo] = useState(false); function reset() { setTitle(""); setCategory("social"); setAspectRatio("1:1"); setPromptTemplate(""); setTextPolicy(t("library.defaultTextPolicy")); setIncludeLogo(false); } function submit() { const trimmed = title.trim(); if (!trimmed) return; createPreset.mutate( { libraryId, title: trimmed, category, aspectRatio, imageSize: "2K", promptTemplate: promptTemplate.trim() || undefined, textPolicy, referencePolicy: "auto", includeLogo, }, { onSuccess: () => { toast.success(t("brandKitDetail.generationPresetCreated")); reset(); setOpen(false); }, onError: (error: Error) => { toast.error( error.message || t("brandKitDetail.couldNotCreatePreset"), ); }, }, ); } return (

{t("brandKitDetail.generationPresets")}

{t("brandKitDetail.generationPresetsDescription")}

{presets.map((preset) => (
{preset.title} {preset.aspectRatio} {preset.includeLogo ? ( {t("brandKitDetail.logo")} ) : null}

{preset.textPolicy || preset.description || preset.category}

))} {!presets.length ? (

{t("brandKitDetail.noPresetsYet")}

) : null}
{ if (!isOpen) setConfirmPresetId(null); }} > {t("brandKitDetail.deleteGenerationPreset")} {t("brandKitDetail.deleteGenerationPresetDescription")} {t("brandKitDetail.cancel")} { event.preventDefault(); if (!confirmPresetId) return; deletePreset.mutate( { id: confirmPresetId }, { onSuccess: () => { setConfirmPresetId(null); toast.success( t("brandKitDetail.generationPresetDeleted"), ); }, onError: (error: Error) => { toast.error( error.message || t("brandKitDetail.couldNotDeletePreset"), ); }, }, ); }} > {t("assetDetail.delete")} {t("brandKitDetail.newGenerationPreset")} {t("brandKitDetail.newGenerationPresetDescription")}
setTitle(event.target.value)} placeholder={t("brandKitDetail.campaignLaunch")} />