1import{b as de,aZ as me,r as l,aI as ue,c0 as xe,c1 as pe,z as j,j as e,W as ge,X as he,ak as fe,c3 as O,p as ye,$ as ve,aT as be,D as je,L as Ne,I as we,aO as ke,c4 as Ce,c5 as H,c6 as W,bf as Se}from"./index-BawMCgu8.js";import{u as M}from"./useFeatureCreditEstimate-CKYhAOwQ.js";import"./locale-en-B8Z5F_o1.js";import"./locale-zh-CN-CFdD1mPv.js";import"./locale-fr-j4CMJpfE.js";import"./locale-de-DuE2gagy.js";import"./locale-it-C6yb6RzN.js";import"./locale-ja-VjZBy5eF.js";import"./locale-ko-Cl0W-Az5.js";import"./locale-es-DwboUZze.js";import"./locale-zh-Hant-uT5aTnfX.js";import"./locale-ru-DEr1xfTZ.js";import"./locale-id-Buh3Uolz.js";import"./locale-pt-BR-CqD5J4_0.js";const q="restore-state";function Ue(){try{const r=localStorage.getItem(q);return r?JSON.parse(r):{sourceUrl:null,resultImage:null,restoreLevel:2,colorize:!1,faceEnhance:!0,resultInfo:null}}catch{return{sourceUrl:null,resultImage:null,restoreLevel:2,colorize:!1,faceEnhance:!0,resultInfo:null}}}function Ge(){const{t:r}=de(),{requireAuth:B}=me(),N=l.useRef(null),u=l.useRef(Ue()).current,[x,f]=l.useState(u.sourceUrl),[G,w]=l.useState(null),[k,y]=l.useState(u.sourceUrl),[p,v]=l.useState(u.resultImage),[C,D]=l.useState(!1),[g,J]=l.useState(u.restoreLevel),[o,P]=l.useState(u.colorize),[S,_]=l.useState(u.faceEnhance),E=M("image_restore"),U=M("image_colorize"),R=E.estimate!=null?E.estimate+(o&&U.estimate!=null?U.estimate:0):null,z=E.insufficient||o&&U.insufficient,{tier:K,credits:X,thresholds:Y}=ue(),A=K!=="premium",[Z,F]=l.useState(!1),{openPicker:Q,PickerElement:V}=xe(),{showSourceChoice:ee,sourceChoiceOpen:re,pickSource:T}=pe(),[h,b]=l.useState(u.resultInfo);l.useEffect(()=>{try{localStorage.setItem(q,JSON.stringify({sourceUrl:k,resultImage:p,restoreLevel:g,colorize:o,faceEnhance:S,resultInfo:h}))}catch{}},[k,p,g,o,S,h]);const se=[{value:1,name:r("image.restoreLevelLight"),desc:r("image.restoreLevelLightDesc")},{value:2,name:r("image.restoreLevelStandard"),desc:r("image.restoreLevelStandardDesc")},{value:3,name:r("image.restoreLevelDeep"),desc:r("image.restoreLevelDeepDesc")}],te=l.useCallback(s=>{var a;const t=(a=s.target.files)==null?void 0:a[0];if(t){if(t.size>10*1024*1024){j.error(r("image.fileTooLarge",{max:"10MB"}));return}const c=new FileReader;c.onload=n=>{var m;f((m=n.target)==null?void 0:m.result),w(t),y(null),v(null),b(null)},c.readAsDataURL(t)}},[r]),ae=l.useCallback(s=>{var a;s.preventDefault();const t=(a=s.dataTransfer.files)==null?void 0:a[0];if(t&&t.type.startsWith("image/")){if(t.size>10*1024*1024){j.error(r("image.fileTooLarge",{max:"10MB"}));return}const c=new FileReader;c.onload=n=>{var m;f((m=n.target)==null?void 0:m.result),w(t),y(null),v(null),b(null)},c.readAsDataURL(t)}},[r]),le=async()=>{var t;const s=await ee();if(s==="local")(t=N.current)==null||t.click();else if(s==="library"){const a=await Q("image");if(!a)return;f(a.url),w(null),y(a.url)}},oe=()=>{f(null),w(null),y(null),v(null),b(null),N.current&&(N.current.value="")},ie=async()=>{if(k)return k;let s=G;if(!s&&x){const n=await(await fetch(x)).blob();s=new File([n],"source.png",{type:n.type||"image/png"})}if(!s)throw new Error("No file selected");const a=(await Se.uploadImage(s)).data.url;return y(a),f(a),a},ce=async()=>{var s,t,a,c,n,m;if(B()&&x){D(!0);try{const I=await ie(),{data:i}=await H.restore({imageUrl:I,colorize:o,restoreLevel:g,faceEnhance:S});if(i.taskId&&i.status==="processing"){for(let $=0;$<90;$++){const d=(await H.getProcessingTaskStatus(i.taskId)).data;if(d.status==="completed"){const L=((s=d.result)==null?void 0:s.imageUrl)||d.imageUrl;if(L){v(L),b({colorized:((t=d.result)==null?void 0:t.colorized)??o,processingTime:(a=d.result)==null?void 0:a.processingTime,creditsUsed:((c=d.result)==null?void 0:c.creditsUsed)??d.creditsUsed}),j.success(r("image.processSuccess")),W();return}throw new Error("No image URL in result")}if(d.status==="failed")throw new Error(d.error||"Processing failed");await new Promise(L=>setTimeout(L,2e3))}throw new Error("Processing timed out")}if(i.status==="completed"&&i.imageUrl)v(i.imageUrl),b({colorized:i.colorized,processingTime:i.processingTime,creditsUsed:i.creditsUsed}),j.success(r("image.processSuccess")),W();else if(i.status==="failed")throw new Error(i.error||"Processing failed")}catch(I){j.error(((m=(n=I.response)==null?void 0:n.data)==null?void 0:m.message)||I.message||r("image.processError"))}finally{D(!1)}}},ne=()=>{if(!p)return;const s=`/api/v1/image/download?url=${encodeURIComponent(p)}`,t=document.createElement("a");t.href=s,t.download=`restored-${o?"colorized-":""}${Date.now()}.png`,document.body.appendChild(t),t.click(),document.body.removeChild(t)};return e.jsxs("div",{className:"h-full overflow-y-auto",style:{background:"var(--bg-base)"},children:[e.jsx("div",{className:"px-6 py-4 border-b",style:{borderColor:"var(--border-default)"},children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl flex items-center justify-center",style:{background:"var(--bg-tertiary)"},children:e.jsx(ge,{className:"w-5 h-5",style:{color:"var(--text-secondary)"}})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold",style:{color:"var(--text-primary)"},children:r("imageHome.features.restore")}),e.jsx("p",{className:"text-sm",style:{color:"var(--text-tertiary)"},children:r("imageHome.features.restoreDesc")})]})]})}),e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"rounded-xl border overflow-hidden",style:{background:"var(--surface-primary)",borderColor:"var(--border-default)"},children:[e.jsxs("div",{className:"px-4 py-3 border-b flex items-center justify-between",style:{borderColor:"var(--border-default)"},children:[e.jsx("span",{className:"font-medium",style:{color:"var(--text-primary)"},children:r("image.sourceImage")}),x&&e.jsx("button",{onClick:oe,className:"p-1.5 rounded-lg hover:bg-[var(--bg-hover)] transition-colors",children:e.jsx(he,{className:"w-4 h-4",style:{color:"var(--text-tertiary)"}})})]}),e.jsx("div",{className:"p-4",children:x?e.jsx(O,{url:x,alt:"Source",className:"w-full rounded-lg",style:{maxHeight:"300px",objectFit:"contain"}}):e.jsxs("div",{className:"border-2 border-dashed rounded-xl p-8 text-center cursor-pointer hover:border-[var(--text-tertiary)] transition-colors",style:{borderColor:"var(--border-default)"},onClick:le,onDrop:ae,onDragOver:s=>s.preventDefault(),children:[e.jsx("input",{ref:N,type:"file",accept:"image/jpeg,image/png,image/webp,image/svg+xml",onChange:te,onClick:s=>s.stopPropagation(),hidden:!0}),e.jsx(fe,{className:"w-12 h-12 mx-auto mb-4",style:{color:"var(--text-tertiary)"}}),e.jsx("p",{className:"font-medium mb-2",style:{color:"var(--text-primary)"},children:r("image.dropOrClick")}),e.jsx("p",{className:"text-sm mb-1",style:{color:"var(--text-tertiary)"},children:r("image.restoreUploadHint")}),e.jsx("p",{className:"text-sm",style:{color:"var(--text-tertiary)"},children:"JPG, PNG, WebP (Max 10MB)"})]})})]}),e.jsxs("div",{className:"rounded-xl border overflow-hidden",style:{background:"var(--surface-primary)",borderColor:"var(--border-default)"},children:[e.jsx("div",{className:"px-4 py-3 border-b",style:{borderColor:"var(--border-default)"},children:e.jsx("span",{className:"font-medium",style:{color:"var(--text-primary)"},children:r("image.options")})}),e.jsxs("div",{className:"p-4 space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-2",style:{color:"var(--text-primary)"},children:r("image.restoreLevel")}),e.jsx("div",{className:"space-y-2",children:se.map(s=>e.jsxs("button",{onClick:()=>
1J(s.value),className:`w-full px-3 py-2 rounded-lg border text-left transition-all ${g===s.value?"border-[var(--text-secondary)] bg-[var(--bg-tertiary)]":"hover:border-gray-300"}`,style:{borderColor:g===s.value?"var(--text-primary)":"var(--border-default)"},children:[e.jsx("span",{className:"text-sm font-medium",style:{fontWeight:g===s.value?600:400},children:s.name}),e.jsx("span",{className:"block text-xs",style:{color:"var(--text-tertiary)"},children:s.desc})]},s.value))})]}),e.jsxs("div",{className:`p-4 rounded-xl border cursor-pointer transition-all ${o?"border-[var(--text-secondary)] bg-[var(--bg-tertiary)]":""}`,style:{borderColor:o?"var(--text-primary)":"var(--border-default)"},onClick:()=>P(!o),children:[e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:o,onChange:s=>P(s.target.checked),className:"w-4 h-4 rounded border-gray-300"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ye,{className:"w-4 h-4",style:{color:o?"var(--text-primary)":"var(--text-tertiary)"}}),e.jsx("span",{className:"text-sm font-medium",style:{color:"var(--text-primary)"},children:r("image.colorize")})]})]}),e.jsx("p",{className:"text-xs mt-2 ml-7",style:{color:"var(--text-tertiary)"},children:r("image.colorizeDesc",{credits:U.estimate??"~"})})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:S,onChange:s=>_(s.target.checked),className:"w-4 h-4 rounded border-gray-300"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ve,{className:"w-4 h-4",style:{color:"var(--text-tertiary)"}}),e.jsx("span",{className:"text-sm",style:{color:"var(--text-primary)"},children:r("image.faceEnhance")})]})]}),e.jsx("p",{className:"text-xs mt-1 ml-7",style:{color:"var(--text-tertiary)"},children:r("image.restoreFaceEnhanceDesc")})]}),e.jsxs("button",{onClick:()=>{if(A){F(!0);return}ce()},disabled:!x||C||z,className:`w-full flex items-center justify-center gap-2 px-4 py-3 rounded-xl font-medium text-white transition-all disabled:opacity-50 disabled:cursor-not-allowed hover:opacity-90 ${z?"!bg-destructive/20 !text-destructive":""} ${A?"opacity-50":""}`,style:z?void 0:{background:"var(--theme)"},children:[r(C?"image.processing":"image.startRestore"),R!=null&&!C&&e.jsxs("span",{className:"flex items-center gap-0.5 text-xs opacity-60 ml-1",children:[e.jsx(be,{className:"w-3 h-3"}),"~",R]})]})]})]}),e.jsxs("div",{className:"rounded-xl border overflow-hidden",style:{background:"var(--surface-primary)",borderColor:"var(--border-default)"},children:[e.jsxs("div",{className:"px-4 py-3 border-b flex items-center justify-between",style:{borderColor:"var(--border-default)"},children:[e.jsx("span",{className:"font-medium",style:{color:"var(--text-primary)"},children:r("image.result")}),p&&e.jsxs("button",{onClick:ne,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-sm font-medium transition-colors",style:{background:"var(--theme)",color:"white"},children:[e.jsx(je,{className:"w-4 h-4"}),r("common.download")]})]}),e.jsx("div",{className:"p-4",children:C?e.jsxs("div",{className:"relative rounded-xl overflow-hidden",style:{minHeight:"300px"},children:[e.jsx("div",{className:"absolute inset-0 video-loading-mesh"}),e.jsx("div",{className:"absolute inset-0 video-loading-blobs"}),e.jsx("div",{className:"absolute inset-0 video-loading-streak"}),e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[e.jsx(Ne,{className:"w-8 h-8 animate-spin mb-3 text-white/80"}),e.jsxs("p",{className:"text-sm font-medium text-white/90",children:[r(o?"image.restoringAndColorizing":"image.restoring"),"..."]})]})]}):p?e.jsxs("div",{children:[e.jsx(O,{url:p,alt:"Result",className:"w-full rounded-lg",style:{maxHeight:"300px",objectFit:"contain"}}),h&&e.jsxs("div",{className:"mt-3 p-3 rounded-lg text-sm",style:{background:"var(--surface-secondary)"},children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("span",{style:{color:"var(--text-tertiary)"},children:[r("image.colorized"),":"]}),e.jsx("span",{style:{color:"var(--text-primary)"},children:h.colorized?r("common.yes"):r("common.no")})]}),e.jsxs("div",{className:"flex justify-between mt-1",children:[e.jsxs("span",{style:{color:"var(--text-tertiary)"},children:[r("image.processingTime"),":"]}),e.jsx("span",{style:{color:"var(--text-primary)"},children:h.processingTime?`${(h.processingTime/1e3).toFixed(1)}s`:"-"})]})]})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-16",children:[e.jsx(we,{className:"w-12 h-12 mb-4",style:{color:"var(--text-tertiary)"}}),e.jsx("p",{style:{color:"var(--text-tertiary)"},children:r("image.resultWillAppear")})]})})]})]}),e.jsxs("div",{className:"mt-6 p-4 rounded-xl",style:{background:"var(--surface-secondary)",border:"1px solid var(--border-default)"},children:[e.jsx("h3",{className:"font-medium mb-2",style:{color:"var(--text-primary)"},children:r("image.tips")}),e.jsxs("ul",{className:"text-sm space-y-1",style:{color:"var(--text-secondary)"},children:[e.jsxs("li",{children:["⢠",r("image.restoreTip1")]}),e.jsxs("li",{children:["⢠",r("image.restoreTip2")]}),e.jsxs("li",{children:["⢠",r("image.restoreTip3")]}),e.jsxs("li",{children:["⢠",r("image.restoreTip4")]})]})]})]}),e.jsx(ke,{open:Z,onClose:()=>F(!1),requiredCredits:Y.premium,currentCredits:X}),V,e.jsx(Ce,{open:re,onLocal:()=>T("local"),onLibrary:()=>T("library"),onClose:()=>T(null)})]})}export{Ge 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.