diff --git a/CHANGELOG.md b/CHANGELOG.md index aec318054..0de8d0acf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,13 +11,14 @@ All notable changes to Bambuddy will be documented in this file. - **External Folder Mounting for File Manager** ([#124](https://github.com/maziggy/bambuddy/issues/124)) — Host directories (NAS shares, USB drives, network storage) can now be mounted into the File Manager without copying files. Click "Link External" to point at a Docker bind-mounted path. Files are indexed into the database on scan but accessed directly from their original location — nothing is copied. Supports read-only mode (default, blocks uploads/moves/deletes), hidden file filtering, and automatic thumbnail extraction for 3MF, STL, gcode, and image files. External folders show a distinct icon and info bar with a rescan button. Deleting an external folder only removes the database index, never the actual files. Requested by @S1N4X. ### Improved -- **SpoolBuddy AMS Slot Action Picker** — Clicking an AMS slot on the SpoolBuddy AMS page now shows a picker with contextual actions: Configure AMS Slot (set filament preset, K-profile, color), Assign Spool / Link to Spoolman (depending on which system is active), and Unassign / Unlink when a spool is already mapped. Previously the slot click went straight to the configure modal with no way to assign inventory spools or link Spoolman spools. +- **SpoolBuddy AMS Slot Action Picker** — Clicking an AMS slot on the SpoolBuddy AMS page now shows a picker with contextual actions: Configure AMS Slot (set filament preset, K-profile, color), and either Assign Spool / Link to Spoolman (when no spool is mapped) or Unassign / Unlink (when one is). Works with both internal inventory and Spoolman. Previously the slot click went straight to the configure modal with no way to manage spool assignments. - **SpoolBuddy Settings Device Tab No Longer Scrolls** — Removed the branding card, folded Device ID into the Device Info card, placed Backend/Auth config and diagnostic buttons side by side in a 2-column layout, removed the redundant online/offline status row from Device Info, and tightened spacing throughout. The Device tab now fits on the small SpoolBuddy touchscreen without scrolling. - **Spool Notes in Assign Spool Modal** ([#793](https://github.com/maziggy/bambuddy/issues/793)) — Spool cards in the Assign Spool modal now show the spool's note as a hover tooltip, making it easier to identify spools by tracking IDs or other metadata stored in notes. Works with both internal inventory and Spoolman-synced spools. Requested by @LegionCanadian. - **WiFi Safeguard for SpoolBuddy Pi** — The install script now drops an APT hook (`/etc/apt/apt.conf.d/80-preserve-wifi`) that backs up NetworkManager WiFi connections before every `apt upgrade` and restores them if they get wiped. Prevents headless SpoolBuddy Pis from losing WiFi connectivity after Raspberry Pi OS package upgrades (observed with Bookworm kernel/raspi-config updates that clear `/etc/NetworkManager/system-connections/`). - **SpoolBuddy Install Script Now Upgrades System Packages** — The install script now runs `apt-get upgrade -y` after installing required packages and the WiFi safeguard. This ensures the Pi is fully up to date before SpoolBuddy is deployed, and the WiFi safeguard protects connectivity during the upgrade. ### Fixed +- **Delete Tag Leaves Stale Tag Type** — The "Delete Tag" button in the spool edit modal only cleared `tag_uid` but left `tray_uuid`, `tag_type`, and `data_origin` intact. All tag-related fields are now cleared together. - **SpoolBuddy NFC Write Fails on NTAG Tags** — Multiple issues prevented writing to NTAG 213/215/216 tags. (1) Some chips report SAK `0x04` (MIFARE Ultralight family) instead of `0x00` during anticollision — both `0x00` and `0x04` are now accepted. (2) TX CRC was disabled for NTAG commands but the spec requires it — enabled for both WRITE and READ. (3) The PN5180 state machine needed IDLE→TRANSCEIVE resets (not just `set_transceive_mode()`) and Crypto1 cleared before NTAG operations. (4) The 4-bit WRITE ACK cannot be captured by the PN5180 (SOF detected but no RX_IRQ) — removed per-page ACK checking. (5) Post-write read-back verification also failed (second READ command gets no response from the PN5180) — removed verification since the tag reliably ACKs each write. - **Database Connection Pool Exhaustion on Large Printer Farms** — Users with 100+ printers connected simultaneously experienced `QueuePool limit of size 10 overflow 20 reached, connection timed out` errors. Increased the SQLAlchemy connection pool from 30 total (10 base + 20 overflow) to 220 (20 base + 200 overflow), and raised the SQLite busy_timeout from 5 to 15 seconds to reduce write contention under heavy concurrent MQTT updates. - **SpoolBuddy Update Check Always Shows "Up to Date"** — The SpoolBuddy daemon update check compared the device's firmware version against GitHub releases instead of the running Bambuddy backend version. This meant the check could incorrectly report "up to date" even when the daemon was behind. Fixed by comparing directly against `APP_VERSION` from the backend config. diff --git a/frontend/src/components/SpoolFormModal.tsx b/frontend/src/components/SpoolFormModal.tsx index b6e2a2c70..89b789cf9 100644 --- a/frontend/src/components/SpoolFormModal.tsx +++ b/frontend/src/components/SpoolFormModal.tsx @@ -372,7 +372,7 @@ export function SpoolFormModal({ const deleteTagMutation = useMutation({ mutationFn: () => - api.updateSpool(spool!.id, { tag_uid: null } as Parameters[1]), + api.updateSpool(spool!.id, { tag_uid: null, tray_uuid: null, tag_type: null, data_origin: null } as Parameters[1]), onSuccess: async () => { await queryClient.invalidateQueries({ queryKey: ['inventory-spools'] }); showToast(t('inventory.tagDeleted', 'Tag removed'), 'success'); diff --git a/static/assets/index-BsSJ-PqL.js b/static/assets/index-CRbRFB2L.js similarity index 99% rename from static/assets/index-BsSJ-PqL.js rename to static/assets/index-CRbRFB2L.js index 4e44fcc04..ea902c973 100644 --- a/static/assets/index-BsSJ-PqL.js +++ b/static/assets/index-CRbRFB2L.js @@ -8712,7 +8712,7 @@ Accuracy: ${t.time_accuracy.toFixed(0)}%`:t.actual_time_seconds?`Actual: ${Bs(t. `+n+"]";if(typeof t=="object"){const r=Object.entries(t);return r.length===0?"{}":`{ `+r.map(([s,o])=>n+" "+JSON.stringify(s)+": "+CL(o,e+1)).join(`, `)+` -`+n+"}"}return String(t)}function ftt({setting:t,onClose:e,onDeleted:n,onDuplicate:r,onEdit:a,hasPermission:s,t:o}){const{showToast:l}=pn(),c=cn(),[d,u]=w.useState(!1),{data:m,isLoading:p}=et({queryKey:["cloudSettingDetail",t.setting_id],queryFn:()=>be.getCloudSettingDetail(t.setting_id)}),f=pt({mutationFn:()=>be.deleteCloudSetting(t.setting_id),onSuccess:()=>{l(o("profiles.presets.toast.deleted")),c.invalidateQueries({queryKey:["cloudSettings"]}),n()},onError:b=>l(b.message,"error")}),y=hw(t.setting_id),v=D5(t.name,m?.setting?.inherits);return i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:i.jsx(At,{className:"w-full max-w-3xl max-h-[90vh] flex flex-col overflow-hidden",children:i.jsxs(Et,{className:"p-0 flex flex-col min-h-0 flex-1",children:[i.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("h2",{className:"text-xl font-semibold text-white truncate",children:t.name}),y&&i.jsx("span",{className:"px-2 py-0.5 text-xs font-medium bg-bambu-green/20 text-bambu-green rounded-full",children:o("profiles.presets.editable")})]}),i.jsxs("div",{className:"flex items-center gap-2 mt-1 text-sm text-bambu-gray",children:[i.jsx("span",{className:"capitalize",children:o(`profiles.presets.types.${t.type}`)}),v.printer&&i.jsxs(i.Fragment,{children:[i.jsx("span",{children:"•"}),i.jsx("span",{children:v.printer})]})]})]}),i.jsx("button",{onClick:e,className:"p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:i.jsx(qt,{className:"w-5 h-5"})})]}),i.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto p-4",children:p?i.jsx("div",{className:"flex items-center justify-center py-16",children:i.jsx(ft,{className:"w-8 h-8 text-bambu-green animate-spin"})}):m?i.jsx("pre",{className:"text-xs text-bambu-gray font-mono whitespace-pre-wrap break-all bg-bambu-dark p-4 rounded-lg border border-bambu-dark-tertiary overflow-x-auto max-w-full",children:CL(m)}):i.jsx("div",{className:"text-center py-16 text-bambu-gray",children:o("profiles.presets.failedToLoadDetails")})}),d?i.jsxs("div",{className:"flex-shrink-0 p-4 border-t border-bambu-dark-tertiary bg-red-500/5",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3 text-red-400",children:[i.jsx(jn,{className:"w-5 h-5"}),i.jsx("span",{className:"font-medium",children:o("profiles.presets.deleteConfirm")})]}),i.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:o("profiles.presets.deleteWarning",{name:t.name})}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Ie,{variant:"secondary",onClick:()=>u(!1),disabled:f.isPending,className:"flex-1",children:o("common.cancel")}),i.jsxs(Ie,{variant:"danger",onClick:()=>f.mutate(),disabled:f.isPending,className:"flex-1",children:[f.isPending?i.jsx(ft,{className:"w-4 h-4 animate-spin"}):i.jsx(an,{className:"w-4 h-4"}),o("common.delete")]})]})]}):i.jsx("div",{className:"flex-shrink-0 p-4 border-t border-bambu-dark-tertiary",children:i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Ie,{variant:"secondary",onClick:e,className:"flex-1",children:o("common.close")}),i.jsxs(Ie,{variant:"secondary",onClick:r,disabled:!s("cloud:auth"),title:s("cloud:auth")?void 0:o("profiles.presets.noDuplicatePermission"),children:[i.jsx(To,{className:"w-4 h-4"}),o("profiles.presets.duplicate")]}),y&&i.jsxs(i.Fragment,{children:[i.jsxs(Ie,{variant:"secondary",onClick:a,disabled:p||!m||!s("cloud:auth"),title:s("cloud:auth")?void 0:o("profiles.presets.noEditPermission"),children:[i.jsx(Xi,{className:"w-4 h-4"}),o("common.edit")]}),i.jsx(Ie,{variant:"danger",onClick:()=>u(!0),disabled:!s("cloud:auth"),title:s("cloud:auth")?void 0:o("profiles.presets.noDeletePermission"),children:i.jsx(an,{className:"w-4 h-4"})})]})]})})]})})})}function Xoe(){try{const t=localStorage.getItem("bambusy_preset_templates");return t?JSON.parse(t):[]}catch{return[]}}function Qoe(t){localStorage.setItem("bambusy_preset_templates",JSON.stringify(t))}function gtt({onClose:t,onApply:e,t:n}){const{showToast:r}=pn(),[a,s]=w.useState(Xoe),[o,l]=w.useState("all"),[c,d]=w.useState(null),[u,m]=w.useState(""),[p,f]=w.useState(""),[y,v]=w.useState("{}"),[b,g]=w.useState(null),[_,k]=w.useState(null),C=o==="all"?a:a.filter(Z=>Z.type===o),N=Z=>{s(Z),Qoe(Z)},P=Z=>{const I=a.filter(ee=>ee.id!==Z);N(I),k(null),r(n("profiles.templates.toast.deleted"))},T=Z=>{d(Z.id),m(Z.name),f(Z.description),v(JSON.stringify(Z.settings,null,2)),g(null)},j=()=>{if(!(!c||!u.trim()))try{const Z=JSON.parse(y),I=a.map(ee=>ee.id===c?{...ee,name:u.trim(),description:p.trim(),settings:Z}:ee);N(I),d(null),r(n("profiles.templates.toast.updated"))}catch(Z){g(Z.message)}},A=()=>{d(null),m(""),f(""),v("{}"),g(null)},F=Z=>{const I=a.map(ee=>ee.id===Z?{...ee,showInModal:!ee.showInModal}:ee);N(I)},G={filament:{label:n("profiles.presets.types.filament"),icon:iT,color:"text-amber-400"},print:{label:n("profiles.presets.types.process"),icon:yd,color:"text-blue-400"},printer:{label:n("profiles.presets.types.printer"),icon:_r,color:"text-purple-400"}},z=_?a.find(Z=>Z.id===_):null;return w.useEffect(()=>{const Z=I=>{I.key==="Escape"&&(_?k(null):c?A():t())};return window.addEventListener("keydown",Z),()=>window.removeEventListener("keydown",Z)},[_,c,t]),i.jsxs("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:[z&&i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-60",children:i.jsx(At,{className:"w-full max-w-md",children:i.jsxs(Et,{className:"p-6",children:[i.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[i.jsx("div",{className:"p-2 bg-red-500/20 rounded-lg",children:i.jsx(jn,{className:"w-6 h-6 text-red-400"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-lg font-semibold text-white",children:n("profiles.templates.deleteTitle")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:n("profiles.templates.deleteWarning")})]})]}),i.jsx("p",{className:"text-white mb-6",children:n("profiles.templates.deleteConfirm",{name:z.name})}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Ie,{variant:"secondary",onClick:()=>k(null),className:"flex-1",children:n("common.cancel")}),i.jsxs(Ie,{onClick:()=>P(_),className:"flex-1 bg-red-500 hover:bg-red-600",children:[i.jsx(an,{className:"w-4 h-4"}),n("common.delete")]})]})]})})}),i.jsx(At,{className:"w-full max-w-2xl max-h-[80vh] flex flex-col",children:i.jsxs(Et,{className:"p-0 flex flex-col h-full",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(fx,{className:"w-5 h-5 text-amber-400"}),n("profiles.templates.title")]}),i.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white",children:i.jsx(qt,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:"flex items-center gap-2 p-4 border-b border-bambu-dark-tertiary",children:[i.jsx("span",{className:"text-sm text-bambu-gray",children:n("profiles.templates.typeFilter")}),["all","filament","print","printer"].map(Z=>i.jsx("button",{onClick:()=>l(Z),className:`px-3 py-1 text-sm rounded-lg transition-colors ${o===Z?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:Z==="all"?n("common.all"):G[Z].label},Z))]}),i.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:C.length===0?i.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[i.jsx(fx,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),i.jsx("p",{children:n("profiles.templates.noTemplates")}),i.jsx("p",{className:"text-sm mt-1",children:n("profiles.templates.createFirst")})]}):i.jsx("div",{className:"space-y-2",children:C.map(Z=>{const I=G[Z.type],ee=I.icon;return c===Z.id?i.jsxs("div",{className:"p-4 bg-bambu-dark rounded-lg border border-bambu-green",children:[i.jsxs("div",{className:"grid grid-cols-2 gap-3 mb-3",children:[i.jsx("input",{type:"text",value:u,onChange:ae=>m(ae.target.value),placeholder:n("profiles.templates.namePlaceholder"),className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",autoFocus:!0}),i.jsx("input",{type:"text",value:p,onChange:ae=>f(ae.target.value),placeholder:n("profiles.templates.descriptionPlaceholder"),className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{className:"mb-3",children:[i.jsx("label",{className:"text-xs text-bambu-gray mb-1 block",children:n("profiles.templates.settingsJson")}),i.jsx("textarea",{value:y,onChange:ae=>{v(ae.target.value),g(null)},rows:6,className:`w-full px-3 py-2 bg-bambu-dark-secondary border rounded text-white text-sm font-mono focus:outline-none ${b?"border-red-500":"border-bambu-dark-tertiary focus:border-bambu-green"}`}),b&&i.jsx("p",{className:"text-xs text-red-400 mt-1",children:b})]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs(Ie,{size:"sm",onClick:j,disabled:!u.trim(),children:[i.jsx(as,{className:"w-4 h-4"}),"Save"]}),i.jsx(Ie,{size:"sm",variant:"secondary",onClick:A,children:"Cancel"})]})]},Z.id):i.jsxs("div",{className:"flex items-center gap-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary hover:border-bambu-gray-dark transition-colors",children:[i.jsx(ee,{className:`w-5 h-5 ${I.color} flex-shrink-0`}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("p",{className:"text-sm font-medium text-white",children:Z.name}),i.jsx("p",{className:"text-xs text-bambu-gray truncate",children:Z.description})]}),i.jsx("span",{className:"text-xs text-bambu-gray-dark px-2 py-1 bg-bambu-dark-secondary rounded",children:n("profiles.templates.fieldsCount",{count:Object.keys(Z.settings).length})}),i.jsx("button",{onClick:()=>F(Z.id),className:`p-1 transition-colors ${Z.showInModal?"text-bambu-green hover:text-bambu-green/70":"text-bambu-gray hover:text-white"}`,title:Z.showInModal?n("profiles.templates.shownInModals"):n("profiles.templates.hiddenInModals"),children:Z.showInModal?i.jsx(Pc,{className:"w-4 h-4"}):i.jsx(xw,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>e(Z),className:"px-3 py-1 text-xs bg-bambu-green/20 text-bambu-green rounded hover:bg-bambu-green/30 transition-colors",children:n("profiles.templates.apply")}),i.jsx("button",{onClick:()=>T(Z),className:"p-1 text-bambu-gray hover:text-white",title:n("common.edit"),children:i.jsx(Xi,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>k(Z.id),className:"p-1 text-bambu-gray hover:text-red-400",title:n("common.delete"),children:i.jsx(an,{className:"w-4 h-4"})})]},Z.id)})})})]})})]})}function Zoe({onClose:t,leftPreset:e,rightPreset:n,leftLabel:r,rightLabel:a,t:s}){const[o,l]=w.useState("changes"),[c,d]=w.useState(""),u=w.useMemo(()=>{const y=new Set([...Object.keys(e),...Object.keys(n)]),v=[];for(const b of y){if(b==="inherits"||b==="version")continue;const g=e[b],_=n[b],k=b in e,C=b in n;let N;!k&&C?N="added":k&&!C?N="removed":JSON.stringify(g)!==JSON.stringify(_)?N="changed":N="same",v.push({key:b,left:g,right:_,status:N})}return v.sort((b,g)=>{const _={changed:0,added:1,removed:2,same:3};return _[b.status]!==_[g.status]?_[b.status]-_[g.status]:b.key.localeCompare(g.key)})},[e,n]),m=w.useMemo(()=>{let y=[...u];if(o==="changes"&&(y=y.filter(v=>v.status!=="same")),c){const v=c.toLowerCase();y=y.filter(b=>b.key.toLowerCase().includes(v)||String(b.left).toLowerCase().includes(v)||String(b.right).toLowerCase().includes(v))}return y},[u,o,c]),p=w.useMemo(()=>({added:u.filter(y=>y.status==="added").length,removed:u.filter(y=>y.status==="removed").length,changed:u.filter(y=>y.status==="changed").length,same:u.filter(y=>y.status==="same").length}),[u]),f=y=>{if(y===void 0)return"—";if(y===null)return"null";if(Array.isArray(y))return y.length===0?"[]":y.length===1?String(y[0]):y.join(", ");if(typeof y=="object")return JSON.stringify(y);const v=String(y);if(v.includes("\\n")||v.length>100){const b=v.split("\\n").length;if(b>1)return`[${b} lines of G-code/script]`;if(v.length>100)return v.substring(0,100)+"…"}return v};return w.useEffect(()=>{const y=v=>{v.key==="Escape"&&t()};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[t]),i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsx(At,{className:"w-full max-w-4xl max-h-[85vh] flex flex-col overflow-hidden",children:i.jsxs(Et,{className:"p-0 flex flex-col min-h-0 flex-1",children:[i.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Kb,{className:"w-5 h-5 text-blue-400"}),s("profiles.diff.title")]}),i.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white",children:i.jsx(qt,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:"flex-shrink-0 grid grid-cols-2 gap-4 p-4 border-b border-bambu-dark-tertiary bg-bambu-dark",children:[i.jsxs("div",{className:"text-center",children:[i.jsx("span",{className:"text-sm text-bambu-gray",children:s("profiles.diff.left")}),i.jsx("p",{className:"text-white font-medium truncate",children:r})]}),i.jsxs("div",{className:"text-center",children:[i.jsx("span",{className:"text-sm text-bambu-gray",children:s("profiles.diff.right")}),i.jsx("p",{className:"text-white font-medium truncate",children:a})]})]}),i.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[i.jsxs("span",{className:"flex items-center gap-1 text-green-400",children:[i.jsx(ir,{className:"w-3.5 h-3.5"}),p.added," ",s("profiles.diff.added")]}),i.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[i.jsx(Uk,{className:"w-3.5 h-3.5"}),p.removed," ",s("profiles.diff.removed")]}),i.jsxs("span",{className:"flex items-center gap-1 text-amber-400",children:[i.jsx(S3,{className:"w-3.5 h-3.5"}),p.changed," ",s("profiles.diff.changed")]}),i.jsxs("span",{className:"flex items-center gap-1 text-bambu-gray",children:[i.jsx(QM,{className:"w-3.5 h-3.5"}),p.same," ",s("profiles.diff.same")]})]}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs("div",{className:"relative",children:[i.jsx(Fr,{className:"absolute left-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:c,onChange:y=>d(y.target.value),placeholder:s("profiles.diff.searchFields"),className:"pl-8 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none w-48"})]}),p.same>0&&i.jsxs("div",{className:"flex rounded overflow-hidden border border-bambu-dark-tertiary",children:[i.jsx("button",{onClick:()=>l("changes"),className:`px-3 py-1.5 text-sm transition-colors ${o==="changes"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:s("profiles.diff.changes")}),i.jsx("button",{onClick:()=>l("all"),className:`px-3 py-1.5 text-sm transition-colors ${o==="all"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:s("common.all")})]})]})]}),i.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:m.length===0?i.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[i.jsx(QM,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),i.jsx("p",{children:s(o==="changes"?"profiles.diff.noDifferences":"profiles.diff.noFieldsMatch")})]}):i.jsxs("table",{className:"w-full",children:[i.jsx("thead",{className:"sticky top-0 bg-bambu-dark-secondary",children:i.jsxs("tr",{className:"text-sm text-bambu-gray border-b border-bambu-dark-tertiary",children:[i.jsx("th",{className:"text-left p-3 w-1/3",children:s("profiles.diff.field")}),i.jsx("th",{className:"text-left p-3 w-1/3",children:r}),i.jsx("th",{className:"text-left p-3 w-1/3",children:a})]})}),i.jsx("tbody",{children:m.map(y=>{const v={added:"bg-green-500/10",removed:"bg-red-500/10",changed:"bg-amber-500/10",same:""}[y.status],b={added:i.jsx(ir,{className:"w-3.5 h-3.5 text-green-400"}),removed:i.jsx(Uk,{className:"w-3.5 h-3.5 text-red-400"}),changed:i.jsx(S3,{className:"w-3.5 h-3.5 text-amber-400"}),same:i.jsx(QM,{className:"w-3.5 h-3.5 text-bambu-gray-dark"})}[y.status];return i.jsxs("tr",{className:`border-b border-bambu-dark-tertiary ${v}`,children:[i.jsx("td",{className:"p-3",children:i.jsxs("div",{className:"flex items-center gap-2",children:[b,i.jsx("span",{className:"text-sm text-white font-mono",children:y.key})]})}),i.jsx("td",{className:"p-3",children:i.jsx("span",{className:`text-sm font-mono break-all ${y.status==="removed"?"text-red-300":y.status==="changed"?"text-white":"text-bambu-gray"}`,children:f(y.left)})}),i.jsx("td",{className:"p-3",children:i.jsx("span",{className:`text-sm font-mono break-all ${y.status==="added"?"text-green-300":y.status==="changed"?"text-white":"text-bambu-gray"}`,children:f(y.right)})})]},y.key)})})]})})]})})})}function btt({onClose:t,initialData:e,allPresets:n,t:r}){const{showToast:a}=pn(),s=cn(),o=!!e?.setting_id,[l,c]=w.useState("common"),[d,u]=w.useState(e?.type||"filament"),[m,p]=w.useState(e?.name?o?e.name:`${e.name} (Copy)`:""),[f,y]=w.useState(e?.base_id||""),[v,b]=w.useState(""),[g,_]=w.useState(e?.setting||{inherits:""}),[k,C]=w.useState(JSON.stringify(e?.setting||{inherits:""},null,2)),[N,P]=w.useState(null),[T,j]=w.useState(""),[A,F]=w.useState(!1),[G,z]=w.useState(""),[Z,I]=w.useState(!1),[ee,ae]=w.useState(Xoe),[X,ce]=w.useState(!1),[ue,pe]=w.useState(""),[K,se]=w.useState(""),[de,ge]=w.useState(!0),[Te,V]=w.useState(null),[J,D]=w.useState(!1),E=w.useMemo(()=>({filament:n.filament,print:n.process,printer:n.printer})[d]||[],[n,d]),U=w.useMemo(()=>E.filter(Ae=>hw(Ae.setting_id)),[E]),{data:W}=et({queryKey:["cloudFields",d],queryFn:()=>be.getCloudFields(d==="print"?"process":d),staleTime:1e3*60*60}),{data:B}=et({queryKey:["allPresetDetails",d,U.map(Ae=>Ae.setting_id).join(",")],queryFn:async()=>{const Ae={};for(let De=0;De{try{const Pe=await be.getCloudSettingDetail(Ke.setting_id);return{id:Ke.setting_id,detail:Pe}}catch{return null}}))).forEach(Ke=>{Ke&&(Ae[Ke.id]=Ke.detail)})}return Ae},enabled:U.length>0,staleTime:1e3*60*10}),{data:ie,isLoading:O}=et({queryKey:["cloudSettingDetail",f],queryFn:()=>be.getCloudSettingDetail(f),enabled:!!f});w.useEffect(()=>{l!=="json"&&C(JSON.stringify(g,null,2))},[g,l]);const $=w.useMemo(()=>({filament:n.filament,print:n.process,printer:n.printer}[d]||[]).filter(Be=>!hw(Be.setting_id)).sort((Be,De)=>Be.name.localeCompare(De.name)),[n,d]);w.useEffect(()=>{if(!f)return;const Ae=$.find(Be=>Be.setting_id===f);Ae&&(b(Ae.name),o||(_({inherits:Ae.name}),C(JSON.stringify({inherits:Ae.name},null,2))))},[f,$,o]);const Y=w.useMemo(()=>{const Ae=W?.fields||[],Be=new Set(Ae.map(Ke=>Ke.key)),De=new Set,We=new Set(["inherits","updated_time","compatible_printers","compatible_prints"]);B&&Object.values(B).forEach(Ke=>{Ke?.setting&&Object.keys(Ke.setting).forEach(Pe=>{!Be.has(Pe)&&!We.has(Pe)&&De.add(Pe)})}),Object.keys(g).forEach(Ke=>{!Be.has(Ke)&&!We.has(Ke)&&De.add(Ke)});const ye=Array.from(De).sort().map(Ke=>({key:Ke,label:Ke.replace(/_/g," ").replace(/\b\w/g,Pe=>Pe.toUpperCase()),type:"text",category:"discovered",description:r("profiles.presets.discoveredFromPresets")}));return[...Ae,...ye]},[W,B,g,r]),q=Y.filter(Ae=>Ae.label.toLowerCase().includes(T.toLowerCase())||Ae.key.toLowerCase().includes(T.toLowerCase())),te=()=>{if(G.trim()){const Ae=G.trim().toLowerCase().replace(/\s+/g,"_");oe(Ae,""),z(""),I(!1),a(r("profiles.presets.toast.fieldAdded",{key:Ae}))}},oe=(Ae,Be)=>{_(De=>{const We={...De};return Be===""||Be===void 0?delete We[Ae]:We[Ae]=Be,We})},he=Ae=>{_(Be=>({...Be,...Ae.settings})),V(Ae.name),a(r("profiles.templates.toast.applied"))},fe=()=>{if(!ue.trim())return;const Ae={...g};if(delete Ae.inherits,Object.keys(Ae).length===0){a(r("profiles.presets.noOverridesToSave"),"error");return}const Be={id:Date.now().toString(),name:ue.trim(),description:K.trim()||r("profiles.presets.customTemplate"),type:d,settings:Ae,showInModal:de},De=[...ee,Be];ae(De),Qoe(De),ce(!1),pe(""),se(""),ge(!0),a(r("profiles.templates.toast.created"))},re=w.useMemo(()=>ee.filter(Ae=>Ae.type===d&&Ae.showInModal),[d,ee]),L=Ae=>{C(Ae);try{const Be=JSON.parse(Ae);_(Be),P(null)}catch(Be){P(Be.message)}},R=Ae=>{Ae.preventDefault(),F(!1);const Be=Ae.dataTransfer.files[0];if(Be&&Be.name.endsWith(".json")){const De=new FileReader;De.onload=We=>{try{const ye=We.target?.result,Ke=JSON.parse(ye),Pe=Ke.setting||Ke;_(Ye=>({...Ye,...Pe})),C(JSON.stringify({...g,...Pe},null,2)),a(r("profiles.presets.fileImported"))}catch{a(r("profiles.presets.invalidJsonFile"),"error")}},De.readAsText(Be)}},ne=pt({mutationFn:()=>{const Ae={...g},Be=d==="filament"?"filament_settings_id":d==="print"?"print_settings_id":"printer_settings_id";Ae[Be]=`"${m}"`;const De={type:d,name:m,base_id:f,setting:Ae};return be.createCloudSetting(De)},onSuccess:async()=>{a(r("profiles.presets.toast.created")),await s.refetchQueries({queryKey:["cloudSettings"]}),t()},onError:Ae=>a(Ae.message,"error")}),ve=pt({mutationFn:()=>{if(!e?.setting_id)throw new Error(r("profiles.presets.noSettingId"));return be.updateCloudSetting(e.setting_id,{name:m,setting:g})},onSuccess:async()=>{a(r("profiles.presets.toast.updated")),s.removeQueries({queryKey:["cloudSettingDetail"]}),await s.refetchQueries({queryKey:["cloudSettings"]}),t()},onError:Ae=>a(Ae.message,"error")}),we=o?ve:ne,me=ie?.setting?.inherits,Me=me?$.find(Ae=>Ae.name===me):void 0,{data:xe}=et({queryKey:["cloudSettingDetail",Me?.setting_id],queryFn:()=>be.getCloudSettingDetail(Me.setting_id),enabled:!!Me?.setting_id}),je=w.useMemo(()=>{const Ae=xe?.setting||{},Be=ie?.setting||{},De=f&&B?.[f]?.setting?B[f].setting:{};return{...Ae,...Be,...De}},[f,ie,xe,B]),He=Ae=>{if(Ae==null)return"";if(Array.isArray(Ae)){const Be=[...new Set(Ae.map(De=>String(De)))];return Be.length===1?Be[0]:Ae.join(", ")}return String(Ae)},Oe=Ae=>{const Be=g[Ae.key],De=je[Ae.key],We=He(De),ye=O?r("common.loading"):We||"",Ke="w-full px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none";if(Ae.type==="boolean"){const Pe=Be==="1"||Be===void 0&&De==="1";return i.jsx("button",{type:"button",onClick:()=>oe(Ae.key,Be==="1"?"0":"1"),className:`w-8 h-5 rounded-full transition-colors ${Pe?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,children:i.jsx("div",{className:`w-4 h-4 rounded-full bg-white shadow transition-transform ${Pe?"translate-x-3.5":"translate-x-0.5"}`})})}return Ae.type==="select"?i.jsxs("select",{value:Be||"",onChange:Pe=>oe(Ae.key,Pe.target.value),className:Ke,children:[i.jsx("option",{value:"",children:ye}),Ae.options?.map(Pe=>i.jsx("option",{value:Pe.value,children:Pe.label},Pe.value))]}):i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:Ae.type==="number"?"number":"text",value:Be!==void 0?String(Be):"",onChange:Pe=>oe(Ae.key,Pe.target.value),step:Ae.step,min:Ae.min,max:Ae.max,placeholder:ye,className:Ke}),Ae.unit&&i.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:Ae.unit})]})},_e=w.useMemo(()=>ie?.setting?ie.setting:{},[ie]);return i.jsxs("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onDragOver:Ae=>{Ae.preventDefault(),F(!0)},onDragLeave:()=>F(!1),onDrop:R,children:[J&&f&&i.jsx(Zoe,{onClose:()=>D(!1),leftPreset:_e,rightPreset:g,leftLabel:r("profiles.presets.baseLabel",{name:v||f}),rightLabel:r("profiles.presets.currentLabel",{name:m||r("profiles.presets.newPreset")}),t:r}),i.jsx(At,{className:"w-full max-w-6xl max-h-[90vh] flex flex-col overflow-y-auto",children:i.jsxs(Et,{className:"p-0 flex flex-col h-full",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("h2",{className:"text-xl font-semibold text-white",children:r(o?"profiles.presets.editPreset":e?"profiles.presets.duplicatePreset":"profiles.presets.createNewPreset")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:r("profiles.presets.customizeSettings")})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[f&&i.jsxs("button",{onClick:()=>D(!0),className:"flex items-center gap-2 px-3 py-2 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors",title:r("profiles.presets.compareWithBase"),children:[i.jsx(Kb,{className:"w-4 h-4"}),r("profiles.presets.compare")]}),i.jsx("button",{onClick:t,className:"p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:i.jsx(qt,{className:"w-5 h-5"})})]})]}),A&&i.jsx("div",{className:"absolute inset-0 bg-bambu-green/10 border-2 border-dashed border-bambu-green rounded-lg flex items-center justify-center z-10",children:i.jsxs("div",{className:"text-center",children:[i.jsx(vi,{className:"w-12 h-12 text-bambu-green mx-auto mb-2"}),i.jsx("p",{className:"text-bambu-green font-medium",children:r("profiles.presets.dropJsonToImport")})]})}),i.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary space-y-3",children:[i.jsxs("div",{className:"grid grid-cols-3 gap-4 max-[640px]:grid-cols-1",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("common.type")}),i.jsxs("select",{value:d,onChange:Ae=>{u(Ae.target.value),y("")},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[i.jsx("option",{value:"filament",children:r("profiles.presets.types.filament")}),i.jsx("option",{value:"print",children:r("profiles.presets.types.process")}),i.jsx("option",{value:"printer",children:r("profiles.presets.types.printer")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("profiles.presets.basePreset")}),i.jsxs("select",{value:f,onChange:Ae=>y(Ae.target.value),className:"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",children:[i.jsx("option",{value:"",children:r("profiles.presets.selectBasePreset")}),$.map(Ae=>i.jsx("option",{value:Ae.setting_id,children:Ae.name},Ae.setting_id))]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("profiles.presets.presetName")}),i.jsx("input",{type:"text",value:m,onChange:Ae=>p(Ae.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",placeholder:r("profiles.presets.myCustomPreset")})]})]}),v&&i.jsx("div",{className:"text-xs text-bambu-gray",children:i.jsxs("p",{className:"flex items-center gap-1",children:[i.jsx(Zr,{className:"w-3 h-3 text-bambu-green"}),r("profiles.presets.inheritsFrom")," ",i.jsx("span",{className:"text-white",children:v}),O&&i.jsx(ft,{className:"w-3 h-3 animate-spin ml-1"})]})})]}),i.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary max-[640px]:flex-wrap max-[640px]:items-center",children:[i.jsxs("button",{onClick:()=>c("common"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${l==="common"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[i.jsx(J8,{className:"w-4 h-4"}),r("profiles.presets.tabs.common")]}),i.jsxs("button",{onClick:()=>c("fields"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${l==="fields"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[i.jsx(oT,{className:"w-4 h-4"}),r("profiles.presets.tabs.allFields")]}),i.jsxs("button",{onClick:()=>c("json"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${l==="json"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[i.jsx(XX,{className:"w-4 h-4"}),"JSON",N&&i.jsx(Oi,{className:"w-3 h-3 text-red-400"})]}),i.jsx("div",{className:"flex-1 max-[640px]:hidden"}),i.jsxs("button",{onClick:()=>{const Ae={name:m,type:d,base_id:f,setting:g},Be=new Blob([JSON.stringify(Ae,null,2)],{type:"application/json"}),De=URL.createObjectURL(Be),We=document.createElement("a");We.href=De,We.download=`${m||"preset"}.json`,document.body.appendChild(We),We.click(),document.body.removeChild(We),URL.revokeObjectURL(De),a(r("profiles.presets.toast.exported"))},className:"flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors",title:r("profiles.presets.exportToJson"),children:[i.jsx(fi,{className:"w-4 h-4"}),r("common.download")]}),i.jsxs("button",{onClick:()=>document.getElementById("file-import")?.click(),className:"flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors",title:r("profiles.presets.importFromJson"),children:[i.jsx(vi,{className:"w-4 h-4"}),r("common.upload")]}),i.jsx("input",{id:"file-import",type:"file",accept:".json",className:"hidden",onChange:Ae=>{const Be=Ae.target.files?.[0];if(Be){const De=new FileReader;De.onload=We=>{try{const ye=JSON.parse(We.target?.result),Ke=ye.setting||ye;_(Pe=>({...Pe,...Ke})),a(r("profiles.presets.fileImported"))}catch{a(r("profiles.presets.invalidJson"),"error")}},De.readAsText(Be)}}})]}),i.jsxs("div",{className:"flex-1 p-4",children:[l==="common"&&i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:[i.jsx(fx,{className:"w-4 h-4 text-amber-400"}),r("profiles.templates.title")]}),Object.keys(g).filter(Ae=>Ae!=="inherits").length>0&&i.jsxs("button",{onClick:()=>ce(!X),className:"text-xs text-bambu-gray hover:text-white flex items-center gap-1 transition-colors",children:[i.jsx(as,{className:"w-3 h-3"}),r("profiles.presets.saveAsTemplate")]})]}),X&&i.jsxs("div",{className:"mb-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"grid grid-cols-2 gap-2 mb-2",children:[i.jsx("input",{type:"text",value:ue,onChange:Ae=>pe(Ae.target.value),placeholder:r("profiles.templates.namePlaceholder"),className:"px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",autoFocus:!0}),i.jsx("input",{type:"text",value:K,onChange:Ae=>se(Ae.target.value),placeholder:r("profiles.templates.descriptionPlaceholder"),className:"px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex gap-2",children:[i.jsxs(Ie,{size:"sm",onClick:fe,disabled:!ue.trim(),children:[i.jsx(as,{className:"w-3 h-3"}),r("common.save")]}),i.jsx(Ie,{size:"sm",variant:"secondary",onClick:()=>ce(!1),children:r("common.cancel")})]}),i.jsxs("button",{onClick:()=>ge(!de),className:`flex items-center gap-1.5 text-xs transition-colors ${de?"text-bambu-green":"text-bambu-gray hover:text-white"}`,children:[de?i.jsx(Pc,{className:"w-3.5 h-3.5"}):i.jsx(xw,{className:"w-3.5 h-3.5"}),r(de?"profiles.templates.shownInModals":"profiles.templates.hiddenInModals")]})]})]}),Te&&i.jsxs("div",{className:"mb-3 px-3 py-2 bg-bambu-green/10 border border-bambu-green/30 rounded-lg flex items-center gap-2",children:[i.jsx(Zr,{className:"w-4 h-4 text-bambu-green"}),i.jsxs("span",{className:"text-sm text-bambu-green",children:[r("profiles.presets.templateApplied")," ",i.jsx("span",{className:"font-medium",children:Te})]}),i.jsx("button",{onClick:()=>V(null),className:"ml-auto text-bambu-green/70 hover:text-bambu-green",children:i.jsx(qt,{className:"w-4 h-4"})})]}),i.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[re.map(Ae=>i.jsxs("button",{onClick:()=>he(Ae),className:"p-3 text-left bg-bambu-dark border border-bambu-dark-tertiary rounded-lg hover:border-bambu-gray-dark transition-colors",children:[i.jsx("p",{className:"text-sm font-medium text-white",children:Ae.name}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:Ae.description})]},Ae.id)),re.length===0&&i.jsx("p",{className:"col-span-3 text-center text-bambu-gray text-sm py-4",children:r("profiles.presets.noTemplatesSelected")})]}),i.jsx("p",{className:"text-xs text-bambu-gray-dark mt-2 text-center",children:r("profiles.presets.manageTemplatesHint")})]}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:r("profiles.presets.commonSettings")}),i.jsx("div",{className:"grid grid-cols-2 gap-x-6 gap-y-3",children:Y.slice(0,10).map(Ae=>i.jsxs("div",{className:"flex items-center justify-between gap-4 max-[640px]:flex-col max-[640px]:items-start",children:[i.jsx("label",{className:"text-sm text-bambu-gray flex-shrink-0",children:Ae.label}),i.jsx("div",{className:"w-48 max-[640px]:w-full",children:Oe(Ae)})]},Ae.key))})]}),Object.keys(g).length>1&&i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:r("profiles.presets.currentOverrides")}),i.jsx("div",{className:"flex flex-wrap gap-2",children:Object.entries(g).filter(([Ae])=>Ae!=="inherits").map(([Ae,Be])=>i.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 bg-bambu-green/10 text-bambu-green text-xs rounded",children:[Ae,": ",String(Be).slice(0,20),i.jsx("button",{onClick:()=>oe(Ae,void 0),className:"hover:text-white",children:i.jsx(qt,{className:"w-3 h-3"})})]},Ae))})]})]}),l==="fields"&&i.jsxs("div",{className:"grid grid-cols-2 gap-6",style:{height:"400px"},children:[i.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3 flex-shrink-0",children:[i.jsx("h3",{className:"text-sm font-medium text-white",children:r("profiles.presets.availableFields")}),i.jsx("span",{className:"text-xs text-bambu-gray",children:B?r("profiles.templates.fieldsCount",{count:Y.length}):r("common.loading")})]}),i.jsxs("div",{className:"relative mb-3 flex-shrink-0",children:[i.jsx(Fr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:T,onChange:Ae=>j(Ae.target.value),placeholder:r("profiles.presets.searchFieldsPlaceholder"),className:"w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{className:"flex-1 overflow-y-auto space-y-1 pr-2 min-h-0",children:[q.filter(Ae=>!(Ae.key in g)).map(Ae=>{const Be=je[Ae.key],De=He(Be);return i.jsxs("div",{onClick:()=>{_(We=>({...We,[Ae.key]:De||""}))},className:"flex items-center justify-between gap-2 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors cursor-pointer group",children:[i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("p",{className:"text-sm text-white truncate",children:Ae.label}),i.jsx("p",{className:"text-xs text-bambu-gray-dark truncate",children:Ae.key})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[De&&i.jsxs("span",{className:"text-xs text-bambu-gray bg-bambu-dark px-2 py-0.5 rounded max-w-32 truncate",title:De,children:[De.slice(0,20),De.length>20?"...":""]}),i.jsx("div",{className:"w-6 h-6 flex items-center justify-center rounded bg-bambu-dark-tertiary group-hover:bg-bambu-green/20 transition-colors",children:i.jsx(ir,{className:"w-4 h-4 text-bambu-gray group-hover:text-bambu-green transition-colors"})})]})]},Ae.key)}),q.filter(Ae=>!(Ae.key in g)).length===0&&i.jsx("p",{className:"text-center text-bambu-gray py-4 text-sm",children:r(T?"profiles.presets.noMatchingFields":"profiles.presets.allFieldsAdded")})]}),i.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0",children:Z?i.jsxs("div",{className:"flex gap-2",children:[i.jsx("input",{type:"text",value:G,onChange:Ae=>z(Ae.target.value),onKeyDown:Ae=>Ae.key==="Enter"&&te(),placeholder:"custom_field_name",className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none",autoFocus:!0}),i.jsx(Ie,{size:"sm",onClick:te,disabled:!G.trim(),children:i.jsx(ir,{className:"w-4 h-4"})}),i.jsx(Ie,{size:"sm",variant:"secondary",onClick:()=>{I(!1),z("")},children:i.jsx(qt,{className:"w-4 h-4"})})]}):i.jsxs("button",{onClick:()=>I(!0),className:"w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors",children:[i.jsx(ir,{className:"w-4 h-4"}),r("profiles.presets.addCustomField")]})})]}),i.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3 flex-shrink-0",children:[i.jsx("h3",{className:"text-sm font-medium text-white",children:r("profiles.presets.yourOverrides")}),i.jsx("span",{className:"text-xs text-bambu-gray",children:r("profiles.templates.fieldsCount",{count:Object.keys(g).filter(Ae=>Ae!=="inherits").length})})]}),i.jsxs("div",{className:"flex-1 overflow-y-auto space-y-2 pr-2 min-h-0",children:[Object.entries(g).filter(([Ae])=>Ae!=="inherits").map(([Ae,Be])=>{const De=Y.find(We=>We.key===Ae);return i.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm font-medium text-white",children:De?.label||Ae}),i.jsx("p",{className:"text-xs text-bambu-gray-dark",children:Ae})]}),i.jsx("button",{onClick:()=>oe(Ae,void 0),className:"p-1 text-bambu-gray hover:text-red-400 transition-colors",children:i.jsx(qt,{className:"w-4 h-4"})})]}),De?Oe(De):i.jsx("input",{type:"text",value:String(Be),onChange:We=>oe(Ae,We.target.value),className:"w-full px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"})]},Ae)}),Object.keys(g).filter(Ae=>Ae!=="inherits").length===0&&i.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[i.jsx(J8,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),i.jsx("p",{className:"text-sm",children:r("profiles.presets.noOverridesYet")}),i.jsx("p",{className:"text-xs mt-1",children:r("profiles.presets.clickFieldsToAdd")})]})]}),Object.keys(g).filter(Ae=>Ae!=="inherits").length>0&&i.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0",children:i.jsxs("button",{onClick:()=>{ce(!0),c("common")},className:"w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors",children:[i.jsx(as,{className:"w-4 h-4"}),r("profiles.presets.saveAsTemplate")]})})]})]}),l==="json"&&i.jsxs("div",{className:"space-y-2",children:[N&&i.jsxs("div",{className:"flex items-center gap-2 text-red-400 text-sm",children:[i.jsx(Oi,{className:"w-4 h-4"}),N]}),i.jsx("textarea",{value:k,onChange:Ae=>L(Ae.target.value),className:`w-full h-80 px-3 py-2 bg-bambu-dark border rounded-lg text-white text-xs font-mono focus:outline-none resize-none ${N?"border-red-500 focus:border-red-500":"border-bambu-dark-tertiary focus:border-bambu-green"}`,spellCheck:!1}),i.jsx("p",{className:"text-xs text-bambu-gray",children:r("profiles.presets.jsonTip")})]})]}),i.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex gap-2",children:[i.jsx(Ie,{variant:"secondary",onClick:t,className:"flex-1",children:r("common.cancel")}),i.jsxs(Ie,{onClick:()=>we.mutate(),disabled:we.isPending||!m.trim()||!o&&!f||!!N,className:"flex-1",children:[we.isPending?i.jsx(ft,{className:"w-4 h-4 animate-spin"}):o?i.jsx(as,{className:"w-4 h-4"}):i.jsx(ir,{className:"w-4 h-4"}),r(o?"common.save":e?"common.duplicate":"common.create")]})]})]})})]})}function xtt({settings:t,lastSyncTime:e,onRefresh:n,isRefreshing:r,printers:a,hasPermission:s,t:o}){const[l,c]=w.useState(""),[d,u]=w.useState("all"),[m,p]=w.useState("all"),[f,y]=w.useState("all"),[v,b]=w.useState("all"),[g,_]=w.useState("all"),[k,C]=w.useState("all"),[N,P]=w.useState(null),[T,j]=w.useState(!1),[A,F]=w.useState(!1),[G,z]=w.useState(null),[Z,I]=w.useState(null),[ee,ae]=w.useState(null),[X,ce]=w.useState(!1),[ue,pe]=w.useState([null,null]),[K,se]=w.useState(!1),[de,ge]=w.useState(null),Te=cn(),V=w.useMemo(()=>[...t.filament.map(te=>({...te,type:"filament"})),...t.printer.map(te=>({...te,type:"printer"})),...t.process.map(te=>({...te,type:"process"}))].map(te=>({...te,meta:D5(te.name)})),[t]),J=w.useMemo(()=>{const q=new Set,te=new Set,oe=new Set;return V.forEach(he=>{he.meta.nozzle&&q.add(he.meta.nozzle),he.meta.filamentType&&te.add(he.meta.filamentType),he.meta.layerHeight&&oe.add(he.meta.layerHeight)}),{printers:a.map(he=>({id:he.id.toString(),name:he.name})),nozzles:Array.from(q).sort((he,fe)=>parseFloat(he)-parseFloat(fe)),filaments:Array.from(te).sort(),layerHeights:Array.from(oe).sort((he,fe)=>parseFloat(he)-parseFloat(fe))}},[V,a]),D=w.useMemo(()=>f==="all"?null:a.find(te=>te.id.toString()===f)?.model||null,[f,a]),E=w.useMemo(()=>V.filter(q=>d==="all"||q.type===d).filter(q=>{if(m==="all")return!0;const te=hw(q.setting_id);return m==="custom"?te:!te}).filter(q=>{if(f==="all"||!D)return!0;const te=q.meta.printer?.toLowerCase()||"",oe=D.toLowerCase();return te.includes(oe)||oe.includes(te)}).filter(q=>v==="all"||q.meta.nozzle===v).filter(q=>g==="all"||q.meta.filamentType===g).filter(q=>k==="all"||q.meta.layerHeight===k).filter(q=>l===""||q.name.toLowerCase().includes(l.toLowerCase())).sort((q,te)=>q.name.localeCompare(te.name)),[V,d,m,f,D,v,g,k,l]),U=q=>{if(X){const te=ue[0]?.setting_id===q.setting_id,oe=ue[1]?.setting_id===q.setting_id;if(te)pe([ue[1],null]);else if(oe)pe([ue[0],null]);else if(!ue[0])pe([q,null]);else if(ue[1]){if(ue[0].type!==q.type)return;pe([ue[0],q])}else{if(ue[0].type!==q.type)return;pe([ue[0],q])}}else P(q)},W=q=>{if(ue[0]?.setting_id===q.setting_id)return 0;if(ue[1]?.setting_id===q.setting_id)return 1},B=async q=>{try{const te=await be.getCloudSettingDetail(q.setting_id),oe=q.type==="process"?"print":q.type;z({type:oe,name:q.name,base_id:te.base_id||"GFSA00",setting:te.setting||{}}),P(null)}catch(te){console.error("Failed to fetch preset details for duplication:",te)}},ie=async q=>{try{Te.removeQueries({queryKey:["cloudSettingDetail",q.setting_id]});const te=await be.getCloudSettingDetail(q.setting_id),oe=q.type==="process"?"print":q.type;I({type:oe,name:q.name,base_id:te.base_id||"GFSA00",setting:te.setting||{},setting_id:q.setting_id}),P(null)}catch(te){console.error("Failed to fetch preset details for editing:",te)}},O=()=>{u("all"),p("all"),y("all"),b("all"),_("all"),C("all"),c("")},$=d!=="all"||m!=="all"||f!=="all"||v!=="all"||g!=="all"||k!=="all"||l!=="",Y=t.filament.length+t.printer.length+t.process.length;return i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"space-y-4 mb-6",children:[i.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsx(Fr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:l,onChange:q=>c(q.target.value),placeholder:o("profiles.cloudView.searchPlaceholder"),className:"w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{className:"flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center",children:[i.jsxs(Ie,{variant:X?"primary":"secondary",onClick:()=>{X?(ce(!1),pe([null,null])):ce(!0)},children:[i.jsx(Kb,{className:"w-4 h-4"}),o(X?"common.cancel":"profiles.presets.compare")]}),i.jsxs(Ie,{variant:"secondary",onClick:()=>F(!0),disabled:!s("cloud:auth"),title:s("cloud:auth")?void 0:o("profiles.cloudView.noTemplatesPermission"),children:[i.jsx(fx,{className:"w-4 h-4"}),o("profiles.cloudView.templates")]}),i.jsxs(Ie,{variant:"secondary",onClick:n,disabled:r||!s("cloud:auth"),title:s("cloud:auth")?void 0:o("profiles.cloudView.noRefreshPermission"),children:[i.jsx(vr,{className:`w-4 h-4 ${r?"animate-spin":""}`}),o("profiles.cloudView.refresh")]}),i.jsxs(Ie,{onClick:()=>j(!0),disabled:!s("cloud:auth"),title:s("cloud:auth")?void 0:o("profiles.cloudView.noCreatePermission"),children:[i.jsx(ir,{className:"w-4 h-4"}),o("profiles.cloudView.newPreset")]})]})]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx(sT,{className:"w-4 h-4 text-bambu-gray"}),i.jsx(Mb,{label:o("profiles.cloudView.filters.type"),value:d,options:[{value:"all",label:o("profiles.cloudView.filters.all"),count:Y},{value:"filament",label:o("profiles.cloudView.filters.filament"),count:t.filament.length},{value:"printer",label:o("profiles.cloudView.filters.printer"),count:t.printer.length},{value:"process",label:o("profiles.cloudView.filters.process"),count:t.process.length}],onChange:q=>u(q)}),i.jsx(Mb,{label:o("profiles.cloudView.filters.owner"),value:m,options:[{value:"all",label:o("profiles.cloudView.filters.all")},{value:"custom",label:o("profiles.cloudView.filters.myPresets")},{value:"builtin",label:o("profiles.cloudView.filters.builtIn")}],onChange:q=>p(q)}),J.printers.length>0&&i.jsx(Mb,{label:o("profiles.cloudView.filters.printer"),value:f,options:[{value:"all",label:o("profiles.cloudView.filters.all")},...J.printers.map(q=>({value:q.id,label:q.name}))],onChange:y}),J.nozzles.length>0&&i.jsx(Mb,{label:o("profiles.cloudView.filters.nozzle"),value:v,options:[{value:"all",label:o("profiles.cloudView.filters.all")},...J.nozzles.map(q=>({value:q,label:q}))],onChange:b}),J.filaments.length>0&&(d==="all"||d==="filament")&&i.jsx(Mb,{label:o("profiles.cloudView.filters.filament"),value:g,options:[{value:"all",label:o("profiles.cloudView.filters.all")},...J.filaments.map(q=>({value:q,label:q}))],onChange:_}),J.layerHeights.length>0&&(d==="all"||d==="process")&&i.jsx(Mb,{label:o("profiles.cloudView.filters.layer"),value:k,options:[{value:"all",label:o("profiles.cloudView.filters.all")},...J.layerHeights.map(q=>({value:q,label:q}))],onChange:C}),$&&i.jsx("button",{onClick:O,className:"px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors",children:o("profiles.cloudView.clearFilters")})]})]}),X&&i.jsx("div",{className:"mb-4 p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-4",children:[i.jsx(Kb,{className:"w-5 h-5 text-blue-400"}),i.jsx("span",{className:"text-white font-medium",children:o("profiles.cloudView.compareMode")}),i.jsx("span",{className:"text-bambu-gray",children:ue[0]?o("profiles.cloudView.selectAnotherPreset",{type:ue[0].type}):o("profiles.cloudView.clickTwoPresets")})]}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${ue[0]?"bg-blue-500/30 text-blue-700 dark:text-blue-300":"bg-bambu-dark text-bambu-gray"}`,children:ue[0]?ue[0].name:o("profiles.cloudView.selectFirst")}),i.jsx(S3,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("span",{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${ue[1]?"bg-blue-500/30 text-blue-700 dark:text-blue-300":"bg-bambu-dark text-bambu-gray"}`,children:ue[1]?ue[1].name:o("profiles.cloudView.selectSecond")})]}),ue[0]&&ue[1]&&i.jsxs(Ie,{size:"sm",onClick:async()=>{try{const[q,te]=await Promise.all([be.getCloudSettingDetail(ue[0].setting_id),be.getCloudSettingDetail(ue[1].setting_id)]);ge([q.setting||{},te.setting||{}]),se(!0)}catch{}},children:[i.jsx(Kb,{className:"w-4 h-4"}),o("profiles.cloudView.compareNow")]})]})]})}),i.jsxs("div",{className:"flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray",children:[e&&i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx(Zn,{className:"w-3 h-3"}),o("profiles.cloudView.lastSynced")," ",C0(e.toISOString(),"system",o)]}),i.jsx("span",{children:o("profiles.cloudView.showingCount",{showing:E.length,total:Y})}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-bambu-green"}),i.jsxs("span",{children:["= ",o("profiles.presets.myPreset")]})]})]}),E.length===0?i.jsxs("div",{className:"text-center py-16",children:[i.jsx(Ki,{className:"w-12 h-12 text-bambu-gray-dark mx-auto mb-4"}),i.jsx("p",{className:"text-bambu-gray",children:o("profiles.cloudView.noPresetsFound")}),$&&i.jsx("button",{onClick:O,className:"mt-2 text-sm text-bambu-green hover:text-bambu-green-light",children:o("profiles.cloudView.clearFilters")})]}):i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3 px-1",children:[i.jsx(iT,{className:"w-4 h-4 text-amber-400"}),i.jsx("h3",{className:"text-sm font-medium text-bambu-gray",children:o("profiles.cloudView.columns.filament")}),i.jsxs("span",{className:"text-xs text-bambu-gray-dark",children:["(",E.filter(q=>q.type==="filament").length,")"]})]}),i.jsxs("div",{className:"space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1",children:[E.filter(q=>q.type==="filament").map(q=>i.jsx(XD,{setting:q,onClick:()=>U(q),onDuplicate:()=>B(q),compareMode:X,isCompareSelected:W(q)!==void 0,compareIndex:W(q),compareDisabled:X&&!!ue[0]&&ue[0].type!==q.type,t:o},q.setting_id)),E.filter(q=>q.type==="filament").length===0&&i.jsx("p",{className:"text-xs text-bambu-gray-dark px-3 py-2",children:o("profiles.cloudView.noFilamentPresets")})]})]}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3 px-1",children:[i.jsx(yd,{className:"w-4 h-4 text-blue-400"}),i.jsx("h3",{className:"text-sm font-medium text-bambu-gray",children:o("profiles.cloudView.columns.process")}),i.jsxs("span",{className:"text-xs text-bambu-gray-dark",children:["(",E.filter(q=>q.type==="process").length,")"]})]}),i.jsxs("div",{className:"space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1",children:[E.filter(q=>q.type==="process").map(q=>i.jsx(XD,{setting:q,onClick:()=>U(q),onDuplicate:()=>B(q),compareMode:X,isCompareSelected:W(q)!==void 0,compareIndex:W(q),compareDisabled:X&&!!ue[0]&&ue[0].type!==q.type,t:o},q.setting_id)),E.filter(q=>q.type==="process").length===0&&i.jsx("p",{className:"text-xs text-bambu-gray-dark px-3 py-2",children:o("profiles.cloudView.noProcessPresets")})]})]}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3 px-1",children:[i.jsx(_r,{className:"w-4 h-4 text-purple-400"}),i.jsx("h3",{className:"text-sm font-medium text-bambu-gray",children:o("profiles.cloudView.columns.printer")}),i.jsxs("span",{className:"text-xs text-bambu-gray-dark",children:["(",E.filter(q=>q.type==="printer").length,")"]})]}),i.jsxs("div",{className:"space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1",children:[E.filter(q=>q.type==="printer").map(q=>i.jsx(XD,{setting:q,onClick:()=>U(q),onDuplicate:()=>B(q),compareMode:X,isCompareSelected:W(q)!==void 0,compareIndex:W(q),compareDisabled:X&&!!ue[0]&&ue[0].type!==q.type,t:o},q.setting_id)),E.filter(q=>q.type==="printer").length===0&&i.jsx("p",{className:"text-xs text-bambu-gray-dark px-3 py-2",children:o("profiles.cloudView.noPrinterPresets")})]})]})]}),N&&i.jsx(ftt,{setting:N,onClose:()=>P(null),onDeleted:()=>P(null),onDuplicate:()=>B(N),onEdit:()=>ie(N),hasPermission:s,t:o}),(T||G||Z||ee)&&i.jsx(btt,{onClose:()=>{j(!1),z(null),I(null),ae(null)},initialData:Z||G||(ee?{type:ee.type,name:"",base_id:"",setting:ee.setting}:void 0),allPresets:t,t:o}),A&&i.jsx(gtt,{onClose:()=>F(!1),onApply:q=>{ae({type:q.type,setting:q.settings}),F(!1)},t:o}),K&&de&&ue[0]&&ue[1]&&i.jsx(Zoe,{onClose:()=>{se(!1),ge(null)},leftPreset:de[0],rightPreset:de[1],leftLabel:ue[0].name,rightLabel:ue[1].name,t:o})]})}function ytt(){const{t}=jt(),e=cn(),{showToast:n}=pn(),{hasPermission:r}=Ar(),[a,s]=w.useState("cloud"),[o,l]=w.useState(),{data:c,isLoading:d}=et({queryKey:["cloudStatus"],queryFn:be.getCloudStatus}),{data:u=[]}=et({queryKey:["printers"],queryFn:be.getPrinters}),{data:m,isLoading:p,refetch:f,dataUpdatedAt:y}=et({queryKey:["cloudSettings"],queryFn:()=>be.getCloudSettings(),enabled:!!c?.is_authenticated,retry:!1,staleTime:1e3*60*5});w.useEffect(()=>{y&&l(new Date(y))},[y]);const v=pt({mutationFn:be.cloudLogout,onSuccess:()=>{e.invalidateQueries({queryKey:["cloudStatus"]}),e.removeQueries({queryKey:["cloudSettings"]}),n(t("profiles.toast.loggedOut"))}}),b=()=>{e.invalidateQueries({queryKey:["cloudStatus"]})};return d?i.jsx("div",{className:"p-4 md:p-8 flex items-center justify-center min-h-[400px]",children:i.jsx(ft,{className:"w-8 h-8 text-bambu-green animate-spin"})}):i.jsxs("div",{className:"p-6 lg:p-8",children:[i.jsxs("div",{className:"mb-6",children:[i.jsx("h1",{className:"text-2xl font-bold text-white",children:t("profiles.title")}),i.jsx("p",{className:"text-bambu-gray",children:t("profiles.subtitle")})]}),i.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary mb-6",children:[i.jsxs("button",{onClick:()=>s("cloud"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${a==="cloud"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[i.jsx(Vx,{className:"w-4 h-4"}),t("profiles.tabs.cloud")]}),i.jsxs("button",{onClick:()=>s("local"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${a==="local"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[i.jsx(Gx,{className:"w-4 h-4"}),t("profiles.tabs.local")]}),i.jsxs("button",{onClick:()=>s("kprofiles"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${a==="kprofiles"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[i.jsx(yw,{className:"w-4 h-4"}),t("profiles.tabs.kprofiles")]})]}),a==="cloud"&&i.jsxs(i.Fragment,{children:[c?.is_authenticated&&i.jsxs("div",{className:"flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"w-2 h-2 rounded-full bg-bambu-green animate-pulse"}),i.jsxs("span",{className:"text-sm text-bambu-gray",children:[t("profiles.connectedAs")," ",i.jsx("span",{className:"text-white",children:c.email})]})]}),i.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>v.mutate(),disabled:v.isPending||!r("cloud:auth"),title:r("cloud:auth")?void 0:t("profiles.noLogoutPermission"),children:[i.jsx(C3,{className:"w-4 h-4"}),t("profiles.logout")]})]}),c?.is_authenticated?p?i.jsx("div",{className:"flex items-center justify-center py-16",children:i.jsx(ft,{className:"w-8 h-8 text-bambu-green animate-spin"})}):m?i.jsx(xtt,{settings:m,lastSyncTime:o,onRefresh:()=>f(),isRefreshing:p,printers:u,hasPermission:r,t}):i.jsxs("div",{className:"text-center py-16",children:[i.jsx("p",{className:"text-bambu-gray mb-4",children:t("profiles.failedToLoad")}),i.jsx(Ie,{onClick:()=>f(),children:t("profiles.retry")})]}):i.jsx(htt,{onSuccess:b,t})]}),a==="local"&&i.jsx(mtt,{}),a==="kprofiles"&&i.jsx(ltt,{}),i.jsx(ptt,{})]})}const Gv={Droplet:iT,Flame:Gp,Ruler:Qge,Sparkles:fx,Square:rl,Cable:KL,Wrench:Ff,Calendar:Xr,Timer:Nu,Cog:Ope,Fan:QX,Zap:Wl,Wind:uQ,Thermometer:hT,Layers:Ki,Box:aa,Target:oQ,RefreshCw:vr,Settings:mT,Filter:sT,CircleDot:xpe};function b0(t){return t&&Gv[t]||Ff}function Eb(t,e,n){if(e==="days"){if(t<1)return n?n("common.today"):"Today";if(t===1)return n?n("maintenance.day"):"1 day";if(t<7){const a=Math.round(t);return n?n("maintenance.days",{count:a}):`${a} days`}if(t<180){const a=Math.round(t/7);return a===1?n?n("maintenance.week"):"1 week":n?n("maintenance.weeks",{count:a}):`${a} weeks`}const r=Math.round(t/30);return r===1?n?n("maintenance.month"):"1 month":n?n("maintenance.months",{count:r}):`${r} months`}else{if(t<1)return`${Math.round(t*60)}m`;if(t<24)return`${t<10?t.toFixed(1):Math.round(t)}h`;const r=t/24;if(r<7)return`${r<2?r.toFixed(1):Math.round(r)}d`;const a=r/7;return a<12?`${a<2?a.toFixed(1):Math.round(a)}w`:`${Math.round(a/4)}mo`}}function QD(t,e,n){return e==="days"?t===1?n?n("maintenance.day"):"1 day":t===7?n?n("maintenance.week"):"1 week":t===14?n?n("maintenance.weeks",{count:2}):"2 weeks":t===30?n?n("maintenance.month"):"1 month":t===60?n?n("maintenance.months",{count:2}):"2 months":t===90?n?n("maintenance.months",{count:3}):"3 months":t===180?n?n("maintenance.months",{count:6}):"6 months":t===365?n?n("maintenance.year"):"1 year":n?n("maintenance.days",{count:t}):`${t} days`:`${t}h`}function vtt(t,e){const n=(e||"").toUpperCase().replace(/[- ]/g,""),r=n.includes("X1"),a=n.includes("P1"),s=n.includes("A1MINI"),o=n.includes("A1")&&!s,l=n.includes("H2D"),c=n.includes("H2C"),d=n.includes("H2S"),u=l||c||d,m=n.includes("P2S");switch(t){case"Lubricate Steel Rods":return m?"https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis":null;case"Clean Steel Rods":return m?"https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis":null;case"Lubricate Linear Rails":return s?"https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis":o?"https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis":u?"https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication":null;case"Clean Nozzle/Hotend":return r||a?"https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog":s||o?"https://wiki.bambulab.com/en/a1-mini/troubleshooting/nozzle-clog":u?"https://wiki.bambulab.com/en/h2/maintenance/nozzl-cold-pull-maintenance-and-cleaning":m?"https://wiki.bambulab.com/en/p2s/maintenance/cold-pull-maintenance-hotend":"https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog";case"Check Belt Tension":return r?"https://wiki.bambulab.com/en/x1/maintenance/belt-tension":a?"https://wiki.bambulab.com/en/p1/maintenance/p1p-maintenance":s?"https://wiki.bambulab.com/en/a1-mini/maintenance/belt_tension":o?"https://wiki.bambulab.com/en/a1/maintenance/belt_tension":l?"https://wiki.bambulab.com/en/h2/maintenance/belt-tension":c?"https://wiki.bambulab.com/en/h2c/maintenance/belt-tension":d?"https://wiki.bambulab.com/en/h2s/maintenance/belt-tension":m?"https://wiki.bambulab.com/en/p2s/maintenance/belt-tension":"https://wiki.bambulab.com/en/x1/maintenance/belt-tension";case"Clean Carbon Rods":return r||a?"https://wiki.bambulab.com/en/general/carbon-rods-clearance":null;case"Clean Linear Rails":return s?"https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis":o?"https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis":u?"https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication":null;case"Clean Build Plate":return"https://wiki.bambulab.com/en/filament-acc/acc/pei-plate-clean-guide";case"Check PTFE Tube":return r||a?"https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube":s||o?"https://wiki.bambulab.com/en/a1-mini/maintenance/ptfe-tube":l?"https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer":d?"https://wiki.bambulab.com/en/h2s/maintenance/replace-ptfe-tube-on-h2s-printer":c?"https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer":"https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube";case"Replace HEPA Filter":case"HEPA Filter":case"Replace Carbon Filter":case"Carbon Filter":return u?"https://wiki.bambulab.com/en/h2/maintenance/replace-smoke-purifier-air-filte":"https://wiki.bambulab.com/en/x1/maintenance/replace-carbon-filter";case"Lubricate Left Nozzle Rail":case"Left Nozzle Rail":return u?"https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication":null;default:return null}}function wtt({item:t,onPerform:e,onToggle:n,hasPermission:r,t:a}){const s=b0(t.maintenance_type_icon),o=t.interval_type||"hours",c=(()=>{if(o==="days"){const f=t.days_since_maintenance??0;return Math.max(0,Math.min(100,f/t.interval_hours*100))}return Math.max(0,Math.min(100,(t.interval_hours-t.hours_until_due)/t.interval_hours*100))})(),d=()=>t.enabled?t.is_due?"text-red-400":t.is_warning?"text-amber-400":"text-bambu-green":"text-bambu-gray",u=()=>t.enabled?t.is_due?"bg-red-500":t.is_warning?"bg-amber-500":"bg-bambu-green":"bg-bambu-gray/30",m=()=>t.enabled?t.is_due?"bg-red-500/5 border-red-500/20":t.is_warning?"bg-amber-500/5 border-amber-500/20":"bg-bambu-dark-secondary border-bambu-dark-tertiary":"bg-bambu-dark-secondary/50",p=()=>{if(!t.enabled)return a("common.disabled");if(o==="days"){const f=t.days_until_due??0;return t.is_due?a("maintenance.overdueBy",{duration:Eb(Math.abs(f),"days",a)}):t.is_warning?a("maintenance.dueIn",{duration:Eb(f,"days",a)}):a("maintenance.timeLeft",{duration:Eb(f,"days",a)})}else return t.is_due?a("maintenance.overdueBy",{duration:Eb(Math.abs(t.hours_until_due),"hours",a)}):t.is_warning?a("maintenance.dueIn",{duration:Eb(t.hours_until_due,"hours",a)}):a("maintenance.timeLeft",{duration:Eb(t.hours_until_due,"hours",a)})};return i.jsx("div",{className:`rounded-xl border p-4 transition-all ${m()}`,children:i.jsxs("div",{className:"flex items-start gap-3 max-[550px]:flex-wrap",children:[i.jsxs("div",{className:`relative p-2.5 rounded-lg shrink-0 ${t.is_due?"bg-red-500/20":t.is_warning?"bg-amber-500/20":t.enabled?"bg-bambu-dark":"bg-bambu-dark/50"}`,children:[i.jsx(s,{className:`w-5 h-5 ${d()}`}),t.enabled&&(t.is_due||t.is_warning)&&i.jsx("span",{className:`absolute -top-1 -right-1 w-2.5 h-2.5 rounded-full ${t.is_due?"bg-red-500":"bg-amber-500"} animate-pulse`})]}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("h3",{className:`font-medium truncate ${t.enabled?"text-white":"text-bambu-gray"}`,children:t.maintenance_type_name}),o==="days"&&i.jsx("span",{title:a("maintenance.timeBasedInterval"),children:i.jsx(Xr,{className:"w-3.5 h-3.5 text-bambu-gray shrink-0"})}),(()=>{const f=t.maintenance_type_wiki_url||vtt(t.maintenance_type_name,t.printer_model);return f?i.jsx("a",{href:f,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-gray hover:text-bambu-green transition-colors shrink-0",title:a("maintenance.viewDocumentation"),onClick:y=>y.stopPropagation(),children:i.jsx(ni,{className:"w-3.5 h-3.5"})}):null})()]}),i.jsx("div",{className:"mt-2 mb-1.5",children:i.jsx("div",{className:"w-full h-1.5 bg-bambu-dark rounded-full overflow-hidden",children:i.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${u()}`,style:{width:`${c}%`}})})}),i.jsxs("div",{className:`text-xs flex items-center gap-1 ${d()}`,children:[t.is_due&&i.jsx(jn,{className:"w-3 h-3"}),t.is_warning&&!t.is_due&&i.jsx(Zn,{className:"w-3 h-3"}),!t.is_due&&!t.is_warning&&t.enabled&&i.jsx(Zr,{className:"w-3 h-3"}),p()]})]}),i.jsxs("div",{className:"flex items-center gap-2 shrink-0 max-[550px]:w-full max-[550px]:justify-end max-[550px]:mt-1",children:[i.jsx("span",{title:r("maintenance:update")?void 0:a("maintenance.noPermissionUpdate"),children:i.jsx(In,{checked:t.enabled,onChange:f=>n(t.id,f),disabled:!r("maintenance:update")})}),i.jsxs(Ie,{size:"sm",variant:t.is_due?"primary":"secondary",onClick:()=>e(t.id),disabled:!t.enabled||!r("maintenance:update"),title:r("maintenance:update")?void 0:a("maintenance.noPermissionPerform"),className:"!px-3",children:[i.jsx(Ao,{className:"w-3.5 h-3.5"}),a("common.reset")]})]})]})})}function Stt({overview:t,onPerform:e,onToggle:n,onSetHours:r,hasPermission:a,t:s}){const[o,l]=w.useState(!1),[c,d]=w.useState(!1),[u,m]=w.useState(t.total_print_hours.toFixed(1)),p=[...t.maintenance_items].sort((v,b)=>v.is_due&&!b.is_due?-1:!v.is_due&&b.is_due?1:v.is_warning&&!b.is_warning?-1:!v.is_warning&&b.is_warning?1:v.maintenance_type_id-b.maintenance_type_id),f=p.find(v=>v.enabled&&(v.is_due||v.is_warning)),y=()=>{const v=parseFloat(u);!isNaN(v)&&v>=0&&(r(t.printer_id,v),d(!1))};return i.jsxs(At,{className:"overflow-hidden",children:[i.jsxs("div",{className:"p-5",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-4",children:[i.jsx("h2",{className:"text-xl font-semibold text-white",children:t.printer_name}),i.jsxs("div",{className:"flex items-center gap-2",children:[t.due_count>0&&i.jsxs("span",{className:"px-2.5 py-1 bg-red-500/20 text-red-400 text-xs font-medium rounded-full flex items-center gap-1.5",children:[i.jsx(jn,{className:"w-3 h-3"}),s("maintenance.overdueCount",{count:t.due_count})]}),t.warning_count>0&&i.jsxs("span",{className:"px-2.5 py-1 bg-amber-500/20 text-amber-400 text-xs font-medium rounded-full flex items-center gap-1.5",children:[i.jsx(Zn,{className:"w-3 h-3"}),s("maintenance.dueSoonCount",{count:t.warning_count})]}),t.due_count===0&&t.warning_count===0&&i.jsxs("span",{className:"px-2.5 py-1 bg-bambu-green/20 text-bambu-green text-xs font-medium rounded-full flex items-center gap-1.5",children:[i.jsx(Zr,{className:"w-3 h-3"}),s("maintenance.allGood")]})]})]}),i.jsxs("button",{onClick:()=>l(!o),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark rounded-lg transition-colors",children:[o?i.jsx(Gl,{className:"w-4 h-4"}):i.jsx(zn,{className:"w-4 h-4"}),s(o?"common.collapse":"common.expand")]})]}),i.jsxs("div",{className:"flex items-center gap-6 mt-4",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"p-2 bg-bambu-dark/50 rounded-lg",children:i.jsx(Nu,{className:"w-4 h-4 text-bambu-gray"})}),c?i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",value:u,onChange:v=>m(v.target.value),onKeyDown:v=>{v.key==="Enter"&&y(),v.key==="Escape"&&d(!1)},className:"w-24 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm",min:"0",step:"1",autoFocus:!0}),i.jsx("span",{className:"text-xs text-bambu-gray",children:s("common.hours")}),i.jsx(Ie,{size:"sm",onClick:y,children:s("common.save")}),i.jsx(Ie,{size:"sm",variant:"secondary",onClick:()=>d(!1),children:s("common.cancel")})]}):i.jsxs("button",{onClick:()=>{a("maintenance:update")&&(m(Math.round(t.total_print_hours).toString()),d(!0))},className:`group ${a("maintenance:update")?"":"cursor-not-allowed opacity-60"}`,title:a("maintenance:update")?void 0:s("maintenance.noPermissionEditHours"),children:[i.jsxs("div",{className:`text-sm font-medium text-white ${a("maintenance:update")?"group-hover:text-bambu-green":""} transition-colors flex items-center gap-1`,children:[Math.round(t.total_print_hours)," ",s("common.hours"),i.jsx(Ef,{className:`w-3 h-3 text-bambu-gray ${a("maintenance:update")?"group-hover:text-bambu-green":""}`})]}),i.jsx("div",{className:"text-xs text-bambu-gray",children:s("maintenance.totalPrintTime")})]})]}),i.jsx("div",{className:"w-px h-10 bg-bambu-dark-tertiary"}),f&&i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:`p-2 rounded-lg ${f.is_due?"bg-red-500/20":"bg-amber-500/20"}`,children:(()=>{const v=b0(f.maintenance_type_icon);return i.jsx(v,{className:`w-4 h-4 ${f.is_due?"text-red-400":"text-amber-400"}`})})()}),i.jsxs("div",{children:[i.jsx("div",{className:`text-sm font-medium ${f.is_due?"text-red-400":"text-amber-400"}`,children:f.maintenance_type_name}),i.jsx("div",{className:`text-xs ${f.is_due?"text-red-400/70":"text-amber-400/70"}`,children:f.is_due?s("common.overdue"):s("maintenance.dueSoon")})]})]})]})]}),o&&i.jsx(Et,{className:"pt-0 border-t border-bambu-dark-tertiary",children:i.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-3 pt-4",children:p.map(v=>i.jsx(wtt,{item:v,onPerform:e,onToggle:n,hasPermission:a,t:s},v.id))})})]})}function _tt({overview:t,types:e,onUpdateInterval:n,onAddType:r,onUpdateType:a,onDeleteType:s,onRestoreDefaults:o,isRestoringDefaults:l,onAssignType:c,onRemoveItem:d,hasPermission:u,t:m}){const[p,f]=w.useState(null),[y,v]=w.useState(""),[b,g]=w.useState("hours"),[_,k]=w.useState(!1),[C,N]=w.useState(""),[P,T]=w.useState("100"),[j,A]=w.useState("hours"),[F,G]=w.useState("Wrench"),[z,Z]=w.useState(""),[I,ee]=w.useState(new Set),[ae,X]=w.useState(null),[ce,ue]=w.useState(null),pe=w.useMemo(()=>t?t.map(L=>({id:L.printer_id,name:L.printer_name})):[],[t]),K=L=>t?t.filter(R=>R.maintenance_items.some(ne=>ne.maintenance_type_id===L)).map(R=>({printerId:R.printer_id,printerName:R.printer_name,itemId:R.maintenance_items.find(ne=>ne.maintenance_type_id===L)?.id})):[],se=L=>{if(!t)return[];const R=new Set(K(L).map(ne=>ne.printerId));return pe.filter(ne=>!R.has(ne.id))},[de,ge]=w.useState(null),[Te,V]=w.useState(""),[J,D]=w.useState(""),[E,U]=w.useState("hours"),[W,B]=w.useState("Wrench"),[ie,O]=w.useState(""),$=L=>{ge(L),V(L.name),D(L.default_interval_hours.toString()),U(L.interval_type||"hours"),B(L.icon||"Wrench"),O(L.wiki_url||"")},Y=()=>{de&&Te.trim()&&parseFloat(J)>0&&(a(de.id,{name:Te.trim(),default_interval_hours:parseFloat(J),interval_type:E,icon:W,wiki_url:ie.trim()||null}),ge(null))},q=(L,R,ne)=>{const ve=parseFloat(y);if(!isNaN(ve)&&ve>0){const we=Math.abs(ve-R)<.01?null:ve;n(L,{custom_interval_hours:we,custom_interval_type:b!==ne?b:null})}f(null)},te=L=>{L.preventDefault(),C.trim()&&parseFloat(P)>0&&I.size>0&&(r({name:C.trim(),default_interval_hours:parseFloat(P),interval_type:j,icon:F,wiki_url:z.trim()||null},Array.from(I)),N(""),T("100"),A("hours"),Z(""),ee(new Set),k(!1))},oe=L=>{ee(R=>{const ne=new Set(R);return ne.has(L)?ne.delete(L):ne.add(L),ne})},he=t?.map(L=>({printerId:L.printer_id,printerName:L.printer_name,items:L.maintenance_items.sort((R,ne)=>R.maintenance_type_id-ne.maintenance_type_id)})).sort((L,R)=>L.printerName.localeCompare(R.printerName))||[],fe=e.filter(L=>L.is_system),re=e.filter(L=>!L.is_system);return i.jsxs("div",{className:"space-y-8",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-4",children:[i.jsxs("div",{children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:m("maintenance.maintenanceTypes")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:m("maintenance.maintenanceTypesDescription")})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Ie,{variant:"secondary",onClick:o,disabled:!u("maintenance:delete")||l,title:u("maintenance:delete")?void 0:m("maintenance.noPermissionDeleteTypes"),children:m("maintenance.restoreDefaults")}),i.jsxs(Ie,{onClick:()=>k(!_),disabled:!u("maintenance:create"),title:u("maintenance:create")?void 0:m("maintenance.noPermissionEditTypes"),children:[i.jsx(ir,{className:"w-4 h-4"}),m("maintenance.addCustomType")]})]})]}),_&&i.jsx(At,{className:"mb-6",children:i.jsx(Et,{className:"py-4",children:i.jsxs("form",{onSubmit:te,children:[i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[i.jsxs("div",{className:"lg:col-span-2",children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:m("common.name")}),i.jsx("input",{type:"text",value:C,onChange:L=>N(L.target.value),className:"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",placeholder:m("maintenance.exampleName"),autoFocus:!0})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:m("maintenance.intervalType")}),i.jsxs("select",{value:j,onChange:L=>{A(L.target.value),L.target.value==="days"?T("30"):T("100")},className:"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",children:[i.jsx("option",{value:"hours",children:m("maintenance.printHours")}),i.jsx("option",{value:"days",children:m("maintenance.calendarDays")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:m("maintenance.intervalValue",{type:j==="days"?m("maintenance.calendarDays").toLowerCase():m("common.hours")})}),i.jsx("input",{type:"number",value:P,onChange:L=>T(L.target.value),className:"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",min:"1"})]})]}),i.jsx("div",{className:"mt-4 flex items-end justify-between",children:i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:m("maintenance.icon")}),i.jsx("div",{className:"flex gap-1",children:Object.keys(Gv).map(L=>{const R=Gv[L];return i.jsx("button",{type:"button",onClick:()=>G(L),className:`p-2 rounded-lg transition-colors ${F===L?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary"}`,children:i.jsx(R,{className:"w-4 h-4"})},L)})})]})}),i.jsxs("div",{className:"mt-4",children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:m("maintenance.documentationLink")}),i.jsx("input",{type:"url",value:z,onChange:L=>Z(L.target.value),className:"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",placeholder:"https://wiki.bambulab.com/..."})]}),i.jsxs("div",{className:"mt-4",children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:m("maintenance.assignToPrinters")}),i.jsx("div",{className:"flex flex-wrap gap-2",children:pe.map(L=>i.jsx("button",{type:"button",onClick:()=>oe(L.id),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${I.has(L.id)?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary"}`,children:L.name},L.id))}),I.size===0&&i.jsx("p",{className:"text-xs text-orange-400 mt-1",children:m("maintenance.selectAtLeastOnePrinter")})]}),i.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[i.jsx(Ie,{type:"button",variant:"secondary",onClick:()=>{k(!1),ee(new Set)},children:m("common.cancel")}),i.jsx(Ie,{type:"submit",disabled:!C.trim()||I.size===0,children:m("maintenance.addType")})]})]})})}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:[fe.map(L=>{const R=b0(L.icon),ne=L.interval_type||"hours";return i.jsx("div",{className:"bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-dark-tertiary",children:i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"p-2.5 bg-bambu-dark rounded-lg",children:i.jsx(R,{className:"w-5 h-5 text-bambu-gray"})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"text-sm font-medium text-white truncate",children:L.name}),i.jsxs("div",{className:"text-xs text-bambu-gray mt-0.5 flex items-center gap-1",children:[ne==="days"?i.jsx(Xr,{className:"w-3 h-3"}):i.jsx(Nu,{className:"w-3 h-3"}),QD(L.default_interval_hours,ne,m)]})]}),i.jsx("button",{onClick:()=>{u("maintenance:delete")&&ue(L)},disabled:!u("maintenance:delete"),title:u("maintenance:delete")?void 0:m("maintenance.noPermissionDeleteTypes"),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-400 transition-colors ${u("maintenance:delete")?"":"opacity-50 cursor-not-allowed"}`,children:i.jsx(an,{className:"w-4 h-4"})})]})},L.id)}),re.map(L=>{const R=b0(L.icon),ne=L.interval_type||"hours";if(de?.id===L.id)return i.jsx("div",{className:"bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green",children:i.jsxs("div",{className:"space-y-3",children:[i.jsx("input",{type:"text",value:Te,onChange:xe=>V(xe.target.value),className:"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",placeholder:m("common.name"),autoFocus:!0}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("select",{value:E,onChange:xe=>U(xe.target.value),className:"flex-1 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",children:[i.jsx("option",{value:"hours",children:m("maintenance.printHours")}),i.jsx("option",{value:"days",children:m("maintenance.calendarDays")})]}),i.jsx("input",{type:"number",value:J,onChange:xe=>D(xe.target.value),className:"w-24 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",min:"1"})]}),i.jsx("div",{className:"flex flex-wrap gap-1",children:Object.keys(Gv).map(xe=>{const je=Gv[xe];return i.jsx("button",{type:"button",onClick:()=>B(xe),className:`p-1.5 rounded transition-colors ${W===xe?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:i.jsx(je,{className:"w-3.5 h-3.5"})},xe)})}),i.jsx("input",{type:"url",value:ie,onChange:xe=>O(xe.target.value),className:"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",placeholder:m("maintenance.documentationLink")}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Ie,{size:"sm",onClick:Y,disabled:!Te.trim(),children:m("common.save")}),i.jsx(Ie,{size:"sm",variant:"secondary",onClick:()=>ge(null),children:m("common.cancel")})]})]})},L.id);const we=K(L.id),me=se(L.id),Me=ae===L.id;return i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green/30",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"p-2.5 bg-bambu-green/20 rounded-lg",children:i.jsx(R,{className:"w-5 h-5 text-bambu-green"})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-sm font-medium text-white truncate",children:L.name}),i.jsx("span",{className:"px-1.5 py-0.5 bg-bambu-green/20 text-bambu-green text-[10px] font-medium rounded",children:m("maintenance.custom")})]}),i.jsxs("div",{className:"text-xs text-bambu-gray mt-0.5 flex items-center gap-1",children:[ne==="days"?i.jsx(Xr,{className:"w-3 h-3"}):i.jsx(Nu,{className:"w-3 h-3"}),QD(L.default_interval_hours,ne,m)]})]}),i.jsxs("button",{onClick:()=>X(Me?null:L.id),className:`px-2 py-1 rounded-lg border transition-colors flex items-center gap-1 ${we.length>0?"border-bambu-green/50 bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20":"border-orange-400/50 bg-orange-400/10 text-orange-400 hover:bg-orange-400/20"}`,title:m("maintenance.printersAssignedClick",{count:we.length}),children:[i.jsx(_r,{className:"w-3 h-3"}),i.jsx("span",{className:"text-xs font-medium",children:we.length}),i.jsx(zn,{className:`w-3 h-3 transition-transform ${Me?"rotate-180":""}`})]}),i.jsx("button",{onClick:()=>$(L),disabled:!u("maintenance:update"),title:u("maintenance:update")?void 0:m("maintenance.noPermissionEditTypes"),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors ${u("maintenance:update")?"":"opacity-50 cursor-not-allowed"}`,children:i.jsx(Ef,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>{confirm(m("maintenance.deleteTypeConfirm",{name:L.name}))&&s(L.id)},disabled:!u("maintenance:delete"),title:u("maintenance:delete")?void 0:m("maintenance.noPermissionDeleteTypes"),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-400 transition-colors ${u("maintenance:delete")?"":"opacity-50 cursor-not-allowed"}`,children:i.jsx(an,{className:"w-4 h-4"})})]}),Me&&i.jsxs("div",{className:"mt-3 pt-3 border-t border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:m("maintenance.assignedToPrinters")}),we.length===0?i.jsx("p",{className:"text-xs text-orange-400",children:m("maintenance.noPrintersAssigned")}):i.jsx("div",{className:"flex flex-wrap gap-1 mb-2",children:we.map(xe=>i.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark rounded text-xs text-white",children:[xe.printerName,i.jsx("button",{onClick:()=>xe.itemId&&d(xe.itemId),disabled:!u("maintenance:delete"),title:u("maintenance:delete")?m("maintenance.removeFromPrinter"):m("maintenance.noPermissionRemovePrinter"),className:`ml-1 ${u("maintenance:delete")?"hover:text-red-400":"opacity-50 cursor-not-allowed"}`,children:"×"})]},xe.printerId))}),me.length>0&&i.jsxs("div",{className:"flex flex-wrap gap-1",children:[i.jsx("span",{className:"text-xs text-bambu-gray mr-1",children:m("maintenance.addPrinterShort")}),me.map(xe=>i.jsxs("button",{onClick:()=>c(xe.id,L.id),disabled:!u("maintenance:create"),title:u("maintenance:create")?void 0:m("maintenance.noPermissionAssignPrinter"),className:`px-2 py-1 bg-bambu-dark rounded text-xs transition-colors ${u("maintenance:create")?"hover:bg-bambu-green/20 text-bambu-gray hover:text-bambu-green":"opacity-50 cursor-not-allowed text-bambu-gray"}`,children:["+ ",xe.name]},xe.id))]})]})]},L.id)})]})]}),he.length>0&&i.jsxs("div",{children:[i.jsxs("div",{className:"mb-4",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:m("maintenance.intervalOverrides")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:m("maintenance.intervalOverridesDescription")})]}),i.jsx("div",{className:"space-y-4",children:he.map(L=>i.jsx(At,{children:i.jsxs(Et,{className:"py-4",children:[i.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:L.printerName}),i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2",children:L.items.map(R=>{const ne=b0(R.maintenance_type_icon),ve=e.find(je=>je.id===R.maintenance_type_id),we=ve?.default_interval_hours||R.interval_hours,me=ve?.interval_type||"hours",Me=R.interval_type||"hours",xe=p===R.id;return i.jsxs("div",{className:"flex items-center gap-2 p-2.5 bg-bambu-dark rounded-lg",children:[i.jsx(ne,{className:"w-4 h-4 text-bambu-gray shrink-0"}),i.jsx("span",{className:"text-xs text-bambu-gray flex-1 truncate",children:R.maintenance_type_name}),xe?i.jsxs("div",{className:"flex items-center gap-1",children:[b==="days"?i.jsx(Xr,{className:"w-3.5 h-3.5 text-bambu-gray shrink-0"}):i.jsx(Nu,{className:"w-3.5 h-3.5 text-bambu-gray shrink-0"}),i.jsxs("select",{value:b,onChange:je=>g(je.target.value),className:"px-1.5 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs",children:[i.jsx("option",{value:"hours",children:m("maintenance.printHours")}),i.jsx("option",{value:"days",children:m("maintenance.calendarDays")})]}),i.jsx("input",{type:"number",value:y,onChange:je=>v(je.target.value),onKeyDown:je=>{je.key==="Enter"&&q(R.id,we,me),je.key==="Escape"&&f(null)},className:"w-16 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs",min:"1"}),i.jsx(Ie,{size:"sm",onClick:()=>q(R.id,we,me),children:"OK"})]}):i.jsxs("button",{onClick:()=>{u("maintenance:update")&&(f(R.id),v(R.interval_hours.toString()),g(Me))},disabled:!u("maintenance:update"),title:u("maintenance:update")?void 0:m("maintenance.noPermissionEditIntervals"),className:`px-2 py-1 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs font-medium text-white transition-colors flex items-center gap-1 ${u("maintenance:update")?"hover:bg-bambu-dark-secondary hover:border-bambu-green":"opacity-50 cursor-not-allowed"}`,children:[Me==="days"?i.jsx(Xr,{className:"w-3 h-3"}):i.jsx(Nu,{className:"w-3 h-3"}),QD(R.interval_hours,Me,m),i.jsx(Ef,{className:"w-3 h-3 text-bambu-gray"})]})]},R.id)})})]})},L.printerId))})]}),he.length===0&&i.jsx(At,{children:i.jsxs(Et,{className:"text-center py-12",children:[i.jsx(Zn,{className:"w-12 h-12 mx-auto mb-4 text-bambu-gray/30"}),i.jsx("p",{className:"text-bambu-gray",children:m("common.noPrinters")}),i.jsx("p",{className:"text-sm text-bambu-gray/70 mt-1",children:m("maintenance.intervalOverridesDescription")})]})}),ce&&i.jsx(kn,{title:m("maintenance.deleteSystemTypeTitle"),message:m("maintenance.deleteSystemTypeMessage",{name:ce.name}),confirmText:m("common.delete"),cancelText:m("common.cancel"),variant:"danger",cancelVariant:"primary",cardClassName:"bg-red-950/70 border border-red-800/70",onConfirm:()=>{s(ce.id),ue(null)},onCancel:()=>ue(null)})]})}function ktt(){const{t}=jt(),e=cn(),{showToast:n}=pn(),{hasPermission:r}=Ar(),[a,s]=w.useState("status"),{data:o,isLoading:l}=et({queryKey:["maintenanceOverview"],queryFn:be.getMaintenanceOverview}),{data:c}=et({queryKey:["maintenanceTypes"],queryFn:be.getMaintenanceTypes}),d=pt({mutationFn:({id:P,notes:T})=>be.performMaintenance(P,T),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]}),e.invalidateQueries({queryKey:["maintenanceSummary"]}),n(t("maintenance.maintenanceComplete"))},onError:P=>{n(P.message,"error")}}),u=pt({mutationFn:({id:P,data:T})=>be.updateMaintenanceItem(P,T),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]})},onError:P=>{n(P.message,"error")}}),m=pt({mutationFn:({id:P,data:T})=>be.updateMaintenanceType(P,T),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceTypes"]}),e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.typeUpdated"))},onError:P=>{n(P.message,"error")}}),p=pt({mutationFn:be.deleteMaintenanceType,onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceTypes"]}),e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.typeDeleted"))},onError:P=>{n(P.message,"error")}}),f=pt({mutationFn:be.restoreDefaultMaintenanceTypes,onSuccess:P=>{e.invalidateQueries({queryKey:["maintenanceTypes"]}),e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.defaultsRestored",{count:P.restored}))},onError:P=>{n(P.message,"error")}}),y=pt({mutationFn:({printerId:P,hours:T})=>be.setPrinterHours(P,T),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]}),e.invalidateQueries({queryKey:["maintenanceSummary"]}),n(t("maintenance.printHoursUpdated"))},onError:P=>{n(P.message,"error")}}),v=pt({mutationFn:({printerId:P,typeId:T})=>be.assignMaintenanceType(P,T),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.printerAssigned"))},onError:P=>{n(P.message,"error")}}),b=pt({mutationFn:be.removeMaintenanceItem,onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.printerRemoved"))},onError:P=>{n(P.message,"error")}}),g=P=>{d.mutate({id:P})},_=(P,T)=>{u.mutate({id:P,data:{enabled:T}})},k=(P,T)=>{y.mutate({printerId:P,hours:T})};if(l)return i.jsx("div",{className:"p-4 md:p-8 flex justify-center",children:i.jsx(ft,{className:"w-8 h-8 text-bambu-green animate-spin"})});const C=o?.reduce((P,T)=>P+T.due_count,0)||0,N=o?.reduce((P,T)=>P+T.warning_count,0)||0;return i.jsxs("div",{className:"p-4 md:p-8",children:[i.jsxs("div",{className:"mb-6",children:[i.jsx("h1",{className:"text-2xl font-bold text-white",children:t("maintenance.title")}),i.jsx("p",{className:"text-bambu-gray text-sm mt-1",children:a==="status"?i.jsxs(i.Fragment,{children:[C>0&&i.jsx("span",{className:"text-red-400",children:t("maintenance.dueCount",{count:C})}),C>0&&N>0&&" · ",N>0&&i.jsx("span",{className:"text-amber-400",children:t("maintenance.warningCount",{count:N})}),C===0&&N===0&&i.jsx("span",{className:"text-bambu-green",children:t("maintenance.allOk")})]}):t("maintenance.configureSettings")})]}),i.jsxs("div",{className:"flex gap-1 mb-6 border-b border-bambu-dark-tertiary",children:[i.jsx("button",{onClick:()=>s("status"),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${a==="status"?"text-bambu-green border-bambu-green":"text-bambu-gray border-transparent hover:text-white"}`,children:t("maintenance.statusTab")}),i.jsx("button",{onClick:()=>s("settings"),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${a==="settings"?"text-bambu-green border-bambu-green":"text-bambu-gray border-transparent hover:text-white"}`,children:t("maintenance.settingsTab")})]}),a==="status"?i.jsx("div",{className:"space-y-6",children:o&&o.length>0?[...o].sort((P,T)=>{const j=P.due_count*10+P.warning_count,A=T.due_count*10+T.warning_count;return j!==A?A-j:P.printer_name.localeCompare(T.printer_name)}).map(P=>i.jsx(Stt,{overview:P,onPerform:g,onToggle:_,onSetHours:k,hasPermission:r,t},P.printer_id)):i.jsx(At,{children:i.jsxs(Et,{className:"text-center py-16",children:[i.jsx(Ff,{className:"w-16 h-16 mx-auto mb-4 text-bambu-gray/30"}),i.jsx("p",{className:"text-lg font-medium text-white mb-2",children:t("common.noPrinters")}),i.jsx("p",{className:"text-bambu-gray",children:t("maintenance.configureSettings")})]})})}):i.jsx(_tt,{overview:o,types:c||[],onUpdateInterval:(P,T)=>u.mutate({id:P,data:T}),onAddType:async(P,T)=>{const j=await be.createMaintenanceType(P);for(const A of T)await be.assignMaintenanceType(A,j.id);e.invalidateQueries({queryKey:["maintenanceTypes"]}),e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.typeUpdated"))},onUpdateType:(P,T)=>m.mutate({id:P,data:T}),onDeleteType:P=>p.mutate(P),onRestoreDefaults:()=>f.mutate(),isRestoringDefaults:f.isPending,onAssignType:(P,T)=>v.mutate({printerId:P,typeId:T}),onRemoveItem:P=>b.mutate(P),hasPermission:r,t})]})}const OY=["#ef4444","#f97316","#eab308","#22c55e","#06b6d4","#3b82f6","#8b5cf6","#ec4899","#6b7280"];function Joe({project:t,onClose:e,onSave:n,isLoading:r,currencySymbol:a,t:s}){const[o,l]=w.useState(t?.name||""),[c,d]=w.useState(t?.description||""),[u,m]=w.useState(t?.color||OY[0]),[p,f]=w.useState(t?.target_count?.toString()||""),[y,v]=w.useState(t?.target_parts_count?.toString()||""),[b,g]=w.useState(t?.status||"active"),[_,k]=w.useState(t?.tags||""),[C,N]=w.useState(t?.due_date?.split("T")[0]||""),[P,T]=w.useState(t?.priority||"normal"),[j,A]=w.useState(t?.budget?.toString()||""),F=G=>{G.preventDefault(),n({name:o.trim(),description:c.trim()||void 0,color:u,target_count:p?parseInt(p,10):void 0,target_parts_count:y?parseInt(y,10):void 0,tags:_.trim()||void 0,due_date:C||void 0,priority:P,budget:j.trim()?parseFloat(j):null,...t&&{status:b}})};return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary",children:[i.jsx("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:s(t?"projects.editProject":"projects.newProject")})}),i.jsxs("form",{onSubmit:F,className:"p-4 space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:s("common.name")}),i.jsx("input",{type:"text",value:o,onChange:G=>l(G.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:s("projects.namePlaceholder"),required:!0})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:s("common.description")}),i.jsx("textarea",{value:c,onChange:G=>d(G.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green resize-none",placeholder:s("projects.descriptionPlaceholder"),rows:2})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:s("projects.color")}),i.jsx("div",{className:"flex gap-2 flex-wrap",children:OY.map(G=>i.jsx("button",{type:"button",onClick:()=>m(G),className:`w-8 h-8 rounded-full transition-transform ${u===G?"ring-2 ring-white ring-offset-2 ring-offset-bambu-dark-secondary scale-110":""}`,style:{backgroundColor:G}},G))})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:s("projects.targetPlates")}),i.jsx("input",{type:"number",value:p,onChange:G=>f(G.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:s("projects.targetPlatesPlaceholder"),min:"1"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:s("projects.targetPlatesHelp")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:s("projects.targetParts")}),i.jsx("input",{type:"number",value:y,onChange:G=>v(G.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:s("projects.targetPartsPlaceholder"),min:"1"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:s("projects.targetPartsHelp")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:s("projects.tagsLabel")}),i.jsx("input",{type:"text",value:_,onChange:G=>k(G.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:s("projects.tagsPlaceholder")})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:s("projects.dueDate")}),i.jsx("input",{type:"date",value:C,onChange:G=>N(G.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:s("projects.priority")}),i.jsxs("select",{value:P,onChange:G=>T(G.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green",children:[i.jsx("option",{value:"low",children:s("projects.priorityLow")}),i.jsx("option",{value:"normal",children:s("projects.priorityNormal")}),i.jsx("option",{value:"high",children:s("projects.priorityHigh")}),i.jsx("option",{value:"urgent",children:s("projects.priorityUrgent")})]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:s("projectDetail.cost.budget")}),i.jsxs("div",{className:"relative",children:[i.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray pointer-events-none",children:a}),i.jsx("input",{type:"number",step:"0.01",min:"0",value:j,onChange:G=>A(G.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded pl-8 pr-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:"0.00"})]})]}),t&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:s("common.status")}),i.jsxs("select",{value:b,onChange:G=>g(G.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green",children:[i.jsx("option",{value:"active",children:s("projects.statusActive")}),i.jsx("option",{value:"completed",children:s("projects.statusCompleted")}),i.jsx("option",{value:"archived",children:s("projects.statusArchived")})]})]}),i.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[i.jsx(Ie,{type:"button",variant:"secondary",onClick:e,children:s("common.cancel")}),i.jsx(Ie,{type:"submit",disabled:!o.trim()||r,children:r?i.jsx(ft,{className:"w-4 h-4 animate-spin"}):s(t?"common.save":"projects.create")})]})]})]})})}function Ntt({project:t,onClick:e,onEdit:n,onDelete:r,hasPermission:a,t:s}){const o=t.target_count?Math.round(t.archive_count/t.target_count*100):0,l=t.target_parts_count?Math.round(t.completed_count/t.target_parts_count*100):0,c=t.status==="completed",d=t.status==="archived",[u,m]=w.useState(!1),f=c?{icon:Sc,color:"text-bambu-green",bg:"bg-bambu-green/10"}:d?{icon:Vs,color:"text-bambu-gray",bg:"bg-bambu-gray/10"}:t.queue_count>0?{icon:Zn,color:"text-blue-400",bg:"bg-blue-400/10"}:{icon:_s,color:"text-bambu-gray",bg:"bg-bambu-gray/10"};return i.jsxs("div",{className:"group relative bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary hover:border-bambu-green/50 hover:shadow-lg hover:shadow-bambu-green/5 transition-all duration-300 cursor-pointer overflow-hidden",onClick:e,children:[i.jsx("div",{className:"absolute top-0 left-0 w-1.5 h-full",style:{backgroundColor:t.color||"#6b7280",boxShadow:`0 0 12px ${t.color||"#6b7280"}40`}}),i.jsxs("div",{className:"p-5 pl-6",children:[i.jsxs("div",{className:"flex items-start justify-between mb-4",children:[i.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[i.jsx("div",{className:`p-2 rounded-lg ${f.bg} flex-shrink-0`,children:i.jsx(f.icon,{className:`w-5 h-5 ${f.color}`})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[i.jsx("h3",{className:"font-semibold text-white truncate",children:t.name}),t.target_parts_count?i.jsxs("span",{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${l>=100?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark text-bambu-gray"}`,children:[t.completed_count,"/",t.target_parts_count," ",s("projects.parts")]}):t.target_count?i.jsxs("span",{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${o>=100?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark text-bambu-gray"}`,children:[t.archive_count,"/",t.target_count," ",s("projects.plates")]}):t.completed_count>0?i.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium bg-bambu-dark text-bambu-gray",children:[t.completed_count," ",s("projects.parts")]}):null,c&&i.jsx("span",{className:"text-xs bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full whitespace-nowrap",children:s("projects.done")}),d&&i.jsx("span",{className:"text-xs bg-bambu-gray/20 text-bambu-gray px-2 py-0.5 rounded-full whitespace-nowrap",children:s("projects.statusArchived")})]}),t.description&&i.jsx("p",{className:"text-sm text-bambu-gray/70 mt-1 line-clamp-1",children:t.description}),t.archives&&t.archives.length>0&&(()=>{const y=t.archives.map(_=>_.filament_type).filter(Boolean).flatMap(_=>_.split(",").map(k=>k.trim())).filter(Boolean),v=[...new Set(y)],b=t.archives.map(_=>_.filament_color).filter(Boolean).flatMap(_=>_.split(",").map(k=>k.trim())).filter(_=>_.startsWith("#")||/^[0-9A-Fa-f]{6}$/.test(_)),g=[...new Set(b)];return v.length===0&&g.length===0?null:i.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[v.slice(0,3).map(_=>i.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-bambu-dark text-bambu-gray rounded",children:_},_)),g.length>0&&i.jsxs("div",{className:"flex items-center gap-0.5",children:[g.slice(0,5).map(_=>i.jsx("div",{className:"w-3 h-3 rounded-full border border-black/20",style:{backgroundColor:_.startsWith("#")?_:`#${_}`},title:_},_)),g.length>5&&i.jsxs("span",{className:"text-[10px] text-bambu-gray ml-0.5",children:["+",g.length-5]})]})]})})()]})]}),i.jsxs("div",{className:"relative",onClick:y=>y.stopPropagation(),children:[i.jsx("button",{className:"p-1.5 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors opacity-0 group-hover:opacity-100",onClick:()=>m(!u),children:i.jsx(Th,{className:"w-4 h-4"})}),u&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>m(!1)}),i.jsxs("div",{className:"absolute right-0 top-8 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]",children:[i.jsxs("button",{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${a("projects:update")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{a("projects:update")&&(n(),m(!1))},disabled:!a("projects:update"),title:a("projects:update")?void 0:s("projects.noEditPermission"),children:[i.jsx(Ef,{className:"w-4 h-4"}),s("common.edit")]}),i.jsxs("button",{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${a("projects:delete")?"text-red-400 hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{a("projects:delete")&&(r(),m(!1))},disabled:!a("projects:delete"),title:a("projects:delete")?void 0:s("projects.noDeletePermission"),children:[i.jsx(an,{className:"w-4 h-4"}),s("common.delete")]})]})]})]})]}),i.jsx("div",{className:"mb-4",children:t.target_count||t.target_parts_count?i.jsxs("div",{className:"space-y-3",children:[t.target_count&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between text-xs mb-1",children:[i.jsx("span",{className:"text-bambu-gray",children:s("projects.plates")}),i.jsxs("span",{className:o>=100?"text-bambu-green font-medium":"text-white",children:[t.archive_count," / ",t.target_count]})]}),i.jsx("div",{className:"h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm",children:i.jsx("div",{className:"h-full transition-all duration-500 ease-out rounded-full relative",style:{width:`${Math.min(o,100)}%`,background:o>=100?"linear-gradient(90deg, #22c55e, #4ade80)":`linear-gradient(90deg, ${t.color||"#6b7280"}, ${t.color||"#6b7280"}cc)`,boxShadow:`0 0 8px ${o>=100?"#22c55e":t.color||"#6b7280"}60`}})})]}),t.target_parts_count&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between text-xs mb-1",children:[i.jsx("span",{className:"text-bambu-gray",children:s("projects.parts")}),i.jsxs("span",{className:l>=100?"text-bambu-green font-medium":"text-white",children:[t.completed_count," / ",t.target_parts_count]})]}),i.jsx("div",{className:"h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm",children:i.jsx("div",{className:"h-full transition-all duration-500 ease-out rounded-full relative",style:{width:`${Math.min(l,100)}%`,background:l>=100?"linear-gradient(90deg, #22c55e, #4ade80)":`linear-gradient(90deg, ${t.color||"#6b7280"}, ${t.color||"#6b7280"}cc)`,boxShadow:`0 0 8px ${l>=100?"#22c55e":t.color||"#6b7280"}60`}})})]}),t.failed_count>0&&i.jsxs("div",{className:"text-xs text-red-400",children:[t.failed_count," ",s("projects.failed")]})]}):t.completed_count>0||t.failed_count>0?i.jsxs("div",{className:"flex items-center gap-4 text-xs",children:[t.completed_count>0&&i.jsxs("div",{className:"flex items-center gap-1.5 text-bambu-gray",children:[i.jsx(Vs,{className:"w-3.5 h-3.5"}),i.jsxs("span",{children:[t.completed_count," ",s("projects.completed")]})]}),t.failed_count>0&&i.jsxs("div",{className:"flex items-center gap-1.5 text-red-400",children:[i.jsx(jn,{className:"w-3.5 h-3.5"}),i.jsxs("span",{children:[t.failed_count," ",s("projects.failed")]})]}),t.queue_count>0&&i.jsxs("div",{className:"flex items-center gap-1.5 text-blue-400",children:[i.jsx(Zn,{className:"w-3.5 h-3.5"}),i.jsxs("span",{children:[t.queue_count," ",s("projects.inQueue")]})]})]}):i.jsx("div",{className:"text-xs text-bambu-gray/60 italic",children:s("projects.noPrintsYet")})}),t.archives&&t.archives.length>0&&i.jsxs("div",{className:"mb-4",children:[i.jsx("div",{className:"grid grid-cols-4 gap-1.5",children:t.archives.slice(0,4).map(y=>i.jsxs("div",{className:"relative aspect-square rounded-lg bg-bambu-dark overflow-hidden border border-bambu-dark-tertiary",title:y.print_name||"Unknown",children:[y.thumbnail_path?i.jsx("img",{src:be.getArchiveThumbnail(y.id),alt:y.print_name||"",className:"w-full h-full object-cover"}):i.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray/50",children:i.jsx(Ii,{className:"w-6 h-6"})}),y.status==="failed"&&i.jsx("div",{className:"absolute inset-0 bg-red-500/40 flex items-center justify-center",children:i.jsx(jn,{className:"w-4 h-4 text-white"})})]},y.id))}),t.archive_count>4&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1.5 text-center",children:s("common.more",{count:t.archive_count-4})})]}),i.jsxs("div",{className:"flex items-center justify-between pt-3 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-4 text-xs text-bambu-gray",children:[i.jsxs("div",{className:"flex items-center gap-1.5",title:s("projects.printJobs"),children:[i.jsx(Ki,{className:"w-3.5 h-3.5 text-blue-400"}),i.jsxs("span",{children:[t.archive_count," ",s("projects.plates")]})]}),i.jsxs("div",{className:"flex items-center gap-1.5",title:s("projects.partsPrinted"),children:[i.jsx(Ii,{className:"w-3.5 h-3.5 text-bambu-green"}),i.jsxs("span",{children:[t.completed_count," ",s("projects.parts")]})]}),t.failed_count>0&&i.jsxs("div",{className:"flex items-center gap-1.5 text-red-400",title:s("projects.failedParts"),children:[i.jsx(jn,{className:"w-3.5 h-3.5"}),i.jsx("span",{children:t.failed_count})]}),t.queue_count>0&&i.jsxs("div",{className:"flex items-center gap-1.5 text-yellow-400",title:s("projects.inQueue"),children:[i.jsx(N3,{className:"w-3.5 h-3.5"}),i.jsx("span",{children:t.queue_count})]})]}),i.jsx(fa,{className:"w-4 h-4 text-bambu-gray/50 group-hover:text-bambu-gray transition-colors"})]})]})]})}function Ctt(){const{t}=jt(),e=ol(),n=cn(),{showToast:r}=pn(),{hasPermission:a}=Ar(),[s,o]=w.useState(!1),[l,c]=w.useState(),[d,u]=w.useState("active"),[m,p]=w.useState(null),{data:f}=et({queryKey:["settings"],queryFn:be.getSettings}),y=go(f?.currency||"USD"),{data:v,isLoading:b}=et({queryKey:["projects",d==="all"?void 0:d],queryFn:()=>be.getProjects(d==="all"?void 0:d)}),g=pt({mutationFn:ee=>be.createProject(ee),onSuccess:()=>{n.invalidateQueries({queryKey:["projects"]}),o(!1),r(t("projects.toast.created"),"success")},onError:ee=>{r(ee.message,"error")}}),_=pt({mutationFn:({id:ee,data:ae})=>be.updateProject(ee,ae),onSuccess:()=>{n.invalidateQueries({queryKey:["projects"]}),o(!1),c(void 0),r(t("projects.toast.updated"),"success")},onError:ee=>{r(ee.message,"error")}}),k=pt({mutationFn:ee=>be.deleteProject(ee),onSuccess:()=>{p(null),r(t("projects.toast.deleted"),"success"),setTimeout(()=>window.location.reload(),100)},onError:ee=>{p(null),r(ee.message,"error")}}),C=pt({mutationFn:ee=>be.importProject(ee),onSuccess:()=>{n.invalidateQueries({queryKey:["projects"]}),r(t("projects.toast.imported"),"success")},onError:ee=>{r(ee.message,"error")}}),N=w.useRef(null),P=async()=>{try{const ee=await be.getProjects(),ae=await Promise.all(ee.map(async pe=>await be.exportProjectJson(pe.id))),X=new Blob([JSON.stringify(ae,null,2)],{type:"application/json"}),ce=URL.createObjectURL(X),ue=document.createElement("a");ue.href=ce,ue.download=`bambuddy_projects_${new Date().toISOString().split("T")[0]}.json`,ue.click(),URL.revokeObjectURL(ce),r(t("projects.toast.exported"),"success")}catch(ee){r(ee.message,"error")}},T=()=>{N.current?.click()},j=async ee=>{const ae=ee.target.files?.[0];if(ae){try{if(ae.name.toLowerCase().endsWith(".zip"))await be.importProjectFile(ae),n.invalidateQueries({queryKey:["projects"]}),r(t("projects.toast.imported"),"success");else{const ce=await ae.text(),ue=JSON.parse(ce),pe=Array.isArray(ue)?ue:[ue];for(const K of pe)await C.mutateAsync(K);pe.length>1&&r(t("projects.toast.multipleImported",{count:pe.length}),"success")}}catch(X){r(`${t("projects.toast.importFailed")}: ${X.message}`,"error")}ee.target.value=""}},A=ee=>{l?_.mutate({id:l.id,data:ee}):g.mutate(ee)},F=ee=>{c(ee),o(!0)},G=ee=>{e(`/projects/${ee.id}`)},z=ee=>{p(ee)},Z=()=>{m!==null&&k.mutate(m)},I=v?.reduce((ee,ae)=>(ee[ae.status]=(ee[ae.status]||0)+1,ee.all=(ee.all||0)+1,ee),{})||{};return i.jsxs("div",{className:"p-4 md:p-8 space-y-8",children:[i.jsx("input",{ref:N,type:"file",accept:".json,.zip",onChange:j,className:"hidden"}),i.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[i.jsxs("div",{children:[i.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[i.jsx("div",{className:"p-2.5 bg-bambu-green/10 rounded-xl",children:i.jsx(_s,{className:"w-6 h-6 text-bambu-green"})}),t("projects.title")]}),i.jsx("p",{className:"text-sm text-bambu-gray mt-2 ml-14",children:t("projects.subtitle")})]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs(Ie,{variant:"secondary",onClick:T,disabled:!a("projects:create"),title:a("projects:create")?t("projects.importProject"):t("projects.noImportPermission"),children:[i.jsx(vi,{className:"w-4 h-4 mr-2"}),t("projects.import")]}),i.jsxs(Ie,{variant:"secondary",onClick:P,disabled:!a("projects:read"),title:a("projects:read")?t("projects.exportAll"):t("projects.noExportPermission"),children:[i.jsx(fi,{className:"w-4 h-4 mr-2"}),t("projects.export")]}),i.jsxs(Ie,{onClick:()=>o(!0),className:"sm:w-auto w-full",disabled:!a("projects:create"),title:a("projects:create")?void 0:t("projects.noCreatePermission"),children:[i.jsx(ir,{className:"w-4 h-4 mr-2"}),t("projects.newProject")]})]})]}),i.jsx("div",{className:"flex gap-1 p-1 bg-bambu-dark rounded-xl w-fit",children:[{key:"active",label:t("projects.statusActive"),icon:Zn},{key:"completed",label:t("projects.statusCompleted"),icon:Sc},{key:"archived",label:t("projects.statusArchived"),icon:Vs},{key:"all",label:t("common.all"),icon:_s}].map(({key:ee,label:ae,icon:X})=>i.jsxs("button",{onClick:()=>u(ee),className:`flex items-center gap-2 px-4 py-2 text-sm rounded-lg transition-all ${d===ee?"bg-bambu-card text-white shadow-sm":"text-bambu-gray hover:text-white"}`,children:[i.jsx(X,{className:"w-4 h-4"}),i.jsx("span",{children:ae}),I[ee]>0&&i.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded-full ${d===ee?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark-tertiary"}`,children:I[ee]})]},ee))}),b?i.jsx("div",{className:"flex items-center justify-center py-20",children:i.jsxs("div",{className:"flex flex-col items-center gap-3",children:[i.jsx(ft,{className:"w-8 h-8 animate-spin text-bambu-green"}),i.jsx("p",{className:"text-sm text-bambu-gray",children:t("projects.loading")})]})}):v?.length===0?i.jsxs("div",{className:"flex flex-col items-center justify-center py-20 px-4",children:[i.jsx("div",{className:"p-4 bg-bambu-dark rounded-2xl mb-4",children:i.jsx(_s,{className:"w-12 h-12 text-bambu-gray/50"})}),i.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:d==="all"?t("projects.noProjects"):t("projects.noProjectsFiltered",{status:d})}),i.jsx("p",{className:"text-bambu-gray text-center max-w-md mb-6",children:d==="all"?t("projects.createFirst"):t("projects.noProjectsFilteredHelp",{status:d})}),d==="all"&&i.jsxs(Ie,{onClick:()=>o(!0),disabled:!a("projects:create"),title:a("projects:create")?void 0:t("projects.noCreatePermission"),children:[i.jsx(ir,{className:"w-4 h-4 mr-2"}),t("projects.createFirstButton")]})]}):i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-8",children:v?.map(ee=>i.jsx(Ntt,{project:ee,onClick:()=>G(ee),onEdit:()=>F(ee),onDelete:()=>z(ee.id),hasPermission:a,t},ee.id))}),m!==null&&i.jsx(kn,{title:t("projects.deleteProject"),message:t("projects.deleteConfirm"),confirmText:t("projects.deleteProject"),variant:"danger",onConfirm:Z,onCancel:()=>p(null)}),s&&i.jsx(Joe,{project:l,onClose:()=>{o(!1),c(void 0)},onSave:A,isLoading:g.isPending||_.isPending,currencySymbol:y,t})]})}function Ttt(t){return t>=1e3?`${(t/1e3).toFixed(2)}kg`:`${Math.round(t)}g`}function Att({status:t,t:e}){const n={active:"bg-bambu-green/20 text-bambu-green",completed:"bg-blue-500/20 text-blue-400",archived:"bg-bambu-gray/20 text-bambu-gray"},r=n[t]||n.active,a={active:e("projectDetail.status.active"),completed:e("projectDetail.status.completed"),archived:e("projectDetail.status.archived")};return i.jsx("span",{className:`px-2 py-1 rounded text-sm font-medium ${r}`,children:a[t]||t.charAt(0).toUpperCase()+t.slice(1)})}function IY({icon:t,label:e,value:n,subValue:r,hint:a,color:s="text-bambu-gray"}){return i.jsx(At,{children:i.jsx(Et,{className:"p-4",children:i.jsxs("div",{className:"flex items-center gap-3",title:a,children:[i.jsx("div",{className:`p-2 rounded-lg bg-bambu-dark ${s}`,children:i.jsx(t,{className:"w-5 h-5"})}),i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:e}),i.jsx("p",{className:"text-xl font-semibold text-white",children:n}),r&&i.jsx("p",{className:"text-xs text-bambu-gray/70",children:r})]})]})})})}function Ptt({archives:t,t:e}){return t.length===0?i.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[i.jsx(Ii,{className:"w-12 h-12 mx-auto mb-2 opacity-50"}),i.jsx("p",{children:e("projectDetail.noPrints")})]}):i.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-3",children:t.map(n=>i.jsxs(bo,{to:`/archives?search=${encodeURIComponent(n.print_name||"")}`,className:"group relative aspect-square rounded-lg bg-bambu-dark border border-bambu-dark-tertiary overflow-hidden hover:border-bambu-green transition-colors",children:[n.thumbnail_path?i.jsx("img",{src:be.getArchiveThumbnail(n.id),alt:n.print_name||"Print",className:"w-full h-full object-cover"}):i.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray",children:i.jsx(Ii,{className:"w-8 h-8"})}),n.status==="failed"&&i.jsx("div",{className:"absolute inset-0 bg-red-500/30 flex items-center justify-center",children:i.jsx(Wi,{className:"w-8 h-8 text-white"})}),n.status==="completed"&&i.jsx("div",{className:"absolute top-1 right-1",children:i.jsx(pr,{className:"w-4 h-4 text-bambu-green"})}),i.jsx("div",{className:"absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/80 to-transparent p-2 opacity-0 group-hover:opacity-100 transition-opacity",children:i.jsx("p",{className:"text-xs text-white truncate",children:n.print_name||"Unknown"})})]},n.id))})}function Mtt({priority:t,t:e}){const n={low:{color:"bg-gray-500/20 text-gray-400",label:e("projectDetail.priority.low")},normal:{color:"bg-blue-500/20 text-blue-400",label:e("projectDetail.priority.normal")},high:{color:"bg-orange-500/20 text-orange-400",label:e("projectDetail.priority.high")},urgent:{color:"bg-red-500/20 text-red-400",label:e("projectDetail.priority.urgent")}},{color:r,label:a}=n[t]||n.normal;return i.jsxs("span",{className:`px-2 py-1 rounded text-xs font-medium flex items-center gap-1 ${r}`,children:[t==="urgent"&&i.jsx(jn,{className:"w-3 h-3"}),a]})}function ZD(t,e){if(!t)return null;const n=Qn(t);if(!n)return null;const r=new Date,a=Math.ceil((n.getTime()-r.getTime())/(1e3*60*60*24));return a<0?{color:"text-red-400",label:e("projectDetail.dueDate.overdue")}:a===0?{color:"text-orange-400",label:e("projectDetail.dueDate.today")}:a<=3?{color:"text-yellow-400",label:e("projectDetail.dueDate.daysLeft",{count:a})}:{color:"text-bambu-gray",label:e("projectDetail.dueDate.daysLeft",{count:a})}}function Ett(){const{id:t}=gw(),e=ol(),{t:n}=jt(),r=cn(),{showToast:a}=pn(),{hasPermission:s}=Ar(),[o,l]=w.useState(!1),[c,d]=w.useState(!1),[u,m]=w.useState(""),p=parseInt(t||"0",10),{data:f,isLoading:y,error:v}=et({queryKey:["project",p],queryFn:()=>be.getProject(p),enabled:p>0}),{data:b,isLoading:g}=et({queryKey:["project-archives",p],queryFn:()=>be.getProjectArchives(p),enabled:p>0}),{data:_,isLoading:k}=et({queryKey:["project-bom",p],queryFn:()=>be.getProjectBOM(p),enabled:p>0}),{data:C,isLoading:N}=et({queryKey:["project-timeline",p],queryFn:()=>be.getProjectTimeline(p,20),enabled:p>0}),{data:P}=et({queryKey:["settings"],queryFn:be.getSettings}),{data:T}=et({queryKey:["project-folders",p],queryFn:()=>be.getLibraryFoldersByProject(p),enabled:p>0}),j=go(P?.currency||"USD"),A=P?.time_format||"system",F=pt({mutationFn:De=>be.updateProject(p,De),onSuccess:()=>{r.invalidateQueries({queryKey:["project",p]}),r.invalidateQueries({queryKey:["projects"]}),l(!1),d(!1),a(n("projectDetail.toast.projectUpdated"),"success")},onError:De=>{a(De.message,"error")}}),G=()=>{m(f?.notes||""),d(!0)},z=()=>{F.mutate({notes:u})},Z=()=>{d(!1),m("")},[I,ee]=w.useState(""),[ae,X]=w.useState(1),[ce,ue]=w.useState(""),[pe,K]=w.useState(""),[se,de]=w.useState(""),[ge,Te]=w.useState(!1),[V,J]=w.useState(!1),[D,E]=w.useState(null),[U,W]=w.useState(""),[B,ie]=w.useState(1),[O,$]=w.useState(""),[Y,q]=w.useState(""),[te,oe]=w.useState(""),[he,fe]=w.useState({isOpen:!1,title:"",message:"",onConfirm:()=>{}}),re=pt({mutationFn:De=>be.createBOMItem(p,De),onSuccess:()=>{r.invalidateQueries({queryKey:["project-bom",p]}),r.invalidateQueries({queryKey:["project",p]}),ee(""),X(1),ue(""),K(""),de(""),Te(!1),a(n("projectDetail.toast.partAdded"),"success")},onError:De=>a(De.message,"error")}),L=pt({mutationFn:({itemId:De,data:We})=>be.updateBOMItem(p,De,We),onSuccess:()=>{r.invalidateQueries({queryKey:["project-bom",p]}),r.invalidateQueries({queryKey:["project",p]}),E(null)},onError:De=>a(De.message,"error")}),R=pt({mutationFn:De=>be.deleteBOMItem(p,De),onSuccess:()=>{r.invalidateQueries({queryKey:["project-bom",p]}),r.invalidateQueries({queryKey:["project",p]}),a(n("projectDetail.toast.partRemoved"),"success")},onError:De=>a(De.message,"error")}),ne=De=>{De.preventDefault(),I.trim()&&re.mutate({name:I.trim(),quantity_needed:ae,unit_price:ce?parseFloat(ce):void 0,sourcing_url:pe.trim()||void 0,remarks:se.trim()||void 0})},ve=De=>{const We=De.is_complete?0:De.quantity_needed;L.mutate({itemId:De.id,data:{quantity_acquired:We}})},we=(De,We)=>{fe({isOpen:!0,title:n("projectDetail.bom.deletePart"),message:n("projectDetail.bom.deleteConfirm",{name:We}),onConfirm:()=>{fe(ye=>({...ye,isOpen:!1})),R.mutate(De)}})},me=De=>{E(De),W(De.name),ie(De.quantity_needed),$(De.unit_price?.toString()||""),q(De.sourcing_url||""),oe(De.remarks||"")},Me=De=>{De.preventDefault(),!(!D||!U.trim())&&L.mutate({itemId:D.id,data:{name:U.trim(),quantity_needed:B,unit_price:O?parseFloat(O):void 0,sourcing_url:Y.trim()||void 0,remarks:te.trim()||void 0}})},xe=()=>{E(null)},je=async()=>{try{const{blob:De,filename:We}=await be.exportProjectZip(Number(p)),ye=URL.createObjectURL(De),Ke=document.createElement("a");Ke.href=ye,Ke.download=We||`${f?.name||"project"}_${new Date().toISOString().split("T")[0]}.zip`,Ke.click(),URL.revokeObjectURL(ye),a(n("projectDetail.toast.projectExported"),"success")}catch(De){a(De.message,"error")}},He=pt({mutationFn:()=>be.createTemplateFromProject(p),onSuccess:()=>{r.invalidateQueries({queryKey:["projects"]}),a(n("projectDetail.toast.templateCreated"),"success")},onError:De=>a(De.message,"error")}),Oe=De=>Lf(De,A,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"});if(y)return i.jsx("div",{className:"flex items-center justify-center py-24",children:i.jsx(ft,{className:"w-8 h-8 animate-spin text-bambu-green"})});if(v||!f)return i.jsxs("div",{className:"text-center py-24",children:[i.jsx("p",{className:"text-bambu-gray",children:v?`${n("common.error")}: ${v.message}`:n("projectDetail.notFound")}),i.jsx(Ie,{variant:"secondary",className:"mt-4",onClick:()=>e("/projects"),children:n("projectDetail.backToProjects")})]});const _e=f.stats,Ae=_e?.progress_percent??0,Be=_e?.parts_progress_percent??0;return i.jsxs("div",{className:"p-4 md:p-8 space-y-8",children:[i.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[i.jsx(bo,{to:"/projects",className:"hover:text-white transition-colors",children:n("navigation.projects")}),i.jsx(fa,{className:"w-4 h-4"}),i.jsx("span",{className:"text-white",children:f.name})]}),i.jsxs("div",{className:"flex items-start justify-between",children:[i.jsxs("div",{className:"flex items-center gap-4",children:[i.jsx("button",{onClick:()=>e("/projects"),className:"p-2 rounded-lg bg-bambu-card hover:bg-bambu-dark-tertiary transition-colors",children:i.jsx(GX,{className:"w-5 h-5 text-bambu-gray"})}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"w-4 h-4 rounded-full flex-shrink-0",style:{backgroundColor:f.color||"#6b7280"}}),i.jsxs("div",{children:[i.jsx("h1",{className:"text-2xl font-bold text-white",children:f.name}),f.description&&i.jsx("p",{className:"text-bambu-gray mt-1",children:f.description})]})]}),i.jsx(Att,{status:f.status,t:n})]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs(Ie,{variant:"secondary",onClick:je,disabled:!s("projects:read"),title:s("projects:read")?n("projectDetail.exportProject"):n("projectDetail.noExportPermission"),children:[i.jsx(fi,{className:"w-4 h-4 mr-2"}),n("projectDetail.export")]}),i.jsxs(Ie,{onClick:()=>l(!0),disabled:!s("projects:update"),title:s("projects:update")?void 0:n("projectDetail.noEditPermission"),children:[i.jsx(Ef,{className:"w-4 h-4 mr-2"}),n("common.edit")]})]})]}),(f.target_count||f.target_parts_count)&&i.jsx(At,{children:i.jsxs(Et,{className:"p-4 space-y-4",children:[f.target_count&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-sm text-bambu-gray",children:n("projectDetail.progress.platesProgress")}),i.jsxs("span",{className:"text-sm font-medium text-white",children:[_e?.total_archives||0," / ",f.target_count," ",n("projectDetail.progress.printJobs")]})]}),i.jsx("div",{className:"h-3 bg-bambu-dark rounded-full overflow-hidden",children:i.jsx("div",{className:"h-full transition-all duration-500",style:{width:`${Math.min(Ae,100)}%`,backgroundColor:Ae>=100?"#22c55e":f.color||"#6b7280"}})}),i.jsxs("div",{className:"flex justify-between mt-1",children:[i.jsx("span",{className:"text-xs text-bambu-gray/70",children:n("projectDetail.progress.percentComplete",{percent:Ae.toFixed(0)})}),_e?.remaining_prints!=null&&_e.remaining_prints>0&&i.jsx("span",{className:"text-xs text-bambu-gray/70",children:n("projectDetail.progress.remaining",{count:_e.remaining_prints})})]})]}),f.target_parts_count&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-sm text-bambu-gray",children:n("projectDetail.progress.partsProgress")}),i.jsxs("span",{className:"text-sm font-medium text-white",children:[_e?.completed_prints||0," / ",f.target_parts_count," ",n("projectDetail.progress.parts")]})]}),i.jsx("div",{className:"h-3 bg-bambu-dark rounded-full overflow-hidden",children:i.jsx("div",{className:"h-full transition-all duration-500",style:{width:`${Math.min(Be,100)}%`,backgroundColor:Be>=100?"#22c55e":f.color||"#6b7280"}})}),i.jsxs("div",{className:"flex justify-between mt-1",children:[i.jsx("span",{className:"text-xs text-bambu-gray/70",children:n("projectDetail.progress.percentComplete",{percent:Be.toFixed(0)})}),_e?.remaining_parts!=null&&_e.remaining_parts>0&&i.jsx("span",{className:"text-xs text-bambu-gray/70",children:n("projectDetail.progress.remaining",{count:_e.remaining_parts})})]})]})]})}),_e&&i.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[i.jsx(At,{children:i.jsx(Et,{className:"p-4",children:i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-bambu-green",children:i.jsx(Ii,{className:"w-5 h-5"})}),i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:n("projectDetail.stats.printJobs")}),i.jsxs("p",{className:"text-xl font-semibold text-white",children:[_e.total_archives," ",i.jsx("span",{className:"text-sm font-normal text-bambu-gray",children:n("projectDetail.stats.total")})]}),_e.failed_prints>0&&i.jsx("p",{className:"text-sm text-status-error",children:n("projectDetail.stats.failed",{count:_e.failed_prints})}),i.jsx("p",{className:"text-sm text-bambu-gray",children:n("projectDetail.stats.partsPrinted",{count:_e.completed_prints})})]})]})})}),i.jsx(IY,{icon:Zn,label:n("projectDetail.stats.printTime"),value:Nxe(_e.total_print_time_hours),color:"text-yellow-400"}),i.jsx(IY,{icon:_r,label:n("projectDetail.stats.filamentUsed"),value:Ttt(_e.total_filament_grams),color:"text-purple-400"})]}),_e&&(()=>{const De=_e.estimated_cost+_e.total_energy_cost+_e.bom_cost;return _e.estimated_cost>0||De>0||f.budget!==null})()&&i.jsx(At,{children:i.jsxs(Et,{className:"p-4",children:[i.jsx("h2",{className:"text-lg font-semibold text-white mb-3",children:n("projectDetail.cost.title")}),i.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.cost.filamentCost")}),i.jsxs("p",{className:"text-lg font-semibold text-white",children:[j,_e.estimated_cost.toFixed(2)]})]}),_e.total_energy_kwh>0&&i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.cost.energy")}),i.jsxs("p",{className:"text-lg font-semibold text-white",children:[_e.total_energy_kwh.toFixed(3)," kWh",_e.total_energy_cost>0&&i.jsxs("span",{className:"text-sm text-bambu-gray ml-1",children:["(",j,_e.total_energy_cost.toFixed(2),")"]})]})]}),(()=>{const De=_e.estimated_cost+_e.total_energy_cost+_e.bom_cost;return De<=0?null:i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.cost.totalCost")}),i.jsxs("p",{className:"text-lg font-semibold text-bambu-green",children:[j,De.toFixed(2)]}),_e.bom_cost>0&&i.jsx("p",{className:"text-xs text-bambu-gray/70",children:n("projectDetail.cost.includesBom")})]})})(),f.budget!==null&&(()=>{const De=_e.estimated_cost+_e.total_energy_cost+_e.bom_cost,We=f.budget-De;return i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.cost.budget")}),i.jsxs("p",{className:"text-sm text-bambu-gray",children:[n("projectDetail.cost.total"),": ",i.jsxs("span",{className:"text-white font-semibold",children:[j,f.budget.toFixed(2)]})]}),i.jsxs("p",{className:`text-sm ${We>=0?"text-bambu-green":"text-red-400"}`,children:[n("projectDetail.cost.remaining"),": ",i.jsxs("span",{className:"font-semibold",children:[j,We.toFixed(2)]})]})]})})()]})]})}),f.children&&f.children.length>0&&i.jsx(At,{children:i.jsxs(Et,{className:"p-4",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2 mb-3",children:[i.jsx(vfe,{className:"w-5 h-5"}),n("projectDetail.subProjects.title",{count:f.children.length})]}),i.jsx("div",{className:"space-y-2",children:f.children.map(De=>i.jsxs(bo,{to:`/projects/${De.id}`,className:"flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:De.color||"#6b7280"}}),i.jsx("span",{className:"text-white",children:De.name}),i.jsx("span",{className:`text-xs px-2 py-0.5 rounded ${De.status==="completed"?"bg-status-ok/20 text-status-ok":De.status==="archived"?"bg-bambu-gray/20 text-bambu-gray":"bg-blue-500/20 text-blue-400"}`,children:De.status})]}),De.progress_percent!==null&&i.jsxs("span",{className:"text-sm text-bambu-gray",children:[De.progress_percent.toFixed(0),"%"]})]},De.id))})]})}),f.parent_id&&f.parent_name&&i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx(Ki,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("span",{className:"text-bambu-gray",children:n("projectDetail.partOf")}),i.jsx(bo,{to:`/projects/${f.parent_id}`,className:"text-bambu-green hover:underline",children:f.parent_name})]}),(f.tags||f.due_date||f.priority!=="normal")&&i.jsxs("div",{className:"flex flex-wrap items-center gap-4",children:[f.priority&&f.priority!=="normal"&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.priorityLabel")}),i.jsx(Mtt,{priority:f.priority,t:n})]}),f.due_date&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Xr,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("span",{className:"text-sm text-white",children:Rf(f.due_date,{year:"numeric",month:"short",day:"numeric"})}),ZD(f.due_date,n)&&i.jsxs("span",{className:`text-xs ${ZD(f.due_date,n).color}`,children:["(",ZD(f.due_date,n).label,")"]})]}),f.tags&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Vu,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("div",{className:"flex flex-wrap gap-1",children:f.tags.split(",").map((De,We)=>i.jsx("span",{className:"px-2 py-0.5 bg-bambu-dark-tertiary text-bambu-gray text-xs rounded",children:De.trim()},We))})]})]}),i.jsx(At,{children:i.jsxs(Et,{className:"p-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Ss,{className:"w-5 h-5"}),n("projectDetail.notes.title")]}),c?i.jsxs("div",{className:"flex gap-2",children:[i.jsxs(Ie,{variant:"secondary",size:"sm",onClick:Z,disabled:F.isPending,children:[i.jsx(qt,{className:"w-4 h-4 mr-1"}),n("common.cancel")]}),i.jsxs(Ie,{size:"sm",onClick:z,disabled:F.isPending,children:[F.isPending?i.jsx(ft,{className:"w-4 h-4 animate-spin mr-1"}):i.jsx(as,{className:"w-4 h-4 mr-1"}),n("common.save")]})]}):i.jsxs(Ie,{variant:"secondary",size:"sm",onClick:G,disabled:!s("projects:update"),title:s("projects:update")?void 0:n("projectDetail.notes.noEditPermission"),children:[i.jsx(Ef,{className:"w-4 h-4 mr-1"}),n("common.edit")]})]}),c?i.jsx(yL,{content:u,onChange:m,placeholder:n("projectDetail.notes.placeholder")}):f.notes?i.jsx("div",{className:"prose prose-invert prose-sm max-w-none",dangerouslySetInnerHTML:{__html:Nie.sanitize(f.notes)}}):i.jsx("p",{className:"text-bambu-gray/70 text-sm italic",children:n("projectDetail.notes.empty")})]})}),i.jsx(At,{children:i.jsxs(Et,{className:"p-4",children:[i.jsx("div",{className:"flex items-center justify-between mb-3",children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Mc,{className:"w-5 h-5"}),n("projectDetail.files.title")]})}),i.jsxs("p",{className:"text-xs text-bambu-gray mb-3",children:[i.jsx(bo,{to:"/files",className:"text-bambu-green hover:underline",children:n("projectDetail.files.linkFolders")})," ",n("projectDetail.files.forQuickAccess")]}),T&&T.length>0?i.jsx("div",{className:"space-y-2",children:T.map(De=>i.jsxs(bo,{to:`/files?folder=${De.id}`,className:"flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors",children:[i.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[i.jsx(Mc,{className:"w-5 h-5 text-bambu-green flex-shrink-0"}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("p",{className:"text-sm text-white truncate",children:De.name}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("projectDetail.files.fileCount",{count:De.file_count})})]})]}),i.jsx(fa,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"})]},De.id))}):i.jsx("p",{className:"text-bambu-gray/70 text-sm italic",children:n("projectDetail.files.empty")})]})}),i.jsx(At,{children:i.jsxs(Et,{className:"p-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-4",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(iQ,{className:"w-5 h-5"}),n("projectDetail.bom.title"),_e&&_e.bom_total_items>0&&i.jsxs("span",{className:"text-sm font-normal text-bambu-gray",children:["(",n("projectDetail.bom.acquired",{completed:_e.bom_completed_items,total:_e.bom_total_items}),")"]})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[_&&_.some(De=>De.is_complete)&&i.jsx("button",{onClick:()=>J(!V),className:`text-xs px-2 py-1 rounded transition-colors ${V?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:n(V?"projectDetail.bom.showAll":"projectDetail.bom.hideDone")}),!ge&&i.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>Te(!0),disabled:!s("projects:update"),title:s("projects:update")?void 0:n("projectDetail.bom.noAddPermission"),children:[i.jsx(ir,{className:"w-4 h-4 mr-1"}),n("projectDetail.bom.addPart")]})]})]}),ge&&i.jsxs("form",{onSubmit:ne,className:"bg-bambu-dark rounded-lg p-4 mb-4 space-y-3",children:[i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[i.jsx("input",{type:"text",value:I,onChange:De=>ee(De.target.value),className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.partNamePlaceholder"),autoFocus:!0}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("input",{type:"number",value:ae,onChange:De=>X(parseInt(De.target.value)||1),className:"w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green",min:"1",placeholder:n("projectDetail.bom.qty")}),i.jsx("input",{type:"number",step:"0.01",value:ce,onChange:De=>ue(De.target.value),className:"flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.price",{currency:j})})]})]}),i.jsx("input",{type:"url",value:pe,onChange:De=>K(De.target.value),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.sourcingUrlPlaceholder")}),i.jsx("input",{type:"text",value:se,onChange:De=>de(De.target.value),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.remarksPlaceholder")}),i.jsxs("div",{className:"flex justify-end gap-2",children:[i.jsx(Ie,{type:"button",variant:"secondary",size:"sm",onClick:()=>Te(!1),children:n("common.cancel")}),i.jsx(Ie,{type:"submit",size:"sm",disabled:!I.trim()||re.isPending,children:re.isPending?i.jsx(ft,{className:"w-4 h-4 animate-spin"}):n("projectDetail.bom.addPart")})]})]}),k?i.jsx("div",{className:"flex items-center justify-center py-4",children:i.jsx(ft,{className:"w-6 h-6 animate-spin text-bambu-green"})}):_&&_.length>0?i.jsxs("div",{className:"space-y-2",children:[_.filter(De=>!V||!De.is_complete).map(De=>i.jsx("div",{className:`p-3 rounded-lg transition-colors ${De.is_complete?"bg-status-ok/10":"bg-bambu-dark"}`,children:D?.id===De.id?i.jsxs("form",{onSubmit:Me,className:"space-y-3",children:[i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[i.jsx("input",{type:"text",value:U,onChange:We=>W(We.target.value),className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.partName"),autoFocus:!0}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("input",{type:"number",value:B,onChange:We=>ie(parseInt(We.target.value)||1),className:"w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green",min:"1",placeholder:n("projectDetail.bom.qty")}),i.jsx("input",{type:"number",step:"0.01",value:O,onChange:We=>$(We.target.value),className:"flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.price",{currency:j})})]})]}),i.jsx("input",{type:"url",value:Y,onChange:We=>q(We.target.value),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.sourcingUrlPlaceholder")}),i.jsx("input",{type:"text",value:te,onChange:We=>oe(We.target.value),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.remarksPlaceholder")}),i.jsxs("div",{className:"flex justify-end gap-2",children:[i.jsx(Ie,{type:"button",variant:"secondary",size:"sm",onClick:xe,children:n("common.cancel")}),i.jsx(Ie,{type:"submit",size:"sm",disabled:!U.trim()||L.isPending,children:L.isPending?i.jsx(ft,{className:"w-4 h-4 animate-spin"}):n("common.save")})]})]}):i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx("button",{onClick:()=>s("projects:update")&&ve(De),disabled:L.isPending||!s("projects:update"),title:s("projects:update")?void 0:n("projectDetail.bom.noUpdatePermission"),className:`w-5 h-5 mt-0.5 rounded border-2 flex items-center justify-center transition-colors flex-shrink-0 ${De.is_complete?"bg-status-ok border-status-ok text-white":s("projects:update")?"border-bambu-gray hover:border-bambu-green":"border-bambu-gray/50 cursor-not-allowed"}`,children:De.is_complete&&i.jsx(pr,{className:"w-3 h-3"})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[i.jsxs("p",{className:`text-sm font-medium ${De.is_complete?"text-bambu-gray line-through":"text-white"}`,children:[De.name,i.jsxs("span",{className:"text-bambu-gray font-normal ml-2",children:["x",De.quantity_needed]})]}),De.unit_price!==null&&i.jsxs("span",{className:"text-xs text-bambu-green whitespace-nowrap",children:[j,(De.unit_price*De.quantity_needed).toFixed(2)]})]}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("button",{onClick:()=>s("projects:update")&&me(De),disabled:!s("projects:update"),className:`p-1 rounded transition-colors flex-shrink-0 ${s("projects:update")?"hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white":"text-bambu-gray/50 cursor-not-allowed"}`,title:s("projects:update")?n("common.edit"):n("projectDetail.bom.noEditPermission"),children:i.jsx(Xi,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>s("projects:update")&&we(De.id,De.name),disabled:!s("projects:update"),className:`p-1 rounded transition-colors flex-shrink-0 ${s("projects:update")?"hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-red-400":"text-bambu-gray/50 cursor-not-allowed"}`,title:s("projects:update")?n("common.delete"):n("projectDetail.bom.noDeletePermission"),children:i.jsx(an,{className:"w-4 h-4"})})]})]}),De.sourcing_url&&i.jsxs("a",{href:De.sourcing_url,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 mt-1 text-xs text-blue-400 hover:text-blue-300 transition-colors",onClick:We=>We.stopPropagation(),children:[i.jsx(ni,{className:"w-3 h-3 flex-shrink-0"}),i.jsx("span",{className:"truncate",children:(()=>{try{return new URL(De.sourcing_url).hostname.replace("www.","")}catch{return De.sourcing_url}})()})]}),De.remarks&&i.jsx("p",{className:"mt-1 text-xs text-bambu-gray/80 italic",children:De.remarks})]})]})},De.id)),_e&&_e.bom_cost>0&&i.jsxs("div",{className:"pt-2 mt-2 border-t border-bambu-dark-tertiary flex justify-between text-sm",children:[i.jsx("span",{className:"text-bambu-gray",children:n("projectDetail.bom.totalCost")}),i.jsxs("span",{className:"text-white font-medium",children:[j,_e.bom_cost.toFixed(2)]})]})]}):i.jsx("p",{className:"text-bambu-gray/70 text-sm italic",children:n("projectDetail.bom.empty")})]})}),i.jsx(At,{children:i.jsxs(Et,{className:"p-4",children:[i.jsx("div",{className:"flex items-center justify-between mb-3",children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(k0,{className:"w-5 h-5"}),n("projectDetail.timeline.title")]})}),N?i.jsx("div",{className:"flex items-center justify-center py-4",children:i.jsx(ft,{className:"w-6 h-6 animate-spin text-bambu-green"})}):C&&C.length>0?i.jsx("div",{className:"space-y-3",children:C.slice(0,10).map((De,We)=>i.jsxs("div",{className:"flex gap-3",children:[i.jsxs("div",{className:`w-8 h-8 rounded-full flex items-center justify-center flex-shrink-0 ${De.event_type==="print_completed"?"bg-status-ok/20 text-status-ok":De.event_type==="print_failed"?"bg-status-error/20 text-status-error":De.event_type==="print_started"?"bg-yellow-500/20 text-yellow-400":"bg-bambu-dark-tertiary text-bambu-gray"}`,children:[De.event_type==="print_completed"&&i.jsx(pr,{className:"w-4 h-4"}),De.event_type==="print_failed"&&i.jsx(Wi,{className:"w-4 h-4"}),De.event_type==="print_started"&&i.jsx(_r,{className:"w-4 h-4"}),De.event_type==="queued"&&i.jsx(N3,{className:"w-4 h-4"}),De.event_type==="project_created"&&i.jsx(ir,{className:"w-4 h-4"})]}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("p",{className:"text-sm text-white",children:De.title}),De.description&&i.jsx("p",{className:"text-xs text-bambu-gray truncate",children:De.description}),i.jsx("p",{className:"text-xs text-bambu-gray/70",children:Oe(De.timestamp)})]})]},We))}):i.jsx("p",{className:"text-bambu-gray/70 text-sm italic",children:n("projectDetail.timeline.empty")})]})}),!f.is_template&&i.jsx("div",{className:"flex justify-end",children:i.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>He.mutate(),disabled:He.isPending||!s("projects:create"),title:s("projects:create")?void 0:n("projectDetail.template.noCreatePermission"),children:[He.isPending?i.jsx(ft,{className:"w-4 h-4 animate-spin mr-2"}):i.jsx(To,{className:"w-4 h-4 mr-2"}),n("projectDetail.template.saveAsTemplate")]})}),_e&&(_e.queued_prints>0||_e.in_progress_prints>0)&&i.jsx(At,{children:i.jsxs(Et,{className:"p-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(N3,{className:"w-5 h-5"}),n("projectDetail.queue.title")]}),i.jsx(bo,{to:`/queue?project=${p}`,className:"text-sm text-bambu-green hover:underline",children:n("projectDetail.queue.viewAll")})]}),i.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[_e.in_progress_prints>0&&i.jsx("span",{className:"text-yellow-400",children:n("projectDetail.queue.printing",{count:_e.in_progress_prints})}),_e.queued_prints>0&&i.jsx("span",{className:"text-bambu-gray",children:n("projectDetail.queue.queued",{count:_e.queued_prints})})]})]})}),i.jsxs("div",{children:[i.jsx("div",{className:"flex items-center justify-between mb-4",children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Ii,{className:"w-5 h-5"}),n("projectDetail.prints.title",{count:b?.length||0})]})}),g?i.jsx("div",{className:"flex items-center justify-center py-8",children:i.jsx(ft,{className:"w-6 h-6 animate-spin text-bambu-green"})}):i.jsx(Ptt,{archives:b||[],t:n})]}),o&&i.jsx(Joe,{t:n,currencySymbol:j,project:{...f,archive_count:_e?.total_archives||0,total_items:_e?.total_items||0,completed_count:_e?.completed_prints||0,failed_count:_e?.failed_prints||0,queue_count:_e?.queued_prints||0,progress_percent:_e?.progress_percent||null,archives:[]},onClose:()=>l(!1),onSave:De=>F.mutate(De),isLoading:F.isPending}),he.isOpen&&i.jsx(kn,{title:he.title,message:he.message,confirmText:n("common.delete"),variant:"danger",onConfirm:he.onConfirm,onCancel:()=>fe(De=>({...De,isOpen:!1}))})]})}function jtt({parentId:t,onClose:e,onSave:n,isLoading:r,t:a}){const[s,o]=w.useState(""),l=c=>{c.preventDefault(),n({name:s.trim(),parent_id:t})};return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary",children:[i.jsx("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("fileManager.newFolder")})}),i.jsxs("form",{onSubmit:l,className:"p-4 space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:a("fileManager.folderName")}),i.jsx("input",{type:"text",value:s,onChange:c=>o(c.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:a("fileManager.folderNamePlaceholder"),autoFocus:!0,required:!0})]}),i.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[i.jsx(Ie,{type:"button",variant:"secondary",onClick:e,children:a("common.cancel")}),i.jsx(Ie,{type:"submit",disabled:!s.trim()||r,children:r?i.jsx(ft,{className:"w-4 h-4 animate-spin"}):a("common.create")})]})]})]})})}function Dtt({onClose:t,onSave:e,isLoading:n,t:r}){const[a,s]=w.useState(""),[o,l]=w.useState(""),[c,d]=w.useState(!0),[u,m]=w.useState(!1),p=f=>{f.preventDefault(),e({name:a.trim(),external_path:o.trim(),readonly:c,show_hidden:u})};return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(zk,{className:"w-5 h-5 text-bambu-green"}),r("fileManager.linkExternalFolder")]}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:r("fileManager.linkExternalFolderDescription")})]}),i.jsxs("form",{onSubmit:p,className:"p-4 space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:r("fileManager.folderName")}),i.jsx("input",{type:"text",value:a,onChange:f=>s(f.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:r("fileManager.externalFolderNamePlaceholder"),autoFocus:!0,required:!0})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:r("fileManager.externalPath")}),i.jsx("input",{type:"text",value:o,onChange:f=>l(f.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green font-mono text-sm",placeholder:"/mnt/nas/3d-prints",required:!0}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:r("fileManager.externalPathHelp")})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:c,onChange:f=>d(f.target.checked),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("span",{className:"text-sm text-white",children:r("fileManager.readOnly")}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:["(",r("fileManager.readOnlyHelp"),")"]})]}),i.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:u,onChange:f=>m(f.target.checked),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("span",{className:"text-sm text-white",children:r("fileManager.showHiddenFiles")})]})]}),i.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[i.jsx(Ie,{type:"button",variant:"secondary",onClick:t,children:r("common.cancel")}),i.jsx(Ie,{type:"submit",disabled:!a.trim()||!o.trim()||n,children:n?i.jsx(ft,{className:"w-4 h-4 animate-spin"}):r("fileManager.linkFolder")})]})]})]})})}function Ftt({type:t,currentName:e,onClose:n,onSave:r,isLoading:a,t:s}){const o=t==="file"?e.match(/(\.gcode\.3mf|\.3mf|\.gcode)$/i)?.[1]??"":"",l=t==="file"&&o?e.slice(0,-o.length):e,[c,d]=w.useState(l),u=m=>{m.preventDefault();const p=t==="file"?c.trim()+o:c.trim();c.trim()&&p!==e&&r(p)};return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary",children:[i.jsx("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:s(t==="file"?"fileManager.renameFile":"fileManager.renameFolder")})}),i.jsxs("form",{onSubmit:u,className:"p-4 space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:s("common.name")}),i.jsxs("div",{className:"flex items-center bg-bambu-dark border border-bambu-dark-tertiary rounded focus-within:border-bambu-green",children:[i.jsx("input",{type:"text",value:c,onChange:m=>d(m.target.value),className:"flex-1 bg-transparent px-3 py-2 text-white placeholder-bambu-gray focus:outline-none min-w-0",autoFocus:!0,required:!0}),o&&i.jsx("span",{className:"pr-3 text-bambu-gray text-sm select-none whitespace-nowrap",children:o})]})]}),i.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[i.jsx(Ie,{type:"button",variant:"secondary",onClick:n,children:s("common.cancel")}),i.jsx(Ie,{type:"submit",disabled:!c.trim()||c.trim()===l||a,children:a?i.jsx(ft,{className:"w-4 h-4 animate-spin"}):s("common.rename")})]})]})]})})}function Rtt({folders:t,selectedFiles:e,currentFolderId:n,onClose:r,onMove:a,isLoading:s,t:o}){const[l,c]=w.useState(null),d=(m,p=0)=>{const f=[];for(const y of m)f.push({id:y.id,name:y.name,depth:p}),y.children.length>0&&f.push(...d(y.children,p+1));return f},u=[{id:null,name:o("fileManager.rootNoFolder"),depth:0},...d(t)];return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary",children:[i.jsx("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:o("fileManager.moveFiles",{count:e.length})})}),i.jsxs("div",{className:"p-4 space-y-4",children:[i.jsx("div",{className:"max-h-64 overflow-y-auto space-y-1",children:u.map(m=>i.jsxs("button",{onClick:()=>c(m.id),disabled:m.id===n,className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${l===m.id?"bg-bambu-green/20 text-bambu-green":m.id===n?"opacity-50 cursor-not-allowed text-bambu-gray":"hover:bg-bambu-dark text-white"}`,style:{paddingLeft:`${12+m.depth*16}px`},children:[i.jsx(Mc,{className:"w-4 h-4"}),m.name,m.id===n&&i.jsxs("span",{className:"text-xs text-bambu-gray ml-auto",children:["(",o("fileManager.current"),")"]})]},m.id??"root"))}),i.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[i.jsx(Ie,{type:"button",variant:"secondary",onClick:r,children:o("common.cancel")}),i.jsx(Ie,{onClick:()=>a(l),disabled:s,children:s?i.jsx(ft,{className:"w-4 h-4 animate-spin"}):o("common.move")})]})]})]})})}function Ltt({folder:t,onClose:e,onLink:n,isLoading:r,t:a}){const[s,o]=w.useState("project"),[l,c]=w.useState(t.project_id||t.archive_id||null);w.useState(()=>{t.archive_id&&o("archive")});const{data:d}=et({queryKey:["projects"],queryFn:()=>be.getProjects()}),{data:u}=et({queryKey:["archives-for-link"],queryFn:()=>be.getArchives(void 0,void 0,100)}),m=()=>{n(s==="project"?{project_id:l,archive_id:0}:{project_id:0,archive_id:l})},p=()=>{n({project_id:0,archive_id:0})},f=t.project_id||t.archive_id;return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Fu,{className:"w-5 h-5 text-bambu-green"}),a("fileManager.linkFolder")]}),i.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark rounded",children:i.jsx(qt,{className:"w-5 h-5 text-bambu-gray"})})]}),i.jsxs("div",{className:"p-4 space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("fileManager.linkFolderDescription",{name:t.name})}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("button",{onClick:()=>{o("project"),c(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${s==="project"?"border-bambu-green bg-bambu-green/10 text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,children:[i.jsx(WX,{className:"w-4 h-4"}),a("fileManager.project")]}),i.jsxs("button",{onClick:()=>{o("archive"),c(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${s==="archive"?"border-bambu-green bg-bambu-green/10 text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,children:[i.jsx(Vs,{className:"w-4 h-4"}),a("fileManager.archive")]})]}),i.jsx("div",{className:"max-h-64 overflow-y-auto space-y-1 bg-bambu-dark rounded-lg p-2",children:s==="project"?d&&d.length>0?d.map(y=>i.jsxs("button",{onClick:()=>c(y.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${l===y.id?"bg-bambu-green/20 text-bambu-green":"hover:bg-bambu-dark-tertiary text-white"}`,children:[i.jsx("div",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:y.color||"#00ae42"}}),i.jsx("span",{className:"truncate",children:y.name})]},y.id)):i.jsx("p",{className:"text-sm text-bambu-gray text-center py-4",children:a("fileManager.noProjectsFound")}):u&&u.length>0?u.map(y=>i.jsxs("button",{onClick:()=>c(y.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${l===y.id?"bg-bambu-green/20 text-bambu-green":"hover:bg-bambu-dark-tertiary text-white"}`,children:[i.jsx(pf,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),i.jsx("span",{className:"truncate",children:y.print_name||y.filename})]},y.id)):i.jsx("p",{className:"text-sm text-bambu-gray text-center py-4",children:a("fileManager.noArchivesFound")})})]}),i.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex justify-between",children:[f&&i.jsxs(Ie,{variant:"danger",onClick:p,disabled:r,children:[i.jsx(Df,{className:"w-4 h-4 mr-2"}),a("fileManager.unlink")]}),i.jsxs("div",{className:`flex gap-2 ${f?"":"ml-auto"}`,children:[i.jsx(Ie,{variant:"secondary",onClick:e,children:a("common.cancel")}),i.jsx(Ie,{onClick:m,disabled:!l||r,children:r?i.jsx(ft,{className:"w-4 h-4 animate-spin"}):a("fileManager.link")})]})]})]})})}function ele({folder:t,selectedFolderId:e,onSelect:n,onDelete:r,onLink:a,onRename:s,depth:o=0,wrapNames:l=!1,hasPermission:c,t:d}){const[u,m]=w.useState(!0),[p,f]=w.useState(!1),y=t.children.length>0,v=t.project_id||t.archive_id,b=t.is_external;return i.jsxs("div",{children:[i.jsxs("div",{className:`group flex items-center gap-1 px-2 py-1.5 rounded cursor-pointer transition-colors ${e===t.id?"bg-bambu-green/20 text-bambu-green":"hover:bg-bambu-dark text-white"}`,style:{paddingLeft:`${8+o*12}px`},onClick:()=>n(t.id),children:[y?i.jsx("button",{onClick:g=>{g.stopPropagation(),m(!u)},className:"p-0.5 hover:bg-bambu-dark-tertiary rounded",children:i.jsx(fa,{className:`w-3.5 h-3.5 transition-transform ${u?"rotate-90":""}`})}):i.jsx("div",{className:"w-4.5"}),b?i.jsx(zk,{className:"w-4 h-4 text-purple-400 flex-shrink-0"}):i.jsx(Mc,{className:"w-4 h-4 text-bambu-green flex-shrink-0"}),i.jsx("span",{className:`text-sm flex-1 min-w-0 ${l?"break-all":"truncate"}`,title:t.name,children:t.name}),v&&i.jsxs("button",{onClick:g=>{g.stopPropagation(),a(t)},className:"flex-shrink-0 flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-blue-500/20 text-blue-400 hover:bg-blue-500/30 transition-colors",title:`${t.project_name?`Project: ${t.project_name}`:`Archive: ${t.archive_name}`} (click to change)`,children:[i.jsx(Fu,{className:"w-3 h-3"}),t.project_name?i.jsx(WX,{className:"w-3 h-3"}):i.jsx(Vs,{className:"w-3 h-3"})]}),b&&t.external_readonly&&i.jsx("span",{title:d("fileManager.readOnly"),children:i.jsx(yu,{className:"w-3 h-3 text-amber-400 flex-shrink-0"})}),t.file_count>0&&i.jsx("span",{className:"flex-shrink-0 text-xs text-bambu-gray",children:t.file_count}),!v&&!b&&i.jsx("button",{onClick:g=>{g.stopPropagation(),a(t)},className:"flex-shrink-0 p-1 rounded hover:bg-bambu-dark-tertiary",title:d("fileManager.linkToProjectOrArchive"),children:i.jsx(Fu,{className:"w-3.5 h-3.5 text-bambu-gray hover:text-bambu-green"})}),i.jsx("div",{className:`flex-shrink-0 flex items-center gap-0.5 transition-opacity ${l?"":"opacity-0 group-hover:opacity-100"}`,onClick:g=>g.stopPropagation(),children:i.jsxs("div",{className:"relative",children:[i.jsx("button",{onClick:()=>f(!p),className:"p-1 rounded hover:bg-bambu-dark-tertiary",children:i.jsx(Th,{className:"w-3.5 h-3.5 text-bambu-gray"})}),p&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>f(!1)}),i.jsxs("div",{className:"absolute right-0 top-full mt-1 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]",children:[i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${c("library:update_all")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{c("library:update_all")&&(s(t),f(!1))},disabled:!c("library:update_all"),title:c("library:update_all")?void 0:d("fileManager.noPermissionRenameFolder"),children:[i.jsx(Xi,{className:"w-3.5 h-3.5"}),d("common.rename")]}),i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${c("library:update_all")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{c("library:update_all")&&(a(t),f(!1))},disabled:!c("library:update_all"),title:c("library:update_all")?void 0:d("fileManager.noPermissionLinkFolder"),children:[i.jsx(Fu,{className:"w-3.5 h-3.5"}),d(v?"fileManager.changeLink":"fileManager.linkTo")]}),i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${c("library:delete_all")?"text-red-400 hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{c("library:delete_all")&&(r(t.id),f(!1))},disabled:!c("library:delete_all"),title:c("library:delete_all")?void 0:d("fileManager.noPermissionDeleteFolder"),children:[i.jsx(an,{className:"w-3.5 h-3.5"}),d("common.delete")]})]})]})]})})]}),y&&u&&i.jsx("div",{children:t.children.map(g=>i.jsx(ele,{folder:g,selectedFolderId:e,onSelect:n,onDelete:r,onLink:a,onRename:s,depth:o+1,wrapNames:l,hasPermission:c,t:d},g.id))})]})}function TL(t){const e=t.toLowerCase();return e.endsWith(".gcode")||e.includes(".gcode.")}function Ott({file:t,isSelected:e,isMobile:n,onSelect:r,onDelete:a,onDownload:s,onAddToQueue:o,onPrint:l,onPreview3d:c,onRename:d,onGenerateThumbnail:u,thumbnailVersion:m,hasPermission:p,canModify:f,authEnabled:y,t:v}){const[b,g]=w.useState(!1);return i.jsxs("div",{className:`group relative bg-bambu-dark-secondary rounded-lg border transition-all cursor-pointer overflow-hidden ${e?"border-bambu-green ring-1 ring-bambu-green":"border-bambu-dark-tertiary hover:border-bambu-green/50"}`,onClick:()=>r(t.id),children:[i.jsxs("div",{className:"aspect-square bg-bambu-dark flex items-center justify-center overflow-hidden",children:[t.thumbnail_path?i.jsx("img",{src:`${be.getLibraryFileThumbnailUrl(t.id)}${m?`?v=${m}`:""}`,alt:t.filename,className:"w-full h-full object-cover"}):i.jsx(pf,{className:"w-12 h-12 text-bambu-gray/30"}),i.jsx("div",{className:`absolute top-2 right-2 text-xs px-1.5 py-0.5 rounded font-medium ${t.file_type==="3mf"?"bg-bambu-green/90 text-white":t.file_type==="gcode"?"bg-blue-500/90 text-white":t.file_type==="stl"?"bg-purple-500/90 text-white":"bg-bambu-gray/90 text-white"}`,children:t.file_type.toUpperCase()})]}),i.jsxs("div",{className:"p-3",children:[i.jsx("h3",{className:"text-sm font-medium text-white truncate",title:t.print_name||t.filename,children:t.print_name||t.filename}),i.jsxs("div",{className:"flex items-center gap-3 mt-1 text-xs text-bambu-gray",children:[i.jsx("span",{children:vo(t.file_size)}),t.print_time_seconds&&i.jsxs("span",{className:"flex items-center gap-1",children:[i.jsx(Zn,{className:"w-3 h-3"}),Bs(t.print_time_seconds)]})]}),t.sliced_for_model&&i.jsxs("div",{className:"mt-1 text-xs text-bambu-gray flex items-center gap-1",children:[i.jsx(_r,{className:"w-3 h-3"}),t.sliced_for_model]}),t.print_count>0&&i.jsx("div",{className:"mt-1 text-xs text-bambu-green",children:v("fileManager.printedCount",{count:t.print_count})}),y&&t.created_by_username&&i.jsxs("div",{className:"mt-1 text-xs text-bambu-gray flex items-center gap-1",children:[i.jsx(Gu,{className:"w-3 h-3"}),t.created_by_username]})]}),i.jsxs("div",{className:`absolute bottom-2 right-2 transition-opacity ${n?"opacity-100":"opacity-0 group-hover:opacity-100"}`,onClick:_=>_.stopPropagation(),children:[i.jsx("button",{onClick:()=>g(!b),className:"p-1.5 rounded bg-bambu-dark-secondary/90 hover:bg-bambu-dark-tertiary",children:i.jsx(Th,{className:"w-4 h-4 text-bambu-gray"})}),b&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>g(!1)}),i.jsxs("div",{className:"absolute right-0 bottom-8 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[140px]",children:[l&&TL(t.filename)&&i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${p("printers:control")?"text-bambu-green hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{p("printers:control")&&(l(t),g(!1))},disabled:!p("printers:control"),title:p("printers:control")?void 0:v("fileManager.noPermissionPrint"),children:[i.jsx(_r,{className:"w-3.5 h-3.5"}),v("common.print")]}),o&&TL(t.filename)&&i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${p("queue:create")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{p("queue:create")&&(o(t.id),g(!1))},disabled:!p("queue:create"),title:p("queue:create")?void 0:v("fileManager.noPermissionAddToQueue"),children:[i.jsx(Zn,{className:"w-3.5 h-3.5"}),v("fileManager.schedulePrint")]}),c&&(t.file_type==="3mf"||t.file_type==="gcode"||t.file_type==="stl")&&i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${p("library:read")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{p("library:read")&&(c(t),g(!1))},disabled:!p("library:read"),title:p("library:read")?void 0:"You do not have permission to preview files",children:[i.jsx(aa,{className:"w-3.5 h-3.5"}),"3D Preview"]}),i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${p("library:read")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{p("library:read")&&(s(t.id),g(!1))},disabled:!p("library:read"),title:p("library:read")?void 0:v("fileManager.noPermissionDownload"),children:[i.jsx(fi,{className:"w-3.5 h-3.5"}),v("common.download")]}),d&&i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${f("library","update",t.created_by_id)?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{f("library","update",t.created_by_id)&&(d(t),g(!1))},disabled:!f("library","update",t.created_by_id),title:f("library","update",t.created_by_id)?void 0:v("fileManager.noPermissionRenameFile"),children:[i.jsx(Xi,{className:"w-3.5 h-3.5"}),v("common.rename")]}),u&&t.file_type==="stl"&&i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${f("library","update",t.created_by_id)?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{f("library","update",t.created_by_id)&&(u(t),g(!1))},disabled:!f("library","update",t.created_by_id),title:f("library","update",t.created_by_id)?void 0:v("fileManager.noPermissionGenerateThumbnail"),children:[i.jsx(qu,{className:"w-3.5 h-3.5"}),v("fileManager.generateThumbnail")]}),i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${f("library","delete",t.created_by_id)?"text-red-400 hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{f("library","delete",t.created_by_id)&&(a(t.id),g(!1))},disabled:!f("library","delete",t.created_by_id),title:f("library","delete",t.created_by_id)?void 0:v("fileManager.noPermissionDeleteFile"),children:[i.jsx(an,{className:"w-3.5 h-3.5"}),v("common.delete")]})]})]})]}),i.jsx("div",{className:`absolute top-2 left-2 w-5 h-5 rounded border-2 flex items-center justify-center transition-all ${e?"bg-bambu-green border-bambu-green":`border-white/30 bg-black/30 ${n?"opacity-100":"opacity-0 group-hover:opacity-100"}`}`,children:e&&i.jsx("div",{className:"w-2 h-2 bg-white rounded-sm"})})]})}function Itt(){const{t}=jt(),e=cn(),{showToast:n}=pn(),{hasPermission:r,hasAnyPermission:a,canModify:s,authEnabled:o}=Ar(),[l]=zL(),c=l.get("folder"),d=c?parseInt(c,10):null,[u,m]=w.useState(d),[p,f]=w.useState([]),[y,v]=w.useState(!1),[b,g]=w.useState(!1),[_,k]=w.useState(!1),[C,N]=w.useState(!1),[P,T]=w.useState(null),[j,A]=w.useState(null),[F,G]=w.useState(null),[z,Z]=w.useState(null),[I,ee]=w.useState(null),[ae,X]=w.useState(null),[ce,ue]=w.useState({}),[pe,K]=w.useState(null),[se,de]=w.useState(()=>localStorage.getItem("library-view-mode")||"grid"),[ge,Te]=w.useState(()=>localStorage.getItem("library-wrap-folders")==="true"),[V,J]=w.useState(()=>{const qe=localStorage.getItem("library-sidebar-width");return qe?parseInt(qe,10):256}),[D,E]=w.useState(!1),U=w.useRef(null);w.useEffect(()=>{if(!D)return;document.body.style.userSelect="none",document.body.style.cursor="col-resize";const qe=Ut=>{if(!U.current)return;const Gt=U.current.parentElement?.getBoundingClientRect();if(!Gt)return;const ln=Ut.clientX-Gt.left,Un=Math.min(500,Math.max(200,ln));J(Un)},St=()=>{E(!1),document.body.style.userSelect="",document.body.style.cursor="",localStorage.setItem("library-sidebar-width",String(V))};return document.addEventListener("mousemove",qe),document.addEventListener("mouseup",St),()=>{document.removeEventListener("mousemove",qe),document.removeEventListener("mouseup",St),document.body.style.userSelect="",document.body.style.cursor=""}},[D,V]);const[W,B]=w.useState(""),[ie,O]=w.useState("all"),[$,Y]=w.useState(""),[q,te]=w.useState(()=>localStorage.getItem("library-sort-field")||"name"),[oe,he]=w.useState(()=>localStorage.getItem("library-sort-direction")||"asc"),fe=gie();w.useEffect(()=>{const qe=l.get("folder");if(qe){const St=parseInt(qe,10);m(St)}},[l]);const{data:re}=et({queryKey:["settings"],queryFn:()=>be.getSettings()}),{data:L,isLoading:R}=et({queryKey:["library-folders"],queryFn:()=>be.getLibraryFolders()}),{data:ne,isLoading:ve}=et({queryKey:["library-files",u],queryFn:()=>be.getLibraryFiles(u,u===null)}),{data:we}=et({queryKey:["library-stats"],queryFn:()=>be.getLibraryStats()}),{data:me}=et({queryKey:["users"],queryFn:()=>be.getUsers()}),Me=w.useMemo(()=>{if(!ne)return[];const qe=new Set(ne.map(St=>St.file_type));return Array.from(qe).sort()},[ne]),xe=w.useMemo(()=>{if(!ne)return[];let qe=[...ne];if(W.trim()){const St=W.toLowerCase();qe=qe.filter(Ut=>Ut.filename.toLowerCase().includes(St)||Ut.print_name&&Ut.print_name.toLowerCase().includes(St))}if(ie!=="all"&&(qe=qe.filter(St=>St.file_type===ie)),$.trim()){const St=$.toLowerCase();qe=qe.filter(Ut=>Ut.created_by_username&&Ut.created_by_username.toLowerCase().includes(St))}return qe.sort((St,Ut)=>{let Gt=0;switch(q){case"name":Gt=(St.print_name||St.filename).localeCompare(Ut.print_name||Ut.filename);break;case"date":Gt=(Qn(St.created_at)?.getTime()??0)-(Qn(Ut.created_at)?.getTime()??0);break;case"size":Gt=St.file_size-Ut.file_size;break;case"type":Gt=St.file_type.localeCompare(Ut.file_type);break;case"prints":Gt=St.print_count-Ut.print_count;break}return oe==="asc"?Gt:-Gt}),qe},[ne,W,ie,$,q,oe]),je=w.useMemo(()=>{if(!we||!re)return!1;const qe=(re.library_disk_warning_gb||5)*1024*1024*1024;return we.disk_free_bytesbe.createLibraryFolder(qe),onSuccess:()=>{e.invalidateQueries({queryKey:["library-folders"]}),v(!1),n(t("fileManager.toast.folderCreated"),"success")},onError:qe=>n(qe.message,"error")}),Oe=pt({mutationFn:async qe=>{const St=await be.createExternalFolder(qe);return await be.scanExternalFolder(St.id),St},onSuccess:qe=>{e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-stats"]}),g(!1),m(qe.id),n(t("fileManager.toast.externalFolderLinked"),"success")},onError:qe=>n(qe.message,"error")}),_e=pt({mutationFn:qe=>be.scanExternalFolder(qe),onSuccess:qe=>{e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-stats"]}),n(t("fileManager.toast.folderScanned",{added:qe.added,removed:qe.removed}),"success")},onError:qe=>n(qe.message,"error")}),Ae=pt({mutationFn:qe=>be.deleteLibraryFolder(qe),onSuccess:()=>{e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-stats"]}),u===j?.id&&m(null),A(null),n(t("fileManager.toast.folderDeleted"),"success")},onError:qe=>{A(null),n(qe.message,"error")}}),Be=pt({mutationFn:qe=>be.deleteLibraryFile(qe),onSuccess:()=>{e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-stats"]}),f(qe=>qe.filter(St=>St!==j?.id)),A(null),n(t("fileManager.toast.fileDeleted"),"success")},onError:qe=>{A(null),n(qe.message,"error")}}),De=pt({mutationFn:qe=>be.bulkDeleteLibrary(qe,[]),onSuccess:(qe,St)=>{e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-stats"]}),n(t("fileManager.toast.filesDeleted",{count:St.length}),"success"),f([]),A(null)},onError:qe=>{A(null),n(qe.message,"error")}}),We=pt({mutationFn:({fileIds:qe,folderId:St})=>be.moveLibraryFiles(qe,St),onSuccess:()=>{e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-folders"]}),f([]),k(!1),n(t("fileManager.toast.filesMoved"),"success")},onError:qe=>n(qe.message,"error")}),ye=pt({mutationFn:({id:qe,data:St})=>be.updateLibraryFolder(qe,St),onSuccess:(qe,St)=>{e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["project-folders"]}),e.invalidateQueries({queryKey:["archive-folders"]}),T(null);const Ut=St.data.project_id===0&&St.data.archive_id===0;n(t(Ut?"fileManager.toast.folderUnlinked":"fileManager.toast.folderLinked"),"success")},onError:qe=>n(qe.message,"error")}),Ke=pt({mutationFn:({id:qe,filename:St})=>be.updateLibraryFile(qe,{filename:St}),onSuccess:()=>{e.invalidateQueries({queryKey:["library-files"]}),X(null),n(t("fileManager.toast.fileRenamed"),"success")},onError:qe=>{X(null),n(qe.message,"error")}}),Pe=pt({mutationFn:({id:qe,name:St})=>be.updateLibraryFolder(qe,{name:St}),onSuccess:()=>{e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-files"]}),X(null),n(t("fileManager.toast.folderRenamed"),"success")},onError:qe=>{X(null),n(qe.message,"error")}}),Ye=pt({mutationFn:()=>be.batchGenerateStlThumbnails({all_missing:!0}),onSuccess:qe=>{if(e.invalidateQueries({queryKey:["library-files"]}),qe.succeeded>0){const St=Date.now(),Ut={};qe.results.forEach(Gt=>{Gt.success&&(Ut[Gt.file_id]=St)}),ue(Gt=>({...Gt,...Ut}))}qe.succeeded>0&&qe.failed===0?n(t("fileManager.toast.thumbnailsGenerated",{count:qe.succeeded}),"success"):qe.succeeded>0&&qe.failed>0?n(t("fileManager.toast.thumbnailsGeneratedPartial",{succeeded:qe.succeeded,failed:qe.failed}),"success"):qe.processed===0?n(t("fileManager.toast.noStlMissingThumbnails"),"info"):n(t("fileManager.toast.failedToGenerateThumbnails",{error:qe.results[0]?.error||"Unknown error"}),"error")},onError:qe=>n(qe.message,"error")}),Ve=pt({mutationFn:qe=>be.batchGenerateStlThumbnails({file_ids:[qe]}),onSuccess:qe=>{if(e.invalidateQueries({queryKey:["library-files"]}),qe.succeeded>0){const St=qe.results[0]?.file_id;St&&ue(Ut=>({...Ut,[St]:Date.now()})),n(t("fileManager.toast.thumbnailGenerated"),"success")}else n(t("fileManager.toast.failedToGenerateThumbnail",{error:qe.results[0]?.error||"Unknown error"}),"error")},onError:qe=>n(qe.message,"error")}),Ne=w.useCallback(qe=>{const St=qe.toLowerCase();return St.endsWith(".gcode")||St.includes(".gcode.")},[]),Ce=w.useMemo(()=>ne?ne.filter(qe=>p.includes(qe.id)&&Ne(qe.filename)):[],[ne,p,Ne]),$e=w.useCallback(qe=>{f(St=>St.includes(qe)?St.filter(Ut=>Ut!==qe):[...St,qe])},[]),nt=w.useCallback(()=>{xe.length>0&&f(xe.map(qe=>qe.id))},[xe]),bt=w.useCallback(()=>{f([])},[]),vt=()=>{e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-stats"]})},mt=qe=>{be.downloadLibraryFile(qe).catch(St=>{console.error("Library file download failed:",St)})},Ht=()=>{j&&(j.type==="file"?Be.mutate(j.id):j.type==="folder"?Ae.mutate(j.id):j.type==="bulk"&&De.mutate(p))},Yt=Ae.isPending||Be.isPending||De.isPending,Pt=qe=>{de(qe),localStorage.setItem("library-view-mode",qe)},ut=R||ve,Lt=w.useMemo(()=>{if(!u||!L)return null;const qe=St=>{for(const Ut of St){if(Ut.id===u)return Ut;const Gt=qe(Ut.children);if(Gt)return Gt}return null};return qe(L)},[u,L]);return i.jsxs("div",{className:"p-4 md:p-8 min-h-[calc(100vh-64px)] lg:h-[calc(100vh-64px)] flex flex-col",children:[i.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6",children:[i.jsxs("div",{children:[i.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[i.jsx("div",{className:"p-2.5 bg-bambu-green/10 rounded-xl",children:i.jsx(Mc,{className:"w-6 h-6 text-bambu-green"})}),t("fileManager.title")]}),i.jsx("p",{className:"text-sm text-bambu-gray mt-2 ml-14",children:t("fileManager.subtitle")})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"flex items-center bg-bambu-dark rounded-lg p-1",children:[i.jsx("button",{onClick:()=>Pt("grid"),className:`p-1.5 rounded transition-colors ${se==="grid"?"bg-bambu-dark-secondary text-white":"text-bambu-gray hover:text-white"}`,title:t("fileManager.gridView"),children:i.jsx(ww,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>Pt("list"),className:`p-1.5 rounded transition-colors ${se==="list"?"bg-bambu-dark-secondary text-white":"text-bambu-gray hover:text-white"}`,title:t("fileManager.listView"),children:i.jsx(oT,{className:"w-4 h-4"})})]}),i.jsxs(Ie,{variant:"secondary",onClick:()=>Ye.mutate(),disabled:Ye.isPending||!a("library:update_own","library:update_all"),title:a("library:update_own","library:update_all")?t("fileManager.generateThumbnailsForMissing"):t("fileManager.noPermissionGenerateThumbnail"),children:[Ye.isPending?i.jsx(ft,{className:"w-4 h-4 mr-2 animate-spin"}):i.jsx(qu,{className:"w-4 h-4 mr-2"}),t("fileManager.generateThumbnails")]}),i.jsxs(Ie,{variant:"secondary",onClick:()=>g(!0),disabled:!r("library:upload"),title:r("library:upload")?t("fileManager.linkExternalFolder"):t("fileManager.noPermissionCreateFolder"),children:[i.jsx(zk,{className:"w-4 h-4 mr-2"}),t("fileManager.linkExternal")]}),i.jsxs(Ie,{variant:"secondary",onClick:()=>v(!0),disabled:!r("library:upload"),title:r("library:upload")?void 0:t("fileManager.noPermissionCreateFolder"),children:[i.jsx(bfe,{className:"w-4 h-4 mr-2"}),t("fileManager.newFolder")]}),i.jsxs(Ie,{onClick:()=>N(!0),disabled:!r("library:upload"),title:r("library:upload")?void 0:t("fileManager.noPermissionUpload"),children:[i.jsx(vi,{className:"w-4 h-4 mr-2"}),t("common.upload")]})]})]}),je&&we&&re&&i.jsxs("div",{className:"flex items-center gap-3 mb-4 p-3 bg-amber-500/10 border border-amber-500/30 rounded-lg",children:[i.jsx(jn,{className:"w-5 h-5 text-amber-500 flex-shrink-0"}),i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-sm text-amber-500 font-medium",children:t("fileManager.lowDiskSpaceWarning")}),i.jsx("p",{className:"text-xs text-amber-500/80",children:t("fileManager.lowDiskSpaceDetails",{free:vo(we.disk_free_bytes),total:vo(we.disk_total_bytes),threshold:re.library_disk_warning_gb})})]})]}),we&&i.jsxs("div",{className:"flex flex-wrap items-center gap-3 sm:gap-6 mb-6 p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx(aT,{className:"w-4 h-4 text-bambu-green"}),i.jsxs("span",{className:"text-bambu-gray",children:[t("fileManager.files"),":"]}),i.jsx("span",{className:"text-white font-medium",children:we.total_files})]}),i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx(Mc,{className:"w-4 h-4 text-blue-400"}),i.jsxs("span",{className:"text-bambu-gray",children:[t("fileManager.folders"),":"]}),i.jsx("span",{className:"text-white font-medium",children:we.total_folders})]}),i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx(Gx,{className:"w-4 h-4 text-amber-400"}),i.jsxs("span",{className:"text-bambu-gray",children:[t("fileManager.size"),":"]}),i.jsx("span",{className:"text-white font-medium",children:vo(we.total_size_bytes)})]}),i.jsxs("div",{className:"flex items-center gap-2 text-sm sm:ml-auto",children:[i.jsxs("span",{className:"text-bambu-gray",children:[t("fileManager.free"),":"]}),i.jsx("span",{className:`font-medium ${je?"text-amber-500":"text-white"}`,children:vo(we.disk_free_bytes)})]})]}),i.jsxs("div",{className:"flex-1 flex flex-col lg:flex-row gap-4 lg:gap-6 min-h-0",children:[i.jsx("div",{className:"lg:hidden",children:i.jsxs("select",{value:u??"",onChange:qe=>m(qe.target.value?parseInt(qe.target.value,10):null),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg px-3 py-2.5 text-white focus:outline-none focus:border-bambu-green",children:[i.jsxs("option",{value:"",children:["📁 ",t("fileManager.allFiles")]}),L&&(()=>{const qe=(St,Ut=0)=>{const Gt=[];for(const ln of St)Gt.push({id:ln.id,name:ln.name,fileCount:ln.file_count,depth:Ut}),ln.children.length>0&&Gt.push(...qe(ln.children,Ut+1));return Gt};return qe(L).map(St=>i.jsxs("option",{value:St.id,children:["│ ".repeat(St.depth),"📂 ",St.name," ",St.fileCount>0?`(${St.fileCount})`:""]},St.id))})()]})}),i.jsxs("div",{ref:U,className:"hidden lg:flex flex-shrink-0 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-hidden flex-col relative",style:{width:`${V}px`},children:[i.jsx("div",{className:`absolute right-0 top-0 bottom-0 w-1.5 cursor-col-resize z-10 group/resize flex items-center justify-center transition-colors ${D?"bg-bambu-green":"hover:bg-bambu-green/50"}`,onMouseDown:qe=>{qe.preventDefault(),E(!0)},onDoubleClick:()=>{J(256),localStorage.setItem("library-sidebar-width","256")},title:t("fileManager.dragToResizeTooltip"),children:i.jsxs("div",{className:`flex flex-col gap-1 opacity-0 group-hover/resize:opacity-100 transition-opacity ${D?"opacity-100":""}`,children:[i.jsx("div",{className:"w-0.5 h-0.5 rounded-full bg-white/70"}),i.jsx("div",{className:"w-0.5 h-0.5 rounded-full bg-white/70"}),i.jsx("div",{className:"w-0.5 h-0.5 rounded-full bg-white/70"})]})}),i.jsxs("div",{className:"p-3 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[i.jsx("h2",{className:"text-sm font-medium text-white",children:t("fileManager.folders")}),i.jsx("button",{onClick:()=>{const qe=!ge;Te(qe),localStorage.setItem("library-wrap-folders",String(qe))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${ge?"bg-bambu-green/20 text-bambu-green":"text-bambu-gray hover:text-white hover:bg-bambu-dark"}`,title:t(ge?"fileManager.disableTextWrapping":"fileManager.enableTextWrapping"),children:t("fileManager.wrap")})]}),i.jsxs("div",{className:"flex-1 overflow-y-auto p-2",children:[i.jsxs("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${u===null?"bg-bambu-green/20 text-bambu-green":"hover:bg-bambu-dark text-white"}`,onClick:()=>m(null),children:[i.jsx(pf,{className:"w-4 h-4"}),i.jsx("span",{className:"text-sm",children:t("fileManager.allFiles")})]}),L?.map(qe=>i.jsx(ele,{folder:qe,selectedFolderId:u,onSelect:m,onDelete:St=>A({type:"folder",id:St}),onLink:T,onRename:St=>X({type:"folder",id:St.id,name:St.name}),wrapNames:ge,hasPermission:r,t},qe.id))]})]}),i.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[Lt?.is_external&&i.jsxs("div",{className:"flex items-center gap-3 mb-4 p-3 bg-purple-500/10 border border-purple-500/30 rounded-lg",children:[i.jsx(zk,{className:"w-5 h-5 text-purple-400 flex-shrink-0"}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-sm font-medium text-purple-300",children:t("fileManager.externalFolder")}),Lt.external_readonly&&i.jsxs("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400 flex items-center gap-1",children:[i.jsx(yu,{className:"w-3 h-3"}),t("fileManager.readOnly")]})]}),i.jsx("p",{className:"text-xs text-bambu-gray truncate font-mono",title:Lt.external_path||"",children:Lt.external_path})]}),i.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>u&&_e.mutate(u),disabled:_e.isPending,title:t("fileManager.scanFolder"),children:[_e.isPending?i.jsx(ft,{className:"w-4 h-4 animate-spin"}):i.jsx(vr,{className:"w-4 h-4"}),i.jsx("span",{className:"ml-1.5",children:t("fileManager.scanFolder")})]})]}),ne&&ne.length>0&&i.jsxs("div",{className:"flex flex-wrap items-center gap-2 sm:gap-3 mb-4 p-2 sm:p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-0 z-10 lg:static",children:[i.jsxs("div",{className:"relative w-full sm:w-auto sm:flex-1 sm:max-w-xs",children:[i.jsx(Fr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",placeholder:t("fileManager.searchFiles"),value:W,onChange:qe=>B(qe.target.value),className:"w-full pl-9 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green"})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(sT,{className:"w-4 h-4 text-bambu-gray hidden sm:block"}),i.jsxs("select",{value:ie,onChange:qe=>O(qe.target.value),className:"bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green",children:[i.jsx("option",{value:"all",children:t("fileManager.allTypes")}),Me.map(qe=>i.jsx("option",{value:qe,children:qe.toUpperCase()},qe))]})]}),o&&i.jsxs("div",{className:"relative",children:[i.jsx("input",{type:"text",placeholder:t("fileManager.filterByUser",{defaultValue:"Filter by user"}),value:$,onChange:qe=>Y(qe.target.value),list:"usernames-list",className:`w-32 sm:w-40 px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green ${$?"pr-7":""}`,style:$?{WebkitAppearance:"none",MozAppearance:"textfield"}:void 0}),$&&i.jsx("button",{onClick:()=>Y(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white z-10",children:i.jsx(qt,{className:"w-3 h-3"})}),i.jsx("datalist",{id:"usernames-list",children:me?.map(qe=>i.jsx("option",{value:qe.username},qe.id))})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("select",{value:q,onChange:qe=>{const St=qe.target.value;te(St),localStorage.setItem("library-sort-field",St)},className:"bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green",children:[i.jsx("option",{value:"name",children:t("common.name")}),i.jsx("option",{value:"date",children:t("common.date")}),i.jsx("option",{value:"size",children:t("fileManager.size")}),i.jsx("option",{value:"type",children:t("common.type")}),i.jsx("option",{value:"prints",children:t("fileManager.prints")})]}),i.jsx("button",{onClick:()=>he(qe=>{const St=qe==="asc"?"desc":"asc";return localStorage.setItem("library-sort-direction",St),St}),className:"p-1.5 rounded bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors",title:t(oe==="asc"?"fileManager.ascending":"fileManager.descending"),children:oe==="asc"?i.jsx(Ohe,{className:"w-4 h-4 text-white"}):i.jsx(Mhe,{className:"w-4 h-4 text-white"})})]}),(W||ie!=="all"||$)&&i.jsx("span",{className:"text-sm text-bambu-gray hidden sm:inline",children:t("fileManager.resultsCount",{showing:xe.length,total:ne.length})})]}),xe.length>0&&i.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-4 p-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-[52px] z-10 lg:static",children:[p.length===xe.length&&p.length>0?i.jsxs(Ie,{variant:"secondary",size:"sm",onClick:bt,children:[i.jsx(rl,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("fileManager.deselectAll")})]}):i.jsxs(Ie,{variant:"secondary",size:"sm",onClick:nt,children:[i.jsx(Ys,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("fileManager.selectAll")})]}),p.length>0&&i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"text-sm text-bambu-gray ml-2",children:t("fileManager.selected",{count:p.length})}),i.jsx("div",{className:"hidden sm:block flex-1"}),i.jsxs("div",{className:"w-full sm:w-auto flex flex-wrap items-center gap-2 mt-2 sm:mt-0",children:[Ce.length===1&&i.jsxs(Ie,{variant:"primary",size:"sm",onClick:()=>Z(Ce[0]),disabled:!r("printers:control"),title:r("printers:control")?void 0:t("fileManager.noPermissionPrint"),children:[i.jsx(Ks,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.print")})]}),Ce.length===1&&i.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>ee(Ce[0]),disabled:!r("queue:create"),title:r("queue:create")?void 0:t("fileManager.noPermissionAddToQueue"),children:[i.jsx(Zn,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("fileManager.schedulePrint")})]}),i.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>k(!0),disabled:!a("library:update_own","library:update_all"),title:a("library:update_own","library:update_all")?void 0:t("fileManager.noPermissionMoveFiles"),children:[i.jsx(Age,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.move")})]}),i.jsxs(Ie,{variant:"danger",size:"sm",onClick:()=>{p.length===1?A({type:"file",id:p[0]}):A({type:"bulk",id:0,count:p.length})},disabled:!a("library:delete_own","library:delete_all"),title:a("library:delete_own","library:delete_all")?void 0:t("fileManager.noPermissionDeleteFiles"),children:[i.jsx(an,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.delete")})]}),i.jsxs(Ie,{variant:"secondary",size:"sm",onClick:bt,children:[i.jsx(qt,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.clear")})]})]})]})]}),ut?i.jsx("div",{className:"flex-1 flex items-center justify-center",children:i.jsxs("div",{className:"flex flex-col items-center gap-3",children:[i.jsx(ft,{className:"w-8 h-8 animate-spin text-bambu-green"}),i.jsx("p",{className:"text-sm text-bambu-gray",children:t("fileManager.loadingFiles")})]})}):ne?.length===0?i.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center",children:[i.jsx("div",{className:"p-4 bg-bambu-dark rounded-2xl mb-4",children:i.jsx(pf,{className:"w-12 h-12 text-bambu-gray/50"})}),i.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:t(u!==null?"fileManager.folderIsEmpty":"fileManager.noFilesYet")}),i.jsx("p",{className:"text-bambu-gray text-center max-w-md mb-6",children:t(u!==null?"fileManager.folderEmptyDescription":"fileManager.noFilesDescription")}),i.jsxs(Ie,{onClick:()=>N(!0),disabled:!r("library:upload"),title:r("library:upload")?void 0:t("fileManager.noPermissionUpload"),children:[i.jsx(ir,{className:"w-4 h-4 mr-2"}),t("fileManager.uploadFiles")]})]}):xe.length===0?i.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center",children:[i.jsx("div",{className:"p-4 bg-bambu-dark rounded-2xl mb-4",children:i.jsx(Fr,{className:"w-12 h-12 text-bambu-gray/50"})}),i.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:t("fileManager.noMatchingFiles")}),i.jsx("p",{className:"text-bambu-gray text-center max-w-md mb-6",children:t("fileManager.noMatchingFilesDescription")}),i.jsx(Ie,{variant:"secondary",onClick:()=>{B(""),O("all")},children:t("fileManager.clearFilters")})]}):se==="grid"?i.jsx("div",{className:"flex-1 lg:overflow-y-auto",children:i.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-4",children:xe.map(qe=>i.jsx(Ott,{file:qe,isSelected:p.includes(qe.id),isMobile:fe,t,onSelect:$e,onDelete:St=>A({type:"file",id:St}),onDownload:mt,onAddToQueue:St=>{const Ut=ne?.find(Gt=>Gt.id===St);Ut&&ee(Ut)},onPrint:G,onPreview3d:K,onRename:St=>X({type:"file",id:St.id,name:St.filename}),onGenerateThumbnail:St=>Ve.mutate(St.id),thumbnailVersion:ce[qe.id],hasPermission:r,canModify:s,authEnabled:o},qe.id))})}):i.jsx("div",{className:"flex-1 lg:overflow-y-auto",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-hidden",children:[i.jsxs("div",{className:`hidden sm:grid ${o?"grid-cols-[auto_1fr_120px_100px_100px_100px_80px]":"grid-cols-[auto_1fr_100px_100px_100px_80px]"} gap-4 px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary text-xs text-bambu-gray font-medium`,children:[i.jsx("div",{className:"w-6"}),i.jsx("div",{children:t("common.name")}),o&&i.jsx("div",{children:t("fileManager.uploadedBy",{defaultValue:"Uploaded By"})}),i.jsx("div",{children:t("common.type")}),i.jsx("div",{children:t("fileManager.size")}),i.jsx("div",{children:t("fileManager.prints")}),i.jsx("div",{})]}),xe.map(qe=>i.jsxs("div",{className:`grid ${o?"grid-cols-[auto_1fr_120px_100px_100px_100px_80px]":"grid-cols-[auto_1fr_100px_100px_100px_80px]"} gap-4 px-4 py-3 items-center border-b border-bambu-dark-tertiary last:border-b-0 cursor-pointer hover:bg-bambu-dark/50 transition-colors ${p.includes(qe.id)?"bg-bambu-green/10":""}`,onClick:()=>$e(qe.id),children:[i.jsx("div",{className:`w-5 h-5 rounded border-2 flex items-center justify-center ${p.includes(qe.id)?"bg-bambu-green border-bambu-green":"border-bambu-gray/50"}`,children:p.includes(qe.id)&&i.jsx("div",{className:"w-2 h-2 bg-white rounded-sm"})}),i.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[i.jsxs("div",{className:"relative group/thumb",children:[i.jsx("div",{className:"w-10 h-10 rounded bg-bambu-dark flex-shrink-0 overflow-hidden",children:qe.thumbnail_path?i.jsx("img",{src:`${be.getLibraryFileThumbnailUrl(qe.id)}${ce[qe.id]?`?v=${ce[qe.id]}`:""}`,alt:"",className:"w-full h-full object-cover"}):i.jsx("div",{className:"w-full h-full flex items-center justify-center",children:i.jsx(pf,{className:"w-5 h-5 text-bambu-gray/50"})})}),qe.thumbnail_path&&i.jsx("div",{className:"absolute left-0 top-full mt-2 z-50 hidden group-hover/thumb:block",children:i.jsx("div",{className:"w-48 h-48 rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary shadow-xl overflow-hidden",children:i.jsx("img",{src:`${be.getLibraryFileThumbnailUrl(qe.id)}${ce[qe.id]?`?v=${ce[qe.id]}`:""}`,alt:qe.filename,className:"w-full h-full object-contain"})})})]}),i.jsx("div",{className:"min-w-0",children:i.jsx("div",{className:"text-sm text-white truncate",children:qe.print_name||qe.filename})})]}),o&&i.jsx("div",{className:"text-sm text-bambu-gray flex items-center gap-1",children:qe.created_by_username?i.jsxs(i.Fragment,{children:[i.jsx(Gu,{className:"w-3 h-3"}),i.jsx("span",{className:"truncate",children:qe.created_by_username})]}):"-"}),i.jsx("div",{children:i.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded font-medium ${qe.file_type==="3mf"?"bg-bambu-green/20 text-bambu-green":qe.file_type==="gcode"?"bg-blue-500/20 text-blue-400":qe.file_type==="stl"?"bg-purple-500/20 text-purple-400":"bg-bambu-gray/20 text-bambu-gray"}`,children:qe.file_type.toUpperCase()})}),i.jsx("div",{className:"text-sm text-bambu-gray",children:vo(qe.file_size)}),i.jsx("div",{className:"text-sm text-bambu-gray",children:qe.print_count>0?`${qe.print_count}x`:"-"}),i.jsxs("div",{className:"flex items-center gap-1",onClick:St=>St.stopPropagation(),children:[TL(qe.filename)&&i.jsxs(i.Fragment,{children:[i.jsx("button",{onClick:()=>r("printers:control")&&G(qe),className:`p-1.5 rounded transition-colors ${r("printers:control")?"hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green":"text-bambu-gray/50 cursor-not-allowed"}`,title:r("printers:control")?t("common.print"):t("fileManager.noPermissionPrint"),disabled:!r("printers:control"),children:i.jsx(_r,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>{r("queue:create")&&ee(qe)},className:`p-1.5 rounded transition-colors ${r("queue:create")?"hover:bg-bambu-dark text-bambu-gray hover:text-white":"text-bambu-gray/50 cursor-not-allowed"}`,title:r("queue:create")?t("fileManager.schedulePrint"):t("fileManager.noPermissionAddToQueue"),disabled:!r("queue:create"),children:i.jsx(Zn,{className:"w-4 h-4"})})]}),(qe.file_type==="3mf"||qe.file_type==="gcode"||qe.file_type==="stl")&&i.jsx("button",{onClick:()=>r("library:read")&&K(qe),className:`p-1.5 rounded transition-colors ${r("library:read")?"hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green":"text-bambu-gray/50 cursor-not-allowed"}`,title:r("library:read")?"3D Preview":"You do not have permission to preview files",disabled:!r("library:read"),children:i.jsx(aa,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>r("library:read")&&mt(qe.id),className:`p-1.5 rounded transition-colors ${r("library:read")?"hover:bg-bambu-dark text-bambu-gray hover:text-white":"text-bambu-gray/50 cursor-not-allowed"}`,title:r("library:read")?t("common.download"):t("fileManager.noPermissionDownload"),disabled:!r("library:read"),children:i.jsx(fi,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>s("library","update",qe.created_by_id)&&X({type:"file",id:qe.id,name:qe.filename}),className:`p-1.5 rounded transition-colors ${s("library","update",qe.created_by_id)?"hover:bg-bambu-dark text-bambu-gray hover:text-white":"text-bambu-gray/50 cursor-not-allowed"}`,title:s("library","update",qe.created_by_id)?t("common.rename"):t("fileManager.noPermissionRenameFile"),disabled:!s("library","update",qe.created_by_id),children:i.jsx(Xi,{className:"w-4 h-4"})}),qe.file_type==="stl"&&i.jsx("button",{onClick:()=>s("library","update",qe.created_by_id)&&Ve.mutate(qe.id),className:`p-1.5 rounded transition-colors ${s("library","update",qe.created_by_id)?"hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green":"text-bambu-gray/50 cursor-not-allowed"}`,title:s("library","update",qe.created_by_id)?t("fileManager.generateThumbnail"):t("fileManager.noPermissionGenerateThumbnail"),disabled:Ve.isPending||!s("library","update",qe.created_by_id),children:i.jsx(qu,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>s("library","delete",qe.created_by_id)&&A({type:"file",id:qe.id}),className:`p-1.5 rounded transition-colors ${s("library","delete",qe.created_by_id)?"hover:bg-bambu-dark text-bambu-gray hover:text-red-400":"text-bambu-gray/50 cursor-not-allowed"}`,title:s("library","delete",qe.created_by_id)?t("common.delete"):t("fileManager.noPermissionDeleteFile"),disabled:!s("library","delete",qe.created_by_id),children:i.jsx(an,{className:"w-4 h-4"})})]})]},qe.id))]})})]})]}),y&&i.jsx(jtt,{parentId:u,onClose:()=>v(!1),onSave:qe=>He.mutate(qe),isLoading:He.isPending,t}),b&&i.jsx(Dtt,{onClose:()=>g(!1),onSave:qe=>Oe.mutate(qe),isLoading:Oe.isPending,t}),_&&L&&i.jsx(Rtt,{folders:L,selectedFiles:p,currentFolderId:u,onClose:()=>k(!1),onMove:qe=>We.mutate({fileIds:p,folderId:qe}),isLoading:We.isPending,t}),C&&i.jsx(lie,{folderId:u,onClose:()=>N(!1),onUploadComplete:vt}),P&&i.jsx(Ltt,{folder:P,onClose:()=>T(null),onLink:qe=>ye.mutate({id:P.id,data:qe}),isLoading:ye.isPending,t}),j&&i.jsx(kn,{title:j.type==="folder"?t("fileManager.deleteFolder"):j.type==="bulk"?t("fileManager.deleteFilesCount",{count:j.count}):t("fileManager.deleteFile"),message:j.type==="folder"?t("fileManager.deleteFolderConfirm"):j.type==="bulk"?t("fileManager.deleteFilesConfirm",{count:j.count}):t("fileManager.deleteFileConfirm"),confirmText:t("common.delete"),variant:"danger",isLoading:Yt,loadingText:t("fileManager.deleting"),onConfirm:Ht,onCancel:()=>A(null)}),F&&i.jsx(xd,{mode:"reprint",libraryFileId:F.id,archiveName:F.print_name||F.filename,onClose:()=>G(null),onSuccess:()=>{G(null),e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["archives"]})}}),z&&i.jsx(xd,{mode:"reprint",libraryFileId:z.id,archiveName:z.print_name||z.filename,onClose:()=>Z(null),onSuccess:()=>{Z(null),f([]),e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["archives"]})}}),I&&i.jsx(xd,{mode:"add-to-queue",libraryFileId:I.id,archiveName:I.print_name||I.filename,onClose:()=>ee(null),onSuccess:()=>{ee(null),f([]),e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["queue"]}),e.invalidateQueries({queryKey:["archives"]})}}),pe&&i.jsx(zI,{libraryFileId:pe.id,title:pe.print_name||pe.filename,fileType:pe.file_type,onClose:()=>K(null)}),ae&&i.jsx(Ftt,{type:ae.type,currentName:ae.name,onClose:()=>X(null),onSave:qe=>{ae.type==="file"?Ke.mutate({id:ae.id,filename:qe}):Pe.mutate({id:ae.id,name:qe})},isLoading:Ke.isPending||Pe.isPending,t})]})}const JD=5,ztt=2e3,Utt=3e4,Btt=5e3;function Htt(){const{t}=jt(),e=cn(),{showToast:n}=pn(),{hasPermission:r}=Ar(),{printerId:a}=gw(),s=parseInt(a||"0",10),[o,l]=w.useState("stream"),[c,d]=w.useState(!1),[u,m]=w.useState(!1),[p,f]=w.useState(!0),[y,v]=w.useState(Date.now()),[b,g]=w.useState(!1),[_,k]=w.useState(!1),[C,N]=w.useState(0),[P,T]=w.useState(!1),[j,A]=w.useState(0),[F,G]=w.useState(1),[z,Z]=w.useState({x:0,y:0}),[I,ee]=w.useState(!1),[ae,X]=w.useState({x:0,y:0}),[ce,ue]=w.useState(null),[pe,K]=w.useState(null),se=w.useRef(null),de=w.useRef(null),ge=w.useRef(null),Te=w.useRef(null),V=w.useRef(null),{data:J}=et({queryKey:["printer",s],queryFn:()=>be.getPrinter(s),enabled:s>0}),{data:D}=et({queryKey:["printerStatus",s],queryFn:()=>be.getPrinterStatus(s),refetchInterval:3e4,enabled:s>0}),E=pt({mutationFn:_e=>be.setChamberLight(s,_e),onMutate:async _e=>{await e.cancelQueries({queryKey:["printerStatus",s]});const Ae=e.getQueryData(["printerStatus",s]);return e.setQueryData(["printerStatus",s],Be=>({...Be,chamber_light:_e})),{previousStatus:Ae}},onSuccess:(_e,Ae)=>{n(`Chamber light ${Ae?"on":"off"}`)},onError:(_e,Ae,Be)=>{Be?.previousStatus&&e.setQueryData(["printerStatus",s],Be.previousStatus),n(_e.message||t("printers.toast.failedToControlChamberLight"),"error")}}),U=(D?.state==="RUNNING"||D?.state==="PAUSE")&&(D?.printable_objects_count??0)>=2;w.useEffect(()=>(J&&(document.title=`${J.name} - Camera`),()=>{document.title="Bambuddy"}),[J]);const W=w.useRef(!1);w.useEffect(()=>{const _e=`/api/v1/printers/${s}/camera/stop`;W.current=!1;const Ae=()=>{if(s>0&&!W.current){W.current=!0;const We={},ye=Wu();ye&&(We.Authorization=`Bearer ${ye}`),fetch(_e,{method:"POST",keepalive:!0,headers:We}).catch(()=>{})}},Be=()=>{Ae()};window.addEventListener("beforeunload",Be);const De=se.current;return()=>{window.removeEventListener("beforeunload",Be),De&&(De.src=""),Ae()}},[s]),w.useEffect(()=>{if(p&&!b){const Ae=setTimeout(()=>{f(!1)},o==="stream"?3e3:2e4);return()=>clearTimeout(Ae)}},[o,p,y,b]),w.useEffect(()=>{const _e=()=>{const Ae=!!document.fullscreenElement;k(Ae),G(1),Z({x:0,y:0}),o==="stream"&&!b&&(se.current&&(se.current.src=""),setTimeout(()=>{f(!0),v(Date.now())},200))};return document.addEventListener("fullscreenchange",_e),()=>document.removeEventListener("fullscreenchange",_e)},[o,b]),w.useEffect(()=>{let _e;const Ae=()=>{clearTimeout(_e),_e=setTimeout(()=>{localStorage.setItem("cameraWindowState",JSON.stringify({width:window.outerWidth,height:window.outerHeight,left:window.screenX,top:window.screenY}))},500)};return window.addEventListener("resize",Ae),()=>{clearTimeout(_e),window.removeEventListener("resize",Ae)}},[]),w.useEffect(()=>()=>{ge.current&&clearTimeout(ge.current),Te.current&&clearInterval(Te.current),V.current&&clearInterval(V.current)},[]);const B=w.useCallback(()=>{if(C>=JD){T(!1),m(!0);return}const _e=Math.min(ztt*Math.pow(2,C),Utt);T(!0),A(Math.ceil(_e/1e3)),Te.current=setInterval(()=>{A(Ae=>Ae<=1?(Te.current&&clearInterval(Te.current),0):Ae-1)},1e3),ge.current=setTimeout(()=>{N(Ae=>Ae+1),T(!1),f(!0),m(!1),se.current&&(se.current.src=""),v(Date.now())},_e)},[C]);w.useEffect(()=>{if(o!=="stream"||p||P||b){V.current&&(clearInterval(V.current),V.current=null);return}return V.current=setInterval(async()=>{try{const _e=await be.getCameraStatus(s);(_e.stalled||!_e.active&&!u)&&(console.log(`Stream issue detected: stalled=${_e.stalled}, active=${_e.active}, reconnecting...`),V.current&&(clearInterval(V.current),V.current=null),f(!1),B())}catch{}},Btt),()=>{V.current&&(clearInterval(V.current),V.current=null)}},[o,p,u,P,b,s,B]);const ie=()=>{f(!1),o==="stream"&&C{if(f(!1),m(!1),N(0),T(!1),ge.current&&clearTimeout(ge.current),Te.current&&clearInterval(Te.current),se.current&&!localStorage.getItem("cameraWindowState")){const _e=se.current,Ae=_e.naturalWidth,Be=_e.naturalHeight;if(Ae>0&&Be>0){const ye=window.outerWidth-window.innerWidth,Ke=window.outerHeight-window.innerHeight,Pe=Ae+16+ye,Ye=Be+45+16+Ke;try{window.resizeTo(Pe,Ye)}catch{}}}},$=()=>{if(s>0){const _e={},Ae=Wu();Ae&&(_e.Authorization=`Bearer ${Ae}`),fetch(`/api/v1/printers/${s}/camera/stop`,{method:"POST",headers:_e}).catch(()=>{})}},Y=_e=>{o===_e||b||(g(!0),f(!0),m(!1),N(0),T(!1),G(1),Z({x:0,y:0}),ge.current&&clearTimeout(ge.current),Te.current&&clearInterval(Te.current),se.current&&(se.current.src=""),o==="stream"&&$(),setTimeout(()=>{l(_e),v(Date.now()),g(!1)},100))},q=()=>{b||(g(!0),f(!0),m(!1),N(0),T(!1),ge.current&&clearTimeout(ge.current),Te.current&&clearInterval(Te.current),se.current&&(se.current.src=""),o==="stream"&&$(),setTimeout(()=>{v(Date.now()),g(!1)},100))},te=()=>{de.current&&(document.fullscreenElement?document.exitFullscreen():de.current.requestFullscreen())},oe=()=>{G(_e=>Math.min(_e+.5,4))},he=()=>{G(_e=>{const Ae=Math.max(_e-.5,1);return Ae===1&&Z({x:0,y:0}),Ae})},fe=_e=>{_e.preventDefault(),_e.deltaY<0?oe():he()},re=_e=>{F>1&&(_e.preventDefault(),ee(!0),X({x:_e.clientX-z.x,y:_e.clientY-z.y}))},L=w.useCallback(()=>{if(!de.current)return{x:300,y:200};const _e=de.current.getBoundingClientRect(),Ae=_e.width*(F-1)/2,Be=_e.height*(F-1)/2;return{x:Math.max(50,Ae),y:Math.max(50,Be)}},[F]),R=_e=>{if(I&&F>1){const Ae=_e.clientX-ae.x,Be=_e.clientY-ae.y,De=L();Z({x:Math.max(-De.x,Math.min(De.x,Ae)),y:Math.max(-De.y,Math.min(De.y,Be))})}},ne=()=>{ee(!1)},ve=_e=>{if(_e.length<2)return 0;const Ae=_e[0].clientX-_e[1].clientX,Be=_e[0].clientY-_e[1].clientY;return Math.sqrt(Ae*Ae+Be*Be)},we=_e=>_e.length<2?{x:_e[0].clientX,y:_e[0].clientY}:{x:(_e[0].clientX+_e[1].clientX)/2,y:(_e[0].clientY+_e[1].clientY)/2},me=_e=>{_e.touches.length===2?(_e.preventDefault(),ue(ve(_e.touches)),K(we(_e.touches))):_e.touches.length===1&&F>1&&(_e.preventDefault(),ee(!0),X({x:_e.touches[0].clientX-z.x,y:_e.touches[0].clientY-z.y}))},Me=_e=>{if(_e.touches.length===2&&ce!==null){_e.preventDefault();const Ae=ve(_e.touches),Be=Ae/ce;G(We=>{const ye=Math.max(1,Math.min(4,We*Be));return ye===1&&Z({x:0,y:0}),ye}),ue(Ae);const De=we(_e.touches);if(pe){const We=L();Z(ye=>({x:Math.max(-We.x,Math.min(We.x,ye.x+(De.x-pe.x))),y:Math.max(-We.y,Math.min(We.y,ye.y+(De.y-pe.y)))}))}K(De)}else if(_e.touches.length===1&&I&&F>1){_e.preventDefault();const Ae=_e.touches[0].clientX-ae.x,Be=_e.touches[0].clientY-ae.y,De=L();Z({x:Math.max(-De.x,Math.min(De.x,Ae)),y:Math.max(-De.y,Math.min(De.y,Be))})}},xe=_e=>{_e.touches.length<2&&(ue(null),K(null)),_e.touches.length===0&&ee(!1)},je=()=>{G(1),Z({x:0,y:0})},He=b?"":o==="stream"?`/api/v1/printers/${s}/camera/stream?fps=15&t=${y}`:`/api/v1/printers/${s}/camera/snapshot?t=${y}`,Oe=p||b||P;return s?i.jsxs("div",{ref:de,className:"min-h-screen bg-black flex flex-col",children:[i.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary",children:[i.jsxs("h1",{className:"text-sm font-medium text-white flex items-center gap-2",children:[i.jsx(hx,{className:"w-4 h-4"}),J?.name||`Printer ${s}`]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"flex bg-bambu-dark rounded p-0.5",children:[i.jsx("button",{onClick:()=>Y("stream"),disabled:Oe,className:`px-3 py-1 text-xs rounded transition-colors ${o==="stream"?"bg-bambu-green text-white":"text-bambu-gray hover:text-white disabled:opacity-50"}`,children:t("camera.live")}),i.jsx("button",{onClick:()=>Y("snapshot"),disabled:Oe,className:`px-3 py-1 text-xs rounded transition-colors ${o==="snapshot"?"bg-bambu-green text-white":"text-bambu-gray hover:text-white disabled:opacity-50"}`,children:t("camera.snapshot")})]}),i.jsx("button",{onClick:()=>E.mutate(!D?.chamber_light),disabled:!D?.connected||E.isPending||!r("printers:control"),className:`p-1.5 rounded disabled:opacity-50 ${D?.chamber_light?"bg-yellow-500/20 hover:bg-yellow-500/30":"hover:bg-bambu-dark-tertiary"}`,title:r("printers:control")?t("camera.chamberLight"):t("printers.permission.noControl"),children:i.jsx(jO,{on:D?.chamber_light??!1,className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>d(!0),disabled:!U||!r("printers:control"),className:`p-1.5 rounded disabled:opacity-50 ${U&&r("printers:control")?"hover:bg-bambu-dark-tertiary":""}`,title:r("printers:control")?t(U?"printers.skipObjects.tooltip":"printers.skipObjects.onlyWhilePrinting"):t("printers.permission.noControl"),children:i.jsx(NT,{className:"w-4 h-4 text-bambu-gray"})}),i.jsx("button",{onClick:q,disabled:Oe,className:"p-1.5 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50",title:t(o==="stream"?"camera.restartStream":"camera.refreshSnapshot"),children:i.jsx(vr,{className:`w-4 h-4 text-bambu-gray ${Oe?"animate-spin":""}`})}),i.jsx("button",{onClick:te,className:"p-1.5 hover:bg-bambu-dark-tertiary rounded",title:t(_?"camera.exitFullscreen":"camera.fullscreen"),children:_?i.jsx(nQ,{className:"w-4 h-4 text-bambu-gray"}):i.jsx(gge,{className:"w-4 h-4 text-bambu-gray"})})]})]}),i.jsx("div",{className:"flex-1 flex items-center justify-center p-2 overflow-hidden",onWheel:fe,onMouseMove:R,onMouseUp:ne,onMouseLeave:ne,onTouchStart:me,onTouchMove:Me,onTouchEnd:xe,style:{touchAction:"none"},children:i.jsxs("div",{className:"relative w-full h-full flex items-center justify-center",children:[(p||b)&&!P&&i.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50 z-10",children:i.jsxs("div",{className:"text-center",children:[i.jsx(vr,{className:"w-8 h-8 text-bambu-gray animate-spin mx-auto mb-2"}),i.jsx("p",{className:"text-sm text-bambu-gray",children:t(o==="stream"?"camera.connectingToCamera":"camera.capturingSnapshot")})]})}),P&&i.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/80 z-10",children:i.jsxs("div",{className:"text-center p-4",children:[i.jsx(Bh,{className:"w-10 h-10 text-orange-400 mx-auto mb-3"}),i.jsx("p",{className:"text-white mb-2",children:t("camera.connectionLost")}),i.jsx("p",{className:"text-sm text-bambu-gray mb-3",children:t("camera.reconnecting",{countdown:j,attempt:C+1,max:JD})}),i.jsx("button",{onClick:q,className:"px-4 py-2 bg-bambu-green text-white text-sm rounded hover:bg-bambu-green/80 transition-colors",children:t("camera.reconnectNow")})]})}),u&&!P&&i.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black z-10",children:i.jsxs("div",{className:"text-center p-4",children:[i.jsx(jn,{className:"w-12 h-12 text-orange-400 mx-auto mb-3"}),i.jsx("p",{className:"text-white mb-2",children:t("camera.cameraUnavailable")}),i.jsx("p",{className:"text-xs text-bambu-gray mb-4 max-w-md",children:t("camera.cameraUnavailableDesc")}),i.jsx("button",{onClick:q,className:"px-4 py-2 bg-bambu-green text-white rounded hover:bg-bambu-green/80 transition-colors",children:t("camera.retry")})]})}),i.jsx("img",{ref:se,src:He,alt:t("camera.cameraStream"),className:"max-w-full max-h-full object-contain select-none",style:{transform:`scale(${F}) translate(${z.x/F}px, ${z.y/F}px) rotate(${J?.camera_rotation||0}deg)`,...J?.camera_rotation===90||J?.camera_rotation===270?{maxWidth:"100vh",maxHeight:"100vw"}:{},cursor:F>1?I?"grabbing":"grab":"default"},onError:He?ie:void 0,onLoad:He?O:void 0,onMouseDown:re,draggable:!1},y),i.jsxs("div",{className:"absolute bottom-4 left-4 flex items-center gap-1.5 bg-black/60 rounded-lg px-2 py-1.5",children:[i.jsx("button",{onClick:he,disabled:F<=1,className:"p-1.5 hover:bg-white/10 rounded disabled:opacity-30",title:t("camera.zoomOut"),children:i.jsx(nO,{className:"w-4 h-4 text-white"})}),i.jsxs("button",{onClick:je,className:"px-2 py-1 text-sm text-white hover:bg-white/10 rounded min-w-[48px]",title:t("camera.resetZoom"),children:[Math.round(F*100),"%"]}),i.jsx("button",{onClick:oe,disabled:F>=4,className:"p-1.5 hover:bg-white/10 rounded disabled:opacity-30",title:t("camera.zoomIn"),children:i.jsx(tO,{className:"w-4 h-4 text-white"})})]})]})}),i.jsx(DO,{printerId:s,isOpen:c,onClose:()=>d(!1)})]}):i.jsx("div",{className:"min-h-screen bg-black flex items-center justify-center",children:i.jsx("p",{className:"text-white",children:t("camera.invalidPrinterId")})})}function $tt(t){const e=t.get("show")?.split(",")||["progress","layers","eta","filename","status"],n=parseInt(t.get("fps")||"15",10),r=Math.min(Math.max(isNaN(n)?15:n,1),30),a=t.get("camera"),s=a!=="false"&&a!=="0";return{size:t.get("size")||"medium",fps:r,showCamera:s,showProgress:e.includes("progress"),showLayers:e.includes("layers"),showEta:e.includes("eta"),showFilename:e.includes("filename"),showStatus:e.includes("status"),showPrinter:e.includes("printer")}}function qtt(t,e){if(t.stg_cur_name)return t.stg_cur_name;switch(t.state){case"RUNNING":return e("streamOverlay.status.printing");case"PAUSE":return e("streamOverlay.status.paused");case"FINISH":return e("streamOverlay.status.finished");case"FAILED":return e("streamOverlay.status.failed");case"IDLE":return e("streamOverlay.status.idle");default:return t.state||e("streamOverlay.status.unknown")}}function Vtt(t){switch(t){case"small":return{container:"p-3",text:"text-sm",textLarge:"text-lg",progressHeight:"h-2",icon:"w-3 h-3",gap:"gap-2",logoHeight:"h-12"};case"large":return{container:"p-6",text:"text-xl",textLarge:"text-3xl",progressHeight:"h-4",icon:"w-6 h-6",gap:"gap-4",logoHeight:"h-24"};default:return{container:"p-4",text:"text-base",textLarge:"text-xl",progressHeight:"h-3",icon:"w-4 h-4",gap:"gap-3",logoHeight:"h-16"}}}function Gtt(){const{printerId:t}=gw(),[e]=zL(),{t:n}=jt(),r=cn(),a=parseInt(t||"0",10),[s,o]=w.useState(Date.now()),l=w.useMemo(()=>$tt(e),[e]),c=Vtt(l.size),{data:d}=et({queryKey:["printer",a],queryFn:()=>be.getPrinter(a),enabled:a>0}),{data:u}=et({queryKey:["printerStatus",a],queryFn:()=>be.getPrinterStatus(a),enabled:a>0,refetchInterval:2e3}),{data:m}=et({queryKey:["settings"],queryFn:be.getSettings}),p=m?.time_format||"system";w.useEffect(()=>{if(!a)return;const _=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/api/v1/ws`,k=new WebSocket(_);return k.onmessage=C=>{try{const N=JSON.parse(C.data);N.type==="printer_status"&&N.printer_id===a&&r.setQueryData(["printerStatus",a],N.status)}catch{}},k.onerror=()=>{},()=>{k.close()}},[a,r]),w.useEffect(()=>(document.title=d?`${d.name} - ${n("streamOverlay.title")}`:n("streamOverlay.title"),()=>{document.title="Bambuddy"}),[d,n]);const f=()=>{setTimeout(()=>{o(Date.now())},3e3)};if(!a)return i.jsx("div",{className:"min-h-screen bg-black flex items-center justify-center",children:i.jsx("p",{className:"text-white",children:n("streamOverlay.invalidPrinterId")})});if(!u)return i.jsx("div",{className:"min-h-screen bg-black flex items-center justify-center",children:i.jsx("p",{className:"text-gray-400",children:n("common.loading")})});const y=u.state==="RUNNING"||u.state==="PAUSE",v=u.progress||0,b=`/api/v1/printers/${a}/camera/stream?fps=${l.fps}&t=${s}`;return i.jsxs("div",{className:"min-h-screen bg-black relative overflow-hidden",children:[l.showCamera&&i.jsx("img",{src:b,alt:n("streamOverlay.cameraStream"),className:"absolute inset-0 w-full h-full object-contain",style:d?.camera_rotation?{transform:`rotate(${d.camera_rotation}deg)`}:void 0,onError:f},s),i.jsx("a",{href:"https://github.com/maziggy/bambuddy",target:"_blank",rel:"noopener noreferrer",className:"absolute top-4 right-4 z-10",children:i.jsx("img",{src:"/img/bambuddy_logo_dark_transparent.png",alt:"Bambuddy",className:`${c.logoHeight} object-contain drop-shadow-lg hover:scale-105 transition-transform`})}),i.jsx("div",{className:"absolute bottom-0 left-0 right-0 z-10 bg-gradient-to-t from-black/80 via-black/60 to-transparent",children:i.jsxs("div",{className:`${c.container}`,children:[l.showPrinter&&d&&i.jsxs("div",{className:`flex items-center ${c.gap} mb-2`,children:[i.jsx(_r,{className:`${c.icon} text-white/70`}),i.jsx("span",{className:`${c.text} text-white font-medium`,children:d.name})]}),l.showFilename&&u.current_print&&i.jsx("div",{className:`${c.textLarge} text-white font-semibold mb-2 truncate drop-shadow-md`,children:u.current_print.replace(/\.gcode\.3mf$|\.3mf$|\.gcode$/i,"")}),l.showStatus&&i.jsx("div",{className:`${c.text} text-white/70 mb-2`,children:qtt(u,n)}),l.showProgress&&y&&i.jsxs("div",{className:"mb-3",children:[i.jsxs("div",{className:`flex items-center justify-between mb-1 ${c.text}`,children:[i.jsx("span",{className:"text-white/70",children:n("streamOverlay.progress")}),i.jsxs("span",{className:"text-white font-bold",children:[Math.round(v),"%"]})]}),i.jsx("div",{className:`w-full bg-white/20 rounded-full ${c.progressHeight}`,children:i.jsx("div",{className:`bg-bambu-green ${c.progressHeight} rounded-full transition-all duration-500`,style:{width:`${v}%`}})})]}),y&&(l.showLayers||l.showEta)&&i.jsxs("div",{className:`flex items-center ${c.gap} flex-wrap`,children:[l.showLayers&&u.layer_num!=null&&u.total_layers!=null&&u.total_layers>0&&i.jsxs("div",{className:`flex items-center ${c.gap} text-white/70`,children:[i.jsx(Ki,{className:c.icon}),i.jsxs("span",{className:c.text,children:[i.jsx("span",{className:"text-white",children:u.layer_num}),i.jsx("span",{className:"mx-1",children:"/"}),i.jsx("span",{children:u.total_layers})]})]}),l.showEta&&u.remaining_time!=null&&u.remaining_time>0&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:`flex items-center ${c.gap} text-white/70`,children:[i.jsx(Nu,{className:c.icon}),i.jsx("span",{className:`${c.text} text-white`,children:Bs(u.remaining_time*60)})]}),i.jsxs("div",{className:`flex items-center ${c.gap} text-white/70`,children:[i.jsx(Zn,{className:c.icon}),i.jsxs("span",{className:`${c.text} text-white`,children:[n("streamOverlay.eta")," ",rO(u.remaining_time,p,n)]})]})]})]}),!y&&i.jsx("div",{className:`${c.text} text-white/70 py-2`,children:u.connected?n("streamOverlay.printerIdle"):n("streamOverlay.printerOffline")})]})})]})}function Wtt(){const{t}=jt(),{id:e}=gw(),{mode:n}=ag(),{data:r,isLoading:a,error:s}=et({queryKey:["external-link",e],queryFn:()=>be.getExternalLink(Number(e)),enabled:!!e});return a?i.jsx("div",{className:"flex items-center justify-center h-full",children:i.jsx(ft,{className:"w-8 h-8 text-bambu-green animate-spin"})}):s||!r?i.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4 text-bambu-gray",children:[i.jsx(jn,{className:"w-12 h-12"}),i.jsx("p",{children:t("common.linkNotFound")})]}):i.jsx("iframe",{src:r.url,className:"h-full w-full border-0",style:{colorScheme:n},title:r.name,sandbox:"allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox"})}function zY(){const{id:t}=gw(),e=ol(),n=cn(),{t:r}=jt(),{showToast:a}=pn(),s=!!t,[o,l]=w.useState(""),[c,d]=w.useState(""),[u,m]=w.useState([]),[p,f]=w.useState(""),[y,v]=w.useState(!1),{data:b,isLoading:g}=et({queryKey:["group",t],queryFn:()=>be.getGroup(Number(t)),enabled:s}),{data:_,isLoading:k}=et({queryKey:["permissions"],queryFn:()=>be.getPermissions()});s&&b&&!y&&(l(b.name),d(b.description||""),m(b.permissions),v(!0));const C=pt({mutationFn:X=>be.createGroup(X),onSuccess:()=>{n.invalidateQueries({queryKey:["groups"]}),a(r("groups.toast.created")),e("/settings?tab=users")},onError:X=>{a(X.message,"error")}}),N=pt({mutationFn:X=>be.updateGroup(Number(t),X),onSuccess:()=>{n.invalidateQueries({queryKey:["groups"]}),a(r("groups.toast.updated")),e("/settings?tab=users")},onError:X=>{a(X.message,"error")}}),P=C.isPending||N.isPending,T=()=>{if(!o.trim()){a(r("groups.toast.enterGroupName"),"error");return}s?N.mutate({name:o!==b?.name?o:void 0,description:c,permissions:u}):C.mutate({name:o,description:c||void 0,permissions:u})},j=X=>{m(ce=>ce.includes(X)?ce.filter(ue=>ue!==X):[...ce,X])},A=(X,ce)=>{const ue=X.permissions.map(pe=>pe.value);m(pe=>{const K=pe.filter(se=>!ue.includes(se));return ce?[...K,...ue]:K})},F=X=>X.permissions.every(ce=>u.includes(ce.value)),G=X=>{const ce=X.permissions.filter(ue=>u.includes(ue.value)).length;return ce>0&&ce{_&&m(_.all_permissions)},Z=()=>{m([])},I=p.toLowerCase(),ee=w.useMemo(()=>_?I?_.categories.map(X=>({...X,permissions:X.permissions.filter(ce=>ce.label.toLowerCase().includes(I))})).filter(X=>X.permissions.length>0):_.categories:[],[_,I]),ae=_?.all_permissions.length??0;return g||k?i.jsx("div",{className:"flex items-center justify-center py-16",children:i.jsx(ft,{className:"w-8 h-8 text-bambu-green animate-spin"})}):i.jsxs("div",{className:"space-y-6 max-w-5xl mx-auto",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("button",{onClick:()=>e("/settings?tab=users"),className:"p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors",children:i.jsx(GX,{className:"w-5 h-5"})}),i.jsx("h1",{className:"text-xl font-bold text-white",children:r(s?"groups.editor.title":"groups.editor.createTitle")})]}),s&&b?.is_system&&i.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 rounded-lg bg-yellow-500/10 border border-yellow-500/20 text-yellow-400 text-sm",children:[i.jsx(jn,{className:"w-4 h-4 shrink-0"}),r("groups.form.systemGroupWarning")]}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:r("groups.form.groupName")}),i.jsx("input",{type:"text",value:o,onChange:X=>l(X.target.value),disabled:s&&b?.is_system,className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors disabled:opacity-50",placeholder:r("groups.form.groupNamePlaceholder")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:r("groups.form.description")}),i.jsx("input",{type:"text",value:c,onChange:X=>d(X.target.value),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:r("groups.form.descriptionPlaceholder")})]})]}),i.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs("span",{className:"text-sm text-bambu-gray",children:[r("groups.editor.permissionsSelected",{count:u.length})," / ",ae]}),i.jsx(Ie,{size:"sm",variant:"ghost",onClick:z,children:r("groups.editor.selectAll")}),i.jsx(Ie,{size:"sm",variant:"ghost",onClick:Z,children:r("groups.editor.clearAll")})]}),i.jsxs("div",{className:"relative",children:[i.jsx(Fr,{className:"w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray"}),i.jsx("input",{type:"text",value:p,onChange:X=>f(X.target.value),placeholder:r("groups.editor.search"),className:"pl-9 pr-4 py-2 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors w-64"})]})]}),ee.length===0?i.jsx("div",{className:"text-center py-12 text-bambu-gray",children:r("groups.editor.noResults")}):i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:ee.map(X=>{const ce=_.categories.find(de=>de.name===X.name),ue=ce.permissions.filter(de=>u.includes(de.value)).length,pe=ce.permissions.length,K=F(ce),se=G(ce);return i.jsxs(At,{children:[i.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between px-4 py-3 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary rounded-t-xl",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs("button",{type:"button",onClick:()=>A(ce,!K),className:`w-5 h-5 rounded border flex items-center justify-center transition-colors shrink-0 ${K?"bg-bambu-green border-bambu-green":se?"bg-bambu-green/50 border-bambu-green":"border-bambu-gray hover:border-white"}`,children:[K&&i.jsx(Zr,{className:"w-3 h-3 text-white"}),se&&!K&&i.jsx(Uk,{className:"w-3 h-3 text-white"})]}),i.jsx(A3,{className:"w-4 h-4 text-bambu-gray shrink-0"}),i.jsx("span",{className:"text-white font-medium text-sm",children:X.name})]}),i.jsxs("span",{className:"text-xs text-bambu-gray tabular-nums",children:[ue,"/",pe]})]}),i.jsx("div",{className:"p-3 space-y-1",children:X.permissions.map(de=>i.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-secondary cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:u.includes(de.value),onChange:()=>j(de.value),className:"w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark-secondary"}),i.jsx("span",{className:"text-sm text-bambu-gray",children:de.label})]},de.value))})]},X.name)})}),i.jsx("div",{className:"h-16"}),i.jsxs("div",{className:"fixed bottom-0 left-0 right-0 z-20 px-6 py-3 bg-bambu-dark-secondary border-t border-bambu-dark-tertiary flex items-center justify-center gap-3",children:[i.jsx(Ie,{variant:"secondary",onClick:()=>e("/settings?tab=users"),children:r("common.cancel")}),i.jsx(Ie,{onClick:T,disabled:P||!o.trim(),children:P?i.jsxs(i.Fragment,{children:[i.jsx(ft,{className:"w-4 h-4 animate-spin"}),r("common.saving")]}):i.jsxs(i.Fragment,{children:[i.jsx(as,{className:"w-4 h-4"}),r("common.save")]})})]})]})}const AL={material:"",subtype:"",brand:"",color_name:"",rgba:"808080FF",label_weight:1e3,core_weight:250,core_weight_catalog_id:null,weight_used:0,slicer_filament:"",note:"",cost_per_kg:null};function tle(t,e=!1){const n={};return e?(t.material||(n.material="Material is required"),{isValid:Object.keys(n).length===0,errors:n}):(t.slicer_filament||(n.slicer_filament="Slicer preset is required"),t.material||(n.material="Material is required"),t.brand||(n.brand="Brand is required"),t.subtype||(n.subtype="Subtype is required"),{isValid:Object.keys(n).length===0,errors:n})}const nle=["PLA","PETG","ABS","TPU","ASA","PC","PA","PVA","HIPS","PA-CF","PETG-CF","PLA-CF"],Ktt=["Bambu","PolyLite","PolyTerra","eSUN","Overture","Fiberon","SUNLU","Inland","Hatchbox","Generic"],x0=["Basic","Matte","Silk","Tough","HF","High Flow","Engineering","Galaxy","Glow","Marble","Metal","Rainbow","Sparkle","Wood","Translucent","Transparent","Clear","Lite","Pro","Plus","Max","Super","Ultra","Flex","Soft","Hard","Strong","Impact","Heat Resistant","UV Resistant","ESD","Conductive","Magnetic","Gradient","Dual Color","Tri Color","Multicolor"],rle=[{name:"Black",hex:"000000"},{name:"White",hex:"FFFFFF"},{name:"Gray",hex:"808080"},{name:"Red",hex:"FF0000"},{name:"Orange",hex:"FFA500"},{name:"Yellow",hex:"FFFF00"},{name:"Green",hex:"00AE42"},{name:"Blue",hex:"0066FF"},{name:"Purple",hex:"8B00FF"},{name:"Pink",hex:"FF69B4"},{name:"Brown",hex:"8B4513"},{name:"Silver",hex:"C0C0C0"}],Ytt=[{name:"Dark Red",hex:"8B0000"},{name:"Crimson",hex:"DC143C"},{name:"Coral",hex:"FF7F50"},{name:"Salmon",hex:"FA8072"},{name:"Dark Orange",hex:"FF8C00"},{name:"Peach",hex:"FFDAB9"},{name:"Gold",hex:"FFD700"},{name:"Khaki",hex:"F0E68C"},{name:"Lemon",hex:"FFF44F"},{name:"Lime",hex:"32CD32"},{name:"Forest Green",hex:"228B22"},{name:"Olive",hex:"808000"},{name:"Mint",hex:"98FF98"},{name:"Teal",hex:"008080"},{name:"Navy",hex:"000080"},{name:"Sky Blue",hex:"87CEEB"},{name:"Royal Blue",hex:"4169E1"},{name:"Cyan",hex:"00FFFF"},{name:"Turquoise",hex:"40E0D0"},{name:"Violet",hex:"EE82EE"},{name:"Magenta",hex:"FF00FF"},{name:"Indigo",hex:"4B0082"},{name:"Lavender",hex:"E6E6FA"},{name:"Plum",hex:"DDA0DD"},{name:"Hot Pink",hex:"FF69B4"},{name:"Rose",hex:"FF007F"},{name:"Blush",hex:"FFB6C1"},{name:"Chocolate",hex:"D2691E"},{name:"Tan",hex:"D2B48C"},{name:"Beige",hex:"F5F5DC"},{name:"Maroon",hex:"800000"},{name:"Dark Gray",hex:"404040"},{name:"Light Gray",hex:"D3D3D3"},{name:"Charcoal",hex:"36454F"},{name:"Ivory",hex:"FFFFF0"},{name:"Bambu Green",hex:"00AE42"},{name:"Jade White",hex:"E8E8E8"},{name:"Titan Gray",hex:"5A5A5A"}],UY=[...rle,...Ytt],ile="bambuddy-recent-colors",Xtt=8,Qtt=[{code:"GFL00",name:"Bambu PLA Basic",displayName:"Bambu PLA Basic",isCustom:!1,allCodes:["GFL00"]},{code:"GFL01",name:"Bambu PLA Matte",displayName:"Bambu PLA Matte",isCustom:!1,allCodes:["GFL01"]},{code:"GFL05",name:"Generic PLA",displayName:"Generic PLA",isCustom:!1,allCodes:["GFL05"]},{code:"GFG00",name:"Bambu PETG Basic",displayName:"Bambu PETG Basic",isCustom:!1,allCodes:["GFG00"]},{code:"GFG05",name:"Generic PETG",displayName:"Generic PETG",isCustom:!1,allCodes:["GFG05"]},{code:"GFB00",name:"Bambu ABS Basic",displayName:"Bambu ABS Basic",isCustom:!1,allCodes:["GFB00"]},{code:"GFB05",name:"Generic ABS",displayName:"Generic ABS",isCustom:!1,allCodes:["GFB05"]},{code:"GFA00",name:"Bambu ASA Basic",displayName:"Bambu ASA Basic",isCustom:!1,allCodes:["GFA00"]},{code:"GFU00",name:"Bambu TPU 95A",displayName:"Bambu TPU 95A",isCustom:!1,allCodes:["GFU00"]},{code:"GFU05",name:"Generic TPU",displayName:"Generic TPU",isCustom:!1,allCodes:["GFU05"]},{code:"GFC00",name:"Bambu PC Basic",displayName:"Bambu PC Basic",isCustom:!1,allCodes:["GFC00"]},{code:"GFN00",name:"Bambu PA Basic",displayName:"Bambu PA Basic",isCustom:!1,allCodes:["GFN00"]},{code:"GFN05",name:"Generic PA",displayName:"Generic PA",isCustom:!1,allCodes:["GFN05"]},{code:"GFS00",name:"Bambu PLA-CF",displayName:"Bambu PLA-CF",isCustom:!1,allCodes:["GFS00"]},{code:"GFT00",name:"Bambu PETG-CF",displayName:"Bambu PETG-CF",isCustom:!1,allCodes:["GFT00"]},{code:"GFNC0",name:"Bambu PA-CF",displayName:"Bambu PA-CF",isCustom:!1,allCodes:["GFNC0"]},{code:"GFV00",name:"Bambu PVA",displayName:"Bambu PVA",isCustom:!1,allCodes:["GFV00"]}];function Qh(t){let e=t.replace(/@.*$/,"").trim();e=e.replace(/\(Custom\)/i,"").trim(),e=e.replace(/^[#*]+\s*/,"").trim();const n=["PLA-CF","PETG-CF","ABS-GF","ASA-CF","PA-CF","PAHT-CF","PA6-CF","PA6-GF","PPA-CF","PPA-GF","PET-CF","PPS-CF","PC-CF","PC-ABS","ABS-GF","PCTG","PETG","PLA","ABS","ASA","PC","PA","TPU","PVA","HIPS","BVOH","PPS","PEEK","PEI"];let r="",a=-1;for(const c of n){const d=e.toUpperCase().indexOf(c.toUpperCase());if(d!==-1){r=c,a=d;break}}let s="";a>0&&(s=e.substring(0,a).trim(),s=s.replace(/[-_\s]+$/,""));let o="";a!==-1&&r&&(o=e.substring(a+r.length).trim(),o=o.replace(/^[-_\s]+/,""));let l="";for(const c of x0)if(o.toLowerCase().includes(c.toLowerCase())){l=c;break}if(!l&&s)for(const c of x0){const d=new RegExp(`\\s+${c}$`,"i");if(d.test(s)){l=c,s=s.replace(d,"").trim();break}}return{brand:s,material:r,variant:l}}function ale(t,e){const n=new Set(Ktt);for(const r of t){const{brand:a}=Qh(r.name);a&&a.length>1&&n.add(a)}if(e)for(const r of e)if(r.filament_vendor&&r.filament_vendor.length>1)n.add(r.filament_vendor);else{const{brand:a}=Qh(r.name);a&&a.length>1&&n.add(a)}return Array.from(n).sort((r,a)=>r.localeCompare(a))}function Ztt(t){const e=t.filter(r=>r.preset_type==="filament");if(e.length===0)return[];const n=new Map;for(const r of e){const a=r.name.replace(/@.*$/,"").trim(),s=n.get(a);if(s)s.allCodes.push(String(r.id));else{const o=r.filament_type||String(r.id);n.set(a,{code:o,name:a,displayName:a,isCustom:!1,allCodes:[o]})}}return Array.from(n.values()).sort((r,a)=>r.displayName.localeCompare(a.displayName))}function sle(t,e,n){if(t.length>0){const r=[],a=new Map;for(const s of t)if(s.is_custom){const o=s.name.toUpperCase();(e.size===0||Array.from(e).some(c=>o.includes(c))||!o.includes("@"))&&r.push({code:s.setting_id,name:s.name,displayName:`${s.name} (Custom)`,isCustom:!0,allCodes:[s.setting_id]})}else{const o=s.name.replace(/@.*$/,"").trim(),l=a.get(o);l?l.allCodes.push(s.setting_id):a.set(o,{code:s.setting_id,name:o,displayName:o,isCustom:!1,allCodes:[s.setting_id]})}return[...r,...Array.from(a.values())].sort((s,o)=>s.displayName.localeCompare(o.displayName))}if(n&&n.length>0){const r=Ztt(n);if(r.length>0)return r}return Qtt}function ole(t,e){if(!t)return;let n=e.find(r=>r.code===t);if(n||(n=e.find(r=>r.allCodes.includes(t))),!n){const r=t.toLowerCase();n=e.find(a=>a.code.toLowerCase()===r||a.allCodes.some(s=>s.toLowerCase()===r))}return n}function lle(){try{const t=localStorage.getItem(ile);if(t)return JSON.parse(t)}catch{}return[]}function cle(t,e){const n=e.filter(a=>a.hex.toUpperCase()!==t.hex.toUpperCase()),r=[t,...n].slice(0,Xtt);try{localStorage.setItem(ile,JSON.stringify(r))}catch{}return r}function e3(t,e){if(!e.material)return!1;const r=(t.name||"").replace(/^High Flow[_\s]+/i,"").replace(/^Standard[_\s]+/i,"").replace(/^HF[_\s]+/i,"").replace(/^S[_\s]+/i,"").trim(),a=Qh(r);return!(!(a.material.toUpperCase()===e.material.toUpperCase())||e.brand&&!(a.brand.toLowerCase().includes(e.brand.toLowerCase())||e.brand.toLowerCase().includes(a.brand.toLowerCase()))||e.subtype&&!(a.variant.toLowerCase().includes(e.subtype.toLowerCase())||e.subtype.toLowerCase().includes(a.variant.toLowerCase())||r.toLowerCase().includes(e.subtype.toLowerCase())))}function dle({formData:t,updateField:e,cloudAuthenticated:n,loadingCloudPresets:r,presetInputValue:a,setPresetInputValue:s,selectedPresetOption:o,filamentOptions:l,availableBrands:c,availableMaterials:d,quickAdd:u,quantity:m,onQuantityChange:p,errors:f}){const{t:y}=jt(),[v,b]=w.useState(!1),[g,_]=w.useState(!1),[k,C]=w.useState(!1),[N,P]=w.useState(!1),[T,j]=w.useState(""),[A,F]=w.useState(""),[G,z]=w.useState(""),[Z,I]=w.useState(String(t.label_weight)),[ee,ae]=w.useState(!1),X=w.useRef(null),ce=w.useRef(null),ue=w.useRef(null),pe=w.useRef(null);w.useEffect(()=>{const V=J=>{X.current&&!X.current.contains(J.target)&&b(!1),pe.current&&!pe.current.contains(J.target)&&P(!1),ce.current&&!ce.current.contains(J.target)&&_(!1),ue.current&&!ue.current.contains(J.target)&&C(!1)};return document.addEventListener("mousedown",V),()=>document.removeEventListener("mousedown",V)},[]);const K=w.useMemo(()=>{if(!a)return l;const V=a.toLowerCase();return l.filter(J=>J.displayName.toLowerCase().includes(V)||J.code.toLowerCase().includes(V))},[l,a]),se=w.useMemo(()=>{if(!T)return c;const V=T.toLowerCase();return c.filter(D=>D.toLowerCase().includes(V)).sort((D,E)=>{const U=D.toLowerCase()===V,W=E.toLowerCase()===V;return U&&!W?-1:!U&&W?1:D.localeCompare(E)})},[c,T]),de=w.useMemo(()=>{if(!A)return x0;const V=A.toLowerCase();return x0.filter(J=>J.toLowerCase().includes(V))},[A]),ge=w.useMemo(()=>{if(!G)return d;const V=G.toLowerCase();return d.filter(D=>D.toLowerCase().includes(V)).sort((D,E)=>{const U=D.toLowerCase()===V,W=E.toLowerCase()===V;return U&&!W?-1:!U&&W?1:D.localeCompare(E)})},[G,d]);w.useEffect(()=>{ee||I(String(t.label_weight))},[t.label_weight,ee]);const Te=V=>{e("slicer_filament",V.code),s(V.displayName),b(!1);const J=Qh(V.name);J.material&&e("material",J.material),J.brand&&e("brand",J.brand),J.variant&&e("subtype",J.variant)};return i.jsxs("div",{className:"space-y-4",children:[!u&&i.jsx("div",{className:"flex items-center gap-2 text-xs text-bambu-gray",children:r?i.jsxs(i.Fragment,{children:[i.jsx(ft,{className:"w-3 h-3 animate-spin"})," ",y("inventory.loadingPresets")]}):n?i.jsxs(i.Fragment,{children:[i.jsx(Vx,{className:"w-3 h-3 text-bambu-green"})," ",y("inventory.cloudConnected")]}):i.jsxs(i.Fragment,{children:[i.jsx(Tpe,{className:"w-3 h-3"})," ",y("inventory.cloudNotConnected")]})}),!u&&i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:[y("inventory.slicerPreset")," *"]}),i.jsxs("div",{className:"relative",ref:X,children:[i.jsx(Fr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none"}),i.jsx("input",{type:"text",className:"w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green",placeholder:y("inventory.searchPresets"),value:a,onChange:V=>{s(V.target.value),b(!0)},onFocus:()=>{b(!0),s("")}}),v&&i.jsx("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto",children:K.length===0?i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:y("inventory.noPresetsFound")}):K.map(V=>i.jsx("button",{type:"button",className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary truncate ${o?.code===V.code?"bg-bambu-green/10 text-bambu-green":"text-white"}`,onClick:()=>Te(V),children:V.displayName},V.code))})]}),o&&i.jsxs("div",{className:"mt-1 text-xs text-bambu-gray",children:[y("inventory.selectedPreset"),": ",i.jsx("span",{className:"font-mono text-bambu-green",children:o.code})]}),f?.slicer_filament&&i.jsx("p",{className:"mt-1 text-xs text-red-400",children:f.slicer_filament})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:[y("inventory.material")," *"]}),i.jsxs("div",{className:"relative",ref:pe,children:[i.jsx("input",{type:"text",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green",placeholder:y("inventory.selectMaterial"),value:N?G:t.material,onChange:V=>{z(V.target.value),P(!0)},onFocus:()=>{P(!0),z("")}}),i.jsx(zn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none"}),N&&i.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto",children:[ge.length===0?i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:y("inventory.noResults")}):ge.map(V=>i.jsx("button",{type:"button",className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${t.material===V?"bg-bambu-green/10 text-bambu-green":"text-white"}`,onClick:()=>{e("material",V),P(!1),z("")},children:V},V)),G&&!ge.includes(G)&&i.jsx("button",{type:"button",className:"w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary",onClick:()=>{e("material",G),P(!1),z("")},children:y("inventory.useCustomMaterial",{material:G})})]})]}),f?.material&&i.jsx("p",{className:"mt-1 text-xs text-red-400",children:f.material})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:[y("inventory.brand"),!u&&" *"]}),i.jsxs("div",{className:"relative",ref:ce,children:[i.jsx("input",{type:"text",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green",placeholder:y("inventory.searchBrand"),value:g?T:t.brand,onChange:V=>{j(V.target.value),_(!0)},onFocus:()=>{_(!0),j("")}}),i.jsx(zn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none"}),g&&i.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto",children:[se.length===0?i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:y("inventory.noResults")}):se.map(V=>i.jsx("button",{type:"button",className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${t.brand===V?"bg-bambu-green/10 text-bambu-green":"text-white"}`,onClick:()=>{e("brand",V),_(!1),j("")},children:V},V)),T&&!se.includes(T)&&i.jsx("button",{type:"button",className:"w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary",onClick:()=>{e("brand",T),_(!1),j("")},children:y("inventory.useCustomBrand",{brand:T})})]})]}),f?.brand&&i.jsx("p",{className:"mt-1 text-xs text-red-400",children:f.brand})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:[y("inventory.subtype"),!u&&" *"]}),i.jsxs("div",{className:"relative",ref:ue,children:[i.jsx("input",{type:"text",value:k?A:t.subtype,onChange:V=>{F(V.target.value),C(!0)},onFocus:()=>{C(!0),F("")},placeholder:"Basic, Matte, Silk...",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green"}),i.jsx(zn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none"}),k&&i.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto",children:[de.length===0?i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:y("inventory.noResults")}):de.map(V=>i.jsx("button",{type:"button",className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${t.subtype===V?"bg-bambu-green/10 text-bambu-green":"text-white"}`,onClick:()=>{e("subtype",V),C(!1),F("")},children:V},V)),A&&!x0.some(V=>V.toLowerCase()===A.toLowerCase().trim())&&i.jsx("button",{type:"button",className:"w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary",onClick:()=>{e("subtype",A),C(!1),F("")},children:y("inventory.useCustomBrand",{brand:A})})]})]}),f?.subtype&&i.jsx("p",{className:"mt-1 text-xs text-red-400",children:f.subtype})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:y("inventory.labelWeight")}),i.jsxs("div",{className:"relative",children:[i.jsx("input",{type:"number",className:"w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green",value:Z,min:0,onFocus:()=>ae(!0),onChange:V=>I(V.target.value),onBlur:()=>{ae(!1);const V=Z.trim(),J=Number(V);if(!V||!Number.isFinite(J)||J<0){I(String(t.label_weight));return}const D=Math.round(J);e("label_weight",D),I(String(D))}}),i.jsx("span",{className:"absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray",children:"g"})]})]}),u&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:y("inventory.quantity")}),i.jsx("input",{type:"number",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green",value:m,min:1,max:100,onChange:V=>{const J=Math.max(1,Math.min(100,parseInt(V.target.value)||1));p(J)}})]})]})}function ule({formData:t,updateField:e,recentColors:n,onColorUsed:r,catalogColors:a}){const{t:s}=jt(),[o,l]=w.useState(!1),[c,d]=w.useState(""),u=t.rgba.replace("#","").substring(0,6),m=g=>u.toUpperCase()===g.toUpperCase(),p=(g,_)=>{e("rgba",g.toUpperCase()+"FF"),e("color_name",_),r({name:_,hex:g})},f=w.useMemo(()=>{if(a.length===0)return[];const g=t.brand?.trim(),_=t.material?.toLowerCase().trim(),k=t.subtype?.toLowerCase().trim();if(!g&&!_)return[];const C=g?g.toLowerCase().split(/[\s\-_]+/).filter(T=>T.length>=2):[],N=T=>{if(C.length===0)return!0;const j=T.toLowerCase();return C.some(A=>j.includes(A))};if(g&&!_){const T=a.filter(j=>N(j.manufacturer));if(T.length>0)return T.map(j=>({name:j.color_name,hex:j.hex_color.replace("#","").substring(0,6),manufacturer:j.manufacturer,material:typeof j.material=="string"?j.material:void 0}))}const P=_&&k?`${_} ${k}`:"";if(P){const T=a.filter(A=>N(A.manufacturer)&&A.material?.toLowerCase()===P);if(T.length>0)return T.map(A=>({name:A.color_name,hex:A.hex_color.replace("#","").substring(0,6),manufacturer:A.manufacturer,material:typeof A.material=="string"?A.material:void 0}));const j=P.replace(/\+$/,"");if(j!==P){const A=a.filter(F=>N(F.manufacturer)&&F.material?.toLowerCase()===j);if(A.length>0)return A.map(F=>({name:F.color_name,hex:F.hex_color.replace("#","").substring(0,6),manufacturer:F.manufacturer,material:typeof F.material=="string"?F.material:void 0}))}}if(_){const T=a.filter(j=>N(j.manufacturer)&&(!j.material||j.material.toLowerCase().startsWith(_)));if(T.length>0)return T.map(j=>({name:j.color_name,hex:j.hex_color.replace("#","").substring(0,6),manufacturer:j.manufacturer,material:typeof j.material=="string"?j.material:void 0}))}return[]},[a,t.brand,t.material,t.subtype]),y=w.useMemo(()=>{if(!c)return f;if(f.length===0)return[];const g=c.toLowerCase();return f.filter(k=>k.name.toLowerCase().includes(g)||(k.manufacturer?.toLowerCase().includes(g)??!1)||(k.material?.toLowerCase().includes(g)??!1))},[c,f]),v=f.length>0,b=w.useMemo(()=>c?UY.filter(g=>g.name.toLowerCase().includes(c.toLowerCase())):o?UY:rle,[c,o]);return i.jsxs("div",{className:"space-y-3",children:[i.jsx("div",{className:"h-10 rounded-lg border border-bambu-dark-tertiary",style:{backgroundColor:`#${u}`}}),n.length>0&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-bambu-gray shrink-0",children:[i.jsx(Zn,{className:"w-3 h-3"}),i.jsx("span",{children:s("inventory.recentColors")})]}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:n.map(g=>i.jsx("button",{type:"button",onClick:()=>p(g.hex,g.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 ${m(g.hex)?"border-bambu-green ring-1 ring-bambu-green/30 scale-110":"border-bambu-dark-tertiary"}`,style:{backgroundColor:`#${g.hex}`},title:g.name},g.hex))})]}),i.jsxs("div",{className:"relative",children:[i.jsx(Fr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none"}),i.jsx("input",{type:"text",className:"w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green",placeholder:s("inventory.searchColors"),value:c,onChange:g=>d(g.target.value)})]}),v?i.jsxs("div",{className:"space-y-1.5",children:[i.jsx("span",{className:"text-xs text-bambu-gray",children:c?s("inventory.searchResults"):`${t.brand}${t.material?` ${t.material}`:""}`}),i.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[y.map(g=>i.jsx("button",{type:"button",onClick:()=>p(g.hex,g.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 hover:z-20 relative group ${m(g.hex)?"border-bambu-green ring-1 ring-bambu-green/30 scale-110":"border-bambu-dark-tertiary"}`,style:{backgroundColor:`#${g.hex}`},title:g.manufacturer&&g.material?`${g.name} (${g.manufacturer} — ${g.material})`:g.manufacturer?`${g.name} (${g.manufacturer})`:g.name,children:i.jsx("span",{className:"absolute -bottom-7 left-1/2 -translate-x-1/2 px-2 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-xs whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-20 shadow-lg text-white",children:g.manufacturer&&g.material?`${g.name} (${g.manufacturer} — ${g.material})`:g.manufacturer?`${g.name} (${g.manufacturer})`:g.name})},`${g.hex}-${g.name}-${g.manufacturer??""}`)),y.length===0&&i.jsx("p",{className:"text-sm text-bambu-gray py-1",children:s("inventory.noColorsFound")})]})]}):i.jsxs("div",{className:"space-y-1.5",children:[i.jsxs("div",{className:"flex items-center justify-between text-xs text-bambu-gray",children:[i.jsx("span",{children:s(c?"inventory.searchResults":o?"inventory.allColors":"inventory.commonColors")}),!c&&i.jsx("button",{type:"button",onClick:()=>l(!o),className:"flex items-center gap-1 hover:text-white transition-colors",children:o?i.jsxs(i.Fragment,{children:[s("inventory.showLess")," ",i.jsx(Gl,{className:"w-3 h-3"})]}):i.jsxs(i.Fragment,{children:[s("inventory.showAll")," ",i.jsx(zn,{className:"w-3 h-3"})]})})]}),i.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[b.map(g=>i.jsx("button",{type:"button",onClick:()=>p(g.hex,g.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 hover:z-20 relative group ${m(g.hex)?"border-bambu-green ring-1 ring-bambu-green/30 scale-110":"border-bambu-dark-tertiary"}`,style:{backgroundColor:`#${g.hex}`},title:g.name,children:i.jsx("span",{className:"absolute -bottom-7 left-1/2 -translate-x-1/2 px-2 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-xs whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-20 shadow-lg text-white",children:g.name})},g.hex)),b.length===0&&i.jsx("p",{className:"text-sm text-bambu-gray py-1",children:s("inventory.noColorsFound")})]})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:s("inventory.colorName")}),i.jsx("input",{type:"text",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green",placeholder:s("inventory.colorNamePlaceholder"),value:t.color_name,onChange:g=>e("color_name",g.target.value)})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:s("inventory.hexColor")}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray",children:"#"}),i.jsx("input",{type:"text",className:"w-full pl-7 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono uppercase focus:outline-none focus:border-bambu-green",placeholder:"RRGGBB",value:u.toUpperCase(),onChange:g=>{const _=g.target.value.replace("#","").replace(/[^0-9A-Fa-f]/g,"");_.length<=8&&e("rgba",_.toUpperCase()+(_.length<=6?"FF":""))}})]}),i.jsx("input",{type:"color",className:"w-11 h-[38px] rounded-lg cursor-pointer border border-bambu-dark-tertiary shrink-0 bg-transparent",value:`#${u}`,onChange:g=>{const _=g.target.value.replace("#","").toUpperCase();e("rgba",_+"FF")},title:s("inventory.pickColor")})]})]})]})]})}function Jtt({catalog:t,value:e,onChange:n,catalogId:r,onCatalogIdChange:a}){const{t:s}=jt(),[o,l]=w.useState(!1),[c,d]=w.useState(""),u=w.useRef(null),m=w.useRef(null);w.useEffect(()=>{const v=b=>{u.current&&!u.current.contains(b.target)&&l(!1)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[]),w.useEffect(()=>{if(t.length===0)return;const v=t.filter(b=>b.weight===e);if(r){const b=t.find(g=>g.id===r);if(b&&b.weight===e)return}v.length===1?a(v[0].id):v.length===0&&r!==null&&a(null)},[e,t,r,a]);const p=w.useMemo(()=>{if(!c)return t;const v=c.toLowerCase();return t.filter(b=>b.name.toLowerCase().includes(v)||b.weight.toString().includes(v))},[t,c]),f=w.useMemo(()=>t.filter(v=>v.weight===e),[t,e]),y=w.useMemo(()=>{if(o)return c;if(r){const v=t.find(b=>b.id===r);if(v)return v.name}return f.length>0?f[0].name:""},[o,c,r,t,f]);return i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:i.jsxs("span",{className:"flex items-center gap-2",children:[i.jsx(ebe,{className:"w-3.5 h-3.5 text-bambu-gray"}),s("inventory.coreWeight")]})}),i.jsxs("div",{className:"flex gap-2 items-center",children:[i.jsxs("div",{className:"flex-1 min-w-0 relative",ref:u,children:[i.jsx("input",{ref:m,type:"text",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green",placeholder:s("inventory.searchSpoolWeight"),value:y,onFocus:()=>{l(!0),d("")},onChange:v=>{d(v.target.value),l(!0)}}),o&&i.jsx("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto",children:p.length===0?i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:s("inventory.noResults")}):p.map(v=>i.jsxs("button",{type:"button",className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex justify-between items-center ${(r?v.id===r:v.weight===e)?"bg-bambu-green/10 text-bambu-green":"text-white"}`,onClick:()=>{a(v.id),n(v.weight),l(!1),d("")},children:[i.jsx("span",{className:"truncate",children:v.name}),i.jsxs("span",{className:"font-mono text-xs text-bambu-gray ml-2 shrink-0",children:[v.weight,"g"]})]},v.id))})]}),i.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[i.jsx("input",{type:"number",className:"w-16 px-2 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm text-center font-mono focus:outline-none focus:border-bambu-green",value:e,min:0,max:2e3,onChange:v=>{const b=parseInt(v.target.value);!isNaN(b)&&b>=0&&n(b)}}),i.jsx("span",{className:"text-bambu-gray text-sm",children:"g"})]})]})]})}function mle({formData:t,updateField:e,spoolCatalog:n,currencySymbol:r}){const{t:a}=jt(),{showToast:s}=pn(),[o,l]=w.useState(""),[c,d]=w.useState(!1),[u,m]=w.useState(""),[p,f]=w.useState(!1),y=Math.max(0,t.label_weight-t.weight_used),v=t.core_weight+y;return w.useEffect(()=>{c||l(String(v))},[c,v]),w.useEffect(()=>{p||m(String(y))},[p,y]),i.jsxs("div",{className:"space-y-4",children:[i.jsx(Jtt,{catalog:n,value:t.core_weight,onChange:b=>e("core_weight",b),catalogId:t.core_weight_catalog_id,onCatalogIdChange:b=>e("core_weight_catalog_id",b)}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:a("inventory.currentWeight")}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsx("input",{type:"number",value:u,min:0,max:t.label_weight,onFocus:()=>f(!0),onChange:b=>{m(b.target.value)},onBlur:()=>{f(!1);const b=u.trim(),g=Number(b);if(!b||!Number.isFinite(g)||g<0||g>t.label_weight){m(String(y));return}const _=Math.round(g);e("weight_used",Math.max(0,t.label_weight-_)),m(String(_))},className:"w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green"}),i.jsx("span",{className:"absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray",children:"g"})]}),i.jsxs("span",{className:"text-xs text-bambu-gray shrink-0",children:["/ ",t.label_weight,"g"]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:a("inventory.measuredWeight")}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsx("input",{type:"number",value:o,min:0,onFocus:()=>d(!0),onChange:b=>{l(b.target.value)},onBlur:()=>{d(!1);const b=o.trim(),g=Number(b),_=t.core_weight,k=t.core_weight+t.label_weight;if(!b||!Number.isFinite(g)||g<_||g>k){s(a("inventory.measuredWeightError",{min:_,max:k}),"error"),l(String(v));return}const C=Math.round(g),N=Math.max(0,Math.min(t.label_weight,C-t.core_weight));e("weight_used",Math.max(0,t.label_weight-N)),l(String(C))},className:"w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green"}),i.jsx("span",{className:"absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray",children:"g"})]}),i.jsxs("span",{className:"text-xs text-bambu-gray shrink-0",children:["/ ",t.core_weight+t.label_weight,"g"]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:a("inventory.costPerKg","Cost per kg")}),i.jsx("div",{className:"flex items-center gap-2",children:i.jsxs("div",{className:"relative flex-1",children:[i.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none",children:r}),i.jsx("input",{type:"number",value:t.cost_per_kg??"",min:0,step:.01,placeholder:"0.00",onChange:b=>{const g=b.target.value===""?null:parseFloat(b.target.value);e("cost_per_kg",g)},style:{paddingLeft:`${Math.max(2,r.length*.6+1)}rem`},className:"w-full py-2 pr-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green"})]})})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:a("inventory.note")}),i.jsx("textarea",{className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green resize-none min-h-[80px]",placeholder:a("inventory.notePlaceholder"),value:t.note,onChange:b=>e("note",b.target.value)})]})]})}function hle({formData:t,printersWithCalibrations:e,selectedProfiles:n,setSelectedProfiles:r,expandedPrinters:a,setExpandedPrinters:s}){const{t:o}=jt(),l=p=>{s(f=>{const y=new Set(f);return y.has(p)?y.delete(p):y.add(p),y})},c=(p,f,y)=>{const v=`${p}:${f}:${y??"null"}`,b=`${p}:${y??"null"}`;r(g=>{const _=new Set(g);if(_.has(v))_.delete(v);else{for(const k of Array.from(_)){const C=k.split(":");`${C[0]}:${C[2]}`===b&&_.delete(k)}_.add(v)}return _})},d=()=>{const p=new Set;for(const{printer:f,calibrations:y}of e){if(!f.connected)continue;const v=y.filter(g=>e3(g,t)),b=new Map;for(const g of v){const _=`${g.extruder_id??"null"}`;b.has(_)||b.set(_,[]),b.get(_).push(g)}for(const[g,_]of b)if(_.length>0){const C=[..._].sort((N,P)=>P.k_value-N.k_value)[0];p.add(`${f.id}:${C.cali_idx}:${g}`)}}r(p)};if(!t.material)return i.jsx("div",{className:"p-6 bg-bambu-dark rounded-lg text-center",children:i.jsx("p",{className:"text-bambu-gray",children:o("inventory.selectMaterialFirst")})});if(e.length===0)return i.jsx("div",{className:"p-6 bg-bambu-dark rounded-lg text-center",children:i.jsx("p",{className:"text-bambu-gray",children:o("inventory.noPrintersConfigured")})});const u=e.reduce((p,{printer:f,calibrations:y})=>f.connected?p+y.filter(v=>e3(v,t)).length:p,0),m=(p,f)=>{const y=`${p.id}:${f.cali_idx}:${f.extruder_id??"null"}`,v=n.has(y);return i.jsxs("label",{className:`flex items-center gap-3 p-3 rounded-lg cursor-pointer transition-all border ${v?"bg-bambu-green/10 border-bambu-green/30":"bg-bambu-dark border-transparent hover:bg-bambu-dark/80"}`,children:[i.jsx("input",{type:"checkbox",checked:v,onChange:()=>c(String(p.id),f.cali_idx,f.extruder_id),className:"w-4 h-4 rounded border-bambu-dark-tertiary text-bambu-green focus:ring-bambu-green"}),i.jsx("div",{className:"flex-1 min-w-0",children:i.jsx("span",{className:`text-sm font-medium ${v?"text-bambu-green":"text-white"}`,children:f.name||f.filament_id})}),i.jsx("div",{className:"flex items-center gap-2 shrink-0",children:i.jsxs("span",{className:"text-xs font-mono px-2 py-0.5 rounded bg-bambu-dark text-bambu-gray",children:["K=",f.k_value.toFixed(3)]})})]},`${f.cali_idx}-${f.extruder_id}`)};return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("p",{className:"text-xs text-bambu-gray",children:[o("inventory.matchingFilter"),": ",t.brand||o("inventory.anyBrand")," / ",t.material," / ",t.subtype||o("inventory.anyVariant")]}),u>0&&i.jsxs("button",{type:"button",onClick:d,className:"flex items-center gap-1.5 px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white hover:border-bambu-green transition-colors",children:[i.jsx(fx,{className:"w-3.5 h-3.5"}),o("inventory.autoSelect")," (",u,")"]})]}),i.jsx("div",{className:"space-y-3",children:e.map(({printer:p,calibrations:f})=>{const y=a.has(String(p.id)),v=f.filter(C=>e3(C,t)),b=v.length,g=v.some(C=>C.extruder_id!==void 0&&C.extruder_id!==null&&C.extruder_id>0),_=v.filter(C=>C.extruder_id===1),k=v.filter(C=>C.extruder_id===0||C.extruder_id===void 0||C.extruder_id===null);return i.jsxs("div",{className:"border border-bambu-dark-tertiary rounded-lg overflow-hidden",children:[i.jsxs("button",{type:"button",onClick:()=>l(String(p.id)),className:"w-full px-4 py-3 flex items-center justify-between bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary transition-colors",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[y?i.jsx(zn,{className:"w-4 h-4 text-bambu-gray"}):i.jsx(fa,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("span",{className:"font-medium text-white",children:p.name}),b>0?i.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green",children:[b," ",o(b!==1?"inventory.matches":"inventory.match")]}):i.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray",children:o("inventory.noMatches")})]}),i.jsx("span",{className:`text-xs px-2 py-1 rounded-full ${p.connected?"bg-green-500/20 text-green-500":"bg-bambu-gray/20 text-bambu-gray"}`,children:p.connected?o("inventory.connected"):o("inventory.offline")})]}),y&&i.jsx("div",{className:"px-4 py-3 space-y-3 bg-bambu-dark border-t border-bambu-dark-tertiary",children:p.connected?b===0?i.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:o("inventory.noKProfilesMatch")}):g?i.jsxs(i.Fragment,{children:[_.length>0&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-xs font-medium text-bambu-gray uppercase tracking-wide",children:o("inventory.leftNozzle")}),i.jsx("div",{className:"space-y-2",children:_.map(C=>m(p,C))})]}),k.length>0&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-xs font-medium text-bambu-gray uppercase tracking-wide",children:o("inventory.rightNozzle")}),i.jsx("div",{className:"space-y-2",children:k.map(C=>m(p,C))})]})]}):i.jsx("div",{className:"space-y-2",children:v.map(C=>m(p,C))}):i.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:o("inventory.printerOffline")})})]},p.id)})}),n.size>0&&i.jsx("div",{className:"p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:i.jsxs("p",{className:"text-sm text-white",children:[i.jsx("span",{className:"font-semibold",children:n.size})," ",o("inventory.profilesSelected")]})})]})}function ent(t){const e=new Date(t);return e.toLocaleDateString("en-GB",{day:"2-digit",month:"2-digit",year:"2-digit"})+" "+e.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"})}const tnt={completed:"text-bambu-green",failed:"text-red-400",aborted:"text-yellow-400"};function nnt({spoolId:t}){const{t:e}=jt(),n=cn(),{showToast:r}=pn(),{data:a,isLoading:s}=et({queryKey:["spool-usage",t],queryFn:()=>be.getSpoolUsageHistory(t)}),o=pt({mutationFn:()=>be.clearSpoolUsageHistory(t),onSuccess:()=>{n.invalidateQueries({queryKey:["spool-usage",t]}),r(e("inventory.historyCleared"),"success")}});return s?i.jsx("div",{className:"flex justify-center py-4",children:i.jsx(ft,{className:"w-5 h-5 animate-spin text-bambu-green"})}):!a||a.length===0?i.jsxs("div",{className:"text-center py-4 text-bambu-gray text-sm",children:[i.jsx(Zn,{className:"w-5 h-5 mx-auto mb-2 opacity-50"}),e("inventory.noUsageHistory")]}):i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("h4",{className:"text-sm font-medium text-white",children:e("inventory.usageHistory")}),i.jsxs(Ie,{variant:"ghost",size:"sm",onClick:()=>o.mutate(),disabled:o.isPending,className:"text-xs text-bambu-gray hover:text-red-400",children:[i.jsx(an,{className:"w-3 h-3 mr-1"}),e("inventory.clearHistory")]})]}),i.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:a.map(l=>i.jsxs("div",{className:"flex items-center justify-between p-2 rounded bg-bambu-dark/50 text-xs",children:[i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("span",{className:"text-bambu-gray",children:ent(l.created_at)}),l.print_name&&i.jsx("span",{className:"text-white ml-2 truncate",title:l.print_name,children:l.print_name})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0 ml-2",children:[i.jsxs("span",{className:"text-white font-medium",children:[l.weight_used.toFixed(1),"g"]}),i.jsxs("span",{className:"text-bambu-gray",children:["(",l.percent_used,"%)"]}),i.jsx("span",{className:tnt[l.status]||"text-bambu-gray",children:l.status})]})]},l.id))})]})}function rnt({isOpen:t,onClose:e,spool:n,printersWithCalibrations:r=[],currencySymbol:a,onSpoolsCreated:s}){const{t:o}=jt(),l=cn(),{showToast:c}=pn(),d=!!n,[u,m]=w.useState(AL),[p,f]=w.useState({}),[y,v]=w.useState("filament"),[b,g]=w.useState(!1),[_,k]=w.useState(!1),[C,N]=w.useState(1),[P,T]=w.useState(!1),[j,A]=w.useState(!1),[F,G]=w.useState([]),[z,Z]=w.useState(""),[I,ee]=w.useState([]),[ae,X]=w.useState([]),[ce,ue]=w.useState([]),[pe,K]=w.useState([]),[se,de]=w.useState([]),[ge,Te]=w.useState(new Set),[V,J]=w.useState(new Set),D=r.length>0?r:se,E=w.useMemo(()=>ge.size,[ge]);w.useEffect(()=>{K(lle())},[]),w.useEffect(()=>{t&&((async()=>{A(!0);try{const Me=await be.getCloudStatus();if(T(Me.is_authenticated),Me.is_authenticated){const xe=await be.getFilamentPresets();G(xe)}}catch(Me){console.error("Failed to fetch cloud presets:",Me),T(!1)}finally{A(!1)}})(),be.getSpoolCatalog().then(ee).catch(console.error),be.getColorCatalog().then(ue).catch(console.error),be.getLocalPresets().then(Me=>X(Me.filament)).catch(console.error),r.length===0&&(async()=>{try{const Me=await be.getPrinters(),xe=await Promise.all(Me.map(He=>be.getPrinterStatus(He.id).catch(()=>null))),je=[];for(let He=0;He({cali_idx:We.slot_id,filament_id:We.filament_id,setting_id:We.setting_id||"",name:We.name,k_value:parseFloat(We.k_value)||0,n_coef:parseFloat(We.n_coef)||0,extruder_id:We.extruder_id,nozzle_diameter:We.nozzle_diameter}))}catch{}je.push({printer:{...Oe,connected:Ae},calibrations:Be})}de(je)}catch(Me){console.error("Failed to fetch printer calibrations:",Me)}})())},[t,r.length]);const U=w.useMemo(()=>sle(F,new Set,ae),[F,ae]),W=w.useMemo(()=>{const me=ale(F,ae),Me=ce.map(je=>je.manufacturer?.trim()).filter(je=>!!je),xe=new Set([...me,...Me]);return Array.from(xe).sort((je,He)=>je.localeCompare(He))},[F,ae,ce]),B=w.useMemo(()=>{const me=ce.map(xe=>xe.material?.trim()).filter(xe=>!!xe),Me=new Set([...nle,...me]);return Array.from(Me).sort((xe,je)=>xe.localeCompare(je))},[ce]),ie=w.useMemo(()=>{const me=[];for(const Me of ce){const xe=Me.manufacturer?.trim(),je=Me.material?.trim();xe&&je&&me.push({brand:xe,material:je})}for(const Me of F){const xe=Qh(Me.name);xe.brand&&xe.material&&me.push({brand:xe.brand,material:xe.material})}for(const Me of ae){const xe=Qh(Me.name),je=Me.filament_vendor?.trim()||xe.brand,He=xe.material;je&&He&&me.push({brand:je,material:He})}return me},[F,ce,ae]),O=w.useMemo(()=>{const me=new Map;for(const Me of ie){const xe=Me.brand.toLowerCase(),je=Me.material.toLowerCase();me.has(xe)||me.set(xe,new Set),me.get(xe).add(je)}return me},[ie]),$=w.useMemo(()=>{const me=new Map;for(const Me of ie){const xe=Me.brand.toLowerCase(),je=Me.material.toLowerCase();me.has(je)||me.set(je,new Set),me.get(je).add(xe)}return me},[ie]),Y=w.useMemo(()=>{if(!u.material)return W;const me=u.material.toLowerCase(),Me=$.get(me);return!Me||Me.size===0?W:W.filter(xe=>Me.has(xe.toLowerCase()))},[W,u.material,$]),q=w.useMemo(()=>{if(!u.brand)return B;const me=u.brand.toLowerCase(),Me=O.get(me);return!Me||Me.size===0?B:B.filter(xe=>Me.has(xe.toLowerCase()))},[B,u.brand,O]),te=w.useMemo(()=>ole(u.slicer_filament,U),[u.slicer_filament,U]);w.useEffect(()=>{if(t){if(n)if(m({material:n.material||"",subtype:n.subtype||"",brand:n.brand||"",color_name:n.color_name||"",rgba:n.rgba||"808080FF",label_weight:n.label_weight||1e3,core_weight:n.core_weight||250,core_weight_catalog_id:n.core_weight_catalog_id??null,weight_used:n.weight_used||0,slicer_filament:n.slicer_filament||"",note:n.note||"",cost_per_kg:n.cost_per_kg??null}),Z(n.slicer_filament_name||n.slicer_filament||""),n.k_profiles&&n.k_profiles.length>0){const me=new Set;for(const Me of n.k_profiles)Me.cali_idx!==null&&Me.cali_idx!==void 0&&me.add(`${Me.printer_id}:${Me.cali_idx}:${Me.extruder??"null"}`);Te(me)}else Te(new Set);else m(AL),Z(""),Te(new Set),k(!1),N(1);f({}),v("filament"),g(!1)}},[t,n]),w.useEffect(()=>{t&&D.length>0&&J(new Set(D.map(me=>String(me.printer.id))))},[t,D]);const oe=(me,Me)=>{m(xe=>({...xe,[me]:Me})),me==="weight_used"&&g(!0),p[me]&&f(xe=>({...xe,[me]:void 0}))},he=me=>{K(Me=>cle(me,Me))},fe=pt({mutationFn:me=>be.createSpool(me),onSuccess:async me=>{ge.size>0&&me?.id&&await ne(me.id),await l.invalidateQueries({queryKey:["inventory-spools"]}),s&&s([me]),c(o("inventory.spoolCreated"),"success"),e()},onError:me=>{c(me.message,"error")}}),re=pt({mutationFn:({data:me,qty:Me})=>be.bulkCreateSpools(me,Me),onSuccess:async me=>{if(ge.size>0)for(const Me of me)await ne(Me.id);await l.invalidateQueries({queryKey:["inventory-spools"]}),s&&s(me),c(o("inventory.spoolsCreated",{count:me.length}),"success"),e()},onError:me=>{c(me.message,"error")}}),L=pt({mutationFn:me=>be.updateSpool(n.id,me),onSuccess:async()=>{n?.id&&await ne(n.id),await l.invalidateQueries({queryKey:["inventory-spools"]}),c(o("inventory.spoolUpdated"),"success"),e()},onError:me=>{c(me.message,"error")}}),R=pt({mutationFn:()=>be.updateSpool(n.id,{tag_uid:null}),onSuccess:async()=>{await l.invalidateQueries({queryKey:["inventory-spools"]}),c(o("inventory.tagDeleted","Tag removed"),"success"),e()},onError:me=>{c(me.message,"error")}}),ne=async me=>{if(ge.size===0){try{await be.saveSpoolKProfiles(me,[])}catch{}return}const Me=[];for(const xe of ge){const[je,He,Oe]=xe.split(":"),_e=parseInt(je),Ae=parseInt(He),Be=Oe==="null"?0:parseInt(Oe),De=D.find(We=>We.printer.id===_e);if(De){const We=De.calibrations.find(ye=>ye.cali_idx===Ae);We&&Me.push({printer_id:_e,extruder:Be,nozzle_diameter:We.nozzle_diameter||"0.4",k_value:We.k_value,name:We.name||null,cali_idx:We.cali_idx,setting_id:We.setting_id||null})}}if(Me.length>0)try{await be.saveSpoolKProfiles(me,Me)}catch(xe){console.error("Failed to save K-profiles:",xe)}};if(w.useEffect(()=>{if(!t)return;const me=Me=>{Me.key==="Escape"&&e()};return document.addEventListener("keydown",me),()=>document.removeEventListener("keydown",me)},[t,e]),!t)return null;const ve=()=>{const me=tle(u,_);if(!me.isValid){f(me.errors),(me.errors.slicer_filament||me.errors.material||me.errors.brand||me.errors.subtype)&&v("filament");return}const Me=te?.displayName||z||null,xe={material:u.material,subtype:u.subtype||null,brand:u.brand||null,color_name:u.color_name||null,rgba:u.rgba||null,label_weight:u.label_weight,core_weight:u.core_weight,core_weight_catalog_id:u.core_weight_catalog_id,slicer_filament:u.slicer_filament||null,slicer_filament_name:Me,nozzle_temp_min:null,nozzle_temp_max:null,note:u.note||null,cost_per_kg:u.cost_per_kg};(!d||b)&&(xe.weight_used=u.weight_used),d?L.mutate(xe):C>1?re.mutate({data:xe,qty:C}):fe.mutate(xe)},we=fe.isPending||re.isPending||L.isPending||R.isPending;return i.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[i.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),i.jsxs("div",{className:"relative w-full max-w-xl mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary flex-shrink-0",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:o(d?"inventory.editSpool":"inventory.addSpool")}),i.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:i.jsx(qt,{className:"w-5 h-5"})})]}),!d&&i.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-bambu-dark-tertiary flex-shrink-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Wl,{className:"w-4 h-4 text-amber-400"}),i.jsx("span",{className:"text-sm text-white",children:o("inventory.quickAdd")})]}),i.jsx("button",{type:"button",onClick:()=>{k(!_),_||v("filament")},className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${_?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,children:i.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${_?"translate-x-4":"translate-x-0.5"}`})})]}),i.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary flex-shrink-0",children:[i.jsxs("button",{onClick:()=>v("filament"),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${y==="filament"?"text-bambu-green border-b-2 border-bambu-green":"text-bambu-gray hover:text-white"}`,children:[i.jsx(Sw,{className:"w-4 h-4"}),o("inventory.filamentInfoTab")]}),!_&&i.jsxs("button",{onClick:()=>v("pa-profile"),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${y==="pa-profile"?"text-bambu-green border-b-2 border-bambu-green":"text-bambu-gray hover:text-white"}`,children:[i.jsx(Uhe,{className:"w-4 h-4"}),o("inventory.paProfileTab"),E>0&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green",children:E})]})]}),i.jsx("div",{className:"p-4 overflow-y-auto flex-1",style:{scrollbarGutter:"stable"},children:y==="filament"?i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3",children:o("inventory.filamentInfo")}),i.jsx(dle,{formData:u,updateField:oe,cloudAuthenticated:P,loadingCloudPresets:j,presetInputValue:z,setPresetInputValue:Z,selectedPresetOption:te,filamentOptions:U,availableBrands:Y,availableMaterials:q,quickAdd:_,quantity:C,onQuantityChange:N,errors:p})]}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3",children:o("inventory.color")}),i.jsx(ule,{formData:u,updateField:oe,recentColors:pe,onColorUsed:he,catalogColors:ce})]}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3",children:o("inventory.additional")}),i.jsx(mle,{formData:u,updateField:oe,spoolCatalog:I,currencySymbol:a})]}),d&&n&&i.jsx("div",{children:i.jsx(nnt,{spoolId:n.id})})]}):i.jsx(hle,{formData:u,updateField:oe,printersWithCalibrations:D,selectedProfiles:ge,setSelectedProfiles:Te,expandedPrinters:V,setExpandedPrinters:J})}),i.jsxs("div",{className:"flex gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0",children:[d&&i.jsxs(Ie,{variant:"secondary",onClick:()=>R.mutate(),disabled:we||!n?.tag_uid,className:"mr-auto",children:[i.jsx(Vu,{className:"w-4 h-4"}),o("inventory.deleteTag","Delete Tag")]}),i.jsxs("div",{className:"flex gap-2 ml-auto",children:[i.jsx(Ie,{variant:"secondary",onClick:e,children:o("common.cancel")}),i.jsx(Ie,{onClick:ve,disabled:we,children:we?i.jsxs(i.Fragment,{children:[i.jsx(ft,{className:"w-4 h-4 animate-spin"}),o("common.saving")]}):i.jsxs(i.Fragment,{children:[i.jsx(as,{className:"w-4 h-4"}),o(d?"common.save":"inventory.addSpool")]})})]})]})]})]})}function int({isOpen:t,onClose:e,columns:n,defaultColumns:r,onSave:a}){const{t:s}=jt(),[o,l]=w.useState(n),[c,d]=w.useState(null),u=w.useRef(null);if(w.useEffect(()=>{t&&l(n.map(C=>({...C})))},[t,n]),w.useEffect(()=>{if(!t)return;const C=N=>{N.key==="Escape"&&e()};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[t,e]),!t)return null;const m=C=>{l(N=>N.map((P,T)=>T===C?{...P,visible:!P.visible}:P))},p=(C,N)=>{N<0||N>=o.length||l(P=>{const T=[...P],[j]=T.splice(C,1);return T.splice(N,0,j),T})},f=(C,N)=>{u.current=N,d(N),C.dataTransfer.effectAllowed="move"},y=(C,N)=>{C.preventDefault(),C.dataTransfer.dropEffect="move";const P=u.current;P!==null&&P!==N&&(p(P,N),u.current=N,d(N))},v=C=>{C.preventDefault()},b=()=>{u.current=null,d(null)},g=()=>{l(r.map(C=>({...C})))},_=()=>{a(o),e()},k=o.filter(C=>C.visible).length;return i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:e,children:i.jsx(At,{className:"w-full max-w-md max-h-[80vh] flex flex-col",onClick:C=>C.stopPropagation(),children:i.jsxs(Et,{className:"p-6 flex flex-col min-h-0",children:[i.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:s("inventory.configureColumns")}),i.jsxs("p",{className:"text-sm text-bambu-gray mb-4",children:[s("inventory.configureColumnsDesc"),i.jsxs("span",{className:"ml-2 text-bambu-gray/60",children:["(",k," ",s("inventory.of")," ",o.length," ",s("inventory.visible"),")"]})]}),i.jsx("div",{className:"space-y-1 overflow-y-auto flex-1 min-h-0 pr-1",children:o.map((C,N)=>i.jsxs("div",{className:`flex items-center gap-2 p-2 rounded-lg border transition-colors ${c===N?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark-tertiary/50"} ${C.visible?"":"opacity-50"}`,draggable:!0,onDragStart:P=>f(P,N),onDragOver:P=>y(P,N),onDrop:v,onDragEnd:b,children:[i.jsx("div",{className:"cursor-grab text-bambu-gray/50 hover:text-bambu-gray",children:i.jsx(Mh,{className:"w-4 h-4"})}),i.jsx("span",{className:"flex-1 font-medium text-sm text-white",children:C.label}),i.jsxs("div",{className:"flex items-center gap-0.5",children:[i.jsx("button",{onClick:()=>p(N,N-1),disabled:N===0,className:"p-1 rounded text-bambu-gray hover:bg-bambu-dark-secondary disabled:opacity-30 disabled:cursor-not-allowed",title:s("inventory.moveUp"),children:i.jsx(Gl,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>p(N,N+1),disabled:N===o.length-1,className:"p-1 rounded text-bambu-gray hover:bg-bambu-dark-secondary disabled:opacity-30 disabled:cursor-not-allowed",title:s("inventory.moveDown"),children:i.jsx(zn,{className:"w-4 h-4"})})]}),i.jsx("button",{onClick:()=>m(N),className:`p-1.5 rounded transition-colors ${C.visible?"text-bambu-green hover:bg-bambu-green/10":"text-bambu-gray/50 hover:bg-bambu-dark-secondary"}`,title:C.visible?s("inventory.hideColumn"):s("inventory.showColumn"),children:C.visible?i.jsx(Pc,{className:"w-4 h-4"}):i.jsx(xw,{className:"w-4 h-4"})})]},C.id))}),i.jsxs("div",{className:"flex items-center gap-3 mt-4 pt-4 border-t border-bambu-dark-tertiary",children:[i.jsxs(Ie,{variant:"secondary",onClick:g,className:"mr-auto",children:[i.jsx(Ao,{className:"w-4 h-4"}),s("inventory.reset")]}),i.jsx(Ie,{variant:"secondary",onClick:e,children:s("inventory.cancel")}),i.jsx(Ie,{onClick:_,children:s("inventory.applyChanges")})]})]})})})}function BY(t){return`${t.material}|${t.subtype||""}|${t.brand||""}|${t.color_name||""}|${t.rgba||""}|${t.label_weight}`}const ple="bambuddy-inventory-columns",Ak=[{id:"id",label:"#",visible:!0},{id:"added_time",label:"Added",visible:!0},{id:"encode_time",label:"Encoded",visible:!1},{id:"last_used_time",label:"Last Used",visible:!1},{id:"rgba",label:"Color",visible:!0},{id:"material",label:"Material",visible:!0},{id:"subtype",label:"Subtype",visible:!0},{id:"color_name",label:"Color Name",visible:!1},{id:"brand",label:"Brand",visible:!0},{id:"slicer_filament",label:"Slicer Filament",visible:!1},{id:"location",label:"Location",visible:!0},{id:"label_weight",label:"Label",visible:!0},{id:"net",label:"Net",visible:!0},{id:"gross",label:"Gross",visible:!1},{id:"added_full",label:"Full",visible:!1},{id:"used",label:"Used",visible:!1},{id:"printed_total",label:"Printed Total",visible:!1},{id:"printed_since_weight",label:"Printed Since Weight",visible:!1},{id:"note",label:"Note",visible:!1},{id:"pa_k",label:"PA(K)",visible:!0},{id:"tag_id",label:"Tag ID",visible:!1},{id:"data_origin",label:"Data Origin",visible:!1},{id:"tag_type",label:"Linked Tag Type",visible:!1},{id:"stock",label:"Stock",visible:!1},{id:"remaining",label:"Remaining",visible:!0},{id:"spool_name",label:"Spool",visible:!1},{id:"cost_per_kg",label:"Cost/kg",visible:!1},{id:"weight_check",label:"Weight Check",visible:!1}];function ant(){try{const t=localStorage.getItem(ple);if(t){const e=JSON.parse(t),n=new Set(Ak.map(o=>o.id)),r=new Set(e.map(o=>o.id)),a=e.filter(o=>n.has(o.id)),s=Ak.filter(o=>!r.has(o.id));return[...a,...s]}}catch{}return Ak.map(t=>({...t}))}function snt(t){try{localStorage.setItem(ple,JSON.stringify(t))}catch{}}function md(t,e=!1){return e&&t>=1e3?`${(t/1e3).toFixed(1)}kg`:`${Math.round(t)}g`}const ont={PLA:"bg-green-500/20 text-green-400",ABS:"bg-red-500/20 text-red-400",PETG:"bg-blue-500/20 text-blue-400",TPU:"bg-purple-500/20 text-purple-400",ASA:"bg-orange-500/20 text-orange-400",PA:"bg-yellow-500/20 text-yellow-400",PC:"bg-cyan-500/20 text-cyan-400",PET:"bg-sky-500/20 text-sky-400"};function t3(t,e="system"){if(!t)return"-";const n=Qn(t);return n?M3(n,e):"-"}const lnt={id:()=>"#",added_time:()=>"Added",encode_time:()=>"Encoded",last_used_time:()=>"Last Used",rgba:t=>t("inventory.color"),material:t=>t("inventory.material"),subtype:t=>t("inventory.subtype"),color_name:t=>t("inventory.colorName"),brand:t=>t("inventory.brand"),slicer_filament:t=>t("inventory.slicerFilament"),location:()=>"Location",label_weight:t=>t("inventory.labelWeight"),net:t=>t("inventory.net"),gross:()=>"Gross",added_full:()=>"Full",used:t=>t("inventory.weightUsed"),printed_total:()=>"Printed Total",printed_since_weight:()=>"Printed Since Weight",note:t=>t("inventory.note"),pa_k:()=>"PA(K)",tag_id:()=>"Tag ID",data_origin:()=>"Data Origin",tag_type:()=>"Linked Tag Type",stock:t=>t("inventory.stock"),remaining:t=>t("inventory.remaining"),spool_name:t=>t("inventory.spoolName"),cost_per_kg:t=>t("inventory.costPerKg"),weight_check:t=>t("inventory.weightCheck")},PL={id:({spool:t})=>i.jsx("span",{className:"text-sm font-medium text-white",children:t.id}),added_time:({spool:t,dateFormat:e})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t3(t.created_at,e)}),encode_time:({spool:t,dateFormat:e})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t3(t.encode_time,e)}),last_used_time:({spool:t,dateFormat:e})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.last_used?t3(t.last_used,e):"Never"}),rgba:({spool:t})=>i.jsx("div",{className:"flex items-center justify-center",children:i.jsx("span",{className:"w-5 h-5 rounded-full border border-black/20 flex-shrink-0",style:{backgroundColor:t.rgba?`#${t.rgba.substring(0,6)}`:"#808080"},title:t.rgba?`#${t.rgba.substring(0,6)}`:void 0})}),material:({spool:t})=>i.jsx("span",{className:"text-sm text-white",children:t.material}),subtype:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.subtype||"-"}),color_name:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:LI(t.color_name,t.rgba)||"-"}),brand:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.brand||"-"}),slicer_filament:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",title:t.slicer_filament||void 0,children:t.slicer_filament_name||t.slicer_filament||"-"}),location:({spool:t,assignmentMap:e})=>{const n=e[t.id];if(!n)return i.jsx("span",{className:"text-sm text-bambu-gray",children:"-"});const r=n.printer_name||`Printer ${n.printer_id}`,a=n.ams_id===254||n.ams_id===255,s=!a&&n.ams_id>=128,o=II(n.ams_id,n.tray_id,s,a);return i.jsxs("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-purple-500/20 text-purple-400",children:[r," ",o,n.ams_label?` (${n.ams_label})`:""]})},label_weight:({spool:t})=>i.jsx("span",{className:"text-sm text-white",children:md(t.label_weight)}),net:({remaining:t})=>i.jsx("span",{className:"text-sm text-white",children:md(t)}),gross:({spool:t,remaining:e})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:md(e+t.core_weight)}),added_full:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.added_full==null?"-":t.added_full?"Yes":"No"}),used:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.weight_used>0?md(t.weight_used):"-"}),printed_total:()=>i.jsx("span",{className:"text-sm text-bambu-gray/50",children:"-"}),printed_since_weight:()=>i.jsx("span",{className:"text-sm text-bambu-gray/50",children:"-"}),note:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray max-w-[150px] truncate block",title:t.note||void 0,children:t.note||"-"}),pa_k:({spool:t})=>(t.k_profiles?.length??0)===0?i.jsx("span",{className:"text-sm text-bambu-gray",children:"-"}):i.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-bambu-green/20 text-bambu-green",children:"K"}),tag_id:({spool:t})=>{const e=t.tag_uid||t.tray_uuid;return e?i.jsx("span",{className:"text-sm text-bambu-gray font-mono",title:e,children:e.length>12?`${e.slice(0,6)}...${e.slice(-4)}`:e}):i.jsx("span",{className:"text-sm text-bambu-gray/50",children:"-"})},data_origin:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.data_origin||"-"}),tag_type:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.tag_type||"-"}),stock:({spool:t,t:e})=>t.slicer_filament?i.jsx("span",{className:"text-sm text-bambu-gray",children:"-"}):i.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-amber-500/20 text-amber-400",children:e("inventory.stock")}),remaining:({remaining:t,pct:e})=>i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("div",{className:"flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden",children:i.jsx("div",{className:`h-full rounded-full ${e>50?"bg-bambu-green":e>20?"bg-yellow-500":"bg-red-500"}`,style:{width:`${Math.min(e,100)}%`}})}),i.jsxs("span",{className:"text-xs text-bambu-gray min-w-[40px] text-right",children:[Math.round(t),"g"]})]}),spool_name:({spool:t,catalogMap:e})=>{const n=t.core_weight_catalog_id!=null?e[t.core_weight_catalog_id]:void 0;return i.jsx("span",{className:"text-sm text-bambu-gray",children:n?.name||"-"})},cost_per_kg:({spool:t,currencySymbol:e})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.cost_per_kg!=null?`${e}${t.cost_per_kg.toFixed(2)}`:"-"}),weight_check:({spool:t,onSyncWeight:e})=>{const n=t.last_scale_weight;if(n==null)return i.jsx("span",{className:"text-sm text-bambu-gray/50",title:"No scale measurement",children:"-"});const r=t.core_weight||0,a=Math.max(0,t.label_weight-t.weight_used)+r;let s,o;n0?`+${Math.round(s)}`:`${Math.round(s)}`,c=o?`Scale: ${Math.round(n)}g +`+n+"}"}return String(t)}function ftt({setting:t,onClose:e,onDeleted:n,onDuplicate:r,onEdit:a,hasPermission:s,t:o}){const{showToast:l}=pn(),c=cn(),[d,u]=w.useState(!1),{data:m,isLoading:p}=et({queryKey:["cloudSettingDetail",t.setting_id],queryFn:()=>be.getCloudSettingDetail(t.setting_id)}),f=pt({mutationFn:()=>be.deleteCloudSetting(t.setting_id),onSuccess:()=>{l(o("profiles.presets.toast.deleted")),c.invalidateQueries({queryKey:["cloudSettings"]}),n()},onError:b=>l(b.message,"error")}),y=hw(t.setting_id),v=D5(t.name,m?.setting?.inherits);return i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:i.jsx(At,{className:"w-full max-w-3xl max-h-[90vh] flex flex-col overflow-hidden",children:i.jsxs(Et,{className:"p-0 flex flex-col min-h-0 flex-1",children:[i.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("h2",{className:"text-xl font-semibold text-white truncate",children:t.name}),y&&i.jsx("span",{className:"px-2 py-0.5 text-xs font-medium bg-bambu-green/20 text-bambu-green rounded-full",children:o("profiles.presets.editable")})]}),i.jsxs("div",{className:"flex items-center gap-2 mt-1 text-sm text-bambu-gray",children:[i.jsx("span",{className:"capitalize",children:o(`profiles.presets.types.${t.type}`)}),v.printer&&i.jsxs(i.Fragment,{children:[i.jsx("span",{children:"•"}),i.jsx("span",{children:v.printer})]})]})]}),i.jsx("button",{onClick:e,className:"p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:i.jsx(qt,{className:"w-5 h-5"})})]}),i.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto p-4",children:p?i.jsx("div",{className:"flex items-center justify-center py-16",children:i.jsx(ft,{className:"w-8 h-8 text-bambu-green animate-spin"})}):m?i.jsx("pre",{className:"text-xs text-bambu-gray font-mono whitespace-pre-wrap break-all bg-bambu-dark p-4 rounded-lg border border-bambu-dark-tertiary overflow-x-auto max-w-full",children:CL(m)}):i.jsx("div",{className:"text-center py-16 text-bambu-gray",children:o("profiles.presets.failedToLoadDetails")})}),d?i.jsxs("div",{className:"flex-shrink-0 p-4 border-t border-bambu-dark-tertiary bg-red-500/5",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3 text-red-400",children:[i.jsx(jn,{className:"w-5 h-5"}),i.jsx("span",{className:"font-medium",children:o("profiles.presets.deleteConfirm")})]}),i.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:o("profiles.presets.deleteWarning",{name:t.name})}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Ie,{variant:"secondary",onClick:()=>u(!1),disabled:f.isPending,className:"flex-1",children:o("common.cancel")}),i.jsxs(Ie,{variant:"danger",onClick:()=>f.mutate(),disabled:f.isPending,className:"flex-1",children:[f.isPending?i.jsx(ft,{className:"w-4 h-4 animate-spin"}):i.jsx(an,{className:"w-4 h-4"}),o("common.delete")]})]})]}):i.jsx("div",{className:"flex-shrink-0 p-4 border-t border-bambu-dark-tertiary",children:i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Ie,{variant:"secondary",onClick:e,className:"flex-1",children:o("common.close")}),i.jsxs(Ie,{variant:"secondary",onClick:r,disabled:!s("cloud:auth"),title:s("cloud:auth")?void 0:o("profiles.presets.noDuplicatePermission"),children:[i.jsx(To,{className:"w-4 h-4"}),o("profiles.presets.duplicate")]}),y&&i.jsxs(i.Fragment,{children:[i.jsxs(Ie,{variant:"secondary",onClick:a,disabled:p||!m||!s("cloud:auth"),title:s("cloud:auth")?void 0:o("profiles.presets.noEditPermission"),children:[i.jsx(Xi,{className:"w-4 h-4"}),o("common.edit")]}),i.jsx(Ie,{variant:"danger",onClick:()=>u(!0),disabled:!s("cloud:auth"),title:s("cloud:auth")?void 0:o("profiles.presets.noDeletePermission"),children:i.jsx(an,{className:"w-4 h-4"})})]})]})})]})})})}function Xoe(){try{const t=localStorage.getItem("bambusy_preset_templates");return t?JSON.parse(t):[]}catch{return[]}}function Qoe(t){localStorage.setItem("bambusy_preset_templates",JSON.stringify(t))}function gtt({onClose:t,onApply:e,t:n}){const{showToast:r}=pn(),[a,s]=w.useState(Xoe),[o,l]=w.useState("all"),[c,d]=w.useState(null),[u,m]=w.useState(""),[p,f]=w.useState(""),[y,v]=w.useState("{}"),[b,g]=w.useState(null),[_,k]=w.useState(null),C=o==="all"?a:a.filter(Z=>Z.type===o),N=Z=>{s(Z),Qoe(Z)},P=Z=>{const I=a.filter(ee=>ee.id!==Z);N(I),k(null),r(n("profiles.templates.toast.deleted"))},T=Z=>{d(Z.id),m(Z.name),f(Z.description),v(JSON.stringify(Z.settings,null,2)),g(null)},j=()=>{if(!(!c||!u.trim()))try{const Z=JSON.parse(y),I=a.map(ee=>ee.id===c?{...ee,name:u.trim(),description:p.trim(),settings:Z}:ee);N(I),d(null),r(n("profiles.templates.toast.updated"))}catch(Z){g(Z.message)}},A=()=>{d(null),m(""),f(""),v("{}"),g(null)},F=Z=>{const I=a.map(ee=>ee.id===Z?{...ee,showInModal:!ee.showInModal}:ee);N(I)},G={filament:{label:n("profiles.presets.types.filament"),icon:iT,color:"text-amber-400"},print:{label:n("profiles.presets.types.process"),icon:yd,color:"text-blue-400"},printer:{label:n("profiles.presets.types.printer"),icon:_r,color:"text-purple-400"}},z=_?a.find(Z=>Z.id===_):null;return w.useEffect(()=>{const Z=I=>{I.key==="Escape"&&(_?k(null):c?A():t())};return window.addEventListener("keydown",Z),()=>window.removeEventListener("keydown",Z)},[_,c,t]),i.jsxs("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:[z&&i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-60",children:i.jsx(At,{className:"w-full max-w-md",children:i.jsxs(Et,{className:"p-6",children:[i.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[i.jsx("div",{className:"p-2 bg-red-500/20 rounded-lg",children:i.jsx(jn,{className:"w-6 h-6 text-red-400"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-lg font-semibold text-white",children:n("profiles.templates.deleteTitle")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:n("profiles.templates.deleteWarning")})]})]}),i.jsx("p",{className:"text-white mb-6",children:n("profiles.templates.deleteConfirm",{name:z.name})}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Ie,{variant:"secondary",onClick:()=>k(null),className:"flex-1",children:n("common.cancel")}),i.jsxs(Ie,{onClick:()=>P(_),className:"flex-1 bg-red-500 hover:bg-red-600",children:[i.jsx(an,{className:"w-4 h-4"}),n("common.delete")]})]})]})})}),i.jsx(At,{className:"w-full max-w-2xl max-h-[80vh] flex flex-col",children:i.jsxs(Et,{className:"p-0 flex flex-col h-full",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(fx,{className:"w-5 h-5 text-amber-400"}),n("profiles.templates.title")]}),i.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white",children:i.jsx(qt,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:"flex items-center gap-2 p-4 border-b border-bambu-dark-tertiary",children:[i.jsx("span",{className:"text-sm text-bambu-gray",children:n("profiles.templates.typeFilter")}),["all","filament","print","printer"].map(Z=>i.jsx("button",{onClick:()=>l(Z),className:`px-3 py-1 text-sm rounded-lg transition-colors ${o===Z?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:Z==="all"?n("common.all"):G[Z].label},Z))]}),i.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:C.length===0?i.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[i.jsx(fx,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),i.jsx("p",{children:n("profiles.templates.noTemplates")}),i.jsx("p",{className:"text-sm mt-1",children:n("profiles.templates.createFirst")})]}):i.jsx("div",{className:"space-y-2",children:C.map(Z=>{const I=G[Z.type],ee=I.icon;return c===Z.id?i.jsxs("div",{className:"p-4 bg-bambu-dark rounded-lg border border-bambu-green",children:[i.jsxs("div",{className:"grid grid-cols-2 gap-3 mb-3",children:[i.jsx("input",{type:"text",value:u,onChange:ae=>m(ae.target.value),placeholder:n("profiles.templates.namePlaceholder"),className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",autoFocus:!0}),i.jsx("input",{type:"text",value:p,onChange:ae=>f(ae.target.value),placeholder:n("profiles.templates.descriptionPlaceholder"),className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{className:"mb-3",children:[i.jsx("label",{className:"text-xs text-bambu-gray mb-1 block",children:n("profiles.templates.settingsJson")}),i.jsx("textarea",{value:y,onChange:ae=>{v(ae.target.value),g(null)},rows:6,className:`w-full px-3 py-2 bg-bambu-dark-secondary border rounded text-white text-sm font-mono focus:outline-none ${b?"border-red-500":"border-bambu-dark-tertiary focus:border-bambu-green"}`}),b&&i.jsx("p",{className:"text-xs text-red-400 mt-1",children:b})]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs(Ie,{size:"sm",onClick:j,disabled:!u.trim(),children:[i.jsx(as,{className:"w-4 h-4"}),"Save"]}),i.jsx(Ie,{size:"sm",variant:"secondary",onClick:A,children:"Cancel"})]})]},Z.id):i.jsxs("div",{className:"flex items-center gap-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary hover:border-bambu-gray-dark transition-colors",children:[i.jsx(ee,{className:`w-5 h-5 ${I.color} flex-shrink-0`}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("p",{className:"text-sm font-medium text-white",children:Z.name}),i.jsx("p",{className:"text-xs text-bambu-gray truncate",children:Z.description})]}),i.jsx("span",{className:"text-xs text-bambu-gray-dark px-2 py-1 bg-bambu-dark-secondary rounded",children:n("profiles.templates.fieldsCount",{count:Object.keys(Z.settings).length})}),i.jsx("button",{onClick:()=>F(Z.id),className:`p-1 transition-colors ${Z.showInModal?"text-bambu-green hover:text-bambu-green/70":"text-bambu-gray hover:text-white"}`,title:Z.showInModal?n("profiles.templates.shownInModals"):n("profiles.templates.hiddenInModals"),children:Z.showInModal?i.jsx(Pc,{className:"w-4 h-4"}):i.jsx(xw,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>e(Z),className:"px-3 py-1 text-xs bg-bambu-green/20 text-bambu-green rounded hover:bg-bambu-green/30 transition-colors",children:n("profiles.templates.apply")}),i.jsx("button",{onClick:()=>T(Z),className:"p-1 text-bambu-gray hover:text-white",title:n("common.edit"),children:i.jsx(Xi,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>k(Z.id),className:"p-1 text-bambu-gray hover:text-red-400",title:n("common.delete"),children:i.jsx(an,{className:"w-4 h-4"})})]},Z.id)})})})]})})]})}function Zoe({onClose:t,leftPreset:e,rightPreset:n,leftLabel:r,rightLabel:a,t:s}){const[o,l]=w.useState("changes"),[c,d]=w.useState(""),u=w.useMemo(()=>{const y=new Set([...Object.keys(e),...Object.keys(n)]),v=[];for(const b of y){if(b==="inherits"||b==="version")continue;const g=e[b],_=n[b],k=b in e,C=b in n;let N;!k&&C?N="added":k&&!C?N="removed":JSON.stringify(g)!==JSON.stringify(_)?N="changed":N="same",v.push({key:b,left:g,right:_,status:N})}return v.sort((b,g)=>{const _={changed:0,added:1,removed:2,same:3};return _[b.status]!==_[g.status]?_[b.status]-_[g.status]:b.key.localeCompare(g.key)})},[e,n]),m=w.useMemo(()=>{let y=[...u];if(o==="changes"&&(y=y.filter(v=>v.status!=="same")),c){const v=c.toLowerCase();y=y.filter(b=>b.key.toLowerCase().includes(v)||String(b.left).toLowerCase().includes(v)||String(b.right).toLowerCase().includes(v))}return y},[u,o,c]),p=w.useMemo(()=>({added:u.filter(y=>y.status==="added").length,removed:u.filter(y=>y.status==="removed").length,changed:u.filter(y=>y.status==="changed").length,same:u.filter(y=>y.status==="same").length}),[u]),f=y=>{if(y===void 0)return"—";if(y===null)return"null";if(Array.isArray(y))return y.length===0?"[]":y.length===1?String(y[0]):y.join(", ");if(typeof y=="object")return JSON.stringify(y);const v=String(y);if(v.includes("\\n")||v.length>100){const b=v.split("\\n").length;if(b>1)return`[${b} lines of G-code/script]`;if(v.length>100)return v.substring(0,100)+"…"}return v};return w.useEffect(()=>{const y=v=>{v.key==="Escape"&&t()};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[t]),i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsx(At,{className:"w-full max-w-4xl max-h-[85vh] flex flex-col overflow-hidden",children:i.jsxs(Et,{className:"p-0 flex flex-col min-h-0 flex-1",children:[i.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Kb,{className:"w-5 h-5 text-blue-400"}),s("profiles.diff.title")]}),i.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white",children:i.jsx(qt,{className:"w-5 h-5"})})]}),i.jsxs("div",{className:"flex-shrink-0 grid grid-cols-2 gap-4 p-4 border-b border-bambu-dark-tertiary bg-bambu-dark",children:[i.jsxs("div",{className:"text-center",children:[i.jsx("span",{className:"text-sm text-bambu-gray",children:s("profiles.diff.left")}),i.jsx("p",{className:"text-white font-medium truncate",children:r})]}),i.jsxs("div",{className:"text-center",children:[i.jsx("span",{className:"text-sm text-bambu-gray",children:s("profiles.diff.right")}),i.jsx("p",{className:"text-white font-medium truncate",children:a})]})]}),i.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[i.jsxs("span",{className:"flex items-center gap-1 text-green-400",children:[i.jsx(ir,{className:"w-3.5 h-3.5"}),p.added," ",s("profiles.diff.added")]}),i.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[i.jsx(Uk,{className:"w-3.5 h-3.5"}),p.removed," ",s("profiles.diff.removed")]}),i.jsxs("span",{className:"flex items-center gap-1 text-amber-400",children:[i.jsx(S3,{className:"w-3.5 h-3.5"}),p.changed," ",s("profiles.diff.changed")]}),i.jsxs("span",{className:"flex items-center gap-1 text-bambu-gray",children:[i.jsx(QM,{className:"w-3.5 h-3.5"}),p.same," ",s("profiles.diff.same")]})]}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs("div",{className:"relative",children:[i.jsx(Fr,{className:"absolute left-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:c,onChange:y=>d(y.target.value),placeholder:s("profiles.diff.searchFields"),className:"pl-8 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none w-48"})]}),p.same>0&&i.jsxs("div",{className:"flex rounded overflow-hidden border border-bambu-dark-tertiary",children:[i.jsx("button",{onClick:()=>l("changes"),className:`px-3 py-1.5 text-sm transition-colors ${o==="changes"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:s("profiles.diff.changes")}),i.jsx("button",{onClick:()=>l("all"),className:`px-3 py-1.5 text-sm transition-colors ${o==="all"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:s("common.all")})]})]})]}),i.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:m.length===0?i.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[i.jsx(QM,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),i.jsx("p",{children:s(o==="changes"?"profiles.diff.noDifferences":"profiles.diff.noFieldsMatch")})]}):i.jsxs("table",{className:"w-full",children:[i.jsx("thead",{className:"sticky top-0 bg-bambu-dark-secondary",children:i.jsxs("tr",{className:"text-sm text-bambu-gray border-b border-bambu-dark-tertiary",children:[i.jsx("th",{className:"text-left p-3 w-1/3",children:s("profiles.diff.field")}),i.jsx("th",{className:"text-left p-3 w-1/3",children:r}),i.jsx("th",{className:"text-left p-3 w-1/3",children:a})]})}),i.jsx("tbody",{children:m.map(y=>{const v={added:"bg-green-500/10",removed:"bg-red-500/10",changed:"bg-amber-500/10",same:""}[y.status],b={added:i.jsx(ir,{className:"w-3.5 h-3.5 text-green-400"}),removed:i.jsx(Uk,{className:"w-3.5 h-3.5 text-red-400"}),changed:i.jsx(S3,{className:"w-3.5 h-3.5 text-amber-400"}),same:i.jsx(QM,{className:"w-3.5 h-3.5 text-bambu-gray-dark"})}[y.status];return i.jsxs("tr",{className:`border-b border-bambu-dark-tertiary ${v}`,children:[i.jsx("td",{className:"p-3",children:i.jsxs("div",{className:"flex items-center gap-2",children:[b,i.jsx("span",{className:"text-sm text-white font-mono",children:y.key})]})}),i.jsx("td",{className:"p-3",children:i.jsx("span",{className:`text-sm font-mono break-all ${y.status==="removed"?"text-red-300":y.status==="changed"?"text-white":"text-bambu-gray"}`,children:f(y.left)})}),i.jsx("td",{className:"p-3",children:i.jsx("span",{className:`text-sm font-mono break-all ${y.status==="added"?"text-green-300":y.status==="changed"?"text-white":"text-bambu-gray"}`,children:f(y.right)})})]},y.key)})})]})})]})})})}function btt({onClose:t,initialData:e,allPresets:n,t:r}){const{showToast:a}=pn(),s=cn(),o=!!e?.setting_id,[l,c]=w.useState("common"),[d,u]=w.useState(e?.type||"filament"),[m,p]=w.useState(e?.name?o?e.name:`${e.name} (Copy)`:""),[f,y]=w.useState(e?.base_id||""),[v,b]=w.useState(""),[g,_]=w.useState(e?.setting||{inherits:""}),[k,C]=w.useState(JSON.stringify(e?.setting||{inherits:""},null,2)),[N,P]=w.useState(null),[T,j]=w.useState(""),[A,F]=w.useState(!1),[G,z]=w.useState(""),[Z,I]=w.useState(!1),[ee,ae]=w.useState(Xoe),[X,ce]=w.useState(!1),[ue,pe]=w.useState(""),[K,se]=w.useState(""),[de,ge]=w.useState(!0),[Te,V]=w.useState(null),[J,D]=w.useState(!1),E=w.useMemo(()=>({filament:n.filament,print:n.process,printer:n.printer})[d]||[],[n,d]),U=w.useMemo(()=>E.filter(Ae=>hw(Ae.setting_id)),[E]),{data:W}=et({queryKey:["cloudFields",d],queryFn:()=>be.getCloudFields(d==="print"?"process":d),staleTime:1e3*60*60}),{data:B}=et({queryKey:["allPresetDetails",d,U.map(Ae=>Ae.setting_id).join(",")],queryFn:async()=>{const Ae={};for(let De=0;De{try{const Pe=await be.getCloudSettingDetail(Ke.setting_id);return{id:Ke.setting_id,detail:Pe}}catch{return null}}))).forEach(Ke=>{Ke&&(Ae[Ke.id]=Ke.detail)})}return Ae},enabled:U.length>0,staleTime:1e3*60*10}),{data:ie,isLoading:O}=et({queryKey:["cloudSettingDetail",f],queryFn:()=>be.getCloudSettingDetail(f),enabled:!!f});w.useEffect(()=>{l!=="json"&&C(JSON.stringify(g,null,2))},[g,l]);const $=w.useMemo(()=>({filament:n.filament,print:n.process,printer:n.printer}[d]||[]).filter(Be=>!hw(Be.setting_id)).sort((Be,De)=>Be.name.localeCompare(De.name)),[n,d]);w.useEffect(()=>{if(!f)return;const Ae=$.find(Be=>Be.setting_id===f);Ae&&(b(Ae.name),o||(_({inherits:Ae.name}),C(JSON.stringify({inherits:Ae.name},null,2))))},[f,$,o]);const Y=w.useMemo(()=>{const Ae=W?.fields||[],Be=new Set(Ae.map(Ke=>Ke.key)),De=new Set,We=new Set(["inherits","updated_time","compatible_printers","compatible_prints"]);B&&Object.values(B).forEach(Ke=>{Ke?.setting&&Object.keys(Ke.setting).forEach(Pe=>{!Be.has(Pe)&&!We.has(Pe)&&De.add(Pe)})}),Object.keys(g).forEach(Ke=>{!Be.has(Ke)&&!We.has(Ke)&&De.add(Ke)});const ye=Array.from(De).sort().map(Ke=>({key:Ke,label:Ke.replace(/_/g," ").replace(/\b\w/g,Pe=>Pe.toUpperCase()),type:"text",category:"discovered",description:r("profiles.presets.discoveredFromPresets")}));return[...Ae,...ye]},[W,B,g,r]),q=Y.filter(Ae=>Ae.label.toLowerCase().includes(T.toLowerCase())||Ae.key.toLowerCase().includes(T.toLowerCase())),te=()=>{if(G.trim()){const Ae=G.trim().toLowerCase().replace(/\s+/g,"_");oe(Ae,""),z(""),I(!1),a(r("profiles.presets.toast.fieldAdded",{key:Ae}))}},oe=(Ae,Be)=>{_(De=>{const We={...De};return Be===""||Be===void 0?delete We[Ae]:We[Ae]=Be,We})},he=Ae=>{_(Be=>({...Be,...Ae.settings})),V(Ae.name),a(r("profiles.templates.toast.applied"))},fe=()=>{if(!ue.trim())return;const Ae={...g};if(delete Ae.inherits,Object.keys(Ae).length===0){a(r("profiles.presets.noOverridesToSave"),"error");return}const Be={id:Date.now().toString(),name:ue.trim(),description:K.trim()||r("profiles.presets.customTemplate"),type:d,settings:Ae,showInModal:de},De=[...ee,Be];ae(De),Qoe(De),ce(!1),pe(""),se(""),ge(!0),a(r("profiles.templates.toast.created"))},re=w.useMemo(()=>ee.filter(Ae=>Ae.type===d&&Ae.showInModal),[d,ee]),L=Ae=>{C(Ae);try{const Be=JSON.parse(Ae);_(Be),P(null)}catch(Be){P(Be.message)}},R=Ae=>{Ae.preventDefault(),F(!1);const Be=Ae.dataTransfer.files[0];if(Be&&Be.name.endsWith(".json")){const De=new FileReader;De.onload=We=>{try{const ye=We.target?.result,Ke=JSON.parse(ye),Pe=Ke.setting||Ke;_(Ye=>({...Ye,...Pe})),C(JSON.stringify({...g,...Pe},null,2)),a(r("profiles.presets.fileImported"))}catch{a(r("profiles.presets.invalidJsonFile"),"error")}},De.readAsText(Be)}},ne=pt({mutationFn:()=>{const Ae={...g},Be=d==="filament"?"filament_settings_id":d==="print"?"print_settings_id":"printer_settings_id";Ae[Be]=`"${m}"`;const De={type:d,name:m,base_id:f,setting:Ae};return be.createCloudSetting(De)},onSuccess:async()=>{a(r("profiles.presets.toast.created")),await s.refetchQueries({queryKey:["cloudSettings"]}),t()},onError:Ae=>a(Ae.message,"error")}),ve=pt({mutationFn:()=>{if(!e?.setting_id)throw new Error(r("profiles.presets.noSettingId"));return be.updateCloudSetting(e.setting_id,{name:m,setting:g})},onSuccess:async()=>{a(r("profiles.presets.toast.updated")),s.removeQueries({queryKey:["cloudSettingDetail"]}),await s.refetchQueries({queryKey:["cloudSettings"]}),t()},onError:Ae=>a(Ae.message,"error")}),we=o?ve:ne,me=ie?.setting?.inherits,Me=me?$.find(Ae=>Ae.name===me):void 0,{data:xe}=et({queryKey:["cloudSettingDetail",Me?.setting_id],queryFn:()=>be.getCloudSettingDetail(Me.setting_id),enabled:!!Me?.setting_id}),je=w.useMemo(()=>{const Ae=xe?.setting||{},Be=ie?.setting||{},De=f&&B?.[f]?.setting?B[f].setting:{};return{...Ae,...Be,...De}},[f,ie,xe,B]),He=Ae=>{if(Ae==null)return"";if(Array.isArray(Ae)){const Be=[...new Set(Ae.map(De=>String(De)))];return Be.length===1?Be[0]:Ae.join(", ")}return String(Ae)},Oe=Ae=>{const Be=g[Ae.key],De=je[Ae.key],We=He(De),ye=O?r("common.loading"):We||"",Ke="w-full px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none";if(Ae.type==="boolean"){const Pe=Be==="1"||Be===void 0&&De==="1";return i.jsx("button",{type:"button",onClick:()=>oe(Ae.key,Be==="1"?"0":"1"),className:`w-8 h-5 rounded-full transition-colors ${Pe?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,children:i.jsx("div",{className:`w-4 h-4 rounded-full bg-white shadow transition-transform ${Pe?"translate-x-3.5":"translate-x-0.5"}`})})}return Ae.type==="select"?i.jsxs("select",{value:Be||"",onChange:Pe=>oe(Ae.key,Pe.target.value),className:Ke,children:[i.jsx("option",{value:"",children:ye}),Ae.options?.map(Pe=>i.jsx("option",{value:Pe.value,children:Pe.label},Pe.value))]}):i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:Ae.type==="number"?"number":"text",value:Be!==void 0?String(Be):"",onChange:Pe=>oe(Ae.key,Pe.target.value),step:Ae.step,min:Ae.min,max:Ae.max,placeholder:ye,className:Ke}),Ae.unit&&i.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:Ae.unit})]})},_e=w.useMemo(()=>ie?.setting?ie.setting:{},[ie]);return i.jsxs("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onDragOver:Ae=>{Ae.preventDefault(),F(!0)},onDragLeave:()=>F(!1),onDrop:R,children:[J&&f&&i.jsx(Zoe,{onClose:()=>D(!1),leftPreset:_e,rightPreset:g,leftLabel:r("profiles.presets.baseLabel",{name:v||f}),rightLabel:r("profiles.presets.currentLabel",{name:m||r("profiles.presets.newPreset")}),t:r}),i.jsx(At,{className:"w-full max-w-6xl max-h-[90vh] flex flex-col overflow-y-auto",children:i.jsxs(Et,{className:"p-0 flex flex-col h-full",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("h2",{className:"text-xl font-semibold text-white",children:r(o?"profiles.presets.editPreset":e?"profiles.presets.duplicatePreset":"profiles.presets.createNewPreset")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:r("profiles.presets.customizeSettings")})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[f&&i.jsxs("button",{onClick:()=>D(!0),className:"flex items-center gap-2 px-3 py-2 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors",title:r("profiles.presets.compareWithBase"),children:[i.jsx(Kb,{className:"w-4 h-4"}),r("profiles.presets.compare")]}),i.jsx("button",{onClick:t,className:"p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:i.jsx(qt,{className:"w-5 h-5"})})]})]}),A&&i.jsx("div",{className:"absolute inset-0 bg-bambu-green/10 border-2 border-dashed border-bambu-green rounded-lg flex items-center justify-center z-10",children:i.jsxs("div",{className:"text-center",children:[i.jsx(vi,{className:"w-12 h-12 text-bambu-green mx-auto mb-2"}),i.jsx("p",{className:"text-bambu-green font-medium",children:r("profiles.presets.dropJsonToImport")})]})}),i.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary space-y-3",children:[i.jsxs("div",{className:"grid grid-cols-3 gap-4 max-[640px]:grid-cols-1",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("common.type")}),i.jsxs("select",{value:d,onChange:Ae=>{u(Ae.target.value),y("")},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[i.jsx("option",{value:"filament",children:r("profiles.presets.types.filament")}),i.jsx("option",{value:"print",children:r("profiles.presets.types.process")}),i.jsx("option",{value:"printer",children:r("profiles.presets.types.printer")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("profiles.presets.basePreset")}),i.jsxs("select",{value:f,onChange:Ae=>y(Ae.target.value),className:"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",children:[i.jsx("option",{value:"",children:r("profiles.presets.selectBasePreset")}),$.map(Ae=>i.jsx("option",{value:Ae.setting_id,children:Ae.name},Ae.setting_id))]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:r("profiles.presets.presetName")}),i.jsx("input",{type:"text",value:m,onChange:Ae=>p(Ae.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",placeholder:r("profiles.presets.myCustomPreset")})]})]}),v&&i.jsx("div",{className:"text-xs text-bambu-gray",children:i.jsxs("p",{className:"flex items-center gap-1",children:[i.jsx(Zr,{className:"w-3 h-3 text-bambu-green"}),r("profiles.presets.inheritsFrom")," ",i.jsx("span",{className:"text-white",children:v}),O&&i.jsx(ft,{className:"w-3 h-3 animate-spin ml-1"})]})})]}),i.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary max-[640px]:flex-wrap max-[640px]:items-center",children:[i.jsxs("button",{onClick:()=>c("common"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${l==="common"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[i.jsx(J8,{className:"w-4 h-4"}),r("profiles.presets.tabs.common")]}),i.jsxs("button",{onClick:()=>c("fields"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${l==="fields"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[i.jsx(oT,{className:"w-4 h-4"}),r("profiles.presets.tabs.allFields")]}),i.jsxs("button",{onClick:()=>c("json"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${l==="json"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[i.jsx(XX,{className:"w-4 h-4"}),"JSON",N&&i.jsx(Oi,{className:"w-3 h-3 text-red-400"})]}),i.jsx("div",{className:"flex-1 max-[640px]:hidden"}),i.jsxs("button",{onClick:()=>{const Ae={name:m,type:d,base_id:f,setting:g},Be=new Blob([JSON.stringify(Ae,null,2)],{type:"application/json"}),De=URL.createObjectURL(Be),We=document.createElement("a");We.href=De,We.download=`${m||"preset"}.json`,document.body.appendChild(We),We.click(),document.body.removeChild(We),URL.revokeObjectURL(De),a(r("profiles.presets.toast.exported"))},className:"flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors",title:r("profiles.presets.exportToJson"),children:[i.jsx(fi,{className:"w-4 h-4"}),r("common.download")]}),i.jsxs("button",{onClick:()=>document.getElementById("file-import")?.click(),className:"flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors",title:r("profiles.presets.importFromJson"),children:[i.jsx(vi,{className:"w-4 h-4"}),r("common.upload")]}),i.jsx("input",{id:"file-import",type:"file",accept:".json",className:"hidden",onChange:Ae=>{const Be=Ae.target.files?.[0];if(Be){const De=new FileReader;De.onload=We=>{try{const ye=JSON.parse(We.target?.result),Ke=ye.setting||ye;_(Pe=>({...Pe,...Ke})),a(r("profiles.presets.fileImported"))}catch{a(r("profiles.presets.invalidJson"),"error")}},De.readAsText(Be)}}})]}),i.jsxs("div",{className:"flex-1 p-4",children:[l==="common"&&i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:[i.jsx(fx,{className:"w-4 h-4 text-amber-400"}),r("profiles.templates.title")]}),Object.keys(g).filter(Ae=>Ae!=="inherits").length>0&&i.jsxs("button",{onClick:()=>ce(!X),className:"text-xs text-bambu-gray hover:text-white flex items-center gap-1 transition-colors",children:[i.jsx(as,{className:"w-3 h-3"}),r("profiles.presets.saveAsTemplate")]})]}),X&&i.jsxs("div",{className:"mb-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"grid grid-cols-2 gap-2 mb-2",children:[i.jsx("input",{type:"text",value:ue,onChange:Ae=>pe(Ae.target.value),placeholder:r("profiles.templates.namePlaceholder"),className:"px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",autoFocus:!0}),i.jsx("input",{type:"text",value:K,onChange:Ae=>se(Ae.target.value),placeholder:r("profiles.templates.descriptionPlaceholder"),className:"px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex gap-2",children:[i.jsxs(Ie,{size:"sm",onClick:fe,disabled:!ue.trim(),children:[i.jsx(as,{className:"w-3 h-3"}),r("common.save")]}),i.jsx(Ie,{size:"sm",variant:"secondary",onClick:()=>ce(!1),children:r("common.cancel")})]}),i.jsxs("button",{onClick:()=>ge(!de),className:`flex items-center gap-1.5 text-xs transition-colors ${de?"text-bambu-green":"text-bambu-gray hover:text-white"}`,children:[de?i.jsx(Pc,{className:"w-3.5 h-3.5"}):i.jsx(xw,{className:"w-3.5 h-3.5"}),r(de?"profiles.templates.shownInModals":"profiles.templates.hiddenInModals")]})]})]}),Te&&i.jsxs("div",{className:"mb-3 px-3 py-2 bg-bambu-green/10 border border-bambu-green/30 rounded-lg flex items-center gap-2",children:[i.jsx(Zr,{className:"w-4 h-4 text-bambu-green"}),i.jsxs("span",{className:"text-sm text-bambu-green",children:[r("profiles.presets.templateApplied")," ",i.jsx("span",{className:"font-medium",children:Te})]}),i.jsx("button",{onClick:()=>V(null),className:"ml-auto text-bambu-green/70 hover:text-bambu-green",children:i.jsx(qt,{className:"w-4 h-4"})})]}),i.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[re.map(Ae=>i.jsxs("button",{onClick:()=>he(Ae),className:"p-3 text-left bg-bambu-dark border border-bambu-dark-tertiary rounded-lg hover:border-bambu-gray-dark transition-colors",children:[i.jsx("p",{className:"text-sm font-medium text-white",children:Ae.name}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:Ae.description})]},Ae.id)),re.length===0&&i.jsx("p",{className:"col-span-3 text-center text-bambu-gray text-sm py-4",children:r("profiles.presets.noTemplatesSelected")})]}),i.jsx("p",{className:"text-xs text-bambu-gray-dark mt-2 text-center",children:r("profiles.presets.manageTemplatesHint")})]}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:r("profiles.presets.commonSettings")}),i.jsx("div",{className:"grid grid-cols-2 gap-x-6 gap-y-3",children:Y.slice(0,10).map(Ae=>i.jsxs("div",{className:"flex items-center justify-between gap-4 max-[640px]:flex-col max-[640px]:items-start",children:[i.jsx("label",{className:"text-sm text-bambu-gray flex-shrink-0",children:Ae.label}),i.jsx("div",{className:"w-48 max-[640px]:w-full",children:Oe(Ae)})]},Ae.key))})]}),Object.keys(g).length>1&&i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:r("profiles.presets.currentOverrides")}),i.jsx("div",{className:"flex flex-wrap gap-2",children:Object.entries(g).filter(([Ae])=>Ae!=="inherits").map(([Ae,Be])=>i.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 bg-bambu-green/10 text-bambu-green text-xs rounded",children:[Ae,": ",String(Be).slice(0,20),i.jsx("button",{onClick:()=>oe(Ae,void 0),className:"hover:text-white",children:i.jsx(qt,{className:"w-3 h-3"})})]},Ae))})]})]}),l==="fields"&&i.jsxs("div",{className:"grid grid-cols-2 gap-6",style:{height:"400px"},children:[i.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3 flex-shrink-0",children:[i.jsx("h3",{className:"text-sm font-medium text-white",children:r("profiles.presets.availableFields")}),i.jsx("span",{className:"text-xs text-bambu-gray",children:B?r("profiles.templates.fieldsCount",{count:Y.length}):r("common.loading")})]}),i.jsxs("div",{className:"relative mb-3 flex-shrink-0",children:[i.jsx(Fr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:T,onChange:Ae=>j(Ae.target.value),placeholder:r("profiles.presets.searchFieldsPlaceholder"),className:"w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{className:"flex-1 overflow-y-auto space-y-1 pr-2 min-h-0",children:[q.filter(Ae=>!(Ae.key in g)).map(Ae=>{const Be=je[Ae.key],De=He(Be);return i.jsxs("div",{onClick:()=>{_(We=>({...We,[Ae.key]:De||""}))},className:"flex items-center justify-between gap-2 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors cursor-pointer group",children:[i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("p",{className:"text-sm text-white truncate",children:Ae.label}),i.jsx("p",{className:"text-xs text-bambu-gray-dark truncate",children:Ae.key})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[De&&i.jsxs("span",{className:"text-xs text-bambu-gray bg-bambu-dark px-2 py-0.5 rounded max-w-32 truncate",title:De,children:[De.slice(0,20),De.length>20?"...":""]}),i.jsx("div",{className:"w-6 h-6 flex items-center justify-center rounded bg-bambu-dark-tertiary group-hover:bg-bambu-green/20 transition-colors",children:i.jsx(ir,{className:"w-4 h-4 text-bambu-gray group-hover:text-bambu-green transition-colors"})})]})]},Ae.key)}),q.filter(Ae=>!(Ae.key in g)).length===0&&i.jsx("p",{className:"text-center text-bambu-gray py-4 text-sm",children:r(T?"profiles.presets.noMatchingFields":"profiles.presets.allFieldsAdded")})]}),i.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0",children:Z?i.jsxs("div",{className:"flex gap-2",children:[i.jsx("input",{type:"text",value:G,onChange:Ae=>z(Ae.target.value),onKeyDown:Ae=>Ae.key==="Enter"&&te(),placeholder:"custom_field_name",className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none",autoFocus:!0}),i.jsx(Ie,{size:"sm",onClick:te,disabled:!G.trim(),children:i.jsx(ir,{className:"w-4 h-4"})}),i.jsx(Ie,{size:"sm",variant:"secondary",onClick:()=>{I(!1),z("")},children:i.jsx(qt,{className:"w-4 h-4"})})]}):i.jsxs("button",{onClick:()=>I(!0),className:"w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors",children:[i.jsx(ir,{className:"w-4 h-4"}),r("profiles.presets.addCustomField")]})})]}),i.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3 flex-shrink-0",children:[i.jsx("h3",{className:"text-sm font-medium text-white",children:r("profiles.presets.yourOverrides")}),i.jsx("span",{className:"text-xs text-bambu-gray",children:r("profiles.templates.fieldsCount",{count:Object.keys(g).filter(Ae=>Ae!=="inherits").length})})]}),i.jsxs("div",{className:"flex-1 overflow-y-auto space-y-2 pr-2 min-h-0",children:[Object.entries(g).filter(([Ae])=>Ae!=="inherits").map(([Ae,Be])=>{const De=Y.find(We=>We.key===Ae);return i.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm font-medium text-white",children:De?.label||Ae}),i.jsx("p",{className:"text-xs text-bambu-gray-dark",children:Ae})]}),i.jsx("button",{onClick:()=>oe(Ae,void 0),className:"p-1 text-bambu-gray hover:text-red-400 transition-colors",children:i.jsx(qt,{className:"w-4 h-4"})})]}),De?Oe(De):i.jsx("input",{type:"text",value:String(Be),onChange:We=>oe(Ae,We.target.value),className:"w-full px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"})]},Ae)}),Object.keys(g).filter(Ae=>Ae!=="inherits").length===0&&i.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[i.jsx(J8,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),i.jsx("p",{className:"text-sm",children:r("profiles.presets.noOverridesYet")}),i.jsx("p",{className:"text-xs mt-1",children:r("profiles.presets.clickFieldsToAdd")})]})]}),Object.keys(g).filter(Ae=>Ae!=="inherits").length>0&&i.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0",children:i.jsxs("button",{onClick:()=>{ce(!0),c("common")},className:"w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors",children:[i.jsx(as,{className:"w-4 h-4"}),r("profiles.presets.saveAsTemplate")]})})]})]}),l==="json"&&i.jsxs("div",{className:"space-y-2",children:[N&&i.jsxs("div",{className:"flex items-center gap-2 text-red-400 text-sm",children:[i.jsx(Oi,{className:"w-4 h-4"}),N]}),i.jsx("textarea",{value:k,onChange:Ae=>L(Ae.target.value),className:`w-full h-80 px-3 py-2 bg-bambu-dark border rounded-lg text-white text-xs font-mono focus:outline-none resize-none ${N?"border-red-500 focus:border-red-500":"border-bambu-dark-tertiary focus:border-bambu-green"}`,spellCheck:!1}),i.jsx("p",{className:"text-xs text-bambu-gray",children:r("profiles.presets.jsonTip")})]})]}),i.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex gap-2",children:[i.jsx(Ie,{variant:"secondary",onClick:t,className:"flex-1",children:r("common.cancel")}),i.jsxs(Ie,{onClick:()=>we.mutate(),disabled:we.isPending||!m.trim()||!o&&!f||!!N,className:"flex-1",children:[we.isPending?i.jsx(ft,{className:"w-4 h-4 animate-spin"}):o?i.jsx(as,{className:"w-4 h-4"}):i.jsx(ir,{className:"w-4 h-4"}),r(o?"common.save":e?"common.duplicate":"common.create")]})]})]})})]})}function xtt({settings:t,lastSyncTime:e,onRefresh:n,isRefreshing:r,printers:a,hasPermission:s,t:o}){const[l,c]=w.useState(""),[d,u]=w.useState("all"),[m,p]=w.useState("all"),[f,y]=w.useState("all"),[v,b]=w.useState("all"),[g,_]=w.useState("all"),[k,C]=w.useState("all"),[N,P]=w.useState(null),[T,j]=w.useState(!1),[A,F]=w.useState(!1),[G,z]=w.useState(null),[Z,I]=w.useState(null),[ee,ae]=w.useState(null),[X,ce]=w.useState(!1),[ue,pe]=w.useState([null,null]),[K,se]=w.useState(!1),[de,ge]=w.useState(null),Te=cn(),V=w.useMemo(()=>[...t.filament.map(te=>({...te,type:"filament"})),...t.printer.map(te=>({...te,type:"printer"})),...t.process.map(te=>({...te,type:"process"}))].map(te=>({...te,meta:D5(te.name)})),[t]),J=w.useMemo(()=>{const q=new Set,te=new Set,oe=new Set;return V.forEach(he=>{he.meta.nozzle&&q.add(he.meta.nozzle),he.meta.filamentType&&te.add(he.meta.filamentType),he.meta.layerHeight&&oe.add(he.meta.layerHeight)}),{printers:a.map(he=>({id:he.id.toString(),name:he.name})),nozzles:Array.from(q).sort((he,fe)=>parseFloat(he)-parseFloat(fe)),filaments:Array.from(te).sort(),layerHeights:Array.from(oe).sort((he,fe)=>parseFloat(he)-parseFloat(fe))}},[V,a]),D=w.useMemo(()=>f==="all"?null:a.find(te=>te.id.toString()===f)?.model||null,[f,a]),E=w.useMemo(()=>V.filter(q=>d==="all"||q.type===d).filter(q=>{if(m==="all")return!0;const te=hw(q.setting_id);return m==="custom"?te:!te}).filter(q=>{if(f==="all"||!D)return!0;const te=q.meta.printer?.toLowerCase()||"",oe=D.toLowerCase();return te.includes(oe)||oe.includes(te)}).filter(q=>v==="all"||q.meta.nozzle===v).filter(q=>g==="all"||q.meta.filamentType===g).filter(q=>k==="all"||q.meta.layerHeight===k).filter(q=>l===""||q.name.toLowerCase().includes(l.toLowerCase())).sort((q,te)=>q.name.localeCompare(te.name)),[V,d,m,f,D,v,g,k,l]),U=q=>{if(X){const te=ue[0]?.setting_id===q.setting_id,oe=ue[1]?.setting_id===q.setting_id;if(te)pe([ue[1],null]);else if(oe)pe([ue[0],null]);else if(!ue[0])pe([q,null]);else if(ue[1]){if(ue[0].type!==q.type)return;pe([ue[0],q])}else{if(ue[0].type!==q.type)return;pe([ue[0],q])}}else P(q)},W=q=>{if(ue[0]?.setting_id===q.setting_id)return 0;if(ue[1]?.setting_id===q.setting_id)return 1},B=async q=>{try{const te=await be.getCloudSettingDetail(q.setting_id),oe=q.type==="process"?"print":q.type;z({type:oe,name:q.name,base_id:te.base_id||"GFSA00",setting:te.setting||{}}),P(null)}catch(te){console.error("Failed to fetch preset details for duplication:",te)}},ie=async q=>{try{Te.removeQueries({queryKey:["cloudSettingDetail",q.setting_id]});const te=await be.getCloudSettingDetail(q.setting_id),oe=q.type==="process"?"print":q.type;I({type:oe,name:q.name,base_id:te.base_id||"GFSA00",setting:te.setting||{},setting_id:q.setting_id}),P(null)}catch(te){console.error("Failed to fetch preset details for editing:",te)}},O=()=>{u("all"),p("all"),y("all"),b("all"),_("all"),C("all"),c("")},$=d!=="all"||m!=="all"||f!=="all"||v!=="all"||g!=="all"||k!=="all"||l!=="",Y=t.filament.length+t.printer.length+t.process.length;return i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"space-y-4 mb-6",children:[i.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsx(Fr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:l,onChange:q=>c(q.target.value),placeholder:o("profiles.cloudView.searchPlaceholder"),className:"w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{className:"flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center",children:[i.jsxs(Ie,{variant:X?"primary":"secondary",onClick:()=>{X?(ce(!1),pe([null,null])):ce(!0)},children:[i.jsx(Kb,{className:"w-4 h-4"}),o(X?"common.cancel":"profiles.presets.compare")]}),i.jsxs(Ie,{variant:"secondary",onClick:()=>F(!0),disabled:!s("cloud:auth"),title:s("cloud:auth")?void 0:o("profiles.cloudView.noTemplatesPermission"),children:[i.jsx(fx,{className:"w-4 h-4"}),o("profiles.cloudView.templates")]}),i.jsxs(Ie,{variant:"secondary",onClick:n,disabled:r||!s("cloud:auth"),title:s("cloud:auth")?void 0:o("profiles.cloudView.noRefreshPermission"),children:[i.jsx(vr,{className:`w-4 h-4 ${r?"animate-spin":""}`}),o("profiles.cloudView.refresh")]}),i.jsxs(Ie,{onClick:()=>j(!0),disabled:!s("cloud:auth"),title:s("cloud:auth")?void 0:o("profiles.cloudView.noCreatePermission"),children:[i.jsx(ir,{className:"w-4 h-4"}),o("profiles.cloudView.newPreset")]})]})]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx(sT,{className:"w-4 h-4 text-bambu-gray"}),i.jsx(Mb,{label:o("profiles.cloudView.filters.type"),value:d,options:[{value:"all",label:o("profiles.cloudView.filters.all"),count:Y},{value:"filament",label:o("profiles.cloudView.filters.filament"),count:t.filament.length},{value:"printer",label:o("profiles.cloudView.filters.printer"),count:t.printer.length},{value:"process",label:o("profiles.cloudView.filters.process"),count:t.process.length}],onChange:q=>u(q)}),i.jsx(Mb,{label:o("profiles.cloudView.filters.owner"),value:m,options:[{value:"all",label:o("profiles.cloudView.filters.all")},{value:"custom",label:o("profiles.cloudView.filters.myPresets")},{value:"builtin",label:o("profiles.cloudView.filters.builtIn")}],onChange:q=>p(q)}),J.printers.length>0&&i.jsx(Mb,{label:o("profiles.cloudView.filters.printer"),value:f,options:[{value:"all",label:o("profiles.cloudView.filters.all")},...J.printers.map(q=>({value:q.id,label:q.name}))],onChange:y}),J.nozzles.length>0&&i.jsx(Mb,{label:o("profiles.cloudView.filters.nozzle"),value:v,options:[{value:"all",label:o("profiles.cloudView.filters.all")},...J.nozzles.map(q=>({value:q,label:q}))],onChange:b}),J.filaments.length>0&&(d==="all"||d==="filament")&&i.jsx(Mb,{label:o("profiles.cloudView.filters.filament"),value:g,options:[{value:"all",label:o("profiles.cloudView.filters.all")},...J.filaments.map(q=>({value:q,label:q}))],onChange:_}),J.layerHeights.length>0&&(d==="all"||d==="process")&&i.jsx(Mb,{label:o("profiles.cloudView.filters.layer"),value:k,options:[{value:"all",label:o("profiles.cloudView.filters.all")},...J.layerHeights.map(q=>({value:q,label:q}))],onChange:C}),$&&i.jsx("button",{onClick:O,className:"px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors",children:o("profiles.cloudView.clearFilters")})]})]}),X&&i.jsx("div",{className:"mb-4 p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-4",children:[i.jsx(Kb,{className:"w-5 h-5 text-blue-400"}),i.jsx("span",{className:"text-white font-medium",children:o("profiles.cloudView.compareMode")}),i.jsx("span",{className:"text-bambu-gray",children:ue[0]?o("profiles.cloudView.selectAnotherPreset",{type:ue[0].type}):o("profiles.cloudView.clickTwoPresets")})]}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${ue[0]?"bg-blue-500/30 text-blue-700 dark:text-blue-300":"bg-bambu-dark text-bambu-gray"}`,children:ue[0]?ue[0].name:o("profiles.cloudView.selectFirst")}),i.jsx(S3,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("span",{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${ue[1]?"bg-blue-500/30 text-blue-700 dark:text-blue-300":"bg-bambu-dark text-bambu-gray"}`,children:ue[1]?ue[1].name:o("profiles.cloudView.selectSecond")})]}),ue[0]&&ue[1]&&i.jsxs(Ie,{size:"sm",onClick:async()=>{try{const[q,te]=await Promise.all([be.getCloudSettingDetail(ue[0].setting_id),be.getCloudSettingDetail(ue[1].setting_id)]);ge([q.setting||{},te.setting||{}]),se(!0)}catch{}},children:[i.jsx(Kb,{className:"w-4 h-4"}),o("profiles.cloudView.compareNow")]})]})]})}),i.jsxs("div",{className:"flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray",children:[e&&i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx(Zn,{className:"w-3 h-3"}),o("profiles.cloudView.lastSynced")," ",C0(e.toISOString(),"system",o)]}),i.jsx("span",{children:o("profiles.cloudView.showingCount",{showing:E.length,total:Y})}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-bambu-green"}),i.jsxs("span",{children:["= ",o("profiles.presets.myPreset")]})]})]}),E.length===0?i.jsxs("div",{className:"text-center py-16",children:[i.jsx(Ki,{className:"w-12 h-12 text-bambu-gray-dark mx-auto mb-4"}),i.jsx("p",{className:"text-bambu-gray",children:o("profiles.cloudView.noPresetsFound")}),$&&i.jsx("button",{onClick:O,className:"mt-2 text-sm text-bambu-green hover:text-bambu-green-light",children:o("profiles.cloudView.clearFilters")})]}):i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3 px-1",children:[i.jsx(iT,{className:"w-4 h-4 text-amber-400"}),i.jsx("h3",{className:"text-sm font-medium text-bambu-gray",children:o("profiles.cloudView.columns.filament")}),i.jsxs("span",{className:"text-xs text-bambu-gray-dark",children:["(",E.filter(q=>q.type==="filament").length,")"]})]}),i.jsxs("div",{className:"space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1",children:[E.filter(q=>q.type==="filament").map(q=>i.jsx(XD,{setting:q,onClick:()=>U(q),onDuplicate:()=>B(q),compareMode:X,isCompareSelected:W(q)!==void 0,compareIndex:W(q),compareDisabled:X&&!!ue[0]&&ue[0].type!==q.type,t:o},q.setting_id)),E.filter(q=>q.type==="filament").length===0&&i.jsx("p",{className:"text-xs text-bambu-gray-dark px-3 py-2",children:o("profiles.cloudView.noFilamentPresets")})]})]}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3 px-1",children:[i.jsx(yd,{className:"w-4 h-4 text-blue-400"}),i.jsx("h3",{className:"text-sm font-medium text-bambu-gray",children:o("profiles.cloudView.columns.process")}),i.jsxs("span",{className:"text-xs text-bambu-gray-dark",children:["(",E.filter(q=>q.type==="process").length,")"]})]}),i.jsxs("div",{className:"space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1",children:[E.filter(q=>q.type==="process").map(q=>i.jsx(XD,{setting:q,onClick:()=>U(q),onDuplicate:()=>B(q),compareMode:X,isCompareSelected:W(q)!==void 0,compareIndex:W(q),compareDisabled:X&&!!ue[0]&&ue[0].type!==q.type,t:o},q.setting_id)),E.filter(q=>q.type==="process").length===0&&i.jsx("p",{className:"text-xs text-bambu-gray-dark px-3 py-2",children:o("profiles.cloudView.noProcessPresets")})]})]}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3 px-1",children:[i.jsx(_r,{className:"w-4 h-4 text-purple-400"}),i.jsx("h3",{className:"text-sm font-medium text-bambu-gray",children:o("profiles.cloudView.columns.printer")}),i.jsxs("span",{className:"text-xs text-bambu-gray-dark",children:["(",E.filter(q=>q.type==="printer").length,")"]})]}),i.jsxs("div",{className:"space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1",children:[E.filter(q=>q.type==="printer").map(q=>i.jsx(XD,{setting:q,onClick:()=>U(q),onDuplicate:()=>B(q),compareMode:X,isCompareSelected:W(q)!==void 0,compareIndex:W(q),compareDisabled:X&&!!ue[0]&&ue[0].type!==q.type,t:o},q.setting_id)),E.filter(q=>q.type==="printer").length===0&&i.jsx("p",{className:"text-xs text-bambu-gray-dark px-3 py-2",children:o("profiles.cloudView.noPrinterPresets")})]})]})]}),N&&i.jsx(ftt,{setting:N,onClose:()=>P(null),onDeleted:()=>P(null),onDuplicate:()=>B(N),onEdit:()=>ie(N),hasPermission:s,t:o}),(T||G||Z||ee)&&i.jsx(btt,{onClose:()=>{j(!1),z(null),I(null),ae(null)},initialData:Z||G||(ee?{type:ee.type,name:"",base_id:"",setting:ee.setting}:void 0),allPresets:t,t:o}),A&&i.jsx(gtt,{onClose:()=>F(!1),onApply:q=>{ae({type:q.type,setting:q.settings}),F(!1)},t:o}),K&&de&&ue[0]&&ue[1]&&i.jsx(Zoe,{onClose:()=>{se(!1),ge(null)},leftPreset:de[0],rightPreset:de[1],leftLabel:ue[0].name,rightLabel:ue[1].name,t:o})]})}function ytt(){const{t}=jt(),e=cn(),{showToast:n}=pn(),{hasPermission:r}=Ar(),[a,s]=w.useState("cloud"),[o,l]=w.useState(),{data:c,isLoading:d}=et({queryKey:["cloudStatus"],queryFn:be.getCloudStatus}),{data:u=[]}=et({queryKey:["printers"],queryFn:be.getPrinters}),{data:m,isLoading:p,refetch:f,dataUpdatedAt:y}=et({queryKey:["cloudSettings"],queryFn:()=>be.getCloudSettings(),enabled:!!c?.is_authenticated,retry:!1,staleTime:1e3*60*5});w.useEffect(()=>{y&&l(new Date(y))},[y]);const v=pt({mutationFn:be.cloudLogout,onSuccess:()=>{e.invalidateQueries({queryKey:["cloudStatus"]}),e.removeQueries({queryKey:["cloudSettings"]}),n(t("profiles.toast.loggedOut"))}}),b=()=>{e.invalidateQueries({queryKey:["cloudStatus"]})};return d?i.jsx("div",{className:"p-4 md:p-8 flex items-center justify-center min-h-[400px]",children:i.jsx(ft,{className:"w-8 h-8 text-bambu-green animate-spin"})}):i.jsxs("div",{className:"p-6 lg:p-8",children:[i.jsxs("div",{className:"mb-6",children:[i.jsx("h1",{className:"text-2xl font-bold text-white",children:t("profiles.title")}),i.jsx("p",{className:"text-bambu-gray",children:t("profiles.subtitle")})]}),i.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary mb-6",children:[i.jsxs("button",{onClick:()=>s("cloud"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${a==="cloud"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[i.jsx(Vx,{className:"w-4 h-4"}),t("profiles.tabs.cloud")]}),i.jsxs("button",{onClick:()=>s("local"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${a==="local"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[i.jsx(Gx,{className:"w-4 h-4"}),t("profiles.tabs.local")]}),i.jsxs("button",{onClick:()=>s("kprofiles"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${a==="kprofiles"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[i.jsx(yw,{className:"w-4 h-4"}),t("profiles.tabs.kprofiles")]})]}),a==="cloud"&&i.jsxs(i.Fragment,{children:[c?.is_authenticated&&i.jsxs("div",{className:"flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"w-2 h-2 rounded-full bg-bambu-green animate-pulse"}),i.jsxs("span",{className:"text-sm text-bambu-gray",children:[t("profiles.connectedAs")," ",i.jsx("span",{className:"text-white",children:c.email})]})]}),i.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>v.mutate(),disabled:v.isPending||!r("cloud:auth"),title:r("cloud:auth")?void 0:t("profiles.noLogoutPermission"),children:[i.jsx(C3,{className:"w-4 h-4"}),t("profiles.logout")]})]}),c?.is_authenticated?p?i.jsx("div",{className:"flex items-center justify-center py-16",children:i.jsx(ft,{className:"w-8 h-8 text-bambu-green animate-spin"})}):m?i.jsx(xtt,{settings:m,lastSyncTime:o,onRefresh:()=>f(),isRefreshing:p,printers:u,hasPermission:r,t}):i.jsxs("div",{className:"text-center py-16",children:[i.jsx("p",{className:"text-bambu-gray mb-4",children:t("profiles.failedToLoad")}),i.jsx(Ie,{onClick:()=>f(),children:t("profiles.retry")})]}):i.jsx(htt,{onSuccess:b,t})]}),a==="local"&&i.jsx(mtt,{}),a==="kprofiles"&&i.jsx(ltt,{}),i.jsx(ptt,{})]})}const Gv={Droplet:iT,Flame:Gp,Ruler:Qge,Sparkles:fx,Square:rl,Cable:KL,Wrench:Ff,Calendar:Xr,Timer:Nu,Cog:Ope,Fan:QX,Zap:Wl,Wind:uQ,Thermometer:hT,Layers:Ki,Box:aa,Target:oQ,RefreshCw:vr,Settings:mT,Filter:sT,CircleDot:xpe};function b0(t){return t&&Gv[t]||Ff}function Eb(t,e,n){if(e==="days"){if(t<1)return n?n("common.today"):"Today";if(t===1)return n?n("maintenance.day"):"1 day";if(t<7){const a=Math.round(t);return n?n("maintenance.days",{count:a}):`${a} days`}if(t<180){const a=Math.round(t/7);return a===1?n?n("maintenance.week"):"1 week":n?n("maintenance.weeks",{count:a}):`${a} weeks`}const r=Math.round(t/30);return r===1?n?n("maintenance.month"):"1 month":n?n("maintenance.months",{count:r}):`${r} months`}else{if(t<1)return`${Math.round(t*60)}m`;if(t<24)return`${t<10?t.toFixed(1):Math.round(t)}h`;const r=t/24;if(r<7)return`${r<2?r.toFixed(1):Math.round(r)}d`;const a=r/7;return a<12?`${a<2?a.toFixed(1):Math.round(a)}w`:`${Math.round(a/4)}mo`}}function QD(t,e,n){return e==="days"?t===1?n?n("maintenance.day"):"1 day":t===7?n?n("maintenance.week"):"1 week":t===14?n?n("maintenance.weeks",{count:2}):"2 weeks":t===30?n?n("maintenance.month"):"1 month":t===60?n?n("maintenance.months",{count:2}):"2 months":t===90?n?n("maintenance.months",{count:3}):"3 months":t===180?n?n("maintenance.months",{count:6}):"6 months":t===365?n?n("maintenance.year"):"1 year":n?n("maintenance.days",{count:t}):`${t} days`:`${t}h`}function vtt(t,e){const n=(e||"").toUpperCase().replace(/[- ]/g,""),r=n.includes("X1"),a=n.includes("P1"),s=n.includes("A1MINI"),o=n.includes("A1")&&!s,l=n.includes("H2D"),c=n.includes("H2C"),d=n.includes("H2S"),u=l||c||d,m=n.includes("P2S");switch(t){case"Lubricate Steel Rods":return m?"https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis":null;case"Clean Steel Rods":return m?"https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis":null;case"Lubricate Linear Rails":return s?"https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis":o?"https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis":u?"https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication":null;case"Clean Nozzle/Hotend":return r||a?"https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog":s||o?"https://wiki.bambulab.com/en/a1-mini/troubleshooting/nozzle-clog":u?"https://wiki.bambulab.com/en/h2/maintenance/nozzl-cold-pull-maintenance-and-cleaning":m?"https://wiki.bambulab.com/en/p2s/maintenance/cold-pull-maintenance-hotend":"https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog";case"Check Belt Tension":return r?"https://wiki.bambulab.com/en/x1/maintenance/belt-tension":a?"https://wiki.bambulab.com/en/p1/maintenance/p1p-maintenance":s?"https://wiki.bambulab.com/en/a1-mini/maintenance/belt_tension":o?"https://wiki.bambulab.com/en/a1/maintenance/belt_tension":l?"https://wiki.bambulab.com/en/h2/maintenance/belt-tension":c?"https://wiki.bambulab.com/en/h2c/maintenance/belt-tension":d?"https://wiki.bambulab.com/en/h2s/maintenance/belt-tension":m?"https://wiki.bambulab.com/en/p2s/maintenance/belt-tension":"https://wiki.bambulab.com/en/x1/maintenance/belt-tension";case"Clean Carbon Rods":return r||a?"https://wiki.bambulab.com/en/general/carbon-rods-clearance":null;case"Clean Linear Rails":return s?"https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis":o?"https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis":u?"https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication":null;case"Clean Build Plate":return"https://wiki.bambulab.com/en/filament-acc/acc/pei-plate-clean-guide";case"Check PTFE Tube":return r||a?"https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube":s||o?"https://wiki.bambulab.com/en/a1-mini/maintenance/ptfe-tube":l?"https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer":d?"https://wiki.bambulab.com/en/h2s/maintenance/replace-ptfe-tube-on-h2s-printer":c?"https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer":"https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube";case"Replace HEPA Filter":case"HEPA Filter":case"Replace Carbon Filter":case"Carbon Filter":return u?"https://wiki.bambulab.com/en/h2/maintenance/replace-smoke-purifier-air-filte":"https://wiki.bambulab.com/en/x1/maintenance/replace-carbon-filter";case"Lubricate Left Nozzle Rail":case"Left Nozzle Rail":return u?"https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication":null;default:return null}}function wtt({item:t,onPerform:e,onToggle:n,hasPermission:r,t:a}){const s=b0(t.maintenance_type_icon),o=t.interval_type||"hours",c=(()=>{if(o==="days"){const f=t.days_since_maintenance??0;return Math.max(0,Math.min(100,f/t.interval_hours*100))}return Math.max(0,Math.min(100,(t.interval_hours-t.hours_until_due)/t.interval_hours*100))})(),d=()=>t.enabled?t.is_due?"text-red-400":t.is_warning?"text-amber-400":"text-bambu-green":"text-bambu-gray",u=()=>t.enabled?t.is_due?"bg-red-500":t.is_warning?"bg-amber-500":"bg-bambu-green":"bg-bambu-gray/30",m=()=>t.enabled?t.is_due?"bg-red-500/5 border-red-500/20":t.is_warning?"bg-amber-500/5 border-amber-500/20":"bg-bambu-dark-secondary border-bambu-dark-tertiary":"bg-bambu-dark-secondary/50",p=()=>{if(!t.enabled)return a("common.disabled");if(o==="days"){const f=t.days_until_due??0;return t.is_due?a("maintenance.overdueBy",{duration:Eb(Math.abs(f),"days",a)}):t.is_warning?a("maintenance.dueIn",{duration:Eb(f,"days",a)}):a("maintenance.timeLeft",{duration:Eb(f,"days",a)})}else return t.is_due?a("maintenance.overdueBy",{duration:Eb(Math.abs(t.hours_until_due),"hours",a)}):t.is_warning?a("maintenance.dueIn",{duration:Eb(t.hours_until_due,"hours",a)}):a("maintenance.timeLeft",{duration:Eb(t.hours_until_due,"hours",a)})};return i.jsx("div",{className:`rounded-xl border p-4 transition-all ${m()}`,children:i.jsxs("div",{className:"flex items-start gap-3 max-[550px]:flex-wrap",children:[i.jsxs("div",{className:`relative p-2.5 rounded-lg shrink-0 ${t.is_due?"bg-red-500/20":t.is_warning?"bg-amber-500/20":t.enabled?"bg-bambu-dark":"bg-bambu-dark/50"}`,children:[i.jsx(s,{className:`w-5 h-5 ${d()}`}),t.enabled&&(t.is_due||t.is_warning)&&i.jsx("span",{className:`absolute -top-1 -right-1 w-2.5 h-2.5 rounded-full ${t.is_due?"bg-red-500":"bg-amber-500"} animate-pulse`})]}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("h3",{className:`font-medium truncate ${t.enabled?"text-white":"text-bambu-gray"}`,children:t.maintenance_type_name}),o==="days"&&i.jsx("span",{title:a("maintenance.timeBasedInterval"),children:i.jsx(Xr,{className:"w-3.5 h-3.5 text-bambu-gray shrink-0"})}),(()=>{const f=t.maintenance_type_wiki_url||vtt(t.maintenance_type_name,t.printer_model);return f?i.jsx("a",{href:f,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-gray hover:text-bambu-green transition-colors shrink-0",title:a("maintenance.viewDocumentation"),onClick:y=>y.stopPropagation(),children:i.jsx(ni,{className:"w-3.5 h-3.5"})}):null})()]}),i.jsx("div",{className:"mt-2 mb-1.5",children:i.jsx("div",{className:"w-full h-1.5 bg-bambu-dark rounded-full overflow-hidden",children:i.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${u()}`,style:{width:`${c}%`}})})}),i.jsxs("div",{className:`text-xs flex items-center gap-1 ${d()}`,children:[t.is_due&&i.jsx(jn,{className:"w-3 h-3"}),t.is_warning&&!t.is_due&&i.jsx(Zn,{className:"w-3 h-3"}),!t.is_due&&!t.is_warning&&t.enabled&&i.jsx(Zr,{className:"w-3 h-3"}),p()]})]}),i.jsxs("div",{className:"flex items-center gap-2 shrink-0 max-[550px]:w-full max-[550px]:justify-end max-[550px]:mt-1",children:[i.jsx("span",{title:r("maintenance:update")?void 0:a("maintenance.noPermissionUpdate"),children:i.jsx(In,{checked:t.enabled,onChange:f=>n(t.id,f),disabled:!r("maintenance:update")})}),i.jsxs(Ie,{size:"sm",variant:t.is_due?"primary":"secondary",onClick:()=>e(t.id),disabled:!t.enabled||!r("maintenance:update"),title:r("maintenance:update")?void 0:a("maintenance.noPermissionPerform"),className:"!px-3",children:[i.jsx(Ao,{className:"w-3.5 h-3.5"}),a("common.reset")]})]})]})})}function Stt({overview:t,onPerform:e,onToggle:n,onSetHours:r,hasPermission:a,t:s}){const[o,l]=w.useState(!1),[c,d]=w.useState(!1),[u,m]=w.useState(t.total_print_hours.toFixed(1)),p=[...t.maintenance_items].sort((v,b)=>v.is_due&&!b.is_due?-1:!v.is_due&&b.is_due?1:v.is_warning&&!b.is_warning?-1:!v.is_warning&&b.is_warning?1:v.maintenance_type_id-b.maintenance_type_id),f=p.find(v=>v.enabled&&(v.is_due||v.is_warning)),y=()=>{const v=parseFloat(u);!isNaN(v)&&v>=0&&(r(t.printer_id,v),d(!1))};return i.jsxs(At,{className:"overflow-hidden",children:[i.jsxs("div",{className:"p-5",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-4",children:[i.jsx("h2",{className:"text-xl font-semibold text-white",children:t.printer_name}),i.jsxs("div",{className:"flex items-center gap-2",children:[t.due_count>0&&i.jsxs("span",{className:"px-2.5 py-1 bg-red-500/20 text-red-400 text-xs font-medium rounded-full flex items-center gap-1.5",children:[i.jsx(jn,{className:"w-3 h-3"}),s("maintenance.overdueCount",{count:t.due_count})]}),t.warning_count>0&&i.jsxs("span",{className:"px-2.5 py-1 bg-amber-500/20 text-amber-400 text-xs font-medium rounded-full flex items-center gap-1.5",children:[i.jsx(Zn,{className:"w-3 h-3"}),s("maintenance.dueSoonCount",{count:t.warning_count})]}),t.due_count===0&&t.warning_count===0&&i.jsxs("span",{className:"px-2.5 py-1 bg-bambu-green/20 text-bambu-green text-xs font-medium rounded-full flex items-center gap-1.5",children:[i.jsx(Zr,{className:"w-3 h-3"}),s("maintenance.allGood")]})]})]}),i.jsxs("button",{onClick:()=>l(!o),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark rounded-lg transition-colors",children:[o?i.jsx(Gl,{className:"w-4 h-4"}):i.jsx(zn,{className:"w-4 h-4"}),s(o?"common.collapse":"common.expand")]})]}),i.jsxs("div",{className:"flex items-center gap-6 mt-4",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"p-2 bg-bambu-dark/50 rounded-lg",children:i.jsx(Nu,{className:"w-4 h-4 text-bambu-gray"})}),c?i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",value:u,onChange:v=>m(v.target.value),onKeyDown:v=>{v.key==="Enter"&&y(),v.key==="Escape"&&d(!1)},className:"w-24 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm",min:"0",step:"1",autoFocus:!0}),i.jsx("span",{className:"text-xs text-bambu-gray",children:s("common.hours")}),i.jsx(Ie,{size:"sm",onClick:y,children:s("common.save")}),i.jsx(Ie,{size:"sm",variant:"secondary",onClick:()=>d(!1),children:s("common.cancel")})]}):i.jsxs("button",{onClick:()=>{a("maintenance:update")&&(m(Math.round(t.total_print_hours).toString()),d(!0))},className:`group ${a("maintenance:update")?"":"cursor-not-allowed opacity-60"}`,title:a("maintenance:update")?void 0:s("maintenance.noPermissionEditHours"),children:[i.jsxs("div",{className:`text-sm font-medium text-white ${a("maintenance:update")?"group-hover:text-bambu-green":""} transition-colors flex items-center gap-1`,children:[Math.round(t.total_print_hours)," ",s("common.hours"),i.jsx(Ef,{className:`w-3 h-3 text-bambu-gray ${a("maintenance:update")?"group-hover:text-bambu-green":""}`})]}),i.jsx("div",{className:"text-xs text-bambu-gray",children:s("maintenance.totalPrintTime")})]})]}),i.jsx("div",{className:"w-px h-10 bg-bambu-dark-tertiary"}),f&&i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:`p-2 rounded-lg ${f.is_due?"bg-red-500/20":"bg-amber-500/20"}`,children:(()=>{const v=b0(f.maintenance_type_icon);return i.jsx(v,{className:`w-4 h-4 ${f.is_due?"text-red-400":"text-amber-400"}`})})()}),i.jsxs("div",{children:[i.jsx("div",{className:`text-sm font-medium ${f.is_due?"text-red-400":"text-amber-400"}`,children:f.maintenance_type_name}),i.jsx("div",{className:`text-xs ${f.is_due?"text-red-400/70":"text-amber-400/70"}`,children:f.is_due?s("common.overdue"):s("maintenance.dueSoon")})]})]})]})]}),o&&i.jsx(Et,{className:"pt-0 border-t border-bambu-dark-tertiary",children:i.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-3 pt-4",children:p.map(v=>i.jsx(wtt,{item:v,onPerform:e,onToggle:n,hasPermission:a,t:s},v.id))})})]})}function _tt({overview:t,types:e,onUpdateInterval:n,onAddType:r,onUpdateType:a,onDeleteType:s,onRestoreDefaults:o,isRestoringDefaults:l,onAssignType:c,onRemoveItem:d,hasPermission:u,t:m}){const[p,f]=w.useState(null),[y,v]=w.useState(""),[b,g]=w.useState("hours"),[_,k]=w.useState(!1),[C,N]=w.useState(""),[P,T]=w.useState("100"),[j,A]=w.useState("hours"),[F,G]=w.useState("Wrench"),[z,Z]=w.useState(""),[I,ee]=w.useState(new Set),[ae,X]=w.useState(null),[ce,ue]=w.useState(null),pe=w.useMemo(()=>t?t.map(L=>({id:L.printer_id,name:L.printer_name})):[],[t]),K=L=>t?t.filter(R=>R.maintenance_items.some(ne=>ne.maintenance_type_id===L)).map(R=>({printerId:R.printer_id,printerName:R.printer_name,itemId:R.maintenance_items.find(ne=>ne.maintenance_type_id===L)?.id})):[],se=L=>{if(!t)return[];const R=new Set(K(L).map(ne=>ne.printerId));return pe.filter(ne=>!R.has(ne.id))},[de,ge]=w.useState(null),[Te,V]=w.useState(""),[J,D]=w.useState(""),[E,U]=w.useState("hours"),[W,B]=w.useState("Wrench"),[ie,O]=w.useState(""),$=L=>{ge(L),V(L.name),D(L.default_interval_hours.toString()),U(L.interval_type||"hours"),B(L.icon||"Wrench"),O(L.wiki_url||"")},Y=()=>{de&&Te.trim()&&parseFloat(J)>0&&(a(de.id,{name:Te.trim(),default_interval_hours:parseFloat(J),interval_type:E,icon:W,wiki_url:ie.trim()||null}),ge(null))},q=(L,R,ne)=>{const ve=parseFloat(y);if(!isNaN(ve)&&ve>0){const we=Math.abs(ve-R)<.01?null:ve;n(L,{custom_interval_hours:we,custom_interval_type:b!==ne?b:null})}f(null)},te=L=>{L.preventDefault(),C.trim()&&parseFloat(P)>0&&I.size>0&&(r({name:C.trim(),default_interval_hours:parseFloat(P),interval_type:j,icon:F,wiki_url:z.trim()||null},Array.from(I)),N(""),T("100"),A("hours"),Z(""),ee(new Set),k(!1))},oe=L=>{ee(R=>{const ne=new Set(R);return ne.has(L)?ne.delete(L):ne.add(L),ne})},he=t?.map(L=>({printerId:L.printer_id,printerName:L.printer_name,items:L.maintenance_items.sort((R,ne)=>R.maintenance_type_id-ne.maintenance_type_id)})).sort((L,R)=>L.printerName.localeCompare(R.printerName))||[],fe=e.filter(L=>L.is_system),re=e.filter(L=>!L.is_system);return i.jsxs("div",{className:"space-y-8",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-4",children:[i.jsxs("div",{children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:m("maintenance.maintenanceTypes")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:m("maintenance.maintenanceTypesDescription")})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Ie,{variant:"secondary",onClick:o,disabled:!u("maintenance:delete")||l,title:u("maintenance:delete")?void 0:m("maintenance.noPermissionDeleteTypes"),children:m("maintenance.restoreDefaults")}),i.jsxs(Ie,{onClick:()=>k(!_),disabled:!u("maintenance:create"),title:u("maintenance:create")?void 0:m("maintenance.noPermissionEditTypes"),children:[i.jsx(ir,{className:"w-4 h-4"}),m("maintenance.addCustomType")]})]})]}),_&&i.jsx(At,{className:"mb-6",children:i.jsx(Et,{className:"py-4",children:i.jsxs("form",{onSubmit:te,children:[i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[i.jsxs("div",{className:"lg:col-span-2",children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:m("common.name")}),i.jsx("input",{type:"text",value:C,onChange:L=>N(L.target.value),className:"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",placeholder:m("maintenance.exampleName"),autoFocus:!0})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:m("maintenance.intervalType")}),i.jsxs("select",{value:j,onChange:L=>{A(L.target.value),L.target.value==="days"?T("30"):T("100")},className:"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",children:[i.jsx("option",{value:"hours",children:m("maintenance.printHours")}),i.jsx("option",{value:"days",children:m("maintenance.calendarDays")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:m("maintenance.intervalValue",{type:j==="days"?m("maintenance.calendarDays").toLowerCase():m("common.hours")})}),i.jsx("input",{type:"number",value:P,onChange:L=>T(L.target.value),className:"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",min:"1"})]})]}),i.jsx("div",{className:"mt-4 flex items-end justify-between",children:i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:m("maintenance.icon")}),i.jsx("div",{className:"flex gap-1",children:Object.keys(Gv).map(L=>{const R=Gv[L];return i.jsx("button",{type:"button",onClick:()=>G(L),className:`p-2 rounded-lg transition-colors ${F===L?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary"}`,children:i.jsx(R,{className:"w-4 h-4"})},L)})})]})}),i.jsxs("div",{className:"mt-4",children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:m("maintenance.documentationLink")}),i.jsx("input",{type:"url",value:z,onChange:L=>Z(L.target.value),className:"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",placeholder:"https://wiki.bambulab.com/..."})]}),i.jsxs("div",{className:"mt-4",children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:m("maintenance.assignToPrinters")}),i.jsx("div",{className:"flex flex-wrap gap-2",children:pe.map(L=>i.jsx("button",{type:"button",onClick:()=>oe(L.id),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${I.has(L.id)?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary"}`,children:L.name},L.id))}),I.size===0&&i.jsx("p",{className:"text-xs text-orange-400 mt-1",children:m("maintenance.selectAtLeastOnePrinter")})]}),i.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[i.jsx(Ie,{type:"button",variant:"secondary",onClick:()=>{k(!1),ee(new Set)},children:m("common.cancel")}),i.jsx(Ie,{type:"submit",disabled:!C.trim()||I.size===0,children:m("maintenance.addType")})]})]})})}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:[fe.map(L=>{const R=b0(L.icon),ne=L.interval_type||"hours";return i.jsx("div",{className:"bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-dark-tertiary",children:i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"p-2.5 bg-bambu-dark rounded-lg",children:i.jsx(R,{className:"w-5 h-5 text-bambu-gray"})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("div",{className:"text-sm font-medium text-white truncate",children:L.name}),i.jsxs("div",{className:"text-xs text-bambu-gray mt-0.5 flex items-center gap-1",children:[ne==="days"?i.jsx(Xr,{className:"w-3 h-3"}):i.jsx(Nu,{className:"w-3 h-3"}),QD(L.default_interval_hours,ne,m)]})]}),i.jsx("button",{onClick:()=>{u("maintenance:delete")&&ue(L)},disabled:!u("maintenance:delete"),title:u("maintenance:delete")?void 0:m("maintenance.noPermissionDeleteTypes"),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-400 transition-colors ${u("maintenance:delete")?"":"opacity-50 cursor-not-allowed"}`,children:i.jsx(an,{className:"w-4 h-4"})})]})},L.id)}),re.map(L=>{const R=b0(L.icon),ne=L.interval_type||"hours";if(de?.id===L.id)return i.jsx("div",{className:"bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green",children:i.jsxs("div",{className:"space-y-3",children:[i.jsx("input",{type:"text",value:Te,onChange:xe=>V(xe.target.value),className:"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",placeholder:m("common.name"),autoFocus:!0}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("select",{value:E,onChange:xe=>U(xe.target.value),className:"flex-1 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",children:[i.jsx("option",{value:"hours",children:m("maintenance.printHours")}),i.jsx("option",{value:"days",children:m("maintenance.calendarDays")})]}),i.jsx("input",{type:"number",value:J,onChange:xe=>D(xe.target.value),className:"w-24 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",min:"1"})]}),i.jsx("div",{className:"flex flex-wrap gap-1",children:Object.keys(Gv).map(xe=>{const je=Gv[xe];return i.jsx("button",{type:"button",onClick:()=>B(xe),className:`p-1.5 rounded transition-colors ${W===xe?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:i.jsx(je,{className:"w-3.5 h-3.5"})},xe)})}),i.jsx("input",{type:"url",value:ie,onChange:xe=>O(xe.target.value),className:"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",placeholder:m("maintenance.documentationLink")}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Ie,{size:"sm",onClick:Y,disabled:!Te.trim(),children:m("common.save")}),i.jsx(Ie,{size:"sm",variant:"secondary",onClick:()=>ge(null),children:m("common.cancel")})]})]})},L.id);const we=K(L.id),me=se(L.id),Me=ae===L.id;return i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green/30",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"p-2.5 bg-bambu-green/20 rounded-lg",children:i.jsx(R,{className:"w-5 h-5 text-bambu-green"})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-sm font-medium text-white truncate",children:L.name}),i.jsx("span",{className:"px-1.5 py-0.5 bg-bambu-green/20 text-bambu-green text-[10px] font-medium rounded",children:m("maintenance.custom")})]}),i.jsxs("div",{className:"text-xs text-bambu-gray mt-0.5 flex items-center gap-1",children:[ne==="days"?i.jsx(Xr,{className:"w-3 h-3"}):i.jsx(Nu,{className:"w-3 h-3"}),QD(L.default_interval_hours,ne,m)]})]}),i.jsxs("button",{onClick:()=>X(Me?null:L.id),className:`px-2 py-1 rounded-lg border transition-colors flex items-center gap-1 ${we.length>0?"border-bambu-green/50 bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20":"border-orange-400/50 bg-orange-400/10 text-orange-400 hover:bg-orange-400/20"}`,title:m("maintenance.printersAssignedClick",{count:we.length}),children:[i.jsx(_r,{className:"w-3 h-3"}),i.jsx("span",{className:"text-xs font-medium",children:we.length}),i.jsx(zn,{className:`w-3 h-3 transition-transform ${Me?"rotate-180":""}`})]}),i.jsx("button",{onClick:()=>$(L),disabled:!u("maintenance:update"),title:u("maintenance:update")?void 0:m("maintenance.noPermissionEditTypes"),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors ${u("maintenance:update")?"":"opacity-50 cursor-not-allowed"}`,children:i.jsx(Ef,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>{confirm(m("maintenance.deleteTypeConfirm",{name:L.name}))&&s(L.id)},disabled:!u("maintenance:delete"),title:u("maintenance:delete")?void 0:m("maintenance.noPermissionDeleteTypes"),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-400 transition-colors ${u("maintenance:delete")?"":"opacity-50 cursor-not-allowed"}`,children:i.jsx(an,{className:"w-4 h-4"})})]}),Me&&i.jsxs("div",{className:"mt-3 pt-3 border-t border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:m("maintenance.assignedToPrinters")}),we.length===0?i.jsx("p",{className:"text-xs text-orange-400",children:m("maintenance.noPrintersAssigned")}):i.jsx("div",{className:"flex flex-wrap gap-1 mb-2",children:we.map(xe=>i.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark rounded text-xs text-white",children:[xe.printerName,i.jsx("button",{onClick:()=>xe.itemId&&d(xe.itemId),disabled:!u("maintenance:delete"),title:u("maintenance:delete")?m("maintenance.removeFromPrinter"):m("maintenance.noPermissionRemovePrinter"),className:`ml-1 ${u("maintenance:delete")?"hover:text-red-400":"opacity-50 cursor-not-allowed"}`,children:"×"})]},xe.printerId))}),me.length>0&&i.jsxs("div",{className:"flex flex-wrap gap-1",children:[i.jsx("span",{className:"text-xs text-bambu-gray mr-1",children:m("maintenance.addPrinterShort")}),me.map(xe=>i.jsxs("button",{onClick:()=>c(xe.id,L.id),disabled:!u("maintenance:create"),title:u("maintenance:create")?void 0:m("maintenance.noPermissionAssignPrinter"),className:`px-2 py-1 bg-bambu-dark rounded text-xs transition-colors ${u("maintenance:create")?"hover:bg-bambu-green/20 text-bambu-gray hover:text-bambu-green":"opacity-50 cursor-not-allowed text-bambu-gray"}`,children:["+ ",xe.name]},xe.id))]})]})]},L.id)})]})]}),he.length>0&&i.jsxs("div",{children:[i.jsxs("div",{className:"mb-4",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:m("maintenance.intervalOverrides")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:m("maintenance.intervalOverridesDescription")})]}),i.jsx("div",{className:"space-y-4",children:he.map(L=>i.jsx(At,{children:i.jsxs(Et,{className:"py-4",children:[i.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:L.printerName}),i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2",children:L.items.map(R=>{const ne=b0(R.maintenance_type_icon),ve=e.find(je=>je.id===R.maintenance_type_id),we=ve?.default_interval_hours||R.interval_hours,me=ve?.interval_type||"hours",Me=R.interval_type||"hours",xe=p===R.id;return i.jsxs("div",{className:"flex items-center gap-2 p-2.5 bg-bambu-dark rounded-lg",children:[i.jsx(ne,{className:"w-4 h-4 text-bambu-gray shrink-0"}),i.jsx("span",{className:"text-xs text-bambu-gray flex-1 truncate",children:R.maintenance_type_name}),xe?i.jsxs("div",{className:"flex items-center gap-1",children:[b==="days"?i.jsx(Xr,{className:"w-3.5 h-3.5 text-bambu-gray shrink-0"}):i.jsx(Nu,{className:"w-3.5 h-3.5 text-bambu-gray shrink-0"}),i.jsxs("select",{value:b,onChange:je=>g(je.target.value),className:"px-1.5 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs",children:[i.jsx("option",{value:"hours",children:m("maintenance.printHours")}),i.jsx("option",{value:"days",children:m("maintenance.calendarDays")})]}),i.jsx("input",{type:"number",value:y,onChange:je=>v(je.target.value),onKeyDown:je=>{je.key==="Enter"&&q(R.id,we,me),je.key==="Escape"&&f(null)},className:"w-16 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs",min:"1"}),i.jsx(Ie,{size:"sm",onClick:()=>q(R.id,we,me),children:"OK"})]}):i.jsxs("button",{onClick:()=>{u("maintenance:update")&&(f(R.id),v(R.interval_hours.toString()),g(Me))},disabled:!u("maintenance:update"),title:u("maintenance:update")?void 0:m("maintenance.noPermissionEditIntervals"),className:`px-2 py-1 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs font-medium text-white transition-colors flex items-center gap-1 ${u("maintenance:update")?"hover:bg-bambu-dark-secondary hover:border-bambu-green":"opacity-50 cursor-not-allowed"}`,children:[Me==="days"?i.jsx(Xr,{className:"w-3 h-3"}):i.jsx(Nu,{className:"w-3 h-3"}),QD(R.interval_hours,Me,m),i.jsx(Ef,{className:"w-3 h-3 text-bambu-gray"})]})]},R.id)})})]})},L.printerId))})]}),he.length===0&&i.jsx(At,{children:i.jsxs(Et,{className:"text-center py-12",children:[i.jsx(Zn,{className:"w-12 h-12 mx-auto mb-4 text-bambu-gray/30"}),i.jsx("p",{className:"text-bambu-gray",children:m("common.noPrinters")}),i.jsx("p",{className:"text-sm text-bambu-gray/70 mt-1",children:m("maintenance.intervalOverridesDescription")})]})}),ce&&i.jsx(kn,{title:m("maintenance.deleteSystemTypeTitle"),message:m("maintenance.deleteSystemTypeMessage",{name:ce.name}),confirmText:m("common.delete"),cancelText:m("common.cancel"),variant:"danger",cancelVariant:"primary",cardClassName:"bg-red-950/70 border border-red-800/70",onConfirm:()=>{s(ce.id),ue(null)},onCancel:()=>ue(null)})]})}function ktt(){const{t}=jt(),e=cn(),{showToast:n}=pn(),{hasPermission:r}=Ar(),[a,s]=w.useState("status"),{data:o,isLoading:l}=et({queryKey:["maintenanceOverview"],queryFn:be.getMaintenanceOverview}),{data:c}=et({queryKey:["maintenanceTypes"],queryFn:be.getMaintenanceTypes}),d=pt({mutationFn:({id:P,notes:T})=>be.performMaintenance(P,T),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]}),e.invalidateQueries({queryKey:["maintenanceSummary"]}),n(t("maintenance.maintenanceComplete"))},onError:P=>{n(P.message,"error")}}),u=pt({mutationFn:({id:P,data:T})=>be.updateMaintenanceItem(P,T),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]})},onError:P=>{n(P.message,"error")}}),m=pt({mutationFn:({id:P,data:T})=>be.updateMaintenanceType(P,T),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceTypes"]}),e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.typeUpdated"))},onError:P=>{n(P.message,"error")}}),p=pt({mutationFn:be.deleteMaintenanceType,onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceTypes"]}),e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.typeDeleted"))},onError:P=>{n(P.message,"error")}}),f=pt({mutationFn:be.restoreDefaultMaintenanceTypes,onSuccess:P=>{e.invalidateQueries({queryKey:["maintenanceTypes"]}),e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.defaultsRestored",{count:P.restored}))},onError:P=>{n(P.message,"error")}}),y=pt({mutationFn:({printerId:P,hours:T})=>be.setPrinterHours(P,T),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]}),e.invalidateQueries({queryKey:["maintenanceSummary"]}),n(t("maintenance.printHoursUpdated"))},onError:P=>{n(P.message,"error")}}),v=pt({mutationFn:({printerId:P,typeId:T})=>be.assignMaintenanceType(P,T),onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.printerAssigned"))},onError:P=>{n(P.message,"error")}}),b=pt({mutationFn:be.removeMaintenanceItem,onSuccess:()=>{e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.printerRemoved"))},onError:P=>{n(P.message,"error")}}),g=P=>{d.mutate({id:P})},_=(P,T)=>{u.mutate({id:P,data:{enabled:T}})},k=(P,T)=>{y.mutate({printerId:P,hours:T})};if(l)return i.jsx("div",{className:"p-4 md:p-8 flex justify-center",children:i.jsx(ft,{className:"w-8 h-8 text-bambu-green animate-spin"})});const C=o?.reduce((P,T)=>P+T.due_count,0)||0,N=o?.reduce((P,T)=>P+T.warning_count,0)||0;return i.jsxs("div",{className:"p-4 md:p-8",children:[i.jsxs("div",{className:"mb-6",children:[i.jsx("h1",{className:"text-2xl font-bold text-white",children:t("maintenance.title")}),i.jsx("p",{className:"text-bambu-gray text-sm mt-1",children:a==="status"?i.jsxs(i.Fragment,{children:[C>0&&i.jsx("span",{className:"text-red-400",children:t("maintenance.dueCount",{count:C})}),C>0&&N>0&&" · ",N>0&&i.jsx("span",{className:"text-amber-400",children:t("maintenance.warningCount",{count:N})}),C===0&&N===0&&i.jsx("span",{className:"text-bambu-green",children:t("maintenance.allOk")})]}):t("maintenance.configureSettings")})]}),i.jsxs("div",{className:"flex gap-1 mb-6 border-b border-bambu-dark-tertiary",children:[i.jsx("button",{onClick:()=>s("status"),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${a==="status"?"text-bambu-green border-bambu-green":"text-bambu-gray border-transparent hover:text-white"}`,children:t("maintenance.statusTab")}),i.jsx("button",{onClick:()=>s("settings"),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${a==="settings"?"text-bambu-green border-bambu-green":"text-bambu-gray border-transparent hover:text-white"}`,children:t("maintenance.settingsTab")})]}),a==="status"?i.jsx("div",{className:"space-y-6",children:o&&o.length>0?[...o].sort((P,T)=>{const j=P.due_count*10+P.warning_count,A=T.due_count*10+T.warning_count;return j!==A?A-j:P.printer_name.localeCompare(T.printer_name)}).map(P=>i.jsx(Stt,{overview:P,onPerform:g,onToggle:_,onSetHours:k,hasPermission:r,t},P.printer_id)):i.jsx(At,{children:i.jsxs(Et,{className:"text-center py-16",children:[i.jsx(Ff,{className:"w-16 h-16 mx-auto mb-4 text-bambu-gray/30"}),i.jsx("p",{className:"text-lg font-medium text-white mb-2",children:t("common.noPrinters")}),i.jsx("p",{className:"text-bambu-gray",children:t("maintenance.configureSettings")})]})})}):i.jsx(_tt,{overview:o,types:c||[],onUpdateInterval:(P,T)=>u.mutate({id:P,data:T}),onAddType:async(P,T)=>{const j=await be.createMaintenanceType(P);for(const A of T)await be.assignMaintenanceType(A,j.id);e.invalidateQueries({queryKey:["maintenanceTypes"]}),e.invalidateQueries({queryKey:["maintenanceOverview"]}),n(t("maintenance.typeUpdated"))},onUpdateType:(P,T)=>m.mutate({id:P,data:T}),onDeleteType:P=>p.mutate(P),onRestoreDefaults:()=>f.mutate(),isRestoringDefaults:f.isPending,onAssignType:(P,T)=>v.mutate({printerId:P,typeId:T}),onRemoveItem:P=>b.mutate(P),hasPermission:r,t})]})}const OY=["#ef4444","#f97316","#eab308","#22c55e","#06b6d4","#3b82f6","#8b5cf6","#ec4899","#6b7280"];function Joe({project:t,onClose:e,onSave:n,isLoading:r,currencySymbol:a,t:s}){const[o,l]=w.useState(t?.name||""),[c,d]=w.useState(t?.description||""),[u,m]=w.useState(t?.color||OY[0]),[p,f]=w.useState(t?.target_count?.toString()||""),[y,v]=w.useState(t?.target_parts_count?.toString()||""),[b,g]=w.useState(t?.status||"active"),[_,k]=w.useState(t?.tags||""),[C,N]=w.useState(t?.due_date?.split("T")[0]||""),[P,T]=w.useState(t?.priority||"normal"),[j,A]=w.useState(t?.budget?.toString()||""),F=G=>{G.preventDefault(),n({name:o.trim(),description:c.trim()||void 0,color:u,target_count:p?parseInt(p,10):void 0,target_parts_count:y?parseInt(y,10):void 0,tags:_.trim()||void 0,due_date:C||void 0,priority:P,budget:j.trim()?parseFloat(j):null,...t&&{status:b}})};return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary",children:[i.jsx("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:s(t?"projects.editProject":"projects.newProject")})}),i.jsxs("form",{onSubmit:F,className:"p-4 space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:s("common.name")}),i.jsx("input",{type:"text",value:o,onChange:G=>l(G.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:s("projects.namePlaceholder"),required:!0})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:s("common.description")}),i.jsx("textarea",{value:c,onChange:G=>d(G.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green resize-none",placeholder:s("projects.descriptionPlaceholder"),rows:2})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:s("projects.color")}),i.jsx("div",{className:"flex gap-2 flex-wrap",children:OY.map(G=>i.jsx("button",{type:"button",onClick:()=>m(G),className:`w-8 h-8 rounded-full transition-transform ${u===G?"ring-2 ring-white ring-offset-2 ring-offset-bambu-dark-secondary scale-110":""}`,style:{backgroundColor:G}},G))})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:s("projects.targetPlates")}),i.jsx("input",{type:"number",value:p,onChange:G=>f(G.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:s("projects.targetPlatesPlaceholder"),min:"1"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:s("projects.targetPlatesHelp")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:s("projects.targetParts")}),i.jsx("input",{type:"number",value:y,onChange:G=>v(G.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:s("projects.targetPartsPlaceholder"),min:"1"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:s("projects.targetPartsHelp")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:s("projects.tagsLabel")}),i.jsx("input",{type:"text",value:_,onChange:G=>k(G.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:s("projects.tagsPlaceholder")})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:s("projects.dueDate")}),i.jsx("input",{type:"date",value:C,onChange:G=>N(G.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:s("projects.priority")}),i.jsxs("select",{value:P,onChange:G=>T(G.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green",children:[i.jsx("option",{value:"low",children:s("projects.priorityLow")}),i.jsx("option",{value:"normal",children:s("projects.priorityNormal")}),i.jsx("option",{value:"high",children:s("projects.priorityHigh")}),i.jsx("option",{value:"urgent",children:s("projects.priorityUrgent")})]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:s("projectDetail.cost.budget")}),i.jsxs("div",{className:"relative",children:[i.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray pointer-events-none",children:a}),i.jsx("input",{type:"number",step:"0.01",min:"0",value:j,onChange:G=>A(G.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded pl-8 pr-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:"0.00"})]})]}),t&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:s("common.status")}),i.jsxs("select",{value:b,onChange:G=>g(G.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green",children:[i.jsx("option",{value:"active",children:s("projects.statusActive")}),i.jsx("option",{value:"completed",children:s("projects.statusCompleted")}),i.jsx("option",{value:"archived",children:s("projects.statusArchived")})]})]}),i.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[i.jsx(Ie,{type:"button",variant:"secondary",onClick:e,children:s("common.cancel")}),i.jsx(Ie,{type:"submit",disabled:!o.trim()||r,children:r?i.jsx(ft,{className:"w-4 h-4 animate-spin"}):s(t?"common.save":"projects.create")})]})]})]})})}function Ntt({project:t,onClick:e,onEdit:n,onDelete:r,hasPermission:a,t:s}){const o=t.target_count?Math.round(t.archive_count/t.target_count*100):0,l=t.target_parts_count?Math.round(t.completed_count/t.target_parts_count*100):0,c=t.status==="completed",d=t.status==="archived",[u,m]=w.useState(!1),f=c?{icon:Sc,color:"text-bambu-green",bg:"bg-bambu-green/10"}:d?{icon:Vs,color:"text-bambu-gray",bg:"bg-bambu-gray/10"}:t.queue_count>0?{icon:Zn,color:"text-blue-400",bg:"bg-blue-400/10"}:{icon:_s,color:"text-bambu-gray",bg:"bg-bambu-gray/10"};return i.jsxs("div",{className:"group relative bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary hover:border-bambu-green/50 hover:shadow-lg hover:shadow-bambu-green/5 transition-all duration-300 cursor-pointer overflow-hidden",onClick:e,children:[i.jsx("div",{className:"absolute top-0 left-0 w-1.5 h-full",style:{backgroundColor:t.color||"#6b7280",boxShadow:`0 0 12px ${t.color||"#6b7280"}40`}}),i.jsxs("div",{className:"p-5 pl-6",children:[i.jsxs("div",{className:"flex items-start justify-between mb-4",children:[i.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[i.jsx("div",{className:`p-2 rounded-lg ${f.bg} flex-shrink-0`,children:i.jsx(f.icon,{className:`w-5 h-5 ${f.color}`})}),i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[i.jsx("h3",{className:"font-semibold text-white truncate",children:t.name}),t.target_parts_count?i.jsxs("span",{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${l>=100?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark text-bambu-gray"}`,children:[t.completed_count,"/",t.target_parts_count," ",s("projects.parts")]}):t.target_count?i.jsxs("span",{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${o>=100?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark text-bambu-gray"}`,children:[t.archive_count,"/",t.target_count," ",s("projects.plates")]}):t.completed_count>0?i.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium bg-bambu-dark text-bambu-gray",children:[t.completed_count," ",s("projects.parts")]}):null,c&&i.jsx("span",{className:"text-xs bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full whitespace-nowrap",children:s("projects.done")}),d&&i.jsx("span",{className:"text-xs bg-bambu-gray/20 text-bambu-gray px-2 py-0.5 rounded-full whitespace-nowrap",children:s("projects.statusArchived")})]}),t.description&&i.jsx("p",{className:"text-sm text-bambu-gray/70 mt-1 line-clamp-1",children:t.description}),t.archives&&t.archives.length>0&&(()=>{const y=t.archives.map(_=>_.filament_type).filter(Boolean).flatMap(_=>_.split(",").map(k=>k.trim())).filter(Boolean),v=[...new Set(y)],b=t.archives.map(_=>_.filament_color).filter(Boolean).flatMap(_=>_.split(",").map(k=>k.trim())).filter(_=>_.startsWith("#")||/^[0-9A-Fa-f]{6}$/.test(_)),g=[...new Set(b)];return v.length===0&&g.length===0?null:i.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[v.slice(0,3).map(_=>i.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-bambu-dark text-bambu-gray rounded",children:_},_)),g.length>0&&i.jsxs("div",{className:"flex items-center gap-0.5",children:[g.slice(0,5).map(_=>i.jsx("div",{className:"w-3 h-3 rounded-full border border-black/20",style:{backgroundColor:_.startsWith("#")?_:`#${_}`},title:_},_)),g.length>5&&i.jsxs("span",{className:"text-[10px] text-bambu-gray ml-0.5",children:["+",g.length-5]})]})]})})()]})]}),i.jsxs("div",{className:"relative",onClick:y=>y.stopPropagation(),children:[i.jsx("button",{className:"p-1.5 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors opacity-0 group-hover:opacity-100",onClick:()=>m(!u),children:i.jsx(Th,{className:"w-4 h-4"})}),u&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>m(!1)}),i.jsxs("div",{className:"absolute right-0 top-8 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]",children:[i.jsxs("button",{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${a("projects:update")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{a("projects:update")&&(n(),m(!1))},disabled:!a("projects:update"),title:a("projects:update")?void 0:s("projects.noEditPermission"),children:[i.jsx(Ef,{className:"w-4 h-4"}),s("common.edit")]}),i.jsxs("button",{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${a("projects:delete")?"text-red-400 hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{a("projects:delete")&&(r(),m(!1))},disabled:!a("projects:delete"),title:a("projects:delete")?void 0:s("projects.noDeletePermission"),children:[i.jsx(an,{className:"w-4 h-4"}),s("common.delete")]})]})]})]})]}),i.jsx("div",{className:"mb-4",children:t.target_count||t.target_parts_count?i.jsxs("div",{className:"space-y-3",children:[t.target_count&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between text-xs mb-1",children:[i.jsx("span",{className:"text-bambu-gray",children:s("projects.plates")}),i.jsxs("span",{className:o>=100?"text-bambu-green font-medium":"text-white",children:[t.archive_count," / ",t.target_count]})]}),i.jsx("div",{className:"h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm",children:i.jsx("div",{className:"h-full transition-all duration-500 ease-out rounded-full relative",style:{width:`${Math.min(o,100)}%`,background:o>=100?"linear-gradient(90deg, #22c55e, #4ade80)":`linear-gradient(90deg, ${t.color||"#6b7280"}, ${t.color||"#6b7280"}cc)`,boxShadow:`0 0 8px ${o>=100?"#22c55e":t.color||"#6b7280"}60`}})})]}),t.target_parts_count&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between text-xs mb-1",children:[i.jsx("span",{className:"text-bambu-gray",children:s("projects.parts")}),i.jsxs("span",{className:l>=100?"text-bambu-green font-medium":"text-white",children:[t.completed_count," / ",t.target_parts_count]})]}),i.jsx("div",{className:"h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm",children:i.jsx("div",{className:"h-full transition-all duration-500 ease-out rounded-full relative",style:{width:`${Math.min(l,100)}%`,background:l>=100?"linear-gradient(90deg, #22c55e, #4ade80)":`linear-gradient(90deg, ${t.color||"#6b7280"}, ${t.color||"#6b7280"}cc)`,boxShadow:`0 0 8px ${l>=100?"#22c55e":t.color||"#6b7280"}60`}})})]}),t.failed_count>0&&i.jsxs("div",{className:"text-xs text-red-400",children:[t.failed_count," ",s("projects.failed")]})]}):t.completed_count>0||t.failed_count>0?i.jsxs("div",{className:"flex items-center gap-4 text-xs",children:[t.completed_count>0&&i.jsxs("div",{className:"flex items-center gap-1.5 text-bambu-gray",children:[i.jsx(Vs,{className:"w-3.5 h-3.5"}),i.jsxs("span",{children:[t.completed_count," ",s("projects.completed")]})]}),t.failed_count>0&&i.jsxs("div",{className:"flex items-center gap-1.5 text-red-400",children:[i.jsx(jn,{className:"w-3.5 h-3.5"}),i.jsxs("span",{children:[t.failed_count," ",s("projects.failed")]})]}),t.queue_count>0&&i.jsxs("div",{className:"flex items-center gap-1.5 text-blue-400",children:[i.jsx(Zn,{className:"w-3.5 h-3.5"}),i.jsxs("span",{children:[t.queue_count," ",s("projects.inQueue")]})]})]}):i.jsx("div",{className:"text-xs text-bambu-gray/60 italic",children:s("projects.noPrintsYet")})}),t.archives&&t.archives.length>0&&i.jsxs("div",{className:"mb-4",children:[i.jsx("div",{className:"grid grid-cols-4 gap-1.5",children:t.archives.slice(0,4).map(y=>i.jsxs("div",{className:"relative aspect-square rounded-lg bg-bambu-dark overflow-hidden border border-bambu-dark-tertiary",title:y.print_name||"Unknown",children:[y.thumbnail_path?i.jsx("img",{src:be.getArchiveThumbnail(y.id),alt:y.print_name||"",className:"w-full h-full object-cover"}):i.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray/50",children:i.jsx(Ii,{className:"w-6 h-6"})}),y.status==="failed"&&i.jsx("div",{className:"absolute inset-0 bg-red-500/40 flex items-center justify-center",children:i.jsx(jn,{className:"w-4 h-4 text-white"})})]},y.id))}),t.archive_count>4&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1.5 text-center",children:s("common.more",{count:t.archive_count-4})})]}),i.jsxs("div",{className:"flex items-center justify-between pt-3 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-4 text-xs text-bambu-gray",children:[i.jsxs("div",{className:"flex items-center gap-1.5",title:s("projects.printJobs"),children:[i.jsx(Ki,{className:"w-3.5 h-3.5 text-blue-400"}),i.jsxs("span",{children:[t.archive_count," ",s("projects.plates")]})]}),i.jsxs("div",{className:"flex items-center gap-1.5",title:s("projects.partsPrinted"),children:[i.jsx(Ii,{className:"w-3.5 h-3.5 text-bambu-green"}),i.jsxs("span",{children:[t.completed_count," ",s("projects.parts")]})]}),t.failed_count>0&&i.jsxs("div",{className:"flex items-center gap-1.5 text-red-400",title:s("projects.failedParts"),children:[i.jsx(jn,{className:"w-3.5 h-3.5"}),i.jsx("span",{children:t.failed_count})]}),t.queue_count>0&&i.jsxs("div",{className:"flex items-center gap-1.5 text-yellow-400",title:s("projects.inQueue"),children:[i.jsx(N3,{className:"w-3.5 h-3.5"}),i.jsx("span",{children:t.queue_count})]})]}),i.jsx(fa,{className:"w-4 h-4 text-bambu-gray/50 group-hover:text-bambu-gray transition-colors"})]})]})]})}function Ctt(){const{t}=jt(),e=ol(),n=cn(),{showToast:r}=pn(),{hasPermission:a}=Ar(),[s,o]=w.useState(!1),[l,c]=w.useState(),[d,u]=w.useState("active"),[m,p]=w.useState(null),{data:f}=et({queryKey:["settings"],queryFn:be.getSettings}),y=go(f?.currency||"USD"),{data:v,isLoading:b}=et({queryKey:["projects",d==="all"?void 0:d],queryFn:()=>be.getProjects(d==="all"?void 0:d)}),g=pt({mutationFn:ee=>be.createProject(ee),onSuccess:()=>{n.invalidateQueries({queryKey:["projects"]}),o(!1),r(t("projects.toast.created"),"success")},onError:ee=>{r(ee.message,"error")}}),_=pt({mutationFn:({id:ee,data:ae})=>be.updateProject(ee,ae),onSuccess:()=>{n.invalidateQueries({queryKey:["projects"]}),o(!1),c(void 0),r(t("projects.toast.updated"),"success")},onError:ee=>{r(ee.message,"error")}}),k=pt({mutationFn:ee=>be.deleteProject(ee),onSuccess:()=>{p(null),r(t("projects.toast.deleted"),"success"),setTimeout(()=>window.location.reload(),100)},onError:ee=>{p(null),r(ee.message,"error")}}),C=pt({mutationFn:ee=>be.importProject(ee),onSuccess:()=>{n.invalidateQueries({queryKey:["projects"]}),r(t("projects.toast.imported"),"success")},onError:ee=>{r(ee.message,"error")}}),N=w.useRef(null),P=async()=>{try{const ee=await be.getProjects(),ae=await Promise.all(ee.map(async pe=>await be.exportProjectJson(pe.id))),X=new Blob([JSON.stringify(ae,null,2)],{type:"application/json"}),ce=URL.createObjectURL(X),ue=document.createElement("a");ue.href=ce,ue.download=`bambuddy_projects_${new Date().toISOString().split("T")[0]}.json`,ue.click(),URL.revokeObjectURL(ce),r(t("projects.toast.exported"),"success")}catch(ee){r(ee.message,"error")}},T=()=>{N.current?.click()},j=async ee=>{const ae=ee.target.files?.[0];if(ae){try{if(ae.name.toLowerCase().endsWith(".zip"))await be.importProjectFile(ae),n.invalidateQueries({queryKey:["projects"]}),r(t("projects.toast.imported"),"success");else{const ce=await ae.text(),ue=JSON.parse(ce),pe=Array.isArray(ue)?ue:[ue];for(const K of pe)await C.mutateAsync(K);pe.length>1&&r(t("projects.toast.multipleImported",{count:pe.length}),"success")}}catch(X){r(`${t("projects.toast.importFailed")}: ${X.message}`,"error")}ee.target.value=""}},A=ee=>{l?_.mutate({id:l.id,data:ee}):g.mutate(ee)},F=ee=>{c(ee),o(!0)},G=ee=>{e(`/projects/${ee.id}`)},z=ee=>{p(ee)},Z=()=>{m!==null&&k.mutate(m)},I=v?.reduce((ee,ae)=>(ee[ae.status]=(ee[ae.status]||0)+1,ee.all=(ee.all||0)+1,ee),{})||{};return i.jsxs("div",{className:"p-4 md:p-8 space-y-8",children:[i.jsx("input",{ref:N,type:"file",accept:".json,.zip",onChange:j,className:"hidden"}),i.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[i.jsxs("div",{children:[i.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[i.jsx("div",{className:"p-2.5 bg-bambu-green/10 rounded-xl",children:i.jsx(_s,{className:"w-6 h-6 text-bambu-green"})}),t("projects.title")]}),i.jsx("p",{className:"text-sm text-bambu-gray mt-2 ml-14",children:t("projects.subtitle")})]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs(Ie,{variant:"secondary",onClick:T,disabled:!a("projects:create"),title:a("projects:create")?t("projects.importProject"):t("projects.noImportPermission"),children:[i.jsx(vi,{className:"w-4 h-4 mr-2"}),t("projects.import")]}),i.jsxs(Ie,{variant:"secondary",onClick:P,disabled:!a("projects:read"),title:a("projects:read")?t("projects.exportAll"):t("projects.noExportPermission"),children:[i.jsx(fi,{className:"w-4 h-4 mr-2"}),t("projects.export")]}),i.jsxs(Ie,{onClick:()=>o(!0),className:"sm:w-auto w-full",disabled:!a("projects:create"),title:a("projects:create")?void 0:t("projects.noCreatePermission"),children:[i.jsx(ir,{className:"w-4 h-4 mr-2"}),t("projects.newProject")]})]})]}),i.jsx("div",{className:"flex gap-1 p-1 bg-bambu-dark rounded-xl w-fit",children:[{key:"active",label:t("projects.statusActive"),icon:Zn},{key:"completed",label:t("projects.statusCompleted"),icon:Sc},{key:"archived",label:t("projects.statusArchived"),icon:Vs},{key:"all",label:t("common.all"),icon:_s}].map(({key:ee,label:ae,icon:X})=>i.jsxs("button",{onClick:()=>u(ee),className:`flex items-center gap-2 px-4 py-2 text-sm rounded-lg transition-all ${d===ee?"bg-bambu-card text-white shadow-sm":"text-bambu-gray hover:text-white"}`,children:[i.jsx(X,{className:"w-4 h-4"}),i.jsx("span",{children:ae}),I[ee]>0&&i.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded-full ${d===ee?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark-tertiary"}`,children:I[ee]})]},ee))}),b?i.jsx("div",{className:"flex items-center justify-center py-20",children:i.jsxs("div",{className:"flex flex-col items-center gap-3",children:[i.jsx(ft,{className:"w-8 h-8 animate-spin text-bambu-green"}),i.jsx("p",{className:"text-sm text-bambu-gray",children:t("projects.loading")})]})}):v?.length===0?i.jsxs("div",{className:"flex flex-col items-center justify-center py-20 px-4",children:[i.jsx("div",{className:"p-4 bg-bambu-dark rounded-2xl mb-4",children:i.jsx(_s,{className:"w-12 h-12 text-bambu-gray/50"})}),i.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:d==="all"?t("projects.noProjects"):t("projects.noProjectsFiltered",{status:d})}),i.jsx("p",{className:"text-bambu-gray text-center max-w-md mb-6",children:d==="all"?t("projects.createFirst"):t("projects.noProjectsFilteredHelp",{status:d})}),d==="all"&&i.jsxs(Ie,{onClick:()=>o(!0),disabled:!a("projects:create"),title:a("projects:create")?void 0:t("projects.noCreatePermission"),children:[i.jsx(ir,{className:"w-4 h-4 mr-2"}),t("projects.createFirstButton")]})]}):i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-8",children:v?.map(ee=>i.jsx(Ntt,{project:ee,onClick:()=>G(ee),onEdit:()=>F(ee),onDelete:()=>z(ee.id),hasPermission:a,t},ee.id))}),m!==null&&i.jsx(kn,{title:t("projects.deleteProject"),message:t("projects.deleteConfirm"),confirmText:t("projects.deleteProject"),variant:"danger",onConfirm:Z,onCancel:()=>p(null)}),s&&i.jsx(Joe,{project:l,onClose:()=>{o(!1),c(void 0)},onSave:A,isLoading:g.isPending||_.isPending,currencySymbol:y,t})]})}function Ttt(t){return t>=1e3?`${(t/1e3).toFixed(2)}kg`:`${Math.round(t)}g`}function Att({status:t,t:e}){const n={active:"bg-bambu-green/20 text-bambu-green",completed:"bg-blue-500/20 text-blue-400",archived:"bg-bambu-gray/20 text-bambu-gray"},r=n[t]||n.active,a={active:e("projectDetail.status.active"),completed:e("projectDetail.status.completed"),archived:e("projectDetail.status.archived")};return i.jsx("span",{className:`px-2 py-1 rounded text-sm font-medium ${r}`,children:a[t]||t.charAt(0).toUpperCase()+t.slice(1)})}function IY({icon:t,label:e,value:n,subValue:r,hint:a,color:s="text-bambu-gray"}){return i.jsx(At,{children:i.jsx(Et,{className:"p-4",children:i.jsxs("div",{className:"flex items-center gap-3",title:a,children:[i.jsx("div",{className:`p-2 rounded-lg bg-bambu-dark ${s}`,children:i.jsx(t,{className:"w-5 h-5"})}),i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:e}),i.jsx("p",{className:"text-xl font-semibold text-white",children:n}),r&&i.jsx("p",{className:"text-xs text-bambu-gray/70",children:r})]})]})})})}function Ptt({archives:t,t:e}){return t.length===0?i.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[i.jsx(Ii,{className:"w-12 h-12 mx-auto mb-2 opacity-50"}),i.jsx("p",{children:e("projectDetail.noPrints")})]}):i.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-3",children:t.map(n=>i.jsxs(bo,{to:`/archives?search=${encodeURIComponent(n.print_name||"")}`,className:"group relative aspect-square rounded-lg bg-bambu-dark border border-bambu-dark-tertiary overflow-hidden hover:border-bambu-green transition-colors",children:[n.thumbnail_path?i.jsx("img",{src:be.getArchiveThumbnail(n.id),alt:n.print_name||"Print",className:"w-full h-full object-cover"}):i.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray",children:i.jsx(Ii,{className:"w-8 h-8"})}),n.status==="failed"&&i.jsx("div",{className:"absolute inset-0 bg-red-500/30 flex items-center justify-center",children:i.jsx(Wi,{className:"w-8 h-8 text-white"})}),n.status==="completed"&&i.jsx("div",{className:"absolute top-1 right-1",children:i.jsx(pr,{className:"w-4 h-4 text-bambu-green"})}),i.jsx("div",{className:"absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/80 to-transparent p-2 opacity-0 group-hover:opacity-100 transition-opacity",children:i.jsx("p",{className:"text-xs text-white truncate",children:n.print_name||"Unknown"})})]},n.id))})}function Mtt({priority:t,t:e}){const n={low:{color:"bg-gray-500/20 text-gray-400",label:e("projectDetail.priority.low")},normal:{color:"bg-blue-500/20 text-blue-400",label:e("projectDetail.priority.normal")},high:{color:"bg-orange-500/20 text-orange-400",label:e("projectDetail.priority.high")},urgent:{color:"bg-red-500/20 text-red-400",label:e("projectDetail.priority.urgent")}},{color:r,label:a}=n[t]||n.normal;return i.jsxs("span",{className:`px-2 py-1 rounded text-xs font-medium flex items-center gap-1 ${r}`,children:[t==="urgent"&&i.jsx(jn,{className:"w-3 h-3"}),a]})}function ZD(t,e){if(!t)return null;const n=Qn(t);if(!n)return null;const r=new Date,a=Math.ceil((n.getTime()-r.getTime())/(1e3*60*60*24));return a<0?{color:"text-red-400",label:e("projectDetail.dueDate.overdue")}:a===0?{color:"text-orange-400",label:e("projectDetail.dueDate.today")}:a<=3?{color:"text-yellow-400",label:e("projectDetail.dueDate.daysLeft",{count:a})}:{color:"text-bambu-gray",label:e("projectDetail.dueDate.daysLeft",{count:a})}}function Ett(){const{id:t}=gw(),e=ol(),{t:n}=jt(),r=cn(),{showToast:a}=pn(),{hasPermission:s}=Ar(),[o,l]=w.useState(!1),[c,d]=w.useState(!1),[u,m]=w.useState(""),p=parseInt(t||"0",10),{data:f,isLoading:y,error:v}=et({queryKey:["project",p],queryFn:()=>be.getProject(p),enabled:p>0}),{data:b,isLoading:g}=et({queryKey:["project-archives",p],queryFn:()=>be.getProjectArchives(p),enabled:p>0}),{data:_,isLoading:k}=et({queryKey:["project-bom",p],queryFn:()=>be.getProjectBOM(p),enabled:p>0}),{data:C,isLoading:N}=et({queryKey:["project-timeline",p],queryFn:()=>be.getProjectTimeline(p,20),enabled:p>0}),{data:P}=et({queryKey:["settings"],queryFn:be.getSettings}),{data:T}=et({queryKey:["project-folders",p],queryFn:()=>be.getLibraryFoldersByProject(p),enabled:p>0}),j=go(P?.currency||"USD"),A=P?.time_format||"system",F=pt({mutationFn:De=>be.updateProject(p,De),onSuccess:()=>{r.invalidateQueries({queryKey:["project",p]}),r.invalidateQueries({queryKey:["projects"]}),l(!1),d(!1),a(n("projectDetail.toast.projectUpdated"),"success")},onError:De=>{a(De.message,"error")}}),G=()=>{m(f?.notes||""),d(!0)},z=()=>{F.mutate({notes:u})},Z=()=>{d(!1),m("")},[I,ee]=w.useState(""),[ae,X]=w.useState(1),[ce,ue]=w.useState(""),[pe,K]=w.useState(""),[se,de]=w.useState(""),[ge,Te]=w.useState(!1),[V,J]=w.useState(!1),[D,E]=w.useState(null),[U,W]=w.useState(""),[B,ie]=w.useState(1),[O,$]=w.useState(""),[Y,q]=w.useState(""),[te,oe]=w.useState(""),[he,fe]=w.useState({isOpen:!1,title:"",message:"",onConfirm:()=>{}}),re=pt({mutationFn:De=>be.createBOMItem(p,De),onSuccess:()=>{r.invalidateQueries({queryKey:["project-bom",p]}),r.invalidateQueries({queryKey:["project",p]}),ee(""),X(1),ue(""),K(""),de(""),Te(!1),a(n("projectDetail.toast.partAdded"),"success")},onError:De=>a(De.message,"error")}),L=pt({mutationFn:({itemId:De,data:We})=>be.updateBOMItem(p,De,We),onSuccess:()=>{r.invalidateQueries({queryKey:["project-bom",p]}),r.invalidateQueries({queryKey:["project",p]}),E(null)},onError:De=>a(De.message,"error")}),R=pt({mutationFn:De=>be.deleteBOMItem(p,De),onSuccess:()=>{r.invalidateQueries({queryKey:["project-bom",p]}),r.invalidateQueries({queryKey:["project",p]}),a(n("projectDetail.toast.partRemoved"),"success")},onError:De=>a(De.message,"error")}),ne=De=>{De.preventDefault(),I.trim()&&re.mutate({name:I.trim(),quantity_needed:ae,unit_price:ce?parseFloat(ce):void 0,sourcing_url:pe.trim()||void 0,remarks:se.trim()||void 0})},ve=De=>{const We=De.is_complete?0:De.quantity_needed;L.mutate({itemId:De.id,data:{quantity_acquired:We}})},we=(De,We)=>{fe({isOpen:!0,title:n("projectDetail.bom.deletePart"),message:n("projectDetail.bom.deleteConfirm",{name:We}),onConfirm:()=>{fe(ye=>({...ye,isOpen:!1})),R.mutate(De)}})},me=De=>{E(De),W(De.name),ie(De.quantity_needed),$(De.unit_price?.toString()||""),q(De.sourcing_url||""),oe(De.remarks||"")},Me=De=>{De.preventDefault(),!(!D||!U.trim())&&L.mutate({itemId:D.id,data:{name:U.trim(),quantity_needed:B,unit_price:O?parseFloat(O):void 0,sourcing_url:Y.trim()||void 0,remarks:te.trim()||void 0}})},xe=()=>{E(null)},je=async()=>{try{const{blob:De,filename:We}=await be.exportProjectZip(Number(p)),ye=URL.createObjectURL(De),Ke=document.createElement("a");Ke.href=ye,Ke.download=We||`${f?.name||"project"}_${new Date().toISOString().split("T")[0]}.zip`,Ke.click(),URL.revokeObjectURL(ye),a(n("projectDetail.toast.projectExported"),"success")}catch(De){a(De.message,"error")}},He=pt({mutationFn:()=>be.createTemplateFromProject(p),onSuccess:()=>{r.invalidateQueries({queryKey:["projects"]}),a(n("projectDetail.toast.templateCreated"),"success")},onError:De=>a(De.message,"error")}),Oe=De=>Lf(De,A,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"});if(y)return i.jsx("div",{className:"flex items-center justify-center py-24",children:i.jsx(ft,{className:"w-8 h-8 animate-spin text-bambu-green"})});if(v||!f)return i.jsxs("div",{className:"text-center py-24",children:[i.jsx("p",{className:"text-bambu-gray",children:v?`${n("common.error")}: ${v.message}`:n("projectDetail.notFound")}),i.jsx(Ie,{variant:"secondary",className:"mt-4",onClick:()=>e("/projects"),children:n("projectDetail.backToProjects")})]});const _e=f.stats,Ae=_e?.progress_percent??0,Be=_e?.parts_progress_percent??0;return i.jsxs("div",{className:"p-4 md:p-8 space-y-8",children:[i.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[i.jsx(bo,{to:"/projects",className:"hover:text-white transition-colors",children:n("navigation.projects")}),i.jsx(fa,{className:"w-4 h-4"}),i.jsx("span",{className:"text-white",children:f.name})]}),i.jsxs("div",{className:"flex items-start justify-between",children:[i.jsxs("div",{className:"flex items-center gap-4",children:[i.jsx("button",{onClick:()=>e("/projects"),className:"p-2 rounded-lg bg-bambu-card hover:bg-bambu-dark-tertiary transition-colors",children:i.jsx(GX,{className:"w-5 h-5 text-bambu-gray"})}),i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"w-4 h-4 rounded-full flex-shrink-0",style:{backgroundColor:f.color||"#6b7280"}}),i.jsxs("div",{children:[i.jsx("h1",{className:"text-2xl font-bold text-white",children:f.name}),f.description&&i.jsx("p",{className:"text-bambu-gray mt-1",children:f.description})]})]}),i.jsx(Att,{status:f.status,t:n})]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs(Ie,{variant:"secondary",onClick:je,disabled:!s("projects:read"),title:s("projects:read")?n("projectDetail.exportProject"):n("projectDetail.noExportPermission"),children:[i.jsx(fi,{className:"w-4 h-4 mr-2"}),n("projectDetail.export")]}),i.jsxs(Ie,{onClick:()=>l(!0),disabled:!s("projects:update"),title:s("projects:update")?void 0:n("projectDetail.noEditPermission"),children:[i.jsx(Ef,{className:"w-4 h-4 mr-2"}),n("common.edit")]})]})]}),(f.target_count||f.target_parts_count)&&i.jsx(At,{children:i.jsxs(Et,{className:"p-4 space-y-4",children:[f.target_count&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-sm text-bambu-gray",children:n("projectDetail.progress.platesProgress")}),i.jsxs("span",{className:"text-sm font-medium text-white",children:[_e?.total_archives||0," / ",f.target_count," ",n("projectDetail.progress.printJobs")]})]}),i.jsx("div",{className:"h-3 bg-bambu-dark rounded-full overflow-hidden",children:i.jsx("div",{className:"h-full transition-all duration-500",style:{width:`${Math.min(Ae,100)}%`,backgroundColor:Ae>=100?"#22c55e":f.color||"#6b7280"}})}),i.jsxs("div",{className:"flex justify-between mt-1",children:[i.jsx("span",{className:"text-xs text-bambu-gray/70",children:n("projectDetail.progress.percentComplete",{percent:Ae.toFixed(0)})}),_e?.remaining_prints!=null&&_e.remaining_prints>0&&i.jsx("span",{className:"text-xs text-bambu-gray/70",children:n("projectDetail.progress.remaining",{count:_e.remaining_prints})})]})]}),f.target_parts_count&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-sm text-bambu-gray",children:n("projectDetail.progress.partsProgress")}),i.jsxs("span",{className:"text-sm font-medium text-white",children:[_e?.completed_prints||0," / ",f.target_parts_count," ",n("projectDetail.progress.parts")]})]}),i.jsx("div",{className:"h-3 bg-bambu-dark rounded-full overflow-hidden",children:i.jsx("div",{className:"h-full transition-all duration-500",style:{width:`${Math.min(Be,100)}%`,backgroundColor:Be>=100?"#22c55e":f.color||"#6b7280"}})}),i.jsxs("div",{className:"flex justify-between mt-1",children:[i.jsx("span",{className:"text-xs text-bambu-gray/70",children:n("projectDetail.progress.percentComplete",{percent:Be.toFixed(0)})}),_e?.remaining_parts!=null&&_e.remaining_parts>0&&i.jsx("span",{className:"text-xs text-bambu-gray/70",children:n("projectDetail.progress.remaining",{count:_e.remaining_parts})})]})]})]})}),_e&&i.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[i.jsx(At,{children:i.jsx(Et,{className:"p-4",children:i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-bambu-green",children:i.jsx(Ii,{className:"w-5 h-5"})}),i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:n("projectDetail.stats.printJobs")}),i.jsxs("p",{className:"text-xl font-semibold text-white",children:[_e.total_archives," ",i.jsx("span",{className:"text-sm font-normal text-bambu-gray",children:n("projectDetail.stats.total")})]}),_e.failed_prints>0&&i.jsx("p",{className:"text-sm text-status-error",children:n("projectDetail.stats.failed",{count:_e.failed_prints})}),i.jsx("p",{className:"text-sm text-bambu-gray",children:n("projectDetail.stats.partsPrinted",{count:_e.completed_prints})})]})]})})}),i.jsx(IY,{icon:Zn,label:n("projectDetail.stats.printTime"),value:Nxe(_e.total_print_time_hours),color:"text-yellow-400"}),i.jsx(IY,{icon:_r,label:n("projectDetail.stats.filamentUsed"),value:Ttt(_e.total_filament_grams),color:"text-purple-400"})]}),_e&&(()=>{const De=_e.estimated_cost+_e.total_energy_cost+_e.bom_cost;return _e.estimated_cost>0||De>0||f.budget!==null})()&&i.jsx(At,{children:i.jsxs(Et,{className:"p-4",children:[i.jsx("h2",{className:"text-lg font-semibold text-white mb-3",children:n("projectDetail.cost.title")}),i.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.cost.filamentCost")}),i.jsxs("p",{className:"text-lg font-semibold text-white",children:[j,_e.estimated_cost.toFixed(2)]})]}),_e.total_energy_kwh>0&&i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.cost.energy")}),i.jsxs("p",{className:"text-lg font-semibold text-white",children:[_e.total_energy_kwh.toFixed(3)," kWh",_e.total_energy_cost>0&&i.jsxs("span",{className:"text-sm text-bambu-gray ml-1",children:["(",j,_e.total_energy_cost.toFixed(2),")"]})]})]}),(()=>{const De=_e.estimated_cost+_e.total_energy_cost+_e.bom_cost;return De<=0?null:i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.cost.totalCost")}),i.jsxs("p",{className:"text-lg font-semibold text-bambu-green",children:[j,De.toFixed(2)]}),_e.bom_cost>0&&i.jsx("p",{className:"text-xs text-bambu-gray/70",children:n("projectDetail.cost.includesBom")})]})})(),f.budget!==null&&(()=>{const De=_e.estimated_cost+_e.total_energy_cost+_e.bom_cost,We=f.budget-De;return i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.cost.budget")}),i.jsxs("p",{className:"text-sm text-bambu-gray",children:[n("projectDetail.cost.total"),": ",i.jsxs("span",{className:"text-white font-semibold",children:[j,f.budget.toFixed(2)]})]}),i.jsxs("p",{className:`text-sm ${We>=0?"text-bambu-green":"text-red-400"}`,children:[n("projectDetail.cost.remaining"),": ",i.jsxs("span",{className:"font-semibold",children:[j,We.toFixed(2)]})]})]})})()]})]})}),f.children&&f.children.length>0&&i.jsx(At,{children:i.jsxs(Et,{className:"p-4",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2 mb-3",children:[i.jsx(vfe,{className:"w-5 h-5"}),n("projectDetail.subProjects.title",{count:f.children.length})]}),i.jsx("div",{className:"space-y-2",children:f.children.map(De=>i.jsxs(bo,{to:`/projects/${De.id}`,className:"flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:De.color||"#6b7280"}}),i.jsx("span",{className:"text-white",children:De.name}),i.jsx("span",{className:`text-xs px-2 py-0.5 rounded ${De.status==="completed"?"bg-status-ok/20 text-status-ok":De.status==="archived"?"bg-bambu-gray/20 text-bambu-gray":"bg-blue-500/20 text-blue-400"}`,children:De.status})]}),De.progress_percent!==null&&i.jsxs("span",{className:"text-sm text-bambu-gray",children:[De.progress_percent.toFixed(0),"%"]})]},De.id))})]})}),f.parent_id&&f.parent_name&&i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx(Ki,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("span",{className:"text-bambu-gray",children:n("projectDetail.partOf")}),i.jsx(bo,{to:`/projects/${f.parent_id}`,className:"text-bambu-green hover:underline",children:f.parent_name})]}),(f.tags||f.due_date||f.priority!=="normal")&&i.jsxs("div",{className:"flex flex-wrap items-center gap-4",children:[f.priority&&f.priority!=="normal"&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-xs text-bambu-gray uppercase",children:n("projectDetail.priorityLabel")}),i.jsx(Mtt,{priority:f.priority,t:n})]}),f.due_date&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Xr,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("span",{className:"text-sm text-white",children:Rf(f.due_date,{year:"numeric",month:"short",day:"numeric"})}),ZD(f.due_date,n)&&i.jsxs("span",{className:`text-xs ${ZD(f.due_date,n).color}`,children:["(",ZD(f.due_date,n).label,")"]})]}),f.tags&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Vu,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("div",{className:"flex flex-wrap gap-1",children:f.tags.split(",").map((De,We)=>i.jsx("span",{className:"px-2 py-0.5 bg-bambu-dark-tertiary text-bambu-gray text-xs rounded",children:De.trim()},We))})]})]}),i.jsx(At,{children:i.jsxs(Et,{className:"p-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Ss,{className:"w-5 h-5"}),n("projectDetail.notes.title")]}),c?i.jsxs("div",{className:"flex gap-2",children:[i.jsxs(Ie,{variant:"secondary",size:"sm",onClick:Z,disabled:F.isPending,children:[i.jsx(qt,{className:"w-4 h-4 mr-1"}),n("common.cancel")]}),i.jsxs(Ie,{size:"sm",onClick:z,disabled:F.isPending,children:[F.isPending?i.jsx(ft,{className:"w-4 h-4 animate-spin mr-1"}):i.jsx(as,{className:"w-4 h-4 mr-1"}),n("common.save")]})]}):i.jsxs(Ie,{variant:"secondary",size:"sm",onClick:G,disabled:!s("projects:update"),title:s("projects:update")?void 0:n("projectDetail.notes.noEditPermission"),children:[i.jsx(Ef,{className:"w-4 h-4 mr-1"}),n("common.edit")]})]}),c?i.jsx(yL,{content:u,onChange:m,placeholder:n("projectDetail.notes.placeholder")}):f.notes?i.jsx("div",{className:"prose prose-invert prose-sm max-w-none",dangerouslySetInnerHTML:{__html:Nie.sanitize(f.notes)}}):i.jsx("p",{className:"text-bambu-gray/70 text-sm italic",children:n("projectDetail.notes.empty")})]})}),i.jsx(At,{children:i.jsxs(Et,{className:"p-4",children:[i.jsx("div",{className:"flex items-center justify-between mb-3",children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Mc,{className:"w-5 h-5"}),n("projectDetail.files.title")]})}),i.jsxs("p",{className:"text-xs text-bambu-gray mb-3",children:[i.jsx(bo,{to:"/files",className:"text-bambu-green hover:underline",children:n("projectDetail.files.linkFolders")})," ",n("projectDetail.files.forQuickAccess")]}),T&&T.length>0?i.jsx("div",{className:"space-y-2",children:T.map(De=>i.jsxs(bo,{to:`/files?folder=${De.id}`,className:"flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors",children:[i.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[i.jsx(Mc,{className:"w-5 h-5 text-bambu-green flex-shrink-0"}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("p",{className:"text-sm text-white truncate",children:De.name}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("projectDetail.files.fileCount",{count:De.file_count})})]})]}),i.jsx(fa,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"})]},De.id))}):i.jsx("p",{className:"text-bambu-gray/70 text-sm italic",children:n("projectDetail.files.empty")})]})}),i.jsx(At,{children:i.jsxs(Et,{className:"p-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-4",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(iQ,{className:"w-5 h-5"}),n("projectDetail.bom.title"),_e&&_e.bom_total_items>0&&i.jsxs("span",{className:"text-sm font-normal text-bambu-gray",children:["(",n("projectDetail.bom.acquired",{completed:_e.bom_completed_items,total:_e.bom_total_items}),")"]})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[_&&_.some(De=>De.is_complete)&&i.jsx("button",{onClick:()=>J(!V),className:`text-xs px-2 py-1 rounded transition-colors ${V?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:n(V?"projectDetail.bom.showAll":"projectDetail.bom.hideDone")}),!ge&&i.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>Te(!0),disabled:!s("projects:update"),title:s("projects:update")?void 0:n("projectDetail.bom.noAddPermission"),children:[i.jsx(ir,{className:"w-4 h-4 mr-1"}),n("projectDetail.bom.addPart")]})]})]}),ge&&i.jsxs("form",{onSubmit:ne,className:"bg-bambu-dark rounded-lg p-4 mb-4 space-y-3",children:[i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[i.jsx("input",{type:"text",value:I,onChange:De=>ee(De.target.value),className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.partNamePlaceholder"),autoFocus:!0}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("input",{type:"number",value:ae,onChange:De=>X(parseInt(De.target.value)||1),className:"w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green",min:"1",placeholder:n("projectDetail.bom.qty")}),i.jsx("input",{type:"number",step:"0.01",value:ce,onChange:De=>ue(De.target.value),className:"flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.price",{currency:j})})]})]}),i.jsx("input",{type:"url",value:pe,onChange:De=>K(De.target.value),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.sourcingUrlPlaceholder")}),i.jsx("input",{type:"text",value:se,onChange:De=>de(De.target.value),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.remarksPlaceholder")}),i.jsxs("div",{className:"flex justify-end gap-2",children:[i.jsx(Ie,{type:"button",variant:"secondary",size:"sm",onClick:()=>Te(!1),children:n("common.cancel")}),i.jsx(Ie,{type:"submit",size:"sm",disabled:!I.trim()||re.isPending,children:re.isPending?i.jsx(ft,{className:"w-4 h-4 animate-spin"}):n("projectDetail.bom.addPart")})]})]}),k?i.jsx("div",{className:"flex items-center justify-center py-4",children:i.jsx(ft,{className:"w-6 h-6 animate-spin text-bambu-green"})}):_&&_.length>0?i.jsxs("div",{className:"space-y-2",children:[_.filter(De=>!V||!De.is_complete).map(De=>i.jsx("div",{className:`p-3 rounded-lg transition-colors ${De.is_complete?"bg-status-ok/10":"bg-bambu-dark"}`,children:D?.id===De.id?i.jsxs("form",{onSubmit:Me,className:"space-y-3",children:[i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[i.jsx("input",{type:"text",value:U,onChange:We=>W(We.target.value),className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.partName"),autoFocus:!0}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("input",{type:"number",value:B,onChange:We=>ie(parseInt(We.target.value)||1),className:"w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green",min:"1",placeholder:n("projectDetail.bom.qty")}),i.jsx("input",{type:"number",step:"0.01",value:O,onChange:We=>$(We.target.value),className:"flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.price",{currency:j})})]})]}),i.jsx("input",{type:"url",value:Y,onChange:We=>q(We.target.value),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.sourcingUrlPlaceholder")}),i.jsx("input",{type:"text",value:te,onChange:We=>oe(We.target.value),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:n("projectDetail.bom.remarksPlaceholder")}),i.jsxs("div",{className:"flex justify-end gap-2",children:[i.jsx(Ie,{type:"button",variant:"secondary",size:"sm",onClick:xe,children:n("common.cancel")}),i.jsx(Ie,{type:"submit",size:"sm",disabled:!U.trim()||L.isPending,children:L.isPending?i.jsx(ft,{className:"w-4 h-4 animate-spin"}):n("common.save")})]})]}):i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx("button",{onClick:()=>s("projects:update")&&ve(De),disabled:L.isPending||!s("projects:update"),title:s("projects:update")?void 0:n("projectDetail.bom.noUpdatePermission"),className:`w-5 h-5 mt-0.5 rounded border-2 flex items-center justify-center transition-colors flex-shrink-0 ${De.is_complete?"bg-status-ok border-status-ok text-white":s("projects:update")?"border-bambu-gray hover:border-bambu-green":"border-bambu-gray/50 cursor-not-allowed"}`,children:De.is_complete&&i.jsx(pr,{className:"w-3 h-3"})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[i.jsxs("p",{className:`text-sm font-medium ${De.is_complete?"text-bambu-gray line-through":"text-white"}`,children:[De.name,i.jsxs("span",{className:"text-bambu-gray font-normal ml-2",children:["x",De.quantity_needed]})]}),De.unit_price!==null&&i.jsxs("span",{className:"text-xs text-bambu-green whitespace-nowrap",children:[j,(De.unit_price*De.quantity_needed).toFixed(2)]})]}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("button",{onClick:()=>s("projects:update")&&me(De),disabled:!s("projects:update"),className:`p-1 rounded transition-colors flex-shrink-0 ${s("projects:update")?"hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white":"text-bambu-gray/50 cursor-not-allowed"}`,title:s("projects:update")?n("common.edit"):n("projectDetail.bom.noEditPermission"),children:i.jsx(Xi,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>s("projects:update")&&we(De.id,De.name),disabled:!s("projects:update"),className:`p-1 rounded transition-colors flex-shrink-0 ${s("projects:update")?"hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-red-400":"text-bambu-gray/50 cursor-not-allowed"}`,title:s("projects:update")?n("common.delete"):n("projectDetail.bom.noDeletePermission"),children:i.jsx(an,{className:"w-4 h-4"})})]})]}),De.sourcing_url&&i.jsxs("a",{href:De.sourcing_url,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 mt-1 text-xs text-blue-400 hover:text-blue-300 transition-colors",onClick:We=>We.stopPropagation(),children:[i.jsx(ni,{className:"w-3 h-3 flex-shrink-0"}),i.jsx("span",{className:"truncate",children:(()=>{try{return new URL(De.sourcing_url).hostname.replace("www.","")}catch{return De.sourcing_url}})()})]}),De.remarks&&i.jsx("p",{className:"mt-1 text-xs text-bambu-gray/80 italic",children:De.remarks})]})]})},De.id)),_e&&_e.bom_cost>0&&i.jsxs("div",{className:"pt-2 mt-2 border-t border-bambu-dark-tertiary flex justify-between text-sm",children:[i.jsx("span",{className:"text-bambu-gray",children:n("projectDetail.bom.totalCost")}),i.jsxs("span",{className:"text-white font-medium",children:[j,_e.bom_cost.toFixed(2)]})]})]}):i.jsx("p",{className:"text-bambu-gray/70 text-sm italic",children:n("projectDetail.bom.empty")})]})}),i.jsx(At,{children:i.jsxs(Et,{className:"p-4",children:[i.jsx("div",{className:"flex items-center justify-between mb-3",children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(k0,{className:"w-5 h-5"}),n("projectDetail.timeline.title")]})}),N?i.jsx("div",{className:"flex items-center justify-center py-4",children:i.jsx(ft,{className:"w-6 h-6 animate-spin text-bambu-green"})}):C&&C.length>0?i.jsx("div",{className:"space-y-3",children:C.slice(0,10).map((De,We)=>i.jsxs("div",{className:"flex gap-3",children:[i.jsxs("div",{className:`w-8 h-8 rounded-full flex items-center justify-center flex-shrink-0 ${De.event_type==="print_completed"?"bg-status-ok/20 text-status-ok":De.event_type==="print_failed"?"bg-status-error/20 text-status-error":De.event_type==="print_started"?"bg-yellow-500/20 text-yellow-400":"bg-bambu-dark-tertiary text-bambu-gray"}`,children:[De.event_type==="print_completed"&&i.jsx(pr,{className:"w-4 h-4"}),De.event_type==="print_failed"&&i.jsx(Wi,{className:"w-4 h-4"}),De.event_type==="print_started"&&i.jsx(_r,{className:"w-4 h-4"}),De.event_type==="queued"&&i.jsx(N3,{className:"w-4 h-4"}),De.event_type==="project_created"&&i.jsx(ir,{className:"w-4 h-4"})]}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("p",{className:"text-sm text-white",children:De.title}),De.description&&i.jsx("p",{className:"text-xs text-bambu-gray truncate",children:De.description}),i.jsx("p",{className:"text-xs text-bambu-gray/70",children:Oe(De.timestamp)})]})]},We))}):i.jsx("p",{className:"text-bambu-gray/70 text-sm italic",children:n("projectDetail.timeline.empty")})]})}),!f.is_template&&i.jsx("div",{className:"flex justify-end",children:i.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>He.mutate(),disabled:He.isPending||!s("projects:create"),title:s("projects:create")?void 0:n("projectDetail.template.noCreatePermission"),children:[He.isPending?i.jsx(ft,{className:"w-4 h-4 animate-spin mr-2"}):i.jsx(To,{className:"w-4 h-4 mr-2"}),n("projectDetail.template.saveAsTemplate")]})}),_e&&(_e.queued_prints>0||_e.in_progress_prints>0)&&i.jsx(At,{children:i.jsxs(Et,{className:"p-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(N3,{className:"w-5 h-5"}),n("projectDetail.queue.title")]}),i.jsx(bo,{to:`/queue?project=${p}`,className:"text-sm text-bambu-green hover:underline",children:n("projectDetail.queue.viewAll")})]}),i.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[_e.in_progress_prints>0&&i.jsx("span",{className:"text-yellow-400",children:n("projectDetail.queue.printing",{count:_e.in_progress_prints})}),_e.queued_prints>0&&i.jsx("span",{className:"text-bambu-gray",children:n("projectDetail.queue.queued",{count:_e.queued_prints})})]})]})}),i.jsxs("div",{children:[i.jsx("div",{className:"flex items-center justify-between mb-4",children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Ii,{className:"w-5 h-5"}),n("projectDetail.prints.title",{count:b?.length||0})]})}),g?i.jsx("div",{className:"flex items-center justify-center py-8",children:i.jsx(ft,{className:"w-6 h-6 animate-spin text-bambu-green"})}):i.jsx(Ptt,{archives:b||[],t:n})]}),o&&i.jsx(Joe,{t:n,currencySymbol:j,project:{...f,archive_count:_e?.total_archives||0,total_items:_e?.total_items||0,completed_count:_e?.completed_prints||0,failed_count:_e?.failed_prints||0,queue_count:_e?.queued_prints||0,progress_percent:_e?.progress_percent||null,archives:[]},onClose:()=>l(!1),onSave:De=>F.mutate(De),isLoading:F.isPending}),he.isOpen&&i.jsx(kn,{title:he.title,message:he.message,confirmText:n("common.delete"),variant:"danger",onConfirm:he.onConfirm,onCancel:()=>fe(De=>({...De,isOpen:!1}))})]})}function jtt({parentId:t,onClose:e,onSave:n,isLoading:r,t:a}){const[s,o]=w.useState(""),l=c=>{c.preventDefault(),n({name:s.trim(),parent_id:t})};return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary",children:[i.jsx("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("fileManager.newFolder")})}),i.jsxs("form",{onSubmit:l,className:"p-4 space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:a("fileManager.folderName")}),i.jsx("input",{type:"text",value:s,onChange:c=>o(c.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:a("fileManager.folderNamePlaceholder"),autoFocus:!0,required:!0})]}),i.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[i.jsx(Ie,{type:"button",variant:"secondary",onClick:e,children:a("common.cancel")}),i.jsx(Ie,{type:"submit",disabled:!s.trim()||r,children:r?i.jsx(ft,{className:"w-4 h-4 animate-spin"}):a("common.create")})]})]})]})})}function Dtt({onClose:t,onSave:e,isLoading:n,t:r}){const[a,s]=w.useState(""),[o,l]=w.useState(""),[c,d]=w.useState(!0),[u,m]=w.useState(!1),p=f=>{f.preventDefault(),e({name:a.trim(),external_path:o.trim(),readonly:c,show_hidden:u})};return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(zk,{className:"w-5 h-5 text-bambu-green"}),r("fileManager.linkExternalFolder")]}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:r("fileManager.linkExternalFolderDescription")})]}),i.jsxs("form",{onSubmit:p,className:"p-4 space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:r("fileManager.folderName")}),i.jsx("input",{type:"text",value:a,onChange:f=>s(f.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:r("fileManager.externalFolderNamePlaceholder"),autoFocus:!0,required:!0})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:r("fileManager.externalPath")}),i.jsx("input",{type:"text",value:o,onChange:f=>l(f.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green font-mono text-sm",placeholder:"/mnt/nas/3d-prints",required:!0}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:r("fileManager.externalPathHelp")})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:c,onChange:f=>d(f.target.checked),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("span",{className:"text-sm text-white",children:r("fileManager.readOnly")}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:["(",r("fileManager.readOnlyHelp"),")"]})]}),i.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:u,onChange:f=>m(f.target.checked),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsx("span",{className:"text-sm text-white",children:r("fileManager.showHiddenFiles")})]})]}),i.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[i.jsx(Ie,{type:"button",variant:"secondary",onClick:t,children:r("common.cancel")}),i.jsx(Ie,{type:"submit",disabled:!a.trim()||!o.trim()||n,children:n?i.jsx(ft,{className:"w-4 h-4 animate-spin"}):r("fileManager.linkFolder")})]})]})]})})}function Ftt({type:t,currentName:e,onClose:n,onSave:r,isLoading:a,t:s}){const o=t==="file"?e.match(/(\.gcode\.3mf|\.3mf|\.gcode)$/i)?.[1]??"":"",l=t==="file"&&o?e.slice(0,-o.length):e,[c,d]=w.useState(l),u=m=>{m.preventDefault();const p=t==="file"?c.trim()+o:c.trim();c.trim()&&p!==e&&r(p)};return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary",children:[i.jsx("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:s(t==="file"?"fileManager.renameFile":"fileManager.renameFolder")})}),i.jsxs("form",{onSubmit:u,className:"p-4 space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:s("common.name")}),i.jsxs("div",{className:"flex items-center bg-bambu-dark border border-bambu-dark-tertiary rounded focus-within:border-bambu-green",children:[i.jsx("input",{type:"text",value:c,onChange:m=>d(m.target.value),className:"flex-1 bg-transparent px-3 py-2 text-white placeholder-bambu-gray focus:outline-none min-w-0",autoFocus:!0,required:!0}),o&&i.jsx("span",{className:"pr-3 text-bambu-gray text-sm select-none whitespace-nowrap",children:o})]})]}),i.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[i.jsx(Ie,{type:"button",variant:"secondary",onClick:n,children:s("common.cancel")}),i.jsx(Ie,{type:"submit",disabled:!c.trim()||c.trim()===l||a,children:a?i.jsx(ft,{className:"w-4 h-4 animate-spin"}):s("common.rename")})]})]})]})})}function Rtt({folders:t,selectedFiles:e,currentFolderId:n,onClose:r,onMove:a,isLoading:s,t:o}){const[l,c]=w.useState(null),d=(m,p=0)=>{const f=[];for(const y of m)f.push({id:y.id,name:y.name,depth:p}),y.children.length>0&&f.push(...d(y.children,p+1));return f},u=[{id:null,name:o("fileManager.rootNoFolder"),depth:0},...d(t)];return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary",children:[i.jsx("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:o("fileManager.moveFiles",{count:e.length})})}),i.jsxs("div",{className:"p-4 space-y-4",children:[i.jsx("div",{className:"max-h-64 overflow-y-auto space-y-1",children:u.map(m=>i.jsxs("button",{onClick:()=>c(m.id),disabled:m.id===n,className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${l===m.id?"bg-bambu-green/20 text-bambu-green":m.id===n?"opacity-50 cursor-not-allowed text-bambu-gray":"hover:bg-bambu-dark text-white"}`,style:{paddingLeft:`${12+m.depth*16}px`},children:[i.jsx(Mc,{className:"w-4 h-4"}),m.name,m.id===n&&i.jsxs("span",{className:"text-xs text-bambu-gray ml-auto",children:["(",o("fileManager.current"),")"]})]},m.id??"root"))}),i.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[i.jsx(Ie,{type:"button",variant:"secondary",onClick:r,children:o("common.cancel")}),i.jsx(Ie,{onClick:()=>a(l),disabled:s,children:s?i.jsx(ft,{className:"w-4 h-4 animate-spin"}):o("common.move")})]})]})]})})}function Ltt({folder:t,onClose:e,onLink:n,isLoading:r,t:a}){const[s,o]=w.useState("project"),[l,c]=w.useState(t.project_id||t.archive_id||null);w.useState(()=>{t.archive_id&&o("archive")});const{data:d}=et({queryKey:["projects"],queryFn:()=>be.getProjects()}),{data:u}=et({queryKey:["archives-for-link"],queryFn:()=>be.getArchives(void 0,void 0,100)}),m=()=>{n(s==="project"?{project_id:l,archive_id:0}:{project_id:0,archive_id:l})},p=()=>{n({project_id:0,archive_id:0})},f=t.project_id||t.archive_id;return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Fu,{className:"w-5 h-5 text-bambu-green"}),a("fileManager.linkFolder")]}),i.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark rounded",children:i.jsx(qt,{className:"w-5 h-5 text-bambu-gray"})})]}),i.jsxs("div",{className:"p-4 space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("fileManager.linkFolderDescription",{name:t.name})}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("button",{onClick:()=>{o("project"),c(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${s==="project"?"border-bambu-green bg-bambu-green/10 text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,children:[i.jsx(WX,{className:"w-4 h-4"}),a("fileManager.project")]}),i.jsxs("button",{onClick:()=>{o("archive"),c(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${s==="archive"?"border-bambu-green bg-bambu-green/10 text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,children:[i.jsx(Vs,{className:"w-4 h-4"}),a("fileManager.archive")]})]}),i.jsx("div",{className:"max-h-64 overflow-y-auto space-y-1 bg-bambu-dark rounded-lg p-2",children:s==="project"?d&&d.length>0?d.map(y=>i.jsxs("button",{onClick:()=>c(y.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${l===y.id?"bg-bambu-green/20 text-bambu-green":"hover:bg-bambu-dark-tertiary text-white"}`,children:[i.jsx("div",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:y.color||"#00ae42"}}),i.jsx("span",{className:"truncate",children:y.name})]},y.id)):i.jsx("p",{className:"text-sm text-bambu-gray text-center py-4",children:a("fileManager.noProjectsFound")}):u&&u.length>0?u.map(y=>i.jsxs("button",{onClick:()=>c(y.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${l===y.id?"bg-bambu-green/20 text-bambu-green":"hover:bg-bambu-dark-tertiary text-white"}`,children:[i.jsx(pf,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),i.jsx("span",{className:"truncate",children:y.print_name||y.filename})]},y.id)):i.jsx("p",{className:"text-sm text-bambu-gray text-center py-4",children:a("fileManager.noArchivesFound")})})]}),i.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex justify-between",children:[f&&i.jsxs(Ie,{variant:"danger",onClick:p,disabled:r,children:[i.jsx(Df,{className:"w-4 h-4 mr-2"}),a("fileManager.unlink")]}),i.jsxs("div",{className:`flex gap-2 ${f?"":"ml-auto"}`,children:[i.jsx(Ie,{variant:"secondary",onClick:e,children:a("common.cancel")}),i.jsx(Ie,{onClick:m,disabled:!l||r,children:r?i.jsx(ft,{className:"w-4 h-4 animate-spin"}):a("fileManager.link")})]})]})]})})}function ele({folder:t,selectedFolderId:e,onSelect:n,onDelete:r,onLink:a,onRename:s,depth:o=0,wrapNames:l=!1,hasPermission:c,t:d}){const[u,m]=w.useState(!0),[p,f]=w.useState(!1),y=t.children.length>0,v=t.project_id||t.archive_id,b=t.is_external;return i.jsxs("div",{children:[i.jsxs("div",{className:`group flex items-center gap-1 px-2 py-1.5 rounded cursor-pointer transition-colors ${e===t.id?"bg-bambu-green/20 text-bambu-green":"hover:bg-bambu-dark text-white"}`,style:{paddingLeft:`${8+o*12}px`},onClick:()=>n(t.id),children:[y?i.jsx("button",{onClick:g=>{g.stopPropagation(),m(!u)},className:"p-0.5 hover:bg-bambu-dark-tertiary rounded",children:i.jsx(fa,{className:`w-3.5 h-3.5 transition-transform ${u?"rotate-90":""}`})}):i.jsx("div",{className:"w-4.5"}),b?i.jsx(zk,{className:"w-4 h-4 text-purple-400 flex-shrink-0"}):i.jsx(Mc,{className:"w-4 h-4 text-bambu-green flex-shrink-0"}),i.jsx("span",{className:`text-sm flex-1 min-w-0 ${l?"break-all":"truncate"}`,title:t.name,children:t.name}),v&&i.jsxs("button",{onClick:g=>{g.stopPropagation(),a(t)},className:"flex-shrink-0 flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-blue-500/20 text-blue-400 hover:bg-blue-500/30 transition-colors",title:`${t.project_name?`Project: ${t.project_name}`:`Archive: ${t.archive_name}`} (click to change)`,children:[i.jsx(Fu,{className:"w-3 h-3"}),t.project_name?i.jsx(WX,{className:"w-3 h-3"}):i.jsx(Vs,{className:"w-3 h-3"})]}),b&&t.external_readonly&&i.jsx("span",{title:d("fileManager.readOnly"),children:i.jsx(yu,{className:"w-3 h-3 text-amber-400 flex-shrink-0"})}),t.file_count>0&&i.jsx("span",{className:"flex-shrink-0 text-xs text-bambu-gray",children:t.file_count}),!v&&!b&&i.jsx("button",{onClick:g=>{g.stopPropagation(),a(t)},className:"flex-shrink-0 p-1 rounded hover:bg-bambu-dark-tertiary",title:d("fileManager.linkToProjectOrArchive"),children:i.jsx(Fu,{className:"w-3.5 h-3.5 text-bambu-gray hover:text-bambu-green"})}),i.jsx("div",{className:`flex-shrink-0 flex items-center gap-0.5 transition-opacity ${l?"":"opacity-0 group-hover:opacity-100"}`,onClick:g=>g.stopPropagation(),children:i.jsxs("div",{className:"relative",children:[i.jsx("button",{onClick:()=>f(!p),className:"p-1 rounded hover:bg-bambu-dark-tertiary",children:i.jsx(Th,{className:"w-3.5 h-3.5 text-bambu-gray"})}),p&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>f(!1)}),i.jsxs("div",{className:"absolute right-0 top-full mt-1 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]",children:[i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${c("library:update_all")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{c("library:update_all")&&(s(t),f(!1))},disabled:!c("library:update_all"),title:c("library:update_all")?void 0:d("fileManager.noPermissionRenameFolder"),children:[i.jsx(Xi,{className:"w-3.5 h-3.5"}),d("common.rename")]}),i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${c("library:update_all")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{c("library:update_all")&&(a(t),f(!1))},disabled:!c("library:update_all"),title:c("library:update_all")?void 0:d("fileManager.noPermissionLinkFolder"),children:[i.jsx(Fu,{className:"w-3.5 h-3.5"}),d(v?"fileManager.changeLink":"fileManager.linkTo")]}),i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${c("library:delete_all")?"text-red-400 hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{c("library:delete_all")&&(r(t.id),f(!1))},disabled:!c("library:delete_all"),title:c("library:delete_all")?void 0:d("fileManager.noPermissionDeleteFolder"),children:[i.jsx(an,{className:"w-3.5 h-3.5"}),d("common.delete")]})]})]})]})})]}),y&&u&&i.jsx("div",{children:t.children.map(g=>i.jsx(ele,{folder:g,selectedFolderId:e,onSelect:n,onDelete:r,onLink:a,onRename:s,depth:o+1,wrapNames:l,hasPermission:c,t:d},g.id))})]})}function TL(t){const e=t.toLowerCase();return e.endsWith(".gcode")||e.includes(".gcode.")}function Ott({file:t,isSelected:e,isMobile:n,onSelect:r,onDelete:a,onDownload:s,onAddToQueue:o,onPrint:l,onPreview3d:c,onRename:d,onGenerateThumbnail:u,thumbnailVersion:m,hasPermission:p,canModify:f,authEnabled:y,t:v}){const[b,g]=w.useState(!1);return i.jsxs("div",{className:`group relative bg-bambu-dark-secondary rounded-lg border transition-all cursor-pointer overflow-hidden ${e?"border-bambu-green ring-1 ring-bambu-green":"border-bambu-dark-tertiary hover:border-bambu-green/50"}`,onClick:()=>r(t.id),children:[i.jsxs("div",{className:"aspect-square bg-bambu-dark flex items-center justify-center overflow-hidden",children:[t.thumbnail_path?i.jsx("img",{src:`${be.getLibraryFileThumbnailUrl(t.id)}${m?`?v=${m}`:""}`,alt:t.filename,className:"w-full h-full object-cover"}):i.jsx(pf,{className:"w-12 h-12 text-bambu-gray/30"}),i.jsx("div",{className:`absolute top-2 right-2 text-xs px-1.5 py-0.5 rounded font-medium ${t.file_type==="3mf"?"bg-bambu-green/90 text-white":t.file_type==="gcode"?"bg-blue-500/90 text-white":t.file_type==="stl"?"bg-purple-500/90 text-white":"bg-bambu-gray/90 text-white"}`,children:t.file_type.toUpperCase()})]}),i.jsxs("div",{className:"p-3",children:[i.jsx("h3",{className:"text-sm font-medium text-white truncate",title:t.print_name||t.filename,children:t.print_name||t.filename}),i.jsxs("div",{className:"flex items-center gap-3 mt-1 text-xs text-bambu-gray",children:[i.jsx("span",{children:vo(t.file_size)}),t.print_time_seconds&&i.jsxs("span",{className:"flex items-center gap-1",children:[i.jsx(Zn,{className:"w-3 h-3"}),Bs(t.print_time_seconds)]})]}),t.sliced_for_model&&i.jsxs("div",{className:"mt-1 text-xs text-bambu-gray flex items-center gap-1",children:[i.jsx(_r,{className:"w-3 h-3"}),t.sliced_for_model]}),t.print_count>0&&i.jsx("div",{className:"mt-1 text-xs text-bambu-green",children:v("fileManager.printedCount",{count:t.print_count})}),y&&t.created_by_username&&i.jsxs("div",{className:"mt-1 text-xs text-bambu-gray flex items-center gap-1",children:[i.jsx(Gu,{className:"w-3 h-3"}),t.created_by_username]})]}),i.jsxs("div",{className:`absolute bottom-2 right-2 transition-opacity ${n?"opacity-100":"opacity-0 group-hover:opacity-100"}`,onClick:_=>_.stopPropagation(),children:[i.jsx("button",{onClick:()=>g(!b),className:"p-1.5 rounded bg-bambu-dark-secondary/90 hover:bg-bambu-dark-tertiary",children:i.jsx(Th,{className:"w-4 h-4 text-bambu-gray"})}),b&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>g(!1)}),i.jsxs("div",{className:"absolute right-0 bottom-8 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[140px]",children:[l&&TL(t.filename)&&i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${p("printers:control")?"text-bambu-green hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{p("printers:control")&&(l(t),g(!1))},disabled:!p("printers:control"),title:p("printers:control")?void 0:v("fileManager.noPermissionPrint"),children:[i.jsx(_r,{className:"w-3.5 h-3.5"}),v("common.print")]}),o&&TL(t.filename)&&i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${p("queue:create")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{p("queue:create")&&(o(t.id),g(!1))},disabled:!p("queue:create"),title:p("queue:create")?void 0:v("fileManager.noPermissionAddToQueue"),children:[i.jsx(Zn,{className:"w-3.5 h-3.5"}),v("fileManager.schedulePrint")]}),c&&(t.file_type==="3mf"||t.file_type==="gcode"||t.file_type==="stl")&&i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${p("library:read")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{p("library:read")&&(c(t),g(!1))},disabled:!p("library:read"),title:p("library:read")?void 0:"You do not have permission to preview files",children:[i.jsx(aa,{className:"w-3.5 h-3.5"}),"3D Preview"]}),i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${p("library:read")?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{p("library:read")&&(s(t.id),g(!1))},disabled:!p("library:read"),title:p("library:read")?void 0:v("fileManager.noPermissionDownload"),children:[i.jsx(fi,{className:"w-3.5 h-3.5"}),v("common.download")]}),d&&i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${f("library","update",t.created_by_id)?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{f("library","update",t.created_by_id)&&(d(t),g(!1))},disabled:!f("library","update",t.created_by_id),title:f("library","update",t.created_by_id)?void 0:v("fileManager.noPermissionRenameFile"),children:[i.jsx(Xi,{className:"w-3.5 h-3.5"}),v("common.rename")]}),u&&t.file_type==="stl"&&i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${f("library","update",t.created_by_id)?"text-white hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{f("library","update",t.created_by_id)&&(u(t),g(!1))},disabled:!f("library","update",t.created_by_id),title:f("library","update",t.created_by_id)?void 0:v("fileManager.noPermissionGenerateThumbnail"),children:[i.jsx(qu,{className:"w-3.5 h-3.5"}),v("fileManager.generateThumbnail")]}),i.jsxs("button",{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${f("library","delete",t.created_by_id)?"text-red-400 hover:bg-bambu-dark":"text-bambu-gray cursor-not-allowed"}`,onClick:()=>{f("library","delete",t.created_by_id)&&(a(t.id),g(!1))},disabled:!f("library","delete",t.created_by_id),title:f("library","delete",t.created_by_id)?void 0:v("fileManager.noPermissionDeleteFile"),children:[i.jsx(an,{className:"w-3.5 h-3.5"}),v("common.delete")]})]})]})]}),i.jsx("div",{className:`absolute top-2 left-2 w-5 h-5 rounded border-2 flex items-center justify-center transition-all ${e?"bg-bambu-green border-bambu-green":`border-white/30 bg-black/30 ${n?"opacity-100":"opacity-0 group-hover:opacity-100"}`}`,children:e&&i.jsx("div",{className:"w-2 h-2 bg-white rounded-sm"})})]})}function Itt(){const{t}=jt(),e=cn(),{showToast:n}=pn(),{hasPermission:r,hasAnyPermission:a,canModify:s,authEnabled:o}=Ar(),[l]=zL(),c=l.get("folder"),d=c?parseInt(c,10):null,[u,m]=w.useState(d),[p,f]=w.useState([]),[y,v]=w.useState(!1),[b,g]=w.useState(!1),[_,k]=w.useState(!1),[C,N]=w.useState(!1),[P,T]=w.useState(null),[j,A]=w.useState(null),[F,G]=w.useState(null),[z,Z]=w.useState(null),[I,ee]=w.useState(null),[ae,X]=w.useState(null),[ce,ue]=w.useState({}),[pe,K]=w.useState(null),[se,de]=w.useState(()=>localStorage.getItem("library-view-mode")||"grid"),[ge,Te]=w.useState(()=>localStorage.getItem("library-wrap-folders")==="true"),[V,J]=w.useState(()=>{const qe=localStorage.getItem("library-sidebar-width");return qe?parseInt(qe,10):256}),[D,E]=w.useState(!1),U=w.useRef(null);w.useEffect(()=>{if(!D)return;document.body.style.userSelect="none",document.body.style.cursor="col-resize";const qe=Ut=>{if(!U.current)return;const Gt=U.current.parentElement?.getBoundingClientRect();if(!Gt)return;const ln=Ut.clientX-Gt.left,Un=Math.min(500,Math.max(200,ln));J(Un)},St=()=>{E(!1),document.body.style.userSelect="",document.body.style.cursor="",localStorage.setItem("library-sidebar-width",String(V))};return document.addEventListener("mousemove",qe),document.addEventListener("mouseup",St),()=>{document.removeEventListener("mousemove",qe),document.removeEventListener("mouseup",St),document.body.style.userSelect="",document.body.style.cursor=""}},[D,V]);const[W,B]=w.useState(""),[ie,O]=w.useState("all"),[$,Y]=w.useState(""),[q,te]=w.useState(()=>localStorage.getItem("library-sort-field")||"name"),[oe,he]=w.useState(()=>localStorage.getItem("library-sort-direction")||"asc"),fe=gie();w.useEffect(()=>{const qe=l.get("folder");if(qe){const St=parseInt(qe,10);m(St)}},[l]);const{data:re}=et({queryKey:["settings"],queryFn:()=>be.getSettings()}),{data:L,isLoading:R}=et({queryKey:["library-folders"],queryFn:()=>be.getLibraryFolders()}),{data:ne,isLoading:ve}=et({queryKey:["library-files",u],queryFn:()=>be.getLibraryFiles(u,u===null)}),{data:we}=et({queryKey:["library-stats"],queryFn:()=>be.getLibraryStats()}),{data:me}=et({queryKey:["users"],queryFn:()=>be.getUsers()}),Me=w.useMemo(()=>{if(!ne)return[];const qe=new Set(ne.map(St=>St.file_type));return Array.from(qe).sort()},[ne]),xe=w.useMemo(()=>{if(!ne)return[];let qe=[...ne];if(W.trim()){const St=W.toLowerCase();qe=qe.filter(Ut=>Ut.filename.toLowerCase().includes(St)||Ut.print_name&&Ut.print_name.toLowerCase().includes(St))}if(ie!=="all"&&(qe=qe.filter(St=>St.file_type===ie)),$.trim()){const St=$.toLowerCase();qe=qe.filter(Ut=>Ut.created_by_username&&Ut.created_by_username.toLowerCase().includes(St))}return qe.sort((St,Ut)=>{let Gt=0;switch(q){case"name":Gt=(St.print_name||St.filename).localeCompare(Ut.print_name||Ut.filename);break;case"date":Gt=(Qn(St.created_at)?.getTime()??0)-(Qn(Ut.created_at)?.getTime()??0);break;case"size":Gt=St.file_size-Ut.file_size;break;case"type":Gt=St.file_type.localeCompare(Ut.file_type);break;case"prints":Gt=St.print_count-Ut.print_count;break}return oe==="asc"?Gt:-Gt}),qe},[ne,W,ie,$,q,oe]),je=w.useMemo(()=>{if(!we||!re)return!1;const qe=(re.library_disk_warning_gb||5)*1024*1024*1024;return we.disk_free_bytesbe.createLibraryFolder(qe),onSuccess:()=>{e.invalidateQueries({queryKey:["library-folders"]}),v(!1),n(t("fileManager.toast.folderCreated"),"success")},onError:qe=>n(qe.message,"error")}),Oe=pt({mutationFn:async qe=>{const St=await be.createExternalFolder(qe);return await be.scanExternalFolder(St.id),St},onSuccess:qe=>{e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-stats"]}),g(!1),m(qe.id),n(t("fileManager.toast.externalFolderLinked"),"success")},onError:qe=>n(qe.message,"error")}),_e=pt({mutationFn:qe=>be.scanExternalFolder(qe),onSuccess:qe=>{e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-stats"]}),n(t("fileManager.toast.folderScanned",{added:qe.added,removed:qe.removed}),"success")},onError:qe=>n(qe.message,"error")}),Ae=pt({mutationFn:qe=>be.deleteLibraryFolder(qe),onSuccess:()=>{e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-stats"]}),u===j?.id&&m(null),A(null),n(t("fileManager.toast.folderDeleted"),"success")},onError:qe=>{A(null),n(qe.message,"error")}}),Be=pt({mutationFn:qe=>be.deleteLibraryFile(qe),onSuccess:()=>{e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-stats"]}),f(qe=>qe.filter(St=>St!==j?.id)),A(null),n(t("fileManager.toast.fileDeleted"),"success")},onError:qe=>{A(null),n(qe.message,"error")}}),De=pt({mutationFn:qe=>be.bulkDeleteLibrary(qe,[]),onSuccess:(qe,St)=>{e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-stats"]}),n(t("fileManager.toast.filesDeleted",{count:St.length}),"success"),f([]),A(null)},onError:qe=>{A(null),n(qe.message,"error")}}),We=pt({mutationFn:({fileIds:qe,folderId:St})=>be.moveLibraryFiles(qe,St),onSuccess:()=>{e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-folders"]}),f([]),k(!1),n(t("fileManager.toast.filesMoved"),"success")},onError:qe=>n(qe.message,"error")}),ye=pt({mutationFn:({id:qe,data:St})=>be.updateLibraryFolder(qe,St),onSuccess:(qe,St)=>{e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["project-folders"]}),e.invalidateQueries({queryKey:["archive-folders"]}),T(null);const Ut=St.data.project_id===0&&St.data.archive_id===0;n(t(Ut?"fileManager.toast.folderUnlinked":"fileManager.toast.folderLinked"),"success")},onError:qe=>n(qe.message,"error")}),Ke=pt({mutationFn:({id:qe,filename:St})=>be.updateLibraryFile(qe,{filename:St}),onSuccess:()=>{e.invalidateQueries({queryKey:["library-files"]}),X(null),n(t("fileManager.toast.fileRenamed"),"success")},onError:qe=>{X(null),n(qe.message,"error")}}),Pe=pt({mutationFn:({id:qe,name:St})=>be.updateLibraryFolder(qe,{name:St}),onSuccess:()=>{e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-files"]}),X(null),n(t("fileManager.toast.folderRenamed"),"success")},onError:qe=>{X(null),n(qe.message,"error")}}),Ye=pt({mutationFn:()=>be.batchGenerateStlThumbnails({all_missing:!0}),onSuccess:qe=>{if(e.invalidateQueries({queryKey:["library-files"]}),qe.succeeded>0){const St=Date.now(),Ut={};qe.results.forEach(Gt=>{Gt.success&&(Ut[Gt.file_id]=St)}),ue(Gt=>({...Gt,...Ut}))}qe.succeeded>0&&qe.failed===0?n(t("fileManager.toast.thumbnailsGenerated",{count:qe.succeeded}),"success"):qe.succeeded>0&&qe.failed>0?n(t("fileManager.toast.thumbnailsGeneratedPartial",{succeeded:qe.succeeded,failed:qe.failed}),"success"):qe.processed===0?n(t("fileManager.toast.noStlMissingThumbnails"),"info"):n(t("fileManager.toast.failedToGenerateThumbnails",{error:qe.results[0]?.error||"Unknown error"}),"error")},onError:qe=>n(qe.message,"error")}),Ve=pt({mutationFn:qe=>be.batchGenerateStlThumbnails({file_ids:[qe]}),onSuccess:qe=>{if(e.invalidateQueries({queryKey:["library-files"]}),qe.succeeded>0){const St=qe.results[0]?.file_id;St&&ue(Ut=>({...Ut,[St]:Date.now()})),n(t("fileManager.toast.thumbnailGenerated"),"success")}else n(t("fileManager.toast.failedToGenerateThumbnail",{error:qe.results[0]?.error||"Unknown error"}),"error")},onError:qe=>n(qe.message,"error")}),Ne=w.useCallback(qe=>{const St=qe.toLowerCase();return St.endsWith(".gcode")||St.includes(".gcode.")},[]),Ce=w.useMemo(()=>ne?ne.filter(qe=>p.includes(qe.id)&&Ne(qe.filename)):[],[ne,p,Ne]),$e=w.useCallback(qe=>{f(St=>St.includes(qe)?St.filter(Ut=>Ut!==qe):[...St,qe])},[]),nt=w.useCallback(()=>{xe.length>0&&f(xe.map(qe=>qe.id))},[xe]),bt=w.useCallback(()=>{f([])},[]),vt=()=>{e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["library-folders"]}),e.invalidateQueries({queryKey:["library-stats"]})},mt=qe=>{be.downloadLibraryFile(qe).catch(St=>{console.error("Library file download failed:",St)})},Ht=()=>{j&&(j.type==="file"?Be.mutate(j.id):j.type==="folder"?Ae.mutate(j.id):j.type==="bulk"&&De.mutate(p))},Yt=Ae.isPending||Be.isPending||De.isPending,Pt=qe=>{de(qe),localStorage.setItem("library-view-mode",qe)},ut=R||ve,Lt=w.useMemo(()=>{if(!u||!L)return null;const qe=St=>{for(const Ut of St){if(Ut.id===u)return Ut;const Gt=qe(Ut.children);if(Gt)return Gt}return null};return qe(L)},[u,L]);return i.jsxs("div",{className:"p-4 md:p-8 min-h-[calc(100vh-64px)] lg:h-[calc(100vh-64px)] flex flex-col",children:[i.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6",children:[i.jsxs("div",{children:[i.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[i.jsx("div",{className:"p-2.5 bg-bambu-green/10 rounded-xl",children:i.jsx(Mc,{className:"w-6 h-6 text-bambu-green"})}),t("fileManager.title")]}),i.jsx("p",{className:"text-sm text-bambu-gray mt-2 ml-14",children:t("fileManager.subtitle")})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"flex items-center bg-bambu-dark rounded-lg p-1",children:[i.jsx("button",{onClick:()=>Pt("grid"),className:`p-1.5 rounded transition-colors ${se==="grid"?"bg-bambu-dark-secondary text-white":"text-bambu-gray hover:text-white"}`,title:t("fileManager.gridView"),children:i.jsx(ww,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>Pt("list"),className:`p-1.5 rounded transition-colors ${se==="list"?"bg-bambu-dark-secondary text-white":"text-bambu-gray hover:text-white"}`,title:t("fileManager.listView"),children:i.jsx(oT,{className:"w-4 h-4"})})]}),i.jsxs(Ie,{variant:"secondary",onClick:()=>Ye.mutate(),disabled:Ye.isPending||!a("library:update_own","library:update_all"),title:a("library:update_own","library:update_all")?t("fileManager.generateThumbnailsForMissing"):t("fileManager.noPermissionGenerateThumbnail"),children:[Ye.isPending?i.jsx(ft,{className:"w-4 h-4 mr-2 animate-spin"}):i.jsx(qu,{className:"w-4 h-4 mr-2"}),t("fileManager.generateThumbnails")]}),i.jsxs(Ie,{variant:"secondary",onClick:()=>g(!0),disabled:!r("library:upload"),title:r("library:upload")?t("fileManager.linkExternalFolder"):t("fileManager.noPermissionCreateFolder"),children:[i.jsx(zk,{className:"w-4 h-4 mr-2"}),t("fileManager.linkExternal")]}),i.jsxs(Ie,{variant:"secondary",onClick:()=>v(!0),disabled:!r("library:upload"),title:r("library:upload")?void 0:t("fileManager.noPermissionCreateFolder"),children:[i.jsx(bfe,{className:"w-4 h-4 mr-2"}),t("fileManager.newFolder")]}),i.jsxs(Ie,{onClick:()=>N(!0),disabled:!r("library:upload"),title:r("library:upload")?void 0:t("fileManager.noPermissionUpload"),children:[i.jsx(vi,{className:"w-4 h-4 mr-2"}),t("common.upload")]})]})]}),je&&we&&re&&i.jsxs("div",{className:"flex items-center gap-3 mb-4 p-3 bg-amber-500/10 border border-amber-500/30 rounded-lg",children:[i.jsx(jn,{className:"w-5 h-5 text-amber-500 flex-shrink-0"}),i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-sm text-amber-500 font-medium",children:t("fileManager.lowDiskSpaceWarning")}),i.jsx("p",{className:"text-xs text-amber-500/80",children:t("fileManager.lowDiskSpaceDetails",{free:vo(we.disk_free_bytes),total:vo(we.disk_total_bytes),threshold:re.library_disk_warning_gb})})]})]}),we&&i.jsxs("div",{className:"flex flex-wrap items-center gap-3 sm:gap-6 mb-6 p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx(aT,{className:"w-4 h-4 text-bambu-green"}),i.jsxs("span",{className:"text-bambu-gray",children:[t("fileManager.files"),":"]}),i.jsx("span",{className:"text-white font-medium",children:we.total_files})]}),i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx(Mc,{className:"w-4 h-4 text-blue-400"}),i.jsxs("span",{className:"text-bambu-gray",children:[t("fileManager.folders"),":"]}),i.jsx("span",{className:"text-white font-medium",children:we.total_folders})]}),i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx(Gx,{className:"w-4 h-4 text-amber-400"}),i.jsxs("span",{className:"text-bambu-gray",children:[t("fileManager.size"),":"]}),i.jsx("span",{className:"text-white font-medium",children:vo(we.total_size_bytes)})]}),i.jsxs("div",{className:"flex items-center gap-2 text-sm sm:ml-auto",children:[i.jsxs("span",{className:"text-bambu-gray",children:[t("fileManager.free"),":"]}),i.jsx("span",{className:`font-medium ${je?"text-amber-500":"text-white"}`,children:vo(we.disk_free_bytes)})]})]}),i.jsxs("div",{className:"flex-1 flex flex-col lg:flex-row gap-4 lg:gap-6 min-h-0",children:[i.jsx("div",{className:"lg:hidden",children:i.jsxs("select",{value:u??"",onChange:qe=>m(qe.target.value?parseInt(qe.target.value,10):null),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg px-3 py-2.5 text-white focus:outline-none focus:border-bambu-green",children:[i.jsxs("option",{value:"",children:["📁 ",t("fileManager.allFiles")]}),L&&(()=>{const qe=(St,Ut=0)=>{const Gt=[];for(const ln of St)Gt.push({id:ln.id,name:ln.name,fileCount:ln.file_count,depth:Ut}),ln.children.length>0&&Gt.push(...qe(ln.children,Ut+1));return Gt};return qe(L).map(St=>i.jsxs("option",{value:St.id,children:["│ ".repeat(St.depth),"📂 ",St.name," ",St.fileCount>0?`(${St.fileCount})`:""]},St.id))})()]})}),i.jsxs("div",{ref:U,className:"hidden lg:flex flex-shrink-0 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-hidden flex-col relative",style:{width:`${V}px`},children:[i.jsx("div",{className:`absolute right-0 top-0 bottom-0 w-1.5 cursor-col-resize z-10 group/resize flex items-center justify-center transition-colors ${D?"bg-bambu-green":"hover:bg-bambu-green/50"}`,onMouseDown:qe=>{qe.preventDefault(),E(!0)},onDoubleClick:()=>{J(256),localStorage.setItem("library-sidebar-width","256")},title:t("fileManager.dragToResizeTooltip"),children:i.jsxs("div",{className:`flex flex-col gap-1 opacity-0 group-hover/resize:opacity-100 transition-opacity ${D?"opacity-100":""}`,children:[i.jsx("div",{className:"w-0.5 h-0.5 rounded-full bg-white/70"}),i.jsx("div",{className:"w-0.5 h-0.5 rounded-full bg-white/70"}),i.jsx("div",{className:"w-0.5 h-0.5 rounded-full bg-white/70"})]})}),i.jsxs("div",{className:"p-3 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[i.jsx("h2",{className:"text-sm font-medium text-white",children:t("fileManager.folders")}),i.jsx("button",{onClick:()=>{const qe=!ge;Te(qe),localStorage.setItem("library-wrap-folders",String(qe))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${ge?"bg-bambu-green/20 text-bambu-green":"text-bambu-gray hover:text-white hover:bg-bambu-dark"}`,title:t(ge?"fileManager.disableTextWrapping":"fileManager.enableTextWrapping"),children:t("fileManager.wrap")})]}),i.jsxs("div",{className:"flex-1 overflow-y-auto p-2",children:[i.jsxs("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${u===null?"bg-bambu-green/20 text-bambu-green":"hover:bg-bambu-dark text-white"}`,onClick:()=>m(null),children:[i.jsx(pf,{className:"w-4 h-4"}),i.jsx("span",{className:"text-sm",children:t("fileManager.allFiles")})]}),L?.map(qe=>i.jsx(ele,{folder:qe,selectedFolderId:u,onSelect:m,onDelete:St=>A({type:"folder",id:St}),onLink:T,onRename:St=>X({type:"folder",id:St.id,name:St.name}),wrapNames:ge,hasPermission:r,t},qe.id))]})]}),i.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[Lt?.is_external&&i.jsxs("div",{className:"flex items-center gap-3 mb-4 p-3 bg-purple-500/10 border border-purple-500/30 rounded-lg",children:[i.jsx(zk,{className:"w-5 h-5 text-purple-400 flex-shrink-0"}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-sm font-medium text-purple-300",children:t("fileManager.externalFolder")}),Lt.external_readonly&&i.jsxs("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400 flex items-center gap-1",children:[i.jsx(yu,{className:"w-3 h-3"}),t("fileManager.readOnly")]})]}),i.jsx("p",{className:"text-xs text-bambu-gray truncate font-mono",title:Lt.external_path||"",children:Lt.external_path})]}),i.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>u&&_e.mutate(u),disabled:_e.isPending,title:t("fileManager.scanFolder"),children:[_e.isPending?i.jsx(ft,{className:"w-4 h-4 animate-spin"}):i.jsx(vr,{className:"w-4 h-4"}),i.jsx("span",{className:"ml-1.5",children:t("fileManager.scanFolder")})]})]}),ne&&ne.length>0&&i.jsxs("div",{className:"flex flex-wrap items-center gap-2 sm:gap-3 mb-4 p-2 sm:p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-0 z-10 lg:static",children:[i.jsxs("div",{className:"relative w-full sm:w-auto sm:flex-1 sm:max-w-xs",children:[i.jsx(Fr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",placeholder:t("fileManager.searchFiles"),value:W,onChange:qe=>B(qe.target.value),className:"w-full pl-9 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green"})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(sT,{className:"w-4 h-4 text-bambu-gray hidden sm:block"}),i.jsxs("select",{value:ie,onChange:qe=>O(qe.target.value),className:"bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green",children:[i.jsx("option",{value:"all",children:t("fileManager.allTypes")}),Me.map(qe=>i.jsx("option",{value:qe,children:qe.toUpperCase()},qe))]})]}),o&&i.jsxs("div",{className:"relative",children:[i.jsx("input",{type:"text",placeholder:t("fileManager.filterByUser",{defaultValue:"Filter by user"}),value:$,onChange:qe=>Y(qe.target.value),list:"usernames-list",className:`w-32 sm:w-40 px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green ${$?"pr-7":""}`,style:$?{WebkitAppearance:"none",MozAppearance:"textfield"}:void 0}),$&&i.jsx("button",{onClick:()=>Y(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white z-10",children:i.jsx(qt,{className:"w-3 h-3"})}),i.jsx("datalist",{id:"usernames-list",children:me?.map(qe=>i.jsx("option",{value:qe.username},qe.id))})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("select",{value:q,onChange:qe=>{const St=qe.target.value;te(St),localStorage.setItem("library-sort-field",St)},className:"bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green",children:[i.jsx("option",{value:"name",children:t("common.name")}),i.jsx("option",{value:"date",children:t("common.date")}),i.jsx("option",{value:"size",children:t("fileManager.size")}),i.jsx("option",{value:"type",children:t("common.type")}),i.jsx("option",{value:"prints",children:t("fileManager.prints")})]}),i.jsx("button",{onClick:()=>he(qe=>{const St=qe==="asc"?"desc":"asc";return localStorage.setItem("library-sort-direction",St),St}),className:"p-1.5 rounded bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors",title:t(oe==="asc"?"fileManager.ascending":"fileManager.descending"),children:oe==="asc"?i.jsx(Ohe,{className:"w-4 h-4 text-white"}):i.jsx(Mhe,{className:"w-4 h-4 text-white"})})]}),(W||ie!=="all"||$)&&i.jsx("span",{className:"text-sm text-bambu-gray hidden sm:inline",children:t("fileManager.resultsCount",{showing:xe.length,total:ne.length})})]}),xe.length>0&&i.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-4 p-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-[52px] z-10 lg:static",children:[p.length===xe.length&&p.length>0?i.jsxs(Ie,{variant:"secondary",size:"sm",onClick:bt,children:[i.jsx(rl,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("fileManager.deselectAll")})]}):i.jsxs(Ie,{variant:"secondary",size:"sm",onClick:nt,children:[i.jsx(Ys,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("fileManager.selectAll")})]}),p.length>0&&i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"text-sm text-bambu-gray ml-2",children:t("fileManager.selected",{count:p.length})}),i.jsx("div",{className:"hidden sm:block flex-1"}),i.jsxs("div",{className:"w-full sm:w-auto flex flex-wrap items-center gap-2 mt-2 sm:mt-0",children:[Ce.length===1&&i.jsxs(Ie,{variant:"primary",size:"sm",onClick:()=>Z(Ce[0]),disabled:!r("printers:control"),title:r("printers:control")?void 0:t("fileManager.noPermissionPrint"),children:[i.jsx(Ks,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.print")})]}),Ce.length===1&&i.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>ee(Ce[0]),disabled:!r("queue:create"),title:r("queue:create")?void 0:t("fileManager.noPermissionAddToQueue"),children:[i.jsx(Zn,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("fileManager.schedulePrint")})]}),i.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>k(!0),disabled:!a("library:update_own","library:update_all"),title:a("library:update_own","library:update_all")?void 0:t("fileManager.noPermissionMoveFiles"),children:[i.jsx(Age,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.move")})]}),i.jsxs(Ie,{variant:"danger",size:"sm",onClick:()=>{p.length===1?A({type:"file",id:p[0]}):A({type:"bulk",id:0,count:p.length})},disabled:!a("library:delete_own","library:delete_all"),title:a("library:delete_own","library:delete_all")?void 0:t("fileManager.noPermissionDeleteFiles"),children:[i.jsx(an,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.delete")})]}),i.jsxs(Ie,{variant:"secondary",size:"sm",onClick:bt,children:[i.jsx(qt,{className:"w-4 h-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.clear")})]})]})]})]}),ut?i.jsx("div",{className:"flex-1 flex items-center justify-center",children:i.jsxs("div",{className:"flex flex-col items-center gap-3",children:[i.jsx(ft,{className:"w-8 h-8 animate-spin text-bambu-green"}),i.jsx("p",{className:"text-sm text-bambu-gray",children:t("fileManager.loadingFiles")})]})}):ne?.length===0?i.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center",children:[i.jsx("div",{className:"p-4 bg-bambu-dark rounded-2xl mb-4",children:i.jsx(pf,{className:"w-12 h-12 text-bambu-gray/50"})}),i.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:t(u!==null?"fileManager.folderIsEmpty":"fileManager.noFilesYet")}),i.jsx("p",{className:"text-bambu-gray text-center max-w-md mb-6",children:t(u!==null?"fileManager.folderEmptyDescription":"fileManager.noFilesDescription")}),i.jsxs(Ie,{onClick:()=>N(!0),disabled:!r("library:upload"),title:r("library:upload")?void 0:t("fileManager.noPermissionUpload"),children:[i.jsx(ir,{className:"w-4 h-4 mr-2"}),t("fileManager.uploadFiles")]})]}):xe.length===0?i.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center",children:[i.jsx("div",{className:"p-4 bg-bambu-dark rounded-2xl mb-4",children:i.jsx(Fr,{className:"w-12 h-12 text-bambu-gray/50"})}),i.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:t("fileManager.noMatchingFiles")}),i.jsx("p",{className:"text-bambu-gray text-center max-w-md mb-6",children:t("fileManager.noMatchingFilesDescription")}),i.jsx(Ie,{variant:"secondary",onClick:()=>{B(""),O("all")},children:t("fileManager.clearFilters")})]}):se==="grid"?i.jsx("div",{className:"flex-1 lg:overflow-y-auto",children:i.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-4",children:xe.map(qe=>i.jsx(Ott,{file:qe,isSelected:p.includes(qe.id),isMobile:fe,t,onSelect:$e,onDelete:St=>A({type:"file",id:St}),onDownload:mt,onAddToQueue:St=>{const Ut=ne?.find(Gt=>Gt.id===St);Ut&&ee(Ut)},onPrint:G,onPreview3d:K,onRename:St=>X({type:"file",id:St.id,name:St.filename}),onGenerateThumbnail:St=>Ve.mutate(St.id),thumbnailVersion:ce[qe.id],hasPermission:r,canModify:s,authEnabled:o},qe.id))})}):i.jsx("div",{className:"flex-1 lg:overflow-y-auto",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-hidden",children:[i.jsxs("div",{className:`hidden sm:grid ${o?"grid-cols-[auto_1fr_120px_100px_100px_100px_80px]":"grid-cols-[auto_1fr_100px_100px_100px_80px]"} gap-4 px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary text-xs text-bambu-gray font-medium`,children:[i.jsx("div",{className:"w-6"}),i.jsx("div",{children:t("common.name")}),o&&i.jsx("div",{children:t("fileManager.uploadedBy",{defaultValue:"Uploaded By"})}),i.jsx("div",{children:t("common.type")}),i.jsx("div",{children:t("fileManager.size")}),i.jsx("div",{children:t("fileManager.prints")}),i.jsx("div",{})]}),xe.map(qe=>i.jsxs("div",{className:`grid ${o?"grid-cols-[auto_1fr_120px_100px_100px_100px_80px]":"grid-cols-[auto_1fr_100px_100px_100px_80px]"} gap-4 px-4 py-3 items-center border-b border-bambu-dark-tertiary last:border-b-0 cursor-pointer hover:bg-bambu-dark/50 transition-colors ${p.includes(qe.id)?"bg-bambu-green/10":""}`,onClick:()=>$e(qe.id),children:[i.jsx("div",{className:`w-5 h-5 rounded border-2 flex items-center justify-center ${p.includes(qe.id)?"bg-bambu-green border-bambu-green":"border-bambu-gray/50"}`,children:p.includes(qe.id)&&i.jsx("div",{className:"w-2 h-2 bg-white rounded-sm"})}),i.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[i.jsxs("div",{className:"relative group/thumb",children:[i.jsx("div",{className:"w-10 h-10 rounded bg-bambu-dark flex-shrink-0 overflow-hidden",children:qe.thumbnail_path?i.jsx("img",{src:`${be.getLibraryFileThumbnailUrl(qe.id)}${ce[qe.id]?`?v=${ce[qe.id]}`:""}`,alt:"",className:"w-full h-full object-cover"}):i.jsx("div",{className:"w-full h-full flex items-center justify-center",children:i.jsx(pf,{className:"w-5 h-5 text-bambu-gray/50"})})}),qe.thumbnail_path&&i.jsx("div",{className:"absolute left-0 top-full mt-2 z-50 hidden group-hover/thumb:block",children:i.jsx("div",{className:"w-48 h-48 rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary shadow-xl overflow-hidden",children:i.jsx("img",{src:`${be.getLibraryFileThumbnailUrl(qe.id)}${ce[qe.id]?`?v=${ce[qe.id]}`:""}`,alt:qe.filename,className:"w-full h-full object-contain"})})})]}),i.jsx("div",{className:"min-w-0",children:i.jsx("div",{className:"text-sm text-white truncate",children:qe.print_name||qe.filename})})]}),o&&i.jsx("div",{className:"text-sm text-bambu-gray flex items-center gap-1",children:qe.created_by_username?i.jsxs(i.Fragment,{children:[i.jsx(Gu,{className:"w-3 h-3"}),i.jsx("span",{className:"truncate",children:qe.created_by_username})]}):"-"}),i.jsx("div",{children:i.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded font-medium ${qe.file_type==="3mf"?"bg-bambu-green/20 text-bambu-green":qe.file_type==="gcode"?"bg-blue-500/20 text-blue-400":qe.file_type==="stl"?"bg-purple-500/20 text-purple-400":"bg-bambu-gray/20 text-bambu-gray"}`,children:qe.file_type.toUpperCase()})}),i.jsx("div",{className:"text-sm text-bambu-gray",children:vo(qe.file_size)}),i.jsx("div",{className:"text-sm text-bambu-gray",children:qe.print_count>0?`${qe.print_count}x`:"-"}),i.jsxs("div",{className:"flex items-center gap-1",onClick:St=>St.stopPropagation(),children:[TL(qe.filename)&&i.jsxs(i.Fragment,{children:[i.jsx("button",{onClick:()=>r("printers:control")&&G(qe),className:`p-1.5 rounded transition-colors ${r("printers:control")?"hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green":"text-bambu-gray/50 cursor-not-allowed"}`,title:r("printers:control")?t("common.print"):t("fileManager.noPermissionPrint"),disabled:!r("printers:control"),children:i.jsx(_r,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>{r("queue:create")&&ee(qe)},className:`p-1.5 rounded transition-colors ${r("queue:create")?"hover:bg-bambu-dark text-bambu-gray hover:text-white":"text-bambu-gray/50 cursor-not-allowed"}`,title:r("queue:create")?t("fileManager.schedulePrint"):t("fileManager.noPermissionAddToQueue"),disabled:!r("queue:create"),children:i.jsx(Zn,{className:"w-4 h-4"})})]}),(qe.file_type==="3mf"||qe.file_type==="gcode"||qe.file_type==="stl")&&i.jsx("button",{onClick:()=>r("library:read")&&K(qe),className:`p-1.5 rounded transition-colors ${r("library:read")?"hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green":"text-bambu-gray/50 cursor-not-allowed"}`,title:r("library:read")?"3D Preview":"You do not have permission to preview files",disabled:!r("library:read"),children:i.jsx(aa,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>r("library:read")&&mt(qe.id),className:`p-1.5 rounded transition-colors ${r("library:read")?"hover:bg-bambu-dark text-bambu-gray hover:text-white":"text-bambu-gray/50 cursor-not-allowed"}`,title:r("library:read")?t("common.download"):t("fileManager.noPermissionDownload"),disabled:!r("library:read"),children:i.jsx(fi,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>s("library","update",qe.created_by_id)&&X({type:"file",id:qe.id,name:qe.filename}),className:`p-1.5 rounded transition-colors ${s("library","update",qe.created_by_id)?"hover:bg-bambu-dark text-bambu-gray hover:text-white":"text-bambu-gray/50 cursor-not-allowed"}`,title:s("library","update",qe.created_by_id)?t("common.rename"):t("fileManager.noPermissionRenameFile"),disabled:!s("library","update",qe.created_by_id),children:i.jsx(Xi,{className:"w-4 h-4"})}),qe.file_type==="stl"&&i.jsx("button",{onClick:()=>s("library","update",qe.created_by_id)&&Ve.mutate(qe.id),className:`p-1.5 rounded transition-colors ${s("library","update",qe.created_by_id)?"hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green":"text-bambu-gray/50 cursor-not-allowed"}`,title:s("library","update",qe.created_by_id)?t("fileManager.generateThumbnail"):t("fileManager.noPermissionGenerateThumbnail"),disabled:Ve.isPending||!s("library","update",qe.created_by_id),children:i.jsx(qu,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>s("library","delete",qe.created_by_id)&&A({type:"file",id:qe.id}),className:`p-1.5 rounded transition-colors ${s("library","delete",qe.created_by_id)?"hover:bg-bambu-dark text-bambu-gray hover:text-red-400":"text-bambu-gray/50 cursor-not-allowed"}`,title:s("library","delete",qe.created_by_id)?t("common.delete"):t("fileManager.noPermissionDeleteFile"),disabled:!s("library","delete",qe.created_by_id),children:i.jsx(an,{className:"w-4 h-4"})})]})]},qe.id))]})})]})]}),y&&i.jsx(jtt,{parentId:u,onClose:()=>v(!1),onSave:qe=>He.mutate(qe),isLoading:He.isPending,t}),b&&i.jsx(Dtt,{onClose:()=>g(!1),onSave:qe=>Oe.mutate(qe),isLoading:Oe.isPending,t}),_&&L&&i.jsx(Rtt,{folders:L,selectedFiles:p,currentFolderId:u,onClose:()=>k(!1),onMove:qe=>We.mutate({fileIds:p,folderId:qe}),isLoading:We.isPending,t}),C&&i.jsx(lie,{folderId:u,onClose:()=>N(!1),onUploadComplete:vt}),P&&i.jsx(Ltt,{folder:P,onClose:()=>T(null),onLink:qe=>ye.mutate({id:P.id,data:qe}),isLoading:ye.isPending,t}),j&&i.jsx(kn,{title:j.type==="folder"?t("fileManager.deleteFolder"):j.type==="bulk"?t("fileManager.deleteFilesCount",{count:j.count}):t("fileManager.deleteFile"),message:j.type==="folder"?t("fileManager.deleteFolderConfirm"):j.type==="bulk"?t("fileManager.deleteFilesConfirm",{count:j.count}):t("fileManager.deleteFileConfirm"),confirmText:t("common.delete"),variant:"danger",isLoading:Yt,loadingText:t("fileManager.deleting"),onConfirm:Ht,onCancel:()=>A(null)}),F&&i.jsx(xd,{mode:"reprint",libraryFileId:F.id,archiveName:F.print_name||F.filename,onClose:()=>G(null),onSuccess:()=>{G(null),e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["archives"]})}}),z&&i.jsx(xd,{mode:"reprint",libraryFileId:z.id,archiveName:z.print_name||z.filename,onClose:()=>Z(null),onSuccess:()=>{Z(null),f([]),e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["archives"]})}}),I&&i.jsx(xd,{mode:"add-to-queue",libraryFileId:I.id,archiveName:I.print_name||I.filename,onClose:()=>ee(null),onSuccess:()=>{ee(null),f([]),e.invalidateQueries({queryKey:["library-files"]}),e.invalidateQueries({queryKey:["queue"]}),e.invalidateQueries({queryKey:["archives"]})}}),pe&&i.jsx(zI,{libraryFileId:pe.id,title:pe.print_name||pe.filename,fileType:pe.file_type,onClose:()=>K(null)}),ae&&i.jsx(Ftt,{type:ae.type,currentName:ae.name,onClose:()=>X(null),onSave:qe=>{ae.type==="file"?Ke.mutate({id:ae.id,filename:qe}):Pe.mutate({id:ae.id,name:qe})},isLoading:Ke.isPending||Pe.isPending,t})]})}const JD=5,ztt=2e3,Utt=3e4,Btt=5e3;function Htt(){const{t}=jt(),e=cn(),{showToast:n}=pn(),{hasPermission:r}=Ar(),{printerId:a}=gw(),s=parseInt(a||"0",10),[o,l]=w.useState("stream"),[c,d]=w.useState(!1),[u,m]=w.useState(!1),[p,f]=w.useState(!0),[y,v]=w.useState(Date.now()),[b,g]=w.useState(!1),[_,k]=w.useState(!1),[C,N]=w.useState(0),[P,T]=w.useState(!1),[j,A]=w.useState(0),[F,G]=w.useState(1),[z,Z]=w.useState({x:0,y:0}),[I,ee]=w.useState(!1),[ae,X]=w.useState({x:0,y:0}),[ce,ue]=w.useState(null),[pe,K]=w.useState(null),se=w.useRef(null),de=w.useRef(null),ge=w.useRef(null),Te=w.useRef(null),V=w.useRef(null),{data:J}=et({queryKey:["printer",s],queryFn:()=>be.getPrinter(s),enabled:s>0}),{data:D}=et({queryKey:["printerStatus",s],queryFn:()=>be.getPrinterStatus(s),refetchInterval:3e4,enabled:s>0}),E=pt({mutationFn:_e=>be.setChamberLight(s,_e),onMutate:async _e=>{await e.cancelQueries({queryKey:["printerStatus",s]});const Ae=e.getQueryData(["printerStatus",s]);return e.setQueryData(["printerStatus",s],Be=>({...Be,chamber_light:_e})),{previousStatus:Ae}},onSuccess:(_e,Ae)=>{n(`Chamber light ${Ae?"on":"off"}`)},onError:(_e,Ae,Be)=>{Be?.previousStatus&&e.setQueryData(["printerStatus",s],Be.previousStatus),n(_e.message||t("printers.toast.failedToControlChamberLight"),"error")}}),U=(D?.state==="RUNNING"||D?.state==="PAUSE")&&(D?.printable_objects_count??0)>=2;w.useEffect(()=>(J&&(document.title=`${J.name} - Camera`),()=>{document.title="Bambuddy"}),[J]);const W=w.useRef(!1);w.useEffect(()=>{const _e=`/api/v1/printers/${s}/camera/stop`;W.current=!1;const Ae=()=>{if(s>0&&!W.current){W.current=!0;const We={},ye=Wu();ye&&(We.Authorization=`Bearer ${ye}`),fetch(_e,{method:"POST",keepalive:!0,headers:We}).catch(()=>{})}},Be=()=>{Ae()};window.addEventListener("beforeunload",Be);const De=se.current;return()=>{window.removeEventListener("beforeunload",Be),De&&(De.src=""),Ae()}},[s]),w.useEffect(()=>{if(p&&!b){const Ae=setTimeout(()=>{f(!1)},o==="stream"?3e3:2e4);return()=>clearTimeout(Ae)}},[o,p,y,b]),w.useEffect(()=>{const _e=()=>{const Ae=!!document.fullscreenElement;k(Ae),G(1),Z({x:0,y:0}),o==="stream"&&!b&&(se.current&&(se.current.src=""),setTimeout(()=>{f(!0),v(Date.now())},200))};return document.addEventListener("fullscreenchange",_e),()=>document.removeEventListener("fullscreenchange",_e)},[o,b]),w.useEffect(()=>{let _e;const Ae=()=>{clearTimeout(_e),_e=setTimeout(()=>{localStorage.setItem("cameraWindowState",JSON.stringify({width:window.outerWidth,height:window.outerHeight,left:window.screenX,top:window.screenY}))},500)};return window.addEventListener("resize",Ae),()=>{clearTimeout(_e),window.removeEventListener("resize",Ae)}},[]),w.useEffect(()=>()=>{ge.current&&clearTimeout(ge.current),Te.current&&clearInterval(Te.current),V.current&&clearInterval(V.current)},[]);const B=w.useCallback(()=>{if(C>=JD){T(!1),m(!0);return}const _e=Math.min(ztt*Math.pow(2,C),Utt);T(!0),A(Math.ceil(_e/1e3)),Te.current=setInterval(()=>{A(Ae=>Ae<=1?(Te.current&&clearInterval(Te.current),0):Ae-1)},1e3),ge.current=setTimeout(()=>{N(Ae=>Ae+1),T(!1),f(!0),m(!1),se.current&&(se.current.src=""),v(Date.now())},_e)},[C]);w.useEffect(()=>{if(o!=="stream"||p||P||b){V.current&&(clearInterval(V.current),V.current=null);return}return V.current=setInterval(async()=>{try{const _e=await be.getCameraStatus(s);(_e.stalled||!_e.active&&!u)&&(console.log(`Stream issue detected: stalled=${_e.stalled}, active=${_e.active}, reconnecting...`),V.current&&(clearInterval(V.current),V.current=null),f(!1),B())}catch{}},Btt),()=>{V.current&&(clearInterval(V.current),V.current=null)}},[o,p,u,P,b,s,B]);const ie=()=>{f(!1),o==="stream"&&C{if(f(!1),m(!1),N(0),T(!1),ge.current&&clearTimeout(ge.current),Te.current&&clearInterval(Te.current),se.current&&!localStorage.getItem("cameraWindowState")){const _e=se.current,Ae=_e.naturalWidth,Be=_e.naturalHeight;if(Ae>0&&Be>0){const ye=window.outerWidth-window.innerWidth,Ke=window.outerHeight-window.innerHeight,Pe=Ae+16+ye,Ye=Be+45+16+Ke;try{window.resizeTo(Pe,Ye)}catch{}}}},$=()=>{if(s>0){const _e={},Ae=Wu();Ae&&(_e.Authorization=`Bearer ${Ae}`),fetch(`/api/v1/printers/${s}/camera/stop`,{method:"POST",headers:_e}).catch(()=>{})}},Y=_e=>{o===_e||b||(g(!0),f(!0),m(!1),N(0),T(!1),G(1),Z({x:0,y:0}),ge.current&&clearTimeout(ge.current),Te.current&&clearInterval(Te.current),se.current&&(se.current.src=""),o==="stream"&&$(),setTimeout(()=>{l(_e),v(Date.now()),g(!1)},100))},q=()=>{b||(g(!0),f(!0),m(!1),N(0),T(!1),ge.current&&clearTimeout(ge.current),Te.current&&clearInterval(Te.current),se.current&&(se.current.src=""),o==="stream"&&$(),setTimeout(()=>{v(Date.now()),g(!1)},100))},te=()=>{de.current&&(document.fullscreenElement?document.exitFullscreen():de.current.requestFullscreen())},oe=()=>{G(_e=>Math.min(_e+.5,4))},he=()=>{G(_e=>{const Ae=Math.max(_e-.5,1);return Ae===1&&Z({x:0,y:0}),Ae})},fe=_e=>{_e.preventDefault(),_e.deltaY<0?oe():he()},re=_e=>{F>1&&(_e.preventDefault(),ee(!0),X({x:_e.clientX-z.x,y:_e.clientY-z.y}))},L=w.useCallback(()=>{if(!de.current)return{x:300,y:200};const _e=de.current.getBoundingClientRect(),Ae=_e.width*(F-1)/2,Be=_e.height*(F-1)/2;return{x:Math.max(50,Ae),y:Math.max(50,Be)}},[F]),R=_e=>{if(I&&F>1){const Ae=_e.clientX-ae.x,Be=_e.clientY-ae.y,De=L();Z({x:Math.max(-De.x,Math.min(De.x,Ae)),y:Math.max(-De.y,Math.min(De.y,Be))})}},ne=()=>{ee(!1)},ve=_e=>{if(_e.length<2)return 0;const Ae=_e[0].clientX-_e[1].clientX,Be=_e[0].clientY-_e[1].clientY;return Math.sqrt(Ae*Ae+Be*Be)},we=_e=>_e.length<2?{x:_e[0].clientX,y:_e[0].clientY}:{x:(_e[0].clientX+_e[1].clientX)/2,y:(_e[0].clientY+_e[1].clientY)/2},me=_e=>{_e.touches.length===2?(_e.preventDefault(),ue(ve(_e.touches)),K(we(_e.touches))):_e.touches.length===1&&F>1&&(_e.preventDefault(),ee(!0),X({x:_e.touches[0].clientX-z.x,y:_e.touches[0].clientY-z.y}))},Me=_e=>{if(_e.touches.length===2&&ce!==null){_e.preventDefault();const Ae=ve(_e.touches),Be=Ae/ce;G(We=>{const ye=Math.max(1,Math.min(4,We*Be));return ye===1&&Z({x:0,y:0}),ye}),ue(Ae);const De=we(_e.touches);if(pe){const We=L();Z(ye=>({x:Math.max(-We.x,Math.min(We.x,ye.x+(De.x-pe.x))),y:Math.max(-We.y,Math.min(We.y,ye.y+(De.y-pe.y)))}))}K(De)}else if(_e.touches.length===1&&I&&F>1){_e.preventDefault();const Ae=_e.touches[0].clientX-ae.x,Be=_e.touches[0].clientY-ae.y,De=L();Z({x:Math.max(-De.x,Math.min(De.x,Ae)),y:Math.max(-De.y,Math.min(De.y,Be))})}},xe=_e=>{_e.touches.length<2&&(ue(null),K(null)),_e.touches.length===0&&ee(!1)},je=()=>{G(1),Z({x:0,y:0})},He=b?"":o==="stream"?`/api/v1/printers/${s}/camera/stream?fps=15&t=${y}`:`/api/v1/printers/${s}/camera/snapshot?t=${y}`,Oe=p||b||P;return s?i.jsxs("div",{ref:de,className:"min-h-screen bg-black flex flex-col",children:[i.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary",children:[i.jsxs("h1",{className:"text-sm font-medium text-white flex items-center gap-2",children:[i.jsx(hx,{className:"w-4 h-4"}),J?.name||`Printer ${s}`]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"flex bg-bambu-dark rounded p-0.5",children:[i.jsx("button",{onClick:()=>Y("stream"),disabled:Oe,className:`px-3 py-1 text-xs rounded transition-colors ${o==="stream"?"bg-bambu-green text-white":"text-bambu-gray hover:text-white disabled:opacity-50"}`,children:t("camera.live")}),i.jsx("button",{onClick:()=>Y("snapshot"),disabled:Oe,className:`px-3 py-1 text-xs rounded transition-colors ${o==="snapshot"?"bg-bambu-green text-white":"text-bambu-gray hover:text-white disabled:opacity-50"}`,children:t("camera.snapshot")})]}),i.jsx("button",{onClick:()=>E.mutate(!D?.chamber_light),disabled:!D?.connected||E.isPending||!r("printers:control"),className:`p-1.5 rounded disabled:opacity-50 ${D?.chamber_light?"bg-yellow-500/20 hover:bg-yellow-500/30":"hover:bg-bambu-dark-tertiary"}`,title:r("printers:control")?t("camera.chamberLight"):t("printers.permission.noControl"),children:i.jsx(jO,{on:D?.chamber_light??!1,className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>d(!0),disabled:!U||!r("printers:control"),className:`p-1.5 rounded disabled:opacity-50 ${U&&r("printers:control")?"hover:bg-bambu-dark-tertiary":""}`,title:r("printers:control")?t(U?"printers.skipObjects.tooltip":"printers.skipObjects.onlyWhilePrinting"):t("printers.permission.noControl"),children:i.jsx(NT,{className:"w-4 h-4 text-bambu-gray"})}),i.jsx("button",{onClick:q,disabled:Oe,className:"p-1.5 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50",title:t(o==="stream"?"camera.restartStream":"camera.refreshSnapshot"),children:i.jsx(vr,{className:`w-4 h-4 text-bambu-gray ${Oe?"animate-spin":""}`})}),i.jsx("button",{onClick:te,className:"p-1.5 hover:bg-bambu-dark-tertiary rounded",title:t(_?"camera.exitFullscreen":"camera.fullscreen"),children:_?i.jsx(nQ,{className:"w-4 h-4 text-bambu-gray"}):i.jsx(gge,{className:"w-4 h-4 text-bambu-gray"})})]})]}),i.jsx("div",{className:"flex-1 flex items-center justify-center p-2 overflow-hidden",onWheel:fe,onMouseMove:R,onMouseUp:ne,onMouseLeave:ne,onTouchStart:me,onTouchMove:Me,onTouchEnd:xe,style:{touchAction:"none"},children:i.jsxs("div",{className:"relative w-full h-full flex items-center justify-center",children:[(p||b)&&!P&&i.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50 z-10",children:i.jsxs("div",{className:"text-center",children:[i.jsx(vr,{className:"w-8 h-8 text-bambu-gray animate-spin mx-auto mb-2"}),i.jsx("p",{className:"text-sm text-bambu-gray",children:t(o==="stream"?"camera.connectingToCamera":"camera.capturingSnapshot")})]})}),P&&i.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/80 z-10",children:i.jsxs("div",{className:"text-center p-4",children:[i.jsx(Bh,{className:"w-10 h-10 text-orange-400 mx-auto mb-3"}),i.jsx("p",{className:"text-white mb-2",children:t("camera.connectionLost")}),i.jsx("p",{className:"text-sm text-bambu-gray mb-3",children:t("camera.reconnecting",{countdown:j,attempt:C+1,max:JD})}),i.jsx("button",{onClick:q,className:"px-4 py-2 bg-bambu-green text-white text-sm rounded hover:bg-bambu-green/80 transition-colors",children:t("camera.reconnectNow")})]})}),u&&!P&&i.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black z-10",children:i.jsxs("div",{className:"text-center p-4",children:[i.jsx(jn,{className:"w-12 h-12 text-orange-400 mx-auto mb-3"}),i.jsx("p",{className:"text-white mb-2",children:t("camera.cameraUnavailable")}),i.jsx("p",{className:"text-xs text-bambu-gray mb-4 max-w-md",children:t("camera.cameraUnavailableDesc")}),i.jsx("button",{onClick:q,className:"px-4 py-2 bg-bambu-green text-white rounded hover:bg-bambu-green/80 transition-colors",children:t("camera.retry")})]})}),i.jsx("img",{ref:se,src:He,alt:t("camera.cameraStream"),className:"max-w-full max-h-full object-contain select-none",style:{transform:`scale(${F}) translate(${z.x/F}px, ${z.y/F}px) rotate(${J?.camera_rotation||0}deg)`,...J?.camera_rotation===90||J?.camera_rotation===270?{maxWidth:"100vh",maxHeight:"100vw"}:{},cursor:F>1?I?"grabbing":"grab":"default"},onError:He?ie:void 0,onLoad:He?O:void 0,onMouseDown:re,draggable:!1},y),i.jsxs("div",{className:"absolute bottom-4 left-4 flex items-center gap-1.5 bg-black/60 rounded-lg px-2 py-1.5",children:[i.jsx("button",{onClick:he,disabled:F<=1,className:"p-1.5 hover:bg-white/10 rounded disabled:opacity-30",title:t("camera.zoomOut"),children:i.jsx(nO,{className:"w-4 h-4 text-white"})}),i.jsxs("button",{onClick:je,className:"px-2 py-1 text-sm text-white hover:bg-white/10 rounded min-w-[48px]",title:t("camera.resetZoom"),children:[Math.round(F*100),"%"]}),i.jsx("button",{onClick:oe,disabled:F>=4,className:"p-1.5 hover:bg-white/10 rounded disabled:opacity-30",title:t("camera.zoomIn"),children:i.jsx(tO,{className:"w-4 h-4 text-white"})})]})]})}),i.jsx(DO,{printerId:s,isOpen:c,onClose:()=>d(!1)})]}):i.jsx("div",{className:"min-h-screen bg-black flex items-center justify-center",children:i.jsx("p",{className:"text-white",children:t("camera.invalidPrinterId")})})}function $tt(t){const e=t.get("show")?.split(",")||["progress","layers","eta","filename","status"],n=parseInt(t.get("fps")||"15",10),r=Math.min(Math.max(isNaN(n)?15:n,1),30),a=t.get("camera"),s=a!=="false"&&a!=="0";return{size:t.get("size")||"medium",fps:r,showCamera:s,showProgress:e.includes("progress"),showLayers:e.includes("layers"),showEta:e.includes("eta"),showFilename:e.includes("filename"),showStatus:e.includes("status"),showPrinter:e.includes("printer")}}function qtt(t,e){if(t.stg_cur_name)return t.stg_cur_name;switch(t.state){case"RUNNING":return e("streamOverlay.status.printing");case"PAUSE":return e("streamOverlay.status.paused");case"FINISH":return e("streamOverlay.status.finished");case"FAILED":return e("streamOverlay.status.failed");case"IDLE":return e("streamOverlay.status.idle");default:return t.state||e("streamOverlay.status.unknown")}}function Vtt(t){switch(t){case"small":return{container:"p-3",text:"text-sm",textLarge:"text-lg",progressHeight:"h-2",icon:"w-3 h-3",gap:"gap-2",logoHeight:"h-12"};case"large":return{container:"p-6",text:"text-xl",textLarge:"text-3xl",progressHeight:"h-4",icon:"w-6 h-6",gap:"gap-4",logoHeight:"h-24"};default:return{container:"p-4",text:"text-base",textLarge:"text-xl",progressHeight:"h-3",icon:"w-4 h-4",gap:"gap-3",logoHeight:"h-16"}}}function Gtt(){const{printerId:t}=gw(),[e]=zL(),{t:n}=jt(),r=cn(),a=parseInt(t||"0",10),[s,o]=w.useState(Date.now()),l=w.useMemo(()=>$tt(e),[e]),c=Vtt(l.size),{data:d}=et({queryKey:["printer",a],queryFn:()=>be.getPrinter(a),enabled:a>0}),{data:u}=et({queryKey:["printerStatus",a],queryFn:()=>be.getPrinterStatus(a),enabled:a>0,refetchInterval:2e3}),{data:m}=et({queryKey:["settings"],queryFn:be.getSettings}),p=m?.time_format||"system";w.useEffect(()=>{if(!a)return;const _=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/api/v1/ws`,k=new WebSocket(_);return k.onmessage=C=>{try{const N=JSON.parse(C.data);N.type==="printer_status"&&N.printer_id===a&&r.setQueryData(["printerStatus",a],N.status)}catch{}},k.onerror=()=>{},()=>{k.close()}},[a,r]),w.useEffect(()=>(document.title=d?`${d.name} - ${n("streamOverlay.title")}`:n("streamOverlay.title"),()=>{document.title="Bambuddy"}),[d,n]);const f=()=>{setTimeout(()=>{o(Date.now())},3e3)};if(!a)return i.jsx("div",{className:"min-h-screen bg-black flex items-center justify-center",children:i.jsx("p",{className:"text-white",children:n("streamOverlay.invalidPrinterId")})});if(!u)return i.jsx("div",{className:"min-h-screen bg-black flex items-center justify-center",children:i.jsx("p",{className:"text-gray-400",children:n("common.loading")})});const y=u.state==="RUNNING"||u.state==="PAUSE",v=u.progress||0,b=`/api/v1/printers/${a}/camera/stream?fps=${l.fps}&t=${s}`;return i.jsxs("div",{className:"min-h-screen bg-black relative overflow-hidden",children:[l.showCamera&&i.jsx("img",{src:b,alt:n("streamOverlay.cameraStream"),className:"absolute inset-0 w-full h-full object-contain",style:d?.camera_rotation?{transform:`rotate(${d.camera_rotation}deg)`}:void 0,onError:f},s),i.jsx("a",{href:"https://github.com/maziggy/bambuddy",target:"_blank",rel:"noopener noreferrer",className:"absolute top-4 right-4 z-10",children:i.jsx("img",{src:"/img/bambuddy_logo_dark_transparent.png",alt:"Bambuddy",className:`${c.logoHeight} object-contain drop-shadow-lg hover:scale-105 transition-transform`})}),i.jsx("div",{className:"absolute bottom-0 left-0 right-0 z-10 bg-gradient-to-t from-black/80 via-black/60 to-transparent",children:i.jsxs("div",{className:`${c.container}`,children:[l.showPrinter&&d&&i.jsxs("div",{className:`flex items-center ${c.gap} mb-2`,children:[i.jsx(_r,{className:`${c.icon} text-white/70`}),i.jsx("span",{className:`${c.text} text-white font-medium`,children:d.name})]}),l.showFilename&&u.current_print&&i.jsx("div",{className:`${c.textLarge} text-white font-semibold mb-2 truncate drop-shadow-md`,children:u.current_print.replace(/\.gcode\.3mf$|\.3mf$|\.gcode$/i,"")}),l.showStatus&&i.jsx("div",{className:`${c.text} text-white/70 mb-2`,children:qtt(u,n)}),l.showProgress&&y&&i.jsxs("div",{className:"mb-3",children:[i.jsxs("div",{className:`flex items-center justify-between mb-1 ${c.text}`,children:[i.jsx("span",{className:"text-white/70",children:n("streamOverlay.progress")}),i.jsxs("span",{className:"text-white font-bold",children:[Math.round(v),"%"]})]}),i.jsx("div",{className:`w-full bg-white/20 rounded-full ${c.progressHeight}`,children:i.jsx("div",{className:`bg-bambu-green ${c.progressHeight} rounded-full transition-all duration-500`,style:{width:`${v}%`}})})]}),y&&(l.showLayers||l.showEta)&&i.jsxs("div",{className:`flex items-center ${c.gap} flex-wrap`,children:[l.showLayers&&u.layer_num!=null&&u.total_layers!=null&&u.total_layers>0&&i.jsxs("div",{className:`flex items-center ${c.gap} text-white/70`,children:[i.jsx(Ki,{className:c.icon}),i.jsxs("span",{className:c.text,children:[i.jsx("span",{className:"text-white",children:u.layer_num}),i.jsx("span",{className:"mx-1",children:"/"}),i.jsx("span",{children:u.total_layers})]})]}),l.showEta&&u.remaining_time!=null&&u.remaining_time>0&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:`flex items-center ${c.gap} text-white/70`,children:[i.jsx(Nu,{className:c.icon}),i.jsx("span",{className:`${c.text} text-white`,children:Bs(u.remaining_time*60)})]}),i.jsxs("div",{className:`flex items-center ${c.gap} text-white/70`,children:[i.jsx(Zn,{className:c.icon}),i.jsxs("span",{className:`${c.text} text-white`,children:[n("streamOverlay.eta")," ",rO(u.remaining_time,p,n)]})]})]})]}),!y&&i.jsx("div",{className:`${c.text} text-white/70 py-2`,children:u.connected?n("streamOverlay.printerIdle"):n("streamOverlay.printerOffline")})]})})]})}function Wtt(){const{t}=jt(),{id:e}=gw(),{mode:n}=ag(),{data:r,isLoading:a,error:s}=et({queryKey:["external-link",e],queryFn:()=>be.getExternalLink(Number(e)),enabled:!!e});return a?i.jsx("div",{className:"flex items-center justify-center h-full",children:i.jsx(ft,{className:"w-8 h-8 text-bambu-green animate-spin"})}):s||!r?i.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4 text-bambu-gray",children:[i.jsx(jn,{className:"w-12 h-12"}),i.jsx("p",{children:t("common.linkNotFound")})]}):i.jsx("iframe",{src:r.url,className:"h-full w-full border-0",style:{colorScheme:n},title:r.name,sandbox:"allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox"})}function zY(){const{id:t}=gw(),e=ol(),n=cn(),{t:r}=jt(),{showToast:a}=pn(),s=!!t,[o,l]=w.useState(""),[c,d]=w.useState(""),[u,m]=w.useState([]),[p,f]=w.useState(""),[y,v]=w.useState(!1),{data:b,isLoading:g}=et({queryKey:["group",t],queryFn:()=>be.getGroup(Number(t)),enabled:s}),{data:_,isLoading:k}=et({queryKey:["permissions"],queryFn:()=>be.getPermissions()});s&&b&&!y&&(l(b.name),d(b.description||""),m(b.permissions),v(!0));const C=pt({mutationFn:X=>be.createGroup(X),onSuccess:()=>{n.invalidateQueries({queryKey:["groups"]}),a(r("groups.toast.created")),e("/settings?tab=users")},onError:X=>{a(X.message,"error")}}),N=pt({mutationFn:X=>be.updateGroup(Number(t),X),onSuccess:()=>{n.invalidateQueries({queryKey:["groups"]}),a(r("groups.toast.updated")),e("/settings?tab=users")},onError:X=>{a(X.message,"error")}}),P=C.isPending||N.isPending,T=()=>{if(!o.trim()){a(r("groups.toast.enterGroupName"),"error");return}s?N.mutate({name:o!==b?.name?o:void 0,description:c,permissions:u}):C.mutate({name:o,description:c||void 0,permissions:u})},j=X=>{m(ce=>ce.includes(X)?ce.filter(ue=>ue!==X):[...ce,X])},A=(X,ce)=>{const ue=X.permissions.map(pe=>pe.value);m(pe=>{const K=pe.filter(se=>!ue.includes(se));return ce?[...K,...ue]:K})},F=X=>X.permissions.every(ce=>u.includes(ce.value)),G=X=>{const ce=X.permissions.filter(ue=>u.includes(ue.value)).length;return ce>0&&ce{_&&m(_.all_permissions)},Z=()=>{m([])},I=p.toLowerCase(),ee=w.useMemo(()=>_?I?_.categories.map(X=>({...X,permissions:X.permissions.filter(ce=>ce.label.toLowerCase().includes(I))})).filter(X=>X.permissions.length>0):_.categories:[],[_,I]),ae=_?.all_permissions.length??0;return g||k?i.jsx("div",{className:"flex items-center justify-center py-16",children:i.jsx(ft,{className:"w-8 h-8 text-bambu-green animate-spin"})}):i.jsxs("div",{className:"space-y-6 max-w-5xl mx-auto",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("button",{onClick:()=>e("/settings?tab=users"),className:"p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors",children:i.jsx(GX,{className:"w-5 h-5"})}),i.jsx("h1",{className:"text-xl font-bold text-white",children:r(s?"groups.editor.title":"groups.editor.createTitle")})]}),s&&b?.is_system&&i.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 rounded-lg bg-yellow-500/10 border border-yellow-500/20 text-yellow-400 text-sm",children:[i.jsx(jn,{className:"w-4 h-4 shrink-0"}),r("groups.form.systemGroupWarning")]}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:r("groups.form.groupName")}),i.jsx("input",{type:"text",value:o,onChange:X=>l(X.target.value),disabled:s&&b?.is_system,className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors disabled:opacity-50",placeholder:r("groups.form.groupNamePlaceholder")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:r("groups.form.description")}),i.jsx("input",{type:"text",value:c,onChange:X=>d(X.target.value),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:r("groups.form.descriptionPlaceholder")})]})]}),i.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs("span",{className:"text-sm text-bambu-gray",children:[r("groups.editor.permissionsSelected",{count:u.length})," / ",ae]}),i.jsx(Ie,{size:"sm",variant:"ghost",onClick:z,children:r("groups.editor.selectAll")}),i.jsx(Ie,{size:"sm",variant:"ghost",onClick:Z,children:r("groups.editor.clearAll")})]}),i.jsxs("div",{className:"relative",children:[i.jsx(Fr,{className:"w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray"}),i.jsx("input",{type:"text",value:p,onChange:X=>f(X.target.value),placeholder:r("groups.editor.search"),className:"pl-9 pr-4 py-2 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors w-64"})]})]}),ee.length===0?i.jsx("div",{className:"text-center py-12 text-bambu-gray",children:r("groups.editor.noResults")}):i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:ee.map(X=>{const ce=_.categories.find(de=>de.name===X.name),ue=ce.permissions.filter(de=>u.includes(de.value)).length,pe=ce.permissions.length,K=F(ce),se=G(ce);return i.jsxs(At,{children:[i.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between px-4 py-3 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary rounded-t-xl",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsxs("button",{type:"button",onClick:()=>A(ce,!K),className:`w-5 h-5 rounded border flex items-center justify-center transition-colors shrink-0 ${K?"bg-bambu-green border-bambu-green":se?"bg-bambu-green/50 border-bambu-green":"border-bambu-gray hover:border-white"}`,children:[K&&i.jsx(Zr,{className:"w-3 h-3 text-white"}),se&&!K&&i.jsx(Uk,{className:"w-3 h-3 text-white"})]}),i.jsx(A3,{className:"w-4 h-4 text-bambu-gray shrink-0"}),i.jsx("span",{className:"text-white font-medium text-sm",children:X.name})]}),i.jsxs("span",{className:"text-xs text-bambu-gray tabular-nums",children:[ue,"/",pe]})]}),i.jsx("div",{className:"p-3 space-y-1",children:X.permissions.map(de=>i.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-secondary cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:u.includes(de.value),onChange:()=>j(de.value),className:"w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark-secondary"}),i.jsx("span",{className:"text-sm text-bambu-gray",children:de.label})]},de.value))})]},X.name)})}),i.jsx("div",{className:"h-16"}),i.jsxs("div",{className:"fixed bottom-0 left-0 right-0 z-20 px-6 py-3 bg-bambu-dark-secondary border-t border-bambu-dark-tertiary flex items-center justify-center gap-3",children:[i.jsx(Ie,{variant:"secondary",onClick:()=>e("/settings?tab=users"),children:r("common.cancel")}),i.jsx(Ie,{onClick:T,disabled:P||!o.trim(),children:P?i.jsxs(i.Fragment,{children:[i.jsx(ft,{className:"w-4 h-4 animate-spin"}),r("common.saving")]}):i.jsxs(i.Fragment,{children:[i.jsx(as,{className:"w-4 h-4"}),r("common.save")]})})]})]})}const AL={material:"",subtype:"",brand:"",color_name:"",rgba:"808080FF",label_weight:1e3,core_weight:250,core_weight_catalog_id:null,weight_used:0,slicer_filament:"",note:"",cost_per_kg:null};function tle(t,e=!1){const n={};return e?(t.material||(n.material="Material is required"),{isValid:Object.keys(n).length===0,errors:n}):(t.slicer_filament||(n.slicer_filament="Slicer preset is required"),t.material||(n.material="Material is required"),t.brand||(n.brand="Brand is required"),t.subtype||(n.subtype="Subtype is required"),{isValid:Object.keys(n).length===0,errors:n})}const nle=["PLA","PETG","ABS","TPU","ASA","PC","PA","PVA","HIPS","PA-CF","PETG-CF","PLA-CF"],Ktt=["Bambu","PolyLite","PolyTerra","eSUN","Overture","Fiberon","SUNLU","Inland","Hatchbox","Generic"],x0=["Basic","Matte","Silk","Tough","HF","High Flow","Engineering","Galaxy","Glow","Marble","Metal","Rainbow","Sparkle","Wood","Translucent","Transparent","Clear","Lite","Pro","Plus","Max","Super","Ultra","Flex","Soft","Hard","Strong","Impact","Heat Resistant","UV Resistant","ESD","Conductive","Magnetic","Gradient","Dual Color","Tri Color","Multicolor"],rle=[{name:"Black",hex:"000000"},{name:"White",hex:"FFFFFF"},{name:"Gray",hex:"808080"},{name:"Red",hex:"FF0000"},{name:"Orange",hex:"FFA500"},{name:"Yellow",hex:"FFFF00"},{name:"Green",hex:"00AE42"},{name:"Blue",hex:"0066FF"},{name:"Purple",hex:"8B00FF"},{name:"Pink",hex:"FF69B4"},{name:"Brown",hex:"8B4513"},{name:"Silver",hex:"C0C0C0"}],Ytt=[{name:"Dark Red",hex:"8B0000"},{name:"Crimson",hex:"DC143C"},{name:"Coral",hex:"FF7F50"},{name:"Salmon",hex:"FA8072"},{name:"Dark Orange",hex:"FF8C00"},{name:"Peach",hex:"FFDAB9"},{name:"Gold",hex:"FFD700"},{name:"Khaki",hex:"F0E68C"},{name:"Lemon",hex:"FFF44F"},{name:"Lime",hex:"32CD32"},{name:"Forest Green",hex:"228B22"},{name:"Olive",hex:"808000"},{name:"Mint",hex:"98FF98"},{name:"Teal",hex:"008080"},{name:"Navy",hex:"000080"},{name:"Sky Blue",hex:"87CEEB"},{name:"Royal Blue",hex:"4169E1"},{name:"Cyan",hex:"00FFFF"},{name:"Turquoise",hex:"40E0D0"},{name:"Violet",hex:"EE82EE"},{name:"Magenta",hex:"FF00FF"},{name:"Indigo",hex:"4B0082"},{name:"Lavender",hex:"E6E6FA"},{name:"Plum",hex:"DDA0DD"},{name:"Hot Pink",hex:"FF69B4"},{name:"Rose",hex:"FF007F"},{name:"Blush",hex:"FFB6C1"},{name:"Chocolate",hex:"D2691E"},{name:"Tan",hex:"D2B48C"},{name:"Beige",hex:"F5F5DC"},{name:"Maroon",hex:"800000"},{name:"Dark Gray",hex:"404040"},{name:"Light Gray",hex:"D3D3D3"},{name:"Charcoal",hex:"36454F"},{name:"Ivory",hex:"FFFFF0"},{name:"Bambu Green",hex:"00AE42"},{name:"Jade White",hex:"E8E8E8"},{name:"Titan Gray",hex:"5A5A5A"}],UY=[...rle,...Ytt],ile="bambuddy-recent-colors",Xtt=8,Qtt=[{code:"GFL00",name:"Bambu PLA Basic",displayName:"Bambu PLA Basic",isCustom:!1,allCodes:["GFL00"]},{code:"GFL01",name:"Bambu PLA Matte",displayName:"Bambu PLA Matte",isCustom:!1,allCodes:["GFL01"]},{code:"GFL05",name:"Generic PLA",displayName:"Generic PLA",isCustom:!1,allCodes:["GFL05"]},{code:"GFG00",name:"Bambu PETG Basic",displayName:"Bambu PETG Basic",isCustom:!1,allCodes:["GFG00"]},{code:"GFG05",name:"Generic PETG",displayName:"Generic PETG",isCustom:!1,allCodes:["GFG05"]},{code:"GFB00",name:"Bambu ABS Basic",displayName:"Bambu ABS Basic",isCustom:!1,allCodes:["GFB00"]},{code:"GFB05",name:"Generic ABS",displayName:"Generic ABS",isCustom:!1,allCodes:["GFB05"]},{code:"GFA00",name:"Bambu ASA Basic",displayName:"Bambu ASA Basic",isCustom:!1,allCodes:["GFA00"]},{code:"GFU00",name:"Bambu TPU 95A",displayName:"Bambu TPU 95A",isCustom:!1,allCodes:["GFU00"]},{code:"GFU05",name:"Generic TPU",displayName:"Generic TPU",isCustom:!1,allCodes:["GFU05"]},{code:"GFC00",name:"Bambu PC Basic",displayName:"Bambu PC Basic",isCustom:!1,allCodes:["GFC00"]},{code:"GFN00",name:"Bambu PA Basic",displayName:"Bambu PA Basic",isCustom:!1,allCodes:["GFN00"]},{code:"GFN05",name:"Generic PA",displayName:"Generic PA",isCustom:!1,allCodes:["GFN05"]},{code:"GFS00",name:"Bambu PLA-CF",displayName:"Bambu PLA-CF",isCustom:!1,allCodes:["GFS00"]},{code:"GFT00",name:"Bambu PETG-CF",displayName:"Bambu PETG-CF",isCustom:!1,allCodes:["GFT00"]},{code:"GFNC0",name:"Bambu PA-CF",displayName:"Bambu PA-CF",isCustom:!1,allCodes:["GFNC0"]},{code:"GFV00",name:"Bambu PVA",displayName:"Bambu PVA",isCustom:!1,allCodes:["GFV00"]}];function Qh(t){let e=t.replace(/@.*$/,"").trim();e=e.replace(/\(Custom\)/i,"").trim(),e=e.replace(/^[#*]+\s*/,"").trim();const n=["PLA-CF","PETG-CF","ABS-GF","ASA-CF","PA-CF","PAHT-CF","PA6-CF","PA6-GF","PPA-CF","PPA-GF","PET-CF","PPS-CF","PC-CF","PC-ABS","ABS-GF","PCTG","PETG","PLA","ABS","ASA","PC","PA","TPU","PVA","HIPS","BVOH","PPS","PEEK","PEI"];let r="",a=-1;for(const c of n){const d=e.toUpperCase().indexOf(c.toUpperCase());if(d!==-1){r=c,a=d;break}}let s="";a>0&&(s=e.substring(0,a).trim(),s=s.replace(/[-_\s]+$/,""));let o="";a!==-1&&r&&(o=e.substring(a+r.length).trim(),o=o.replace(/^[-_\s]+/,""));let l="";for(const c of x0)if(o.toLowerCase().includes(c.toLowerCase())){l=c;break}if(!l&&s)for(const c of x0){const d=new RegExp(`\\s+${c}$`,"i");if(d.test(s)){l=c,s=s.replace(d,"").trim();break}}return{brand:s,material:r,variant:l}}function ale(t,e){const n=new Set(Ktt);for(const r of t){const{brand:a}=Qh(r.name);a&&a.length>1&&n.add(a)}if(e)for(const r of e)if(r.filament_vendor&&r.filament_vendor.length>1)n.add(r.filament_vendor);else{const{brand:a}=Qh(r.name);a&&a.length>1&&n.add(a)}return Array.from(n).sort((r,a)=>r.localeCompare(a))}function Ztt(t){const e=t.filter(r=>r.preset_type==="filament");if(e.length===0)return[];const n=new Map;for(const r of e){const a=r.name.replace(/@.*$/,"").trim(),s=n.get(a);if(s)s.allCodes.push(String(r.id));else{const o=r.filament_type||String(r.id);n.set(a,{code:o,name:a,displayName:a,isCustom:!1,allCodes:[o]})}}return Array.from(n.values()).sort((r,a)=>r.displayName.localeCompare(a.displayName))}function sle(t,e,n){if(t.length>0){const r=[],a=new Map;for(const s of t)if(s.is_custom){const o=s.name.toUpperCase();(e.size===0||Array.from(e).some(c=>o.includes(c))||!o.includes("@"))&&r.push({code:s.setting_id,name:s.name,displayName:`${s.name} (Custom)`,isCustom:!0,allCodes:[s.setting_id]})}else{const o=s.name.replace(/@.*$/,"").trim(),l=a.get(o);l?l.allCodes.push(s.setting_id):a.set(o,{code:s.setting_id,name:o,displayName:o,isCustom:!1,allCodes:[s.setting_id]})}return[...r,...Array.from(a.values())].sort((s,o)=>s.displayName.localeCompare(o.displayName))}if(n&&n.length>0){const r=Ztt(n);if(r.length>0)return r}return Qtt}function ole(t,e){if(!t)return;let n=e.find(r=>r.code===t);if(n||(n=e.find(r=>r.allCodes.includes(t))),!n){const r=t.toLowerCase();n=e.find(a=>a.code.toLowerCase()===r||a.allCodes.some(s=>s.toLowerCase()===r))}return n}function lle(){try{const t=localStorage.getItem(ile);if(t)return JSON.parse(t)}catch{}return[]}function cle(t,e){const n=e.filter(a=>a.hex.toUpperCase()!==t.hex.toUpperCase()),r=[t,...n].slice(0,Xtt);try{localStorage.setItem(ile,JSON.stringify(r))}catch{}return r}function e3(t,e){if(!e.material)return!1;const r=(t.name||"").replace(/^High Flow[_\s]+/i,"").replace(/^Standard[_\s]+/i,"").replace(/^HF[_\s]+/i,"").replace(/^S[_\s]+/i,"").trim(),a=Qh(r);return!(!(a.material.toUpperCase()===e.material.toUpperCase())||e.brand&&!(a.brand.toLowerCase().includes(e.brand.toLowerCase())||e.brand.toLowerCase().includes(a.brand.toLowerCase()))||e.subtype&&!(a.variant.toLowerCase().includes(e.subtype.toLowerCase())||e.subtype.toLowerCase().includes(a.variant.toLowerCase())||r.toLowerCase().includes(e.subtype.toLowerCase())))}function dle({formData:t,updateField:e,cloudAuthenticated:n,loadingCloudPresets:r,presetInputValue:a,setPresetInputValue:s,selectedPresetOption:o,filamentOptions:l,availableBrands:c,availableMaterials:d,quickAdd:u,quantity:m,onQuantityChange:p,errors:f}){const{t:y}=jt(),[v,b]=w.useState(!1),[g,_]=w.useState(!1),[k,C]=w.useState(!1),[N,P]=w.useState(!1),[T,j]=w.useState(""),[A,F]=w.useState(""),[G,z]=w.useState(""),[Z,I]=w.useState(String(t.label_weight)),[ee,ae]=w.useState(!1),X=w.useRef(null),ce=w.useRef(null),ue=w.useRef(null),pe=w.useRef(null);w.useEffect(()=>{const V=J=>{X.current&&!X.current.contains(J.target)&&b(!1),pe.current&&!pe.current.contains(J.target)&&P(!1),ce.current&&!ce.current.contains(J.target)&&_(!1),ue.current&&!ue.current.contains(J.target)&&C(!1)};return document.addEventListener("mousedown",V),()=>document.removeEventListener("mousedown",V)},[]);const K=w.useMemo(()=>{if(!a)return l;const V=a.toLowerCase();return l.filter(J=>J.displayName.toLowerCase().includes(V)||J.code.toLowerCase().includes(V))},[l,a]),se=w.useMemo(()=>{if(!T)return c;const V=T.toLowerCase();return c.filter(D=>D.toLowerCase().includes(V)).sort((D,E)=>{const U=D.toLowerCase()===V,W=E.toLowerCase()===V;return U&&!W?-1:!U&&W?1:D.localeCompare(E)})},[c,T]),de=w.useMemo(()=>{if(!A)return x0;const V=A.toLowerCase();return x0.filter(J=>J.toLowerCase().includes(V))},[A]),ge=w.useMemo(()=>{if(!G)return d;const V=G.toLowerCase();return d.filter(D=>D.toLowerCase().includes(V)).sort((D,E)=>{const U=D.toLowerCase()===V,W=E.toLowerCase()===V;return U&&!W?-1:!U&&W?1:D.localeCompare(E)})},[G,d]);w.useEffect(()=>{ee||I(String(t.label_weight))},[t.label_weight,ee]);const Te=V=>{e("slicer_filament",V.code),s(V.displayName),b(!1);const J=Qh(V.name);J.material&&e("material",J.material),J.brand&&e("brand",J.brand),J.variant&&e("subtype",J.variant)};return i.jsxs("div",{className:"space-y-4",children:[!u&&i.jsx("div",{className:"flex items-center gap-2 text-xs text-bambu-gray",children:r?i.jsxs(i.Fragment,{children:[i.jsx(ft,{className:"w-3 h-3 animate-spin"})," ",y("inventory.loadingPresets")]}):n?i.jsxs(i.Fragment,{children:[i.jsx(Vx,{className:"w-3 h-3 text-bambu-green"})," ",y("inventory.cloudConnected")]}):i.jsxs(i.Fragment,{children:[i.jsx(Tpe,{className:"w-3 h-3"})," ",y("inventory.cloudNotConnected")]})}),!u&&i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:[y("inventory.slicerPreset")," *"]}),i.jsxs("div",{className:"relative",ref:X,children:[i.jsx(Fr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none"}),i.jsx("input",{type:"text",className:"w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green",placeholder:y("inventory.searchPresets"),value:a,onChange:V=>{s(V.target.value),b(!0)},onFocus:()=>{b(!0),s("")}}),v&&i.jsx("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto",children:K.length===0?i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:y("inventory.noPresetsFound")}):K.map(V=>i.jsx("button",{type:"button",className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary truncate ${o?.code===V.code?"bg-bambu-green/10 text-bambu-green":"text-white"}`,onClick:()=>Te(V),children:V.displayName},V.code))})]}),o&&i.jsxs("div",{className:"mt-1 text-xs text-bambu-gray",children:[y("inventory.selectedPreset"),": ",i.jsx("span",{className:"font-mono text-bambu-green",children:o.code})]}),f?.slicer_filament&&i.jsx("p",{className:"mt-1 text-xs text-red-400",children:f.slicer_filament})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:[y("inventory.material")," *"]}),i.jsxs("div",{className:"relative",ref:pe,children:[i.jsx("input",{type:"text",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green",placeholder:y("inventory.selectMaterial"),value:N?G:t.material,onChange:V=>{z(V.target.value),P(!0)},onFocus:()=>{P(!0),z("")}}),i.jsx(zn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none"}),N&&i.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto",children:[ge.length===0?i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:y("inventory.noResults")}):ge.map(V=>i.jsx("button",{type:"button",className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${t.material===V?"bg-bambu-green/10 text-bambu-green":"text-white"}`,onClick:()=>{e("material",V),P(!1),z("")},children:V},V)),G&&!ge.includes(G)&&i.jsx("button",{type:"button",className:"w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary",onClick:()=>{e("material",G),P(!1),z("")},children:y("inventory.useCustomMaterial",{material:G})})]})]}),f?.material&&i.jsx("p",{className:"mt-1 text-xs text-red-400",children:f.material})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:[y("inventory.brand"),!u&&" *"]}),i.jsxs("div",{className:"relative",ref:ce,children:[i.jsx("input",{type:"text",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green",placeholder:y("inventory.searchBrand"),value:g?T:t.brand,onChange:V=>{j(V.target.value),_(!0)},onFocus:()=>{_(!0),j("")}}),i.jsx(zn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none"}),g&&i.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto",children:[se.length===0?i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:y("inventory.noResults")}):se.map(V=>i.jsx("button",{type:"button",className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${t.brand===V?"bg-bambu-green/10 text-bambu-green":"text-white"}`,onClick:()=>{e("brand",V),_(!1),j("")},children:V},V)),T&&!se.includes(T)&&i.jsx("button",{type:"button",className:"w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary",onClick:()=>{e("brand",T),_(!1),j("")},children:y("inventory.useCustomBrand",{brand:T})})]})]}),f?.brand&&i.jsx("p",{className:"mt-1 text-xs text-red-400",children:f.brand})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:[y("inventory.subtype"),!u&&" *"]}),i.jsxs("div",{className:"relative",ref:ue,children:[i.jsx("input",{type:"text",value:k?A:t.subtype,onChange:V=>{F(V.target.value),C(!0)},onFocus:()=>{C(!0),F("")},placeholder:"Basic, Matte, Silk...",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green"}),i.jsx(zn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none"}),k&&i.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto",children:[de.length===0?i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:y("inventory.noResults")}):de.map(V=>i.jsx("button",{type:"button",className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${t.subtype===V?"bg-bambu-green/10 text-bambu-green":"text-white"}`,onClick:()=>{e("subtype",V),C(!1),F("")},children:V},V)),A&&!x0.some(V=>V.toLowerCase()===A.toLowerCase().trim())&&i.jsx("button",{type:"button",className:"w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary",onClick:()=>{e("subtype",A),C(!1),F("")},children:y("inventory.useCustomBrand",{brand:A})})]})]}),f?.subtype&&i.jsx("p",{className:"mt-1 text-xs text-red-400",children:f.subtype})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:y("inventory.labelWeight")}),i.jsxs("div",{className:"relative",children:[i.jsx("input",{type:"number",className:"w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green",value:Z,min:0,onFocus:()=>ae(!0),onChange:V=>I(V.target.value),onBlur:()=>{ae(!1);const V=Z.trim(),J=Number(V);if(!V||!Number.isFinite(J)||J<0){I(String(t.label_weight));return}const D=Math.round(J);e("label_weight",D),I(String(D))}}),i.jsx("span",{className:"absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray",children:"g"})]})]}),u&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:y("inventory.quantity")}),i.jsx("input",{type:"number",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green",value:m,min:1,max:100,onChange:V=>{const J=Math.max(1,Math.min(100,parseInt(V.target.value)||1));p(J)}})]})]})}function ule({formData:t,updateField:e,recentColors:n,onColorUsed:r,catalogColors:a}){const{t:s}=jt(),[o,l]=w.useState(!1),[c,d]=w.useState(""),u=t.rgba.replace("#","").substring(0,6),m=g=>u.toUpperCase()===g.toUpperCase(),p=(g,_)=>{e("rgba",g.toUpperCase()+"FF"),e("color_name",_),r({name:_,hex:g})},f=w.useMemo(()=>{if(a.length===0)return[];const g=t.brand?.trim(),_=t.material?.toLowerCase().trim(),k=t.subtype?.toLowerCase().trim();if(!g&&!_)return[];const C=g?g.toLowerCase().split(/[\s\-_]+/).filter(T=>T.length>=2):[],N=T=>{if(C.length===0)return!0;const j=T.toLowerCase();return C.some(A=>j.includes(A))};if(g&&!_){const T=a.filter(j=>N(j.manufacturer));if(T.length>0)return T.map(j=>({name:j.color_name,hex:j.hex_color.replace("#","").substring(0,6),manufacturer:j.manufacturer,material:typeof j.material=="string"?j.material:void 0}))}const P=_&&k?`${_} ${k}`:"";if(P){const T=a.filter(A=>N(A.manufacturer)&&A.material?.toLowerCase()===P);if(T.length>0)return T.map(A=>({name:A.color_name,hex:A.hex_color.replace("#","").substring(0,6),manufacturer:A.manufacturer,material:typeof A.material=="string"?A.material:void 0}));const j=P.replace(/\+$/,"");if(j!==P){const A=a.filter(F=>N(F.manufacturer)&&F.material?.toLowerCase()===j);if(A.length>0)return A.map(F=>({name:F.color_name,hex:F.hex_color.replace("#","").substring(0,6),manufacturer:F.manufacturer,material:typeof F.material=="string"?F.material:void 0}))}}if(_){const T=a.filter(j=>N(j.manufacturer)&&(!j.material||j.material.toLowerCase().startsWith(_)));if(T.length>0)return T.map(j=>({name:j.color_name,hex:j.hex_color.replace("#","").substring(0,6),manufacturer:j.manufacturer,material:typeof j.material=="string"?j.material:void 0}))}return[]},[a,t.brand,t.material,t.subtype]),y=w.useMemo(()=>{if(!c)return f;if(f.length===0)return[];const g=c.toLowerCase();return f.filter(k=>k.name.toLowerCase().includes(g)||(k.manufacturer?.toLowerCase().includes(g)??!1)||(k.material?.toLowerCase().includes(g)??!1))},[c,f]),v=f.length>0,b=w.useMemo(()=>c?UY.filter(g=>g.name.toLowerCase().includes(c.toLowerCase())):o?UY:rle,[c,o]);return i.jsxs("div",{className:"space-y-3",children:[i.jsx("div",{className:"h-10 rounded-lg border border-bambu-dark-tertiary",style:{backgroundColor:`#${u}`}}),n.length>0&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-bambu-gray shrink-0",children:[i.jsx(Zn,{className:"w-3 h-3"}),i.jsx("span",{children:s("inventory.recentColors")})]}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:n.map(g=>i.jsx("button",{type:"button",onClick:()=>p(g.hex,g.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 ${m(g.hex)?"border-bambu-green ring-1 ring-bambu-green/30 scale-110":"border-bambu-dark-tertiary"}`,style:{backgroundColor:`#${g.hex}`},title:g.name},g.hex))})]}),i.jsxs("div",{className:"relative",children:[i.jsx(Fr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none"}),i.jsx("input",{type:"text",className:"w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green",placeholder:s("inventory.searchColors"),value:c,onChange:g=>d(g.target.value)})]}),v?i.jsxs("div",{className:"space-y-1.5",children:[i.jsx("span",{className:"text-xs text-bambu-gray",children:c?s("inventory.searchResults"):`${t.brand}${t.material?` ${t.material}`:""}`}),i.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[y.map(g=>i.jsx("button",{type:"button",onClick:()=>p(g.hex,g.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 hover:z-20 relative group ${m(g.hex)?"border-bambu-green ring-1 ring-bambu-green/30 scale-110":"border-bambu-dark-tertiary"}`,style:{backgroundColor:`#${g.hex}`},title:g.manufacturer&&g.material?`${g.name} (${g.manufacturer} — ${g.material})`:g.manufacturer?`${g.name} (${g.manufacturer})`:g.name,children:i.jsx("span",{className:"absolute -bottom-7 left-1/2 -translate-x-1/2 px-2 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-xs whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-20 shadow-lg text-white",children:g.manufacturer&&g.material?`${g.name} (${g.manufacturer} — ${g.material})`:g.manufacturer?`${g.name} (${g.manufacturer})`:g.name})},`${g.hex}-${g.name}-${g.manufacturer??""}`)),y.length===0&&i.jsx("p",{className:"text-sm text-bambu-gray py-1",children:s("inventory.noColorsFound")})]})]}):i.jsxs("div",{className:"space-y-1.5",children:[i.jsxs("div",{className:"flex items-center justify-between text-xs text-bambu-gray",children:[i.jsx("span",{children:s(c?"inventory.searchResults":o?"inventory.allColors":"inventory.commonColors")}),!c&&i.jsx("button",{type:"button",onClick:()=>l(!o),className:"flex items-center gap-1 hover:text-white transition-colors",children:o?i.jsxs(i.Fragment,{children:[s("inventory.showLess")," ",i.jsx(Gl,{className:"w-3 h-3"})]}):i.jsxs(i.Fragment,{children:[s("inventory.showAll")," ",i.jsx(zn,{className:"w-3 h-3"})]})})]}),i.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[b.map(g=>i.jsx("button",{type:"button",onClick:()=>p(g.hex,g.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 hover:z-20 relative group ${m(g.hex)?"border-bambu-green ring-1 ring-bambu-green/30 scale-110":"border-bambu-dark-tertiary"}`,style:{backgroundColor:`#${g.hex}`},title:g.name,children:i.jsx("span",{className:"absolute -bottom-7 left-1/2 -translate-x-1/2 px-2 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-xs whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-20 shadow-lg text-white",children:g.name})},g.hex)),b.length===0&&i.jsx("p",{className:"text-sm text-bambu-gray py-1",children:s("inventory.noColorsFound")})]})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:s("inventory.colorName")}),i.jsx("input",{type:"text",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green",placeholder:s("inventory.colorNamePlaceholder"),value:t.color_name,onChange:g=>e("color_name",g.target.value)})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:s("inventory.hexColor")}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray",children:"#"}),i.jsx("input",{type:"text",className:"w-full pl-7 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono uppercase focus:outline-none focus:border-bambu-green",placeholder:"RRGGBB",value:u.toUpperCase(),onChange:g=>{const _=g.target.value.replace("#","").replace(/[^0-9A-Fa-f]/g,"");_.length<=8&&e("rgba",_.toUpperCase()+(_.length<=6?"FF":""))}})]}),i.jsx("input",{type:"color",className:"w-11 h-[38px] rounded-lg cursor-pointer border border-bambu-dark-tertiary shrink-0 bg-transparent",value:`#${u}`,onChange:g=>{const _=g.target.value.replace("#","").toUpperCase();e("rgba",_+"FF")},title:s("inventory.pickColor")})]})]})]})]})}function Jtt({catalog:t,value:e,onChange:n,catalogId:r,onCatalogIdChange:a}){const{t:s}=jt(),[o,l]=w.useState(!1),[c,d]=w.useState(""),u=w.useRef(null),m=w.useRef(null);w.useEffect(()=>{const v=b=>{u.current&&!u.current.contains(b.target)&&l(!1)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[]),w.useEffect(()=>{if(t.length===0)return;const v=t.filter(b=>b.weight===e);if(r){const b=t.find(g=>g.id===r);if(b&&b.weight===e)return}v.length===1?a(v[0].id):v.length===0&&r!==null&&a(null)},[e,t,r,a]);const p=w.useMemo(()=>{if(!c)return t;const v=c.toLowerCase();return t.filter(b=>b.name.toLowerCase().includes(v)||b.weight.toString().includes(v))},[t,c]),f=w.useMemo(()=>t.filter(v=>v.weight===e),[t,e]),y=w.useMemo(()=>{if(o)return c;if(r){const v=t.find(b=>b.id===r);if(v)return v.name}return f.length>0?f[0].name:""},[o,c,r,t,f]);return i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:i.jsxs("span",{className:"flex items-center gap-2",children:[i.jsx(ebe,{className:"w-3.5 h-3.5 text-bambu-gray"}),s("inventory.coreWeight")]})}),i.jsxs("div",{className:"flex gap-2 items-center",children:[i.jsxs("div",{className:"flex-1 min-w-0 relative",ref:u,children:[i.jsx("input",{ref:m,type:"text",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green",placeholder:s("inventory.searchSpoolWeight"),value:y,onFocus:()=>{l(!0),d("")},onChange:v=>{d(v.target.value),l(!0)}}),o&&i.jsx("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto",children:p.length===0?i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:s("inventory.noResults")}):p.map(v=>i.jsxs("button",{type:"button",className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex justify-between items-center ${(r?v.id===r:v.weight===e)?"bg-bambu-green/10 text-bambu-green":"text-white"}`,onClick:()=>{a(v.id),n(v.weight),l(!1),d("")},children:[i.jsx("span",{className:"truncate",children:v.name}),i.jsxs("span",{className:"font-mono text-xs text-bambu-gray ml-2 shrink-0",children:[v.weight,"g"]})]},v.id))})]}),i.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[i.jsx("input",{type:"number",className:"w-16 px-2 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm text-center font-mono focus:outline-none focus:border-bambu-green",value:e,min:0,max:2e3,onChange:v=>{const b=parseInt(v.target.value);!isNaN(b)&&b>=0&&n(b)}}),i.jsx("span",{className:"text-bambu-gray text-sm",children:"g"})]})]})]})}function mle({formData:t,updateField:e,spoolCatalog:n,currencySymbol:r}){const{t:a}=jt(),{showToast:s}=pn(),[o,l]=w.useState(""),[c,d]=w.useState(!1),[u,m]=w.useState(""),[p,f]=w.useState(!1),y=Math.max(0,t.label_weight-t.weight_used),v=t.core_weight+y;return w.useEffect(()=>{c||l(String(v))},[c,v]),w.useEffect(()=>{p||m(String(y))},[p,y]),i.jsxs("div",{className:"space-y-4",children:[i.jsx(Jtt,{catalog:n,value:t.core_weight,onChange:b=>e("core_weight",b),catalogId:t.core_weight_catalog_id,onCatalogIdChange:b=>e("core_weight_catalog_id",b)}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:a("inventory.currentWeight")}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsx("input",{type:"number",value:u,min:0,max:t.label_weight,onFocus:()=>f(!0),onChange:b=>{m(b.target.value)},onBlur:()=>{f(!1);const b=u.trim(),g=Number(b);if(!b||!Number.isFinite(g)||g<0||g>t.label_weight){m(String(y));return}const _=Math.round(g);e("weight_used",Math.max(0,t.label_weight-_)),m(String(_))},className:"w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green"}),i.jsx("span",{className:"absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray",children:"g"})]}),i.jsxs("span",{className:"text-xs text-bambu-gray shrink-0",children:["/ ",t.label_weight,"g"]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:a("inventory.measuredWeight")}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsx("input",{type:"number",value:o,min:0,onFocus:()=>d(!0),onChange:b=>{l(b.target.value)},onBlur:()=>{d(!1);const b=o.trim(),g=Number(b),_=t.core_weight,k=t.core_weight+t.label_weight;if(!b||!Number.isFinite(g)||g<_||g>k){s(a("inventory.measuredWeightError",{min:_,max:k}),"error"),l(String(v));return}const C=Math.round(g),N=Math.max(0,Math.min(t.label_weight,C-t.core_weight));e("weight_used",Math.max(0,t.label_weight-N)),l(String(C))},className:"w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green"}),i.jsx("span",{className:"absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray",children:"g"})]}),i.jsxs("span",{className:"text-xs text-bambu-gray shrink-0",children:["/ ",t.core_weight+t.label_weight,"g"]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:a("inventory.costPerKg","Cost per kg")}),i.jsx("div",{className:"flex items-center gap-2",children:i.jsxs("div",{className:"relative flex-1",children:[i.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none",children:r}),i.jsx("input",{type:"number",value:t.cost_per_kg??"",min:0,step:.01,placeholder:"0.00",onChange:b=>{const g=b.target.value===""?null:parseFloat(b.target.value);e("cost_per_kg",g)},style:{paddingLeft:`${Math.max(2,r.length*.6+1)}rem`},className:"w-full py-2 pr-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green"})]})})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:a("inventory.note")}),i.jsx("textarea",{className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green resize-none min-h-[80px]",placeholder:a("inventory.notePlaceholder"),value:t.note,onChange:b=>e("note",b.target.value)})]})]})}function hle({formData:t,printersWithCalibrations:e,selectedProfiles:n,setSelectedProfiles:r,expandedPrinters:a,setExpandedPrinters:s}){const{t:o}=jt(),l=p=>{s(f=>{const y=new Set(f);return y.has(p)?y.delete(p):y.add(p),y})},c=(p,f,y)=>{const v=`${p}:${f}:${y??"null"}`,b=`${p}:${y??"null"}`;r(g=>{const _=new Set(g);if(_.has(v))_.delete(v);else{for(const k of Array.from(_)){const C=k.split(":");`${C[0]}:${C[2]}`===b&&_.delete(k)}_.add(v)}return _})},d=()=>{const p=new Set;for(const{printer:f,calibrations:y}of e){if(!f.connected)continue;const v=y.filter(g=>e3(g,t)),b=new Map;for(const g of v){const _=`${g.extruder_id??"null"}`;b.has(_)||b.set(_,[]),b.get(_).push(g)}for(const[g,_]of b)if(_.length>0){const C=[..._].sort((N,P)=>P.k_value-N.k_value)[0];p.add(`${f.id}:${C.cali_idx}:${g}`)}}r(p)};if(!t.material)return i.jsx("div",{className:"p-6 bg-bambu-dark rounded-lg text-center",children:i.jsx("p",{className:"text-bambu-gray",children:o("inventory.selectMaterialFirst")})});if(e.length===0)return i.jsx("div",{className:"p-6 bg-bambu-dark rounded-lg text-center",children:i.jsx("p",{className:"text-bambu-gray",children:o("inventory.noPrintersConfigured")})});const u=e.reduce((p,{printer:f,calibrations:y})=>f.connected?p+y.filter(v=>e3(v,t)).length:p,0),m=(p,f)=>{const y=`${p.id}:${f.cali_idx}:${f.extruder_id??"null"}`,v=n.has(y);return i.jsxs("label",{className:`flex items-center gap-3 p-3 rounded-lg cursor-pointer transition-all border ${v?"bg-bambu-green/10 border-bambu-green/30":"bg-bambu-dark border-transparent hover:bg-bambu-dark/80"}`,children:[i.jsx("input",{type:"checkbox",checked:v,onChange:()=>c(String(p.id),f.cali_idx,f.extruder_id),className:"w-4 h-4 rounded border-bambu-dark-tertiary text-bambu-green focus:ring-bambu-green"}),i.jsx("div",{className:"flex-1 min-w-0",children:i.jsx("span",{className:`text-sm font-medium ${v?"text-bambu-green":"text-white"}`,children:f.name||f.filament_id})}),i.jsx("div",{className:"flex items-center gap-2 shrink-0",children:i.jsxs("span",{className:"text-xs font-mono px-2 py-0.5 rounded bg-bambu-dark text-bambu-gray",children:["K=",f.k_value.toFixed(3)]})})]},`${f.cali_idx}-${f.extruder_id}`)};return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("p",{className:"text-xs text-bambu-gray",children:[o("inventory.matchingFilter"),": ",t.brand||o("inventory.anyBrand")," / ",t.material," / ",t.subtype||o("inventory.anyVariant")]}),u>0&&i.jsxs("button",{type:"button",onClick:d,className:"flex items-center gap-1.5 px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white hover:border-bambu-green transition-colors",children:[i.jsx(fx,{className:"w-3.5 h-3.5"}),o("inventory.autoSelect")," (",u,")"]})]}),i.jsx("div",{className:"space-y-3",children:e.map(({printer:p,calibrations:f})=>{const y=a.has(String(p.id)),v=f.filter(C=>e3(C,t)),b=v.length,g=v.some(C=>C.extruder_id!==void 0&&C.extruder_id!==null&&C.extruder_id>0),_=v.filter(C=>C.extruder_id===1),k=v.filter(C=>C.extruder_id===0||C.extruder_id===void 0||C.extruder_id===null);return i.jsxs("div",{className:"border border-bambu-dark-tertiary rounded-lg overflow-hidden",children:[i.jsxs("button",{type:"button",onClick:()=>l(String(p.id)),className:"w-full px-4 py-3 flex items-center justify-between bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary transition-colors",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[y?i.jsx(zn,{className:"w-4 h-4 text-bambu-gray"}):i.jsx(fa,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("span",{className:"font-medium text-white",children:p.name}),b>0?i.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green",children:[b," ",o(b!==1?"inventory.matches":"inventory.match")]}):i.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray",children:o("inventory.noMatches")})]}),i.jsx("span",{className:`text-xs px-2 py-1 rounded-full ${p.connected?"bg-green-500/20 text-green-500":"bg-bambu-gray/20 text-bambu-gray"}`,children:p.connected?o("inventory.connected"):o("inventory.offline")})]}),y&&i.jsx("div",{className:"px-4 py-3 space-y-3 bg-bambu-dark border-t border-bambu-dark-tertiary",children:p.connected?b===0?i.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:o("inventory.noKProfilesMatch")}):g?i.jsxs(i.Fragment,{children:[_.length>0&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-xs font-medium text-bambu-gray uppercase tracking-wide",children:o("inventory.leftNozzle")}),i.jsx("div",{className:"space-y-2",children:_.map(C=>m(p,C))})]}),k.length>0&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-xs font-medium text-bambu-gray uppercase tracking-wide",children:o("inventory.rightNozzle")}),i.jsx("div",{className:"space-y-2",children:k.map(C=>m(p,C))})]})]}):i.jsx("div",{className:"space-y-2",children:v.map(C=>m(p,C))}):i.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:o("inventory.printerOffline")})})]},p.id)})}),n.size>0&&i.jsx("div",{className:"p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:i.jsxs("p",{className:"text-sm text-white",children:[i.jsx("span",{className:"font-semibold",children:n.size})," ",o("inventory.profilesSelected")]})})]})}function ent(t){const e=new Date(t);return e.toLocaleDateString("en-GB",{day:"2-digit",month:"2-digit",year:"2-digit"})+" "+e.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"})}const tnt={completed:"text-bambu-green",failed:"text-red-400",aborted:"text-yellow-400"};function nnt({spoolId:t}){const{t:e}=jt(),n=cn(),{showToast:r}=pn(),{data:a,isLoading:s}=et({queryKey:["spool-usage",t],queryFn:()=>be.getSpoolUsageHistory(t)}),o=pt({mutationFn:()=>be.clearSpoolUsageHistory(t),onSuccess:()=>{n.invalidateQueries({queryKey:["spool-usage",t]}),r(e("inventory.historyCleared"),"success")}});return s?i.jsx("div",{className:"flex justify-center py-4",children:i.jsx(ft,{className:"w-5 h-5 animate-spin text-bambu-green"})}):!a||a.length===0?i.jsxs("div",{className:"text-center py-4 text-bambu-gray text-sm",children:[i.jsx(Zn,{className:"w-5 h-5 mx-auto mb-2 opacity-50"}),e("inventory.noUsageHistory")]}):i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("h4",{className:"text-sm font-medium text-white",children:e("inventory.usageHistory")}),i.jsxs(Ie,{variant:"ghost",size:"sm",onClick:()=>o.mutate(),disabled:o.isPending,className:"text-xs text-bambu-gray hover:text-red-400",children:[i.jsx(an,{className:"w-3 h-3 mr-1"}),e("inventory.clearHistory")]})]}),i.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:a.map(l=>i.jsxs("div",{className:"flex items-center justify-between p-2 rounded bg-bambu-dark/50 text-xs",children:[i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("span",{className:"text-bambu-gray",children:ent(l.created_at)}),l.print_name&&i.jsx("span",{className:"text-white ml-2 truncate",title:l.print_name,children:l.print_name})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0 ml-2",children:[i.jsxs("span",{className:"text-white font-medium",children:[l.weight_used.toFixed(1),"g"]}),i.jsxs("span",{className:"text-bambu-gray",children:["(",l.percent_used,"%)"]}),i.jsx("span",{className:tnt[l.status]||"text-bambu-gray",children:l.status})]})]},l.id))})]})}function rnt({isOpen:t,onClose:e,spool:n,printersWithCalibrations:r=[],currencySymbol:a,onSpoolsCreated:s}){const{t:o}=jt(),l=cn(),{showToast:c}=pn(),d=!!n,[u,m]=w.useState(AL),[p,f]=w.useState({}),[y,v]=w.useState("filament"),[b,g]=w.useState(!1),[_,k]=w.useState(!1),[C,N]=w.useState(1),[P,T]=w.useState(!1),[j,A]=w.useState(!1),[F,G]=w.useState([]),[z,Z]=w.useState(""),[I,ee]=w.useState([]),[ae,X]=w.useState([]),[ce,ue]=w.useState([]),[pe,K]=w.useState([]),[se,de]=w.useState([]),[ge,Te]=w.useState(new Set),[V,J]=w.useState(new Set),D=r.length>0?r:se,E=w.useMemo(()=>ge.size,[ge]);w.useEffect(()=>{K(lle())},[]),w.useEffect(()=>{t&&((async()=>{A(!0);try{const Me=await be.getCloudStatus();if(T(Me.is_authenticated),Me.is_authenticated){const xe=await be.getFilamentPresets();G(xe)}}catch(Me){console.error("Failed to fetch cloud presets:",Me),T(!1)}finally{A(!1)}})(),be.getSpoolCatalog().then(ee).catch(console.error),be.getColorCatalog().then(ue).catch(console.error),be.getLocalPresets().then(Me=>X(Me.filament)).catch(console.error),r.length===0&&(async()=>{try{const Me=await be.getPrinters(),xe=await Promise.all(Me.map(He=>be.getPrinterStatus(He.id).catch(()=>null))),je=[];for(let He=0;He({cali_idx:We.slot_id,filament_id:We.filament_id,setting_id:We.setting_id||"",name:We.name,k_value:parseFloat(We.k_value)||0,n_coef:parseFloat(We.n_coef)||0,extruder_id:We.extruder_id,nozzle_diameter:We.nozzle_diameter}))}catch{}je.push({printer:{...Oe,connected:Ae},calibrations:Be})}de(je)}catch(Me){console.error("Failed to fetch printer calibrations:",Me)}})())},[t,r.length]);const U=w.useMemo(()=>sle(F,new Set,ae),[F,ae]),W=w.useMemo(()=>{const me=ale(F,ae),Me=ce.map(je=>je.manufacturer?.trim()).filter(je=>!!je),xe=new Set([...me,...Me]);return Array.from(xe).sort((je,He)=>je.localeCompare(He))},[F,ae,ce]),B=w.useMemo(()=>{const me=ce.map(xe=>xe.material?.trim()).filter(xe=>!!xe),Me=new Set([...nle,...me]);return Array.from(Me).sort((xe,je)=>xe.localeCompare(je))},[ce]),ie=w.useMemo(()=>{const me=[];for(const Me of ce){const xe=Me.manufacturer?.trim(),je=Me.material?.trim();xe&&je&&me.push({brand:xe,material:je})}for(const Me of F){const xe=Qh(Me.name);xe.brand&&xe.material&&me.push({brand:xe.brand,material:xe.material})}for(const Me of ae){const xe=Qh(Me.name),je=Me.filament_vendor?.trim()||xe.brand,He=xe.material;je&&He&&me.push({brand:je,material:He})}return me},[F,ce,ae]),O=w.useMemo(()=>{const me=new Map;for(const Me of ie){const xe=Me.brand.toLowerCase(),je=Me.material.toLowerCase();me.has(xe)||me.set(xe,new Set),me.get(xe).add(je)}return me},[ie]),$=w.useMemo(()=>{const me=new Map;for(const Me of ie){const xe=Me.brand.toLowerCase(),je=Me.material.toLowerCase();me.has(je)||me.set(je,new Set),me.get(je).add(xe)}return me},[ie]),Y=w.useMemo(()=>{if(!u.material)return W;const me=u.material.toLowerCase(),Me=$.get(me);return!Me||Me.size===0?W:W.filter(xe=>Me.has(xe.toLowerCase()))},[W,u.material,$]),q=w.useMemo(()=>{if(!u.brand)return B;const me=u.brand.toLowerCase(),Me=O.get(me);return!Me||Me.size===0?B:B.filter(xe=>Me.has(xe.toLowerCase()))},[B,u.brand,O]),te=w.useMemo(()=>ole(u.slicer_filament,U),[u.slicer_filament,U]);w.useEffect(()=>{if(t){if(n)if(m({material:n.material||"",subtype:n.subtype||"",brand:n.brand||"",color_name:n.color_name||"",rgba:n.rgba||"808080FF",label_weight:n.label_weight||1e3,core_weight:n.core_weight||250,core_weight_catalog_id:n.core_weight_catalog_id??null,weight_used:n.weight_used||0,slicer_filament:n.slicer_filament||"",note:n.note||"",cost_per_kg:n.cost_per_kg??null}),Z(n.slicer_filament_name||n.slicer_filament||""),n.k_profiles&&n.k_profiles.length>0){const me=new Set;for(const Me of n.k_profiles)Me.cali_idx!==null&&Me.cali_idx!==void 0&&me.add(`${Me.printer_id}:${Me.cali_idx}:${Me.extruder??"null"}`);Te(me)}else Te(new Set);else m(AL),Z(""),Te(new Set),k(!1),N(1);f({}),v("filament"),g(!1)}},[t,n]),w.useEffect(()=>{t&&D.length>0&&J(new Set(D.map(me=>String(me.printer.id))))},[t,D]);const oe=(me,Me)=>{m(xe=>({...xe,[me]:Me})),me==="weight_used"&&g(!0),p[me]&&f(xe=>({...xe,[me]:void 0}))},he=me=>{K(Me=>cle(me,Me))},fe=pt({mutationFn:me=>be.createSpool(me),onSuccess:async me=>{ge.size>0&&me?.id&&await ne(me.id),await l.invalidateQueries({queryKey:["inventory-spools"]}),s&&s([me]),c(o("inventory.spoolCreated"),"success"),e()},onError:me=>{c(me.message,"error")}}),re=pt({mutationFn:({data:me,qty:Me})=>be.bulkCreateSpools(me,Me),onSuccess:async me=>{if(ge.size>0)for(const Me of me)await ne(Me.id);await l.invalidateQueries({queryKey:["inventory-spools"]}),s&&s(me),c(o("inventory.spoolsCreated",{count:me.length}),"success"),e()},onError:me=>{c(me.message,"error")}}),L=pt({mutationFn:me=>be.updateSpool(n.id,me),onSuccess:async()=>{n?.id&&await ne(n.id),await l.invalidateQueries({queryKey:["inventory-spools"]}),c(o("inventory.spoolUpdated"),"success"),e()},onError:me=>{c(me.message,"error")}}),R=pt({mutationFn:()=>be.updateSpool(n.id,{tag_uid:null,tray_uuid:null,tag_type:null,data_origin:null}),onSuccess:async()=>{await l.invalidateQueries({queryKey:["inventory-spools"]}),c(o("inventory.tagDeleted","Tag removed"),"success"),e()},onError:me=>{c(me.message,"error")}}),ne=async me=>{if(ge.size===0){try{await be.saveSpoolKProfiles(me,[])}catch{}return}const Me=[];for(const xe of ge){const[je,He,Oe]=xe.split(":"),_e=parseInt(je),Ae=parseInt(He),Be=Oe==="null"?0:parseInt(Oe),De=D.find(We=>We.printer.id===_e);if(De){const We=De.calibrations.find(ye=>ye.cali_idx===Ae);We&&Me.push({printer_id:_e,extruder:Be,nozzle_diameter:We.nozzle_diameter||"0.4",k_value:We.k_value,name:We.name||null,cali_idx:We.cali_idx,setting_id:We.setting_id||null})}}if(Me.length>0)try{await be.saveSpoolKProfiles(me,Me)}catch(xe){console.error("Failed to save K-profiles:",xe)}};if(w.useEffect(()=>{if(!t)return;const me=Me=>{Me.key==="Escape"&&e()};return document.addEventListener("keydown",me),()=>document.removeEventListener("keydown",me)},[t,e]),!t)return null;const ve=()=>{const me=tle(u,_);if(!me.isValid){f(me.errors),(me.errors.slicer_filament||me.errors.material||me.errors.brand||me.errors.subtype)&&v("filament");return}const Me=te?.displayName||z||null,xe={material:u.material,subtype:u.subtype||null,brand:u.brand||null,color_name:u.color_name||null,rgba:u.rgba||null,label_weight:u.label_weight,core_weight:u.core_weight,core_weight_catalog_id:u.core_weight_catalog_id,slicer_filament:u.slicer_filament||null,slicer_filament_name:Me,nozzle_temp_min:null,nozzle_temp_max:null,note:u.note||null,cost_per_kg:u.cost_per_kg};(!d||b)&&(xe.weight_used=u.weight_used),d?L.mutate(xe):C>1?re.mutate({data:xe,qty:C}):fe.mutate(xe)},we=fe.isPending||re.isPending||L.isPending||R.isPending;return i.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[i.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),i.jsxs("div",{className:"relative w-full max-w-xl mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary flex-shrink-0",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:o(d?"inventory.editSpool":"inventory.addSpool")}),i.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:i.jsx(qt,{className:"w-5 h-5"})})]}),!d&&i.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-bambu-dark-tertiary flex-shrink-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Wl,{className:"w-4 h-4 text-amber-400"}),i.jsx("span",{className:"text-sm text-white",children:o("inventory.quickAdd")})]}),i.jsx("button",{type:"button",onClick:()=>{k(!_),_||v("filament")},className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${_?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,children:i.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${_?"translate-x-4":"translate-x-0.5"}`})})]}),i.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary flex-shrink-0",children:[i.jsxs("button",{onClick:()=>v("filament"),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${y==="filament"?"text-bambu-green border-b-2 border-bambu-green":"text-bambu-gray hover:text-white"}`,children:[i.jsx(Sw,{className:"w-4 h-4"}),o("inventory.filamentInfoTab")]}),!_&&i.jsxs("button",{onClick:()=>v("pa-profile"),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${y==="pa-profile"?"text-bambu-green border-b-2 border-bambu-green":"text-bambu-gray hover:text-white"}`,children:[i.jsx(Uhe,{className:"w-4 h-4"}),o("inventory.paProfileTab"),E>0&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green",children:E})]})]}),i.jsx("div",{className:"p-4 overflow-y-auto flex-1",style:{scrollbarGutter:"stable"},children:y==="filament"?i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3",children:o("inventory.filamentInfo")}),i.jsx(dle,{formData:u,updateField:oe,cloudAuthenticated:P,loadingCloudPresets:j,presetInputValue:z,setPresetInputValue:Z,selectedPresetOption:te,filamentOptions:U,availableBrands:Y,availableMaterials:q,quickAdd:_,quantity:C,onQuantityChange:N,errors:p})]}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3",children:o("inventory.color")}),i.jsx(ule,{formData:u,updateField:oe,recentColors:pe,onColorUsed:he,catalogColors:ce})]}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3",children:o("inventory.additional")}),i.jsx(mle,{formData:u,updateField:oe,spoolCatalog:I,currencySymbol:a})]}),d&&n&&i.jsx("div",{children:i.jsx(nnt,{spoolId:n.id})})]}):i.jsx(hle,{formData:u,updateField:oe,printersWithCalibrations:D,selectedProfiles:ge,setSelectedProfiles:Te,expandedPrinters:V,setExpandedPrinters:J})}),i.jsxs("div",{className:"flex gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0",children:[d&&i.jsxs(Ie,{variant:"secondary",onClick:()=>R.mutate(),disabled:we||!n?.tag_uid,className:"mr-auto",children:[i.jsx(Vu,{className:"w-4 h-4"}),o("inventory.deleteTag","Delete Tag")]}),i.jsxs("div",{className:"flex gap-2 ml-auto",children:[i.jsx(Ie,{variant:"secondary",onClick:e,children:o("common.cancel")}),i.jsx(Ie,{onClick:ve,disabled:we,children:we?i.jsxs(i.Fragment,{children:[i.jsx(ft,{className:"w-4 h-4 animate-spin"}),o("common.saving")]}):i.jsxs(i.Fragment,{children:[i.jsx(as,{className:"w-4 h-4"}),o(d?"common.save":"inventory.addSpool")]})})]})]})]})]})}function int({isOpen:t,onClose:e,columns:n,defaultColumns:r,onSave:a}){const{t:s}=jt(),[o,l]=w.useState(n),[c,d]=w.useState(null),u=w.useRef(null);if(w.useEffect(()=>{t&&l(n.map(C=>({...C})))},[t,n]),w.useEffect(()=>{if(!t)return;const C=N=>{N.key==="Escape"&&e()};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[t,e]),!t)return null;const m=C=>{l(N=>N.map((P,T)=>T===C?{...P,visible:!P.visible}:P))},p=(C,N)=>{N<0||N>=o.length||l(P=>{const T=[...P],[j]=T.splice(C,1);return T.splice(N,0,j),T})},f=(C,N)=>{u.current=N,d(N),C.dataTransfer.effectAllowed="move"},y=(C,N)=>{C.preventDefault(),C.dataTransfer.dropEffect="move";const P=u.current;P!==null&&P!==N&&(p(P,N),u.current=N,d(N))},v=C=>{C.preventDefault()},b=()=>{u.current=null,d(null)},g=()=>{l(r.map(C=>({...C})))},_=()=>{a(o),e()},k=o.filter(C=>C.visible).length;return i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:e,children:i.jsx(At,{className:"w-full max-w-md max-h-[80vh] flex flex-col",onClick:C=>C.stopPropagation(),children:i.jsxs(Et,{className:"p-6 flex flex-col min-h-0",children:[i.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:s("inventory.configureColumns")}),i.jsxs("p",{className:"text-sm text-bambu-gray mb-4",children:[s("inventory.configureColumnsDesc"),i.jsxs("span",{className:"ml-2 text-bambu-gray/60",children:["(",k," ",s("inventory.of")," ",o.length," ",s("inventory.visible"),")"]})]}),i.jsx("div",{className:"space-y-1 overflow-y-auto flex-1 min-h-0 pr-1",children:o.map((C,N)=>i.jsxs("div",{className:`flex items-center gap-2 p-2 rounded-lg border transition-colors ${c===N?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark-tertiary/50"} ${C.visible?"":"opacity-50"}`,draggable:!0,onDragStart:P=>f(P,N),onDragOver:P=>y(P,N),onDrop:v,onDragEnd:b,children:[i.jsx("div",{className:"cursor-grab text-bambu-gray/50 hover:text-bambu-gray",children:i.jsx(Mh,{className:"w-4 h-4"})}),i.jsx("span",{className:"flex-1 font-medium text-sm text-white",children:C.label}),i.jsxs("div",{className:"flex items-center gap-0.5",children:[i.jsx("button",{onClick:()=>p(N,N-1),disabled:N===0,className:"p-1 rounded text-bambu-gray hover:bg-bambu-dark-secondary disabled:opacity-30 disabled:cursor-not-allowed",title:s("inventory.moveUp"),children:i.jsx(Gl,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>p(N,N+1),disabled:N===o.length-1,className:"p-1 rounded text-bambu-gray hover:bg-bambu-dark-secondary disabled:opacity-30 disabled:cursor-not-allowed",title:s("inventory.moveDown"),children:i.jsx(zn,{className:"w-4 h-4"})})]}),i.jsx("button",{onClick:()=>m(N),className:`p-1.5 rounded transition-colors ${C.visible?"text-bambu-green hover:bg-bambu-green/10":"text-bambu-gray/50 hover:bg-bambu-dark-secondary"}`,title:C.visible?s("inventory.hideColumn"):s("inventory.showColumn"),children:C.visible?i.jsx(Pc,{className:"w-4 h-4"}):i.jsx(xw,{className:"w-4 h-4"})})]},C.id))}),i.jsxs("div",{className:"flex items-center gap-3 mt-4 pt-4 border-t border-bambu-dark-tertiary",children:[i.jsxs(Ie,{variant:"secondary",onClick:g,className:"mr-auto",children:[i.jsx(Ao,{className:"w-4 h-4"}),s("inventory.reset")]}),i.jsx(Ie,{variant:"secondary",onClick:e,children:s("inventory.cancel")}),i.jsx(Ie,{onClick:_,children:s("inventory.applyChanges")})]})]})})})}function BY(t){return`${t.material}|${t.subtype||""}|${t.brand||""}|${t.color_name||""}|${t.rgba||""}|${t.label_weight}`}const ple="bambuddy-inventory-columns",Ak=[{id:"id",label:"#",visible:!0},{id:"added_time",label:"Added",visible:!0},{id:"encode_time",label:"Encoded",visible:!1},{id:"last_used_time",label:"Last Used",visible:!1},{id:"rgba",label:"Color",visible:!0},{id:"material",label:"Material",visible:!0},{id:"subtype",label:"Subtype",visible:!0},{id:"color_name",label:"Color Name",visible:!1},{id:"brand",label:"Brand",visible:!0},{id:"slicer_filament",label:"Slicer Filament",visible:!1},{id:"location",label:"Location",visible:!0},{id:"label_weight",label:"Label",visible:!0},{id:"net",label:"Net",visible:!0},{id:"gross",label:"Gross",visible:!1},{id:"added_full",label:"Full",visible:!1},{id:"used",label:"Used",visible:!1},{id:"printed_total",label:"Printed Total",visible:!1},{id:"printed_since_weight",label:"Printed Since Weight",visible:!1},{id:"note",label:"Note",visible:!1},{id:"pa_k",label:"PA(K)",visible:!0},{id:"tag_id",label:"Tag ID",visible:!1},{id:"data_origin",label:"Data Origin",visible:!1},{id:"tag_type",label:"Linked Tag Type",visible:!1},{id:"stock",label:"Stock",visible:!1},{id:"remaining",label:"Remaining",visible:!0},{id:"spool_name",label:"Spool",visible:!1},{id:"cost_per_kg",label:"Cost/kg",visible:!1},{id:"weight_check",label:"Weight Check",visible:!1}];function ant(){try{const t=localStorage.getItem(ple);if(t){const e=JSON.parse(t),n=new Set(Ak.map(o=>o.id)),r=new Set(e.map(o=>o.id)),a=e.filter(o=>n.has(o.id)),s=Ak.filter(o=>!r.has(o.id));return[...a,...s]}}catch{}return Ak.map(t=>({...t}))}function snt(t){try{localStorage.setItem(ple,JSON.stringify(t))}catch{}}function md(t,e=!1){return e&&t>=1e3?`${(t/1e3).toFixed(1)}kg`:`${Math.round(t)}g`}const ont={PLA:"bg-green-500/20 text-green-400",ABS:"bg-red-500/20 text-red-400",PETG:"bg-blue-500/20 text-blue-400",TPU:"bg-purple-500/20 text-purple-400",ASA:"bg-orange-500/20 text-orange-400",PA:"bg-yellow-500/20 text-yellow-400",PC:"bg-cyan-500/20 text-cyan-400",PET:"bg-sky-500/20 text-sky-400"};function t3(t,e="system"){if(!t)return"-";const n=Qn(t);return n?M3(n,e):"-"}const lnt={id:()=>"#",added_time:()=>"Added",encode_time:()=>"Encoded",last_used_time:()=>"Last Used",rgba:t=>t("inventory.color"),material:t=>t("inventory.material"),subtype:t=>t("inventory.subtype"),color_name:t=>t("inventory.colorName"),brand:t=>t("inventory.brand"),slicer_filament:t=>t("inventory.slicerFilament"),location:()=>"Location",label_weight:t=>t("inventory.labelWeight"),net:t=>t("inventory.net"),gross:()=>"Gross",added_full:()=>"Full",used:t=>t("inventory.weightUsed"),printed_total:()=>"Printed Total",printed_since_weight:()=>"Printed Since Weight",note:t=>t("inventory.note"),pa_k:()=>"PA(K)",tag_id:()=>"Tag ID",data_origin:()=>"Data Origin",tag_type:()=>"Linked Tag Type",stock:t=>t("inventory.stock"),remaining:t=>t("inventory.remaining"),spool_name:t=>t("inventory.spoolName"),cost_per_kg:t=>t("inventory.costPerKg"),weight_check:t=>t("inventory.weightCheck")},PL={id:({spool:t})=>i.jsx("span",{className:"text-sm font-medium text-white",children:t.id}),added_time:({spool:t,dateFormat:e})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t3(t.created_at,e)}),encode_time:({spool:t,dateFormat:e})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t3(t.encode_time,e)}),last_used_time:({spool:t,dateFormat:e})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.last_used?t3(t.last_used,e):"Never"}),rgba:({spool:t})=>i.jsx("div",{className:"flex items-center justify-center",children:i.jsx("span",{className:"w-5 h-5 rounded-full border border-black/20 flex-shrink-0",style:{backgroundColor:t.rgba?`#${t.rgba.substring(0,6)}`:"#808080"},title:t.rgba?`#${t.rgba.substring(0,6)}`:void 0})}),material:({spool:t})=>i.jsx("span",{className:"text-sm text-white",children:t.material}),subtype:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.subtype||"-"}),color_name:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:LI(t.color_name,t.rgba)||"-"}),brand:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.brand||"-"}),slicer_filament:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",title:t.slicer_filament||void 0,children:t.slicer_filament_name||t.slicer_filament||"-"}),location:({spool:t,assignmentMap:e})=>{const n=e[t.id];if(!n)return i.jsx("span",{className:"text-sm text-bambu-gray",children:"-"});const r=n.printer_name||`Printer ${n.printer_id}`,a=n.ams_id===254||n.ams_id===255,s=!a&&n.ams_id>=128,o=II(n.ams_id,n.tray_id,s,a);return i.jsxs("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-purple-500/20 text-purple-400",children:[r," ",o,n.ams_label?` (${n.ams_label})`:""]})},label_weight:({spool:t})=>i.jsx("span",{className:"text-sm text-white",children:md(t.label_weight)}),net:({remaining:t})=>i.jsx("span",{className:"text-sm text-white",children:md(t)}),gross:({spool:t,remaining:e})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:md(e+t.core_weight)}),added_full:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.added_full==null?"-":t.added_full?"Yes":"No"}),used:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.weight_used>0?md(t.weight_used):"-"}),printed_total:()=>i.jsx("span",{className:"text-sm text-bambu-gray/50",children:"-"}),printed_since_weight:()=>i.jsx("span",{className:"text-sm text-bambu-gray/50",children:"-"}),note:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray max-w-[150px] truncate block",title:t.note||void 0,children:t.note||"-"}),pa_k:({spool:t})=>(t.k_profiles?.length??0)===0?i.jsx("span",{className:"text-sm text-bambu-gray",children:"-"}):i.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-bambu-green/20 text-bambu-green",children:"K"}),tag_id:({spool:t})=>{const e=t.tag_uid||t.tray_uuid;return e?i.jsx("span",{className:"text-sm text-bambu-gray font-mono",title:e,children:e.length>12?`${e.slice(0,6)}...${e.slice(-4)}`:e}):i.jsx("span",{className:"text-sm text-bambu-gray/50",children:"-"})},data_origin:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.data_origin||"-"}),tag_type:({spool:t})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.tag_type||"-"}),stock:({spool:t,t:e})=>t.slicer_filament?i.jsx("span",{className:"text-sm text-bambu-gray",children:"-"}):i.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-amber-500/20 text-amber-400",children:e("inventory.stock")}),remaining:({remaining:t,pct:e})=>i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("div",{className:"flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden",children:i.jsx("div",{className:`h-full rounded-full ${e>50?"bg-bambu-green":e>20?"bg-yellow-500":"bg-red-500"}`,style:{width:`${Math.min(e,100)}%`}})}),i.jsxs("span",{className:"text-xs text-bambu-gray min-w-[40px] text-right",children:[Math.round(t),"g"]})]}),spool_name:({spool:t,catalogMap:e})=>{const n=t.core_weight_catalog_id!=null?e[t.core_weight_catalog_id]:void 0;return i.jsx("span",{className:"text-sm text-bambu-gray",children:n?.name||"-"})},cost_per_kg:({spool:t,currencySymbol:e})=>i.jsx("span",{className:"text-sm text-bambu-gray",children:t.cost_per_kg!=null?`${e}${t.cost_per_kg.toFixed(2)}`:"-"}),weight_check:({spool:t,onSyncWeight:e})=>{const n=t.last_scale_weight;if(n==null)return i.jsx("span",{className:"text-sm text-bambu-gray/50",title:"No scale measurement",children:"-"});const r=t.core_weight||0,a=Math.max(0,t.label_weight-t.weight_used)+r;let s,o;n0?`+${Math.round(s)}`:`${Math.round(s)}`,c=o?`Scale: ${Math.round(n)}g Calculated: ${Math.round(a)}g Difference: ${l}g (within tolerance)`:`Scale: ${Math.round(n)}g Calculated: ${Math.round(a)}g diff --git a/static/index.html b/static/index.html index c38a46fc7..05d0b026d 100644 --- a/static/index.html +++ b/static/index.html @@ -23,7 +23,7 @@ - +