1import{j as e,K as N,ag as Q,Z as I,N as M,J as O,a1 as U,a2 as V,a9 as Y}from"./ui-B1dMR2zo.js";import{r as u}from"./vendor-MPt6aqX6.js";import{u as B,i as H,h as W,s as y,t as w}from"./index-UI575IED.js";import{u as L}from"./useMutation-Dq0Ky1ph.js";import{D as Z,b as $,c as X,d as ee}from"./dialog-CkiPYWIJ.js";import{B as C}from"./button-Bpu3Na_L.js";import{T as R}from"./textarea-CyowIGuZ.js";import{S as D,a as A,b as q,c as J,d as K}from"./select-yTW2uprs.js";import{u as te}from"./useCharacters-B5lM1-l8.js";import{S as se}from"./SectionLayout--pHLsUpA.js";import"./supabase-D_2IiIQD.js";import"./index-1FCQw4jE.js";function ae(){const{user:s}=B(),l=H(),c=u.useRef(null),i=W({queryKey:["photo-jobs",s==null?void 0:s.id],enabled:!!s,queryFn:async()=>{const{data:a,error:r}=await y.from("photo_jobs").select("*").order("created_at",{ascending:!1});if(r)throw r;return a??[]}}),m=u.useCallback(async()=>{if(!i.data)return;const a=i.data.filter(r=>r.status==="processing");a.length!==0&&(await Promise.allSettled(a.map(r=>y.functions.invoke("poll-photo-job",{body:{photoJobId:r.id}}))),l.invalidateQueries({queryKey:["photo-jobs"]}),l.invalidateQueries({queryKey:["credits"]}))},[i.data,l]);u.useEffect(()=>{var r;if((r=i.data)==null?void 0:r.some(d=>d.status==="processing"||d.status==="pending"))return c.current=setInterval(m,8e3),()=>{c.current&&clearInterval(c.current)};c.current&&clearInterval(c.current)},[i.data,m]);const h=L({mutationFn:async({characterId:a,preset:r,prompt:d,customInstructions:g,style:o,size:x})=>{if(!s)throw new Error("Not authenticated");const{data:p,error:b}=await y.from("photo_jobs").insert({user_id:s.id,character_id:a,preset:r,prompt:d,custom_instructions:g||null,style:o,size:x,status:"pending",credits_used:25}).select().single();if(b)throw b;const{error:v}=await y.functions.invoke("generate-photo",{body:{photoJobId:p.id}});if(v)throw v;return p},onSuccess:()=>{l.invalidateQueries({queryKey:["photo-jobs"]}),l.invalidateQueries({queryKey:["credits"]}),w({title:"Photo generation started",description:"This usually takes 30-60 seconds."})},onError:a=>{w({title:"Error",description:a.message,variant:"destructive"})}}),n=L({mutationFn:async a=>{if(!s)throw new Error("Not authenticated");const{error:r}=await y.from("photo_jobs").delete().eq("id",a);if(r)throw r},onSuccess:()=>{l.invalidateQueries({queryKey:["photo-jobs"]}),w({title:"Photo deleted"})},onError:a=>{w({title:"Error",description:a.message,variant:"destructive"})}});return{photoJobs:i.data??[],isLoading:i.isLoading,refetch:i.refetch,createPhotoJob:h,deletePhotoJob:n}}const j=[{id:"profile_picture",label:"Profile Picture",prompt:"Professional headshot portrait, clean background, warm lighting, confident expression, business casual outfit, high resolution",style:"Realistic",size:"1536*1536",emoji:"ð¤"},{id:"passport_photo",label:"Passport Photo",prompt:"Official passport photo, plain white background, neutral expression, front-facing, evenly lit, formal attire, no shadows on face",style:"Realistic",size:"1536*1536",emoji:"ðªª"},{id:"street_action",label:"Street Action",prompt:"Dynamic street photography, walking confidently through a busy city, natural sunlight, motion blur in background, streetwear outfit, cinematic vibe",style:"Crossing the street",size:"1152*2048",emoji:"ð"},{id:"fashion_editorial",label:"Fashion Editorial",prompt:"High-fashion editorial photoshoot, dramatic lighting, bold pose, designer outfit, studio setting, Vogue magazine quality",style:"FashionShow",size:"1152*2048",emoji:"â¨"},{id:"outdoor_adventure",label:"Outdoor Adventure",prompt:"Adventurous outdoor photo, hiking mountains at golden hour, athletic outfit, windswept hair, epic landscape in background, natural lighting",style:"Realistic",size:"2048*1152",emoji:"ðï¸"},{id:"night_vibe",label:"Night Vibe",prompt:"Nighttime urban portrait, neon lights reflecting, moody atmosphere, stylish dark outfit, cinematic color grading, shallow depth of field",style:"Night rider",size:"1152*2048",emoji:"ð"},{id:"y2k_retro",label:"Y2K Retro",prompt:"Y2K aesthetic photo, retro fashion, digital camera flash, low resolution vintage feel, colorful and playful, nostalgic vibes",style:"Y2K",size:"1536*1536",emoji:"ð¸"},{id:"custom",label:"Custom",prompt:"",style:"Realistic",size:"1152*2048",emoji:"ð¨"}],re=["Realistic","DigitalCam","Creatures","Medieval","Spotlight","Subway","Library","Grillz Selfie","Angel Wings","Quiet luxury","FashionShow","90s Grain","Sunset beach","Street view","Y2K","Grunge","Movie","Foggy Morning","Night rider","Crossing the street","0.5 Selfie"],oe=[{value:"1536*1536",label:"Square (1:1)"},{value:"1152*2048",label:"Portrait (9:16)"},{value:"2048*1152",label:"Landscape (16:9)"},{value:"1536*2048",label:"Tall (3:4)"},{value:"2048*1536",label:"Wide (4:3)"}];function ie({open:s,onOpenChange:l,onSubmit:c}){const{data:i,isLoading:m}=te(),[h,n]=u.useState(""),[a,r]=u.useState(j[0].id),[d,g]=u.useState(""),[o,x]=u.useState(""),[p,b]=u.useState("Realistic"),[v,P]=u.useState("1152*2048"),[_,z]=u.useState(!1),S=j.find(t=>
1t.id===a),k=a==="custom",T=t=>{r(t);const f=j.find(G=>G.id===t);f&&t!=="custom"&&(b(f.style),P(f.size))},F=async()=>{if(!h)return;const t=k?d:(S==null?void 0:S.prompt)||"";if(t.trim()){z(!0);try{await c({characterId:h,preset:a,prompt:t,customInstructions:o.trim()||void 0,style:p,size:v}),l(!1),r(j[0].id),g(""),x(""),n("")}catch{}finally{z(!1)}}},E=(i??[]).filter(t=>t.reference_image_url||t.profile_image_url).sort((t,f)=>t.is_favorite&&!f.is_favorite?-1:!t.is_favorite&&f.is_favorite?1:0);return e.jsx(Z,{open:s,onOpenChange:l,children:e.jsxs($,{className:"max-w-lg max-h-[90vh] overflow-y-auto",style:{background:"var(--bg2)",border:"1px solid var(--brd)"},children:[e.jsx(X,{children:e.jsx(ee,{className:"text-lg font-bold",children:"Generate AI Photo"})}),e.jsxs("div",{className:"space-y-5 mt-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium mb-1.5 block",style:{color:"var(--tx2)"},children:"Character"}),m?e.jsxs("div",{className:"flex items-center gap-2 text-sm",style:{color:"var(--tx3)"},children:[e.jsx(N,{size:14,className:"animate-spin"})," Loading..."]}):E.length===0?e.jsx("p",{className:"text-sm",style:{color:"var(--tx3)"},children:"No characters with photos found. Create a character with a reference photo first."}):e.jsx("div",{className:"grid grid-cols-4 gap-2",children:E.map(t=>e.jsxs("button",{onClick:()=>n(t.id),className:"flex flex-col items-center gap-1 p-2 rounded-lg border transition-all cursor-pointer bg-transparent",style:{borderColor:h===t.id?"var(--purple)":"var(--brd)",background:h===t.id?"var(--glow-p)":"transparent"},children:[e.jsx("img",{src:t.profile_image_url||t.reference_image_url||"",alt:t.name,className:"w-12 h-12 rounded-full object-cover"}),e.jsxs("span",{className:"text-[10px] font-medium truncate w-full text-center",style:{color:"var(--tx2)"},children:[t.is_favorite?"â
":"",t.name]})]},t.id))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium mb-1.5 block",style:{color:"var(--tx2)"},children:"Preset"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:j.map(t=>e.jsxs("button",{onClick:()=>T(t.id),className:"flex items-center gap-2 p-2.5 rounded-lg border transition-all text-left cursor-pointer bg-transparent",style:{borderColor:a===t.id?"var(--purple)":"var(--brd)",background:a===t.id?"var(--glow-p)":"transparent"},children:[e.jsx("span",{className:"text-lg",children:t.emoji}),e.jsx("span",{className:"text-xs font-medium",style:{color:a===t.id?"var(--tx)":"var(--tx2)"},children:t.label})]},t.id))})]}),k&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium mb-1.5 block",style:{color:"var(--tx2)"},children:"Describe the photo you want"}),e.jsx(R,{value:d,onChange:t=>g(t.target.value),placeholder:"e.g. Studio portrait with dramatic rim lighting, wearing a leather jacket...",className:"text-sm",rows:3,style:{background:"var(--bg3)",borderColor:"var(--brd)"}})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-xs font-medium mb-1.5 block",style:{color:"var(--tx2)"},children:["Custom Instructions ",e.jsx("span",{style:{color:"var(--tx3)"},children:"(optional)"})]}),e.jsx(R,{value:o,onChange:t=>x(t.target.value),placeholder:"e.g. Make them smile, add sunglasses, change hair to blonde...",className:"text-sm",rows:2,style:{background:"var(--bg3)",borderColor:"var(--brd)"}})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium mb-1.5 block",style:{color:"var(--tx2)"},children:"Style"}),e.jsxs(D,{value:p,onValueChange:b,children:[e.jsx(A,{style:{background:"var(--bg3)",borderColor:"var(--brd)"},children:e.jsx(q,{})}),e.jsx(J,{children:re.map(t=>e.jsx(K,{value:t,children:t},t))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium mb-1.5 block",style:{color:"var(--tx2)"},children:"Aspect Ratio"}),e.jsxs(D,{value:v,onValueChange:P,children:[e.jsx(A,{style:{background:"var(--bg3)",borderColor:"var(--brd)"},children:e.jsx(q,{})}),e.jsx(J,{children:oe.map(t=>e.jsx(K,{value:t.value,children:t.label},t.value))})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsxs("span",{className:"text-xs",style:{color:"var(--tx3)"},children:["Cost: ",e.jsx("span",{className:"font-bold",style:{color:"var(--purple-l)"},children:"25 credits"})]}),e.jsxs(C,{onClick:F,disabled:!h||_||k&&!d.trim(),className:"gap-2",style:{background:"var(--purple)",color:"#fff"},children:[_?e.jsx(N,{size:16,className:"animate-spin"}):e.jsx(Q,{size:16}),"Generate Photo"]})]})]})]})})}const ye=()=>{const{photoJobs:s,isLoading:l,refetch:c,createPhotoJob:i,deletePhotoJob:m}=ae(),[h,n]=u.useState(!1),[a,r]=u.useState(null),d=async o=>{await i.mutateAsync(o)},g=async o=>{r(o);try{await m.mutateAsync(o)}catch{}finally{r(null)}};return e.jsxs(e.Fragment,{children:[e.jsx(se,{title:"AI Photos",subtitle:"Generate stunning photos of your characters using Higgsfield Soul.",stats:[{label:"Total",value:s.length,icon:I,color:"var(--purple-l)"},{label:"Completed",value:s.filter(o=>o.status==="complete").length,icon:M,color:"var(--green)"},{label:"Processing",value:s.filter(o=>["pending","processing"].includes(o.status)).length,icon:O,color:"var(--cyan)"}],ctaLabel:"New Photo",onCtaClick:()=>n(!0),onRefresh:()=>c(),isLoading:l,emptyIcon:I,emptyTitle:"No AI photos yet",emptySubtitle:'Click "New Photo" to generate your first one.',isEmpty:s.length===0,children:s.map(o=>e.jsx(le,{job:o,onDelete:()=>g(o.id),isDeleting:a===o.id},o.id))}),e.jsx(ie,{open:h,onOpenChange:n,onSubmit:d})]})};function le({job:s,onDelete:l,isDeleting:c}){var r;const i=["pending","processing"].includes(s.status),m=s.status==="complete",h=s.status==="error",n=(r=s.output_image_urls)==null?void 0:r[0],a=async d=>{if(d.stopPropagation(),!!n)try{const o=await(await fetch(n)).blob(),x=URL.createObjectURL(o),p=document.createElement("a");p.href=x,p.download=`ai-photo-${s.id.slice(0,8)}.png`,p.click(),URL.revokeObjectURL(x)}catch{w({title:"Download failed",variant:"destructive"})}};return e.jsxs("div",{className:"flex items-center gap-3 px-3 sm:px-4 py-3 rounded-xl",style:{background:"var(--bg2)",border:"1px solid var(--brd)"},children:[e.jsx("div",{className:"shrink-0 w-10 h-10 rounded-lg overflow-hidden flex items-center justify-center",style:{background:"var(--bg3)"},children:m&&n?e.jsx("img",{src:n,alt:"",className:"w-full h-full object-cover"}
1):i?e.jsx(N,{size:14,className:"animate-spin",style:{color:"var(--purple-l)"}}):e.jsx(U,{size:14,style:{color:"var(--error, #ef4444)"}})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate capitalize",children:s.preset.replace(/_/g," ")}),e.jsx("p",{className:"text-xs truncate mt-0.5",style:{color:"var(--tx2)"},children:h?s.error_message||"Generation failed":i?"Generatingâ¦":s.style})]}),e.jsx("span",{className:"shrink-0 text-[11px] hidden sm:block",style:{color:"var(--tx3)"},children:new Date(s.created_at).toLocaleDateString()}),e.jsxs("div",{className:"shrink-0 flex items-center gap-1",children:[m&&n&&e.jsx(C,{variant:"ghost",size:"icon",className:"h-7 w-7",style:{color:"var(--tx2)"},onClick:a,children:e.jsx(V,{size:14})}),e.jsx(C,{variant:"ghost",size:"icon",className:"h-7 w-7 text-red-400/60 hover:text-red-400 hover:bg-red-400/10",onClick:l,disabled:c,children:c?e.jsx(N,{size:14,className:"animate-spin"}):e.jsx(Y,{size:14})})]})]})}export{ye 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.