1import{r as n,j as e}from"./react-vendor-CHQL15iE.js";import{u as H,x as c,g as J,l as j,T as V}from"./main-Dck1T9BT.js";import{r as z}from"./assetUrl-D33wRw9g.js";import{am as Y,O as B,G as U,af as q,J as L,b as w,ac as Q}from"./lucide-BFLOpGdB.js";import"./pdfjs-ji3DqnKJ.js";import"./markdown-W-rE_H7s.js";import"./katex-math-BxKHCrdI.js";const re=({onSelect:T,onCancel:A,language:I})=>{const t=H(),[o,g]=n.useState([]),[l,p]=n.useState(c[0].url),[y,x]=n.useState(c[0].name),[f,N]=n.useState(!1),[D,$]=n.useState(!0),[m,b]=n.useState(""),[E,h]=n.useState(!1),[u,v]=n.useState(null),i=V[I],{showAlert:R,showConfirm:F}=J(),P=t?{paddingTop:"max(0px, env(safe-area-inset-top))",paddingRight:"max(0px, env(safe-area-inset-right))",paddingBottom:"max(0px, env(safe-area-inset-bottom))",paddingLeft:"max(0px, env(safe-area-inset-left))"}:void 0,M=t?{paddingTop:"max(0.5rem, env(safe-area-inset-top))",paddingRight:"max(0.5rem, env(safe-area-inset-right))",paddingBottom:"max(0.5rem, env(safe-area-inset-bottom))",paddingLeft:"max(0.5rem, env(safe-area-inset-left))"}:void 0;n.useEffect(()=>{O()},[]);const O=async()=>{const a=localStorage.getItem("p2g_token");if(!a){$(!1);return}try{const s=await j("/api/user/backgrounds",{headers:{Authorization:`Bearer ${a}`}});if(s.ok){const r=await s.json();g(r)}}catch(s){console.error("Failed to fetch backgrounds",s)}finally{$(!1)}},_=a=>{var r;const s=(r=a.target.files)==null?void 0:r[0];s&&(v(s),b(s.name.split(".")[0]),h(!0))},G=async()=>{if(!u||!m)return;const a=localStorage.getItem("p2g_token");if(!a)return;N(!0);const s=new FormData;s.append("image",u),s.append("name",m);try{const r=await j("/api/user/backgrounds",{method:"POST",headers:{Authorization:`Bearer ${a}`},body:s});if(r.ok){const d=await r.json();g([d,...o]),p(d.url),x(d.name||"Custom"),h(!1),v(null),b("")}}catch(r){console.error("Upload failed",r),await R("Upload failed",{variant:"error"})}finally{N(!1)}},K=async(a,s)=>{var S;if(s.stopPropagation(),!await F(i.deleteBgConfirm,{variant:"warning",confirmText:i.delete,cancelText:i.cancel}))return;const d=localStorage.getItem("p2g_token");try{(await j(`/api/user/backgrounds/${a}`,{method:"DELETE",headers:{Authorization:`Bearer ${d}`}})).ok&&(g(o.filter(k=>k.id!==a)),l===((S=o.find(k=>k.id===a))==null?void 0:S.url)&&(p(c[0].url),x(c[0].name)))}catch(C){console.error("Delete failed",C)}};return e.jsxs("div",{className:`fixed inset-0 z-[100] flex flex-col bg-[#fff0f5] animate-fade-in font-sans box-border ${t?"overflow-y-auto overscroll-y-contain":"overflow-hidden"}`,style:P,children:[e.jsx("div",{className:"absolute inset-0 opacity-[0.03] pointer-events-none",style:{backgroundImage:"linear-gradient(45deg, #f472b6 25%, transparent 25%, transparent 50%, #f472b6 50%, #f472b6 75%, transparent 75%, transparent)",backgroundSize:"100px 100px"}}),e.jsx("div",{className:"absolute top-[-20%] right-[-10%] w-[60%] h-[60%] rounded-full border-[40px] border-white/40 animate-spin-slow pointer-events-none"}),e.jsxs("header",{className:"relative z-20 px-4 py-4 md:px-12 md:py-8 flex flex-col md:flex-row md:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 md:gap-6 min-w-0",children:[e.jsx("button",{onClick:A,className:"p-2 md:p-3 bg-white/80 backdrop-blur-md rounded-xl text-slate-400 hover:text-pink-500 hover:shadow-lg transition-all border border-white group shrink-0",children:e.jsx(Y,{size:24,className:"group-hover:-translate-x-1 transition-transform"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h1",{className:"text-2xl md:text-4xl font-black text-slate-800 tracking-tighter flex items-center gap-2 md:gap-3 italic leading-tight truncate",children:[e.jsx(B,{className:"text-pink-500 shrink-0",size:28}),e.jsx("span",{className:"truncate",children:i.customBgTitle})]}),e.jsx("p",{className:"text-slate-400 font-bold uppercase tracking-[0.2em] text-[8px] md:text-[10px] mt-0.5 ml-0.5 opacity-70",children:"Environment / èæ¯éæ©"})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-4 bg-white/50 backdrop-blur-md p-1.5 rounded-2xl border border-white/50 shadow-sm self-start md:self-auto",children:[e.jsxs("label",{className:"flex items-center gap-2 px-4 py-2 bg-gradient-to-r from-pink-500 to-rose-600 text-white rounded-xl font-black text-xs hover:scale-105 active:scale-95 transition-all shadow-md group cursor-pointer",children:[e.jsx(U,{size:14,className:"group-hover:-translate-y-0.5 transition-transform"}),e.jsx("span",{children:i.uploadBg}),e.jsx("input",{type:"file",className:"hidden",accept:"image/*",onChange:_,disabled:f})]}),e.jsx("div",{className:"h-8 w-px bg-slate-200 hidden sm:block"}),e.jsxs("div",{className:"px-4 py-1",children:[e.jsx("p",{className:"text-[9px] font-black text-slate-400 uppercase tracking-widest mb-0.5",children:"Selected"}),e.jsx("p",{className:"text-sm font-black text-slate-700 leading-none truncate max-w-[120px]",children:y})]}),e.jsxs("button",{onClick:()=>{const a=c.find(r=>r.url===l),s=o.find(r=>r.url===l);T(l,y,a?{kind:"preset",id:a.id}:s?{kind:"custom",id:s.id}:void 0)},className:"px-6 py-2 bg-slate-800 text-white rounded-xl font-black text-xs hover:bg-slate-900 transition-all flex items-center gap-2",children:[i.chooseBg," ",e.jsx(q,{size:14})]})]})]}),e.jsx("main",{className:`relative z-10 px-4 pb-8 md:px-12 md:pb-16 custom-scrollbar ${t?"":"flex-1 min-h-0 overflow-y-auto"}`,children:D?e.jsxs("div",{className:`${t?"min-h-[45vh]":"h-full"} flex flex-col items-center justify-center gap-6`,children:[e.jsx(L,{className:"animate-spin text-pink-400",size:64}),e.jsx("p",{className:"text-slate-400 font-black text-xl animate-pulse tracking-tighter italic",children:"Loading Landscapes..."})]}):e.jsxs("div",{className:`${t?"space-y-6":"space-y-12"}`,children:[e.jsxs("section",{children:[e.jsxs("h3",{className:`${t?"text-[10px] mb-3 tracking-[0.15em]":"text-xs mb-6 tracking-[0.2em]"} font-black text-slate-400 uppercase flex items-center gap-2`,children:[e.jsx("span",{className:`${t?"w-6":"w-8"} h-1 bg-pink-100 rounded-full`}),i.defaultBgs]}),e.jsx("div",{className:`${t?"grid grid-cols-3 gap-2":"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 2xl:grid-cols-5 ga
1p-6"}`,children:c.map(a=>e.jsx("div",{onClick:()=>{p(a.url),x(a.name)},className:`group relative bg-white shadow-lg transition-all duration-300 overflow-hidden cursor-pointer ${t?"rounded-[12px] border-[2px] h-[170px]":"rounded-[24px] border-[4px] h-[240px]"} ${l===a.url?t?"border-pink-500 ring-2 ring-pink-100":"border-pink-500 ring-4 ring-pink-100 scale-95":"border-white hover:shadow-xl hover:-translate-y-1"}`,children:e.jsxs("div",{className:"h-full relative",children:[e.jsx("img",{src:z(a.url),className:"w-full h-full object-cover transition-transform duration-700 group-hover:scale-110",alt:a.name}),e.jsxs("div",{className:`absolute inset-0 bg-gradient-to-t from-black/70 via-black/10 to-transparent flex flex-col justify-end ${t?"p-2":"p-5"} transition-opacity ${l===a.url?"opacity-100":"opacity-0 group-hover:opacity-100"}`,children:[e.jsx("h4",{className:`text-white font-black italic tracking-tight ${t?"text-[11px] line-clamp-2 leading-tight":"text-lg"}`,children:a.name}),!t&&e.jsx("p",{className:"text-white/60 text-[10px] font-bold uppercase tracking-widest",children:"Default Setting"})]}),l===a.url&&e.jsx("div",{className:`absolute ${t?"top-2 right-2 p-1 rounded-lg":"top-4 right-4 p-1.5 rounded-xl"} bg-pink-500 text-white shadow-lg animate-bounce-in`,children:e.jsx(w,{size:t?14:20})})]})},a.id))})]}),e.jsxs("section",{children:[e.jsxs("h3",{className:`${t?"text-[10px] mb-3 tracking-[0.15em]":"text-xs mb-6 tracking-[0.2em]"} font-black text-slate-400 uppercase flex items-center gap-2`,children:[e.jsx("span",{className:`${t?"w-6":"w-8"} h-1 bg-pink-100 rounded-full`}),i.customBgs]}),o.length===0?e.jsxs("div",{className:`${t?"py-10 rounded-[20px] border-2 gap-2":"py-20 rounded-[40px] border-4 gap-4"} bg-white/40 backdrop-blur-sm border-dashed border-white flex flex-col items-center justify-center text-slate-300`,children:[e.jsx(B,{size:t?30:48,className:"opacity-20"}),e.jsx("p",{className:`font-bold italic ${t?"text-xs":""}`,children:i.noCustomBgs})]}):e.jsx("div",{className:`${t?"grid grid-cols-3 gap-2":"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 2xl:grid-cols-5 gap-6"}`,children:o.map(a=>e.jsx("div",{onClick:()=>{p(a.url),x(a.name||"Custom")},className:`group relative bg-white shadow-lg transition-all duration-300 overflow-hidden cursor-pointer ${t?"rounded-[12px] border-[2px] h-[170px]":"rounded-[24px] border-[4px] h-[240px]"} ${l===a.url?t?"border-pink-500 ring-2 ring-pink-100":"border-pink-500 ring-4 ring-pink-100 scale-95":"border-white hover:shadow-xl hover:-translate-y-1"}`,children:e.jsxs("div",{className:"h-full relative",children:[e.jsx("img",{src:z(a.url),className:"w-full h-full object-cover transition-transform duration-700 group-hover:scale-110",alt:a.name}),e.jsxs("div",{className:`absolute inset-0 bg-gradient-to-t from-black/70 via-black/10 to-transparent flex flex-col justify-end ${t?"p-2":"p-5"} transition-opacity ${l===a.url?"opacity-100":"opacity-0 group-hover:opacity-100"}`,children:[e.jsx("h4",{className:`text-white font-black italic tracking-tight truncate ${t?"text-[11px]":"text-lg"}`,children:a.name}),!t&&e.jsx("p",{className:"text-white/60 text-[10px] font-bold uppercase tracking-widest",children:"Shared Image"})]}),e.jsx("div",{className:`absolute ${t?"top-2 left-2":"top-4 left-4"} flex gap-2`,children:e.jsx("button",{onClick:s=>K(a.id,s),className:`${t?"p-1 rounded-lg opacity-100":"p-2 rounded-xl opacity-0 group-hover:opacity-100"} bg-red-500/80 text-white hover:bg-red-600 transition-all shadow-lg`,children:e.jsx(Q,{size:t?12:16})})}),l===a.url&&e.jsx("div",{className:`absolute ${t?"top-2 right-2 p-1 rounded-lg":"top-4 right-4 p-1.5 rounded-xl"} bg-pink-500 text-white shadow-lg animate-bounce-in`,children:e.jsx(w,{size:t?14:20})})]})},a.id))})]})]})}),E&&e.jsx("div",{className:`fixed inset-0 z-[110] overflow-y-auto overscroll-y-contain bg-slate-900/40 backdrop-blur-md animate-fade-in ${t?"p-3":"p-6"}`,style:M,onClick:()=>h(!1),children:e.jsx("div",{className:"min-h-full flex items-center justify-center py-2 sm:py-4",children:e.jsxs("div",{className:`bg-white shadow-2xl border-white ring-pink-100 max-w-md w-full min-h-0 max-h-[90dvh] animate-bounce-in flex flex-col overflow-y-auto overscroll-y-contain custom-scrollbar ${t?"rounded-[24px] border-[2px] ring-2 p-4":"rounded-[40px] border-[6px] ring-4 p-8 md:p-10"}`,onClick:a=>a.stopPropagation(),children:[e.jsx("div",{className:`${t?"w-12 h-12 mb-4":"w-16 h-16 mb-6"} bg-pink-50 text-pink-500 rounded-2xl flex items-center justify-center mx-auto
1shrink-0`,children:e.jsx(U,{size:t?26:32})}),e.jsx("h3",{className:`${t?"text-xl":"text-2xl"} font-black text-slate-800 mb-2 text-center tracking-tighter shrink-0`,children:"Naming Your View"}),e.jsx("p",{className:`text-slate-500 font-bold ${t?"mb-4 text-xs":"mb-8 text-sm"} text-center italic shrink-0`,children:"Give this location a name. This helps the AI set the atmosphere for your story."}),e.jsxs("div",{className:`space-y-4 ${t?"mb-4":"space-y-6 mb-8"}`,children:[e.jsx("div",{className:"aspect-[16/9] max-h-[min(38vh,240px)] sm:max-h-none rounded-2xl overflow-hidden border-2 border-slate-100 shadow-inner bg-slate-50 shrink-0",children:u&&e.jsx("img",{src:URL.createObjectURL(u),className:"w-full h-full object-cover max-h-[inherit]",alt:"Preview"})}),e.jsx("input",{type:"text",enterKeyHint:"done",autoComplete:"off",value:m,onChange:a=>b(a.target.value),placeholder:"e.g. Secret Lab, Sunset Beach...",className:`w-full bg-slate-50 border-2 border-slate-100 rounded-2xl font-bold text-slate-700 outline-none focus:border-pink-300 transition-all text-center tracking-wider shadow-inner ${t?"px-3 py-3 text-sm":"px-5 py-4 text-sm"}`})]}),e.jsxs("div",{className:`flex ${t?"flex-col-reverse gap-2.5":"flex-row gap-4"} shrink-0 mt-auto pt-1`,children:[e.jsx("button",{onClick:()=>{h(!1),v(null)},className:`${t?"w-full py-3.5":"flex-1 py-4"} bg-slate-100 hover:bg-slate-200 text-slate-500 rounded-2xl font-black transition-all`,children:i.cancel}),e.jsxs("button",{onClick:G,disabled:f||!m.trim(),className:`${t?"w-full py-3.5":"flex-1 py-4"} bg-gradient-to-r from-pink-500 to-rose-600 text-white rounded-2xl font-black shadow-lg shadow-pink-100 transition-all hover:-translate-y-1 active:scale-95 disabled:opacity-50 disabled:pointer-events-none flex items-center justify-center gap-2`,children:[f?e.jsx(L,{size:18,className:"animate-spin"}):e.jsx(w,{size:18}),"Upload"]})]})]})})})]})};export{re 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.