PageSourceSearch

https://deep-image.ai/app/assets/EnhancerStudio-BwIbJ0l2.js

js deep-image.ai collected 2026-09-25 14:07:41 UTC 120,472 bytes, 2 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/EnhancerDebugPanel-ieigNOxt.js","assets/index-DHT8ocXi.js","assets/index-0J5qu82O.css","assets/RerollBtn-BPahoQdf.js","assets/_baseClone-CLcwX-rf.js","assets/RerollBtn-DcM1AXx0.css","assets/DebugPanel-CKyk3-2x.js","assets/Input-CTfNZgbW.js","assets/routes-B59S94UY.js","assets/useHandlePaymentModalGA4Events-D4ZazDL-.js","assets/routes-D34f1brb.css","assets/Input-CEKvWR-s.css","assets/ImagesPanelHoverContent-CdOkaddC.js","assets/useDragAndDropUpload-BBapqkk3.js","assets/ImagesPanelHoverContent-C3PC9TX9.css","assets/DownloadButton-DzfOgk6T.js","assets/DownloadButton-BNtbxYRA.css","assets/useWorkspacePageState-Coqh8zQW.js","assets/useToolsCommonTranslation-BfZuY8AC.js","assets/useApplyEnhanceRequest-D3rWtCU7.js","assets/useJobHistory-D3ZXTA5S.js","assets/InvalidResInfo-Dl3hlJ2W.js","assets/cloneDeep-DRG-8RHb.js","assets/useApplyEnhanceRequest-C2dWm5vC.css","assets/UploadErrors-Q8NyUKz6.js","assets/Choice-CwYvbpHy.js","assets/Choice-DtV891-w.css","assets/SelectRadix-BSZTHgK6.js","assets/SelectRadix-DEjX7V9Y.css","assets/Title-BwZhq2WI.js","assets/Title-Cqakt19V.css","assets/clamp-Bd0JiHwK.js","assets/useValidateImages-V4Y70p9X.js","assets/index-BhNLXOHO.js"])))=>i.map(i=>d[i]);
2import{r as l,j as e,jP as Es,jQ as hn,a8 as H,bh as Y,h as Me,Y as fe,bA as Jt,dv as He,eI as Ae,a_ as Te,cK as ws,jR as Cs,Q as ks,b7 as Ss,ck as Ts,a5 as Ns,hp as Is,k as Rs,a9 as As,dl as zt,cV as Oe,F as en,jS as Os,ax as Ln,R as Ne,aG as Un,g_ as Ds,cJ as ye,jT as Ps,bw as Ke,jU as Ms,jV as Ls,jW as Us,aO as Vn,ac as he,aN as Ie,cy as tn,jX as X,jY as B,jZ as M,j_ as Vs,j$ as Fs,k0 as Bs,k1 as Gs,k2 as Ws,cC as $t,bX as zs,k3 as ie,k4 as xe,k5 as $s,aY as qs,k6 as Hs,k7 as Ks,k8 as Ys,k9 as Qs,ka as me,gl as D,kb as qt,kc as ct,gj as Fn,kd as Bn,ke as Xs,kf as Zs,kg as _e,kh as Ht,ki as Js,kj as ea,kk as Gn,kl as ta,cW as ve,km as Nt,kn as pn,bv as nn,ko as na,kp as Wn,kq as sa,kr as de,ks as aa,kt as ra,c6 as sn,aq as ia,ku as oa,kv as la,kw as ca,dm as ua,cB as gn,cz as da,fL as ha,kx as It,dk as pa,gY as ga,ky as ma,gZ as fa,g$ as xa,aw as _a,kz as ja,gx as je,gw as mn,kA as ba,aK as va,kB as ya,kC as Ea,kD as wa,kE as Ca,gX as ka,dI as Sa}from"./index-DHT8ocXi.js";import{aK as zn,T as Ta,as as Na,k as ut,a9 as L,Z as De,aa as T,an as Ia,ac as Ra,aB as Aa,aJ as Oa,aL as Da,aM as Pa,m as fn,l as Rt,aN as Ma,aO as La,aP as Ua,ak as Pe,aQ as Ee,aR as dt,a3 as xn,aS as Va,aT as $n,at as et,D as tt,aU as Kt,aV as Fa,aW as Re,aX as Ba,aY as Ga,aZ as Wa,ah as za,a_ as $a,W as V}from"./RerollBtn-BPahoQdf.js";import{D as _n,u as qa,E as Ha,O as gt}from"./Input-CTfNZgbW.js";import{W as qn,u as Ka,a as Ya,I as Qa,s as jn}from"./ImagesPanelHoverContent-CdOkaddC.js";import{u as O,D as Xa,E as Za,O as Ja,a as Le,b as bn,c as er}from"./DownloadButton-DzfOgk6T.js";import{u as tr,b as vn}from"./useWorkspacePageState-Coqh8zQW.js";import{b as nr,u as an}from"./useToolsCommonTranslation-BfZuY8AC.js";import{u as sr,H as ar,a as rr,s as ir,c as or,E as lr,T as cr,D as ur,b as dr}from"./useApplyEnhanceRequest-D3rWtCU7.js";import{u as mt,a as hr}from"./useDragAndDropUpload-BBapqkk3.js";import{U as pr}from"./UploadErrors-Q8NyUKz6.js";import{O as te}from"./Choice-CwYvbpHy.js";import{C as gr,O as Q,a as ae,S as xt,b as ne,u as _t,c as mr,I as fr,d as xr}from"./routes-B59S94UY.js";import{S as jt}from"./SelectRadix-BSZTHgK6.js";import{O as Ue}from"./Title-BwZhq2WI.js";import{c as yn}from"./clamp-Bd0JiHwK.js";import{u as _r}from"./useValidateImages-V4Y70p9X.js";const Hn=l.createContext(null),ft=l.createContext(void 0),jr=({slots:t})=>{const n=l.useRef(null),s=l.useRef(null),[a,r]=l.useState(null),[i,c]=l.useState(!1),o=l.useCallback(()=>c(!1),[]),[g,d]=l.useState(!1),{t:p}=O(),x=l.useCallback(()=>d(!1),[]);return l.useLayoutEffect(()=>{const u=s.current;if(!u)return;const m=()=>n.current?.style.setProperty("--enhancer-controls-height",`${u.offsetHeight}px`);m();const j=new ResizeObserver(m);return j.observe(u),()=>j.disconnect()},[]),e.jsxs(qn,{appContainerProps:{className:"enhancer-mobile-workspace",ref:n},children:[e.jsx("div",{className:"enhancer-mobile-workspace__editor",children:t.center}),e.jsxs("div",{ref:s,className:"enhancer-mobile-workspace__controls",children:[e.jsxs("div",{className:"enhancer-mobile-workspace__buttons",children:[e.jsxs("button",{type:"button",className:"enhancer-mobile-workspace__pill enhancer-mobile-workspace__pill--images","aria-label":p("mobile.history"),"aria-haspopup":"dialog","aria-expanded":i,onClick:()=>c(!0),children:[e.jsx(Es,{"aria-hidden":"true"}),e.jsx("span",{children:p("mobile.images")}),e.jsx(hn,{"aria-hidden":"true"})]}),e.jsxs("button",{type:"button",className:"enhancer-mobile-workspace__pill","aria-haspopup":"dialog","aria-expanded":g,onClick:()=>d(!0),children:[e.jsx(zn,{"aria-hidden":"true"}),e.jsx("span",{children:p("mobile.options")}),e.jsx(hn,{"aria-hidden":"true"})]})]}),e.jsx("div",{ref:r,className:"enhancer-mobile-workspace__actions"})]}),e.jsx(_n,{open:i,onOpenChange:c,side:"bottom",ariaLabel:p("mobile.history"),title:p("mobile.images"),keepMounted:!0,contentClassName:"enhancer-mobile-history",bodyClassName:"enhancer-mobile-history__body",children:e.jsx(ft.Provider,{value:o,children:t.left})}),e.jsx(_n,{open:g,onOpenChange:d,side:"bottom",title:p("mobile.options"),keepMounted:!0,contentClassName:"enhancer-mobile-options",bodyClassName:"enhancer-mobile-options__body",footer
2:e.jsx(H,{variant:"primary",text:p("mobile.done"),className:"w-100",onClick:x}),children:e.jsx(ft.Provider,{value:x,children:e.jsx(Hn.Provider,{value:a,children:t.right})})})]})},br=10,En=t=>{if(typeof t!="string"||!t)return null;try{const n=new URL(t);return`${n.origin}${n.pathname}`}catch{return t.split(/[?#]/)[0]||null}},wn=(t,n)=>{const s=t.data?.image_id||t.request_data?.image_id;if(s)return s===n.id;const a=new Set([n.img_url,n.thumbnail_url].map(En).filter(r=>!!r));return[t.data?.source,t.data?.storage_source,t.storage_source,t.result?.origin_url].map(En).some(r=>!!(r&&a.has(r)))},Kn={action:Ta.TRANSFORM,imageApp:Y.ENHANCER_STUDIO,pageSize:br},vr=({selectedJobHash:t,onSelectJob:n,onAddImage:s})=>{const a=l.useContext(ft),{t:r}=O(),{i18n:i}=Me(),o=fe(Jt)?._id,g=!!o,d=l.useRef(),p=l.useRef(!1),x=fe(He),{data:u,refetch:m,isFetched:j}=Ae(Y.ENHANCER_STUDIO,{enabled:g}),f=l.useMemo(()=>x.find(K=>K.metadata?.isContextOnly!=="true")||u?.find(K=>K.metadata?.isContextOnly!=="true")||null,[u,x]),h=qa(),_=l.useCallback(()=>{a?.(),h(),n?.(null)},[n,h,a]),v=l.useCallback(K=>{a?.(),n?.(K)},[n,a]),{allJobs:y,hasMoreJobs:E,isLoadingMore:I,showInitialLoading:b,hasLoadedInitialPage:R,loadMore:U,refetchJobs:F,applyUpdatedJobs:$}=Ka({userId:o,enabled:g,query:Kn}),w=l.useRef(null);l.useEffect(()=>{if(!(w.current?.id===o&&w.current!==null)){if(w.current={id:o},!o){n?.(null),Te.removeQueries({queryKey:["jobs_v2"]});return}F(),m()}},[o,F,m,n]);const{perItemQueries:A,perItemByHash:C,notFoundHashes:P}=Ya(y),{visiblePanelJobs:G,uploadedImageHistoryJob:S}=l.useMemo(()=>{if(!f)return{visiblePanelJobs:y,uploadedImageHistoryJob:null};const K=[],se=[];y.forEach(q=>{const ce=C.get(q.hash)||q;wn(q,f)||wn(ce,f)?K.push(ce):se.push(q)});const vt=K.reduce((q,ce)=>!q||ce.timestamp>q.timestamp?ce:q,null);return{visiblePanelJobs:se,uploadedImageHistoryJob:vt}},[y,C,f]);l.useEffect(()=>{if(d.current!==o&&(d.current=o,p.current=!1),!(!o||p.current)){if(t){p.current=!0;return}!R||!j||(p.current=!0,S&&v(S.hash))}},[v,R,j,t,S,o]),l.useEffect(()=>{const K=A.map(se=>se.data).filter(se=>!!se).filter(se=>ws(se)||se.is_failed);K.length!==0&&$(K)},[$,A]);const N=l.useMemo(()=>{if(!f||!g)return null;const K=f.img_url||f.thumbnail_url;return K?{id:f.id,previewUrl:K,alt:f.file_name||r("images_panel.uploaded_image")}:null},[f,g,r]),W=l.useMemo(()=>nr({jobs:G,i18nLanguage:i.language,labels:{today:r("images_panel.today"),yesterday:r("images_panel.yesterday"),loadMore:r("images_panel.load_more"),imageFrom:K=>r("images_panel.image_from",{date:K})},perItemByHash:C,notFoundHashes:P,hasMoreJobs:E,includeHoverContent:!0}),[E,i.language,P,C,r,G]),ee=l.useCallback(()=>{if(S){v(S.hash);return}_()},[v,_,S]),Ye=l.useCallback(()=>{U()},[U]);return e.jsx(Qa,{uploadedImage:N,groups:W,selectedItemId:t,isLoading:b,isLoadingMore:I&&y.length>0,onSelectItem:v,showAddImage:!!s,addButtonIcon:e.jsx(Cs,{size:24}),allowAddWithUploadedImage:!0,onAddImage:()=>{s?.(),a?.()},onUploadedImageClick:N?ee:void 0,onLoadMore:E?Ye:void 0})},yr=({selectedJob:t,rootJobHash:n,latestJobHash:s,selectedHistoryItemId:a,viewMode:r="result",onSelectChildJob:i,onLatestJobHashChange:c,onViewModeChange:o,onHistoryItemSelect:g})=>{const{t:d}=O(),{i18n:p}=Me(),x=l.useCallback(y=>d("history.job_from",{date:new Date(y.timestamp*1e3).toLocaleDateString(p.language)}),[p.language,d]),{items:u,rootItem:m,activeTimelineId:j,showInitialLoading:f,showLoadingMore:h,handleSelectChildJob:_,handleLoadMore:v}=sr({selectedJob:t,rootJobHash:n,latestJobHash:s,selectedHistoryItemId:a,viewMode:r,onSelectChildJob:i,onLatestJobHashChange:c,onViewModeChange:o,onHistoryItemSelect:g,buildItemTitle:x,rootItemTitle:d("history.original_image")});return e.jsx("div",{className:"enhancer-history-panel",children:e.jsx(ar,{items:u,rootItem:m,selectedId:j,isLoading:f,isLoadingMore:h,onSelect:_,onLoadMore:v,animationKey:n})})},Er="enhancer-studio-upload-input",wr=({onImageUploaded:t})=>{const{t:n}=O();return e.jsx(Ha,{app:Y.ENHANCER_STUDIO,title:n("editor.upload.title"),subtitle:n("editor.upload.subtitle"),deviceText:n("editor.upload.your_device"),cloudText:n("editor.upload.cloud_storage"),replaceStaging:!0,onUploadSuccess:t,isSingleUpload:!0,inputId:Er,shouldHandlePaste:s=>!document.activeElement?.closest(".enhancer-reference-panel"),footer:e.jsx(Na,{variant:"inline",app:Y.ENHANCER_STUDIO,replace:!0,onPicked:t})})},Cr=({isVisible:t})=>{const{t:n}=O();return e.jsx(Xa,{isVisible:t,title:n("editor.upload.drop_title")})},kr=()=>{const{t,i18n:n}=O(),[s,a]=l.useState(!1),[r,i]=l.useState(!1),c=ks(),{data:o}=Ss(),g=fe(Jt),d=Ts(g),p=fe(Ns);l.useEffect(()=>{if(g?.id){const u=`enhancer_watermark_info_closed_${g.id}`,m=localStorage.getItem(u)==="true";i(m)}},[g?.id]);const x=()=>{i(!0),g?.id&&localStorage.setItem(`enhancer_watermark_info_closed_${g.id}`,"true")};return l.useEffect(()=>{!r&&g&&!Is(d)&&o&&(o.totalCount>=1||o.results?.length>=1)?s||a(!0):s&&a(!1)},[o,s,g,d,r]),!s||p?null:e.jsx(ut,{title:e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[t("watermark_info.title"),e.jsx("div",{className:"sub-title",children:t("watermark_info.subtitle")})]}),e.jsx("div",{className:"cta",children:e.jsx(H,{sizeVariant:"short",variant:"tertiary",text:t("watermark_info.button"),roundedVariant:"large",onClick:()=>c.push(Rs(As,n.language))})})]}),className:"enhancer-editor-watermark-info",closeFn:x})},Se="Create a photo of the product from first image in a similar scenario as depicted in second image (without the item present in the second image). The product's appearance, including its colour, texture, shape and condition, must remain identical to first image.",Sr="enhance-ui-state",Tr="enhance-selected-backgrounds",Nr={styleDraft:Se,backgroundDraft:"",referenceDraft:null,initialized:!1,styleModeActive:!1},Ir=(t,n)=>{switch(n.type){case"setStyleDraft":return{...t,styleDraft:n.payload};
2case"setBackgroundDraft":return{...t,backgroundDraft:n.payload};case"setReferenceDraft":return{...t,referenceDraft:n.payload};case"setStyleModeActive":return{...t,styleModeActive:n.payload};case"initialize":return{...t,styleDraft:n.payload.styleDraft,backgroundDraft:n.payload.backgroundDraft,styleModeActive:n.payload.styleModeActive,initialized:!0};default:return t}},Yn=l.createContext(null),Rr=({children:t})=>{const n=L(),[s]=De("enhance-tab-id","upscale"),a=s==="style-reference",r=T(y=>!!y.request.reference_image_url),i=T(y=>y.request.reference_image_url),[c,o]=Ia({reducer:Ir,initializerArg:Nr,devtoolsName:"enhance-ui",localStorageKey:Sr,blacklist:["initialized"]}),g=T(y=>{const E=y.request.background.generate;return(Array.isArray(E.context_images)&&E.context_images.length>0||!!y.request.reference_image_url)&&(E.model_type===zt.GOOGLE_GEMINI_PRO||E.adapter_type===Oe.IMG2IMG)}),d=T(y=>y.request.background.generate.description),p=l.useRef(!1);l.useEffect(()=>{p.current||(p.current=!0,g?d&&d!==c.styleDraft?o({type:"initialize",payload:{styleDraft:d||Se,backgroundDraft:c.backgroundDraft,styleModeActive:a}}):o({type:"initialize",payload:{styleDraft:c.styleDraft,backgroundDraft:c.backgroundDraft,styleModeActive:a}}):d&&d!==c.backgroundDraft&&o({type:"initialize",payload:{styleDraft:c.styleDraft||Se,backgroundDraft:d,styleModeActive:!1}}))},[]);const x=l.useRef(null),u=T(y=>y.optionsRemountTrigger),m=l.useRef(u);l.useEffect(()=>{u!==m.current&&(m.current=u,o({type:"initialize",payload:{styleDraft:Se,backgroundDraft:"",styleModeActive:!1}}),x.current=null)},[u,o]);const j=l.useRef(d);l.useEffect(()=>{const y=j.current;if(d!==y&&(j.current=d,x.current===null)){if(g){c.styleDraft===y&&o({type:"setStyleDraft",payload:d||Se});return}if(c.backgroundDraft===y){try{window.localStorage.removeItem(Tr)}catch{}o({type:"setBackgroundDraft",payload:d||""})}}},[d,g,c.styleDraft,c.backgroundDraft,o]),l.useEffect(()=>{if(!(x.current===!1&&g)&&(x.current===!1&&!g&&(x.current=null),g&&!c.styleModeActive)){if(!a)return;o({type:"setStyleModeActive",payload:!0})}},[g,c.styleModeActive,o,a]),l.useEffect(()=>{c.styleModeActive&&(a||g||(o({type:"setStyleModeActive",payload:!1}),x.current=null))},[c.styleModeActive,a,g,o]);const f=l.useCallback(y=>o({type:"setStyleDraft",payload:y??""}),[o]),h=l.useCallback(y=>o({type:"setBackgroundDraft",payload:y??""}),[o]),_=l.useCallback((y,E)=>{const I=E?.force??!1;if(!(y&&!I&&!a))if(x.current=y,o({type:"setStyleModeActive",payload:y}),y){h(""),n("clearBackgroundRemoveOptions"),r||(n("clearBackgroundGenerateOptions"),c.referenceDraft&&n("setReferenceImageUrl",c.referenceDraft));const b=c.styleDraft&&c.styleDraft.trim().length>0?c.styleDraft:Se;b!==c.styleDraft&&f(b)}else n("clearBackgroundGenerateOptions"),o({type:"setReferenceDraft",payload:i??null}),n("setReferenceImageUrl",null),n("setBackgroundGenerateDescription",c.backgroundDraft)},[n,g,d,r,c.styleDraft,c.backgroundDraft,c.referenceDraft,i,h,f,a]),v=l.useMemo(()=>({styleDraft:c.styleDraft,setStyleDraft:f,backgroundDraft:c.backgroundDraft,setBackgroundDraft:h,isStyleModeEnabled:c.styleModeActive,toggleStyleMode:_,isStyleModeActive:c.styleModeActive}),[c.styleDraft,c.backgroundDraft,f,h,c.styleModeActive,_]);return e.jsx(Yn.Provider,{value:v,children:t})},Ve=()=>{const t=l.useContext(Yn);if(!t)throw new Error("useEnhanceUIContext must be used within EnhanceUIContextProvider");return t},rn=()=>{const t=rr(),{toggleStyleMode:n,setStyleDraft:s}=Ve(),a=en(),{i18n:r}=Me(),i=()=>{try{const o=window?.localStorage?.getItem("enhance-tab-id");return o?JSON.parse(o)==="style-reference":!1}catch{return!1}},c=l.useCallback(o=>{if(!o)return null;const g=String(o);if(!g.startsWith("http://")&&!g.startsWith("https://"))return g;try{const d=new URL(g);return d.searchParams.get("thumbnail_url")||d.searchParams.set("thumbnail_url",g),d.toString()}catch{return g}},[]);return l.useCallback((o,g)=>{if(!o)return;const{known:d}=ir(o),p=d?.background?.generate?.description,x=d?.background?.generate?.adapter_type,u=d?.background?.generate?.model_type,m=v=>{const y=or(v);return y?.background?.generate&&(delete y.background.generate.description,delete y.background.generate.adapter_type,delete y.background.generate.model_type),y},j=(v,y)=>{const E=!!x||!!u||typeof p=="string"&&p.trim().length>0||!!v;if(n(E,{force:E&&!i()}),E&&typeof p=="string"&&s(p),y){const I=m(o);t(I,{...g,referenceImageUrl:v})}else t(o,{...g,referenceImageUrl:v})},f=g?.referenceImageUrl??d?.reference_image_url??null,h=c(f),_=()=>{a({type:Ln,notification:Os(r.t("application.error_message.reference_image_unavailable"))})};if(h&&(h.startsWith("http://")||h.startsWith("https://"))){fetch(h,{method:"HEAD"}).then(v=>{v.ok?j(f??null,!1):(_(),j(null,!0))}).catch(()=>{_(),j(null,!0)});return}j(f??null,!1)},[t,n,s,c,a,r])}
2,Ar=t=>{const n=l.useRef(null),s=l.useCallback(i=>{n.current={sourceKey:t,transform:i}},[t]),a=n.current;return{transformState:a&&a.sourceKey===t?a.transform:void 0,onTransformStateChange:s}},ke=({src:t,alt:n,className:s})=>t?e.jsx("img",{src:t,alt:n,className:s}):null,Qn=t=>{if(!t)return null;const[n,s]=t.split("x").map(i=>i.trim()),a=Math.round(Number(n)),r=Math.round(Number(s));return Number.isNaN(a)||Number.isNaN(r)||a<=0||r<=0?null:[a,r]},At=t=>t&&(t.result?.origin_url||t.data?.source||t.data?.storage_source||t.storage_source)||null,Or=t=>{if(!t)return null;if(Array.isArray(t.newSize)&&t.newSize.length===2){const[a,r]=t.newSize;if(a>0&&r>0)return[Math.round(a),Math.round(r)]}const n=Qn(t.data?.dimensions||"");if(n)return n;const s=t.generation_metadata?.image_dimensions?.[0];return s?.width&&s?.height?[Math.round(s.width),Math.round(s.height)]:null},nt={},Dr=Ne.lazy(()=>Un(()=>import("./EnhancerDebugPanel-ieigNOxt.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32])).then(t=>({default:t.EnhancerDebugPanelControl}))),Pr=({showUploader:t=!1,onImageUploaded:n,selectedJobHash:s,rootJobHash:a,latestJobHash:r,selectedHistoryItemId:i,imagesPanelSelectedHash:c,onSelectChildJob:o,onLatestJobHashChange:g,onHistoryItemSelect:d,children:p})=>{const{i18n:x}=Me(),{t:u}=O(),m=en(),j=rn();Ra(Y.ENHANCER_STUDIO);const f=fe(He),{isLoading:h}=Ae(Y.ENHANCER_STUDIO),_=mt(h??!1,500),v=l.useMemo(()=>f.filter(z=>z.metadata?.isContextOnly!=="true"),[f]),y=t?1:Math.max(0,1-v.length),b=!!!fe(Ds)&&y>0,{isDragOver:R,handleDragOver:U,handleDragLeave:F,handleDrop:$}=hr({imageApp:Y.ENHANCER_STUDIO,replaceStaging:!0,maxImagesLeft:y,isEnabled:b,onUploadSuccess:n}),{data:w,isLoading:A,isError:C,error:P}=ye(s||void 0,{refetchInterval:z=>s?Ps(z):!1,retry:(z,Z)=>Z?.response?.status===404?!1:z<3}),G=C&&P?.response?.status===404,S=w?.relations?.root||w?.relations?.parent||a||s,{data:N}=ye(S||void 0),[W,ee]=l.useState("result"),[Ye,K]=l.useState(50),{transformState:se,onTransformStateChange:vt}=Ar(a),q=Aa(w),ce=L(),yt=T(z=>z.isSendingRequest),Qe=T(z=>z.pendingSubmittedJobHash);l.useEffect(()=>{yt&&Qe&&s===Qe&&w?.hash===Qe&&q?.isJobStateSet&&(ce("setIsSendingRequest",!1),ce("setPendingSubmittedJobHash",null))},[ce,yt,q?.isJobStateSet,Qe,w?.hash,s]);const Et=l.useRef(null);l.useEffect(()=>{s||(Et.current=null)},[s]);const Xe=Ke(Jt);Oa(),l.useEffect(()=>{if(t||!s||!N)return;const z=`source-${N.hash}`,Z=Ae.key(Y.ENHANCER_STUDIO),J=Te.getQueryData(Z)||[],Ze=pe=>pe.metadata?.isContextOnly==="true"&&pe.metadata?.originalImageId===N.hash;if(Et.current===z&&f.some(Ze)&&J.some(Ze))return;Et.current=z||null;const be=J.filter(pe=>pe.metadata?.isContextOnly==="true");if(be.length>0){const pe=J.filter(Tt=>Tt.metadata?.isContextOnly!=="true");Te.setQueryData(Z,pe),be.forEach(Tt=>{m(Ms(Tt.id))})}const Je=At(N),St=Da(Je?{...N,storage_source:Je}:N,Y.ENHANCER_STUDIO,!1);if(St){const pe={...St,app:Y.ENHANCER_STUDIO,metadata:{...St.metadata,isContextOnly:"true",originalImageId:N.hash}};Pa(pe,!1)}},[m,f,N,s,t]);const ue=l.useMemo(()=>At(N||w),[N,w]),re=l.useMemo(()=>w?w.result?.result_url:null,[w]),Be=l.useMemo(()=>v.length===0?null:v[0].img_url||v[0].thumbnail_url||null,[v]),cs=!1,wt=l.useMemo(()=>!i||!s?!1:i===`root-${s}`,[i,s]),we=At(N)||Be||ue,Ge=!!(yt||s&&w&&q?.isProcessing&&!wt&&W!=="source"),us=l.useMemo(()=>{if(wt){const J=Qn(w?.data?.dimensions||"");if(J)return{width:J[0],height:J[1]}}const z=Or(w);if(z)return{width:z[0],height:z[1]};const Z=v[0];return Z?.metadata?.width&&Z.metadata.height?{width:Z.metadata.width,height:Z.metadata.height}:null},[wt,w,v]);l.useEffect(()=>{ee("result")},[a]),l.useEffect(()=>{i&&!i.startsWith("root-")&&ee("result")},[i]);const cn=l.useMemo(()=>Ge&&we?"single":G?"error":s?!w&&A||!w||w&&!q?.isJobStateSet?"loading":w&&q?.isProcessing||W==="source"||w.is_failed||!re?"single":"compare":!s&&!Xe?._id?"empty":!s&&_&&f.length===0?"loading":!s&&f.length===0?"empty":"single",[G,f.length,_,A,w,s,q?.isProcessing,q?.isJobStateSet,re,cs,Xe,Ge,we,W]),ds=mt(cn==="loading",500),Ct=t?"empty":ds?"loading":cn,hs=s&&w&&q?.isProcessing?e.jsx(lr,{isJobSelected:!0,isQueued:!!q?.isWaitingInQueue}):void 0,ps=e.jsx(wr,{onImageUploaded:n}),gs=e.jsx(ut,{type:Rt.ERROR,variant:fn.ERROR.WHITE_ON_TERTIARY,title:u("editor.job_not_found_title"),children:u("editor.job_not_found_desc")}),ms=l.useMemo(()=>Ge&&we?e.jsx(ke,{src:we,alt:u("editor.source_alt"),className:"enhancer-editor__single-image"}):s&&ue&&W==="source"?e.jsx(ke,{src:ue,alt:u("editor.source_alt"),className:"enhancer-editor__single-image"}):s&&ue&&(w?.is_failed||!re)?e.jsx(ke,{src:ue,alt:u("editor.source_alt"),className:"enhancer-editor__single-image"}):s&&re&&W==="result"?e.jsx(ke,{src:re,alt:u("editor.result_alt"),className:"enhancer-editor__single-image"}):Be?e.jsx(ke,{src:Be,alt:u("editor.uploaded_alt"),className:"enhancer-editor__single-image"}):null,[ue,re,Be,s,W,w?.is_failed,Ge,we,u]),fs=l.useMemo(()=>
2{if(!(!ue||!re))return{compareView:e.jsx(Ma,{className:"enhancer-editor__compare-fit",imageBefore:ue,imageAfter:re,comparePosition:Ye,onComparePositionChange:K,disableTransform:!0,hideControls:!0,children:p}),soloView:e.jsx(ke,{src:re,alt:u("editor.result_alt"),className:"enhancer-editor__single-image"})}},[re,ue,p,Ye,u]),Ce=l.useCallback(async z=>{try{const Z=ye.key(z);let J=Te.getQueryData(Z);if(J||(J=await Ls(z)),J?.request_data){const Ze=J.request_data,be=J?.data?.reference_image_url_resolved,Je={...Ze,...typeof be=="string"&&(be.startsWith("http://")||be.startsWith("https://"))?{reference_image_url:be}:{}};j(Je)}else J?.data&&j(J.data)}catch(Z){console.error("Error applying job settings:",Z)}},[j]),kt=l.useRef(null);l.useEffect(()=>{if(!c){kt.current=null;return}w?.hash!==c||kt.current===c||(kt.current=c,Ce(c))},[Ce,c,w?.hash]);const un=l.useCallback(z=>{if(d?.(z),!z||z==="load-more")return;const Z=z.startsWith("root-")?z.replace("root-",""):z;Ce(Z)},[Ce,d]),xs=l.useMemo(()=>s?e.jsx(yr,{selectedJob:w,rootJobHash:a,latestJobHash:r,selectedHistoryItemId:i,viewMode:W,onSelectChildJob:o,onLatestJobHashChange:g,onViewModeChange:ee,onHistoryItemSelect:un}):null,[s,un,g,o,a,r,i,w,W]),_s=l.useMemo(()=>w?e.jsx(Za,{job:w,isSourceView:W==="source"||!!i?.startsWith("root-"),user:Xe,onApplyJobSettings:Ce}):null,[w,i,W,Xe,Ce]),dn=!t&&Ge,js=e.jsxs(cr,{children:[e.jsx(ur,{alertStyle:nt,uploadErrors:e.jsx(pr,{alertStyle:nt})}),e.jsx(kr,{}),w&&!w.is_failed&&La(w)&&Ct!=="loading"&&W!=="source"&&e.jsx(ut,{style:nt,type:Rt.WARNING,title:u("editor.blocked_title"),children:u("editor.blocked_desc")}),w&&w.is_failed&&Ct!=="loading"&&W!=="source"&&e.jsx(ut,{style:nt,type:Rt.ERROR,variant:fn.ERROR.WHITE_ON_TERTIARY,title:w.error_message??x.t("application.error_message.transform_part_1"),children:w.error_message?null:e.jsxs(e.Fragment,{children:[x.t("application.error_message.transform_part_2")," ",x.t("application.error_message.transform_part_3")]})})]}),[bs,vs]=l.useState(!0),ys=fe(Us);return e.jsxs("section",{className:"enhancer-editor",style:{position:"relative"},onDragOver:b?U:void 0,onDragLeave:b?F:void 0,onDrop:b?$:void 0,children:[e.jsx(Cr,{isVisible:R&&b}),e.jsx(Ua,{mode:Ct,loadingContent:hs,emptyContent:ps,errorContent:gs,singleView:ms,compareConfig:fs,showCompareToggle:!0,defaultCompareMode:bs,onCompareModeChange:vs,hideControls:dn,contentKey:a||s||we||Be||"",disableCompareModeAnimation:!0,disableContentAnimation:!0,topOverlay:t?void 0:js,bottomOverlay:t?void 0:xs,resolutionDimensions:us??void 0,extraControls:_s,transformState:se,onTransformStateChange:vt}),e.jsx(Vn,{children:dn&&e.jsx(dr,{isQueued:!!q?.isWaitingInQueue})}),ys&&e.jsx(Ne.Suspense,{fallback:null,children:e.jsx(Dr,{selectedJobHash:s})})]})},Xn=Ne.forwardRef(({icon:t,text:n,isSelected:s,hasActiveOptions:a,children:r,disabled:i,...c},o)=>{const g=!!i,d=g||s;return e.jsxs("button",{...c,ref:o,className:he("item",s&&"item--selected",g&&"item--disabled",c.className),disabled:d,"aria-label":typeof n=="string"?n:void 0,children:[a&&e.jsx("span",{className:"item__indicator","aria-label":"Has active options"}),t,r]})});Xn.displayName="OptionsItem";const Mr=({items:t,defaultItemId:n,action:s,contentPrefix:a,storageKey:r,remountTrigger:i,className:c,itemsTopChildren:o,itemsBottomChildren:g})=>{const d=l.useMemo(()=>t.filter(E=>!E.isHidden),[t]),p="__tabbed-options-noop__",[x,u]=De(r??p,n),[m,j]=Ne.useState(n),f=!!r,h=f?x:m;Ne.useEffect(()=>{f||window.localStorage.removeItem(p)},[f,p]);const _=l.useCallback(E=>{f?u(E):j(E)},[f,j,u]);Ne.useEffect(()=>{const E=d.find(I=>I.id===h);if(E&&E.isDisabled){const I=d.find(b=>!b.isDisabled);I&&_(I.id)}},[h,d,_]);const v=l.useMemo(()=>d.find(E=>E.id===h)||d[0],[d,h]),y=l.useMemo(()=>{if(!v)return null;const E=v.render();return e.jsxs(Ie.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},exit:{opacity:0,x:-20},transition:{duration:.2,ease:"easeInOut"},className:"content",children:[a&&a,E]},v.id)},[a,v]);return e.jsx(Ja,{className:c,actionComponent:s,contentComponent:y,itemsComponent:e.jsxs(e.Fragment,{children:[o,d.map(E=>
2{const I=E.id===v?.id,b=!!E.isDisabled||I,R=e.jsx(Xn,{id:E.id,"data-testid":E.id,"aria-label":E.label,onClick:()=>{E.isDisabled||_(E.id)},isSelected:I,text:E.label,icon:E.icon,hasActiveOptions:E.hasActiveOptions,disabled:E.isDisabled,children:I&&e.jsx(Ie.div,{layoutId:"tab-indicator",className:"item__background",transition:{type:"spring",stiffness:320,damping:28}})}),U=b?e.jsx("span",{style:{display:"inline-flex",cursor:E.isDisabled?"not-allowed":void 0},children:R}):R;return e.jsx(tn,{content:e.jsx(X,{children:e.jsx("span",{children:E.tooltip||E.label})}),contentProps:{side:"left",align:"center"},delayDuration:E.isDisabled?0:300,children:U},E.id)}),g]})},i)},Yt={[B.A0]:{width:841,height:1189},[B.A5]:{width:148,height:210},[B.A6]:{width:105,height:148},[B.B5]:{width:176,height:250},[B.LETTER]:{width:215.9,height:279.4},[B.LEGAL]:{width:215.9,height:355.6},[B.PHOTO_10_15]:{width:100,height:150},[B.PHOTO_13_18]:{width:130,height:180},[B.PHOTO_20_30]:{width:200,height:300},[B.A1]:{width:594,height:841},[B.A2]:{width:420,height:594},[B.A3]:{width:297,height:420},[B.A4]:{width:210,height:297}},Zn=(t,n)=>{const s=Yt[t];return s?n&&n.width>n.height?{width:s.height,height:s.width}:s:null},Ot=[{value:B.A4,label:"A4"},{value:B.PHOTO_10_15,label:"10 × 15 cm"},{value:B.A3,label:"A3"},{value:B.LETTER,label:"US Letter"},{value:B.A5,label:"A5"},{value:B.PHOTO_13_18,label:"13 × 18 cm"},{value:B.PHOTO_20_30,label:"20 × 30 cm"},{value:B.A6,label:"A6"},{value:B.LEGAL,label:"US Legal"},{value:B.B5,label:"B5"},{value:B.A2,label:"A2"},{value:B.A1,label:"A1"},{value:B.A0,label:"A0"}],Lr=({value:t,onChange:n})=>{const{t:s}=O(),a=l.useRef([]),r=[{value:M.OFF,key:"off",icon:e.jsx(Vs,{}),hint:"1:1"},{value:M.RATIO,key:"scale",icon:e.jsx(Fs,{}),hint:"2× · 3× · 4×"},{value:M.WIDTH_AND_HEIGHT,key:"width_height",icon:e.jsx(Bs,{}),hint:"px"},{value:M.PAPER,key:"paper",icon:e.jsx(Gs,{}),hint:"mm · DPI"}];return e.jsx("div",{className:"upscale-method-picker",role:"radiogroup","aria-label":s("options.upscale.method.label"),children:r.map((i,c)=>e.jsxs("button",{ref:o=>{a.current[c]=o},type:"button",role:"radio","aria-checked":t===i.value,"aria-label":s(`options.upscale.method.${i.key}`),tabIndex:t===i.value?0:-1,onClick:()=>n(i.value),onKeyDown:o=>{if(!["ArrowRight","ArrowLeft","ArrowUp","ArrowDown"].includes(o.key))return;o.preventDefault();const g=o.key==="ArrowLeft"||o.key==="ArrowUp"?-1:1,d=(c+g+r.length)%r.length;n(r[d].value),a.current[d]?.focus()},children:[e.jsx("span",{className:"upscale-method-picker__icon","aria-hidden":"true",children:i.icon}),e.jsxs("span",{className:"upscale-method-picker__copy",children:[e.jsx("strong",{children:s(`options.upscale.method.${i.key}`).replace("&"," & ")}),e.jsx("small",{children:i.hint})]})]},i.value))})},Ur=()=>{const t=T(r=>r.request.height),n=L(),s=String(t).includes("%")?parseInt(String(t))/100:null,a=r=>{const i=r?`${r}00%`:null;n("setWidthHeight",{height:i,width:i})};return e.jsx("div",{className:"ratio-options",children:Object.entries(Ws).filter(([r])=>isNaN(Number(r))).map(([r,i])=>e.jsx(gr,{text:`${i}
2x`,pressed:i===s,onPressedChange:()=>{s!==i&&a(i)}},i))})},st=t=>{const n=parseInt(t)||null;return n&&n<=0?1:n},Vr=({onManualDimensionChange:t})=>{const{t:n}=O(),s=T(p=>p.request.height),a=T(p=>p.request.width),[r,i]=l.useState(s),[c,o]=l.useState(a),g=L(),d=Pe(()=>g("setWidthHeight",{width:c,height:r}));return l.useEffect(()=>{i(s)},[s]),l.useEffect(()=>{o(a)},[a]),e.jsxs("div",{className:"width-weight-options",children:[e.jsx(gt,{type:"number",id:"upscale-width",label:n("options.upscale.width"),hideArrows:!0,placeholder:n("options.upscale.auto"),rightText:"px",value:c||"",onChange:p=>{o(st(p.target.value)),t?.("width",st(p.target.value)),d()}}),e.jsx(gt,{id:"upscale-height",label:n("options.upscale.height"),type:"number",hideArrows:!0,placeholder:n("options.upscale.auto"),rightText:"px",value:r||"",onChange:p=>{i(st(p.target.value)),t?.("height",st(p.target.value)),d()}})]})},Fr=t=>{const n=parseInt(t)||null;return n&&n<=0?1:n},Br=()=>{const{t}=O(),n=T(i=>i.request.dpi),s=T(i=>i.request.print_size),a=L(),r=i=>e.jsxs("span",{className:"paper-options__choice",children:[e.jsx("span",{children:i.label})," ",e.jsxs("small",{children:[Yt[i.value].width," × ",Yt[i.value].height," mm"]})]});return e.jsxs("div",{className:"paper-options",children:[e.jsx(gt,{label:t("options.upscale.dpi"),id:"upscale-dpi",type:"number",hideArrows:!0,placeholder:t("options.upscale.auto"),rightText:"DPI",value:n||"",onChange:i=>{s||a("setPrintSize",B.A4),a("setDPI",Fr(i.target.value)||null)}}),e.jsx(Q,{as:"div",text:t("options.upscale.international_papers"),children:e.jsx("div",{"data-base-ui-swipe-ignore":!0,children:e.jsx(jt,{label:t("options.upscale.international_papers"),options:Ot,value:Ot.find(i=>i.value===s)||Ot[0],onChange:i=>a("setPrintSize",i?.value||B.A4),renderOption:r,renderValue:r})})})," "]})},le=({label:t,...n})=>{const s=e.jsx(jt,{...n,label:t});return e.jsx("div",{className:"select-wrapper",children:t?e.jsx(Q,{text:t,children:s}):s})},Dt=$t.V1,Pt="enhance-options-upscale-model-type-memory",Jn=()=>{const{t}=O(),n=T(m=>m.request.upscale_parameters.type),s=l.useMemo(()=>[{label:t("options.upscale.content_types.general",{defaultValue:"General"}),value:$t.V1},{label:t("options.upscale.model_types.documents"),value:$t.TEXT_X4}],[t]),a=T(m=>m.request),r=T(m=>m.request.generative_upscale),i=L(),c=!!(a?.height||a?.width||a?.dpi||a?.print_size);l.useEffect(()=>{if(r){n!==null&&i("setUpscaleParametersType",{type:null});return}if(c){if(n===null)try{const m=localStorage.getItem(Pt),f=(m?JSON.parse(m):null)?.type??Dt;i("setUpscaleParametersType",{type:f})}catch{i("setUpscaleParametersType",{type:Dt})}}else n!==null&&i("setUpscaleParametersType",{type:null})},[i,c,r,n]);const o=m=>{const j=m?.value??null;try{localStorage.setItem(Pt,JSON.stringify({type:j}))}catch{}c&&!r&&i("setUpscaleParametersType",{type:j})},g=!!r||!c,d=s[0],x=n??(()=>{try{const m=localStorage.getItem(Pt);return(m?JSON.parse(m):null)?.type??null}catch{return null}})()??Dt,u=s.find(m=>m.value===x)||d;return e.jsx(le,{label:t("options.upscale.content_type",{defaultValue:"Content type"}),isDisabled:g,options:s,value:u,onChange:o})},es="enhance-options-upscale-type-memory",ts=()=>{try{const t=localStorage.getItem(es);return t?JSON.parse(t):{}}catch{return{}}},Mt=t=>{try{const n=ts();localStorage.setItem(es,JSON.stringify({...n,...t}))}catch{}},Cn=(t,n)=>{if(t)switch(t){case M.RATIO:Mt({ratio:{width:n.width,height:n.height}});break;case M.WIDTH_AND_HEIGHT:Mt({widthAndHeight:{width:n.width,height:n.height}});break;case M.PAPER:Mt({paper:{dpi:n.dpi,print_size:n.print_size}});break}},Gr=(t,n)=>{const s=ts();switch(t){case M.OFF:{n("clearPrintSizeAndDpi"),n("clearWidthHeight");break}case M.RATIO:{const a=s.ratio||{width:null};n("clearPrintSizeAndDpi");const r=a.width&&String(a.width).includes("%")?a.width:"200%";n("setWidthHeight",{width:r,height:r});break}case M.WIDTH_AND_HEIGHT:{const a=s.widthAndHeight||{width:null,height:null};n("clearPrintSizeAndDpi"),n("setWidthHeight",{width:a.width??null,height:a.height??null});break}case M.PAPER:{const a=s.paper||{dpi:null,print_size:null};n("clearWidthHeight"),n("setDPI",a.dpi??null),n("setPrintSize",a.print_size??B.A4);break}}},Wr=(t,n,s)=>{switch(t){case M.OFF:return null;case M.RATIO:return e.jsx(Ur,{});case M.WIDTH_AND_HEIGHT:return e.jsxs(e.Fragment,{children:[e.jsx(Vr,{onManualDimensionChange:s}),n]});case M.PAPER:return e.jsx(Br,{});default:return null}},Qt=t=>String(t.height).includes("%")||String(t.width).includes("%")?M.RATIO:t.dpi||t.print_size?M.PAPER:t.height||t.width?M.WIDTH_AND_HEIGHT:M.OFF,zr=({studio:t=!1,widthHeightOptions:n,onManualDimensionChange:s})=>{const{t:a}=O(),r=T(p=>p),i=L(),[c,o]=l.useState(Qt(r.request)||M.OFF),g=zs(c);l.useEffect(()=>{const p=Qt(r.request);if(p&&p!==c){if(p===M.OFF&&(c===M.WIDTH_AND_HEIGHT||c===M.PAPER))return;o(p)}},[r.request.width,r.request.height,r.request.dpi,r.request.print_size]),l.useEffect(()=>{Cn(c,r.request)},[c,r.request.width,r.request.height,r.request.dpi,r.request.print_size,r.request]);const d=p=>{const x=p||M.OFF;Cn(g||c,r.request),o(x),Gr(x,i)};return e.jsx(e.Fragment,{children:e.jsxs("div",{className:t?"upscale-type-chooser upscale-type-chooser--studio":"upscale-type-chooser",children:[e.jsx(Q,{as:"div",text:a("options.upscale.method.label"),children:e.jsxs(ae,{children:[t?e.jsx(Lr,{value:c,onChange:d}):e.jsxs(te.Group,{type:"single",value:c,onValueChange:d,children:[e.jsx(te.GroupItem,{label:a("options.upscale.method.off"),value:M.OFF,"aria-label":a("options.upscale.method.off")}),e.jsx(te.GroupItem,{label:a("options.upscale.method.scale"),value:M.RATIO,"aria-label":a("options.upscale.method.scale")}),e.jsx(te.GroupItem,{label:a("options.upscale.method.paper"),value:M.PAPER,"aria-label":a("options.upscale.method.paper")}),e.jsx(te.GroupItem,{label:a("options.upscale.method.width_height"),value:M.WIDTH_AND_HEIGHT,"aria-label":a("options.upscale.method.width_height")})]}),Wr(c,n,s),!t&&e.jsx(Jn,{})]})})," "]})})},kn=25.4,ht=t=>{if(!t)return null;const s=t.toLowerCase().replace(/\s+/g,"").split("x");if(s.length!==2)return null;const a=Number(s[0]),r=Number(s[1]);return!Number.isFinite(a)||!Number.isFinite(r)||a<=0||r<=0?null:{width:a,height:r}},$r=t=>{if(!t)return null;if(t.is_failed||!t.result){const n=ht(t.data?.dimensions);if(n)return n}return t.newSize?{width:t.newSize[0],height:t.newSize[1]}:null},Sn=t=>{if(t==null||t==="")return null;const n=typeof t=="number"?t:Number(t);return Number.isFinite(n)?n:null},Tn=t=>{if(typeof t=="string"&&t.includes("%")){const n=Number(t.replace("%","").trim());if(Number.isFinite(n))return n/100}return typeof t=="number"&&Number.isFinite(t)?t:null},qr=(t,n)=>{const s=Qt(n);if(!s||s===M.OFF)return t;if(s===M.RATIO){if(!t)return null;const a=Tn(n.height)??Tn(n.width)??1;return a<=0?null:{width:Math.max(1,Math.round(t.width*a)),height:Math.max(1,Math.round(t.height*a))}}if(s===M.WIDTH_AND_HEIGHT){const a=Sn(n.width),r=Sn(n.height);return a&&r?{width:Math.max(1,Math.round(a)),height:Math.max(1,Math.round(r))}:t?a?{width:Math.max(1,Math.round(a)),height:Math.max(1,Math.round(a/t.width*t.height))}:r?{width:Math.max(1,Math.round(r/t.height*t.width)),height:Math.max(1,Math.round(r))}:{width:t.width,height:t.height}:a&&r?{width:Math.round(a),height:Math.round(r)}:null}if(s===M.PAPER){const a=n.print_size,r=n.dpi??300;if(!a||r<=0)return null;const i=Zn(a,t);return i?{width:Math.max(1,Math.floor(i.width/kn*r)),height:Math.max(1,Math.floor(i.height/kn*r))}:null}return null},bt=({selectedJobHash:t,selectedHistoryItemId:n,rootJobHash:s})=>{const a=T(j=>j.request),{data:r}=ye(t??void 0),{data:i}=ye(s??void 0),c=Ke(He),o=l.useMemo(()=>
2{if(t){const j=c.find(f=>f.metadata?.isContextOnly==="true"&&(!s||f.metadata.originalImageId===s));if(j)return j;if(s)return null}return c.find(j=>j.metadata?.isContextOnly!=="true")||null},[c,t,s]),g=!!n&&!!t&&n===`root-${t}`,d=l.useMemo(()=>{if(o?.metadata?.width&&o.metadata.height)return{width:o.metadata.width,height:o.metadata.height};const j=ht(i?.data?.dimensions);if(j)return j;if(g){const h=ht(r?.data?.dimensions);if(h)return h}const f=ht(r?.data?.dimensions)||$r(r);return f||null},[r,i,o,g]),p=l.useMemo(()=>qr(d,a),[d,a]),x=i||r,u=x?.data,m=o?.img_url||x?.result?.origin_url||u?.source||u?.storage_source||x?.storage_source||null;return{sourceResolution:d,targetResolution:p,sourceUrl:m}},Hr=({sections:t,label:n})=>{const[s,a]=l.useState(0),r=l.useRef(null),i=l.useRef([]),c=l.useId(),o=l.useRef(s);o.current=s,l.useLayoutEffect(()=>{const d=r.current;if(!d)return;const p=new ResizeObserver(()=>{d.scrollTo?.({left:d.clientWidth*o.current,behavior:"auto"})});return p.observe(d),()=>p.disconnect()},[]);const g=d=>{a(d);const p=r.current;p&&p.scrollTo?.({left:p.clientWidth*d,behavior:window.matchMedia("(prefers-reduced-motion: reduce)").matches?"auto":"smooth"})};return e.jsxs("div",{className:"canvas-controls",children:[e.jsx("div",{ref:r,className:"canvas-controls__pages","data-base-ui-swipe-ignore":!0,onScroll:d=>{const p=d.currentTarget;p.clientWidth&&a(Math.min(t.length-1,Math.round(p.scrollLeft/p.clientWidth)))},children:t.map((d,p)=>e.jsx("section",{className:"canvas-controls__page",role:"tabpanel",id:`${c}-panel-${d.id}`,"aria-labelledby":`${c}-tab-${d.id}`,"aria-hidden":p!==s,...p!==s?{inert:""}:{},children:d.content},d.id))}),e.jsx("div",{className:"canvas-controls__tabs",role:"tablist","aria-label":n,children:t.map((d,p)=>e.jsxs("button",{ref:x=>{i.current[p]=x},type:"button",role:"tab",id:`${c}-tab-${d.id}`,"aria-controls":`${c}-panel-${d.id}`,"aria-selected":s===p,tabIndex:s===p?0:-1,onClick:()=>g(p),onKeyDown:x=>{let u=p;if(x.key==="ArrowRight")u=(p+1)%t.length;else if(x.key==="ArrowLeft")u=(p+t.length-1)%t.length;else if(x.key==="Home")u=0;else if(x.key==="End")u=t.length-1;else return;x.preventDefault(),g(u),i.current[u]?.focus()},children:[e.jsx("span",{"aria-hidden":"true",children:d.icon}),d.label]},d.id))})]})},k=t=>e.jsx("div",{className:"options-slider-wrapper",children:e.jsx(xt,{...t})});k.Track=xt.Track;k.Range=xt.Range;k.Thumb=xt.Thumb;function Fe({enabled:t,storageKey:n,read:s,write:a,toggle:r}){const i=l.useCallback(o=>{try{const g=localStorage.getItem(n),d=g?JSON.parse(g):{};localStorage.setItem(n,JSON.stringify({...d,...o}))}catch{}},[n]);return{onToggle:l.useCallback(()=>{if(t){const o=s();try{localStorage.setItem(n,JSON.stringify(o))}catch{}a(null),r()}else{r();try{const o=localStorage.getItem(n);if(!o)return;const g=JSON.parse(o);a(g)}catch{}}},[t,n,s,a,r]),persist:i}}const at=9,Kr=({sliderOnly:t=!1})=>{const{t:n}=O(),s=T(u=>u.request.generative_upscale),a=T(u=>u.request.background?.generate?.adapter_type),r=T(u=>u.request.upscale_strength),i=L(),[c,o]=l.useState(r??null),{onToggle:g,persist:d}=Fe({enabled:!!s,storageKey:"enhance-options-generative-upscale-memory",read:()=>({upscale_strength:r??null}),write:u=>{u?i("setUpscaleStrength",u.upscale_strength):i("setUpscaleStrength",null)},toggle:()=>i("setGenerativeUpscale",s?null:!0)}),p=Pe(()=>{i("setUpscaleStrength",c)});l.useEffect(()=>{o(r??null)},[r]),l.useEffect(()=>{s?(a||i("setBackgroundGenerateAdapterType",Oe.UPSCALE),r===null&&i("setUpscaleStrength",1)):a===Oe.UPSCALE&&i("setBackgroundGenerateAdapterType",null)},[a,i,s,r]);const x=l.useCallback(u=>u.toString(),[]);if(t){const u=s?yn(r??1,1,at):0;return e.jsxs(k,{label:n("options.upscale.generative_upscale"),value:[u],min:0,max:at,step:1,showValue:!0,renderValue:m=>m?.[0]?String(m[0]):n("options.upscale.method.off"),onValueChange:m=>{const j=m[0];i("setUpscaleStrength",j||null),i("setGenerativeUpscale",j>0?!0:null)},children:[e.jsx(k.Track,{children:e.jsx(k.Range,{})}),e.jsx(k.Thumb,{})]})}return e.jsx(e.Fragment,{children:e.jsx(ne,{containerProps:{style:{marginTop:8}},text:n("options.upscale.generative_upscale"),checked:!!s,onChange:g,children:s?e.jsx(e.Fragment,{children:e.jsxs(k,{label:n("options.upscale.upscale_strength"),value:[yn((c??1)||1,1,at)],step:1,min:1,max:at,onValueChange:u=>{o(u[0]),d({upscale_strength:u[0]}),p()},showValue:!0,renderValue:u=>x(u?.[0]??0),children:[e.jsx(k.Track,{children:e.jsx(k.Range,{})}),e.jsx(k.Thumb,{})]})}):null})})},Yr=({value:t})=>{const n=l.useId().replace(/:/g,""),s=t.startsWith("crop:"),a=t==="canvas:outpainting",r=t==="auto"||t==="canvas"||a,i=t==="cover";return e.jsxs("svg",{className:"framing-choice__icon",viewBox:"0 0 64 48","aria-hidden":"true",children:[e.jsx("defs",{children:e.jsx("clipPath",{id:n,children:e.jsx("rect",{x:"16",y:"4",width:"32",height:"40",rx:"2"})})}),e.jsx("rect",{className:"framing-icon__frame",x:"16",y:"4",width:"32",height:"40",rx:"2",strokeDasharray:"3 2"}),a&&e.jsxs(e.Fragment,{children:[e.jsx("rect",{className:"framing-icon__generative",x:"17",y:"5",width:"30",height:"38"}),e.jsx("path",{className:"framing-icon__accent",d:"m39 5 2 4 4 2-4 2-2 4-2-4-4-2 4-2z"})]}),r||t==="bounds"?e.jsxs("g",{children:[e.jsx("rect",{className:r?"framing-icon__sky framing-icon__sky--framed":"framing-icon__sky framing-icon__sky--highlighted",x:"16",y:"13",width:"32",height:"22",rx:"1"}),e.jsx("path",{className:"framing-icon__ground",d:"m17 34 10-13 8 8 5-6 7 11"}),e.jsx("circle",{className:"framing-icon__sun",cx:"39",cy:"19",r:"3"})]}):i?e.jsxs("g",{children:[e.jsx("rect",{className:"framing-icon__sky framing-icon__sky--highlighted",x:"3",y:"4",width:"58",height:"40",rx:"2"}),e.jsx("path",{className:"framing-icon__ground",d:"m4 43 18-26 14 15 9-13 15 24"}),e.jsx("rect",{className:"framing-icon__inner-frame",x:"16",y:"4",width:"32",height:"40",strokeDasharray:"3 2"})]}
2):s?e.jsxs("g",{clipPath:`url(#${n})`,children:[e.jsx("rect",{className:"framing-icon__sky",x:"3",y:"4",width:"58",height:"40"}),t==="crop:center"?e.jsx("path",{className:"framing-icon__ground",d:"m3 43 19-30 16 21 13-15 11 24"}):e.jsxs(e.Fragment,{children:[e.jsx("circle",{className:"framing-icon__ground",cx:t==="crop:item"?32:27,cy:"17",r:"6"}),e.jsx("path",{className:"framing-icon__ground",d:t==="crop:item"?"M22 43v-9a10 10 0 0 1 20 0v9":"M17 43v-9a10 10 0 0 1 20 0v9"})]}),e.jsx("rect",{className:"framing-icon__crop-frame",x:"16.5",y:"4.5",width:"31",height:"39"})]}):null]})},Qr=()=>{const{t}=O(),n=T(u=>u.request.fit),s=L(),a=!!n&&typeof n=="object"&&"canvas"in n&&n.canvas==="outpainting",[r,i]=l.useState(ie.CANVAS),c=a&&n&&typeof n=="object"&&!("crop"in n)?r:n,o=u=>!u||u===ie.CANVAS||u===ie.BOUNDS||typeof u=="object"&&"crop"in u&&(u.crop===xe.ITEM||u.crop===xe.CONTENT),g=u=>{a&&o(u)?u&&typeof u=="object"&&"crop"in u?s("setFit",{...u,canvas:"outpainting"}):(i(u),s("setFit",{canvas:"outpainting"})):s("setFit",u)},d=c?typeof c=="string"?c:"crop"in c?`crop:${c.crop}`:ie.CANVAS:"auto",p=[{value:"auto",label:t("options.framing.auto"),fit:null},...Object.values(ie).map(u=>({value:u,label:t(`options.framing.types.${u}`),fit:u})),...Object.values(xe).map(u=>({value:`crop:${u}`,label:t(`options.framing.types.crop_${u}`),fit:{crop:u}}))],x=u=>e.jsxs("span",{className:"framing-choice",children:[e.jsx(Yr,{value:u.value}),e.jsxs("span",{className:"framing-choice__text",children:[e.jsx("span",{children:u.label})," ",e.jsx("small",{children:t(`options.framing.descriptions.${u.value.replace(":","_")}`)})]})]});return e.jsxs(e.Fragment,{children:[e.jsx(Q,{as:"div",text:t("options.framing.type"),children:e.jsx("div",{"data-base-ui-swipe-ignore":!0,children:e.jsx(jt,{label:t("options.framing.type"),options:p,value:p.find(u=>u.value===d)||p[0],onChange:u=>g(u?.fit??null),renderOption:x,renderValue:x,className:"framing-choice__trigger"})})}),o(c)&&e.jsx(ne,{text:t("options.framing.types.generative_fill"),checked:a,onChange:u=>{c&&typeof c=="object"&&"crop"in c?u?s("setFit",{crop:c.crop,canvas:"outpainting"}):s("setFit",{crop:c.crop}):u?(i(c),s("setFit",{canvas:"outpainting"})):s("setFit",c)}})]})},Xr=()=>{const{t}=O(),n=T(a=>a.request.padding),s=L();return e.jsx(Q,{as:"div",text:t("options.framing.border"),children:e.jsx(ae,{children:e.jsxs(k,{label:t("options.framing.padding"),value:[parseInt(n||"0")],min:0,max:30,step:1,onValueChange:a=>{let r=null;a[0]>0&&(r=`${a[0]}%`),s("setPadding",r)},showValue:!0,renderValue:a=>`${a?.[0]}%`,children:[e.jsx(k.Track,{children:e.jsx(k.Range,{})}),e.jsx(k.Thumb,{})]})})})},ns="enhance-options-background-color-memory",ss=()=>{const t=T(d=>d.request.background.color),n=L(),{onToggle:s,persist:a}=Fe({enabled:!!t,storageKey:ns,read:()=>({color:t??"white"}),write:d=>{n("setBackgroundColor",d?.color??null)},toggle:()=>{}}),r=T(d=>d.request.background.remove),i=T(d=>d.request.padding),c=T(d=>d.request.fit),o=!!r||!!i||!!c,g=l.useCallback(d=>{d&&!o||n("setBackgroundColor",d)},[n,o]);return l.useEffect(()=>{!o&&t!==null&&g(null)},[t,o,g]),{backgroundColor:t,setBackgroundColor:g,onToggle:s,persist:a}},{SketchPicker:Zr}=$s(()=>Un(()=>import("./index-BhNLXOHO.js"),__vite__mapDeps([33,1,2,4,22])),{fallback:null}),as=({color:t,className:n,onChangeComplete:s})=>e.jsx(Zr,{className:n,disableAlpha:!0,color:t||void 0,onChangeComplete:a=>s(a.hex)}),Jr=()=>{const{t}=O(),{backgroundColor:n,setBackgroundColor:s,persist:a}=ss(),[r,i]=l.useState(n);l.useEffect(()=>{i(n)},[n]);const c=Pe(()=>s(r));return e.jsx(Q,{as:"div",text:t("options.framing.border"),children:e.jsx(ae,{children:e.jsx("div",{className:"d-flex justify-content-center w-100",children:e.jsx(as,{className:"mx-auto",color:r,onChangeComplete:o=>{i(o),a({color:o}),c()}})})})})};function ei(t,n,s){let a=n,r=s,i=-1,c=-1;for(let o=0;o<s;o++)for(let g=0;g<n;g++)t[(o*n+g)*4+3]>16&&(a=Math.min(a,g),i=Math.max(i,g),r=Math.min(r,o),c=Math.max(c,o));return i<a?{x:0,y:0,width:1,height:1}:{x:a/n,y:r/s,width:(i-a+1)/n,height:(c-r+1)/s}}const ti=t=>new Promise((n,s)=>{const a=new Image;a.crossOrigin="anonymous",a.onerror=()=>s(new Error("Could not load foreground preview")),a.onload=()=>{try{const r=document.createElement("canvas");
2r.width=a.naturalWidth,r.height=a.naturalHeight;const i=r.getContext("2d");if(!i)throw new Error("Could not read foreground preview");i.drawImage(a,0,0),n(ei(i.getImageData(0,0,r.width,r.height).data,r.width,r.height))}catch(r){s(r)}},a.src=t}),ni=t=>["foreground-preview","512-full",t];function rs(t,n){return qs(ni(t),async()=>{const s={id:"result-foreground-preview",img_url:t,thumbnail_url:t,file_name:"preview",created_at:0,user_id:"",app:Y.ENHANCER_STUDIO,metadata:{width:0,height:0},downscaled:!1},a=await Hs({image:s,parameters:{},preserveCanvas:!0});if(!a.result_url)throw new Error("No foreground preview returned");return{url:a.result_url,bounds:await ti(a.result_url)}},{enabled:n&&!!t,staleTime:1/0,cacheTime:1800*1e3,retry:!1,retryOnMount:!1,refetchOnWindowFocus:!1})}function si(t,n,s,a){const r=s.fit||ie.CANVAS,i=typeof r=="object"&&"crop"in r,c=i&&r.crop!=="center",o=r===ie.BOUNDS||r===ie.COVER,g=r===ie.COVER?Math.max(n.width/t.width,n.height/t.height):Math.min(n.width/t.width,n.height/t.height),d=o?{width:Math.round(t.width*g),height:Math.round(t.height*g)}:n,p=Math.max(0,Math.min(.49,parseFloat(s.padding||"0")/100)),x=Math.floor(n.width*p),u=Math.floor(n.height*p),m=Math.max(1,d.width-x*2),j=Math.max(1,d.height-u*2),f=i&&(!c||a&&r.crop===xe.CONTENT)||r===ie.COVER?Math.max(m/t.width,j/t.height):Math.min(m/t.width,j/t.height),h={width:t.width*f,height:t.height*f,x:(d.width-t.width*f)/2,y:(d.height-t.height*f)/2},_={x,y:u,width:m,height:j};if(a&&i)if(r.crop===xe.ITEM){const v=Math.min(m/(t.width*a.width),j/(t.height*a.height));h.width=t.width*v,h.height=t.height*v,h.x=d.width/2-(a.x+a.width/2)*h.width,h.y=d.height/2-(a.y+a.height/2)*h.height,_.x=h.x+a.x*h.width,_.y=h.y+a.y*h.height,_.width=a.width*h.width,_.height=a.height*h.height}else r.crop===xe.CONTENT&&(h.x=Math.max(d.width-x-h.width,Math.min(x,d.width/2-(a.x+a.width/2)*h.width)),h.y=Math.max(d.height-u-h.height,Math.min(u,d.height/2-(a.y+a.height/2)*h.height)));return{canvas:d,image:h,clip:_,approximate:c}}const ai=t=>{const{t:n}=O(),s=T(G=>G.request),{sourceResolution:a,targetResolution:r,sourceUrl:i}=bt(t),c=typeof s.fit=="object"&&s.fit&&"crop"in s.fit&&(s.fit.crop===xe.CONTENT||s.fit.crop===xe.ITEM),o=!!(s.width||s.height||s.min_length||s.print_size),g=o&&typeof s.fit=="object"&&s.fit&&"canvas"in s.fit&&s.fit.canvas==="outpainting",d=rs(i,!!c&&o),p=c&&o?d.data:void 0,x=i,u=l.useId().replace(/:/g,""),m=a&&r?si(a,r,s,p?.bounds):null;if(!m||!i)return e.jsx("div",{className:"image-canvas__empty",children:n("options.canvas.empty")});const{canvas:j,image:f,clip:h}=m,_=r,v=s.print_size?Zn(s.print_size,a):null,y=j.width!==_.width||j.height!==_.height,E=Math.min(260/Math.max(j.width,_.width,p?0:f.width),170/Math.max(j.height,_.height,p?0:f.height)),I=(320-_.width*E)/2,b=(240-_.height*E)/2,R=(320-j.width*E)/2,U=(240-j.height*E)/2,F=Math.min(R,I,p?R:R+f.x*E),$=Math.min(U,b,p?U:U+f.y*E),w=!p&&(f.x<-.01||f.y<-.01),A=j.width>_.width||j.height>_.height,C=s.background?.color,P=C&&C!=="auto"?C:"#ffffff";return e.jsxs("figure",{className:"image-canvas__preview",children:[e.jsxs("svg",{viewBox:"0 0 320 240",role:"img","aria-label":n("options.canvas.preview"),children:[e.jsxs("defs",{children:[e.jsxs("pattern",{id:`${u}-generative`,width:"12",height:"12",patternUnits:"userSpaceOnUse",children:[e.jsx("rect",{className:"image-canvas__generative-bg",width:"12",height:"12"}),e.jsx("path",{className:"image-canvas__generative-stroke",d:"M-3 3l6-6M0 12L12 0M9 15l6-6",strokeWidth:"2"})]}),e.jsxs("pattern",{id:`${u}-grid`,width:"12",height:"12",patternUnits:"userSpaceOnUse",children:[e.jsx("rect",{className:"image-canvas__grid-bg",width:"12",height:"12"}),e.jsx("path",{className:"image-canvas__grid-cell",d:"M0 0h6v6H0z M6 6h6v6H6z"})]}),e.jsx("clipPath",{id:`${u}-clip`,children:e.jsx("rect",{x:h.x,y:h.y,width:h.width,height:h.height})}),A&&e.jsxs("mask",{id:`${u}-overflow`,maskUnits:"userSpaceOnUse",x:"0",y:"0",width:"320",height:"240",children:[e.jsx("rect",{x:R,y:U,width:j.width*E,height:j.height*E,fill:"#fff"}),e.jsx("rect",{x:I,y:b,width:_.width*E,height:_.height*E,fill:"#000"})]})]}),e.jsx("path",{className:"image-canvas__dimension",d:`M${I} ${$-9}v-5h${_.width*E}v5`}),e.jsx("path",{className:"image-canvas__dimension",d:`M${F-9} ${b}h-5v${_.height*E}h5`}),e.jsxs("text",{x:"160",y:$-18,textAnchor:"middle",children:[v?`${v.width} mm · `:"",_.width," px"]}),e.jsxs("text",{transform:`translate(${F-18},120) rotate(-90)`,textAnchor:"middle",children:[v?`${v.height} mm · `:"",_.height," px"]}),w&&e.jsx("g",{className:"image-canvas__cropped-source",opacity:"0.45",transform:`translate(${R},${U}) scale(${E})`,children:e.jsx("image",{href:String(x),x:f.x,y:f.y,width:f.width,height:f.height,preserveAspectRatio:"none"})}),e.jsxs("g",{transform:`translate(${R},${U}) scale(${E})`,children:[e.jsx("rect",{width:j.width,height:j.height,fill:`url(#${u}-grid)`}),e.jsx("rect",{width:j.width,height:j.height,fill:g?`url(#${u}-generative)`:P}),e.jsx("image",{href:String(x),x:f.x,y:f.y,width:f.width,height:f.height,preserveAspectRatio:"none",clipPath:`url(#${u}-clip)`}),e.jsx("rect",{className:"image-canvas__clip",x:h.x,y:h.y,width:h.width,height:h.height,strokeWidth:"1",strokeDasharray:"4 3",vectorEffect:"non-scaling-stroke"}),e.jsx("rect",{className:"image-canvas__outline",width:j.width,height:j.height,strokeWidth:"1",vectorEffect:"non-scaling-stroke"})]}),A&&e.jsx("rect",{className:"image-canvas__overflow",x:R,y:U,width:j.width*E,height:j.height*E,fill:"#000",fillOpacity:"0.45",mask:`url(#${u}-overflow)`,pointerEvents:"none"}),y&&e.jsx("rect",{className:"image-canvas__requested",x:I,y:b,width:_.width*E,height:_.height*E,strokeDasharray:"4 3",children:e.jsx("title",{children:n("options.canvas.requested_size",{defaultValue:"Requested size"})})})]}),e.jsxs("figcaption",{children:[e.jsxs("span",{className:"image-canvas__resolution",children:[j.width," × ",j.height," px"]}),c&&o&&d.isFetching&&e.jsx("div",{role:"status",children:n("options.canvas.loading_foreground",{defaultValue:"Preparing preview…"})}),c&&o&&d.isError&&!d.isFetching&&e.jsxs("div",{role:"status",className:"image-canvas__error",children:[n("options.canvas.foreground_error",{defaultValue:"Preview unavailable."}),e.jsx("button",{type:"button",onClick:()=>d.refetch(),children:n("options.canvas.retry",{defaultValue:"Retry"})})]})]})]})},is=[[1,1],[3,2],[2,3],[4,3],[3,4],[16,9],[9,16],[4,5],[5,4],[21,9]],Lt=(t,n,s)=>{const a=is.find(([r,i])=>t===Math.round(n*r/i)||n===Math.round(t*i/r));return a?`${a[0]}:${a[1]}`:s},ri=({anchor:t,...n})=>{const{sourceResolution:s}=bt(n),{t:a}=O(),r=L(),i=T(h=>h.request.width),c=T(h=>h.request.height);if(!s)return null;const o=s.width*s.height,g=h=>t?.axis==="width"?{width:t.value,height:Math.max(1,Math.round(t.value/h))}:t?.axis==="height"?{width:Math.max(1,Math.round(t.value*h)),height:t.value}:{width:Math.max(1,Math.round(Math.sqrt(o*h))),height:Math.max(1,Math.round(Math.sqrt(o/h)))},d=[{...t?g(s.width/s.height):s,ratioLabel:Lt(s.width,s.height,a("options.upscale.aspect_original"))},...is.map(([h,_])=>({...g(h/_),ratioLabel:`${h}:${_}`}))],p=d.filter((h,_)=>d.findIndex(v=>v.width===h.width&&v.height===h.height)===_).map(h=>({...h,value:`${h.width}x${h.height}`,label:`${h.ratioLabel} · ${h.width} × ${h.height} px`})),x=Number(i),u=Number(c);let m=p.find(h=>h.width===x&&h.height===u);!m&&Number.isFinite(x)&&x>0&&Number.isFinite(u)&&u>0&&(m={width:x,height:u,value:`${x}x${u}`,ratioLabel:Lt(x,u,a("options.upscale.aspect_custom")),label:`${Lt(x,u,a("options.upscale.aspect_custom"))} · ${x} × ${u} px`},p.unshift(m));const j=h=>{const _=h.width/h.height;return e.jsxs("span",{className:"image-canvas__aspect-option",children:[e.jsx("svg",{width:"28",height:"28",viewBox:"0 0 28 28","aria-hidden":"true",children:e.jsx("rect",{x:(28-Math.min(24,24*_))/2,y:(28-Math.min(24,24/_))/2,width:Math.min(24,24*_),height:Math.min(24,24/_),rx:"2",fill:"none",stroke:"currentColor"})}),h.label]})},f=a("options.upscale.aspect_ratio");return e.jsx(Q,{as:"div",text:f,children:e.jsx(jt,{label:f,options:p,value:m??null,placeholder:a("options.upscale.choose_resolution"),renderOption:j,renderValue:j,onChange:h=>{h&&r("setWidthHeight",{width:h.width,height:h.height})}})})},ii=({hidePreview:t=!1,...n})=>{const{t:s}=O(),{sourceUrl:a}=bt(n),[r,i]=l.useState(null),c=r?.sourceUrl===a?r:null;return e.jsxs(e.Fragment,{children:[e.jsx(Ue,{text:s("options.canvas.title")}),t?e.jsx("div",{className:"image-canvas__empty",children:s("options.canvas.empty")}):e.jsx(ai,{...n}),e.jsx(Hr,{label:s("options.canvas.title"),sections:[{id:"upscale",label:s("options.tabs.upscale"),icon:e.jsx(Ks,{}),content:e.jsxs(e.Fragment,{children:[e.jsx(Jn,{}),e.jsx("div",{className:"canvas-controls__ai",children:e.jsx(Kr,{sliderOnly:!0})}),e.jsx(zr,{studio:!0,onManualDimensionChange:(o,g)=>i(g?{axis:o,value:g,sourceUrl:a}:null),widthHeightOptions:!t&&e.jsx(ri,{...n,anchor:c})})]})},{id:"framing",label:s("options.framing.title"),icon:e.jsx(Ys,{}),content:e.jsxs(e.Fragment,{children:[e.jsx(Qr,{}),e.jsx(Xr,{})]})},{id:"fill",label:s("options.framing.border"),icon:e.jsx(Qs,{}),content:e.jsx(Jr,{})}]})]})},Nn=new Set([me.V3,me.V3_FULL]),oi=()=>{const{t}=O(),n=l.useMemo(()=>[{label:t("options.adjust.face.types.beautify"),value:me.V2},{label:t("options.adjust.face.types.beautify_real"),value:me.V1},{label:t("options.adjust.face.types.beautify_v2"),value:me.V3},{label:t("options.adjust.face.types.beautify_v2_full"),value:me.V3_FULL}],[t]),s=T(Ee(D.FACE_ENHANCE)),a=T(h=>h.request.face_enhance_parameters),[r,i]=l.useState(a.type||me.V2),[c,o]=l.useState(a?.level?a.level*100:null),[g,d]=l.useState(a?.smoothing_level?a.smoothing_level*100:null),p=L(),x=!Nn.has(r),{onToggle:u,persist:m}=Fe({enabled:s,storageKey:"enhance-options-face-memory",read:()=>({level:a?.level??null,smoothing_level:a?.smoothing_level??null,type:a?.type??r??null}),write:h=>{h?(p("setFaceEnhanceLevel",h.level??null),p("setFaceEnhanceSmoothingLevel",h.smoothing_level??null),h.type&&(p("setFaceEnhanceType",h.type),i(h.type))):(p("setFaceEnhanceLevel",null),p("setFaceEnhanceSmoothingLevel",null),p("setFaceEnhanceType",null))},toggle:()=>p("toggleEnhancement",D.FACE_ENHANCE)}),j=Pe(()=>{const h=c&&c/100||null;p("setFaceEnhanceLevel",h)}),f=Pe(()=>{const h=g&&g/100||null;p("setFaceEnhanceSmoothingLevel",h)});return l.useEffect(()=>{o(a?.level?a.level*100:null),d(a?.smoothing_level?a.smoothing_level*100:null),a?.type&&i(a.type)},[a?.level,a?.smoothing_level,a?.type]),l.useEffect(()=>{if(!s)return;const h=a?.type??r??me.V2;h&&a?.type!==h&&p("setFaceEnhanceType",h)},[p,a?.type,r,s]),l.useEffect(()=>{!s||x||a?.level===null&&a?.smoothing_level===null||(o(null),d(null),p("setFaceEnhanceLevel",null),p("setFaceEnhanceSmoothingLevel",null),m({level:null,smoothing_level:null}))},[p,a?.level,a?.smoothing_level,s,m,x]),e.jsx(e.Fragment,{children:e.jsx(ne,{text:t("options.adjust.face.label"),checked:s,onChange:u,children:s?e.jsxs(e.Fragment,{children:[e.jsx(le,{label:t("options.adjust.face.type_label"),options:n,value:n.find(h=>h.value===r)||n[0],onChange:h=>{const _=h?.value;_&&(i(_),p("setFaceEnhanceType",_),Nn.has(_)?(o(null),d(null),p("setFaceEnhanceLevel",null),p("setFaceEnhanceSmoothingLevel",null),m({type:_,level:null,smoothing_level:null})):m({type:_}))}}),x?e.jsxs(e.Fragment,{children:[e.jsxs(k,{label:t("options.adjust.face.level"),value:[parseInt(String(c||"0"))],min:0,offValue:0,max:100,step:1,onValueChange:h=>{o(h[0]),m({level:h[0]?h[0]/100:null}),j()},showValue:!0,children:[e.jsx(k.Track,{children:e.jsx(k.Range,{})}),e.jsx(k.Thumb,{})]}),e.jsxs(k,{label:t("options.adjust.face.smoothing_level"),value:[parseInt(String(g||"0"))],min:0,offValue:0,max:100,step:1,onValueChange:h=>{d(h[0]),m({smoothing_level:h[0]?h[0]/100:null}),f()},showValue:!0,children:[e.jsx(k.Track,{children:e.jsx(k.Range,{})}),e.jsx(k.Thumb,{})]})]}):null]}):null})})},In=qt.V2,li=()=>{const{t}=O(),n=l.useMemo(()=>[{label:t("options.adjust.noise.types.v2"),value:qt.V2},{label:t("options.adjust.noise.types.v1"),value:qt.V1}],[t]),s=T(Ee(D.DENOISE)),a=T(o=>o.request.denoise_parameters.type),r=L(),{onToggle:i,persist:c}=Fe({enabled:s,storageKey:"enhance-options-denoise-memory",read:()=>({type:a??In}),write:o=>{r("setDenoiseType",o?.type??null)},toggle:()=>r("toggleEnhancement",D.DENOISE)});return l.useEffect(()=>{if(!s)return;const o=a??In;o&&a!==o&&(r("setDenoiseType",o),c({type:o}))},[a,r,s,c]),e.jsx(e.Fragment,{children:e.jsx(ne,{text:t("options.adjust.noise.label"),checked:s,onChange:i,children:s?e.jsx(e.Fragment,{children:e.jsx(le,{label:t("options.adjust.noise.type_label"),options:n,value:n.find(o=>o.value===a),onChange:o=>{const g=o?.value;g&&(r("setDenoiseType",g),c({type:g}))}})}):null})})},Rn=ct.V3,ci=()=>{const{t}=O(),n=l.useMemo(()=>[{label:t("options.adjust.sharp.types.generative"),value:ct.V3},{label:t("options.adjust.sharp.types.v2"),value:ct.V2},{label:t("options.adjust.sharp.types.v1"),value:ct.V1}],[t]),s=T(Ee(D.DEBLUR)),a=T(o=>o.request.deblur_parameters.type),r=L(),{onToggle:i,persist:c}=Fe({enabled:s,storageKey:"enhance-options-deblur-memory",read:()=>({type:a??Rn}),write:o=>{r("setDeblurType",o?.type??null)},toggle:()=>r("toggleEnhancement",D.DEBLUR)});return l.useEffect(()=>{if(!s)return;const o=a??Rn;o&&a!==o&&(r("setDeblurType",o),c({type:o}))},[a,r,s,c]),e.jsx(e.Fragment,{children:e.jsx(ne,{text:t("options.adjust.sharp.label"),checked:s,onChange:i,children:s?e.jsx(e.Fragment,{children:e.jsx(le,{label:t("options.adjust.sharp.type_label"),options:n,value:n.find(o=>o.value===a),onChange:o=>{const g=o?.value;g&&(r("setDeblurType",g),c({type:g}))}})}):null})})},oe=({className:t,rightText:n,...s})=>e.jsxs("div",{className:"position-relative",children:[e.jsx("textarea",{...s,className:he("textarea",
2n&&"textarea--after",t)}),n?e.jsx("span",{className:"textarea-after",children:n}):null]}),ui=({className:t,text:n,...s})=>e.jsx("label",{...s,className:he("textarea-label",t),children:n}),di=({className:t,children:n,...s})=>e.jsx("div",{...s,className:he("textarea-wrapper",t),children:n});oe.OptionsTextareaLabel=ui;oe.OptionsTextareaWrapper=di;const hi="generative-tone-correction-",pi="generative-tone-correction-general",Ut=new Set([D.LIGHT,D.COLOR,D.WHITE_BALANCE,D.EXPOSURE_CORRECTION]),An=t=>t.name===pi?0:1,Vt=(t,n)=>({...Fn,...t.config.generative_tone_correction_parameters??{},preset_name:t.name,additional_description:n}),gi=({controlsOnly:t=!1})=>{const{t:n}=O(),s=L(),a=T(Ee(D.GENERATIVE_TONE_CORRECTION)),r=T(b=>b.request.generative_tone_correction_parameters??Fn),i=T(b=>b.request.enhancements),{data:c=[],isLoading:o}=Bn("enhancer_studio"),[g,d]=l.useState(!1);l.useEffect(()=>{a&&i.some(b=>Ut.has(b))&&s("setEnhancements",i.filter(b=>!Ut.has(b)))},[s,i,a]);const p=l.useMemo(()=>c.filter(b=>b.name.startsWith(hi)&&b.config.enhancements?.includes(D.GENERATIVE_TONE_CORRECTION)).sort((b,R)=>An(b)-An(R)||(b.display_name??b.name).localeCompare(R.display_name??R.name)),[c]),x=Xs(p,r),u=l.useMemo(()=>[...p.map(b=>({label:b.display_name??b.name,value:b.name,preset:b})),{label:n("options.adjust.generative_tone_correction.custom"),value:"custom",preset:null}],[p,n]),m=g||!x?u[u.length-1]:u.find(b=>b.preset===x)??null,j=x?Vt(x,""):null,f=b=>{s("setGenerativeToneCorrectionParameters",b)},h=()=>{if(a){s("setEnhancements",i.filter(b=>b!==D.GENERATIVE_TONE_CORRECTION));return}x&&!g&&f(Vt(x,r.additional_description??"")),s("setEnhancements",[...i.filter(b=>!Ut.has(b)&&b!==D.GENERATIVE_TONE_CORRECTION),D.GENERATIVE_TONE_CORRECTION])},_=b=>{if(b){if(!b.preset){d(!0),f(Zs(r));return}d(!1),f(Vt(b.preset,r.additional_description??""))}},v=(b,R)=>{f({...r,[b]:R[0]/100})},y=b=>{j&&f({...r,[b]:j[b]})},E=[{key:"light_transfer_strength",label:n("options.adjust.generative_tone_correction.light_transfer")},{key:"exposure_strength",label:n("options.adjust.generative_tone_correction.exposure")},{key:"contrast_strength",label:n("options.adjust.generative_tone_correction.contrast")},{key:"white_balance_strength",label:n("options.adjust.generative_tone_correction.white_balance")},{key:"saturation_strength",label:n("options.adjust.generative_tone_correction.saturation")}],I=e.jsx(e.Fragment,{children:a?e.jsxs("div",{className:"generative-tone-correction-options",children:[e.jsx(le,{label:n("options.adjust.generative_tone_correction.preset"),options:u,value:m,onChange:_,placeholder:n("options.adjust.generative_tone_correction.preset_placeholder"),isDisabled:o,getOptionLabel:b=>b.label,getOptionValue:b=>b.value}),E.map(({key:b,label:R})=>{const U=!!(j&&Math.round(r[b]*100)!==Math.round(j[b]*100));return e.jsxs(k,{label:U?e.jsx("strong",{children:R}):R,value:[Math.round(r[b]*100)],min:0,max:100,step:1,onValueChange:F=>v(b,F),showValue:!0,renderValue:F=>`${F?.[0]}%`,children:[e.jsx(k.Track,{children:e.jsx(k.Range,{})}),e.jsx(k.Thumb,{"aria-label":R,onDoubleClick:F=>{F.preventDefault(),F.stopPropagation(),y(b)}})]},b)}),e.jsxs(oe.OptionsTextareaWrapper,{children:[e.jsx(oe.OptionsTextareaLabel,{text:n("options.adjust.generative_tone_correction.additional_description")}),e.jsx(oe,{value:r.additional_description??"",onChange:b=>f({...r,additional_description:b.target.value}),maxLength:1500,rows:4,placeholder:n("options.adjust.generative_tone_correction.additional_description_placeholder")})]})]}):null});return t?I:e.jsx(ne,{text:n("options.adjust.generative_tone_correction.ai",{defaultValue:"AI"}),checked:a,onChange:h,children:I})},rt=_e.HDR_LIGHT_ADVANCED,mi=()=>{const{t}=O(),n=L(),s=T(u=>u.request.light_parameters),a=T(Ee(D.LIGHT)),r=l.useMemo(()=>[{value:_e.HDR_LIGHT_ADVANCED,label:t("options.adjust.light.types.hdr_light_advanced")},{value:_e.HDR_LIGHT,label:t("options.adjust.light.types.hdr_light")},{value:_e.CONTRAST,label:t("options.adjust.light.types.contrast")}],[t]),[i,c]=l.useState(s.type||rt),[o,g]=l.useState(s.level?s.level*100:0);l.useEffect(()=>{c(s.type||rt),g(s.level?s.level*100:0)},[s]),l.useEffect(()=>{(s.level??0)>0&&!s.type&&n("setLightType",rt)},[n,s.level,s.type]);const d=_t(l.useCallback((u,m)=>{const j=u>0,f=j?u/100:null,h=j?m:null;
2s.level!==f&&n("setLightLevel",f),s.type!==h&&n("setLightType",h),j&&!a?n("toggleEnhancement",D.LIGHT):!j&&a&&n("toggleEnhancement",D.LIGHT)},[n,a,s]),300),p=u=>{const m=u[0];g(m),d(m,i)},x=u=>{const m=u?.value||rt;c(m),o>0&&d(o,m)};return e.jsxs(ae,{children:[e.jsx(le,{label:t("options.adjust.light.label"),options:r,value:r.find(u=>u.value===i),onChange:x}),e.jsxs(k,{label:t("options.adjust.light.level"),value:[o],min:0,max:100,step:1,offValue:0,onValueChange:p,showValue:!0,renderValue:u=>`${u?.[0]}%`,children:[e.jsx(k.Track,{children:e.jsx(k.Range,{})}),e.jsx(k.Thumb,{})]})]})},it=_e.HDR_LIGHT_ADVANCED,fi=()=>{const{t}=O(),n=L(),s=T(u=>u.request.color_parameters),a=T(Ee(D.COLOR)),r=l.useMemo(()=>[{value:_e.HDR_LIGHT_ADVANCED,label:t("options.adjust.saturation.types.hdr_light_advanced")},{value:_e.HDR_LIGHT,label:t("options.adjust.saturation.types.hdr_light")},{value:_e.CONTRAST,label:t("options.adjust.saturation.types.contrast")}],[t]),[i,c]=l.useState(s.type||it),[o,g]=l.useState(s.level?s.level*100:0);l.useEffect(()=>{c(s.type||it),g(s.level?s.level*100:0)},[s]),l.useEffect(()=>{(s.level??0)>0&&!s.type&&n("setColorType",it)},[n,s.level,s.type]);const d=_t(l.useCallback((u,m)=>{const j=u>0,f=j?u/100:null,h=j?m:null;s.level!==f&&n("setColorLevel",f),s.type!==h&&n("setColorType",h),j&&!a?n("toggleEnhancement",D.COLOR):!j&&a&&n("toggleEnhancement",D.COLOR)},[n,a,s]),300),p=u=>{const m=u[0];g(m),d(m,i)},x=u=>{const m=u?.value||it;c(m),o>0&&d(o,m)};return e.jsxs(ae,{children:[e.jsx(le,{label:t("options.adjust.saturation.label"),options:r,value:r.find(u=>u.value===i),onChange:x}),e.jsxs(k,{label:t("options.adjust.saturation.level"),value:[o],min:0,max:100,step:1,offValue:0,onValueChange:p,showValue:!0,renderValue:u=>`${u?.[0]}%`,children:[e.jsx(k.Track,{children:e.jsx(k.Range,{})}),e.jsx(k.Thumb,{})]})]})},ot=Ht.V2,xi=()=>{const{t}=O(),n=T(u=>u.request.white_balance_parameters),s=L(),a=T(Ee(D.WHITE_BALANCE)),r=l.useMemo(()=>[{value:Ht.V2,label:t("options.adjust.white_balance.types.v2")},{value:Ht.V1,label:t("options.adjust.white_balance.types.v1")}],[t]),[i,c]=l.useState(n.type||ot),[o,g]=l.useState(n.level?n.level*100:0);l.useEffect(()=>{c(n.type||ot),g(n.level?n.level*100:0)},[n]),l.useEffect(()=>{(n.level??0)>0&&!n.type&&s("setWhiteBalanceType",ot)},[s,n.level,n.type]);const d=_t(l.useCallback((u,m)=>{const j=u>0,f=j?u/100:null,h=j?m:null;n.level!==f&&s("setWhiteBalanceLevel",f),n.type!==h&&s("setWhiteBalanceType",h),j&&!a?s("toggleEnhancement",D.WHITE_BALANCE):!j&&a&&s("toggleEnhancement",D.WHITE_BALANCE)},[s,a,n]),300),p=u=>{const m=u[0];g(m),d(m,i)},x=u=>{const m=u?.value||ot;c(m),o>0&&d(o,m)};return e.jsxs(ae,{children:[e.jsx(le,{label:t("options.adjust.white_balance.label"),options:r,value:r.find(u=>u.value===i),onChange:x}),e.jsxs(k,{label:t("options.adjust.white_balance.level"),value:[o],min:0,max:100,step:1,offValue:0,onValueChange:p,showValue:!0,renderValue:u=>`${u?.[0]}%`,children:[e.jsx(k.Track,{children:e.jsx(k.Range,{})}),e.jsx(k.Thumb,{})]})]})},pt=D.GENERATIVE_TONE_CORRECTION,Xt=[D.LIGHT,D.COLOR,D.WHITE_BALANCE,D.EXPOSURE_CORRECTION],on=t=>t===pt||Xt.includes(t),$e=t=>({light_parameters:t.light_parameters,color_parameters:t.color_parameters,white_balance_parameters:t.white_balance_parameters}),Ft=t=>JSON.stringify([t.enhancements.filter(on),$e(t)]),Bt=t=>t.enhancements.some(on)||Object.values($e(t)).some(n=>!!n?.type||!!n?.level),_i=()=>{const{t}=O(),n=T(p=>p.request),s=L(),[a,r]=l.useState(Bt(n)),[i,c]=l.useState(n.enhancements.includes(pt)||!Bt(n)?"advanced":"legacy"),o=l.useRef(Ft(n)),g=l.useRef({parameters:$e(n),enhancements:n.enhancements.filter(p=>Xt.includes(p))});l.useEffect(()=>{const p=Ft(n);if(o.current===p)return;o.current=p;const x=Bt(n);r(x),c(n.enhancements.includes(pt)||!x?"advanced":"legacy")},[n]);const d=(p,x)=>{i==="legacy"&&a&&(g.current={parameters:$e(n),enhancements:n.enhancements.filter(m=>Xt.includes(m))});const u={...n,...$e(dt.request),enhancements:n.enhancements.filter(m=>!on(m))};p&&x==="advanced"&&u.enhancements.push(pt),p&&x==="legacy"&&(Object.assign(u,g.current.parameters),u.enhancements.push(...g.current.enhancements)),o.current=Ft(u),r(p),c(x),s("setRequest",u)};return e.jsx(ne,{text:t("options.adjust.color_and_lighting",{defaultValue:"Color & lighting"}),checked:a,onChange:()=>d(!a,i),children:a&&e.jsxs(e.Fragment,{children:[e.jsxs(te.Group,{type:"single",value:i,onValueChange:p=>{p&&d(!0,p)},children:[e.jsx(te.GroupItem,{value:"advanced",label:t("options.adjust.generative_tone_correction.ai",{defaultValue:"AI"}),"aria-label":t("options.adjust.generative_tone_correction.ai",{defaultValue:"AI"})}),e.jsx(te.GroupItem,{value:"legacy",label:t("options.adjust.generative_tone_correction.legacy",{defaultValue:"Legacy"}),"aria-label":t("options.adjust.generative_tone_correction.legacy",{defaultValue:"Legacy"})})]}),i==="advanced"?e.jsx(gi,{controlsOnly:!0}):e.jsxs(e.Fragment,{children:[e.jsx(mi,{}),e.jsx(fi,{}),e.jsx(xi,{})]})]})})},ge={temperature:0,tint:0,vibrance:0,saturation:0,exposure:0,brightness:0,contrast:0,blacks:0,whites:0,highlights:0,shadows:0,hue:0},Zt=Object.keys(ge),On=t=>{const n={};return Zt.forEach(s=>{const a=t[s]??0;n[s]=a===0?null:a}),n},ji=(t,n)=>{try{const s=new URL(t,window.location.href);return s.searchParams.set("v",n),s.toString()}catch{return t}},bi=t=>{try{const n=new URL(t,window.location.href);if(!n.hostname.startsWith("neuroapi-store."))return t;const a=new URL("https://deep-image.ai"),r=n.pathname.startsWith("/")?n.pathname.slice(1):n.pathname;return a.pathname=`/neuroapi-store/${r}`,a.search=n.search,a.hash=n.hash,a.toString()}catch(n){return console.log(n),t}},lt=t=>{const n=new Set;return t.forEach(s=>{s&&(n.has(s)||n.add(s))}),Array.from(n)},vi=({selectedJobHash:t,selectedHistoryItemId:n})=>{const{t:s}=O(),a=L(),r=T(w=>w.request.corrections),[i,c]=l.useState(()=>Object.values(r??{}).some(w=>w!=null&&w!==0)),o=l.useRef(JSON.stringify(r)),g=l.useRef(ge),d=l.useMemo(()=>({title:s("options.adjust.corrections.title"),help:s("options.adjust.corrections.help"),labels:{temperature:s("options.adjust.corrections.temperature"),tint:s("options.adjust.corrections.tint"),vibrance:s("options.adjust.corrections.vibrance"),saturation:s("options.adjust.corrections.saturation"),exposure:s("options.adjust.corrections.exposure"),brightness:s("options.adjust.corrections.brightness"),contrast:s("options.adjust.corrections.contrast")}}),[s]),[p,x]=l.useState(ge),u=Ke(He),{data:m}=ye(t||"",{enabled:!!t}),j=l.useRef(null),f=l.useRef(null),[h,_]=l.useState(!1),[v,y]=l.useState(0),E=l.useMemo(()=>
2{if(m){const A=n?.startsWith("root-"),C=!!m.is_failed;return lt(A?[m.thumbnail_url,m.result_thumbnail_url,m.result?.origin_url,m.result?.result_url,m.origin_url,m.source,m.storage_source]:C?[m.thumbnail_url,m.storage_source,m.result_thumbnail_url,m.result?.origin_url,m.result?.result_url]:[m.result_thumbnail_url,m.thumbnail_url,m.result?.result_url,m.result?.origin_url,m.storage_source])}const w=Array.isArray(u)&&u.length>0?u[0]:null;return lt([w?.thumbnail_url,w?.img_url])},[m,n,u]),I=l.useMemo(()=>{const w=E[v]||null;if(!w)return null;const A=bi(w),C=[t,n].filter(Boolean).join("-");return C?ji(A,C):A},[E,v,t,n]);l.useEffect(()=>{y(0)},[t,n]),l.useEffect(()=>{const w=JSON.stringify(r);if(w!==o.current&&(o.current=w,g.current={...ge,...r??{}},c(Object.values(r??{}).some(C=>C!=null&&C!==0))),!r){x(ge);return}const A={...ge};Zt.forEach(C=>{const P=r?.[C];P!=null&&(A[C]=P)}),x(C=>Zt.some(G=>C[G]!==A[G])?A:C)},[r]);const b=_t(l.useCallback(w=>{const A=On(w);o.current=JSON.stringify(A),a("setCorrections",A)},[a]),300),R=()=>{b.cancel();const w=!i;w||(g.current={...p});const A=w?On(g.current):null;o.current=JSON.stringify(A),c(w),a("setCorrections",A)},U=l.useCallback(()=>{x(ge),b(ge)},[b]),F=l.useCallback(w=>A=>{const C=A[0];x(P=>{const G={...P,[w]:C};return b(G),G})},[b]),$=l.useCallback(w=>()=>{x(A=>{const C={...A,[w]:0};return b(C),C})},[b]);return l.useEffect(()=>{if(_(!1),f.current=null,!i||!I)return;const w=new Image;w.crossOrigin="anonymous",w.onerror=()=>{_(!1),f.current=null,y(A=>A+1)},w.onload=()=>{const A=w.width||1,C=w.height||1,P=document.createElement("canvas");P.width=A,P.height=C;const G=P.getContext("2d");if(G){G.drawImage(w,0,0,A,C);try{f.current=G.getImageData(0,0,A,C),_(!0)}catch(S){f.current=null,_(!1),console.warn("Cannot read image data for corrections preview",S),y(N=>N+1)}}},w.src=I},[I,i]),l.useEffect(()=>{if(!h||!f.current||!j.current)return;const w=f.current,A=j.current,C=A.getContext("2d");if(!C)return;const P=Js(w,p);A.width=P.width,A.height=P.height,C.putImageData(P,0,0)},[h,p,I,i]),e.jsxs(ae,{className:"options-switch",children:[e.jsx(Q,{as:"div",text:d.title,tooltip:d.help,children:e.jsx(mr,{checked:i,onChange:R,"aria-label":d.title,offColor:xn.colorGray7})}),i&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"options-switch-divider"}),e.jsxs("button",{type:"button",onClick:U,style:{alignSelf:"flex-end",display:"inline-flex",alignItems:"center",gap:4,fontSize:11,color:"#64748b",background:"none",border:"none",cursor:"pointer"},children:[e.jsx(ea,{size:14}),e.jsx("span",{children:s("options.reset.button")})]}),e.jsx("div",{style:{margin:"0 auto 8px",borderRadius:8,overflow:"hidden",backgroundColor:"#f3f4f6",width:150,height:150,display:"flex",alignItems:"center",justifyContent:"center"},children:h&&f.current?e.jsx("canvas",{ref:j,className:"corrections-preview-image"}):I?e.jsx("img",{src:I,crossOrigin:"anonymous",alt:s("options.adjust.corrections.preview_alt"),className:"corrections-preview-image"}):e.jsx(Gn,{size:48,color:xn.colorOptionsBorderSoft})},I),e.jsxs("div",{style:{display:"grid",gap:8},children:[e.jsxs(k,{label:d.labels.temperature,value:[p.temperature??0],min:-100,max:100,step:1,onValueChange:F("temperature"),onDoubleClick:$("temperature"),showValue:!0,children:[e.jsx(k.Track,{children:e.jsx(k.Range,{})}),e.jsx(k.Thumb,{})]}),e.jsxs(k,{label:d.labels.tint,value:[p.tint??0],min:-100,max:100,step:1,onValueChange:F("tint"),onDoubleClick:$("tint"),showValue:!0,children:[e.jsx(k.Track,{children:e.jsx(k.Range,{})}),e.jsx(k.Thumb,{})]}),e.jsxs(k,{label:d.labels.vibrance,value:[p.vibrance??0],min:-100,max:100,step:1,onValueChange:F("vibrance"),onDoubleClick:$("vibrance"),showValue:!0,children:[e.jsx(k.Track,{children:e.jsx(k.Range,{})}),e.jsx(k.Thumb,{})]}),e.jsxs(k,{label:d.labels.saturation,value:[p.saturation??0],min:-100,max:100,step:1,onValueChange:F("saturation"),onDoubleClick:$("saturation"),showValue:!0,children:[e.jsx(k.Track,{children:e.jsx(k.Range,{})}),e.jsx(k.Thumb,{})]}),e.jsxs(k,{label:d.labels.exposure,value:[p.exposure??0],min:-100,max:100,step:1,onValueChange:F("exposure"),onDoubleClick:$("exposure"),showValue:!0,children:[e.jsx(k.Track,{children:e.jsx(k.Range,{})}),e.jsx(k.Thumb,{})]}),e.jsxs(k,{label:d.labels.brightness,value:[p.brightness??0],min:-100,max:100,step:1,onValueChange:F("brightness"),onDoubleClick:$("brightness"),showValue:!0,children:[e.jsx(k.Track,{children:e.jsx(k.Range,{})}),e.jsx(k.Thumb,{})]}),e.jsxs(k,{label:d.labels.contrast,value:[p.contrast??0],min:-100,max:100,step:1,onValueChange:F("contrast"),onDoubleClick:$("contrast"),showValue:!0,children:[e.jsx(k.Track,{children:e.jsx(k.Range,{})}),e.jsx(k.Thumb,{})]})]})]})]})},yi=({selectedJobHash:t,selectedHistoryItemId:n})=>{const{t:s}=O(),a=e.jsxs(X,{imageSrc:ta,imageAlt:"Adjust help",children:[e.jsx("p",{style:{marginBottom:8},children:s("options.adjust.help.intro")}),e.jsx("p",{style:{fontWeight:600,marginBottom:4},children:s("options.adjust.help.face_title")}),e.jsx("p",{style:{marginBottom:8},children:s("options.adjust.help.face")}),e.jsx("p",{style:{fontWeight:600,marginBottom:4},children:s("options.adjust.help.noise_title")}),e.jsx("p",{style:{marginBottom:8},children:s("options.adjust.help.noise")}),e.jsx("p",{style:{fontWeight:600,marginBottom:4},children:s("options.adjust.help.sharpen_title")}),e.jsx("p",{style:{marginBottom:12},children:s("options.adjust.help.sharpen")}),e.jsx("p",{style:{fontWeight:600,marginBottom:4},children:s("options.adjust.help.color_title")}),e.jsxs("ul",{children:[e.jsx("li",{children:s("options.adjust.help.light")}),e.jsx("li",{children:s("options.adjust.help.saturation")}),e.jsx("li",{children:s("options.adjust.help.white_balance")})]})]});return e.jsxs(e.Fragment,{children:[e.jsx(Ue,{text:s("options.adjust.title"),tooltip:a,textProps:{style:{marginRight:"auto"}},containerProps:{style:{justifyContent:"space-between"}}}),e.jsxs(Le,{children:[e.jsx(oi,{}),e.jsx(li,{}),e.jsx(ci,{}),e.jsx(_i,{}),e.jsx(vi,{selectedJobHash:t,selectedHistoryItemId:n})]})]})},Ei=()=>{const{t}
2=O(),{backgroundColor:n,setBackgroundColor:s,onToggle:a,persist:r}=ss();return l.useEffect(()=>{try{localStorage.getItem(ns)||r({color:"white"})}catch{}},[r]),e.jsxs(e.Fragment,{children:[e.jsx(ne,{text:t("options.background.replace_with_color"),checked:!!n,onChange:a}),n?e.jsx(as,{className:"mx-auto",color:n,onChangeComplete:i=>{s(i),r({color:i})}}):null]})},wi=()=>{const{t}=O(),n=L(),s=T(o=>o.request.background.remove),a=T(o=>o.request.background.prompt),r=pn(s),i=l.useMemo(()=>[{value:ve.AUTO,label:t("options.background.remove_types.auto")},{value:ve.HUMAN,label:t("options.background.remove_types.human")},{value:ve.ITEM,label:t("options.background.remove_types.item")},{value:ve.V2,label:t("options.background.remove_types.v2")},{value:ve.GENERATIVE,label:t("options.background.remove_types.generative")},{value:ve.GENERATIVE_REGENERATE,label:t("options.background.remove_types.generative_regenerate")}],[t]);l.useEffect(()=>{r&&!a&&n("setBackgroundOptions",{prompt:Nt})},[n,r,a]);const c=i.find(o=>o.value===s)??i[0];return e.jsxs(e.Fragment,{children:[e.jsx(le,{label:t("options.background.remove_type_label"),options:i,value:c,onChange:o=>{o&&n("setBackgroundOptions",{remove:o.value,...pn(o.value)&&!a?{prompt:Nt}:{}})}}),r?e.jsx(ae,{children:e.jsxs(oe.OptionsTextareaWrapper,{children:[e.jsx(oe.OptionsTextareaLabel,{text:t("options.background.generative_prompt_label")}),e.jsx(oe,{rows:4,value:a||Nt,onChange:o=>{n("setBackgroundOptions",{prompt:o.target.value})}})]})}):null,e.jsx(Ei,{})]})},ln=({isDisabled:t,children:n,message:s})=>{const[a,r]=l.useState({x:0,y:0}),[i,c]=l.useState(!1);if(!t)return e.jsx(e.Fragment,{children:n});const o=g=>{r({x:g.clientX,y:g.clientY})};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"disabled-section-wrapper",style:{cursor:"not-allowed"},onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),onMouseMove:o,children:e.jsx("div",{className:"enhance-section--disabled",children:n})}),i&&nn.createPortal(e.jsx("div",{className:"tooltip-radix-content",style:{position:"fixed",top:a.y+16,left:a.x+16,zIndex:9999,pointerEvents:"none",animationName:"none"},children:e.jsx(X,{children:s})}),document.body)]})},Ci=()=>{const{t}=O(),n=L(),{isStyleModeEnabled:s}=Ve(),a=T(m=>m.request.background.generate.description),r=T(m=>m.request.background.generate.item_area_percentage),i=()=>typeof r=="number"&&!Number.isNaN(r)?Math.min(1,Math.max(.35,r)):.5,[c,o]=De("enhance-options-bg-generate-location-enabled",!0),[g,d]=De("enhance-options-bg-generate-location-size",i()),p=Pe(()=>{!c||s||(a?n("setBackgroundGenerateItemAreaPercentage",g):n("setBackgroundGenerateItemAreaPercentage",null))}),{onToggle:x,persist:u}=Fe({enabled:c,storageKey:"enhance-options-bg-generate-location-memory",read:()=>({item_area_percentage:g}),write:m=>{if(!m){n("setBackgroundGenerateItemAreaPercentage",null);return}const j=Math.min(1,Math.max(.35,m.item_area_percentage??g));a&&!s?n("setBackgroundGenerateItemAreaPercentage",j):n("setBackgroundGenerateItemAreaPercentage",null)},toggle:()=>o(!c)});return l.useEffect(()=>{p()},[p,g,a,c]),e.jsx(ln,{isDisabled:s,message:"Location settings are disabled while Style Transfer is enabled.",children:e.jsx(ne,{text:t("options.background.change_object_size"),checked:c,onChange:x,children:c?e.jsx(e.Fragment,{children:e.jsxs(k,{label:t("options.background.object_size"),value:[parseInt(String(Math.round((g??1)*100)))],min:35,max:100,step:1,onValueChange:m=>{const j=m?.[0]??100,f=Math.min(1,Math.max(.35,j/100));d(f),u({item_area_percentage:f})},showValue:!0,renderValue:m=>`${m?.[0]}%`,children:[e.jsx(k.Track,{children:e.jsx(k.Range,{})}),e.jsx(k.Thumb,{})]})}):null})})},Dn=t=>e.jsxs("div",{...t.containerProps,className:he("sub-title",t.containerProps?.className),children:[t.text,t.children]}),os=({background:t,isSelected:n,...s})=>e.jsx("div",{className:"background-item-wrapper",title:t.name,children:e.jsxs("button",{...s,className:he("background-item",s.className,n&&"background-item--selected"),children:[e.jsx(Ie.div,{className:"image-wrapper",whileHover:{scale:1.05},transition:{type:"spring",duration:.4},children:e.jsx(na.LazyLoadImage,{src:t.thumbnail_path})}),e.jsx("div",{className:"text",children:t.name})]})}),ki={visible:{opacity:1,y:"0%",transition:{duration:.2,when:"beforeChildren"}},hidden:{opacity:0,y:"-20%",transition:{duration:.2,when:"afterChildren"}}},Si={visible:{transition:{delayChildren:jn(.01)}},hidden:{transition:{delayChildren:jn(.005,{from:"center"})}}},Ti={visible:{opacity:1,y:0},hidden:{opacity:0,y:10}}
2,Ni=({group:t,selectedBackgrounds:n,close:s,toggleBackground:a})=>e.jsxs(Ie.div,{style:{background:"white",height:"100%"},variants:ki,initial:"hidden",animate:"visible",exit:"hidden",children:[e.jsx("div",{className:"select-backgrounds-button",children:e.jsx(H,{leftIcon:e.jsx(Va,{}),text:t.name,variant:"outline",sizeVariant:"short",onClick:s})}),e.jsx(Le,{children:e.jsx(Ie.div,{className:"select-backgrounds",variants:Si,children:t.items.map(r=>e.jsx(Ie.div,{variants:Ti,children:e.jsx(os,{background:r,onClick:()=>a(r),isSelected:n.some(({_id:i})=>i===r._id)})},r._id))},`${t.name}-${t.items.length}`)})]}),Ii=()=>{const{t}=O(),n=L(),s=T(v=>v.request.background.generate.description),{backgroundDraft:a,setBackgroundDraft:r,isStyleModeEnabled:i}=Ve(),{data:c}=Wn(),[o,g]=l.useState(null),[d,p]=De("enhance-selected-backgrounds",[]),[x,u]=l.useState({}),m=l.useRef(null);l.useEffect(()=>{m.current=document.getElementById(bn)},[]);const j=l.useRef("manual"),f=l.useRef(!1),h=l.useCallback(v=>{const y=v.target.value;j.current="manual",r(y),i||n("setBackgroundGenerateDescription",y)},[r,i,n]);l.useEffect(()=>{const v=d.length>0,y={};if(d.forEach(I=>{const b=I.group;y[b]?y[b]++:y[b]=1}),u(y),!v){j.current==="selection"&&(j.current="manual",r(""),i||n("setBackgroundGenerateDescription",""));return}const E=sa(d);!f.current&&j.current==="manual"&&(s&&s.trim().length>0)&&s!==E||(j.current="selection",r(E),i||n("setBackgroundGenerateDescription",E))},[d,n,i,r,s]);const _=l.useCallback(v=>{f.current=!0,d.some(y=>y._id===v._id)?p(y=>y.filter(E=>E._id!==v._id)):p(y=>[...y,v])},[d,p]);return e.jsxs(ln,{isDisabled:i,message:"Background generation options are disabled while Style Transfer is enabled.",children:[m.current&&nn.createPortal(e.jsx(Vn,{mode:"wait",children:o?e.jsx(Ni,{toggleBackgroun
2d:_,selectedBackgrounds:d,group:o,close:()=>g(null)},`${o.name}-${o.items.length}`):null}),m.current),e.jsx(Dn,{text:t("options.background.components")}),e.jsx(oe,{required:!0,"aria-invalid":!a?.trim(),rows:3,placeholder:t("options.background.placeholder"),value:a||"",onChange:h}),!a?.trim()&&e.jsx("p",{role:"status",children:t("options.background.description_required",{defaultValue:"Enter a description to generate a background."})}),d.length?e.jsxs(ae,{children:[e.jsx(Dn,{text:t("options.background.selected")}),e.jsx("div",{className:"select-backgrounds",children:d.map(v=>e.jsx(os,{background:v,onClick:()=>_(v)},v._id))})]}):null,e.jsx("div",{className:"components",children:c&&c.map(v=>{let y=v.name;const E=x[y];return E&&(y=`${y} (${E})`),e.jsx("button",{className:"bg-group",onClick:()=>{m.current=document.getElementById(bn),g(v)},children:e.jsx("div",{className:"name",children:y})},v.name+v.ordering)})})]})},Ri=()=>e.jsxs(e.Fragment,{children:[e.jsx(Ci,{}),e.jsx(Ii,{})]});function Ai(t){const{t:n}=O(),{sourceUrl:s}=bt(t),a=rs(s,!0);return s?e.jsxs("div",{className:"background-foreground-preview",children:[a.data&&e.jsx("img",{src:a.data.url,alt:n("options.background.foreground_preview",{defaultValue:"Background removal preview"})}),a.isFetching&&e.jsx("span",{role:"status",children:n("options.canvas.loading_foreground",{defaultValue:"Preparing preview…"})}),a.isError&&e.jsxs("div",{role:"status",children:[n("options.canvas.foreground_error",{defaultValue:"Preview unavailable."}),e.jsx("button",{type:"button",onClick:()=>a.refetch(),children:n("options.canvas.retry",{defaultValue:"Retry"})})]})]}):null}const ze="off",Oi=t=>{switch(t){case de.REMOVE:return e.jsx(wi,{});case de.GENERATE:return e.jsx(Ri,{});default:return null}},Di=t=>t.background.remove?de.REMOVE:$n(t)?de.GENERATE:ze,Pi=t=>{const{t:n}=O(),s=T(g=>g.request),a=L(),{isStyleModeEnabled:r}=Ve(),i=Di(s),c=r?ze:i,o=n("options.background.disabled_by_style");return e.jsxs("div",{className:he("background-type-chooser",{"background-type-chooser--locked":r}),children:[e.jsx(ln,{isDisabled:r,message:o,children:e.jsx("div",{className:he("background-type-chooser__choices",{"background-type-chooser__choices--disabled":r}),children:e.jsxs(te.Group,{type:"single",value:c||ze,onValueChange:g=>{const d=g||ze;d===i||r||(a("clearBackgroundGenerateOptions"),a("clearBackgroundRemoveOptions"),d===de.REMOVE?a("setBackgroundRemoveType",ve.AUTO):d===de.GENERATE&&a("setBackgroundGenerateAdapterType",Oe.GENERATE_BACKGROUND))},children:[e.jsx(te.GroupItem,{label:n("options.background.off"),value:ze}),e.jsx(te.GroupItem,{label:n("options.background.remove"),value:de.REMOVE}),e.jsx(te.GroupItem,{label:n("options.background.generate"),value:de.GENERATE})]})})}),c===de.REMOVE&&e.jsx(Ai,{...t}),!r&&Oi(c)]})},Mi=t=>{const{t:n}=O(),s=e.jsxs(X,{imageSrc:aa,imageAlt:"Background help",children:[e.jsx("p",{style:{marginBottom:8},children:n("options.background.help.intro")}),e.jsx("p",{style:{fontWeight:600,marginBottom:4},children:n("options.background.help.options_title")}),e.jsxs("ul",{style:{marginBottom:12},children:[e.jsx("li",{children:n("options.background.help.options.remove")}),e.jsx("li",{children:n("options.background.help.options.generate")}),e.jsx("li",{children:n("options.background.help.options.color")})]}),e.jsx("p",{style:{fontWeight:600,marginBottom:4},children:n("options.background.help.generate_features_title")}),e.jsxs("ul",{children:[e.jsx("li",{children:n("options.background.help.generate_features.location")}),e.jsx("li",{children:n("options.background.help.generate_features.components")})]})]});return e.jsxs(e.Fragment,{children:[e.jsx(Ue,{text:n("options.background.title"),tooltip:s}),e.jsx(Le,{children:e.jsx(Pi,{...t})})]})},Li=t=>t?t.split(/[_-]+/).map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" "):"",ls=({id:t,name:n,displayName:s,referenceImageUrl:a,isLoadable:r=!0,isSelected:i,onSelect:c,onLoad:o,onDelete:g,isDeleting:d=!1,config:p})=>{const{t:x}=O(),{t:u}=an(),[m,j]=l.useState(!1),f=x(r?"options.presets.load_tooltip":"options.presets.load_disabled_tooltip");
2return e.jsxs("div",{className:"enhance-presets-row",children:[e.jsx("div",{className:`enhance-presets-item ${i?"enhance-presets-item--selected":""}`,onClick:c,onKeyDown:h=>{(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),c())},role:"button",tabIndex:0,children:e.jsxs("div",{className:"enhance-presets-item__main",children:[e.jsx("div",{className:`enhance-presets-item__thumb ${a?"enhance-presets-item__thumb--transparent":""}`,children:a?e.jsx("img",{src:a,alt:""}):e.jsx(fr,{width:16,height:16})}),e.jsx("div",{className:"enhance-presets-item__name",children:s||Li(n)})]})}),e.jsxs("div",{className:"enhance-presets-row__actions",children:[r?e.jsx(H,{variant:"primary",sizeVariant:"shorter",text:x("options.presets.load_label"),onClick:h=>{h.stopPropagation(),o()},title:f,className:"enhance-presets-action-btn"}):e.jsx(tn,{content:e.jsx(X,{children:f}),children:e.jsx("span",{className:"d-inline-block",children:e.jsx(H,{variant:"primary",sizeVariant:"shorter",text:x("options.presets.load_label"),disabled:!0,onClick:h=>{h.stopPropagation()},className:"enhance-presets-action-btn"})})}),e.jsx("div",{onClick:h=>h.stopPropagation(),children:e.jsxs(et,{children:[e.jsx(et.Trigger,{children:e.jsx(H,{variant:"transparent",sizeVariant:"shorter",icon:e.jsx(ra,{})})}),e.jsx(et.Menu,{contentProps:{sideOffset:0,side:"top"},children:e.jsx(et.MenuItem,{onSelect:()=>j(!0),children:x("options.presets.show_api_request")})})]})}),g&&e.jsx(tt,{title:x("options.presets.delete_confirm_title"),description:x("options.presets.delete_confirm_desc"),trigger:e.jsx(H,{variant:"tertiary",sizeVariant:"shorter",icon:e.jsx(sn,{}),"aria-label":x("options.presets.delete"),disabled:d,onClick:h=>{h.stopPropagation()},title:x("options.presets.delete")}),children:e.jsxs("div",{className:"d-flex justify-content-end gap-2 w-100",children:[e.jsx(tt.Close,{children:e.jsx("div",{className:"enhance-presets-dialog-action-wrapper",children:e.jsx(H,{variant:"primary",text:u("options.presets.cancel"),className:"enhance-presets-btn--full"})})}),e.jsx(tt.Close,{children:e.jsx("div",{className:"enhance-presets-dialog-action-wrapper",children:e.jsx(H,{variant:"tertiary",text:x("options.presets.delete"),onClick:()=>g(),className:"enhance-presets-btn--full"})})})]})})]}),e.jsx(tt,{open:m,onHeaderCloseButtonClick:()=>j(!1),title:x("options.presets.api_dialog.title"),size:"lg",children:e.jsxs("div",{className:"enhance-presets-api-dialog",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"enhance-presets-api-dialog__section-title",children:x("options.presets.api_dialog.preset_parameter")}),e.jsx("div",{className:"enhance-presets-api-dialog__json-box",children:e.jsx(Kt,{src:{preset:n},name:null,displayDataTypes:!1,displayObjectSize:!1})})]}),e.jsx("div",{className:"enhance-presets-api-dialog__separator",children:x("options.presets.api_dialog.or")}),e.jsxs("div",{children:[e.jsx("h4",{className:"enhance-presets-api-dialog__section-title",children:x("options.presets.api_dialog.config_parameters")}),e.jsx("div",{className:"enhance-presets-api-dialog__json-box",children:e.jsx(Kt,{src:p,name:null,displayDataTypes:!1,collapsed:!1,displayObjectSize:!1})})]})]})})]})},Ui=()=>{const{t}=O();return e.jsx(ae,{children:t("options.presets.unauthorized.message")})},Vi=t=>{const n=t.trim();if(!n)return!1;if(n.startsWith("data:image/"))return!0;try{const s=new URL(n);return s.protocol==="http:"||s.protocol==="https:"}catch{return!1}},Fi=t=>{const n=t?.background?.generate?.context_images,s=t?.reference_image_url||(Array.isArray(n)&&n.length>0?n[n.length-1]:null);if(!s)return null;const a=String(s);if(!Vi(a))return null;if(a.trim().startsWith("data:image/"))return a;try{const r=new URL(a),i=r.searchParams;return i.get("thumbnail_url")&&i.delete("thumbnail_url"),r.origin+r.pathname+(i.toString()?`?${i.toString()}`:"")}catch{return null}},Bi=()=>{const{t}=O(),{t:n}=an(),{user:s}=fe(C=>C.auth),a=s?._id,i=!!ia()&&!!s,{data:c,isLoading:o,isError:g,refetch:d}=oa("enhancer_studio",{enabled:i}),p=mt(!!(i&&o),500),x=T(C=>C.request),u=L(),m=rn(),[j,f]=l.useState(""),[h,_]=l.useState(!1),[v,y]=l.useState(null);l.useEffect(()=>{if(!v)return;const C=setTimeout(()=>{y(null)},400);return()=>clearTimeout(C)},[v]);const{mutateAsync:E,isLoading:I}=la(),{mutateAsync:b,isLoading:R}=ca(),U=l.useCallback(C=>{m(C.config,{referenceImageUrl:C.reference_image_url}),y(C.id)},[m]),F=l.useCallback(C=>{x.preset===C.name?u("setPreset",null):u("setPreset",C.name)},[u,x.preset]),$=l.useMemo(()=>(c||[]).slice().sort((C,P)=>{const G=(C.display_name||C.name||"").toLowerCase(),S=(P.display_name||P.name||"").toLowerCase();return G.localeCompare(S)}),[c]),w=l.useCallback(async()=>{const C=j.trim();if(!C)return;const P=Fi(x),G=C.toLowerCase().replace(/\s+/g,"_"),S=Fa(x);S.background?.generate?.context_images&&delete S.background.generate.context_images,S.background?.generate?.context_images_back&&delete S.background.generate.context_images_back;const N=P||void 0;
2N&&(S.reference_image_url=N),await E({name:G,display_name:C,config:S,reference_image_url:N,owner_id:a}),await d(),f(""),_(!1)},[E,j,d,x,a]),A=l.useCallback(async C=>{await b(C),await d()},[b,d]);return i?p?e.jsxs("div",{className:"enhance-presets-section",children:[e.jsx(Q,{as:"div",text:t("options.presets.own_label"),className:"enhance-presets-header",tooltip:e.jsx(X,{children:e.jsx("p",{children:t("options.presets.own_help")})})}),e.jsxs("div",{className:"enhance-presets-list",children:[e.jsx("div",{className:"enhance-presets-row",children:e.jsx(Re,{style:{height:32,width:"100%",borderRadius:8,margin:4}})}),e.jsx("div",{className:"enhance-presets-row",children:e.jsx(Re,{style:{height:32,width:"100%",borderRadius:8,margin:4}})}),e.jsx("div",{className:"enhance-presets-row",children:e.jsx(Re,{style:{height:32,width:"100%",borderRadius:8,margin:4}})})]})]}):g?e.jsxs("div",{className:"enhance-presets-section",children:[e.jsx(Q,{as:"div",text:t("options.presets.own_label"),className:"enhance-presets-header",tooltip:e.jsx(X,{children:e.jsx("p",{children:t("options.presets.own_help")})})}),e.jsx("div",{className:"enhance-presets-list",children:e.jsxs("div",{className:"enhance-presets-message",children:[e.jsx("p",{style:{margin:0},children:t("options.presets.load_error")}),e.jsx(H,{variant:"outline",sizeVariant:"short",text:n("options.presets.try_again"),onClick:()=>d(),type:"button"})]})})]}):e.jsxs("div",{className:"enhance-presets-section",children:[e.jsx(Q,{as:"div",text:t("options.presets.own_label"),className:"enhance-presets-header",tooltip:e.jsx(X,{children:e.jsx("p",{children:t("options.presets.own_help")})})}),e.jsxs("div",{className:"enhance-presets-list",children:[e.jsxs("div",{className:he("enhance-presets-own__controls",$.length!==0&&"enhance-presets-own__controls--border-bottom"),children:[h?e.jsxs("div",{className:"enhance-presets-create-form",children:[e.jsx(gt,{autoFocus:!0,disabled:I||R,type:"text",placeholder:t("options.presets.name_placeholder"),value:j,onChange:C=>f(C.target.value),onKeyDown:C=>{C.key==="Enter"&&(C.preventDefault(),w()),C.key==="Escape"&&(C.preventDefault(),_(!1),f(""))}}),e.jsx(H,{text:n("options.presets.save_button"),disabled:I||R||!j.trim(),onClick:()=>{w()},variant:"primary",sizeVariant:"short",className:"enhance-presets-btn--small"}),e.jsx(H,{variant:"tertiary",sizeVariant:"short","aria-label":n("options.presets.cancel"),onClick:()=>{_(!1),f("")},disabled:I||R,icon:e.jsx(sn,{}),noPadding:!0})]}):e.jsx("div",{className:"enhance-presets-create-wrapper",children:e.jsx(H,{text:t("options.presets.create_button"),className:"enhance-presets-btn--full enhance-presets-btn--small",onClick:()=>_(!0),variant:"outline",sizeVariant:"short"})}),$.length===0&&e.jsx("span",{className:"enhance-presets-empty",children:t("options.presets.empty_state")})]}),$?.length?e.jsx("div",{className:"enhance-presets-own__list",children:$.map(C=>{const P=x.preset===C.name,G=!C.image_apps||C.image_apps.includes("enhancer_studio");return e.jsx(ls,{id:C.id,name:C.name,displayName:C.display_name,referenceImageUrl:C.reference_image_url,isLoadable:G,isSelected:P,onSelect:()=>F(C),onLoad:()=>U(C),onDelete:()=>A(C.id),isDeleting:R,config:C.config},C.id)})}):null," "]})]}):e.jsxs("div",{className:"enhance-presets-section",children:[e.jsx(Q,{as:"div",text:t("options.presets.own_label"),className:"enhance-presets-header",tooltip:e.jsx(X,{children:e.jsx("p",{children:t("options.presets.own_help")})})}),e.jsx("div",{className:"enhance-presets-list",children:e.jsx(Ui,{})})]})},Gi=()=>{const{t}=O(),n=Ke(ua),{t:s}=an(),a=T(_=>_.request),r=L(),i=rn(),{data:c,isLoading:o,isError:g,refetch:d}=Bn("enhancer_studio"),p=l.useMemo(()=>c?.filter(_=>!n||![gn.AUTO_ENHANCE_PRO,gn.AUTO_ENHANCE_QWEN].includes(_.name)),[c,n]),x=mt(!!o,500),[u,m]=l.useState(null);l.useEffect(()=>{if(!u)return;const _=setTimeout(()=>m(null),400);return()=>clearTimeout(_)},[u]);const j=l.useMemo(()=>(p||[]).reduce((_,v)=>(_[v.name]=v,_),{}),[p]),f=l.useCallback(_=>{a.preset===_?r("setPreset",null):r("setPreset",_)},[r,a.preset]),h=l.useCallback(_=>{const v=j[_];v&&(i(v.config,{referenceImageUrl:v.reference_image_url}),m(v.id))},[i,j]);
2return x?e.jsxs("div",{className:"enhance-presets-section enhance-presets-section--app",children:[e.jsx(Q,{as:"div",text:t("options.presets.shared_label"),className:"enhance-presets-header",tooltip:e.jsx(X,{children:e.jsx("p",{children:t("options.presets.shared_help")})})}),e.jsxs("div",{className:"enhance-presets-list",children:[e.jsx("div",{className:"enhance-presets-row",children:e.jsx(Re,{style:{height:32,width:"100%",borderRadius:8,margin:4}})}),e.jsx("div",{className:"enhance-presets-row",children:e.jsx(Re,{style:{height:32,width:"100%",borderRadius:8,margin:4}})}),e.jsx("div",{className:"enhance-presets-row",children:e.jsx(Re,{style:{height:32,width:"100%",borderRadius:8,margin:4}})})]})]}):g?e.jsxs("div",{className:"enhance-presets-section enhance-presets-section--app",children:[e.jsx(Q,{as:"div",text:t("options.presets.shared_label"),className:"enhance-presets-header",tooltip:e.jsx(X,{children:e.jsx("p",{children:t("options.presets.shared_help")})})}),e.jsx("div",{className:"enhance-presets-list",children:e.jsxs("div",{className:"enhance-presets-message",children:[e.jsx("p",{style:{margin:0},children:t("options.presets.load_error")}),e.jsx(H,{variant:"outline",sizeVariant:"short",text:s("options.presets.try_again"),onClick:()=>d(),type:"button"})]})})]}):!p||!p.length?null:e.jsxs("div",{className:"enhance-presets-section enhance-presets-section--app",children:[e.jsx(Q,{as:"div",text:t("options.presets.shared_label"),className:"enhance-presets-header",tooltip:e.jsx(X,{children:e.jsx("p",{children:t("options.presets.shared_help")})})}),e.jsx("div",{className:"enhance-presets-list",children:p.map(_=>{const v=a.preset===_.name,y=!_.image_apps||_.image_apps.includes("enhancer_studio");return e.jsx(ls,{id:_.id,name:_.name,displayName:_.display_name,referenceImageUrl:_.reference_image_url,isLoadable:y,isSelected:v,onSelect:()=>f(_.name),onLoad:()=>h(_.name),config:_.config},_.id)})})]})},Wi=()=>{const{t}=O(),n=L(),s=T(g=>g.presetExtraOptions),[a,r]=l.useState(!1),i=l.useRef(null),c=l.useMemo(()=>s?Object.keys(s).length:0,[s]),o=l.useCallback(()=>{n("setPresetExtraOptions",null)},[n]);return l.useEffect(()=>{a&&i.current&&setTimeout(()=>{i.current?.scrollIntoView({behavior:"smooth",block:"end"})},100)},[a]),c===0?null:e.jsx("div",{className:"enhance-presets-section enhance-presets-section--extra",ref:i,children:e.jsxs(ae,{children:[e.jsxs("div",{className:"enhance-presets-extra__header",children:[e.jsx(tn,{content:e.jsxs(X,{children:[e.jsx("p",{children:t("options.presets.extra_options.help.what")}),e.jsxs("ul",{children:[e.jsx("li",{children:t("options.presets.extra_options.help.sent")}),e.jsx("li",{children:t("options.presets.extra_options.help.remove")})]})]}),children:e.jsx("div",{className:"enhance-presets-extra__info",children:e.jsx(da,{size:18,color:"#64748b"})})}),e.jsxs("div",{className:"enhance-presets-extra__text",children:[e.jsx("div",{className:"enhance-presets-extra__title",children:t("options.presets.extra_options.active_title")}),e.jsx("div",{className:"enhance-presets-extra__desc",children:t("options.presets.extra_options.active_desc")})]})]}),e.jsxs("div",{className:"enhance-presets-extra__actions",children:[e.jsx(H,{variant:"outline",sizeVariant:"shorter",text:t(a?"options.presets.hide_details":"options.presets.show_details"),onClick:()=>r(g=>!g),className:"enhance-presets-extra__action-btn "}),e.jsx(H,{variant:"tertiaryOutline",sizeVariant:"shorter",text:t("options.presets.clear_all"),onClick:o,className:"enhance-presets-extra__action-btn"})]}),a&&e.jsx("div",{className:"enhance-presets-extra__json",children:e.jsx(Kt,{src:s||{},name:!1,collapsed:2,displayDataTypes:!1,displayObjectSize:!1,enableClipboard:!0,theme:"rjv-default"})})]})})},zi=()=>{const{t}=O();return e.jsxs(e.Fragment,{children:[e.jsx(Ue,{text:t("options.presets.title"),tooltip:e.jsxs(X,{children:[e.jsx("p",{children:t("options.presets.help.intro")}),e.jsxs("ul",{children:[e.jsxs("li",{children:[e.jsx("strong",{children:t("options.presets.help.select_title")}),t("options.presets.help.select_body")]}),e.jsxs("li",{children:[e.jsx("strong",{children:t("options.presets.help.load_title")}),t("options.presets.help.load_body")]})]}),e.jsx("p",{children:t("options.presets.help.extra")})]})}
2),e.jsx(Le,{children:e.jsxs("div",{className:"enhance-presets-content",children:[e.jsx(Bi,{}),e.jsx(Gi,{}),e.jsx(Wi,{})]})})]})};function $i(t){return ha({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{d:"M3 3a2 2 0 0 1 2-2h9.982a2 2 0 0 1 1.414.586l4.018 4.018A2 2 0 0 1 21 7.018V21a2 2 0 0 1-2 2H4.75a.75.75 0 0 1 0-1.5H19a.5.5 0 0 0 .5-.5V8.5h-4a2 2 0 0 1-2-2v-4H5a.5.5 0 0 0-.5.5v6.25a.75.75 0 0 1-1.5 0Zm12-.5v4a.5.5 0 0 0 .5.5h4a.5.5 0 0 0-.146-.336l-4.018-4.018A.5.5 0 0 0 15 2.5Z"},child:[]},{tag:"path",attr:{d:"M4.53 12.24a.75.75 0 0 1-.039 1.06l-2.639 2.45 2.64 2.45a.75.75 0 1 1-1.022 1.1l-3.23-3a.75.75 0 0 1 0-1.1l3.23-3a.75.75 0 0 1 1.06.04Zm3.979 1.06a.75.75 0 1 1 1.02-1.1l3.231 3a.75.75 0 0 1 0 1.1l-3.23 3a.75.75 0 1 1-1.021-1.1l2.639-2.45-2.64-2.45Z"},child:[]}]})(t)}const Gt=[{value:"auto",label:"Auto"},{value:It.JPEG,label:"JPEG"},{value:It.PNG,label:"PNG"},{value:It.WEBP,label:"WEBP"}],qi=()=>{const{t}=O(),{i18n:n}=Me(),s=L(),{use_original_filename:a,keep_icc_profile:r,output_format:i}=T(g=>g.request),c=l.useMemo(()=>Gt.find(g=>g.value===(i||"auto"))||Gt[0],[i]),o=e.jsxs(X,{children:[e.jsx("p",{style:{marginBottom:8},children:t("options.advanced.help.intro")}),e.jsx("p",{style:{fontWeight:600,marginBottom:4},children:t("options.advanced.help.features_title")}),e.jsxs("ul",{children:[e.jsx("li",{children:t("options.advanced.help.features.filename")}),e.jsx("li",{children:t("options.advanced.help.features.icc_profile")}),e.jsx("li",{children:t("options.advanced.help.features.format")}),e.jsx("li",{children:t("options.advanced.help.features.api")})]})]});return e.jsxs(e.Fragment,{children:[e.jsx(Ue,{text:t("options.advanced.title"),tooltip:o}),e.jsxs(Le,{children:[e.jsx(ne,{text:n.t("application.options.advancedOptions.keep_original_file_name"),checked:!!a,onChange:()=>s("setAdvancedKeepOriginalFileName",a?null:!0)}),e.jsx(ne,{text:n.t("application.options.advancedOptions.keepIccProfile"),checked:!!r,onChange:()=>s("setAdvancedKeepIccProfile",r?null:!0)}),e.jsx(le,{label:n.t("application.options.advancedOptions.save_as"),options:Gt,value:c,onChange:g=>{const d=g?.value??"auto";s("setAdvancedSaveFormat",d==="auto"?null:d)}}),e.jsx(Ba,{triggerButtonProps:{style:{aspectRatio:"unset"},variant:"primary",sizeVariant:"medium",text:t("options.advanced.api_request"),icon:null,rightIcon:e.jsx($i,{size:24,strokeWidth:.25})}})]})]})},Hi=t=>t?t.replace(/\/$/,""):null,qe=t=>t.startsWith("http://")||t.startsWith("https://"),Wt=t=>{if(!t)return null;if(!qe(t))return t;try{const n=new URL(t);return`${n.origin}${n.pathname}`.replace(/\/$/,"")}catch{return Hi(t)}},We=t=>{const n=je(t.img_url||"")||je(t.thumbnail_url||"");if(!n)return null;try{const s=new URL(n),a=je(t.thumbnail_url||"");return a&&s.searchParams.set("thumbnail_url",a),s.toString()}catch(s){return console.error("Failed to build context image URL",s),null}},Pn=t=>{if(!t)return null;if(!qe(t))return{raw:t,source:t,thumbnail:void 0};try{const n=new URL(t),s=n.searchParams,a=s.get("thumbnail_url");a&&s.delete("thumbnail_url");const r=n.origin+n.pathname+(s.toString()?`?${s.toString()}`:"");return{raw:t,source:r,thumbnail:a||void 0}}catch(n){return console.error("Failed to parse context image URL",n),{raw:t,source:t,thumbnail:void 0}}},Ki=(t,n)=>{if(!n)return!1;if(!qe(n))return t.id===n;const s=Wt(n);return[Wt(je(t.img_url||"")),Wt(je(t.thumbnail_url||""))].filter(Boolean).some(r=>r===s)},Yi=({isBlockedByBackgroundGenerate:t=!1,isStyleModeEnabled:n})=>{const{t:s}=O(),{i18n:a}=Me(),r=en(),i=L(),c=T(S=>S.isSendingRequest),o=T(S=>S.request.background.generate.context_images),g=T(S=>S.request.reference_image_url),[d,p]=l.useState(!1),x=l.useRef(!1),u=l.useRef(!1),{data:m}=Ae(Y.REF_IMAGE,{skipStateUpdate:!0}),j=l.useRef(m?.length??0),f=l.useMemo(()=>!m||m.length===0?null:m[m.length-1],[m]),h=l.useMemo(()=>{if(g)return Pn(g);if(Array.isArray(o)&&o.length>0){const S=o[o.length-1];return Pn(S)}return null},[o,g]),_=l.useMemo(()=>!h?.source||!m?null:m.find(S=>Ki(S,h.source))||null,[h?.source,m]),{mutate:v,isLoading:y}=pa(_?.id??"",Y.REF_IMAGE,{onSuccess:()=>{p(!0),i("setReferenceImageUrl",null)}});ga(S=>S&&S.preventDefault()),l.useEffect(()=>{h?.raw&&p(!1)},[h?.raw]),l.useEffect(()=>{!n||d||h?.raw||!f||f.id&&i("setReferenceImageUrl",f.id)},[n,f,h?.raw,d,i]),l.useEffect(()=>{if(!n||!m)return;const S=m.length,N=j.current;S>N&&x.current&&f&&!d&&(f.id&&i("setReferenceImageUrl",f.id),x.current=!1),j.current=S},[n,m,f,i,d]),l.useEffect(()=>{if(!(!n||!m||!g)){if(!qe(g)){const S=m.find(N=>N.id===g);if(S){const N=We(S);N&&i("setReferenceImageUrl",N)}return}if(_){const S=We(_);S&&S!==g&&i("setReferenceImageUrl",S)}}},[n,m,g,_,i]),l.useEffect(()=>{if(!(!n||!m)){if(c){u.current=!0;return}
2if(u.current&&_){try{ma(_.id,Y.REF_IMAGE),Te.invalidateQueries({queryKey:Ae.key(Y.REF_IMAGE)})}catch(S){console.error(S)}u.current=!1}}},[n,c,_]),l.useEffect(()=>{if(!n||!o||!o.length||!m)return;const S=o[0];if(S.startsWith("http://")||S.startsWith("https://"))return;const W=m.find(ee=>ee.id===S);if(W){const ee=We(W);ee&&(i("setReferenceImageUrl",ee),i("setBackgroundGenerateOptions",{context_images:null,context_images_back:null}))}},[n,o,m,i]);const{fileInput:E,handleUpload:I,browseFiles:b,isLoading:R,isDisabled:U}=fa({app:Y.REF_IMAGE,isSingleUpload:!0,keep_it:!1,metadata:{isContextOnly:"true"}}),F=l.useCallback(S=>{if(S?.stopPropagation(),S?.preventDefault(),_?.id){v();return}i("setReferenceImageUrl",null)},[i,_?.id,v]),$=l.useCallback(S=>{S.preventDefault(),!U&&!R&&(p(!1),x.current=!0,I(S))},[U,R,I]),w=l.useCallback(()=>{p(!1),x.current=!0,b()},[b]),A=_?.thumbnail_url||_?.img_url||h?.thumbnail||h?.source||null,C=!A&&!t&&!U&&!R,P=l.useCallback(S=>{p(!1),x.current=!0,I(S)},[I]);xa(P,{enabled:C,maxFiles:1,shouldHandlePaste:S=>!!document.activeElement?.closest(".enhancer-reference-panel")});const G=l.useCallback(()=>{if(m){if(_){const S=We(_);if(S){i("setReferenceImageUrl",S);return}}if(f){const S=We(f);if(S){p(!1),i("setReferenceImageUrl",S);return}}h?.source&&qe(h.source)&&!_||(p(!0),i("setReferenceImageUrl",null),r({type:Ln,notification:_a(a.t("application.error_message.reference_image_unavailable"))}))}},[i,r,a,_,m,f,h?.source,h?.thumbnail,n,g]);return e.jsx("div",{className:"enhancer-reference-panel",children:e.jsxs(Q,{as:"div",text:s("options.style.reference_image.label"),children:[e.jsx("input",{ref:E,disabled:!!A||R,"data-testid":"reference-image-input",onClick:S=>{S.target.value=""},type:"file",name:"reference-image",accept:"image/*",style:{display:"none"},onChange:I}),e.jsxs("div",{onDrop:$,onDragOver:S=>S.preventDefault(),children:[!A&&e.jsx("div",{className:"d-flex gap-2 align-items-center flex-wrap",children:e.jsx(H,{className:"w-100",variant:"outline",sizeVariant:"short",text:s(R?"options.style.reference_image.uploading":"options.style.reference_image.upload_button"),onClick:w,disabled:t||R||U||y})}),h?.raw&&A&&e.jsxs("div",{className:"mt-1",style:{cursor:"default",position:"relative",marginLeft:"auto",marginRight:"auto",width:120,height:120,borderRadius:8,overflow:"hidden",backgroundColor:"#f3f4f6"},children:[e.jsx("img",{src:A,alt:s("options.style.reference_image.thumbnail_alt"),onError:G,style:{display:"block",width:"120px",height:"120px",objectFit:"cover"}}),e.jsx(H,{style:{position:"absolute",top:4,right:4},variant:"tertiary",icon:y?e.jsx(ja,{}):e.jsx(sn,{}),"aria-label":s("options.style.reference_image.clear_button_aria"),disabled:y,sizeVariant:"shorter",roundedVariant:"full",onClick:F})]})]})]})})},Qi=()=>{const{styleDraft:t,setStyleDraft:n,isStyleModeEnabled:s,toggleStyleMode:a}=Ve(),{t:r}=O(),i=L(),c=T(f=>f.request.reference_image_url),o=T(f=>f.request.background.generate),g=T(f=>f.request.background.generate.context_images),d=l.useCallback(f=>{const _=(Te.getQueryData(Ae.key(Y.REF_IMAGE))||[]).find(y=>y?.id===f);if(!_)return null;const v=je(_?.img_url||"")||je(_?.thumbnail_url||"");if(!v)return null;try{const y=new URL(v),E=je(_?.thumbnail_url||"");return E&&!y.searchParams.get("thumbnail_url")&&y.searchParams.set("thumbnail_url",E),y.toString()}catch{return v}},[]),p=l.useCallback(f=>{if(!f)return null;const h=String(f);if(!h.startsWith("http://")&&!h.startsWith("https://"))return h;try{const _=new URL(h);return _.searchParams.get("thumbnail_url")||_.searchParams.set("thumbnail_url",h),_.toString()}catch{return h}},[]),x=l.useMemo(()=>c?!0:!!(Array.isArray(g)&&g.length>0),[c,g]);l.useEffect(()=>{if(!s)return;const f=p(c??null),h=p(g?.[0]??null);if(typeof f=="string"&&mn(f)){const _=d(f);if(_&&_!==c){i("setReferenceImageUrl",_);return}}if(!f&&typeof h=="string"&&mn(h)){const _=d(h);if(_){i("setReferenceImageUrl",_),i("setBackgroundGenerateOptions",{context_images:null,context_images_back:null});return}}if(!f&&h){i("setReferenceImageUrl",h),i("setBackgroundGenerateOptions",{context_images:null,context_images_back:null});return}f&&c!==f&&i("setReferenceImageUrl",f)},[s,c,g,p,d,i]);const u=l.useCallback(f=>{a(f)},[a]);l.useEffect(()=>{s&&(x?(o.adapter_type!==Oe.IMG2IMG||o.model_type!==zt.GOOGLE_GEMINI_PRO||o.description!==t)&&i("setBackgroun
2dGenerateOptions",{description:t,adapter_type:Oe.IMG2IMG,model_type:zt.GOOGLE_GEMINI_PRO}):((o.description!==""||o.adapter_type!==null||o.model_type!==null)&&i("setBackgroundGenerateOptions",{description:"",adapter_type:null,model_type:null}),c&&i("setReferenceImageUrl",null)))},[x,s,t,i,o.adapter_type,o.model_type,o.description,c]);const m=l.useCallback(f=>{const h=f.target.value;n(h)},[n]),j=e.jsxs(X,{children:[e.jsx("p",{style:{marginBottom:8},children:r("options.style.help.intro")}),e.jsx("p",{style:{fontWeight:600,marginBottom:4},children:r("options.style.help.options_title")}),e.jsxs("ul",{children:[e.jsx("li",{children:r("options.style.help.options.description")}),e.jsx("li",{children:r("options.style.help.options.reference")})]})]});return e.jsxs(e.Fragment,{children:[e.jsx(Ue,{text:r("options.style.title"),tooltip:j}),e.jsx(Le,{children:e.jsx(ne,{text:r("options.style.enable"),checked:s,onChange:u,children:s&&e.jsxs(e.Fragment,{children:[e.jsx("div",{children:e.jsx(Q,{text:r("options.style.description_label"),children:e.jsx(oe,{"data-testid":"style-desc",rows:3,placeholder:r("options.style.description_placeholder"),value:t||"",onChange:m})})})," ",e.jsx(Yi,{isStyleModeEnabled:s})]})})})]})},Xi=t=>!!(t.width||t.height||t.min_length||t.print_size||t.dpi||t.fit&&typeof t.fit=="object"&&"canvas"in t.fit&&t.fit.canvas==="outpainting"||t.generative_upscale||t.upscale_parameters?.type||t.upscale_strength),Zi=t=>{const n=[D.DENOISE,D.DEBLUR,D.FACE_ENHANCE,D.LIGHT,D.COLOR,D.WHITE_BALANCE,D.CLEAN,D.EXPOSURE_CORRECTION,D.GENERATIVE_TONE_CORRECTION],s=t.enhancements?.some?.(r=>n.includes(r)),a=t.light_parameters?.type!==null||t.light_parameters?.level!==null||t.color_parameters?.type!==null||t.color_parameters?.level!==null||t.deblur_parameters?.type!==null||t.denoise_parameters?.type!==null||t.face_enhance_parameters?.type!==null||t.face_enhance_parameters?.level!==null||t.face_enhance_parameters?.smoothing_level!==null||t.white_balance_parameters?.type!==null||t.white_balance_parameters?.level!==null||(t.corrections?Object.values(t.corrections).some(r=>!!r):!1);return s||a},Ji=(t,n)=>!!t.preset||!!n,eo=t=>!!(t.use_original_filename||t.keep_icc_profile||t.output_format!==null),to=({selectedJobHash:t,selectedHistoryItemId:n,latestJobHash:s,rootJobHash:a,onNewJobCreated:r,onAddImage:i,isUploadOpen:c})=>{const{t:o}=O(),g=l.useContext(Hn),d=l.useContext(ft);Wn(),_r();const{data:p}=ye(t||void 0),x=L(),{toggleStyleMode:u,isStyleModeEnabled:m}=Ve();De("enhance-tab-id","upscale");const j=Ke(He),f=l.useMemo(()=>j.find(N=>N.metadata?.isContextOnly!=="true"),[j]),h=T(N=>N.request),_=T(N=>N.presetExtraOptions),v=T(N=>N.optionsRemountTrigger),y=l.useCallback(()=>{u(!1),x("setRequest",JSON.parse(JSON.stringify(dt.request))),x("setPresetExtraOptions",null),x("triggerOptionsRemount")},[x,u]),E=l.useMemo(()=>{const N=Ga(JSON.parse(JSON.stringify(dt.request)),h),W=Wa(N,dt.request),ee=!h.preset&&!_;return W&&ee},[h,_]),I=l.useCallback(N=>{const W=!!N.background?.color&&!!N.background?.remove,ee=$n(N);return!!(N.background?.remove||W||ee&&!m||N.placement)},[m]),b=l.useMemo(()=>!!h.reference_image_url,[h.reference_image_url]),R=!!h.preset,U=R?o("options.preset_active_tooltip"):void 0,F=R||b,$=R?U:b?o("options.background.disabled_by_style"):void 0,w=R||I(h),A=R?U:I(h)?o("options.style.disabled_by_background"):void 0,C=l.useMemo(()=>[{id:"upscale",label:o("options.canvas.title"),icon:e.jsx(ba,{size:27}),render:()=>e.jsx(ii,{hidePreview:c,selectedJobHash:t,selectedHistoryItemId:n,rootJobHash:a}),hasActiveOptions:Xi(h),isDisabled:R,tooltip:U},{id:"adjust",label:o("options.tabs.adjust"),icon:e.jsx(zn,{size:30}),render:()=>e.jsx(yi,{selectedJobHash:t,selectedHistoryItemId:n}),hasActiveOptions:Zi(h),isDisabled:R,tooltip:U},{id:"background",label:o("options.tabs.background"),icon:e.jsx(Gn,{size:30}),render:()=>e.jsx(Mi,{selectedJobHash:t,selectedHistoryItemId:n,rootJobHash:a}),hasActiveOptions:I(h),isDisabled:F,tooltip:$},{id:"style-reference",label:o("options.tabs.style"),icon:e.jsx(va,{size:26}),render:()=>e.jsx(Qi,{}),isHidden:!1,hasActiveOptions:b,isDisabled:w,tooltip:A},{id:"presets",label:o("options.tabs.presets"),icon:e.jsx(ya,{size:30}),render:()=>e.jsx(zi,{}
2),hasActiveOptions:Ji(h,_)},{id:"advanced",label:o("options.tabs.advanced"),icon:e.jsx(Ea,{size:30}),render:()=>e.jsx(qi,{}),hasActiveOptions:eo(h)}],[h,c,_,t,n,a,o,b,I,R,U,F,$,w,A]),P=l.useMemo(()=>{if(t){const N=j.find(W=>W.metadata?.isContextOnly==="true"&&(!a||W.metadata?.originalImageId===a));return N?[N]:!a&&f?[f]:[]}return f?[f]:[]},[j,a,t,f]),G=l.useMemo(()=>{const N=a?s||a||void 0:t||void 0;return e.jsxs("div",{className:"submit-container",style:{display:"flex",gap:"8px"},children:[e.jsx(H,{text:o("images_panel.add_image",{defaultValue:"Add image"}),icon:e.jsx(wa,{size:24}),rightIcon:null,variant:"tertiary",onClick:()=>{i?.(),d?.()}}),e.jsx(za,{disabled:c,onBeforeSubmit:d,variant:"tertiary",allowSubmitWhileLoading:!0,overrideProcessRequest:()=>({parent_job_hash:N,..._}),overrideImages:P,historyPushFunc:W=>{r?.(W)}}),e.jsx(er,{disabled:c||!t||!p?.result?.result_url||!!p.is_failed||!!p.is_deleted||!!a&&n===`root-${a}`,selectedJobHash:t,selectedHistoryItemId:n,rootJobHash:a,job:p})]})},[o,i,c,d,a,n,t,s,p,P,h.background?.generate,j,r,_,m]),S=e.jsx("div",{className:"enhancer-options__reset-container",children:e.jsxs("button",{type:"button",className:"enhancer-options__reset-btn",onClick:y,disabled:E,"aria-label":"Reset",children:[e.jsx(Ca,{size:24}),e.jsx("span",{children:"Reset"})]})});return e.jsxs(e.Fragment,{children:[g&&nn.createPortal(G,g),e.jsx(Mr,{items:C,defaultItemId:"upscale",storageKey:"enhance-tab-id",remountTrigger:v,action:g?void 0:G,itemsTopChildren:d?void 0:S,itemsBottomChildren:d?S:void 0})]})},no=t=>e.jsx(to,{...t}),Mn=[{id:"enhancer-images-panel",slot:"left",render:({latestJobHash:t,rootJobHash:n,onSelectFromImagesPanel:s,onAddImage:a})=>e.jsx(vr,{selectedJobHash:t||n,onSelectJob:s,onAddImage:a})},{id:"enhancer-editor",slot:"center",render:({selectedJobHash:t,rootJobHash:n,latestJobHash:s,selectedHistoryItemId:a,imagesPanelSelectedHash:r,onSelectFromHistory:i,onLatestJobHashChange:c,onHistoryItemSelect:o,onImageUploaded:g,isUploadOpen:d})=>e.jsx(Pr,{showUploader:d,onImageUploaded:g,selectedJobHash:t,rootJobHash:n,latestJobHash:s,selectedHistoryItemId:a,imagesPanelSelectedHash:r,onSelectChildJob:i,onLatestJobHashChange:c,onHistoryItemSelect:o})},{id:"enhancer-options",slot:"right",render:({selectedJobHash:t,selectedHistoryItemId:n,latestJobHash:s,rootJobHash:a,onNewJobCreated:r,onAddImage:i,isUploadOpen:c})=>e.jsx(no,{selectedJobHash:t,selectedHistoryItemId:n,latestJobHash:s,rootJobHash:a,onNewJobCreated:r,onAddImage:i,isUploadOpen:c})}],so=910,ao=()=>{const{ready:t}=O(),n=xr(),{baseContext:s}=tr({imagesPanelQuery:Kn,pagePath:Sa,persistJobSelection:!0}
2),[a,r]=l.useState(!1),{onResetEditorView:i}=s,c=l.useCallback(()=>{i?.(),r(!1)},[i]),{onSelectFromImagesPanel:o,selectedJobHash:g}=s,d=l.useCallback(u=>{r(!1),u!==g&&o?.(u)},[o,g]),p={...s,isUploadOpen:a,onAddImage:()=>r(!0),onImageUploaded:c,onSelectFromImagesPanel:d},x=n.width>0&&n.width<so;return t?e.jsx($a,{options:{cacheKey:"enhancer-pro-v3-enhance-context",initialEnhancements:[D.GENERATIVE_TONE_CORRECTION]},children:e.jsx(Rr,{children:x?e.jsx(jr,{slots:vn(Mn,p)}):e.jsx(qn,{slots:vn(Mn,p)})})}):null},ro=ka(ao),io=()=>e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"enhancer-studio__workspace",children:e.jsx(ro,{})}),e.jsxs(V,{className:"container",children:[e.jsx(V.Header,{children:"AI Enhancer Studio – Professional AI Image Enhancement in Full-Screen Mode"}),e.jsx(V.Paragraph,{children:"AI Enhancer Studio is a powerful responsive version of our AI Enhancer PRO, designed for users who want maximum control, clarity, and workspace in their editing process. This full-screen enhancement suite lets you focus entirely on your photo without distractions - ideal for professionals and creators working on high-resolution images."}),e.jsx(V.Paragraph,{children:"With AI Enhancer Studio, you can use every enhancement feature available on our platform, all from a single, streamlined interface:"}),e.jsxs(V.List,{children:[e.jsxs(V.ListItem,{children:[e.jsx("strong",{children:"AI Upscale"})," – enhance resolution up to 4x for crisp, detailed output"]}),e.jsxs(V.ListItem,{children:[e.jsx("strong",{children:"Generative Upscale"})," – expand images with AI-generated realistic content"]}),e.jsxs(V.ListItem,{children:[e.jsx("strong",{children:"Print-Ready Optimization"})," – sharpen and prepare your images for large format printing"]}),e.jsxs(V.ListItem,{children:[e.jsx("strong",{children:"Color Correction"})," – fix white balance, lighting, and tone with AI precision"]}),e.jsxs(V.ListItem,{children:[e.jsx("strong",{children:"Deblur"})," – remove motion blur and bring clarity to unfocused shots"]}),e.jsxs(V.ListItem,{children:[e.jsx("strong",{children:"Denoise"})," – clean up low-light or grainy photos without losing detail"]}),e.jsxs(V.ListItem,{children:[e.jsx("strong",{children:"Backgroun
2d Generation & Removal"})," – replace or erase backgrounds in seconds"]}),e.jsxs(V.ListItem,{children:[e.jsx("strong",{children:"Framing"})," - extend, center, or recompose your photo to better fit social media formats, posters, or product displays"]})]}),e.jsx(V.Header,{children:"Desktop and Mobile Workspace"}),e.jsx(V.Paragraph,{children:"On desktop, AI Enhancer Studio uses the full screen for image comparison, enhancement options, and your image gallery. On mobile, the bottom buttons open your images and options in slide-up panels. The history at the bottom lets you revisit enhancement jobs for the current photo."}),e.jsx(V.Header,{children:"Who is AI Enhancer Studio for?"}),e.jsxs(V.List,{children:[e.jsx(V.ListItem,{children:"Photographers enhancing RAW or high-res images"}),e.jsx(V.ListItem,{children:"Designers preparing assets for print or web"}),e.jsx(V.ListItem,{children:"E-commerce sellers improving product shots"}),e.jsx(V.ListItem,{children:"Artists, AI creators, and illustrators working on clean final output"}),e.jsx(V.ListItem,{children:"Anyone who needs total control over the enhancement pipeline"})]}),e.jsx(V.Header,{children:"Why choose AI Enhancer Studio?"}),e.jsxs(V.List,{children:[e.jsx(V.ListItem,{children:"Combines all enhancement tools in one space"}),e.jsx(V.ListItem,{children:"Real-time feedback on changes"}),e.jsx(V.ListItem,{children:"Zero prompt writing – just visual editing"}),e.jsx(V.ListItem,{children:"Full-screen performance, made for multitasking and precision editing"}),e.jsx(V.ListItem,{children:"Integrated with Deep-Image’s advanced AI engine"})]}),e.jsx(V.Paragraph,{children:"If you’re serious about professional-level image enhancement, AI Enhancer Studio gives you everything you need in one place – no compromise, no clutter."})]})]}),wo=Object.freeze(Object.defineProperty({__proto__:null,default:io},Symbol.toStringTag,{value:"Module"}));export{wo as E,Ve as u};

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.