| 1 |
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{C as t,T as n,a as r,k as i,t as a,w as o}from"./client-DWQBE01c.js";import{f as s,l as c,n as l}from"./chunk-62JRHF6Z-DYKXAPSj.js";import{n as u}from"./QueryClientProvider-CfzZA5MJ.js";import{t as d}from"./useQuery-Q4exvDrv.js";import{t as f}from"./useMutation-D7HomC3_.js";import{t as p}from"./arrow-left-D0jaisfr.js";import{t as m}from"./arrow-right-NtE9qQKI.js";import{t as h}from"./box-2IRrqIPf.js";import{t as g}from"./check-DWMoPMOi.js";import{r as _}from"./info-CPhSLaIW.js";import{t as v}from"./chevron-right-CposVUhM.js";import{t as y}from"./chevron-left-bnx2dB0Q.js";import{n as ee}from"./ToastContext-Bg6SLDR7.js";import{t as b}from"./cog-CzVm_nY6.js";import{t as x}from"./download-8MUb8xIU.js";import{t as S}from"./external-link-Dp7WgKqd.js";import{t as C}from"./folder-open-ByHf1Zg4.js";import{t as w}from"./globe-DzZjvWFV.js";import{t as T}from"./SliceModal-DunwtcGl.js";import{t as E}from"./loader-circle-QIogdiwG.js";import{t as D}from"./search-DLu9V8cG.js";import{t as O}from"./settings-B-xfKNHZ.js";import{t as k}from"./trash-2-BeUbCuhB.js";import{t as A}from"./x-Ros7hs1-.js";import{n as te}from"./AuthContext-dqmb9nDE.js";import{i as j,n as M,t as N}from"./Card-DwWt21H0.js";import{t as P}from"./Button-CDViejCk.js";import{t as F}from"./ConfirmModal-FHGIQVx7.js";import{n as ne}from"./useUiSettings-DNDF6KSU.js";import{a as re,o as ie}from"./slicer-DgCA7cW6.js";import{t as ae}from"./purify.es-DaBa283-.js";import{t as oe}from"./libraryFiles-CZJbXn67.js";var I=t(`images`,[[`path`,{d:`m22 11-1.296-1.296a2.4 2.4 0 0 0-3.408 0L11 16`,key:`9kzy35`}],[`path`,{d:`M4 8a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2`,key:`1t0f0t`}],[`circle`,{cx:`13`,cy:`7`,r:`1`,fill:`currentColor`,key:`1obus6`}],[`rect`,{x:`8`,y:`2`,width:`14`,height:`14`,rx:`2`,key:`1gvhby`}]]),L=t(`library`,[[`path`,{d:`m16 6 4 14`,key:`ji33uf`}],[`path`,{d:`M12 6v14`,key:`1n7gus`}],[`path`,{d:`M8 8v12`,key:`1gg7y9`}],[`path`,{d:`M4 4v16`,key:`6qkkli`}]]),R=e(i(),1),z=o(),B=new Set([`manyfold_not_configured`,`manyfold_credentials`,`manyfold_scope`,`manyfold_rate_limited`,`manyfold_unreachable`,`manyfold_forbidden`,`manyfold_not_found`,`manyfold_too_large`,`manyfold_not_importable`,`manyfold_bad_url`,`manyfold_secret_required`,`manyfold_failed`]);function V(e,t){return e instanceof a&&e.code&&B.has(e.code)?t(`manyfold.errors.${e.code}`):e instanceof Error&&e.message?e.message:t(`manyfold.errors.manyfold_failed`)}function H(e){return((e.split(`/`)[1]??``).replace(/^x-/,``).split(/[+.;]/)[0]||`?`).toUpperCase()}function U(e,t=0,n=[]){n.push({folder:e,depth:t});for(let r of e.children??[])U(r,t+1,n);return n}function W({modelId:e,className:t}){let{data:n,isLoading:i}=d({queryKey:[`manyfold-preview`,e],queryFn:()=>r.getManyfoldPreview(e),staleTime:1/0,retry:!1}),[a,o]=(0,R.useState)(null);return(0,R.useEffect)(()=>{if(!n){o(null);return}let e=URL.createObjectURL(n);return o(e),()=>URL.revokeObjectURL(e)},[n]),(0,z.jsx)(`div`,{className:`flex items-center justify-center bg-bambu-dark overflow-hidden ${t??``}`,children:a?(0,z.jsx)(`img`,{src:a,alt:``,className:`w-full h-full object-contain`}):i?(0,z.jsx)(E,{className:`w-6 h-6 text-bambu-gray animate-spin`}):(0,z.jsx)(h,{className:`w-10 h-10 text-bambu-gray/50`,"aria-hidden":!0})})}function G({onDone:e}){let{t}=n(),{showToast:i}=ee(),a=u(),o=d({queryKey:[`manyfold-config`],queryFn:()=>r.getManyfoldConfig()}),[s,c]=(0,R.useState)(``),[l,p]=(0,R.useState)(``),[m,h]=(0,R.useState)(``),[g,_]=(0,R.useState)(null),[v,y]=(0,R.useState)(!1);(0,R.useEffect)(()=>{o.data&&(c(o.data.url),p(o.data.client_id))},[o.data]);let b=o.data?.has_client_secret??!1,x={url:s.trim(),client_id:l.trim(),client_secret:m.trim()||void 0},S=!!x.url&&!!x.client_id&&(!!x.client_secret||b),C=()=>{a.invalidateQueries({queryKey:[`manyfold-config`]}),a.invalidateQueries({queryKey:[`manyfold-status`]}),a.invalidateQueries({queryKey:[`manyfold-models`]}),a.invalidateQueries({queryKey:[`manyfold-model`]}),a.invalidateQueries({queryKey:[`manyfold-preview`]})},w=f({mutationFn:()=>r.testManyfoldConfig(x),onSuccess:e=>_({ok:!0,text:t(`manyfold.testOk`,{count:e.model_count})}),onError:e=>_({ok:!1,text:V(e,t)})}),T=f({mutationFn:()=>r.updateManyfoldConfig(x),onSuccess:()=>{h(``),C(),i(t(`settings.toast.settingsSaved`),`success`),e?.()},onError:e=>i(V(e,t),`error`)}),D=f({mutationFn:()=>r.deleteManyfoldConfig(),onSuccess:()=>{y(!1),c(``),p(``),h(``),_(null),C(),i(t(`manyfold.disconnected`),`success`)},onError:e=>{y(!1),i(V(e,t),`error`)}}),k=`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`;return(0,z.jsxs)(N,{children:[(0,z.jsx)(j,{children:(0,z.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,z.jsx)(O,{className:`w-5 h-5 text-bambu-green`}),t(`manyfold.connectionTitle`)]})}),(0,z.jsxs)(M,{className:`space-y-4`,children:[(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t(`manyfold.connectionHelp`)}),(0,z.jsxs)(`form`,{className:`space-y-3`,onSubmit:e=>{e.preventDefault(),S&&T.mutate()},children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{htmlFor:`manyfold-url`,className:`block text-sm text-bambu-gray mb-1`,children:t(`manyfold.url`)}),(0,z.jsx)(`input`,{id:`manyfold-url`,type:`url`,value:s,onChange:e=>{c(e.target.value),_(null)},placeholder:t(`manyfold.urlPlaceholder`),className:k,autoComplete:`off`})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{htmlFor:`manyfold-client-id`,className:`block text-sm text-bambu-gray mb-1`,children:t(`manyfold.clientId`)}),(0,z.jsx)(`input`,{id:`manyfold-client-id`,type:`text`,value:l,onChange:e=>{p(e.target.value),_(null)},className:k,autoComplete:`off`})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{htmlFor:`manyfold-client-secret`,className:`block text-sm text-bambu-gray mb-1`,children:t(`manyfold.clientSecret`)}),(0,z.jsx)(`input`,{id:`manyfold-client-secret`,type:`password`,value:m,onChange:e=>{h(e.target.value),_(null)},placeholder:b?t(`manyfold.clientSecretStored`):``,className:k,autoComplete:`new-password`})]}),g&&(0,z.jsx)(`p`,{role:`status`,className:`text-sm ${g.ok?`text-bambu-green`:`text-red-400`}`,children:g.text}),(0,z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,z.jsxs)(P,{type:`submit`,disabled:!S||T.isPending,children:[T.isPending?(0,z.jsx)(E,{className:`w-4 h-4 animate-spin`}):null,t(`common.save`)]}),(0,z.jsxs)(P,{type:`button`,variant:`secondary`,disabled:!S||w.isPending,onClick:()=>w.mutate(),children:[w.isPending?(0,z.jsx)(E,{className:`w-4 h-4 animate-spin`}):null,t(`manyfold.test`)]}),o.data?.configured&&(0,z.jsx)(P,{type:`button`,variant:`danger`,onClick:()=>y(!0),children:t(`manyfold.disconnect`)}),e&&o.data?.configured&&(0,z.jsx)(P,{type:`button`,variant:`ghost`,onClick:e,children:t(`common.cancel`)})]})]})]}),v&&(0,z.jsx)(F,{title:t(`manyfold.disconnectTitle`),message:t(`manyfold.disconnectBody`),confirmText:t(`manyfold.disconnect`),variant:`danger`,isLoading:D.isPending,onCancel:()=>y(!1),onConfirm:()=>D.mutate()})]})}function se({value:e,onChange:t,disabled:i}){let{t:a}=n(),o=(d({queryKey:[`library-folders`],queryFn:()=>r.getLibraryFolders()}).data??[]).filter(e=>!(e.is_external&&e.external_readonly)).flatMap(e=>U(e));return(0,z.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[a(`manyfold.importTo`),(0,z.jsxs)(`select`,{value:e??``,disabled:i,onChange:e=>t(e.target.value?Number(e.target.value):null),className:`px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm`,children:[(0,z.jsx)(`option`,{value:``,children:a(`manyfold.folderAuto`)}),o.map(({folder:e,depth:t})=>(0,z.jsx)(`option`,{value:e.id,disabled:e.can_write===!1,children:`${`— `.repeat(t)}${e.name}`},e.id))]})]})}function K(e){return e.length>3?`${e.slice(0,3).join(`, `)} +${e.length-3}`:e.join(`, `)}function q(){let{t:e}=n(),{showToast:t}=ee(),i=u(),[a,o]=(0,R.useState)(null);return{run:async(n,a)=>{if(n.length===0){t(e(`manyfold.bulkNothing`),`info`);return}let s=0,c=0,l=[],u=null;try{for(let e=0;e<n.length;e+=1){o({current:e+1,total:n.length});try{(await r.importManyfoldFile(n[e].modelId,n[e].fileId,a)).was_existing?c+=1:s+=1}catch(t){l.push(n[e].name),u??=t}}}finally{o(null),i.invalidateQueries({queryKey:[`manyfold-model`]}),i.invalidateQueries({queryKey:[`library-files`]}),i.invalidateQueries({queryKey:[`library-folders`]})}t(e(`manyfold.bulkDone`,{imported:s,existing:c,failed:l.length}),l.length?`warning`:`success`),l.length&&t(e(`manyfold.bulkFailed`,{names:K(l),reason:V(u,e)}),`error`)},progress:a,busy:a!==null}}function ce({modelId:e,onBack:t,onSlice:i}){let{t:a}=n(),{hasPermission:o}=te(),{showToast:s}=ee(),l=u(),m=c(),h=o(`manyfold:import`),[_,v]=(0,R.useState)(null),[y,w]=(0,R.useState)(null),[T,D]=(0,R.useState)(new Set),O=q(),k=d({queryKey:[`manyfold-model`,e],queryFn:()=>r.getManyfoldModel(e)}),A=ne(),F=A.data?.use_slicer_api??!1,re=ie(A.data?.open_in_slicer,A.data?.preferred_slicer),ae=f({mutationFn:t=>r.importManyfoldFile(e,t.id,_),onMutate:e=>w(e.id),onSettled:()=>w(null),onSuccess:t=>{l.invalidateQueries({queryKey:[`manyfold-model`,e]}),l.invalidateQueries({queryKey:[`library-files`]}),l.invalidateQueries({queryKey:[`library-folders`]}),s(t.was_existing?a(`manyfold.alreadyInLibrary`):a(`manyfold.imported`,{filename:t.filename}),`success`)},onError:e=>s(V(e,a),`error`)});if(k.isLoading)return(0,z.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,z.jsx)(E,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(k.isError||!k.data)return(0,z.jsxs)(`div`,{className:`space-y-4`,children:[(0,z.jsxs)(P,{variant:`ghost`,size:`sm`,onClick:t,children:[(0,z.jsx)(p,{className:`w-4 h-4`}),a(`manyfold.back`)]}),(0,z.jsx)(`p`,{className:`text-red-400 text-sm`,children:V(k.error,a)})]});let I=k.data,L=I.files.filter(e=>e.importable&&!e.library_file),B=L.filter(e=>T.has(e.id)),U=L.length>0&&B.length===L.length,G=O.busy||ae.isPending,K=async e=>{await O.run(e.map(e=>({modelId:I.id,fileId:e.id,name:e.name})),_),D(new Set)};return(0,z.jsxs)(`div`,{className:`space-y-4`,children:[(0,z.jsxs)(P,{variant:`ghost`,size:`sm`,onClick:t,children:[(0,z.jsx)(p,{className:`w-4 h-4`}),a(`manyfold.back`)]}),(0,z.jsx)(N,{children:(0,z.jsx)(M,{children:(0,z.jsxs)(`div`,{className:`flex flex-col md:flex-row gap-6 py-2`,children:[(0,z.jsx)(W,{modelId:I.id,className:`w-full md:w-72 aspect-square rounded-lg shrink-0`}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`h2`,{className:`text-xl font-semibold text-white break-words`,children:I.name}),I.caption&&(0,z.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:I.caption})]}),I.description&&(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray whitespace-pre-line break-words`,children:I.description}),I.tags.length>0&&(0,z.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:I.tags.map(e=>(0,z.jsx)(`span`,{className:`px-2 py-0.5 rounded-full bg-bambu-dark-tertiary text-xs text-white`,children:e},e))}),(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2 text-sm`,children:[I.license&&(0,z.jsxs)(`span`,{className:`text-bambu-gray`,children:[a(`manyfold.license`),`: `,(0,z.jsx)(`span`,{className:`text-white`,children:I.license})]}),(0,z.jsxs)(`a`,{href:I.url,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-bambu-green hover:underline`,children:[(0,z.jsx)(S,{className:`w-3.5 h-3.5`}),a(`manyfold.openInManyfold`)]})]})]})]})})}),(0,z.jsxs)(N,{children:[(0,z.jsxs)(j,{children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,z.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:a(`manyfold.files`)}),h&&(0,z.jsx)(se,{value:_,onChange:v,disabled:G})]}),h&&L.length>0&&(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 mt-3`,children:[(0,z.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-white`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:U,ref:e=>{e&&(e.indeterminate=B.length>0&&!U)},disabled:G,onChange:()=>D(U?new Set:new Set(L.map(e=>e.id))),className:`accent-bambu-green`}),a(`manyfold.selectAll`)]}),O.progress?(0,z.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,z.jsx)(E,{className:`w-4 h-4 animate-spin`}),a(`manyfold.importProgress`,O.progress)]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(P,{variant:`primary`,size:`sm`,disabled:G||B.length===0,onClick:()=>K(B),children:[(0,z.jsx)(x,{className:`w-3.5 h-3.5`}),a(`manyfold.importSelected`,{count:B.length})]}),(0,z.jsx)(P,{variant:`secondary`,size:`sm`,disabled:G,onClick:()=>K(L),children:a(`manyfold.importAll`)})]})]})]}),(0,z.jsx)(M,{children:I.files.length===0?(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:a(`manyfold.noFiles`)}):(0,z.jsx)(`ul`,{className:`divide-y divide-bambu-dark-tertiary`,children:I.files.map(e=>{let t=e.library_file,n=t!==null&&oe({filename:t.filename},F,re);return(0,z.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 py-2`,children:[h&&L.length>0&&(0,z.jsx)(`span`,{className:`w-4 shrink-0 flex`,children:e.importable&&!t&&(0,z.jsx)(`input`,{type:`checkbox`,"aria-label":a(`manyfold.selectFile`,{name:e.name}),checked:T.has(e.id),disabled:G,onChange:()=>D(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n}),className:`accent-bambu-green`})}),(0,z.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-bambu-dark-tertiary text-[11px] font-mono text-bambu-gray shrink-0`,children:H(e.mime)}),(0,z.jsx)(`span`,{className:`text-sm text-white min-w-0 flex-1 break-words`,children:e.name}),(0,z.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:e.importable?t?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs text-bambu-green`,children:[(0,z.jsx)(g,{className:`w-3.5 h-3.5`}),a(`manyfold.inLibrary`)]}),(0,z.jsxs)(P,{variant:`ghost`,size:`sm`,onClick:()=>m(t.folder_id?`/files?folder=${t.folder_id}`:`/files`),children:[(0,z.jsx)(C,{className:`w-3.5 h-3.5`}),a(`manyfold.showInLibrary`)]}),n&&(0,z.jsxs)(P,{variant:`ghost`,size:`sm`,onClick:()=>i(t.id,t.filename),children:[(0,z.jsx)(b,{className:`w-3.5 h-3.5`}),a(`slice.action`,`Slice`)]})]}):h?(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,disabled:G,onClick:()=>ae.mutate(e),children:[y===e.id?(0,z.jsx)(E,{className:`w-3.5 h-3.5 animate-spin`}):(0,z.jsx)(x,{className:`w-3.5 h-3.5`}),y===e.id?a(`manyfold.importing`):a(`manyfold.import`)]}):null:(0,z.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:a(`manyfold.notImportable`)})})]},e.id)})})})]})]})}function le(){let{t:e}=n(),{hasPermission:t}=te(),i=t(`settings:update`),[a,o]=(0,R.useState)(!1),[s,c]=(0,R.useState)(``),[l,f]=(0,R.useState)(``),[p,m]=(0,R.useState)(1),[h,g]=(0,R.useState)(null),[_,b]=(0,R.useState)(null),[S,C]=(0,R.useState)(new Map),[w,k]=(0,R.useState)(null),[A,j]=(0,R.useState)(null),F=t(`manyfold:import`),ae=u(),{showToast:oe}=ee(),I=q(),L=A!==null||I.busy,B=A?e(`manyfold.collectProgress`,A):I.progress?e(`manyfold.importProgress`,I.progress):null,H=(e,t)=>C(n=>{let r=new Map(n);return r.has(e)?r.delete(e):r.set(e,t),r}),U=async()=>{let t=[...S.keys()],n=[],i=[];try{for(let e=0;e<t.length;e+=1){j({current:e+1,total:t.length});try{let i=await ae.fetchQuery({queryKey:[`manyfold-model`,t[e]],queryFn:()=>r.getManyfoldModel(t[e])});for(let e of i.files)e.importable&&!e.library_file&&n.push({modelId:i.id,fileId:e.id,name:`${i.name}: ${e.name}`})}catch{i.push(S.get(t[e])??t[e])}}}finally{j(null)}i.length&&oe(e(`manyfold.modelsUnreadable`,{names:K(i)}),`error`),await I.run(n,w),C(new Map)},le=ne(),J=d({queryKey:[`manyfold-status`],queryFn:()=>r.getManyfoldStatus()}),ue=J.data?.configured??!1,Y=d({queryKey:[`manyfold-models`,l,p],queryFn:()=>r.listManyfoldModels(l,p),enabled:ue,placeholderData:e=>e}),X=async(e,t)=>{if(le.data?.use_slicer_api){b({kind:`libraryFile`,id:e,filename:t});return}let n=ie(le.data?.open_in_slicer,le.data?.preferred_slicer);try{let{token:i}=await r.createLibrarySlicerToken(e);re(`${window.location.origin}${r.getLibrarySlicerDownloadUrl(e,i,t)}`,n)}catch{re(`${window.location.origin}${r.getLibraryFileDownloadUrl(e)}`,n)}};if(J.isLoading)return(0,z.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,z.jsx)(E,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(!ue||a)return(0,z.jsxs)(`div`,{className:`space-y-6`,children:[(0,z.jsx)(`p`,{className:`text-bambu-gray`,children:e(`manyfold.description`)}),i?(0,z.jsx)(G,{onDone:ue?()=>o(!1):void 0}):(0,z.jsx)(N,{children:(0,z.jsx)(M,{children:(0,z.jsxs)(`div`,{className:`py-2`,children:[(0,z.jsx)(`p`,{className:`font-medium text-white`,children:e(`manyfold.notConnectedTitle`)}),(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`manyfold.notConnectedBody`)})]})})})]});let Z=Y.data;return(0,z.jsxs)(`div`,{className:`space-y-6`,children:[h?(0,z.jsx)(ce,{modelId:h,onBack:()=>g(null),onSlice:X}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,z.jsx)(`p`,{className:`text-bambu-gray flex-1 min-w-[16rem]`,children:e(`manyfold.description`)}),i&&(0,z.jsxs)(P,{variant:`ghost`,size:`sm`,onClick:()=>o(!0),children:[(0,z.jsx)(O,{className:`w-4 h-4`}),e(`manyfold.editConnection`)]})]}),(0,z.jsxs)(`form`,{className:`flex gap-2`,role:`search`,onSubmit:e=>{e.preventDefault(),f(s.trim()),m(1)},children:[(0,z.jsxs)(`div`,{className:`relative flex-1`,children:[(0,z.jsx)(D,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2`}),(0,z.jsx)(`input`,{type:`search`,value:s,onChange:e=>c(e.target.value),placeholder:e(`manyfold.searchPlaceholder`),"aria-label":e(`manyfold.searchPlaceholder`),className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,z.jsx)(P,{type:`submit`,children:e(`common.search`)})]}),Y.isError?(0,z.jsx)(`p`,{className:`text-sm text-red-400`,children:V(Y.error,e)}):Z?Z.models.length===0?(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`manyfold.noModels`)}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`manyfold.modelCount`,{count:Z.total})}),F&&(0,z.jsx)(P,{variant:`ghost`,size:`sm`,disabled:L,onClick:()=>C(e=>{let t=new Map(e);for(let e of Z.models)t.set(e.id,e.name);return t}),children:e(`manyfold.selectPage`)})]}),F&&S.size>0&&(0,z.jsxs)(`div`,{className:`sticky top-0 z-10 flex flex-wrap items-center gap-3 rounded-lg border border-bambu-green/40 bg-bambu-dark-secondary px-4 py-3`,children:[(0,z.jsx)(`span`,{className:`text-sm text-white`,children:e(`manyfold.modelsSelected`,{count:S.size})}),(0,z.jsx)(se,{value:w,onChange:k,disabled:L}),B?(0,z.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,z.jsx)(E,{className:`w-4 h-4 animate-spin`}),B]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(P,{variant:`primary`,size:`sm`,onClick:U,children:[(0,z.jsx)(x,{className:`w-3.5 h-3.5`}),e(`manyfold.importModels`)]}),(0,z.jsx)(P,{variant:`ghost`,size:`sm`,onClick:()=>C(new Map),children:e(`manyfold.clearSelection`)})]})]}),(0,z.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-6 gap-4`,children:Z.models.map(t=>{let n=S.has(t.id);return(0,z.jsxs)(`div`,{className:`relative rounded-lg border bg-bambu-dark-secondary overflow-hidden transition-colors ${n?`border-bambu-green ring-1 ring-bambu-green`:`border-bambu-dark-tertiary hover:border-bambu-green`}`,children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>g(t.id),disabled:L,className:`block w-full text-left disabled:cursor-wait`,children:[(0,z.jsx)(W,{modelId:t.id,className:`aspect-square`}),(0,z.jsx)(`span`,{className:`block px-3 py-2 text-sm text-white truncate`,title:t.name,children:t.name})]}),F&&(0,z.jsx)(`label`,{className:`absolute top-2 left-2 flex items-center justify-center w-7 h-7 rounded bg-black/60 cursor-pointer`,children:(0,z.jsx)(`input`,{type:`checkbox`,"aria-label":e(`manyfold.selectModel`,{name:t.name}),checked:n,disabled:L,onChange:()=>H(t.id,t.name),className:`accent-bambu-green w-4 h-4`})})]},t.id)})}),(Z.has_previous||Z.has_next)&&(0,z.jsxs)(`div`,{className:`flex items-center justify-center gap-3`,children:[(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,disabled:!Z.has_previous||Y.isFetching,onClick:()=>m(e=>Math.max(1,e-1)),children:[(0,z.jsx)(y,{className:`w-4 h-4`}),e(`manyfold.previous`)]}),(0,z.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e(`manyfold.page`,{page:Z.page})}),(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,disabled:!Z.has_next||Y.isFetching,onClick:()=>m(e=>e+1),children:[e(`manyfold.next`),(0,z.jsx)(v,{className:`w-4 h-4`})]})]})]}):(0,z.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,z.jsx)(E,{className:`w-8 h-8 text-bambu-green animate-spin`})})]}),_&&(0,z.jsx)(T,{source:_,onClose:()=>b(null)})]})}function J(e,t){let n=e?.[t];return typeof n==`string`?n:``}function ue(e){return e.replace(/(https?:\/\/(?:makerworld|public-cdn)\.bblmw\.com\/[^\s"']+)/gi,e=>`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(e)}`)}function Y(e){return e?/^https?:\/\/(makerworld|public-cdn)\.bblmw\.com\//i.test(e)?`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(e)}`:e:``}function X(e,t){let n=e?.[t];return typeof n==`number`?n:null}function Z(e,t){let n=e?.[t];return n&&typeof n==`object`&&!Array.isArray(n)?n:void 0}function de(e,t=0,n=[]){n.push({folder:e,depth:t});for(let r of e.children??[])de(r,t+1,n);return n}function fe(e,t){return t(e<1?`makerworld.phaseResolving`:`makerworld.phaseDownloading`)}function pe(e){let[t,n]=(0,R.useState)(0);return(0,R.useEffect)(()=>{if(!e){n(0);return}let t=Date.now(),r=()=>n(Math.floor((Date.now()-t)/1e3));r();let i=window.setInterval(r,1e3);return()=>window.clearInterval(i)},[e]),t}function me({embedded:e=!1}={}){let{t}=n(),{hasPermission:i}=te(),{showToast:a}=ee(),o=u(),s=i(`makerworld:import`),[c,p]=(0,R.useState)(``),[h,D]=(0,R.useState)(null),[O,oe]=(0,R.useState)(null),[L,B]=(0,R.useState)(null),[V,H]=(0,R.useState)(null),[U,W]=(0,R.useState)(null),[G,se]=(0,R.useState)(``),[K,q]=(0,R.useState)({}),ce=d({queryKey:[`makerworld-status`],queryFn:()=>r.getMakerworldStatus()}),le=d({queryKey:[`library-folders`],queryFn:()=>r.getLibraryFolders()}),me=d({queryKey:[`makerworld-recent-imports`],queryFn:()=>r.getMakerworldRecentImports(10)}),he=ne(),ge=he.data?.use_slicer_api??!1,_e=he.data?.preferred_slicer||`bambu_studio`,ve=ie(he.data?.open_in_slicer,he.data?.preferred_slicer),ye=ge?_e:ve,be=ye===`orcaslicer`?`OrcaSlicer`:`Bambu Studio`,[xe,Se]=(0,R.useState)(null),Ce=(e,t)=>{Se({kind:`libraryFile`,id:e,filename:t})},we=f({mutationFn:e=>r.resolveMakerworldUrl(e),onSuccess:(e,t)=>{D(e),se(t),q({})},onError:e=>a(e.message||t(`makerworld.errors.resolveFailed`),`error`)});(0,R.useEffect)(()=>{h!==null&&c.trim()!==G.trim()&&(D(null),se(``),q({}))},[c,h,G]);let Te=f({mutationFn:({instanceId:e,profileId:t})=>r.importMakerworldInstance(h?.model_id??0,e,t,O),onSuccess:e=>{o.invalidateQueries({queryKey:[`library-files`]}),o.invalidateQueries({queryKey:[`library-folders`]}),e.profile_id&&q(t=>({...t,[e.profile_id]:e})),a(e.was_existing?t(`makerworld.alreadyInLibrary`):t(`makerworld.importSuccess`,{filename:e.filename}),`success`)},onError:e=>a(e.message||t(`makerworld.errors.downloadFailed`),`error`)}),Ee=f({mutationFn:({libraryFileId:e})=>r.deleteLibraryFile(e),onSuccess:(e,{profileId:n})=>{o.invalidateQueries({queryKey:[`library-files`]}),o.invalidateQueries({queryKey:[`library-folders`]}),o.invalidateQueries({queryKey:[`makerworld-recent-imports`]}),q(e=>{let t={...e};return delete t[n],t}),H(null),a(t(`makerworld.importDeleted`),`success`)},onError:e=>{H(null),a(e.message||t(`makerworld.errors.deleteFailed`),`error`)}}),De=f({mutationFn:({instanceId:e,profileId:t})=>r.importMakerworldInstance(h?.model_id??0,e,t,O),onSuccess:async e=>{o.invalidateQueries({queryKey:[`library-files`]}),o.invalidateQueries({queryKey:[`library-folders`]}),o.invalidateQueries({queryKey:[`makerworld-recent-imports`]}),e.profile_id&&q(t=>({...t,[e.profile_id]:e})),ge?Ce(e.library_file_id,e.filename):await Me(e.library_file_id,e.filename,ye)},onError:e=>a(e.message||t(`makerworld.errors.downloadFailed`),`error`)}),Q=pe(Te.isPending||De.isPending),Oe=fe(Q,t),ke=e=>{e?.preventDefault();let t=c.trim();t&&we.mutate(t)};(0,R.useEffect)(()=>{if(!U)return;let e=e=>{e.key===`Escape`?W(null):e.key===`ArrowLeft`?W(e=>e&&e.index>0?{...e,index:e.index-1}:e):e.key===`ArrowRight`&&W(e=>e&&e.index<e.images.length-1?{...e,index:e.index+1}:e)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[U]);let Ae=e=>{let t=(Array.isArray(e.pictures)?e.pictures:[]).filter(e=>typeof e==`object`&&!!e).map(e=>({name:J(e,`name`)||`image`,url:J(e,`url`)})).filter(e=>e.url);if(t.length>0)return t;let n=J(e,`cover`);return n?[{name:`cover`,url:n}]:[]},je=async()=>{if(!h)return;let e=h.instances.filter(e=>{let t=X(e,`profileId`);return t!==null&&!K[t]});if(e.length!==0){B({current:0,total:e.length});try{for(let t=0;t<e.length;t+=1){let n=e[t],r=X(n,`id`),i=X(n,`profileId`);if(!(r===null||i===null)){B({current:t+1,total:e.length});try{await Te.mutateAsync({instanceId:r,profileId:i})}catch{}}}}finally{B(null)}}},Me=async(e,t,n)=>{try{let{token:i}=await r.createLibrarySlicerToken(e),a=r.getLibrarySlicerDownloadUrl(e,i,t);re(`${window.location.origin}${a}`,n)}catch{let t=r.getLibraryFileDownloadUrl(e);re(`${window.location.origin}${t}`,n)}},$=h?.design,Ne=Z($,`designCreator`),Pe=h?.instances??[],Fe=(h?.already_imported_library_ids.length??0)>0,Ie=ce.data?.can_download??!1,Le=ce.data?.sign_in_expired??!1,Re=(0,R.useMemo)(()=>J($,`coverUrl`),[$]),ze=J($,`title`),Be=J($,`summary`),Ve=J($,`license`),He=X($,`downloadCount`);return(0,z.jsxs)(`div`,{className:e?`space-y-6`:`p-4 md:p-8 max-w-screen-2xl space-y-6`,children:[e?(0,z.jsx)(`p`,{className:`text-bambu-gray`,children:t(`makerworld.description`)}):(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,z.jsx)(w,{className:`w-7 h-7 text-bambu-green`}),t(`makerworld.title`)]}),(0,z.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:t(`makerworld.description`)})]}),(0,z.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-[1fr_20rem]`,children:[(0,z.jsxs)(`div`,{className:`space-y-6 min-w-0`,children:[!Ie&&(0,z.jsx)(N,{className:`border-amber-300 dark:border-amber-700 bg-amber-50 dark:bg-amber-900/20`,children:(0,z.jsx)(M,{children:(0,z.jsxs)(`div`,{className:`flex items-start gap-3 py-2`,children:[(0,z.jsx)(_,{className:`w-5 h-5 text-amber-600 dark:text-amber-400 mt-0.5 shrink-0`}),(0,z.jsxs)(`div`,{className:`text-sm`,children:[(0,z.jsx)(`p`,{className:`font-medium text-amber-900 dark:text-amber-100`,children:t(Le?`makerworld.signInExpiredTitle`:`makerworld.signInRequiredTitle`)}),(0,z.jsxs)(`p`,{className:`text-amber-800 dark:text-amber-200 mt-1`,children:[t(Le?`makerworld.signInExpiredBody`:`makerworld.signInRequiredBody`),` `,(0,z.jsx)(l,{to:`/profiles`,className:`underline`,children:t(`makerworld.openCloudSettings`)})]})]})]})})}),(0,z.jsxs)(N,{children:[(0,z.jsx)(j,{children:(0,z.jsx)(`h2`,{className:`text-lg font-semibold`,children:t(`makerworld.pasteUrlHeader`)})}),(0,z.jsx)(M,{children:(0,z.jsxs)(`form`,{onSubmit:ke,className:`flex gap-2`,children:[(0,z.jsx)(`input`,{type:`text`,value:c,onChange:e=>p(e.target.value),placeholder:t(`makerworld.pasteUrlPlaceholder`),className:`flex-1 min-w-0 px-3 py-2 border rounded bg-white dark:bg-gray-800 border-gray-300 dark:border-gray-700`,autoComplete:`off`}),(0,z.jsxs)(P,{type:`submit`,variant:`primary`,disabled:!c.trim()||we.isPending,children:[we.isPending?(0,z.jsx)(E,{className:`w-4 h-4 animate-spin`}):(0,z.jsx)(m,{className:`w-4 h-4`}),(0,z.jsx)(`span`,{className:`ml-2`,children:t(`makerworld.resolveButton`)})]})]})})]}),h&&(0,z.jsx)(N,{children:(0,z.jsx)(M,{children:(0,z.jsxs)(`div`,{className:`flex gap-4 py-2`,children:[Re&&(0,z.jsx)(`img`,{src:Y(Re),alt:ze,className:`w-32 h-32 object-cover rounded`,loading:`lazy`}),(0,z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,z.jsx)(`h3`,{className:`text-xl font-semibold truncate`,children:ze||t(`makerworld.untitledModel`)}),Ne&&(0,z.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-1`,children:t(`makerworld.byCreator`,{name:J(Ne,`name`)})}),(0,z.jsxs)(`div`,{className:`flex flex-wrap gap-3 mt-2 text-xs text-gray-500 dark:text-gray-400`,children:[He!==null&&(0,z.jsx)(`span`,{children:t(`makerworld.downloadsCount`,{count:He})}),Ve&&(0,z.jsxs)(`span`,{children:[t(`makerworld.licensePrefix`),`: `,Ve]}),Fe&&(0,z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-emerald-600 dark:text-emerald-400`,children:[(0,z.jsx)(g,{className:`w-3 h-3`}),` `,t(`makerworld.alreadyImported`)]})]}),Be&&(0,z.jsx)(`div`,{className:`mt-3 text-sm prose prose-sm max-w-none dark:prose-invert line-clamp-3`,dangerouslySetInnerHTML:{__html:ae.sanitize(ue(Be))}}),h&&(0,z.jsxs)(`a`,{href:`https://makerworld.com/models/${h.model_id}${h.profile_id?`#profileId-${h.profile_id}`:``}`,target:`_blank`,rel:`noopener noreferrer`,className:`mt-3 inline-flex items-center gap-1 text-xs text-brand-500 hover:underline`,children:[(0,z.jsx)(S,{className:`w-3 h-3`}),` `,t(`makerworld.openOnMakerworld`)]})]})]})})}),h&&Pe.length>0&&(0,z.jsxs)(N,{children:[(0,z.jsx)(j,{children:(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,z.jsx)(`h2`,{className:`text-lg font-semibold`,children:t(`makerworld.platesHeader`,{count:Pe.length})}),(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,z.jsx)(`label`,{className:`text-xs text-gray-600 dark:text-gray-400`,children:t(`makerworld.importTo`)}),(0,z.jsxs)(`select`,{value:O??``,onChange:e=>oe(e.target.value?Number(e.target.value):null),className:`text-sm px-2 py-1 border rounded bg-white dark:bg-gray-800 border-gray-300 dark:border-gray-700`,disabled:L!==null,children:[(0,z.jsx)(`option`,{value:``,children:t(`makerworld.folderAuto`)}),(le.data??[]).filter(e=>!(e.is_external&&e.external_readonly)).flatMap(e=>de(e)).map(({folder:e,depth:t})=>(0,z.jsx)(`option`,{value:e.id,disabled:e.can_write===!1,children:`${`— `.repeat(t)}${e.name}`},e.id))]}),(0,z.jsx)(P,{variant:`primary`,size:`sm`,disabled:!s||!Ie||L!==null||Te.isPending||De.isPending,onClick:je,children:L===null?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(x,{className:`w-4 h-4`}),(0,z.jsx)(`span`,{className:`ml-2`,children:t(`makerworld.importAll`)})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(E,{className:`w-4 h-4 animate-spin`}),(0,z.jsxs)(`span`,{className:`ml-2`,children:[t(`makerworld.importAllProgress`,{current:L.current,total:L.total}),Q>0&&` · ${Oe} · ${Q}s`]})]})})]})]})}),(0,z.jsx)(M,{children:(0,z.jsx)(`div`,{className:`grid gap-3`,children:Pe.map((e,n)=>{let r=X(e,`id`),i=X(e,`profileId`),a=J(e,`title`),o=J(e,`cover`),c=X(e,`materialCnt`),l=e?.needAms===!0,u=X(e,`downloadCount`),d=e?.compatibility??null,f=e?.otherCompatibility??null,p=d?.devProductName??null,m=Array.isArray(f)?f.map(e=>e?.devProductName??``).filter(Boolean):[];if(r==null)return null;let h=Te.isPending&&Te.variables?.instanceId===r,_=De.isPending&&De.variables?.instanceId===r,v=i===null?void 0:K[i];return(0,z.jsxs)(`div`,{className:`flex flex-col gap-2 p-3 border rounded border-gray-200 dark:border-gray-700`,children:[(0,z.jsxs)(`div`,{className:`flex gap-3 items-center`,children:[(()=>{let n=Ae(e),r=n.length>0;return(0,z.jsxs)(`button`,{type:`button`,disabled:!r,onClick:()=>r&&W({images:n,index:0}),className:`relative w-16 h-16 shrink-0 rounded overflow-hidden group`,"aria-label":t(`makerworld.openGallery`),children:[o?(0,z.jsx)(`img`,{src:Y(o),alt:``,className:`w-16 h-16 object-cover`,loading:`lazy`}):(0,z.jsx)(`div`,{className:`w-16 h-16 bg-gray-100 dark:bg-gray-800`}),n.length>1&&(0,z.jsxs)(`span`,{className:`absolute bottom-0.5 right-0.5 bg-black/70 text-white text-[10px] px-1.5 py-0.5 rounded flex items-center gap-1`,children:[(0,z.jsx)(I,{className:`w-2.5 h-2.5`}),n.length]})]})})(),(0,z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,z.jsx)(`p`,{className:`font-medium truncate`,children:a||t(`makerworld.plateDefaultName`,{n:n+1})}),(0,z.jsxs)(`div`,{className:`flex flex-wrap gap-3 text-xs text-gray-500 dark:text-gray-400 mt-1`,children:[p&&(0,z.jsx)(`span`,{className:`font-medium text-gray-700 dark:text-gray-300`,children:t(`makerworld.slicedFor`,{printer:p,defaultValue:`Sliced for {{printer}}`})}),c!==null&&(0,z.jsx)(`span`,{children:t(`makerworld.materialCount`,{count:c})}),l&&(0,z.jsx)(`span`,{children:t(`makerworld.amsRequired`)}),u!==null&&(0,z.jsx)(`span`,{children:t(`makerworld.downloadsCount`,{count:u})})]}),m.length>0&&(0,z.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,title:m.join(`, `),children:t(`makerworld.alsoCompatible`,{printers:m.slice(0,6).join(`, `)+(m.length>6?`…`:``),defaultValue:`Also marked compatible: {{printers}}`})})]}),(0,z.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[(0,z.jsx)(P,{variant:`ghost`,size:`sm`,disabled:!s||!Ie||h||_||L!==null,onClick:()=>Te.mutate({instanceId:r,profileId:i}),title:Ie?void 0:t(`makerworld.signInRequiredTitle`),children:h?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(E,{className:`w-4 h-4 animate-spin`}),(0,z.jsxs)(`span`,{className:`ml-2`,children:[Oe,Q>0&&` · ${Q}s`]})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(x,{className:`w-4 h-4`}),(0,z.jsx)(`span`,{className:`ml-2`,children:t(`makerworld.importToLibrary`)})]})}),(0,z.jsx)(P,{variant:`primary`,size:`sm`,disabled:!s||!Ie||h||_||L!==null,onClick:()=>De.mutate({instanceId:r,profileId:i}),title:Ie?void 0:t(`makerworld.signInRequiredTitle`),children:_?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(E,{className:`w-4 h-4 animate-spin`}),(0,z.jsxs)(`span`,{className:`ml-2`,children:[Oe,Q>0&&` · ${Q}s`]})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(S,{className:`w-4 h-4`}),(0,z.jsx)(`span`,{className:`ml-2`,children:t(`makerworld.sliceIn`,{slicer:be})})]})})]})]}),v&&(0,z.jsxs)(`div`,{className:`flex items-center gap-2 pl-20 text-xs`,children:[(0,z.jsx)(g,{className:`w-3.5 h-3.5 text-emerald-600 dark:text-emerald-400 shrink-0`}),(0,z.jsx)(`span`,{className:`text-emerald-700 dark:text-emerald-300`,children:v.was_existing?t(`makerworld.lastImportAlreadyInLibrary`):t(`makerworld.lastImportSuccess`)}),(0,z.jsxs)(P,{variant:`ghost`,size:`sm`,onClick:()=>{let e=v.folder_id?`/files?folder=${v.folder_id}`:`/files`;window.location.assign(e)},children:[(0,z.jsx)(C,{className:`w-3.5 h-3.5`}),(0,z.jsx)(`span`,{className:`ml-1.5`,children:t(`makerworld.viewInLibrary`)})]}),ge?(0,z.jsxs)(P,{variant:`ghost`,size:`sm`,onClick:()=>Ce(v.library_file_id,v.filename),children:[(0,z.jsx)(b,{className:`w-3.5 h-3.5`}),(0,z.jsx)(`span`,{className:`ml-1.5`,children:t(`slice.action`,`Slice`)})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(P,{variant:`ghost`,size:`sm`,onClick:()=>Me(v.library_file_id,v.filename,`bambu_studio`),children:[(0,z.jsx)(S,{className:`w-3.5 h-3.5`}),(0,z.jsx)(`span`,{className:`ml-1.5`,children:t(`makerworld.openInBambuStudio`)})]}),(0,z.jsxs)(P,{variant:`ghost`,size:`sm`,onClick:()=>Me(v.library_file_id,v.filename,`orcaslicer`),children:[(0,z.jsx)(S,{className:`w-3.5 h-3.5`}),(0,z.jsx)(`span`,{className:`ml-1.5`,children:t(`makerworld.openInOrcaSlicer`)})]})]}),(0,z.jsx)(`div`,{className:`ml-auto`,children:(0,z.jsx)(P,{variant:`ghost`,size:`sm`,disabled:Ee.isPending&&Ee.variables?.profileId===i,onClick:()=>{i!==null&&H({libraryFileId:v.library_file_id,profileId:i,filename:v.filename})},title:t(`makerworld.deleteImport`),children:Ee.isPending&&Ee.variables?.profileId===i?(0,z.jsx)(E,{className:`w-3.5 h-3.5 animate-spin`}):(0,z.jsx)(k,{className:`w-3.5 h-3.5 text-red-500`})})})]})]},r)})})})]})]}),(0,z.jsx)(`aside`,{className:`lg:sticky lg:top-6 lg:self-start min-w-0`,children:me.data&&me.data.length>0&&(0,z.jsxs)(N,{children:[(0,z.jsx)(j,{children:(0,z.jsx)(`h2`,{className:`text-base font-semibold`,children:t(`makerworld.recentImportsHeader`)})}),(0,z.jsx)(M,{children:(0,z.jsx)(`div`,{className:`flex flex-col gap-2 max-h-[28rem] overflow-y-auto -mx-2 px-2`,children:me.data.map(e=>(0,z.jsxs)(`div`,{className:`flex gap-2 p-2 border rounded border-gray-200 dark:border-gray-700`,children:[e.thumbnail_path?(0,z.jsx)(`img`,{src:r.getLibraryFileThumbnailUrl(e.library_file_id),alt:``,className:`w-12 h-12 shrink-0 object-cover rounded bg-gray-100 dark:bg-gray-800`,loading:`lazy`}):(0,z.jsx)(`div`,{className:`w-12 h-12 shrink-0 rounded bg-gray-100 dark:bg-gray-800`}),(0,z.jsxs)(`div`,{className:`flex-1 min-w-0 flex flex-col gap-1`,children:[(0,z.jsx)(`p`,{className:`text-xs font-medium truncate`,title:e.filename,children:e.filename}),(0,z.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,z.jsx)(P,{variant:`ghost`,size:`sm`,onClick:()=>{let t=e.folder_id?`/files?folder=${e.folder_id}`:`/files`;window.location.assign(t)},title:t(`makerworld.viewInLibrary`),children:(0,z.jsx)(C,{className:`w-3.5 h-3.5`})}),ge?(0,z.jsx)(P,{variant:`ghost`,size:`sm`,onClick:()=>Ce(e.library_file_id,e.filename),title:t(`slice.action`,`Slice`),children:(0,z.jsx)(b,{className:`w-3.5 h-3.5`})}):(0,z.jsx)(P,{variant:`ghost`,size:`sm`,onClick:()=>Me(e.library_file_id,e.filename,`bambu_studio`),title:t(`makerworld.openInBambuStudio`),children:(0,z.jsx)(S,{className:`w-3.5 h-3.5`})}),e.source_url&&(0,z.jsx)(`a`,{href:e.source_url,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center justify-center h-7 w-7 rounded text-gray-500 hover:text-gray-700 dark:hover:text-gray-300`,title:t(`makerworld.openOnMakerworld`),children:(0,z.jsx)(w,{className:`w-3.5 h-3.5`})})]})]})]},e.library_file_id))})})]})})]}),(0,z.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 pt-4 border-t border-gray-200 dark:border-gray-700`,children:t(`makerworld.disclaimer`)}),V&&(0,z.jsx)(F,{title:t(`makerworld.deleteImport`),message:t(`makerworld.confirmDelete`,{filename:V.filename}),confirmText:t(`makerworld.deleteImport`),variant:`danger`,isLoading:Ee.isPending,loadingText:t(`makerworld.importDeleting`),onCancel:()=>H(null),onConfirm:()=>Ee.mutate({libraryFileId:V.libraryFileId,profileId:V.profileId})}),xe&&(0,z.jsx)(T,{source:xe,onClose:()=>Se(null)}),U&&(0,z.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-50`,onClick:()=>W(null),role:`dialog`,"aria-modal":`true`,children:[(0,z.jsx)(`button`,{type:`button`,className:`absolute top-4 right-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white`,onClick:e=>{e.stopPropagation(),W(null)},"aria-label":t(`common.close`,`Close`),children:(0,z.jsx)(A,{className:`w-5 h-5`})}),U.images.length>1&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`button`,{type:`button`,className:`absolute left-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white disabled:opacity-30`,disabled:U.index===0,onClick:e=>{e.stopPropagation(),W(e=>e&&{...e,index:Math.max(0,e.index-1)})},"aria-label":t(`makerworld.galleryPrev`),children:(0,z.jsx)(y,{className:`w-6 h-6`})}),(0,z.jsx)(`button`,{type:`button`,className:`absolute right-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white disabled:opacity-30`,disabled:U.index>=U.images.length-1,onClick:e=>{e.stopPropagation(),W(e=>e&&{...e,index:Math.min(e.images.length-1,e.index+1)})},"aria-label":t(`makerworld.galleryNext`),children:(0,z.jsx)(v,{className:`w-6 h-6`})})]}),(0,z.jsx)(`img`,{src:Y(U.images[U.index].url),alt:U.images[U.index].name,className:`max-w-[90vw] max-h-[90vh] object-contain`,onClick:e=>e.stopPropagation()}),U.images.length>1&&(0,z.jsxs)(`div`,{className:`absolute bottom-6 left-1/2 -translate-x-1/2 text-white bg-black/60 px-3 py-1 rounded text-xs`,children:[U.index+1,` / `,U.images.length]})]})]})}function he(){let{t:e}=n(),{hasPermission:t}=te(),[i,a]=s(),o=t(`manyfold:view`),c=d({queryKey:[`manyfold-status`],queryFn:()=>r.getManyfoldStatus(),enabled:o}),l=o&&(c.data?.configured===!0||t(`settings:update`)),u=[];t(`makerworld:view`)&&u.push({id:`makerworld`,label:e(`modelSources.tabMakerworld`),icon:w}),l&&u.push({id:`manyfold`,label:e(`modelSources.tabManyfold`),icon:L});let f=i.get(`tab`),p=u.find(e=>e.id===f)?.id??u[0]?.id??(o?`manyfold`:void 0);return(0,z.jsxs)(`div`,{className:`p-4 md:p-8 max-w-screen-2xl`,children:[(0,z.jsx)(`div`,{className:`mb-6`,children:(0,z.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,z.jsx)(w,{className:`w-7 h-7 text-bambu-green`}),e(`modelSources.title`)]})}),u.length>1&&(0,z.jsx)(`div`,{className:`flex border-b border-bambu-dark-tertiary mb-6`,role:`tablist`,children:u.map(({id:e,label:t,icon:n})=>(0,z.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":p===e,onClick:()=>a({tab:e},{replace:!0}),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${p===e?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,z.jsx)(n,{className:`w-4 h-4`}),t]},e))}),p===`makerworld`&&(0,z.jsx)(me,{embedded:!0}),p===`manyfold`&&(0,z.jsx)(le,{})]})}export{he as ModelSourcesPage};
|