1import{a as d,j as e}from"./vendor-query-CUrCPljQ.js";import{u as Y,e as Z}from"./vendor-react-BRVFC246.js";import{u as ee,h as ae,e as E,a as f,S as re,l as z,g as te}from"./index-Dj4_Ew37.js";import{Character as C}from"./Character-DVDndd1E.js";import{GenerateImage as se,InvokeLLM as ie}from"./Core-DkoTAQXn.js";import{b as B}from"./content-moderation-EU2n1eVj.js";import{I as S}from"./input-DkVKe5IN.js";import{T as O}from"./textarea-DWHrcN23.js";import{L as g}from"./label-Dx9UIsm1.js";import{C as _,b as D,c as I,a as A,d as le}from"./card-DSRyeHHj.js";import{S as V,a as W,b as H,c as J,d as o}from"./select-OycU2L2Z.js";import{u as ne}from"./use-toast-BFOIPtKL.js";import{S as ce,A as oe,a as de,b as me,c as he,d as pe,e as xe,f as ge,g as ue,h as fe}from"./alert-dialog-CsP48zQM.js";import{L as v}from"./loader-circle-CYfkAKdo.js";import{m as j}from"./vendor-motion-CTPhcexI.js";import{A as ve}from"./arrow-left-SX2igFqY.js";import{P as je}from"./palette-BG_gcEzz.js";import{W as ye}from"./wand-sparkles-BfFCVOwb.js";import{E as be}from"./eye-BoaZrjAr.js";import{T as Ne}from"./trash-2-ANGJ_e0R.js";import"./vendor-sanity-CFlrRrW_.js";import"./vendor-clerk-DTlJ4EYF.js";import"./vendor-ui-D3so5JLU.js";import"./chevron-down-Dozq31yJ.js";import"./check-XEuJLllV.js";import"./chevron-up-Bq1KRJMP.js";const k={hidden:{opacity:0,y:18},visible:(x=0)=>({opacity:1,y:0,transition:{delay:x*.08,duration:.35,ease:"easeOut"}})};function Xe(){const x=Y(),[y]=Z(),{toast:l}=ne(),{t:a,isRTL:s}=ee(),$=ae(),[r,h]=d.useState({id:null,name:"",gender:"neutral",age:5,personality:"",appearance:"",art_style:"cartoon",primary_image_url:""}),[q,b]=d.useState(!0),[P,G]=d.useState(!1),[L,F]=d.useState(!1),[u,T]=d.useState(!1),[U,R]=d.useState(!1);d.useEffect(()=>{const t=y.get("id"),n=y.get("name"),i=y.get("data"),c=async m=>{try{const w=await C.get(m);h(w)}catch{l({title:a("characterEditor.errorLoad"),variant:"destructive"}),x(E("Characters"));return}finally{b(!1)}};if(t)c(t);else if(i)try{const m=JSON.parse(decodeURIComponent(i));h(w=>({...w,...m}))}catch{}finally{b(!1)}else n&&h(m=>({...m,name:decodeURIComponent(n)})),b(!1)},[y]);const p=(t,n)=>{h(i=>({...i,[t]:n}))},M=d.useCallback(async()=>{T(!0);try{const n=B("5-10")+`A ${r.gender==="boy"?"boy":r.gender==="girl"?"girl":"child"} character named ${r.name}, age ${r.age}, with ${r.appearance}. Style: ${r.art_style}. Child-friendly, wholesome illustration.`,i=await se({prompt:n,quality:"standard",size:"1024x1024"}),c=typeof i=="string"?i:i.url;h(m=>({...m,primary_image_url:c})),l({title:a("characterEditor.imageGenerated"),description:a("characterEditor.imageGeneratedDesc")})}catch{l({variant:"destructive",title:a("characterEditor.imageGenerateFailed"),description:a("characterEditor.tryAgain")})}finally{T(!1)}},[r]),X=d.useCallback(async()=>{R(!0);try{const n=B("5-10")+'Generate a name, age (a number between 4 and 10), gender (boy/girl/neutral), personality, and appearance for a fictional child character. Focus on positive, child-friendly traits. Provide the output as a JSON object with keys: "name", "age", "gender", "personality", "appearance". Example: {"name": "Lily", "age": 7, "gender": "girl", "personality": "Brave and adventurous, loves to explore.", "appearance": "Long brown hair, big blue eyes, wears a red dress."}',i=await ie({prompt:n,temperature:.7,max_tokens:500,response_json_schema:{type:"object",properties:{name:{type:"string"},age:{type:"number"},gender:{type:"string"},personality:{type:"string"},appearance:{type:"string"}}}});h(c=>({...c,name:i.name||c.name,age:i.age||c.age,gender:i.gender||c.gender,personality:i.personality||c.personality,appearance:i.appearance||c.appearance})),l({title:a("characterEditor.detailsGenerated"),description:a("characterEditor.detailsGeneratedDesc")})}catch{l({variant:"destructive",title:a("characterEditor.detailsGenerateFailed"),description:a("characterEditor.tryAgain")})}finally{R(!1)}},[]),K=async()=>{if(!r.name||!r.personality||!r.appearance){l({variant:"destructive",title:a("characterEditor.missingInfo"),description:a("characterEditor.missingFields")});return}G(!0);try{if(r.id===null){const n=await C.create(r);l({title:a("characterEditor.successCreate")}),$.awardXP("character_created"),$.incrementStat("totalCharacters"),h(i=>({...i,id:n.id})),x(`${E("CharacterEditor")}?id=${n.id}`)}else await C.update(r.id,r),l({title:a("characterEditor.successU
1pdate")})}catch{l({variant:"destructive",title:r.id===null?a("characterEditor.errorCreate"):a("characterEditor.errorUpdate")})}finally{G(!1)}},Q=async()=>{F(!0);try{await C.delete(r.id),l({title:a("characterEditor.successDelete")}),x(E("Characters"))}catch{l({variant:"destructive",title:a("characterEditor.errorDelete")})}finally{F(!1)}},N=r.id===null;return q?e.jsx("div",{className:"flex justify-center items-center h-dvh",children:e.jsx(v,{className:"h-10 w-10 animate-spin text-purple-600"})}):e.jsxs("div",{className:"max-w-5xl mx-auto",dir:s?"rtl":"ltr",children:[e.jsxs(j.div,{initial:{opacity:0,y:-12},animate:{opacity:1,y:0},transition:{duration:.35},className:"relative mb-6 md:mb-8 rounded-b-3xl overflow-hidden bg-gradient-to-r from-violet-600 via-purple-600 to-indigo-600 px-4 md:px-8 pt-6 pb-8 shadow-lg mx-0",children:[e.jsx("div",{className:"absolute inset-0 bg-[url('/images/character-workshop.jpg')] bg-cover bg-center opacity-10"}),e.jsxs("div",{className:`relative flex flex-col md:flex-row md:items-center justify-between gap-4 ${s?"md:flex-row-reverse":""}`,children:[e.jsxs("div",{className:`flex items-center gap-3 ${s?"flex-row-reverse":""}`,children:[e.jsx("button",{onClick:()=>x(E("Characters")),className:"flex items-center justify-center w-9 h-9 rounded-xl bg-white/20 hover:bg-white/30 transition-colors text-white","aria-label":a("characterEditor.back"),children:e.jsx(ve,{className:`h-5 w-5 ${s?"rotate-180":""}`})}),e.jsxs("div",{className:s?"text-right":"",children:[e.jsx("h1",{className:"text-2xl md:text-3xl font-bold text-white drop-shadow-sm",children:a(N?"characterEditor.createNew":"characterEditor.editCharacter")}),!N&&r.name&&e.jsx("p",{className:"text-purple-100 mt-0.5 text-sm",children:r.name})]})]}),e.jsxs(f,{onClick:X,disabled:U,className:"bg-white text-purple-700 hover:bg-purple-50 shadow-md rounded-xl gap-2 shrink-0",children:[U?e.jsx(v,{className:"h-4 w-4 animate-spin"}):e.jsx(re,{className:"h-4 w-4"}),a("characterEditor.generateDetails")]})]})]}),e.jsxs("div",{className:"px-4 md:px-6 pb-8 grid grid-cols-1 md:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"md:col-span-2 space-y-5",children:[e.jsx(j.div,{custom:0,variants:k,initial:"hidden",animate:"visible",children:e.jsxs(_,{className:"rounded-2xl shadow-sm border-0 ring-1 ring-black/5 dark:ring-white/10",children:[e.jsx(D,{className:"pb-3",children:e.jsxs(I,{className:"text-base flex items-center gap-2",children:[e.jsx("span",{className:"flex items-center justify-center w-7 h-7 rounded-lg bg-purple-100 dark:bg-purple-900/40 text-purple-600 dark:text-purple-400",children:e.jsx(z,{className:"h-4 w-4"})}),a("characterEditor.basicInfo")]})}),e.jsxs(A,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(g,{htmlFor:"name",className:`text-sm font-medium mb-1.5 block ${s?"text-right":""}`,children:a("characterEditor.name")}),e.jsx(S,{id:"name",value:r.name,onChange:t=>p("name",t.target.value),className:"rounded-xl",dir:s?"rtl":"ltr"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(g,{htmlFor:"age",className:`text-sm font-medium mb-1.5 block ${s?"text-right":""}`,children:a("characterEditor.age")}),e.jsx(S,{id:"age",type:"number",value:r.age,onChange:t=>p("age",t.target.valueAsNumber||""),className:"rounded-xl"})]}),e.jsxs("div",{children:[e.jsx(g,{htmlFor:"gender",className:`text-sm font-medium mb-1.5 block ${s?"text-right":""}`,children:a("characterEditor.gender")}),e.jsxs(V,{value:r.gender,onValueChange:t=>p("gender",t),children:[e.jsx(W,{className:"rounded-xl",children:e.jsx(H,{})}),e.jsxs(J,{children:[e.jsx(o,{value:"boy",children:a("characterEditor.boy")}),e.jsx(o,{value:"girl",children:a("characterEditor.girl")}),e.jsx(o,{value:"neutral",children:a("characterEditor.neutral")})]})]})]})]})]})]})}),e.jsx(j.div,{custom:1,variants:k,initial:"hidden",animate:"visible",children:e.jsxs(_,{className:"rounded-2xl shadow-sm border-0 ring-1 ring-black/5 dark:ring-white/10",children:[e.jsxs(D,{className:"pb-3",children:[e.jsxs(I,{className:"text-base flex items-center gap-2",children:[e.jsx("span",{className:"flex items-center justify-center w-7 h-7 rounded-lg bg-indigo-100 dark:bg-indigo-900/40 text-indigo-600 dark:text-indigo-400",children:e.jsx(te,{className:"h-4 w-4"})}),a("characterEditor.personalityAppearance")]}),e.jsx(le,{className:s?"text-right":"",children:a("characterEditor.personalityDesc")})]}),e.jsxs(A,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(g,{htmlFor:"personality",className:`text-sm font-medium mb-1.5 block ${s?"text-right":""}`,children:a("characterEditor.personality")}),e.jsx(O,{id:"personality",placeholder:a("characterEditor.personalityPlaceholder"),value:r.personality,onChange:t=>p("personality",t.target.value),rows:4,className:"rounded-xl resize-none",dir:s?"rtl":"ltr"})]}),e.jsxs("div",{children:[e.jsx(g,{htmlFor:"appearance",className:`text-sm font-medium mb-1.5 block ${s?"text-right":""}`,children:a("characterEditor.appearance")}),e.jsx(O,{id:"appearance",placeholder:a("characterEditor.appearancePlaceholder"),value:r.appearance,onChange:t=>p("appearance",t.target.value),rows:4,className:"rounded-xl resize-none",dir:s?"rtl":"ltr"})]})]})]})})]}),e.jsxs("div",{className:"space-y-5",children:[e.jsx(j.div,{custom:2,variants:k,initial:"hidden",animate:"visible",children:e.jsxs(_,{className:"rounded-2xl shadow-sm border-0 ring-1 ring-black/5 dark:ring-white/10 overflow-hidden",children:[e.jsx(D,{className:"pb-3",children:e.jsxs(I,{className:"text-base flex items-center gap-2",children:[e.jsx("span",{className:"flex items-center justify-center w-7 h-7 rounded-lg bg-violet-100 dar
1k:bg-violet-900/40 text-violet-600 dark:text-violet-400",children:e.jsx(je,{className:"h-4 w-4"})}),a("characterEditor.visuals")]})}),e.jsxs(A,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(g,{htmlFor:"art_style",className:`text-sm font-medium mb-1.5 block ${s?"text-right":""}`,children:a("characterEditor.artStyle")}),e.jsxs(V,{value:r.art_style,onValueChange:t=>p("art_style",t),children:[e.jsx(W,{className:"rounded-xl",children:e.jsx(H,{})}),e.jsxs(J,{children:[e.jsx(o,{value:"cartoon",children:a("characterEditor.styleCartoon")}),e.jsx(o,{value:"disney",children:a("characterEditor.styleDisney")}),e.jsx(o,{value:"pixar",children:a("characterEditor.stylePixar")}),e.jsx(o,{value:"watercolor",children:a("characterEditor.styleWatercolor")}),e.jsx(o,{value:"sketch",children:a("characterEditor.styleSketch")}),e.jsx(o,{value:"realistic",children:a("characterEditor.styleRealistic")}),e.jsx(o,{value:"anime",children:a("characterEditor.styleAnime")})]})]})]}),e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"absolute -inset-1 rounded-full bg-gradient-to-br from-purple-400 via-violet-500 to-indigo-500 opacity-70 blur-sm group-hover:opacity-100 transition-opacity duration-300"}),e.jsx("div",{className:"relative rounded-full overflow-hidden h-40 w-40 ring-2 ring-white dark:ring-gray-800 shadow-xl",children:r.primary_image_url?e.jsx("img",{src:r.primary_image_url,alt:r.name||a("characterEditor.preview"),className:"w-full h-full object-cover"}):e.jsx("div",{className:"w-full h-full bg-gradient-to-br from-purple-100 to-indigo-100 dark:from-purple-900/40 dark:to-indigo-900/40 flex items-center justify-center",children:e.jsx(z,{className:"h-20 w-20 text-purple-300 dark:text-purple-600"})})}),u&&e.jsx("div",{className:"absolute inset-0 rounded-full overflow-hidden",children:e.jsx("div",{className:"absolute inset-0 bg-gradient-to-r from-transparent via-white/40 to-transparent animate-[shimmer_1.5s_infinite] -translate-x-full"})})]}),r.name&&e.jsxs("div",{className:`text-center ${s?"text-right":""}`,children:[e.jsx("p",{className:"font-semibold text-gray-900 dark:text-white",children:r.name}),r.age>0&&e.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:[r.age," · ",r.gender&&a(`characterEditor.${r.gender}`)]})]}),e.jsx(S,{placeholder:a("characterEditor.imageUrlPlaceholder"),value:r.primary_image_url,onChange:t=>p("primary_image_url",t.target.value),className:"rounded-xl text-xs",dir:"ltr"}),e.jsxs(f,{onClick:M,disabled:u||!r.name||!r.appearance,className:"w-full relative overflow-hidden rounded-xl bg-gradient-to-r from-violet-600 to-purple-600 hover:from-violet-700 hover:to-purple-700 text-white shadow-md gap-2 group",children:[!u&&e.jsx("span",{className:"absolute inset-0 bg-gradient-to-r from-transparent via-white/25 to-transparent -translate-x-full group-hover:translate-x-full transition-transform duration-700 ease-in-out"}),u?e.jsx(v,{className:"h-4 w-4 animate-spin"}):e.jsx(ye,{className:"h-4 w-4"}),u?a("characterEditor.generating")||"Generating...":a("characterEditor.generateImage")]}),r.primary_image_url&&e.jsxs(f,{variant:"outline",className:"w-full rounded-xl gap-2",onClick:()=>window.open(r.primary_image_url,"_blank","noopener,noreferrer"),children:[e.jsx(be,{className:"h-4 w-4"}),a("characterEditor.viewImage")]})]})]})]})}),e.jsxs(j.div,{custom:3,variants:k,initial:"hidden",animate:"visible",className:"space-y-3",children:[e.jsxs(f,{onClick:K,disabled:P,className:"w-full rounded-xl bg-gradient-to-r from-purple-600 to-indigo-600 hover:from-purple-700 hover:to-indigo-700 text-white shadow-md gap-2 h-11",children:[P?e.jsx(v,{className:"h-4 w-4 animate-spin"}):e.jsx(ce,{className:"h-4 w-4"}),a(N?"characterEditor.createCharacter":"characterEditor.saveChanges")]}),!N&&e.jsxs(oe,{children:[e.jsx(de,{asChild:!0,children:e.jsxs(f,{variant:"outline",disabled:L,className:"w-full rounded-xl border-red-200 text-red-600 hover:bg-red-50 dark:border-red-800 dark:text-red-400 dark:hover:bg-red-950/30 gap-2",children:[L?e.jsx(v,{className:"h-4 w-4 animate-spin"}):e.jsx(Ne,{className:"h-4 w-4"}),a("characterEditor.deleteCharacter")]})}),e.jsxs(me,{className:"rounded-2xl",children:[e.jsxs(he,{children:[e.jsx(pe,{children:a("characterEditor.deleteCharacter")}),e.jsx(xe,{children:a("characterEditor.deleteConfirm")})]}),e.jsxs(ge,{children:[e.jsx(ue,{className:"rounded-xl",children:a("characterEditor.cancelBtn")}),e.jsx(fe,{className:"bg-destructive text-destructive-foreground hover:bg-destructive/90 rounded-xl",onClick:Q,children:a("characterEditor.deleteCharacter")})]})]})]})]})]})]})]})}export{Xe as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.