ModelSourcesPage-C9OvAi9p.js 40 KB

1
  1. import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,t as i,w as a}from"./client-BdOyoZJz.js";import{n as o}from"./QueryClientProvider-Clbyr4Jg.js";import{t as s}from"./useQuery-CCy0EwsM.js";import{t as c}from"./useMutation-qh3Iyscy.js";import{t as l}from"./createLucideIcon-Yo2YoYjm.js";import{t as u}from"./arrow-left-MSgMxOFV.js";import{t as d}from"./arrow-right-Da96kh4S.js";import{t as f}from"./box-BIRPxdgi.js";import{t as p}from"./check-D1Pn8T1J.js";import{r as m}from"./info-DcT0QU8O.js";import{n as h}from"./ToastContext-VFOrCCoA.js";import{t as g}from"./cog-pa-nvQzt.js";import{t as _}from"./SliceModal-DilRo4MU.js";import{t as v}from"./loader-circle-CB4leTZa.js";import{t as y}from"./search-BpAJdxRw.js";import{t as b}from"./x-Dctff5l9.js";import{i as x,n as S,t as C}from"./Card-OUAj0Ayh.js";import{t as w}from"./Button-pwVKPiYn.js";import{At as T,Cn as E,Mn as D,Rn as O,Vn as k,Vt as A,Wn as j,_t as M,hn as N,jn as ee,vn as P,wn as te,yt as ne}from"./index-BoVbGTav.js";import{a as re,o as ie}from"./slicer-DgCA7cW6.js";import{t as ae}from"./purify.es-F_7NWVtX.js";import{t as oe}from"./libraryFiles-B0B1SFfn.js";var F=l(`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`}]]),I=l(`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`}]]),L=e(n(),1),R=t(),z=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 B(e,t){return e instanceof i&&e.code&&z.has(e.code)?t(`manyfold.errors.${e.code}`):e instanceof Error&&e.message?e.message:t(`manyfold.errors.manyfold_failed`)}function V(e){return((e.split(`/`)[1]??``).replace(/^x-/,``).split(/[+.;]/)[0]||`?`).toUpperCase()}function H(e,t=0,n=[]){n.push({folder:e,depth:t});for(let r of e.children??[])H(r,t+1,n);return n}function U({modelId:e,className:t}){let{data:n,isLoading:i}=s({queryKey:[`manyfold-preview`,e],queryFn:()=>r.getManyfoldPreview(e),staleTime:1/0,retry:!1}),[a,o]=(0,L.useState)(null);return(0,L.useEffect)(()=>{if(!n){o(null);return}let e=URL.createObjectURL(n);return o(e),()=>URL.revokeObjectURL(e)},[n]),(0,R.jsx)(`div`,{className:`flex items-center justify-center bg-bambu-dark overflow-hidden ${t??``}`,children:a?(0,R.jsx)(`img`,{src:a,alt:``,className:`w-full h-full object-contain`}):i?(0,R.jsx)(v,{className:`w-6 h-6 text-bambu-gray animate-spin`}):(0,R.jsx)(f,{className:`w-10 h-10 text-bambu-gray/50`,"aria-hidden":!0})})}function W({onDone:e}){let{t}=a(),{showToast:n}=h(),i=o(),l=s({queryKey:[`manyfold-config`],queryFn:()=>r.getManyfoldConfig()}),[u,d]=(0,L.useState)(``),[f,p]=(0,L.useState)(``),[m,g]=(0,L.useState)(``),[_,y]=(0,L.useState)(null),[b,T]=(0,L.useState)(!1);(0,L.useEffect)(()=>{l.data&&(d(l.data.url),p(l.data.client_id))},[l.data]);let E=l.data?.has_client_secret??!1,D={url:u.trim(),client_id:f.trim(),client_secret:m.trim()||void 0},O=!!D.url&&!!D.client_id&&(!!D.client_secret||E),k=()=>{i.invalidateQueries({queryKey:[`manyfold-config`]}),i.invalidateQueries({queryKey:[`manyfold-status`]}),i.invalidateQueries({queryKey:[`manyfold-models`]}),i.invalidateQueries({queryKey:[`manyfold-model`]}),i.invalidateQueries({queryKey:[`manyfold-preview`]})},j=c({mutationFn:()=>r.testManyfoldConfig(D),onSuccess:e=>y({ok:!0,text:t(`manyfold.testOk`,{count:e.model_count})}),onError:e=>y({ok:!1,text:B(e,t)})}),N=c({mutationFn:()=>r.updateManyfoldConfig(D),onSuccess:()=>{g(``),k(),n(t(`settings.toast.settingsSaved`),`success`),e?.()},onError:e=>n(B(e,t),`error`)}),ee=c({mutationFn:()=>r.deleteManyfoldConfig(),onSuccess:()=>{T(!1),d(``),p(``),g(``),y(null),k(),n(t(`manyfold.disconnected`),`success`)},onError:e=>{T(!1),n(B(e,t),`error`)}}),P=`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,R.jsxs)(C,{children:[(0,R.jsx)(x,{children:(0,R.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,R.jsx)(A,{className:`w-5 h-5 text-bambu-green`}),t(`manyfold.connectionTitle`)]})}),(0,R.jsxs)(S,{className:`space-y-4`,children:[(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t(`manyfold.connectionHelp`)}),(0,R.jsxs)(`form`,{className:`space-y-3`,onSubmit:e=>{e.preventDefault(),O&&N.mutate()},children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{htmlFor:`manyfold-url`,className:`block text-sm text-bambu-gray mb-1`,children:t(`manyfold.url`)}),(0,R.jsx)(`input`,{id:`manyfold-url`,type:`url`,value:u,onChange:e=>{d(e.target.value),y(null)},placeholder:t(`manyfold.urlPlaceholder`),className:P,autoComplete:`off`})]}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{htmlFor:`manyfold-client-id`,className:`block text-sm text-bambu-gray mb-1`,children:t(`manyfold.clientId`)}),(0,R.jsx)(`input`,{id:`manyfold-client-id`,type:`text`,value:f,onChange:e=>{p(e.target.value),y(null)},className:P,autoComplete:`off`})]}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{htmlFor:`manyfold-client-secret`,className:`block text-sm text-bambu-gray mb-1`,children:t(`manyfold.clientSecret`)}),(0,R.jsx)(`input`,{id:`manyfold-client-secret`,type:`password`,value:m,onChange:e=>{g(e.target.value),y(null)},placeholder:E?t(`manyfold.clientSecretStored`):``,className:P,autoComplete:`new-password`})]}),_&&(0,R.jsx)(`p`,{role:`status`,className:`text-sm ${_.ok?`text-bambu-green`:`text-red-400`}`,children:_.text}),(0,R.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,R.jsxs)(w,{type:`submit`,disabled:!O||N.isPending,children:[N.isPending?(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}):null,t(`common.save`)]}),(0,R.jsxs)(w,{type:`button`,variant:`secondary`,disabled:!O||j.isPending,onClick:()=>j.mutate(),children:[j.isPending?(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}):null,t(`manyfold.test`)]}),l.data?.configured&&(0,R.jsx)(w,{type:`button`,variant:`danger`,onClick:()=>T(!0),children:t(`manyfold.disconnect`)}),e&&l.data?.configured&&(0,R.jsx)(w,{type:`button`,variant:`ghost`,onClick:e,children:t(`common.cancel`)})]})]})]}),b&&(0,R.jsx)(M,{title:t(`manyfold.disconnectTitle`),message:t(`manyfold.disconnectBody`),confirmText:t(`manyfold.disconnect`),variant:`danger`,isLoading:ee.isPending,onCancel:()=>T(!1),onConfirm:()=>ee.mutate()})]})}function se({value:e,onChange:t,disabled:n}){let{t:i}=a(),o=(s({queryKey:[`library-folders`],queryFn:()=>r.getLibraryFolders()}).data??[]).filter(e=>!(e.is_external&&e.external_readonly)).flatMap(e=>H(e));return(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[i(`manyfold.importTo`),(0,R.jsxs)(`select`,{value:e??``,disabled:n,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,R.jsx)(`option`,{value:``,children:i(`manyfold.folderAuto`)}),o.map(({folder:e,depth:t})=>(0,R.jsx)(`option`,{value:e.id,disabled:e.can_write===!1,children:`${`— `.repeat(t)}${e.name}`},e.id))]})]})}function G(e){return e.length>3?`${e.slice(0,3).join(`, `)} +${e.length-3}`:e.join(`, `)}function K(){let{t:e}=a(),{showToast:t}=h(),n=o(),[i,s]=(0,L.useState)(null);return{run:async(i,a)=>{if(i.length===0){t(e(`manyfold.bulkNothing`),`info`);return}let o=0,c=0,l=[],u=null;try{for(let e=0;e<i.length;e+=1){s({current:e+1,total:i.length});try{(await r.importManyfoldFile(i[e].modelId,i[e].fileId,a)).was_existing?c+=1:o+=1}catch(t){l.push(i[e].name),u??=t}}}finally{s(null),n.invalidateQueries({queryKey:[`manyfold-model`]}),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]})}t(e(`manyfold.bulkDone`,{imported:o,existing:c,failed:l.length}),l.length?`warning`:`success`),l.length&&t(e(`manyfold.bulkFailed`,{names:G(l),reason:B(u,e)}),`error`)},progress:i,busy:i!==null}}function ce({modelId:e,onBack:t,onSlice:n}){let{t:i}=a(),{hasPermission:l}=ne(),{showToast:d}=h(),f=o(),m=k(),_=l(`manyfold:import`),[y,b]=(0,L.useState)(null),[T,D]=(0,L.useState)(null),[O,A]=(0,L.useState)(new Set),j=K(),M=s({queryKey:[`manyfold-model`,e],queryFn:()=>r.getManyfoldModel(e)}),N=s({queryKey:[`settings`],queryFn:()=>r.getSettings()}),ee=N.data?.use_slicer_api??!1,re=ie(N.data?.open_in_slicer,N.data?.preferred_slicer),ae=c({mutationFn:t=>r.importManyfoldFile(e,t.id,y),onMutate:e=>D(e.id),onSettled:()=>D(null),onSuccess:t=>{f.invalidateQueries({queryKey:[`manyfold-model`,e]}),f.invalidateQueries({queryKey:[`library-files`]}),f.invalidateQueries({queryKey:[`library-folders`]}),d(t.was_existing?i(`manyfold.alreadyInLibrary`):i(`manyfold.imported`,{filename:t.filename}),`success`)},onError:e=>d(B(e,i),`error`)});if(M.isLoading)return(0,R.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,R.jsx)(v,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(M.isError||!M.data)return(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:t,children:[(0,R.jsx)(u,{className:`w-4 h-4`}),i(`manyfold.back`)]}),(0,R.jsx)(`p`,{className:`text-red-400 text-sm`,children:B(M.error,i)})]});let F=M.data,I=F.files.filter(e=>e.importable&&!e.library_file),z=I.filter(e=>O.has(e.id)),H=I.length>0&&z.length===I.length,W=j.busy||ae.isPending,G=async e=>{await j.run(e.map(e=>({modelId:F.id,fileId:e.id,name:e.name})),y),A(new Set)};return(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:t,children:[(0,R.jsx)(u,{className:`w-4 h-4`}),i(`manyfold.back`)]}),(0,R.jsx)(C,{children:(0,R.jsx)(S,{children:(0,R.jsxs)(`div`,{className:`flex flex-col md:flex-row gap-6 py-2`,children:[(0,R.jsx)(U,{modelId:F.id,className:`w-full md:w-72 aspect-square rounded-lg shrink-0`}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`h2`,{className:`text-xl font-semibold text-white break-words`,children:F.name}),F.caption&&(0,R.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:F.caption})]}),F.description&&(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray whitespace-pre-line break-words`,children:F.description}),F.tags.length>0&&(0,R.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:F.tags.map(e=>(0,R.jsx)(`span`,{className:`px-2 py-0.5 rounded-full bg-bambu-dark-tertiary text-xs text-white`,children:e},e))}),(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2 text-sm`,children:[F.license&&(0,R.jsxs)(`span`,{className:`text-bambu-gray`,children:[i(`manyfold.license`),`: `,(0,R.jsx)(`span`,{className:`text-white`,children:F.license})]}),(0,R.jsxs)(`a`,{href:F.url,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-bambu-green hover:underline`,children:[(0,R.jsx)(E,{className:`w-3.5 h-3.5`}),i(`manyfold.openInManyfold`)]})]})]})]})})}),(0,R.jsxs)(C,{children:[(0,R.jsxs)(x,{children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,R.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:i(`manyfold.files`)}),_&&(0,R.jsx)(se,{value:y,onChange:b,disabled:W})]}),_&&I.length>0&&(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 mt-3`,children:[(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-white`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:H,ref:e=>{e&&(e.indeterminate=z.length>0&&!H)},disabled:W,onChange:()=>A(H?new Set:new Set(I.map(e=>e.id))),className:`accent-bambu-green`}),i(`manyfold.selectAll`)]}),j.progress?(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}),i(`manyfold.importProgress`,j.progress)]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(w,{variant:`primary`,size:`sm`,disabled:W||z.length===0,onClick:()=>G(z),children:[(0,R.jsx)(te,{className:`w-3.5 h-3.5`}),i(`manyfold.importSelected`,{count:z.length})]}),(0,R.jsx)(w,{variant:`secondary`,size:`sm`,disabled:W,onClick:()=>G(I),children:i(`manyfold.importAll`)})]})]})]}),(0,R.jsx)(S,{children:F.files.length===0?(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`manyfold.noFiles`)}):(0,R.jsx)(`ul`,{className:`divide-y divide-bambu-dark-tertiary`,children:F.files.map(e=>{let t=e.library_file,r=t!==null&&oe({filename:t.filename},ee,re);return(0,R.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 py-2`,children:[_&&I.length>0&&(0,R.jsx)(`span`,{className:`w-4 shrink-0 flex`,children:e.importable&&!t&&(0,R.jsx)(`input`,{type:`checkbox`,"aria-label":i(`manyfold.selectFile`,{name:e.name}),checked:O.has(e.id),disabled:W,onChange:()=>A(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,R.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-bambu-dark-tertiary text-[11px] font-mono text-bambu-gray shrink-0`,children:V(e.mime)}),(0,R.jsx)(`span`,{className:`text-sm text-white min-w-0 flex-1 break-words`,children:e.name}),(0,R.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:e.importable?t?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs text-bambu-green`,children:[(0,R.jsx)(p,{className:`w-3.5 h-3.5`}),i(`manyfold.inLibrary`)]}),(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>m(t.folder_id?`/files?folder=${t.folder_id}`:`/files`),children:[(0,R.jsx)(P,{className:`w-3.5 h-3.5`}),i(`manyfold.showInLibrary`)]}),r&&(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>n(t.id,t.filename),children:[(0,R.jsx)(g,{className:`w-3.5 h-3.5`}),i(`slice.action`,`Slice`)]})]}):_?(0,R.jsxs)(w,{variant:`secondary`,size:`sm`,disabled:W,onClick:()=>ae.mutate(e),children:[T===e.id?(0,R.jsx)(v,{className:`w-3.5 h-3.5 animate-spin`}):(0,R.jsx)(te,{className:`w-3.5 h-3.5`}),T===e.id?i(`manyfold.importing`):i(`manyfold.import`)]}):null:(0,R.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:i(`manyfold.notImportable`)})})]},e.id)})})})]})]})}function le(){let{t:e}=a(),{hasPermission:t}=ne(),n=t(`settings:update`),[i,c]=(0,L.useState)(!1),[l,u]=(0,L.useState)(``),[d,f]=(0,L.useState)(``),[p,m]=(0,L.useState)(1),[g,b]=(0,L.useState)(null),[x,T]=(0,L.useState)(null),[E,O]=(0,L.useState)(new Map),[k,j]=(0,L.useState)(null),[M,N]=(0,L.useState)(null),P=t(`manyfold:import`),ae=o(),{showToast:oe}=h(),F=K(),I=M!==null||F.busy,z=M?e(`manyfold.collectProgress`,M):F.progress?e(`manyfold.importProgress`,F.progress):null,V=(e,t)=>O(n=>{let r=new Map(n);return r.has(e)?r.delete(e):r.set(e,t),r}),H=async()=>{let t=[...E.keys()],n=[],i=[];try{for(let e=0;e<t.length;e+=1){N({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(E.get(t[e])??t[e])}}}finally{N(null)}i.length&&oe(e(`manyfold.modelsUnreadable`,{names:G(i)}),`error`),await F.run(n,k),O(new Map)},le=s({queryKey:[`settings`],queryFn:()=>r.getSettings()}),q=s({queryKey:[`manyfold-status`],queryFn:()=>r.getManyfoldStatus()}),ue=q.data?.configured??!1,J=s({queryKey:[`manyfold-models`,d,p],queryFn:()=>r.listManyfoldModels(d,p),enabled:ue,placeholderData:e=>e}),Y=async(e,t)=>{if(le.data?.use_slicer_api){T({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(q.isLoading)return(0,R.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,R.jsx)(v,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(!ue||i)return(0,R.jsxs)(`div`,{className:`space-y-6`,children:[(0,R.jsx)(`p`,{className:`text-bambu-gray`,children:e(`manyfold.description`)}),n?(0,R.jsx)(W,{onDone:ue?()=>c(!1):void 0}):(0,R.jsx)(C,{children:(0,R.jsx)(S,{children:(0,R.jsxs)(`div`,{className:`py-2`,children:[(0,R.jsx)(`p`,{className:`font-medium text-white`,children:e(`manyfold.notConnectedTitle`)}),(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`manyfold.notConnectedBody`)})]})})})]});let X=J.data;return(0,R.jsxs)(`div`,{className:`space-y-6`,children:[g?(0,R.jsx)(ce,{modelId:g,onBack:()=>b(null),onSlice:Y}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,R.jsx)(`p`,{className:`text-bambu-gray flex-1 min-w-[16rem]`,children:e(`manyfold.description`)}),n&&(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>c(!0),children:[(0,R.jsx)(A,{className:`w-4 h-4`}),e(`manyfold.editConnection`)]})]}),(0,R.jsxs)(`form`,{className:`flex gap-2`,role:`search`,onSubmit:e=>{e.preventDefault(),f(l.trim()),m(1)},children:[(0,R.jsxs)(`div`,{className:`relative flex-1`,children:[(0,R.jsx)(y,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2`}),(0,R.jsx)(`input`,{type:`search`,value:l,onChange:e=>u(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,R.jsx)(w,{type:`submit`,children:e(`common.search`)})]}),J.isError?(0,R.jsx)(`p`,{className:`text-sm text-red-400`,children:B(J.error,e)}):X?X.models.length===0?(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`manyfold.noModels`)}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`manyfold.modelCount`,{count:X.total})}),P&&(0,R.jsx)(w,{variant:`ghost`,size:`sm`,disabled:I,onClick:()=>O(e=>{let t=new Map(e);for(let e of X.models)t.set(e.id,e.name);return t}),children:e(`manyfold.selectPage`)})]}),P&&E.size>0&&(0,R.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,R.jsx)(`span`,{className:`text-sm text-white`,children:e(`manyfold.modelsSelected`,{count:E.size})}),(0,R.jsx)(se,{value:k,onChange:j,disabled:I}),z?(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}),z]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(w,{variant:`primary`,size:`sm`,onClick:H,children:[(0,R.jsx)(te,{className:`w-3.5 h-3.5`}),e(`manyfold.importModels`)]}),(0,R.jsx)(w,{variant:`ghost`,size:`sm`,onClick:()=>O(new Map),children:e(`manyfold.clearSelection`)})]})]}),(0,R.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-6 gap-4`,children:X.models.map(t=>{let n=E.has(t.id);return(0,R.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,R.jsxs)(`button`,{type:`button`,onClick:()=>b(t.id),disabled:I,className:`block w-full text-left disabled:cursor-wait`,children:[(0,R.jsx)(U,{modelId:t.id,className:`aspect-square`}),(0,R.jsx)(`span`,{className:`block px-3 py-2 text-sm text-white truncate`,title:t.name,children:t.name})]}),P&&(0,R.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,R.jsx)(`input`,{type:`checkbox`,"aria-label":e(`manyfold.selectModel`,{name:t.name}),checked:n,disabled:I,onChange:()=>V(t.id,t.name),className:`accent-bambu-green w-4 h-4`})})]},t.id)})}),(X.has_previous||X.has_next)&&(0,R.jsxs)(`div`,{className:`flex items-center justify-center gap-3`,children:[(0,R.jsxs)(w,{variant:`secondary`,size:`sm`,disabled:!X.has_previous||J.isFetching,onClick:()=>m(e=>Math.max(1,e-1)),children:[(0,R.jsx)(ee,{className:`w-4 h-4`}),e(`manyfold.previous`)]}),(0,R.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e(`manyfold.page`,{page:X.page})}),(0,R.jsxs)(w,{variant:`secondary`,size:`sm`,disabled:!X.has_next||J.isFetching,onClick:()=>m(e=>e+1),children:[e(`manyfold.next`),(0,R.jsx)(D,{className:`w-4 h-4`})]})]})]}):(0,R.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,R.jsx)(v,{className:`w-8 h-8 text-bambu-green animate-spin`})})]}),x&&(0,R.jsx)(_,{source:x,onClose:()=>T(null)})]})}function q(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 J(e){return e?/^https?:\/\/(makerworld|public-cdn)\.bblmw\.com\//i.test(e)?`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(e)}`:e:``}function Y(e,t){let n=e?.[t];return typeof n==`number`?n:null}function X(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,L.useState)(0);return(0,L.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}=a(),{hasPermission:n}=ne(),{showToast:i}=h(),l=o(),u=n(`makerworld:import`),[f,y]=(0,L.useState)(``),[k,A]=(0,L.useState)(null),[j,oe]=(0,L.useState)(null),[I,z]=(0,L.useState)(null),[B,V]=(0,L.useState)(null),[H,U]=(0,L.useState)(null),[W,se]=(0,L.useState)(``),[G,K]=(0,L.useState)({}),ce=s({queryKey:[`makerworld-status`],queryFn:()=>r.getMakerworldStatus()}),le=s({queryKey:[`library-folders`],queryFn:()=>r.getLibraryFolders()}),me=s({queryKey:[`makerworld-recent-imports`],queryFn:()=>r.getMakerworldRecentImports(10)}),he=s({queryKey:[`settings`],queryFn:()=>r.getSettings()}),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,L.useState)(null),Ce=(e,t)=>{Se({kind:`libraryFile`,id:e,filename:t})},we=c({mutationFn:e=>r.resolveMakerworldUrl(e),onSuccess:(e,t)=>{A(e),se(t),K({})},onError:e=>i(e.message||t(`makerworld.errors.resolveFailed`),`error`)});(0,L.useEffect)(()=>{k!==null&&f.trim()!==W.trim()&&(A(null),se(``),K({}))},[f,k,W]);let Z=c({mutationFn:({instanceId:e,profileId:t})=>r.importMakerworldInstance(k?.model_id??0,e,t,j),onSuccess:e=>{l.invalidateQueries({queryKey:[`library-files`]}),l.invalidateQueries({queryKey:[`library-folders`]}),e.profile_id&&K(t=>({...t,[e.profile_id]:e})),i(e.was_existing?t(`makerworld.alreadyInLibrary`):t(`makerworld.importSuccess`,{filename:e.filename}),`success`)},onError:e=>i(e.message||t(`makerworld.errors.downloadFailed`),`error`)}),Te=c({mutationFn:({libraryFileId:e})=>r.deleteLibraryFile(e),onSuccess:(e,{profileId:n})=>{l.invalidateQueries({queryKey:[`library-files`]}),l.invalidateQueries({queryKey:[`library-folders`]}),l.invalidateQueries({queryKey:[`makerworld-recent-imports`]}),K(e=>{let t={...e};return delete t[n],t}),V(null),i(t(`makerworld.importDeleted`),`success`)},onError:e=>{V(null),i(e.message||t(`makerworld.errors.deleteFailed`),`error`)}}),Ee=c({mutationFn:({instanceId:e,profileId:t})=>r.importMakerworldInstance(k?.model_id??0,e,t,j),onSuccess:async e=>{l.invalidateQueries({queryKey:[`library-files`]}),l.invalidateQueries({queryKey:[`library-folders`]}),l.invalidateQueries({queryKey:[`makerworld-recent-imports`]}),e.profile_id&&K(t=>({...t,[e.profile_id]:e})),ge?Ce(e.library_file_id,e.filename):await je(e.library_file_id,e.filename,ye)},onError:e=>i(e.message||t(`makerworld.errors.downloadFailed`),`error`)}),Q=pe(Z.isPending||Ee.isPending),De=fe(Q,t),Oe=e=>{e?.preventDefault();let t=f.trim();t&&we.mutate(t)};(0,L.useEffect)(()=>{if(!H)return;let e=e=>{e.key===`Escape`?U(null):e.key===`ArrowLeft`?U(e=>e&&e.index>0?{...e,index:e.index-1}:e):e.key===`ArrowRight`&&U(e=>e&&e.index<e.images.length-1?{...e,index:e.index+1}:e)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[H]);let ke=e=>{let t=(Array.isArray(e.pictures)?e.pictures:[]).filter(e=>typeof e==`object`&&!!e).map(e=>({name:q(e,`name`)||`image`,url:q(e,`url`)})).filter(e=>e.url);if(t.length>0)return t;let n=q(e,`cover`);return n?[{name:`cover`,url:n}]:[]},Ae=async()=>{if(!k)return;let e=k.instances.filter(e=>{let t=Y(e,`profileId`);return t!==null&&!G[t]});if(e.length!==0){z({current:0,total:e.length});try{for(let t=0;t<e.length;t+=1){let n=e[t],r=Y(n,`id`),i=Y(n,`profileId`);if(!(r===null||i===null)){z({current:t+1,total:e.length});try{await Z.mutateAsync({instanceId:r,profileId:i})}catch{}}}}finally{z(null)}}},je=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)}},$=k?.design,Me=X($,`designCreator`),Ne=k?.instances??[],Pe=(k?.already_imported_library_ids.length??0)>0,Fe=ce.data?.can_download??!1,Ie=ce.data?.sign_in_expired??!1,Le=(0,L.useMemo)(()=>q($,`coverUrl`),[$]),Re=q($,`title`),ze=q($,`summary`),Be=q($,`license`),Ve=Y($,`downloadCount`);return(0,R.jsxs)(`div`,{className:e?`space-y-6`:`p-4 md:p-8 max-w-screen-2xl space-y-6`,children:[e?(0,R.jsx)(`p`,{className:`text-bambu-gray`,children:t(`makerworld.description`)}):(0,R.jsxs)(`div`,{children:[(0,R.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,R.jsx)(N,{className:`w-7 h-7 text-bambu-green`}),t(`makerworld.title`)]}),(0,R.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:t(`makerworld.description`)})]}),(0,R.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-[1fr_20rem]`,children:[(0,R.jsxs)(`div`,{className:`space-y-6 min-w-0`,children:[!Fe&&(0,R.jsx)(C,{className:`border-amber-300 dark:border-amber-700 bg-amber-50 dark:bg-amber-900/20`,children:(0,R.jsx)(S,{children:(0,R.jsxs)(`div`,{className:`flex items-start gap-3 py-2`,children:[(0,R.jsx)(m,{className:`w-5 h-5 text-amber-600 dark:text-amber-400 mt-0.5 shrink-0`}),(0,R.jsxs)(`div`,{className:`text-sm`,children:[(0,R.jsx)(`p`,{className:`font-medium text-amber-900 dark:text-amber-100`,children:t(Ie?`makerworld.signInExpiredTitle`:`makerworld.signInRequiredTitle`)}),(0,R.jsxs)(`p`,{className:`text-amber-800 dark:text-amber-200 mt-1`,children:[t(Ie?`makerworld.signInExpiredBody`:`makerworld.signInRequiredBody`),` `,(0,R.jsx)(O,{to:`/profiles`,className:`underline`,children:t(`makerworld.openCloudSettings`)})]})]})]})})}),(0,R.jsxs)(C,{children:[(0,R.jsx)(x,{children:(0,R.jsx)(`h2`,{className:`text-lg font-semibold`,children:t(`makerworld.pasteUrlHeader`)})}),(0,R.jsx)(S,{children:(0,R.jsxs)(`form`,{onSubmit:Oe,className:`flex gap-2`,children:[(0,R.jsx)(`input`,{type:`text`,value:f,onChange:e=>y(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,R.jsxs)(w,{type:`submit`,variant:`primary`,disabled:!f.trim()||we.isPending,children:[we.isPending?(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}):(0,R.jsx)(d,{className:`w-4 h-4`}),(0,R.jsx)(`span`,{className:`ml-2`,children:t(`makerworld.resolveButton`)})]})]})})]}),k&&(0,R.jsx)(C,{children:(0,R.jsx)(S,{children:(0,R.jsxs)(`div`,{className:`flex gap-4 py-2`,children:[Le&&(0,R.jsx)(`img`,{src:J(Le),alt:Re,className:`w-32 h-32 object-cover rounded`,loading:`lazy`}),(0,R.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,R.jsx)(`h3`,{className:`text-xl font-semibold truncate`,children:Re||t(`makerworld.untitledModel`)}),Me&&(0,R.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-1`,children:t(`makerworld.byCreator`,{name:q(Me,`name`)})}),(0,R.jsxs)(`div`,{className:`flex flex-wrap gap-3 mt-2 text-xs text-gray-500 dark:text-gray-400`,children:[Ve!==null&&(0,R.jsx)(`span`,{children:t(`makerworld.downloadsCount`,{count:Ve})}),Be&&(0,R.jsxs)(`span`,{children:[t(`makerworld.licensePrefix`),`: `,Be]}),Pe&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-emerald-600 dark:text-emerald-400`,children:[(0,R.jsx)(p,{className:`w-3 h-3`}),` `,t(`makerworld.alreadyImported`)]})]}),ze&&(0,R.jsx)(`div`,{className:`mt-3 text-sm prose prose-sm max-w-none dark:prose-invert line-clamp-3`,dangerouslySetInnerHTML:{__html:ae.sanitize(ue(ze))}}),k&&(0,R.jsxs)(`a`,{href:`https://makerworld.com/models/${k.model_id}${k.profile_id?`#profileId-${k.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,R.jsx)(E,{className:`w-3 h-3`}),` `,t(`makerworld.openOnMakerworld`)]})]})]})})}),k&&Ne.length>0&&(0,R.jsxs)(C,{children:[(0,R.jsx)(x,{children:(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,R.jsx)(`h2`,{className:`text-lg font-semibold`,children:t(`makerworld.platesHeader`,{count:Ne.length})}),(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,R.jsx)(`label`,{className:`text-xs text-gray-600 dark:text-gray-400`,children:t(`makerworld.importTo`)}),(0,R.jsxs)(`select`,{value:j??``,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:I!==null,children:[(0,R.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,R.jsx)(`option`,{value:e.id,disabled:e.can_write===!1,children:`${`— `.repeat(t)}${e.name}`},e.id))]}),(0,R.jsx)(w,{variant:`primary`,size:`sm`,disabled:!u||!Fe||I!==null||Z.isPending||Ee.isPending,onClick:Ae,children:I===null?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(te,{className:`w-4 h-4`}),(0,R.jsx)(`span`,{className:`ml-2`,children:t(`makerworld.importAll`)})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}),(0,R.jsxs)(`span`,{className:`ml-2`,children:[t(`makerworld.importAllProgress`,{current:I.current,total:I.total}),Q>0&&` · ${De} · ${Q}s`]})]})})]})]})}),(0,R.jsx)(S,{children:(0,R.jsx)(`div`,{className:`grid gap-3`,children:Ne.map((e,n)=>{let r=Y(e,`id`),i=Y(e,`profileId`),a=q(e,`title`),o=q(e,`cover`),s=Y(e,`materialCnt`),c=e?.needAms===!0,l=Y(e,`downloadCount`),d=e?.compatibility??null,f=e?.otherCompatibility??null,m=d?.devProductName??null,h=Array.isArray(f)?f.map(e=>e?.devProductName??``).filter(Boolean):[];if(r==null)return null;let _=Z.isPending&&Z.variables?.instanceId===r,y=Ee.isPending&&Ee.variables?.instanceId===r,b=i===null?void 0:G[i];return(0,R.jsxs)(`div`,{className:`flex flex-col gap-2 p-3 border rounded border-gray-200 dark:border-gray-700`,children:[(0,R.jsxs)(`div`,{className:`flex gap-3 items-center`,children:[(()=>{let n=ke(e),r=n.length>0;return(0,R.jsxs)(`button`,{type:`button`,disabled:!r,onClick:()=>r&&U({images:n,index:0}),className:`relative w-16 h-16 shrink-0 rounded overflow-hidden group`,"aria-label":t(`makerworld.openGallery`),children:[o?(0,R.jsx)(`img`,{src:J(o),alt:``,className:`w-16 h-16 object-cover`,loading:`lazy`}):(0,R.jsx)(`div`,{className:`w-16 h-16 bg-gray-100 dark:bg-gray-800`}),n.length>1&&(0,R.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,R.jsx)(F,{className:`w-2.5 h-2.5`}),n.length]})]})})(),(0,R.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,R.jsx)(`p`,{className:`font-medium truncate`,children:a||t(`makerworld.plateDefaultName`,{n:n+1})}),(0,R.jsxs)(`div`,{className:`flex flex-wrap gap-3 text-xs text-gray-500 dark:text-gray-400 mt-1`,children:[m&&(0,R.jsx)(`span`,{className:`font-medium text-gray-700 dark:text-gray-300`,children:t(`makerworld.slicedFor`,{printer:m,defaultValue:`Sliced for {{printer}}`})}),s!==null&&(0,R.jsx)(`span`,{children:t(`makerworld.materialCount`,{count:s})}),c&&(0,R.jsx)(`span`,{children:t(`makerworld.amsRequired`)}),l!==null&&(0,R.jsx)(`span`,{children:t(`makerworld.downloadsCount`,{count:l})})]}),h.length>0&&(0,R.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,title:h.join(`, `),children:t(`makerworld.alsoCompatible`,{printers:h.slice(0,6).join(`, `)+(h.length>6?`…`:``),defaultValue:`Also marked compatible: {{printers}}`})})]}),(0,R.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[(0,R.jsx)(w,{variant:`ghost`,size:`sm`,disabled:!u||!Fe||_||y||I!==null,onClick:()=>Z.mutate({instanceId:r,profileId:i}),title:Fe?void 0:t(`makerworld.signInRequiredTitle`),children:_?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}),(0,R.jsxs)(`span`,{className:`ml-2`,children:[De,Q>0&&` · ${Q}s`]})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(te,{className:`w-4 h-4`}),(0,R.jsx)(`span`,{className:`ml-2`,children:t(`makerworld.importToLibrary`)})]})}),(0,R.jsx)(w,{variant:`primary`,size:`sm`,disabled:!u||!Fe||_||y||I!==null,onClick:()=>Ee.mutate({instanceId:r,profileId:i}),title:Fe?void 0:t(`makerworld.signInRequiredTitle`),children:y?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}),(0,R.jsxs)(`span`,{className:`ml-2`,children:[De,Q>0&&` · ${Q}s`]})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(E,{className:`w-4 h-4`}),(0,R.jsx)(`span`,{className:`ml-2`,children:t(`makerworld.sliceIn`,{slicer:be})})]})})]})]}),b&&(0,R.jsxs)(`div`,{className:`flex items-center gap-2 pl-20 text-xs`,children:[(0,R.jsx)(p,{className:`w-3.5 h-3.5 text-emerald-600 dark:text-emerald-400 shrink-0`}),(0,R.jsx)(`span`,{className:`text-emerald-700 dark:text-emerald-300`,children:b.was_existing?t(`makerworld.lastImportAlreadyInLibrary`):t(`makerworld.lastImportSuccess`)}),(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>{let e=b.folder_id?`/files?folder=${b.folder_id}`:`/files`;window.location.assign(e)},children:[(0,R.jsx)(P,{className:`w-3.5 h-3.5`}),(0,R.jsx)(`span`,{className:`ml-1.5`,children:t(`makerworld.viewInLibrary`)})]}),ge?(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>Ce(b.library_file_id,b.filename),children:[(0,R.jsx)(g,{className:`w-3.5 h-3.5`}),(0,R.jsx)(`span`,{className:`ml-1.5`,children:t(`slice.action`,`Slice`)})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>je(b.library_file_id,b.filename,`bambu_studio`),children:[(0,R.jsx)(E,{className:`w-3.5 h-3.5`}),(0,R.jsx)(`span`,{className:`ml-1.5`,children:t(`makerworld.openInBambuStudio`)})]}),(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>je(b.library_file_id,b.filename,`orcaslicer`),children:[(0,R.jsx)(E,{className:`w-3.5 h-3.5`}),(0,R.jsx)(`span`,{className:`ml-1.5`,children:t(`makerworld.openInOrcaSlicer`)})]})]}),(0,R.jsx)(`div`,{className:`ml-auto`,children:(0,R.jsx)(w,{variant:`ghost`,size:`sm`,disabled:Te.isPending&&Te.variables?.profileId===i,onClick:()=>{i!==null&&V({libraryFileId:b.library_file_id,profileId:i,filename:b.filename})},title:t(`makerworld.deleteImport`),children:Te.isPending&&Te.variables?.profileId===i?(0,R.jsx)(v,{className:`w-3.5 h-3.5 animate-spin`}):(0,R.jsx)(T,{className:`w-3.5 h-3.5 text-red-500`})})})]})]},r)})})})]})]}),(0,R.jsx)(`aside`,{className:`lg:sticky lg:top-6 lg:self-start min-w-0`,children:me.data&&me.data.length>0&&(0,R.jsxs)(C,{children:[(0,R.jsx)(x,{children:(0,R.jsx)(`h2`,{className:`text-base font-semibold`,children:t(`makerworld.recentImportsHeader`)})}),(0,R.jsx)(S,{children:(0,R.jsx)(`div`,{className:`flex flex-col gap-2 max-h-[28rem] overflow-y-auto -mx-2 px-2`,children:me.data.map(e=>(0,R.jsxs)(`div`,{className:`flex gap-2 p-2 border rounded border-gray-200 dark:border-gray-700`,children:[e.thumbnail_path?(0,R.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,R.jsx)(`div`,{className:`w-12 h-12 shrink-0 rounded bg-gray-100 dark:bg-gray-800`}),(0,R.jsxs)(`div`,{className:`flex-1 min-w-0 flex flex-col gap-1`,children:[(0,R.jsx)(`p`,{className:`text-xs font-medium truncate`,title:e.filename,children:e.filename}),(0,R.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,R.jsx)(w,{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,R.jsx)(P,{className:`w-3.5 h-3.5`})}),ge?(0,R.jsx)(w,{variant:`ghost`,size:`sm`,onClick:()=>Ce(e.library_file_id,e.filename),title:t(`slice.action`,`Slice`),children:(0,R.jsx)(g,{className:`w-3.5 h-3.5`})}):(0,R.jsx)(w,{variant:`ghost`,size:`sm`,onClick:()=>je(e.library_file_id,e.filename,`bambu_studio`),title:t(`makerworld.openInBambuStudio`),children:(0,R.jsx)(E,{className:`w-3.5 h-3.5`})}),e.source_url&&(0,R.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,R.jsx)(N,{className:`w-3.5 h-3.5`})})]})]})]},e.library_file_id))})})]})})]}),(0,R.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`)}),B&&(0,R.jsx)(M,{title:t(`makerworld.deleteImport`),message:t(`makerworld.confirmDelete`,{filename:B.filename}),confirmText:t(`makerworld.deleteImport`),variant:`danger`,isLoading:Te.isPending,loadingText:t(`makerworld.importDeleting`),onCancel:()=>V(null),onConfirm:()=>Te.mutate({libraryFileId:B.libraryFileId,profileId:B.profileId})}),xe&&(0,R.jsx)(_,{source:xe,onClose:()=>Se(null)}),H&&(0,R.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-50`,onClick:()=>U(null),role:`dialog`,"aria-modal":`true`,children:[(0,R.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(),U(null)},"aria-label":t(`common.close`,`Close`),children:(0,R.jsx)(b,{className:`w-5 h-5`})}),H.images.length>1&&(0,R.jsxs)(R.Fragment,{children:[(0,R.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:H.index===0,onClick:e=>{e.stopPropagation(),U(e=>e&&{...e,index:Math.max(0,e.index-1)})},"aria-label":t(`makerworld.galleryPrev`),children:(0,R.jsx)(ee,{className:`w-6 h-6`})}),(0,R.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:H.index>=H.images.length-1,onClick:e=>{e.stopPropagation(),U(e=>e&&{...e,index:Math.min(e.images.length-1,e.index+1)})},"aria-label":t(`makerworld.galleryNext`),children:(0,R.jsx)(D,{className:`w-6 h-6`})})]}),(0,R.jsx)(`img`,{src:J(H.images[H.index].url),alt:H.images[H.index].name,className:`max-w-[90vw] max-h-[90vh] object-contain`,onClick:e=>e.stopPropagation()}),H.images.length>1&&(0,R.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:[H.index+1,` / `,H.images.length]})]})]})}function he(){let{t:e}=a(),{hasPermission:t}=ne(),[n,i]=j(),o=t(`manyfold:view`),c=s({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:N}),l&&u.push({id:`manyfold`,label:e(`modelSources.tabManyfold`),icon:I});let d=n.get(`tab`),f=u.find(e=>e.id===d)?.id??u[0]?.id??(o?`manyfold`:void 0);return(0,R.jsxs)(`div`,{className:`p-4 md:p-8 max-w-screen-2xl`,children:[(0,R.jsx)(`div`,{className:`mb-6`,children:(0,R.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,R.jsx)(N,{className:`w-7 h-7 text-bambu-green`}),e(`modelSources.title`)]})}),u.length>1&&(0,R.jsx)(`div`,{className:`flex border-b border-bambu-dark-tertiary mb-6`,role:`tablist`,children:u.map(({id:e,label:t,icon:n})=>(0,R.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":f===e,onClick:()=>i({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 ${f===e?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,R.jsx)(n,{className:`w-4 h-4`}),t]},e))}),f===`makerworld`&&(0,R.jsx)(me,{embedded:!0}),f===`manyfold`&&(0,R.jsx)(le,{})]})}export{he as ModelSourcesPage};