1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5893],{4486:(e,t,a)=>{a.r(t),a.d(t,{MusicGenerator:()=>_});var r=a(72590),s=a(79998),i=a(57200),n=a(92853),l=a(98566),o=a(33477),d=a(42569),c=a(36331),m=a(77117),u=a(57795),h=a(94797),g=a(86247),p=a(33710),f=a(24892),x=a(87585),v=a(83847),b=a(96534),w=a(36476),y=a(254),j=a(53828),N=a(32679),k=a(55930),C=a(81766),S=a(81496),R=a(57006),T=a(83461);function _(e){var t;let{className:a,srOnlyTitle:_}=e,E=(0,g.c3)("ai.music"),{user:U,isCheckSign:A,setIsShowSignModal:F,fetchUserCredits:P}=(0,R.U)(),[I,L]=(0,s.useState)("kie"),[z,D]=(0,s.useState)("V5"),[O,G]=(0,s.useState)(!1),[M,V]=(0,s.useState)(""),[$,B]=(0,s.useState)(""),[J,q]=(0,s.useState)(!1),[W,Z]=(0,s.useState)(""),[H,X]=(0,s.useState)(""),[K,Q]=(0,s.useState)(!1),[Y,ee]=(0,s.useState)(null),[et,ea]=(0,s.useState)(0),[er,es]=(0,s.useState)([]),[ei,en]=(0,s.useState)(null),[el,eo]=(0,s.useState)(null),[ed,ec]=(0,s.useState)(!1),[em,eu]=(0,s.useState)(!1),eh=(0,s.useRef)(null),[eg,ep]=(0,s.useState)(!1);(0,s.useEffect)(()=>{ep(!0)},[]);let ef=async e=>{try{if(el&&Date.now()-el>18e4)return ea(0),Q(!1),eo(null),p.oR.error("Generate music timed out. Please try again."),!0;let t=await fetch("/api/ai/query",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({taskId:e})});if(!t.ok)throw Error("request failed with status: ".concat(t.status));let{code:a,message:r,data:s}=await t.json();if(0!==a)throw Error(r);let{status:i,taskInfo:n}=s;if(!i||!n)throw Error("Query task info failed");let{errorCode:l,errorMessage:o,songs:d}=JSON.parse(n);if(l||o)throw Error(o);if(i===x.i.PENDING)return ea(10),!1;if(i===x.i.PROCESSING){ea(20);let e=d.some(e=>e.imageUrl),t=d.some(e=>e.audioUrl);if(e)return ea(60),es(d),!1;return t&&(ea(85),es(d)),!1}if(i===x.i.FAILED)return ea(0),Q(!1),eo(null),p.oR.error("Generate music failed: "+o),P(),!0;if(i===x.i.SUCCESS)return es(d),ea(100),Q(!1),eo(null),!0;return ea(e=>Math.min(e+3,80)),!1}catch(e){return console.error("Error polling task:",e),Q(!1),ea(0),eo(null),p.oR.error("Create song failed: "+e.message),P(),!0}};(0,s.useEffect)(()=>{if(Y&&K){let e=setInterval(async()=>{await ef(Y)&&clearInterval(e)},1e4);return()=>clearInterval(e)}},[Y,K,el]);let ex=async()=>{if(!U)return void F(!0);if(!U.credits||U.credits.remainingCredits<10)return void p.oR.error("Insufficient credits");if(!I||!z)return void p.oR.error("Invalid provider or model");if(O){if(!M||!$)return void p.oR.error("Please enter title and style");if(!J&&!W)return void p.oR.error("Please enter lyrics")}else if(!H)return void p.oR.error("Please enter prompt");let e={mediaType:"music",provider:I,model:z};O?(e.options={customMode:!0,style:$,title:M,instrumental:J},J||(e.options.lyrics=W)):(e.prompt=H,e.options={customMode:!1,instrumental:J}),Q(!0),ea(10),es([]),en(null),eo(Date.now());try{let e=await fetch("/api/ai/generate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mediaType:"music",provider:I,model:z,prompt:H,options:{style:$,title:M,lyrics:W,customMode:O,instrumental:J}})});if(!e.ok)throw Error("request failed with status: ".concat(e.status));let{code:t,message:a,data:r}=await e.json();if(0!==t)throw Error(a||"Failed to generate music");let{id:s}=r;if(!s)throw Error("Failed to generate music");await P(),ee(s),ea(20)}catch(e){p.oR.error("Failed to generate music: "+e.message),Q(!1),ea(0),eo(null)}},ev=async e=>{if(null==e?void 0:e.audioUrl){eu(!0);try{if(eh.current&&!eh.current.paused&&eh.current.pause(),(null==ei?void 0:ei.id)===e.id&&ed){ec(!1),en(null),eu(!1);return}eh.current=new Audio(e.audioUrl),eh.current.addEventListener("ended",()=>{ec(!1),en(null)}),eh.current.addEventListener("error",e=>{console.error("Audio playback error:",e),eu(!1),ec(!1),en(null)}),await eh.current.play(),ec(!0),en(e),eu(!1)}catch(e){console.error("Failed to play audio:",e),eu(!1),ec(!1),en(null)}}},eb=async e=>{if(null==e?void 0:e.audioUrl)try{p.oR.info(E("generator.downloading"));let t=await fetch(e.audioUrl);if(!t.ok)throw Error("Failed to fetch audio file");let a=await t.blob(),r=URL.createObjectURL(a),s=document.createElement("a");s.href=r,s.download="".concat(e.title,".mp3"),document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(()=>URL.revokeObjectURL(r),100),p.oR.success(E("generator.download_success"))}catch(e){console.error("Failed to download audio:",e),p.oR.error(E("generator.download_failed"))}};return(0,r.jsxs)("section",{id:"create",className:(0,T.cn)("py-16 md:py-24",a),children:[_&&(0,r.jsx)("h2",{className:"sr-only",children:_}),(0,r.jsx)("div",{className:"container",children:(0,r.jsx)("div",{className:"mx-auto max-w-6xl",children:(0,r.jsxs)("div",{className:"grid grid-cols-1 gap-8 lg:grid-cols-2",children:[(0,r.jsxs)(w.Zp,{children:[(0,r.jsx)(w.aR,{children:(0,r.jsx)(w.ZB,{className:"flex items-center gap-2",children:E("generator.title")})}),(0,r.jsx)(w.Wu,{className:"space-y-6",children:(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(C.d,{checked:O,onCheckedChange:G}),(0,r.jsx)(j.J,{children:E("generator.form.custom_mode")})]}),(0,r.jsx)("div",{className:"flex-1"}),(0,r.jsxs)("div",{className:"flex items-center gap-4",children:[(0,r.jsx)(j.J,{children:E("generator.form.model")}),(0,r.jsxs)(k.l6,{value:z,onValueChange:D,children:[(0,r.jsx)(k.bq,{className:"w-32",children:(0,r.jsx)(k.yv,{})}),(0,r.jsxs)(k.gC,{children:[(0,r.jsx)(k.eb,{value:"V5",children:"Suno V5"}),(0,r.jsx)(k.eb,{value:"V4_5PLUS",children:"Suno V4.5+"}),(0,r.jsx)(k.eb,{value:"V4_5",children:"Suno V4.5"}),(0,r.jsx)(k.eb,{value:"V4",children:"Suno V4"}),(0,r.jsx)(k.eb,{value:"V3_5",children:"Suno V3.5"})]})]})]})]})}),(0,r.jsxs)(w.Wu,{className:"space-y-6",children:[O&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(j.J,{htmlFor:"title",children:E("generator.form.title")}),(0,r.jsx)(y.p,{id:"title",placeholder:E("generator.form.title_placeholder"),value:M,onChange:e=>V(e.target.value)})]}),O&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(j.J,{htmlFor:"style",children:E("generator.form.style")}),(0,r.jsx)(S.T,{id:"style",placeholder:E("generator.form.style_placeholder"),value:$,onChange:e=>B(e.target.value),className:"min-h-24"}),(0,r.jsxs)("div",{className:"text-muted-foreground text-right text-sm",children:[$.length,"/1000"]})]}),!O&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(j.J,{htmlFor:"prompt",children:E("generator.form.prompt")}),(0,r.jsx)(S.T,{id:"prompt",placeholder:E("generator.form.prompt_placeholder"),value:H,onChange:e=>X(e.target.value),className:"min-h-32",required:!0})]}),(0,r.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,r.jsx)(C.d,{id:"instrumental",checked:J,onCheckedChange:q}),(0,r.jsx)(j.J,{htmlFor:"instrumental",children:E("generator.form.instrumental")})]}),O&&!J&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(j.J,{htmlFor:"lyrics",children:E("generator.form.lyrics")}),(0,r.jsx)(S.T,{id:"lyrics",placeholder:E("generator.form.lyrics_placeholder"),value:W,onChange:e=>Z(e.target.value),className:"min-h-32"})]}),eg?A?(0,r.jsxs)(b.$,{className:"w-full",size:"lg",children:[(0,r.jsx)(n.A,{className:"size-4 animate-spin"})," ",E("generator.loading")]}):U?(0,r.jsx)(b.$,{onClick:ex,disabled:K,className:"w-full",size:"lg",children:K?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.A,{className:"mr-2 h-4 w-4 animate-spin"}),E("generator.generating")]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(i.A,{className:"mr-2 h-4 w-4"}),E("generator.generate")]})}):(0,r.jsxs)(b.$,{className:"w-full",size:"lg",onClick:()=>F(!0),children:[(0,r.jsx)(l.A,{className:"mr-2 h-4 w-4"})," ",E("generator.sign_in_to_generate")]}):(0,r.jsxs)(b.$,{className:"w-full",size:"lg",disabled:!0,children:[(0,r.jsx)(i.A,{className:"mr-2 h-4 w-4"}),E("generator.generate")]}),eg?U&&U.credits&&U.credits.remainingCredits>0?(0,r.jsxs)("div",{className:"mb-6 flex items-center justify-between text-sm",children:[(0,r.jsx)("span",{className:"text-primary",children:E("generator.credits_cost",{credits:10})}),(0,r.jsx)("span",{className:"text-foreground font-medium",children:E("generator.credits_remaining",{credits:U.credits.remainingCredits})})]}):(0,r.jsxs)("div",{className:"mb-6 flex items-center justify-between text-sm",children:[(0,r.jsxs)("span",{className:"text-primary",children:[E("generator.credits_cost",{credits:10}),","," ",E("generator.credits_remaining",{credits:(null==U||null==(t=U.credits)?void 0:t.remainingCredits)||0})]}),(0,r.jsx)(f.N_,{href:"/pricing",children:(0,r.jsxs)(b.$,{className:"w-full",size:"lg",variant:"outline",children:[(0,r.jsx)(o.A,{className:"size-4"})," ",E("generator.buy_credits")]})})]}):(0,r.jsxs)("div",{className:"mb-6 flex items-center justify-between text-sm",children:[(0,r.jsx)("span",{className:"text-primary",children:E("generator.credits_cost",{credits:10})}),(0,r.jsx)("span",{className:"text-foreground font-medium",children:E("generator.credits_remaining",{credits:0})})]}),K&&(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("div",{className:"flex justify-between text-sm",children:[(0,r.jsx)("span",{children:E("generator.generation_progress")}),(0,r.jsxs)("span",{children:[et,"%"]})]}),(0,r.jsx)(N.k,{value:et,className:"w-full"}),(0,r.jsx)("p",{className:"text-muted-foreground text-center text-sm",children:E("generator.time_cost")})]})]})]}),(0,r.jsxs)(w.Zp,{children:[(0,r.jsx)(w.aR,{children:(0,r.jsxs)(w.ZB,{className:"flex items-center gap-2",children:[(0,r.jsx)(i.A,{className:"h-5 w-5"}),E("generator.generated_song")]})}),(0,r.jsx)(w.Wu,{children:er.length>0?(0,r.jsx)("div",{className:"space-y-4",children:er.map((e,t)=>{let a=(null==ei?void 0:ei.id)===e.id&&ed,s=(null==ei?void 0:ei.id)===e.id&&em;return(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"flex gap-4",children:[(0,r.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,r.jsx)("div",{className:"bg-muted relative h-20 w-20 overflow-hidden rounded-lg",children:e.imageUrl?(0,r.jsx)("img",{src:e.imageUrl,alt:e.title,loading:"lazy",className:"h-full w-full object-cover"}):(0,r.jsx)("div",{className:"from-primary/20 to-accent/20 flex h-full w-full items-center justify-center bg-gradient-to-br",children:(0,r.jsx)(i.A,{className:"text-muted-foreground h-6 w-6"})})}),e.audioUrl&&(0,r.jsx)(b.$,{size:"sm",variant:"secondary",className:"absolute top-6 right-6 h-8 w-8 rounded-full p-0 shadow-lg",onClick:()=>ev(e),disabled:s,children:s?(0,r.jsx)(n.A,{className:"h-4 w-4 animate-spin"}):a?(0,r.jsx)(d.A,{className:"h-3 w-3"}):(0,r.jsx)(c.A,{className:"h-3 w-3"})})]}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsx)("h3",{className:"text-foreground mb-1 text-lg font-semibold",children:e.title}),(0,r.jsxs)("div",{className:"text-muted-foreground mb-2 flex items-center gap-2 text-sm",children:[(0,r.jsx)(l.A,{className:"h-4 w-4"}),(0,r.jsx)("span",{children:e.artist}),(0,r.jsx)(m.A,{className:"ml-2 h-4 w-4"}),(0,r.jsx)("span",{children:(e=>{let t=Math.floor(e/60),a=Math.floor(e%60);return"".concat(t,":").concat(a.toString().padStart(2,"0"))})(e.duration)})]}),(0,r.jsx)("div",{className:"mb-2 line-clamp-1 flex flex-wrap gap-1",children:e.style&&e.style.split(",").slice(0,2).map((e,t)=>(0,r.jsx)(v.E,{variant:"default",className:"text-xs",children:e.trim()},t))}),(0,r.jsx)("div",{className:"flex items-center gap-2 text-sm",children:e.audioUrl?(0,r.jsxs)("div",{className:"flex items-center gap-2 text-green-600",children:[(0,r.jsx)(u.A,{className:"h-4 w-4"}),(0,r.jsx)("span",{children:E("generator.ready_to_play")})]}):(0,r.jsxs)("div",{className:"flex items-center gap-2 text-yellow-600",children:[(0,r.jsx)(n.A,{className:"h-4 w-4 animate-spin"}),(0,r.jsx)("span",{children:E("generator.audio_generating")})]})})]}),(0,r.jsx)("div",{className:"flex flex-col gap-2",children:e.audioUrl&&(0,r.jsx)(b.$,{variant:"outline",size:"sm",onClick:()=>eb(e),children:(0,r.jsx)(h.A,{className:"h-4 w-4"})})})]}),t<er.length-1&&(0,r.jsx)("div",{className:"border-t"})]},e.id)})}):(0,r.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[(0,r.jsx)("div",{className:"bg-muted mb-4 flex h-16 w-16 items-center justify-center rounded-full",children:(0,r.jsx)(i.A,{className:"text-muted-foreground h-8 w-8"})}),(0,r.jsx)("p",{className:"text-muted-foreground mb-2",children:K?E("generator.generating_song"):E("generator.no_song_generated")})]})})]})]})})})]})}},29736:(e,t,a)=>{a.r(t),a.d(t,{ImageGenerator:()=>T});var r=a(72590),s=a(79998),i=a(92853),n=a(42126),l=a(98566),o=a(33477),d=a(20494),c=a(94797),m=a(86247),u=a(33710),h=a(24892),g=a(87585),p=a(79110),f=a(96534),x=a(36476),v=a(53828),b=a(32679),w=a(55930),y=a(10646),j=a(81496),N=a(57006);let k=[{value:"black-forest-labs/flux-schnell",label:"FLUX Schnell",provider:"replicate",scenes:["text-to-image"]},{value:"google/nano-banana",label:"Nano Banana",provider:"replicate",scenes:["text-to-image","image-to-image"]},{value:"bytedance/seedream-4",label:"Seedream 4",provider:"replicate",scenes:["text-to-image","image-to-image"]}],C=[{value:"replicate",label:"Replicate"}];function S(e){if(!e)return null;try{return JSON.parse(e)}catch(e){return console.warn("Failed to parse taskResult:",e),null}}function R(e){var t,a,r,s,i,n;if(!e)return[];let l=null!=(a=null!=(t=e.output)?t:e.images)?a:e.data;if(!l)return[];if("string"==typeof l)return[l];if(Array.isArray(l))return l.flatMap(e=>{if(!e)return[];if("string"==typeof e)return[e];if("object"==typeof e){var t,a,r,s;let i=null!=(s=null!=(r=null!=(a=null!=(t=e.url)?t:e.uri)?a:e.image)?r:e.src)?s:e.imageUrl;return"string"==typeof i?[i]:[]}return[]}
1).filter(Boolean);if("object"==typeof l){let e=null!=(n=null!=(i=null!=(s=null!=(r=l.url)?r:l.uri)?s:l.image)?i:l.src)?n:l.imageUrl;if("string"==typeof e)return[e]}return[]}let T=s.forwardRef((e,t)=>{var a,T,_,E,U,A;let{allowMultipleImages:F=!0,maxImages:P=9,maxSizeMB:I=5,srOnlyTitle:L}=e,z=(0,m.c3)("ai.image.generator"),[D,O]=(0,s.useState)("text-to-image"),[G,M]=(0,s.useState)(2),[V,$]=(0,s.useState)(null!=(E=null==(a=C[0])?void 0:a.value)?E:""),[B,J]=(0,s.useState)(null!=(U=null==(T=k[0])?void 0:T.value)?U:""),[q,W]=(0,s.useState)(""),[Z,H]=(0,s.useState)([]),[X,K]=(0,s.useState)([]),[Q,Y]=(0,s.useState)([]),[ee,et]=(0,s.useState)(!1),[ea,er]=(0,s.useState)(0),[es,ei]=(0,s.useState)(null),[en,el]=(0,s.useState)(null),[eo,ed]=(0,s.useState)(null),[ec,em]=(0,s.useState)(null),[eu,eh]=(0,s.useState)(!1),{user:eg,isCheckSign:ep,setIsShowSignModal:ef,fetchUserCredits:ex}=(0,N.U)();(0,s.useEffect)(()=>{eh(!0)},[]),(0,s.useImperativeHandle)(t,()=>({setPrompt:e=>{W(e)}}));let ev=q.trim().length,eb=null!=(A=null==eg||null==(_=eg.credits)?void 0:_.remainingCredits)?A:0,ew=ev>2e3,ey="text-to-image"===D,ej=(0,s.useMemo)(()=>{if(!eo)return"";switch(eo){case g.i.PENDING:return"Waiting for the model to start";case g.i.PROCESSING:return"Generating your image...";case g.i.SUCCESS:return"Image generation completed";case g.i.FAILED:return"Generation failed";default:return""}},[eo]),eN=(0,s.useCallback)(e=>{H(e),K(e.filter(e=>"uploaded"===e.status&&e.url).map(e=>e.url))},[]),ek=(0,s.useMemo)(()=>Z.some(e=>"uploading"===e.status),[Z]),eC=(0,s.useMemo)(()=>Z.some(e=>"error"===e.status),[Z]),eS=(0,s.useCallback)(()=>{et(!1),er(0),ei(null),el(null),ed(null)},[]),eR=(0,s.useCallback)(async e=>{try{if(en&&Date.now()-en>18e4)return eS(),u.oR.error("Image generation timed out. Please try again."),!0;let t=await fetch("/api/ai/query",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({taskId:e})});if(!t.ok)throw Error("request failed with status: ".concat(t.status));let{code:a,message:r,data:s}=await t.json();if(0!==a)throw Error(r||"Query task failed");let i=s.status;ed(i);let n=S(s.taskResult),l=R(n);if(i===g.i.PENDING)return er(e=>Math.max(e,20)),!1;if(i===g.i.PROCESSING)return l.length>0?(Y(l.map((e,t)=>{var a;return{id:"".concat(s.id,"-").concat(t),url:e,provider:s.provider,model:s.model,prompt:null!=(a=s.prompt)?a:void 0}})),er(e=>Math.max(e,85))):er(e=>Math.min(e+10,80)),!1;if(i===g.i.SUCCESS)return 0===l.length?u.oR.error("The provider returned no images. Please retry."):(Y(l.map((e,t)=>{var a;return{id:"".concat(s.id,"-").concat(t),url:e,provider:s.provider,model:s.model,prompt:null!=(a=s.prompt)?a:void 0}})),u.oR.success("Image generated successfully")),er(100),eS(),!0;if(i===g.i.FAILED){let e=(null==n?void 0:n.error)||(null==n?void 0:n.failure_reason)||"Generate image failed";return u.oR.error(e),eS(),ex(),!0}return er(e=>Math.min(e+5,95)),!1}catch(e){return console.error("Error polling image task:",e),u.oR.error("Query task failed: ".concat(e.message)),eS(),ex(),!0}},[en,eS]);(0,s.useEffect)(()=>{if(!es||!ee)return;let e=!1;(async()=>{es&&await eR(es)&&(e=!0)})();let t=setInterval(async()=>{if(e||!es)return void clearInterval(t);await eR(es)&&clearInterval(t)},5e3);return()=>{e=!0,clearInterval(t)}},[es,ee,eR]);let eT=async()=>{if(!eg)return void ef(!0);if(eb<G)return void u.oR.error("Insufficient credits. Please top up to keep creating.");let e=q.trim();if(!e)return void u.oR.error("Please enter a prompt before generating.");if(!V||!B)return void u.oR.error("Provider or model is not configured correctly.");if(!ey&&0===X.length)return void u.oR.error("Please upload reference images before generating.");et(!0),er(15),ed(g.i.PENDING),Y([]),el(Date.now());try{let t={};ey||(t.image_input=X);let a=await fetch("/api/ai/generate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mediaType:g.V.IMAGE,scene:ey?"text-to-image":"image-to-image",provider:V,model:B,prompt:e,options:t})});if(!a.ok)throw Error("request failed with status: ".concat(a.status));let{code:r,message:s,data:i}=await a.json();if(0!==r)throw Error(s||"Failed to create an image task");let n=null==i?void 0:i.id;if(!n)throw Error("Task id missing in response");if(i.status===g.i.SUCCESS&&i.taskInfo){let t=S(i.taskInfo),a=R(t);if(a.length>0){Y(a.map((t,a)=>({id:"".concat(n,"-").concat(a),url:t,provider:V,model:B,prompt:e}))),u.oR.success("Image generated successfully"),er(100),eS(),await ex();return}}ei(n),er(25),await ex()}catch(e){console.error("Failed to generate image:",e),u.oR.error("Failed to generate image: ".concat(e.message)),eS()}},e_=async e=>{if(e.url)try{em(e.id);let t=await fetch(e.url);if(!t.ok)throw Error("Failed to fetch image");let a=await t.blob(),r=URL.createObjectURL(a),s=document.createElement("a");s.href=r,s.download="".concat(e.id,".png"),document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(()=>URL.revokeObjectURL(r),200),u.oR.success("Image downloaded")}catch(e){console.error("Failed to download image:",e),u.oR.error("Failed to download image")}finally{em(null)}};return(0,r.jsx)("section",{id:"generator",className:"py-16 md:py-24",children:(0,r.jsx)("div",{className:"container",children:(0,r.jsx)("div",{className:"mx-auto max-w-6xl",children:(0,r.jsxs)("div",{className:"grid grid-cols-1 gap-8 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]",children:[(0,r.jsxs)(x.Zp,{children:[(0,r.jsxs)(x.aR,{children:[L&&(0,r.jsx)("h2",{className:"sr-only",children:L}),(0,r.jsx)(x.ZB,{className:"flex items-center gap-2 text-xl font-semibold",children:z("title")})]}),(0,r.jsxs)(x.Wu,{className:"space-y-6 pb-8",children:[(0,r.jsx)(y.tU,{value:D,onValueChange:e=>{O(e);let t=k.filter(t=>t.scenes.includes(e)&&t.provider===V);t.length>0?J(t[0].value):J(""),"text-to-image"===e?M(2):M(4)},children:(0,r.jsxs)(y.j7,{className:"bg-primary/10 grid w-full grid-cols-2",children:[(0,r.jsx)(y.Xi,{value:"text-to-image",children:z("tabs.text-to-image")}),(0,r.jsx)(y.Xi,{value:"image-to-image",children:z("tabs.image-to-image")})]})}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(v.J,{children:z("form.provider")}),(0,r.jsxs)(w.l6,{value:V,onValueChange:e=>{$(e);let t=k.filter(t=>t.scenes.includes(D)&&t.provider===e);t.length>0?J(t[0].value):J("")},children:[(0,r.jsx)(w.bq,{className:"w-full",children:(0,r.jsx)(w.yv,{placeholder:z("form.select_provider")})}),(0,r.jsx)(w.gC,{children:C.map(e=>(0,r.jsx)(w.eb,{value:e.value,children:e.label},e.value))})]})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(v.J,{children:z("form.model")}),(0,r.jsxs)(w.l6,{value:B,onValueChange:J,children:[(0,r.jsx)(w.bq,{className:"w-full",children:(0,r.jsx)(w.yv,{placeholder:z("form.select_model")})}),(0,r.jsx)(w.gC,{children:k.filter(e=>e.scenes.includes(D)&&e.provider===V).map(e=>(0,r.jsx)(w.eb,{value:e.value,children:e.label},e.value))})]})]})]}
1),!ey&&(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsx)(p.GA,{title:z("form.reference_image"),allowMultiple:F,maxImages:F?P:1,maxSizeMB:I,onChange:eN,emptyHint:z("form.reference_image_placeholder")}),eC&&(0,r.jsx)("p",{className:"text-destructive text-xs",children:z("form.some_images_failed_to_upload")})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)(v.J,{htmlFor:"image-prompt",children:z("form.prompt")}),(0,r.jsx)(j.T,{id:"image-prompt",value:q,onChange:e=>W(e.target.value),placeholder:z("form.prompt_placeholder"),className:"min-h-32"}),(0,r.jsxs)("div",{className:"text-muted-foreground flex items-center justify-between text-xs",children:[(0,r.jsxs)("span",{children:[ev," / ",2e3]}),ew&&(0,r.jsx)("span",{className:"text-destructive",children:z("form.prompt_too_long")})]})]}),eu?ep?(0,r.jsxs)(f.$,{className:"w-full",disabled:!0,size:"lg",children:[(0,r.jsx)(i.A,{className:"mr-2 h-4 w-4 animate-spin"}),z("checking_account")]}):eg?(0,r.jsx)(f.$,{size:"lg",className:"w-full",onClick:eT,disabled:ee||!q.trim()||ew||ek||eC,children:ee?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(i.A,{className:"mr-2 h-4 w-4 animate-spin"}),z("generating")]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.A,{className:"mr-2 h-4 w-4"}),z("generate")]})}):(0,r.jsxs)(f.$,{size:"lg",className:"w-full",onClick:()=>ef(!0),children:[(0,r.jsx)(l.A,{className:"mr-2 h-4 w-4"}),z("sign_in_to_generate")]}):(0,r.jsxs)(f.$,{className:"w-full",disabled:!0,size:"lg",children:[(0,r.jsx)(i.A,{className:"mr-2 h-4 w-4 animate-spin"}),z("loading")]}),eu?eg&&eb>0?(0,r.jsxs)("div",{className:"flex items-center justify-between text-sm",children:[(0,r.jsx)("span",{className:"text-primary",children:z("credits_cost",{credits:G})}),(0,r.jsx)("span",{children:z("credits_remaining",{credits:eb})})]}):(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between text-sm",children:[(0,r.jsx)("span",{className:"text-primary",children:z("credits_cost",{credits:G})}),(0,r.jsx)("span",{children:z("credits_remaining",{credits:eb})})]}),(0,r.jsx)(h.N_,{href:"/pricing",children:(0,r.jsxs)(f.$,{variant:"outline",className:"w-full",size:"lg",children:[(0,r.jsx)(o.A,{className:"mr-2 h-4 w-4"}),z("buy_credits")]})})]}):(0,r.jsxs)("div",{className:"flex items-center justify-between text-sm",children:[(0,r.jsx)("span",{className:"text-primary",children:z("credits_cost",{credits:G})}),(0,r.jsx)("span",{children:z("credits_remaining",{credits:0})})]}),ee&&(0,r.jsxs)("div",{className:"space-y-2 rounded-lg border p-4",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between text-sm",children:[(0,r.jsx)("span",{children:z("progress")}),(0,r.jsxs)("span",{children:[ea,"%"]})]}),(0,r.jsx)(b.k,{value:ea}),ej&&(0,r.jsx)("p",{className:"text-muted-foreground text-center text-xs",children:ej})]})]})]}),(0,r.jsxs)(x.Zp,{children:[(0,r.jsx)(x.aR,{children:(0,r.jsxs)(x.ZB,{className:"flex items-center gap-2 text-xl font-semibold",children:[(0,r.jsx)(d.A,{className:"h-5 w-5"}),z("generated_images")]})}),(0,r.jsx)(x.Wu,{className:"pb-8",children:Q.length>0?(0,r.jsx)("div",{className:1===Q.length?"grid gap-6 grid-cols-1":"grid gap-6 sm:grid-cols-2",children:Q.map(e=>(0,r.jsx)("div",{className:"space-y-3",children:(0,r.jsxs)("div",{className:1===Q.length?"relative overflow-hidden rounded-lg border":"relative aspect-square overflow-hidden rounded-lg border",children:[(0,r.jsx)(p.oD,{src:e.url,alt:e.prompt||"Generated image",className:1===Q.length?"w-full h-auto":"h-full w-full object-cover"}),(0,r.jsx)("div",{className:"absolute right-2 bottom-2 flex justify-end text-sm",children:(0,r.jsx)("div",{className:"rounded-md bg-background/90 p-1 shadow-lg backdrop-blur transition-all duration-200 ease-out hover:shadow-xl hover:-translate-y-0.5",children:(0,r.jsx)(f.$,{size:"sm",variant:"ghost",className:"rounded-md text-foreground bg-background/80 hover:bg-primary hover:text-primary-foreground transition-colors duration-200 ease-out",onClick:()=>e_(e),disabled:ec===e.id,children:ec===e.id?(0,r.jsx)(i.A,{className:"h-4 w-4 animate-spin"}):(0,r.jsx)(c.A,{className:"h-4 w-4"})})})})]})},e.id))}):(0,r.jsxs)("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[(0,r.jsx)("div",{className:"bg-muted mb-4 flex h-16 w-16 items-center justify-center rounded-full",children:(0,r.jsx)(d.A,{className:"text-muted-foreground h-10 w-10"})}),(0,r.jsx)("p",{className:"text-muted-foreground",children:z(ee?"ready_to_generate":"no_images_generated")})]})})]})]})})})})});T.displayName="ImageGenerator"},32679:(e,t,a)=>{a.d(t,{k:()=>n});var r=a(72590);a(79998);var s=a(56629),i=a(83461);function n(e){let{className:t,value:a,...n}=e;return(0,r.jsx)(s.bL,{"data-slot":"progress",className:(0,i.cn)("bg-primary/20 relative h-2 w-full overflow-hidden rounded-full",t),...n,children:(0,r.jsx)(s.C1,{"data-slot":"progress-indicator",className:"bg-primary h-full w-full flex-1 transition-all",style:{transform:"translateX(-".concat(100-(a||0),"%)")}})})}},65367:(e,t,a)=>{a.r(t),a.d(t,{PromptInspiration:()=>d});var r=a(72590),s=a(86247),i=a(33710),n=a(40740),l=a(96534);let o=[{image:"/imgs/prompt/1.webp",prompt:"An astronaut, a Caucasian man in his late 20s or early 30s, is the central figure, framed from the chest up, positioned
1slightly right of center. He wears a reflective, red and silver spacesuit with a metallic helmet, the visor showing a reflection of the vibrant cosmic scene. The astronauts facial features are visible through the helmet; he has short brown hair and a contemplative expression, gazing upwards and to the right. The background is a swirling nebula of fiery reds, oranges, and yellows, with scattered stars and streaks of light, suggesting an explosive cosmic event. The lighting is dramatic and intense, emanating from the background, illuminating the astronauts suit and face. The composition is dynamic, with the astronauts pose conveying a sense of exploration and awe. The overall atmosphere is one of wonder and danger, suggesting the vastness of space.",alt:"Mountain landscape"},{image:"/imgs/prompt/2.webp",prompt:"A series of six panels, each depicting scenes of a young girl with sheep, in a bright, cheerful, anime-inspired style. The girl, appearing to be East Asian, with short brown hair and large expressive eyes, is seen in various poses: walking with sheep and a blue bucket, tending to sheep near a stream, and cuddling a sheep during a sunset. She wears a simple pink dress in most panels. The sheep are fluffy and white. The settings vary, with some panels showcasing a sunny meadow filled with wildflowers, a serene stream with rocks, a winding path through green fields, and a sunset. Lighting is warm and soft. The compositions often feature the girl and sheep as the main subjects, with a slight tilt towards a lower-angle perspective, creating a sense of intimacy and care. The overall atmosphere is wholesome, friendly, and evokes a feeling of gentle pastoral life.",alt:"Futuristic city"},{image:"/imgs/prompt/3.webp",prompt:"A cute, cartoonish ginger tabby kitten is the main subject, centrally positioned in the image. The kitten is lying down in a soft, fluffy cat bed, its body curled slightly. It has large, expressive turquoise eyes, pink inner ears, and a pink nose. The kitten's fur is a vibrant orange with darker stripes. Its tongue is sticking out playfully. The kitten is holding a small, brown toy with multiple colors. The cat bed is a soft, off-white color. The lighting appears soft and warm, with light originating from the upper left. The overall atmosphere is cute, friendly, and inviting, with a focus on capturing a moment of playful relaxation. The style is reminiscent of digital art, possibly anime-inspired or a children's book illustration.",alt:"Portrait in garden"},{image:"/imgs/prompt/4.webp",prompt:"Victorian London street scene, a cobblestone road, bathed in a dusky, atmospheric fog. The focus is a horse-drawn carriage speeding down the street, its wheels creating a blurred motion effect. A man in a black top hat and coat guides the horse, while steam billows around the carriage. Two elegant women, one in a dark black gown, the other in a light cream dress with elaborate details, walk in the foreground, their backs to the viewer. Several gentlemen in top hats and long coats walk along the sidewalks. Gas lamps illuminate the street, casting an orange glow. The scene evokes a sense of mystery and movement, with a cool blue cast from shadows. The buildings lining the street are tall, with rows of windows and a classic design. The overall aesthetic feels like a cinematic shot from a historical drama, evoking a mood of suspense and the feeling of a cold and mysterious night. Cinematic lighting, Victorian era, atmospheric perspective, Steampunk, art style.",alt:"Abstract art"},{image:"/imgs/prompt/5.webp",prompt:"A luxurious modern house perched on a mountain ridge overlooking a majestic mountain range at dusk. The multi-story dwelling features expansive glass walls, reflecting the ambient light and revealing elegantly furnished interiors illuminated by warm lighting and chandeliers. A long, infinity-edge swimming pool extends from the house, its surface mirroring the twilight sky. The foreground includes meticulously landscaped elements, featuring carefully placed rocks, drought-resistant shrubbery, and gravel paths. The mountain backdrop displays a gradient of blue hues as the sun sets, creating a serene and captivating atmosphere. The composition utilizes a wide-angle lens, offering a panoramic view of the house and its surroundings. The overall aesthetic is sleek and minimalist, embodying modern architecture and design. The style incorporates elements of contemporary and luxury interior design, evoking a sense of tranquility and opulence. The lighting transitions from warm interior glows to the cool blues and purples of the dusk sky, creating a stunning contrast and visual drama. The image creates a sense of peaceful isolation.",alt:"Coffee shop"},{image:"/imgs/prompt/6.webp",prompt:"Astronaut, standing confidently, centered in dynamic cosmic explosion. The astronaut, mid-thirties, wears a futuristic, sleek spacesuit predominantly white with dark grey accents. Luminescant blue light elements highlight the suit's design, emphasizing chest, shoulders, and along suit lines. The helmet reflects the vibrant nebulae, which showcases fiery orange, yellow, and red hues dominating the background. Meteoroids float around the astronaut, seemingly unaffected by the chaotic cosmic event. The astronaut's pose is upright, slightly angled towards the viewer, hands are relaxed at sides. The lighting is dramatic, with bright emanations from the stellar explosion bathing the scene. The overall mood is awe-inspiring and slightly ominous, suggesting both wonder and potential danger. The composition is symmetrical, highlighting the astronaut's central position against the backdrop. Style evokes both science fiction art and futuristic designs, with strong use of dynamic light and contrast.",alt:"Lion in savanna"},{image:"/imgs/prompt/7.webp",prompt:"A young Asian male, mid-20s, silhouetted against a brilliant sunset. The subject is seen in profile, gaze directed towards the setting sun. He is wearing a dark gray hooded sweatshirt, pulled over a lighter undershirt. Hair is dark, slightly tousled, and catching the light. Facial features show a strong jawline, a prominent nose, and a contemplative expression. The skin has a smooth texture, capturing the warm glow of the setting sun. The background is a gradient of oranges, yellows, and reds, indicating the time of day. The sun is a bright, overexposed disc in the center, and the ocean is visible with reflecting light. The composition uses the rule of thirds, with the subject positioned on the left, and the sun on the right. The overall mood is serene and thoughtful, perhaps melancholy. The lighting creates a strong contrast between the subject and the background, drawing focus to his silhouette. The style is soft, focusing on form and color contrast. The atmosphere is calm and contemplative. The texture is soft, with a natural feel.",alt:"Modern kitchen"},{image:"/imgs/prompt/8.webp",prompt:"A cartoon illustration depicting a young woman, likely in her 20s, with dark hair, and light skin, enjoying music. She is wearing a light green short-sleeved top, dark grey pants, and white headphones. The woman is reclining on a stylized music note shape, suggesting relaxation. She is holding a smartphone in her right hand, seemingly listening to music. Her eyes are closed, and her face expresses contentment. Above her head, a speech bubble contains a green heart, suggesting enjoyment. Musical notes and lines float in the background. The background is a dark gradient from black to green. The style is flat, with simple shapes and colors, and there is a sense of calm and enjoyment. The position of the woman is center-left, with a slight tilt towards the right, the perspective is from a slightly high angle looking down.",alt:"Ocean sunset"}];function d(e){let{generatorRef:t,items:a=o}=e,d=(0,s.c3)("ai.image.generator.promptInspiration");return(0,r.jsx)("section",{className:"container py-12",children:(0,r.jsxs)("div",{className:"space-y-6",children:[(0,r.jsxs)("div",{className:"text-center space-y-2",children:[(0,r.jsx)("h2",{className:"text-3xl font-bold tracking-tight",children:d("title")||"è·åçµæ"}),(0,r.jsx)("p",{className:"text-muted-foreground text-lg",children:d("description")||"ä»ç¤ºä¾å¾çä¸è·åçµæï¼ç¹å»å¾çå°æç¤ºè¯å¤å¶å°è¾å
¥æ¡"})]}),(0,r.jsx)("div",{className:"columns-1 md:columns-2 lg:columns-2 xl:columns-3 2xl:columns-4",style:{columnGap:"0.75rem"},children:a.map((e,a)=>(0,r.jsxs)("div",{className:"group relative mb-3 break-inside-avoid overflow-hidden rounded-lg border bg-muted/50 cursor-pointer transition-all hover:shadow-lg hover:scale-[1.02]",onClick:()=>(e=>{if(null==t?void 0:t.current)t.current.setPrompt(e),i.oR.success(d("promptCopied")||"Prompt copied to input");else{let t=document.getElementById("image-prompt");t?(t.value=e,t.dispatchEvent(new Event("input",{bubbles:!0})),i.oR.success(d("promptCopied")||"Prompt copied to input")):navigator.clipboard.writeText(e).then(()=>{i.oR.success(d("promptCopiedToClipboard")||"Prompt copied to clipboard")})}setTimeout(()=>{let e=document.getElementById("generator");e&&e.scrollIntoView({behavior:"smooth",block:"start"})},100)})(e.prompt),style:{display:"inline-block",width:"100%"},children:[(0,r.jsx)("div",{className:"relative w-full",children:(0,r.jsx)("img",{src:e.image,alt:e.alt||"Inspiration ".concat(a+1),className:"w-full h-auto block transition-transform duration-300 group-hover:scale-110",loading:"lazy",style:{display:"block",width:"100%",height:"auto"}})}),(0,r.jsx)("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/20 transition-colors duration-300 pointer-events-none"}),(0,r.jsx)("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity duration-300 pointer-events-none",children:(0,r.jsxs)(l.$,{size:"sm",variant:"secondary",className:"pointer-events-none",children:[(0,r.jsx)(n.A,{className:"mr-2 h-4 w-4"}),d("copyPrompt")||"å¤å¶æç¤ºè¯"]})})]},a))})]})})}},81496:(e,t,a)=>{a.d(t,{T:()=>n});var r=a(72590),s=a(79998),i=a(83461);let n=s.forwardRef((e,t)=>
1{let{className:a,...s}=e;return(0,r.jsx)("textarea",{className:(0,i.cn)("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background placeholder:text-muted-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",a),ref:t,...s})});n.displayName="Textarea"},81766:(e,t,a)=>{a.d(t,{d:()=>n});var r=a(72590);a(79998);var s=a(44260),i=a(83461);function n(e){let{className:t,...a}=e;return(0,r.jsx)(s.bL,{"data-slot":"switch",className:(0,i.cn)("peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",t),...a,children:(0,r.jsx)(s.zi,{"data-slot":"switch-thumb",className:(0,i.cn)("bg-background dark:data-[state=unchecked]:bg-foreground dark:data-[state=checked]:bg-primary-foreground pointer-events-none block size-4 rounded-full ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0")})})}},87585:(e,t,a)=>{a.d(t,{V:()=>r,i:()=>s});var r=function(e){return e.MUSIC="music",e.IMAGE="image",e.VIDEO="video",e.TEXT="text",e.SPEECH="speech",e}({}),s=function(e){return e.PENDING="pending",e.PROCESSING="processing",e.SUCCESS="success",e.FAILED="failed",e.CANCELED="canceled",e}({})},91356:(e,t,a)=>{a.r(t),a.d(t,{BackgroundRemover:()=>y});var r=a(72590),s=a(79998),i=a(96534),n=a(65592),l=a(92853),o=a(25395),d=a(94797),c=a(55850),m=a(33710),u=a(83461),h=a(45623),g=a(62321),p=a.n(g),f=a(93759),x=a(24893),v=a(57006);let b=[{name:"Transparent",value:"transparent",gradient:!0},{name:"Custom",value:"custom",icon:"pipette"},{name:"Black",value:"#000000"},{name:"White",value:"#FFFFFF"},{name:"Light Gray",value:"#f5f5f5"},{name:"Red",value:"#ef4444"},{name:"Orange",value:"#f97316"},{name:"Amber",value:"#f59e0b"},{name:"Yellow",value:"#eab308"},{name:"Lime",value:"#84cc16"},{name:"Green",value:"#22c55e"},{name:"Teal",value:"#14b8a6"},{name:"Cyan",value:"#06b6d4"},{name:"Blue",value:"#3b82f6"},{name:"Indigo",value:"#6366f1"}],w=()=>new Promise(e=>setTimeout(e,0));function y(e){let t=f.b.app_name||"background-remover",{configs:a}=(0,v.U)(),[g,y]=(0,s.useState)([]),[j,N]=(0,s.useState)("transparent"),[k,C]=(0,s.useState)("#ffffff"),[S,R]=(0,s.useState)(!1),[T,_]=(0,s.useState)(!1),[E,U]=(0,s.useState)(!1),[A,F]=(0,s.useState)(null),[P,I]=(0,s.use
1State)(null),[L,z]=(0,s.useState)(!1),D=(0,s.useRef)(null),O=(0,s.useRef)(null),G=(0,s.useRef)(null),M=(0,s.useRef)(new Map),V=(0,s.useMemo)(()=>{let e=(null==a?void 0:a.turnstile_enabled)==="true",t=null==a?void 0:a.turnstile_site_key;return{enabled:e,siteKey:e&&t&&"string"==typeof t&&t.trim().length>0?t.trim():null}},[a]);(0,s.useEffect)(()=>{z(V.enabled),I(V.siteKey)},[V]),(0,s.useEffect)(()=>{let e=e=>{O.current&&!O.current.contains(e.target)&&U(!1)};if(E)return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[E]);let $=()=>"".concat(Date.now(),"-").concat(Math.random().toString(36).substr(2,9)),B=async(e,t)=>{if("transparent"===t)return e;let a=new Image,r=URL.createObjectURL(e);try{await new Promise((e,t)=>{a.onload=()=>e(),a.onerror=()=>t(Error("Failed to load image")),a.src=r});let e=document.createElement("canvas");e.width=a.width,e.height=a.height;let s=e.getContext("2d",{alpha:!0,willReadFrequently:!1});return s.imageSmoothingEnabled=!0,s.imageSmoothingQuality="high",s.fillStyle=t,s.fillRect(0,0,e.width,e.height),s.drawImage(a,0,0),await new Promise((t,a)=>{e.toBlob(e=>{e?t(e):a(Error("Failed to create blob"))},"image/png")})}finally{URL.revokeObjectURL(r)}},J=(0,s.useCallback)((e,t)=>{let a=M.current;if(a.has(e))return void a.set(e,t);if(a.size>=32){let e=a.keys().next().value;e&&a.delete(e)}a.set(e,t)},[M]),q=(0,s.useCallback)(async e=>{if(!e.processedUrl)throw Error("Processed image is not ready");let t=M.current.get(e.processedUrl);if(t)return t;let a=await fetch("/api/background-remover/download?url=".concat(encodeURIComponent(e.processedUrl)));if(!a.ok)throw Error("Download failed: ".concat(a.status));let r=await a.blob();return J(e.processedUrl,r),r},[J,M]),W=e=>["image/jpeg","image/jpg","image/png","image/webp"].includes(e.type)?e.size>0xa00000?"File size must be less than 10MB":null:"Please upload JPG, PNG or WebP format",Z=(0,s.useCallback)(e=>{let t=Array.from(e).slice(0,20-g.length),a=[];for(let e of t){let t=W(e);if(t){m.oR.error(t);continue}a.push({id:$(),originalFile:e,originalUrl:URL.createObjectURL(e),processedUrl:null,status:"pending"})}a.length>0&&y(e=>[...e,...a]),g.length+a.length>=20&&m.oR.info("Maximum 20 images allowed")},[g.length]),H=async()=>{let e=g.filter(e=>"pending"===e.status);if(0===e.length)return void m.oR.error("No images to process");if(L&&!A)return void m.oR.error("Please complete the verification");_(!0),y(e=>e.map(e=>"pending"===e.status?{...e,status:"processing",error:void 0}:e));let t=0,a=0,r=async e=>{try{let a=new FormData;a.append("file",e.originalFile),L&&A&&a.append("turnstile_token",A);let s=await fetch("/api/background-remover",{method:"POST",body:a}),i=await s.json();if(0!==i.code){var r;throw(null==(r=i.message)?void 0:r.includes("Turnstile"))&&L&&G.current&&(G.current.reset(),F(null)),Error(i.message||"Processing failed")}let n=i.data.processed_url;y(t=>t.map(t=>t.id===e.id?{...t,processedUrl:n,status:"completed",error:void 0}:t)),e.processedUrl&&M.current.delete(e.processedUrl),new Image().src=n,t++}catch(t){console.error("Processing error:",t),y(a=>a.map(a=>a.id===e.id?{...a,status:"error",error:t.message||"Failed to process"}:a)),a++}},s=0,i=Array.from({length:Math.min(3,e.length)},async()=>{for(;s<e.length;){let t=e[s];if(s++,!t)break;await r(t)}});await Promise.all(i),0===a?m.oR.success("Successfully processed ".concat(t," images")):0===t?m.oR.error("Failed to process all ".concat(a," images")):m.oR.warning("Processed ".concat(t," images, ").concat(a," failed")),_(!1)},X=e=>{y(t=>{let a=t.find(t=>t.id===e);return a&&(URL.revokeObjectURL(a.originalUrl),a.processedUrl&&M.current.delete(a.processedUrl)),t.filter(t=>t.id!==e)})},K=async function(e){let t=!(arguments.length>1)||void 0===arguments[1]||arguments[1];if(e.processedUrl)try{let a=await q(e),r=await B(a,j),s=URL.createObjectURL(r);try{let t=document.createElement("a");t.href=s,t.download="bg-removed-".concat(e.originalFile.name.replace(/\.[^/.]+$/,""),".png"),document.body.appendChild(t),t.click(),document.body.removeChild(t)}finally{URL.revokeObjectURL(s)}t&&m.oR.success("Image downloaded successfully")}catch(e){throw console.error("Download error:",e),t&&m.oR.error("Failed to download image"),e}},Q=async()=>{let e=g.filter(e=>"completed"===e.status&&e.processedUrl);if(0===e.length)return void m.oR.error("No completed images to download");let a=m.oR.loading("Preparing ".concat(e.length," images for download..."));try{let r=new(p());for(let t=0;t<e.length;t++){let s=e[t];m.oR.loading("Processing ".concat(t+1,"/").concat(e.length," images..."),{id:a});try{let e=await q(s),t=await B(e,j),a="bg-removed-".concat(s.originalFile.
1name.replace(/\.[^/.]+$/,""),".png");r.file(a,t)}catch(e){console.error("Processing error:",e)}finally{await w()}}m.oR.loading("Generating ZIP file...",{id:a});let s=await r.generateAsync({type:"blob"}),i=URL.createObjectURL(s);try{let e=document.createElement("a");e.href=i,e.download="".concat(t,"-background-removed-").concat(Date.now(),".zip"),document.body.appendChild(e),e.click(),document.body.removeChild(e)}finally{URL.revokeObjectURL(i)}m.oR.dismiss(a),m.oR.success("Successfully downloaded ".concat(e.length," images as ZIP"))}catch(e){console.error("Download error:",e),m.oR.dismiss(a),m.oR.error("Failed to create ZIP file")}},{pendingCount:Y,processingCount:ee,completedCount:et,hasCompleted:ea,shouldShowPrimaryButton:er}=(0,s.useMemo)(()=>{let e=g.filter(e=>"pending"===e.status).length,t=g.filter(e=>"processing"===e.status).length,a=g.filter(e=>"completed"===e.status).length;return{pendingCount:e,processingCount:t,completedCount:a,hasCompleted:a>0,shouldShowPrimaryButton:e>0||t>0||T}},[g,T]),es=()=>T?ee>
10?"Processing...":"Uploading...":"Remove Background",ei=(0,s.useCallback)(e=>{F(e)},[]),en=(0,s.useCallback)(e=>{console.error("Turnstile error:",e),F(null)},[]),el=(0,s.useCallback)(()=>{F(null)},[]);return(0,r.jsxs)("div",{className:"w-full max-w-7xl mx-auto space-y-8 py-0",children:[0===g.length&&(0,r.jsxs)("div",{className:"space-y-6",children:[(0,r.jsxs)("div",{onClick:()=>{var e;return null==(e=D.current)?void 0:e.click()},onDrop:e=>{e.preventDefault(),R(!1);let t=e.dataTransfer.files;t&&0!==t.length&&Z(t)},onDragOver:e=>{e.preventDefault(),R(!0)},onDragLeave:e=>{e.preventDefault(),R(!1)},className:(0,u.cn)("relative rounded-3xl p-12 text-center cursor-pointer group border border-border/60 bg-white/80 backdrop-blur-sm shadow-sm transition-all duration-200",S&&"ring-2 ring-primary/50 bg-primary/5"),style:{backgroundImage:S?void 0:"linear-gradient(45deg, #f7f7f7 25%, transparent 25%, transparent 75%, #f7f7f7 75%, #f7f7f7), linear-gradient(45deg, #f7f7f7 25%, transparent 25%, transparent 75%, #f7f7f7 75%, #f7f7f7)",backgroundSize:S?void 0:"20px 20px",backgroundPosition:S?void 0:"0 0, 10px 10px"},children:[(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"inline-flex items-center gap-2 rounded-2xl bg-[#fcd948] text-[#3c2d00] px-6 py-3 text-lg font-semibold shadow-md shadow-[#fcd948]/40 transition-transform duration-200 group-hover:-translate-y-0.5",children:[(0,r.jsx)(n.A,{className:"w-5 h-5",strokeWidth:2.3}),(0,r.jsx)("span",{children:S?"Drop your images here":"Add Your Images"})]}),(0,r.jsxs)("div",{className:"space-y-1",children:[(0,r.jsx)("p",{className:"text-lg font-semibold text-[#2f3173]",children:S?"Release to upload":"Drag & Drop your images here"}),(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:"jpeg, png, webp images allowed"})]})]}),(0,r.jsx)("input",{ref:D,type:"file",accept:"image/jpeg,image/jpg,image/png,image/webp",onChange:e=>{let t=e.target.files;t&&0!==t.length&&(Z(t),e.target.value="")},multiple:!0,className:"hidden"})]}),(0,r.jsxs)("div",{className:"text-center space-y-3 py-0",children:[(0,r.jsx)("p",{className:"text-sm font-medium text-muted-foreground",children:"No pictures on hand? Try these below:"}),(0,r.jsx)("div",{className:"grid grid-cols-4 gap-1.5 max-w-xs mx-auto",children:[1,2,3,4].map(e=>(0,r.jsx)("div",{className:"aspect-square rounded-lg overflow-hidden border border-border cursor-pointer hover:scale-105 hover:border-primary/50 transition-all duration-300 group shadow-sm hover:shadow-md",onClick:async()=>{try{let t=await fetch("/imgs/showcases/sample".concat(e,".jpg")),a=await t.blob(),r=a.type||"image/jpeg",s=new File([a],"sample-".concat(e,".jpg"),{type:r});Z([s]),m.oR.success("Sample image imported successfully")}catch(e){console.error("Failed to load sample image:",e),m.oR.error("Failed to load sample image")}},children:(0,r.jsx)("img",{src:"/imgs/showcases/sample".concat(e,".jpg"),alt:"Sample ".concat(e),className:"w-full h-full object-cover transition-transform duration-300 group-hover:scale-110",onError:e=>{e.currentTarget.src="/imgs/placeholder.png"}})},e))})]})]}),g.length>0&&(0,r.jsx)("div",{className:"bg-gradient-to-br from-muted/40 via-muted/20 to-background dark:from-muted/30 dark:via-muted/10 dark:to-background rounded-3xl p-6 md:p-8 border border-border/50 shadow-sm",children:(0,r.jsx)("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4 md:gap-6",children:g.map(e=>(0,r.jsx)("div",{className:"relative group rounded-2xl overflow-hidden border-2 border-border bg-card shadow-sm hover:shadow-lg hover:border-primary/30 transition-all duration-300",children:(0,r.jsxs)("div",{className:(0,u.cn)("aspect-square relative overflow-hidden rounded-xl","transparent"===j?"bg-[linear-gradient(45deg,#f0f0f0_25%,transparent_25%,transparent_75%,#f0f0f0_75%,#f0f0f0),linear-gradient(45deg,#f0f0f0_25%,transparent_25%,transparent_75%,#f0f0f0_75%,#f0f0f0)] bg-[length:20px_20px] bg-[position:0_0,10px_10px]":""),style:{backgroundColor:"transparent"!==j?j:void 0},children:["processing"===e.status&&(0,r.jsxs)("div",{className:"absolute inset-0 bg-black/70 backdrop-blur-md flex flex-col items-center justify-center z-10 rounded-xl",children:[(0,r.jsx)(l.A,{className:"w-12 h-12 text-white animate-spin mb
1-4",strokeWidth:2.5}),(0,r.jsx)("p",{className:"text-white text-sm font-semibold",children:"Processing..."})]}),"error"===e.status&&(0,r.jsxs)("div",{className:"absolute inset-0 bg-red-500/30 backdrop-blur-md flex flex-col items-center justify-center z-10 rounded-xl",children:[(0,r.jsx)("div",{className:"w-12 h-12 rounded-full bg-red-500/20 flex items-center justify-center mb-3",children:(0,r.jsx)(o.A,{className:"w-8 h-8 text-red-500",strokeWidth:2.5})}),(0,r.jsx)("p",{className:"text-red-600 dark:text-red-400 text-xs px-3 text-center font-medium",children:e.error||"Failed"})]}),(0,r.jsx)("img",{src:e.processedUrl||e.originalUrl,alt:"Preview",className:"w-full h-full object-contain transition-transform duration-300 group-hover:scale-105",loading:"lazy",decoding:"async",onError:e=>{let t=e.currentTarget,a=t.src;a&&a.startsWith("http")&&!a.includes("/api/background-remover/proxy")&&(t.src="/api/background-remover/proxy?url=".concat(encodeURIComponent(a)))},style:{imageRendering:"auto",backfaceVisibility:"hidden",transform:"translateZ(0)"}}),"pending"===e.status&&(0,r.jsx)("div",{className:"absolute top-2 left-2 px-2 py-1 rounded-md bg-yellow-500/90 backdrop-blur-sm text-white text-xs font-medium shadow-sm",children:"Pending"}),"completed"===e.status&&(0,r.jsxs)("div",{className:"absolute top-2 right-2 flex gap-2 opacity-0 group-hover:opacity-100 transition-all duration-300",children:[(0,r.jsx)("button",{onClick:t=>{t.stopPropagation(),K(e)},className:"p-2.5 bg-white/95 dark:bg-gray-800/95 backdrop-blur-sm rounded-full shadow-lg hover:bg-primary hover:text-primary-foreground transition-all duration-200 hover:scale-110",title:"Download",children:(0,r.jsx)(d.A,{className:"w-4 h-4",strokeWidth:2.5})}),(0,r.jsx)("button",{onClick:t=>{t.stopPropagation(),X(e.id)},className:"p-2.5 bg-white/95 dark:bg-gray-800/95 backdrop-blur-sm rounded-full shadow-lg hover:bg-red-500 hover:text-white transition-all duration-200 hover:scale-110",title:"Delete",children:(0,r.jsx)(c.A,{className:"w-4 h-4",strokeWidth:2.5})})]}),"pending"===e.status&&(0,r.jsx)("button",{onClick:t=>{t.stopPropagation(),X(e.id)},className:"absolute top-2 right-2 p-2.5 bg-white/95 dark:bg-gray-800/95 backdrop-blur-sm rounded-full shadow-lg hover:bg-red-500 hover:text-white transition-all duration-200 opacity-0 group-hover:opacity-100 hover:scale-110",title:"Delete",children:(0,r.jsx)(c.A,{className:"w-4 h-4",strokeWidth:2.5})})]})},e.id))})}),g.length>0&&(0,r.jsxs)("div",{className:"flex flex-col items-center space-y-6 py-8",children:[(0,r.jsxs)("div",{className:"space-y-6",children:[g.length>0&&(0,r.jsx)("div",{className:"flex items-center justify-center gap-3 max-sm:gap-2 flex-wrap max-sm:max-w-[400px]",children:b.map(e=>(0,r.jsxs)("div",{className:(0,u.cn)("relative","custom"===e.value&&""),children:[(0,r.jsx)("button",{onClick:()=>{"custom"===e.value?U(!E):(N(e.value),U(!1))},className:(0,u.cn)("w-10 h-10 sm:w-10 sm:h-10 md:w-10 md:h-10 rounded-full border-2 transition-all hover:scale-110 cursor-pointer","max-sm:w-8 max-sm:h-8",j!==e.value&&("custom"!==e.value||b.find(e=>e.value===j))?"border-gray-300 dark:border-gray-700":"border-primary ring-2 ring-primary ring-offset-2"),title:e.name,style:{backgroundColor:"transparent"===e.value?void 0:"custom"===e.value?k:e.value,backgroundImage:e.gradient?"linear-gradient(45deg, #f0f0f0 25%, transparent 25%, transparent 75%, #f0f0f0 75%, #f0f0f0), linear-gradient(45deg, #f0f0f0 25%, transparent 25%, transparent 75%, #f0f0f0 75%, #f0f0f0)":void 0,backgroundSize:e.gradient?"10px 10px":void 0,backgroundPosition:e.gradient?"0 0, 5px 5px":void 0},children:"pipette"===e.icon&&(0,r.jsxs)("svg",{className:"w-full h-full",viewBox:"0 0 24 24",fill:"none",children:[(0,r.jsx)("defs",{children:(0,r.jsxs)("linearGradient",{id:"rainbowGradient",x1:"0%",y1:"0%",x2:"100%",y2:"100%",children:[(0,r.jsx)("stop",{offset:"0%",stopColor:"#FF6B6B"}),(0,r.jsx)("stop",{offset:"20%",stopColor:"#FFA500"}),(0,r.jsx)("stop",{offset:"40%",stopColor:"#FFD93D"}),(0,r.jsx)("stop",{offset:"60%",stopColor:"#6BCB77"}),(0,r.jsx)("stop",{offset:"80%",stopColor:"#4D96FF"}),(0,r.jsx)("stop",{offset:"100%",stopColor:"#9D4EDD"})]})}),(0,r.jsx)("circle",{cx:"12",cy:"12",r:"12",fill:"url(#rainbowGradient)"})]})}),"custom"===e.value&&E&&(0,r.jsxs)("div",{ref:O,className:"absolute top-full left-0 mt-2 z-50 bg-white dark:bg-gray-900 rounded-xl shadow-2xl border border-gray-200 dark:border-gray-700 overflow-hidden",children:[(0,r.jsx)("div",{className:"p-3 flex justify-center",children:(0,r.jsx)(h.jI,{color:k,onChange:e=>{C(e),N(e)}})}),(0,r.jsx)("div",{className:"h-px bg-gray-200 dark:bg-gray-700"}),(0,r.jsxs)("div",{className:"p-3 space-y-2",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("div",{className:"w-10 h-10 rounded-lg border-2 border-gray-300 dark:border-gray-600 shadow-inner flex-shrink-0",style:{backgroundColor:k}}),(0,r.jsxs)("div",{className:"flex-1",children:[(0,r.jsx)("label",{className:"block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1",children:"HEX Color"}),(0,r.jsx)("input",{type:"text",value:k,onChange:e=>{let t=e.target.value;/^#[0-9A-Fa-f]{0,6}$/.test(t)&&(C(t),7===t.length&&N(t))},className:"w-full px-2 py-1.5 text-sm font-mono border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all uppercase",placeholder:"#FFFFFF"})]})]}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(i.$,{variant:"outline",size:"sm",onClick:()=>U(!1),className:"flex-1",children:"Cancel"}),(0,r.jsx)(i.$,{size:"sm",onClick:()=>{N(k),U(!1)},className:"flex-1",children:"Apply"})]})]})]})]},e.value))}),(0,r.jsxs)("div",{className:"flex flex-col items-center gap-4",children:[L&&P&&er&&(0,r.jsx)("div",{className:"flex justify-center",children:(0,r.jsx)(x.Xs,{ref:G,siteKey:P,onSuccess:ei,onError:en,onExpire:el,options:{theme:"light",size:"normal"}})}),L&&!P&&er&&(0,r.jsx)("div",{className:"text-center text-red-500 text-sm",children:"Turnstile is enabled but Site Key is not configured. Please configure it in the admin settings."}),(0,r.jsxs)("div",{className:"flex items-center justify-center gap-4",children:[er&&(0,r.jsx)(i.$,{size:"lg",onClick:H,disabled:T||L&&!A,className:"bg-yellow-500 hover:bg-yellow-600 text-black font-semibold px-8 py-6 text-base rounded-xl shadow-lg disabled:opacity-50",children:T?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(l.A,{className:"w-5 h-5 mr-2 animate-spin"}),es()]}):es()}),ea&&(0,r.jsxs)(i.$,{size:"lg",onClick:Q,className:"bg-yellow-500 hover:bg-yellow-600 text-black font-semibold px-8 py-6 text-base rounded-xl shadow-lg",children:[(0,r.jsx)(d.A,{className:"w-5 h-5 mr-2"}),"Download All"]})]})]})]}),(0,r.jsx)(i.$,{variant:"ghost",size:"lg",onClick:()=>
1{g.forEach(e=>{URL.revokeObjectURL(e.originalUrl),e.processedUrl&&M.current.delete(e.processedUrl)}),y([]),_(!1),M.current.clear()},disabled:T,className:"font-semibold text-base",children:"Clear all"})]})]})}}}]);
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.