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