1import{c as H,r as n,u as q,b as f,j as t}from"./vendor-query-DDCPTvxb.js";import{A as Q,a as K,b as O,c as _,d as Y,e as X,f as J,g as Z,h as ee}from"./alert-dialog-C_3qlhMp.js";import{D as te,a as ae,b as ie,c as se,d as ne}from"./dialog-BF98E8xV.js";import{T as re}from"./textarea-CWXnNIo1.js";import{i as v}from"./index-DtwcHb1v.js";import{A as oe}from"./app-header-vP0HKDHF.js";import{A as le,P as de,H as ce,a as pe,E as ge}from"./app-page-ChyFx8zM.js";import"./vendor-ui-CRa-3O-M.js";import"./AppRoutes-C5NoxxgN.js";import"./loader-circle-C3vmmYU2.js";const I=20;function Ae(){const m=H(),[R,S]=n.useState(new Set),T=e=>{S(a=>{if(a.has(e))return a;const i=new Set(a);return i.add(e),i})},A=e=>{S(a=>{if(!a.has(e))return a;const i=new Set(a);return i.delete(e),i})},[w,z]=n.useState(new Set),$=e=>{z(a=>{if(a.has(e))return a;const i=new Set(a);return i.add(e),i})},G=e=>{!w.has(e.id)&&!!e.enhancedImageUrl&&e.enhancedImageUrl!==e.imageUrl?$(e.id):T(e.id)},F=n.useRef({}),[c,U]=n.useState(new Set),k=(e,a)=>{U(i=>{if(a===i.has(e))return i;const s=new Set(i);return a?s.add(e):s.delete(e),s})},{data:y,isLoading:W}=q({queryKey:["/api/avatars/saved"]}),p=f({mutationFn:async e=>{await v("DELETE",`/api/avatars/${e}`)},onSuccess:()=>{m.invalidateQueries({queryKey:["/api/avatars/saved"]})},onError:e=>{alert(e.message||"Failed to delete avatar. Please try again.")}}),M=f({mutationFn:async({avatarId:e,file:a})=>{const i=new FormData;i.append("image",a);const s=await fetch(`/api/avatars/${e}/replace-image`,{method:"POST",body:i,credentials:"include"});if(!s.ok){const V=await s.json().catch(()=>({}));throw new Error(V.message||"Failed to replace image")}return s.json()},onMutate:({avatarId:e})=>{k(e,!0)},onSuccess:(e,{avatarId:a})=>{A(a),m.invalidateQueries({queryKey:["/api/avatars/saved"]})},onError:e=>{alert((e==null?void 0:e.message)||"Failed to replace image. Please try again.")},onSettled:(e,a,{avatarId:i})=>{k(i,!1)}}),B=(e,a)=>{var s;const i=(s=a.target.files)==null?void 0:s[0];i&&!c.has(e)&&M.mutate({avatarId:e,file:i}),a.target.value=""},[o,E]=n.useState(null),[l,j]=n.useState(""),[C,u]=n.useState([]),[D,d]=n.useState(null),[P,x]=n.useState(null),L=e=>{E(e),j(""),u([]),d(null),x(null)},N=()=>{E(null),j(""),u([]),d(null),x(null)},r=f({mutationFn:async({avatarId:e,prompt:a})=>(await v("POST",`/api/avatars/${e}/remix`,{prompt:a})).json(),onSuccess:e=>
1{d(null),u(e.avatars||[]),m.invalidateQueries({queryKey:["/api/credits"]})},onError:e=>{d((e==null?void 0:e.message)||"Failed to generate variations. Please try again.")}}),g=f({mutationFn:async e=>(await v("POST",`/api/avatars/${e}/save`)).json(),onMutate:e=>{x(e)},onSuccess:()=>{m.invalidateQueries({queryKey:["/api/avatars/saved"]}),N()},onError:e=>{x(null),d((e==null?void 0:e.message)||"Failed to save the new avatar. Please try again.")}}),b=(y==null?void 0:y.avatars)||[],h=b.length>=I;return t.jsxs("div",{className:"mi-theme",style:{minHeight:"100vh"},children:[t.jsx(oe,{active:"avatars"}),t.jsxs(le,{children:[t.jsx(de,{kicker:"Library",title:"My Avatars",subtitle:"All your saved avatars and enhanced creations, ready to turn into scenes.",action:t.jsx(ce,{label:"Create Avatar",testId:"button-create-avatar",onClick:()=>window.location.href="/app"})}),W?t.jsx(pe,{label:"Loading your avatars..."}):b.length===0?t.jsx(ge,{icon:"ph-user-circle-plus",title:"No Saved Avatars Yet",body:"Generate and enhance avatars to see them appear in your collection.",actionLabel:"Generate Your First Avatar",testId:"button-generate-first-avatar",onAction:()=>window.location.href="/app"}):t.jsx("div",{className:"mi-collapse-4",style:{display:"grid",gridTemplateColumns:"repeat(4,1fr)",gap:22},children:b.map(e=>{const a=R.has(e.id);return t.jsxs("div",{className:"mi-card-glow",style:{background:"#FCFBF7",border:"1px solid #E6E1D6",borderRadius:18,overflow:"hidden"},children:[t.jsxs("div",{style:{position:"relative",aspectRatio:"1/1",background:"#E7E2D8",display:"flex",alignItems:"center",justifyContent:"center"},children:[t.jsx("img",{src:w.has(e.id)?e.imageUrl:e.enhancedImageUrl||e.imageUrl,alt:"Saved Avatar",style:{width:"100%",height:"100%",objectFit:"cover",opacity:a?0:1},onError:()=>G(e),onLoad:()=>A(e.id)}),a&&t.jsxs("div",{"data-testid":`status-unavailable-${e.id}`,style:{position:"absolute",inset:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",textAlign:"center",padding:16,background:"#E7E2D8"},children:[t.jsx("i",{className:"ph ph-camera",style:{fontSize:34,color:"#CFC9BC"}}),t.jsx("p",{style:{color:"#8A857A",fontSize:13,fontWeight:500,marginTop:10},children:"Image unavailable"}),t.jsx("p",{style:{color:"#A39D8F",fontSize:12,marginTop:2},children:"Please re-upload or regenerate this avatar"})]}),e.enhancedImageUrl&&!a&&t.jsxs("span",{className:"mi-mono",style:{position:"absolute",top:12,left:12,display:"inline-flex",alignItems:"center",gap:5,background:"#E4F3EC",color:"#1F7A4D",border:"1px solid #C9E7D6",fontSize:11,padding:"4px 9px",borderRadius:999},children:[t.jsx("i",{className:"ph-fill ph-heart"})," Enhanced"]}),t.jsxs(Q,{children:[t.jsx(K,{asChild:!0,children:t.jsx("button",{className:"mi-del","data-testid":`button-delete-${e.id}`,disabled:p.isPending,style:{position:"absolute",top:12,right:12,width:32,height:32,borderRadius:9,background:"#fff",border:"1px solid #E6E1D6",color:"#8A857A",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"all .15s"},children:t.jsx("i",{className:p.isPending?"ph ph-circle-notch":"ph ph-trash",style:{fontSize:15}})})}),t.jsxs(O,{className:"mi-pop",children:[t.jsxs(_,{children:[t.jsx(Y,{children:"Delete Avatar"}),t.jsx(X,{children:"Are you sure you want to delete this avatar? This action cannot be undone."})]}),t.jsxs(J,{children:[t.jsx(Z,{children:"Cancel"}),t.jsx(ee,{onClick:()=>p.mutate(e.id),className:"bg-red-600 hover:bg-red-700",disabled:p.isPending,children:p.isPending?"Deleting...":"Delete"})]})]})]})]}),t.jsxs("div",{style:{padding:16},children:[t.jsx("div",{className:"mi-mono",style:{fontSize:11,letterSpacing:"0.1em",textTransform:"uppercase",color:"#A39D8F"},children:"Avatar"}),t.jsx("div",{style:{fontWeight:600,fontSize:14,marginTop:6,color:"#1C1A16",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:e.prompt}),a?t.jsxs(t.Fragment,{children:[t.jsx("input",{type:"file",accept:"image/*",style:{display:"none"},ref:i=>{F.current[e.id]=i},onChange:i=>B(e.id,i),"data-testid":`input-replace-${e.id}`}),t.jsx("button",{onClick:()=>{var i;return(i=F.current[e.id])==null?void 0:i.click()},disabled:c.has(e.id),"data-testid":`button-replace-${e.id}`,className:"mi-btn-primary",style:{marginTop:14,width:"100%",display:"flex",alignItems:"center",justifyContent:"center",gap:8,fontFamily:"'Space Grotesk', sans-serif",fontWeight:600,fontSize:14,padding:10,borderRadius:11,cursor:c.has(e.id)?"not-allowed":"pointer",opacity:c.has(e.id)?.7:1},children:c.has(e.id)?t.jsxs(t.Fragment,{children:[t.jsx("i",{className:"ph ph-circle-notch"})," Uploading..."]}):t.jsxs(t.Fragment,{children:[t.jsx("i",{className:"ph ph-image"})," Replace Photo"]})})]}):t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:()=>window.location.href=`/app?avatar=${e.id}&step=scene`,"data-testid":`button-create-scene-${e.id}`,className:"mi-btn-primary",style:{marginTop:14,width:"100%",display:"flex",alignItems:"center",justifyContent:"center",gap:8,fontFamily:"'Space Grotesk', sans-serif",fontWeight:600,fontSize:14,padding:10,borderRadius:11,cursor:"pointer"}
1,children:[t.jsx("i",{className:"ph ph-video-camera"})," Create A New Scene"]}),t.jsxs("button",{onClick:()=>L(e),"data-testid":`button-edit-${e.id}`,style:{marginTop:8,width:"100%",display:"flex",alignItems:"center",justifyContent:"center",gap:8,fontFamily:"'Space Grotesk', sans-serif",fontWeight:600,fontSize:14,padding:10,borderRadius:11,cursor:"pointer",background:"#fff",border:"1px solid #E6E1D6",color:"#1C1A16"},children:[t.jsx("i",{className:"ph ph-magic-wand"})," Edit / Make a Variation"]})]})]})]},e.id)})}),t.jsx(te,{open:!!o,onOpenChange:e=>{!e&&!r.isPending&&N()},children:t.jsxs(ae,{className:"mi-pop",style:{maxWidth:560,maxHeight:"85vh",overflowY:"auto"},children:[t.jsxs(ie,{children:[t.jsx(se,{children:"Edit Avatar"}),t.jsx(ne,{children:"Describe the change you want. We'll use your saved avatar as the reference and generate variations â your original avatar stays untouched. Costs 50 credits."})]}),o&&t.jsxs("div",{style:{display:"flex",gap:14,alignItems:"flex-start"},children:[t.jsx("img",{src:o.enhancedImageUrl||o.imageUrl,alt:"Avatar to edit",style:{width:88,height:88,objectFit:"cover",borderRadius:12,border:"1px solid #E6E1D6",flexShrink:0}}),t.jsx("div",{style:{flex:1},children:t.jsx(re,{value:l,onChange:e=>j(e.target.value),placeholder:"e.g. Change the hair to shoulder-length blonde, add a leather jacketâ¦",rows:4,disabled:r.isPending,"data-testid":"input-edit-prompt"})})]}),D&&t.jsx("p",{"data-testid":"text-remix-error",style:{color:"#B42318",fontSize:13},children:D}),C.length===0?t.jsxs(t.Fragment,{children:[h&&t.jsxs("div",{"data-testid":"text-avatar-limit-warning",style:{background:"#FEF3F2",border:"1px solid #FECDCA",borderRadius:10,padding:"10px 12px",display:"flex",alignItems:"flex-start",gap:8},children:[t.jsx("i",{className:"ph ph-warning-circle",style:{color:"#B42318",fontSize:16,marginTop:1,flexShrink:0}}),t.jsxs("p",{style:{color:"#B42318",fontSize:13,margin:0},children:["You've reached the maximum of ",I," saved avatars, so a new variation couldn't be saved. Delete an avatar first â then come back to generate variations (this avoids spending 50 credits on variations you can't keep)."]})]}),t.jsx("button",{onClick:()=>!h&&o&&l.trim()&&r.mutate({avatarId:o.id,prompt:l.trim()}),disabled:h||r.isPending||!l.trim(),"data-testid":"button-generate-variations",className:"mi-btn-primary",style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",gap:8,fontFamily:"'Space Grotesk', sans-serif",fontWeight:600,fontSize:14,padding:11,borderRadius:11,cursor:h||r.isPending||!l.trim()?"not-allowed":"pointer",opacity:h||r.isPending||!l.trim()?.7:1},children:r.isPending?t.jsxs(t.Fragment,{children:[t.jsx("i",{className:"ph ph-circle-notch"})," Generating variations⦠(may take a minute)"]}):t.jsxs(t.Fragment,{children:[t.jsx("i",{className:"ph ph-magic-wand"})," Generate Variations (50 credits)"]})})]}):t.jsxs(t.Fragment,{children:[t.jsx("p",{style:{fontSize:13,color:"#5F5A50",fontWeight:600},children:"Pick the one you want to keep â it will be saved as a new avatar:"}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(2,1fr)",gap:12},children:C.map(e=>t.jsxs("div",{style:{border:"1px solid #E6E1D6",borderRadius:12,overflow:"hidden",background:"#FCFBF7"},children:[t.jsx("img",{src:e.imageUrl,alt:"Variation",style:{width:"100%",aspectRatio:"1/1",objectFit:"cover",display:"block"}}),t.jsx("button",{onClick:()=>g.mutate(e.id),disabled:g.isPending,"data-testid":`button-save-variation-${e.id}`,className:"mi-btn-primary",style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",gap:6,fontFamily:"'Space Grotesk', sans-serif",fontWeight:600,fontSize:13,padding:9,cursor:g.isPending?"not-allowed":"pointer",opacity:g.isPending&&P!==e.id?.6:1},children:P===e.id?t.jsxs(t.Fragment,{children:[t.jsx("i",{className:"ph ph-circle-notch"})," Savingâ¦"]}):t.jsxs(t.Fragment,{children:[t.jsx("i",{className:"ph ph-check"})," Save as New Avatar"]})})]},e.id))}),t.jsx("button",{onClick:()=>{u([]),d(null)},disabled:g.isPending,"data-testid":"button-try-again",style:{width:"100%",background:"#fff",border:"1px solid #E6E1D6",color:"#5F5A50",fontFamily:"'Space Grotesk', sans-serif",fontWeight:600,fontSize:13,padding:9,borderRadius:10,cursor:"pointer"},children:"Try a different description"})]})]})})]})]})}export{Ae 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.