import{v as M,r as l,c as h,j as e,C as u,F as c,x,B as f,W as C,D as I}from"./index-BB5hb7GN.js";import P from"./ImageUploadField-BxMq7UAM.js";import"./resizeImage-C6PvAwh0.js";const z=[["{fahrzeug}","Marke und Modell, z. B. „VW Golf 7“"],["{marke}","Marke"],["{modell}","Modellname"],["{baujahre}","Baujahre aus der Fahrzeug-Vorlage (leer, wenn unbekannt)"]],F=[["urls",'Liste von URLs ["https://…"]'],["url",'Einzelne URL "https://…"'],["input_images",'Objekte [{"type": "image_url", "image_url": "…"}]']],b=n=>({api_key:"",endpoint:n.endpoint||"",image_field:n.image_field||"image_urls",image_format:n.image_format||"urls",prompt:n.prompt||"",params:n.params||"",reference_path:n.reference_path||""});function T(){const n=M(),[r,j]=l.useState(null),[a,m]=l.useState(null),[_,y]=l.useState(!1),[k,v]=l.useState(""),[S,w]=l.useState(!1),[d,p]=l.useState(null);l.useEffect(()=>{h.get("/settings/higgsfield").then(t=>{j(t),m(b(t))})},[]);const s=(t,i)=>m(o=>({...o,[t]:i})),g=async(t,i={})=>{t==null||t.preventDefault(),y(!0),v("");try{const o=await h.post("/settings/higgsfield",{...a,...i});return j(o),m(b(o)),n.success("KI-Einstellungen gespeichert."),!0}catch(o){return v(o.message),!1}finally{y(!1)}},E=r&&a&&JSON.stringify(a)!==JSON.stringify(b(r)),N=async()=>{w(!0),p(null);try{if(E&&!await g())return;p(await h.post("/settings/connection-test",{key:"higgsfield"}))}catch(t){p({status:"error",message:t.message})}finally{w(!1)}};return a?e.jsxs("form",{onSubmit:g,className:"max-w-2xl space-y-6",children:[e.jsx(u,{title:"Zugang",description:"API-Key aus der Higgsfield-Cloud (cloud.higgsfield.ai > API Keys) im Format KEY_ID:KEY_SECRET. Er bleibt auf dem Server und wird nie exportiert.",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(c,{label:"API-Key",hint:r.has_api_key?`Hinterlegt (${r.api_key_hint}). Leer lassen = unverändert.`:"Noch kein Key hinterlegt.",children:e.jsx(x,{type:"password",autoComplete:"off",value:a.api_key,onChange:t=>s("api_key",t.target.value),placeholder:r.has_api_key?"••••••••":"KEY_ID:KEY_SECRET"})}),e.jsx(c,{label:"Modell-Endpunkt",hint:"Pfad des Higgsfield-Modells, wie er in der API-Doku bzw. im Playground des Modells steht – ohne https://api.higgsfield.ai/. Das Modell muss Referenzbilder annehmen (Bild-Bearbeitung / Image-to-Image).",children:e.jsx(x,{value:a.endpoint,onChange:t=>s("endpoint",t.target.value),placeholder:"z. B. bytedance/seedream/v4/edit"})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx(f,{variant:"secondary",onClick:N,disabled:S,children:S?"Teste…":E?"Speichern und testen":"Verbindung testen"}),r.has_api_key&&e.jsx(f,{variant:"ghost",onClick:()=>window.confirm("API-Key wirklich entfernen?")&&g(null,{api_key:"",remove_api_key:!0}),children:"Key entfernen"})]}),d&&e.jsxs("p",{className:`rounded-md p-3 text-sm ${d.status==="ok"?"bg-green-50 text-green-800 dark:bg-green-900/20 dark:text-green-300":d.status==="error"?"bg-red-50 text-red-800 dark:bg-red-900/20 dark:text-red-300":"bg-amber-50 text-amber-800 dark:bg-amber-900/20 dark:text-amber-300"}`,children:[d.message,d.hint&&e.jsx("span",{className:"mt-1 block text-xs opacity-80",children:d.hint})]})]})}),e.jsxs(u,{title:"Prompt",description:"Wird für jedes Modell ausgefüllt und an Higgsfield geschickt.",children:[e.jsx(C,{rows:6,value:a.prompt,onChange:t=>s("prompt",t.target.value)}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-1.5",children:[z.map(([t,i])=>e.jsx("button",{type:"button",title:i,onClick:()=>s("prompt",`${a.prompt}${a.prompt.endsWith(" ")||!a.prompt?"":" "}${t}`),className:"rounded-md bg-neutral-100 px-2 py-1 font-mono text-xs text-neutral-600 hover:bg-neutral-200 dark:bg-neutral-800 dark:text-neutral-300 dark:hover:bg-neutral-700",children:t},t)),a.prompt!==r.default_prompt&&e.jsx("button",{type:"button",onClick:()=>s("prompt",r.default_prompt),className:"ml-auto text-xs text-neutral-500 underline",children:"Standard-Prompt"})]})]}),e.jsx(u,{title:"Referenzbild",description:"Gibt Bildstil, Perspektive, Licht und Hintergrund vor, damit alle Modellbilder einheitlich aussehen. Wird bei jeder Generierung mitgeschickt.",children:e.jsx(P,{value:a.reference_path,onChange:t=>s("reference_path",t||""),label:"Bild"})}),e.jsx(u,{title:"Erweitert",description:"Nur ändern, wenn das gewählte Higgsfield-Modell andere Feldnamen erwartet.",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsx(c,{label:"Feld für Referenzbilder",hint:"Meist image_urls.",children:e.jsx(x,{value:a.image_field,onChange:t=>s("image_field",t.target.value),placeholder:"image_urls"})}),e.jsx(c,{label:"Format",children:e.jsx(I,{value:a.image_format,onChange:t=>s("image_format",t.target.value),children:F.map(([t,i])=>e.jsx("option",{value:t,children:i},t))})})]}),e.jsx(c,{label:"Zusätzliche Parameter (JSON)",hint:`Werden 1:1 mitgeschickt, z. B. Seitenverhältnis oder Auflösung. Standard: ${r.default_params}`,children:e.jsx(C,{rows:3,className:"font-mono text-xs",value:a.params,onChange:t=>s("params",t.target.value)})})]})}),k&&e.jsx("p",{className:"text-sm text-red-600",children:k}),e.jsx(f,{type:"submit",disabled:_,children:_?"Speichere…":"Speichern"})]}):e.jsx("p",{className:"text-sm text-neutral-400",children:"Lädt…"})}export{T as default};