ProjectDetailPage-CaZEFrXK.js 41 KB

1
  1. import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-BdOyoZJz.js";import{n as a}from"./QueryClientProvider-Clbyr4Jg.js";import{t as o}from"./useQuery-CCy0EwsM.js";import{t as s}from"./useMutation-qh3Iyscy.js";import{t as ee}from"./arrow-left-MSgMxOFV.js";import{t as te}from"./RichTextEditor-CtyYZFiu.js";import{t as ne}from"./calendar-DiVEdzUw.js";import{n as re}from"./info-DcT0QU8O.js";import{n as ie,r as c}from"./ToastContext-VFOrCCoA.js";import{t as ae}from"./copy-3N5VKzXz.js";import{t as oe}from"./file-box-BjB1o93N.js";import{t as se}from"./history-BBZbf3sJ.js";import{t as l}from"./loader-circle-CB4leTZa.js";import{t as u}from"./package-D9xR0eOt.js";import{t as ce}from"./pen-line-DYnjxVtS.js";import{t as d}from"./triangle-alert-gIik0G2C.js";import{t as le}from"./x-Dctff5l9.js";import{n as f,t as p}from"./Card-OUAj0Ayh.js";import{t as m}from"./Button-pwVKPiYn.js";import{a as ue,i as de,s as fe,v as h}from"./date-G9KUauqz.js";import{$t as pe,At as me,Cn as he,Jt as g,Mn as ge,N as _e,On as ve,Pt as ye,Rn as _,Un as be,Ut as xe,Vn as Se,Zt as Ce,_t as we,at as Te,b as Ee,cn as De,vn as Oe,wn as ke,xn as Ae,yt as je,zt as Me}from"./index-BoVbGTav.js";import{t as Ne}from"./purify.es-F_7NWVtX.js";import{n as Pe}from"./libraryFiles-B0B1SFfn.js";import{ProjectModal as Fe,n as v,t as Ie}from"./ProjectsPage-C2aXY-5x.js";var y=e(n(),1),b=t();function x(e){return e>=1e3?`${(e/1e3).toFixed(2)}kg`:`${Math.round(e)}g`}function Le({status:e,t}){let n={active:`bg-bambu-green/20 text-bambu-green`,completed:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,archived:`bg-bambu-gray/20 text-bambu-gray`},r=n[e]||n.active,i={active:t(`projectDetail.status.active`),completed:t(`projectDetail.status.completed`),archived:t(`projectDetail.status.archived`)};return(0,b.jsx)(`span`,{className:`px-2 py-1 rounded text-sm font-medium ${r}`,children:i[e]||e.charAt(0).toUpperCase()+e.slice(1)})}function Re({icon:e,label:t,value:n,subValue:r,hint:i,color:a=`text-bambu-gray`}){return(0,b.jsx)(p,{children:(0,b.jsx)(f,{className:`p-4`,children:(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,title:i,children:[(0,b.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark ${a}`,children:(0,b.jsx)(e,{className:`w-5 h-5`})}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t}),(0,b.jsx)(`p`,{className:`text-xl font-semibold text-white`,children:n}),r&&(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:r})]})]})})})}function ze({archives:e,t}){return e.length===0?(0,b.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,b.jsx)(u,{className:`w-12 h-12 mx-auto mb-2 opacity-50`}),(0,b.jsx)(`p`,{children:t(`projectDetail.noPrints`)})]}):(0,b.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:e.map(e=>(0,b.jsxs)(_,{to:`/archives?search=${encodeURIComponent(e.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:[e.thumbnail_path?(0,b.jsx)(`img`,{src:r.getArchiveThumbnail(e.id),alt:e.print_name||`Print`,className:`w-full h-full object-cover`}):(0,b.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,b.jsx)(u,{className:`w-8 h-8`})}),e.status===`failed`&&(0,b.jsx)(`div`,{className:`absolute inset-0 bg-red-500/30 flex items-center justify-center`,children:(0,b.jsx)(re,{className:`w-8 h-8 text-white`})}),e.status===`completed`&&(0,b.jsx)(`div`,{className:`absolute top-1 right-1`,children:(0,b.jsx)(c,{className:`w-4 h-4 text-bambu-green`})}),(0,b.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:(0,b.jsx)(`p`,{className:`text-xs text-white truncate`,children:e.print_name||`Unknown`})})]},e.id))})}function Be({priority:e,t}){let n={low:{color:`bg-gray-500/20 text-gray-400`,label:t(`projectDetail.priority.low`)},normal:{color:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,label:t(`projectDetail.priority.normal`)},high:{color:`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400`,label:t(`projectDetail.priority.high`)},urgent:{color:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`,label:t(`projectDetail.priority.urgent`)}},{color:r,label:i}=n[e]||n.normal;return(0,b.jsxs)(`span`,{className:`px-2 py-1 rounded text-xs font-medium flex items-center gap-1 ${r}`,children:[e===`urgent`&&(0,b.jsx)(d,{className:`w-3 h-3`}),i]})}function S(e,t){if(!e)return null;let n=h(e);if(!n)return null;let r=new Date,i=Math.ceil((n.getTime()-r.getTime())/(1e3*60*60*24));return i<0?{color:`text-red-700 dark:text-red-400`,label:t(`projectDetail.dueDate.overdue`)}:i===0?{color:`text-orange-700 dark:text-orange-400`,label:t(`projectDetail.dueDate.today`)}:i<=3?{color:`text-yellow-700 dark:text-yellow-400`,label:t(`projectDetail.dueDate.daysLeft`,{count:i})}:{color:`text-bambu-gray`,label:t(`projectDetail.dueDate.daysLeft`,{count:i})}}function C(){let{id:e}=be(),t=Se(),{t:n}=i(),d=a(),{showToast:h}=ie(),{hasPermission:C}=je(),[Ve,w]=(0,y.useState)(!1),[He,T]=(0,y.useState)(!1),[Ue,E]=(0,y.useState)(``),[D,O]=(0,y.useState)(null),k=parseInt(e||`0`,10),{data:A,isLoading:We,error:j}=o({queryKey:[`project`,k],queryFn:()=>r.getProject(k),enabled:k>0}),{data:Ge,isLoading:Ke}=o({queryKey:[`project-archives`,k],queryFn:()=>r.getProjectArchives(k),enabled:k>0}),{data:M,isLoading:qe}=o({queryKey:[`project-bom`,k],queryFn:()=>r.getProjectBOM(k),enabled:k>0}),{data:N,isLoading:Je}=o({queryKey:[`project-timeline`,k],queryFn:()=>r.getProjectTimeline(k,20),enabled:k>0}),{data:Ye}=o({queryKey:[`settings`],queryFn:r.getSettings}),{data:P}=o({queryKey:[`project-folders`,k],queryFn:()=>r.getLibraryFoldersByProject(k),enabled:k>0}),{data:F,isLoading:Xe}=o({queryKey:[`project-files`,k],queryFn:()=>r.getLibraryFiles(null,!1,k),enabled:k>0}),Ze=(0,y.useMemo)(()=>{let e=new Map;for(let t of F??[])if(t.folder_id!=null){let n=e.get(t.folder_id)??[];n.push(t),e.set(t.folder_id,n)}return e},[F]),{data:Qe}=o({queryKey:[`project-file-progress`,k],queryFn:()=>r.getProjectFileProgress(k),enabled:k>0}),I=(0,y.useMemo)(()=>{let e=new Map;for(let t of Qe??[])e.set(t.file_id,t.completed_count);return e},[Qe]),L=(0,y.useMemo)(()=>{let e=A?.target_sets;if(!e||!F)return null;let t=F.filter(e=>Pe(e));return t.length===0?null:Math.min(...t.map(t=>Math.min(I.get(t.id)??0,e)))},[A?.target_sets,F,I]),R=Te(Ye?.currency||`USD`),$e=Ye?.time_format||`system`,z=s({mutationFn:e=>r.updateProject(k,e),onSuccess:()=>{d.invalidateQueries({queryKey:[`project`,k]}),d.invalidateQueries({queryKey:[`projects`]}),w(!1),T(!1),h(n(`projectDetail.toast.projectUpdated`),`success`)},onError:e=>{h(e.message,`error`)}}),et=()=>{E(A?.notes||``),T(!0)},tt=()=>{z.mutate({notes:Ue})},nt=()=>{T(!1),E(``)},[B,rt]=(0,y.useState)(``),[it,at]=(0,y.useState)(1),[V,ot]=(0,y.useState)(``),[st,ct]=(0,y.useState)(``),[lt,ut]=(0,y.useState)(``),[dt,H]=(0,y.useState)(!1),[U,ft]=(0,y.useState)(!1),[W,G]=(0,y.useState)(null),[K,pt]=(0,y.useState)(``),[mt,ht]=(0,y.useState)(1),[q,gt]=(0,y.useState)(``),[_t,vt]=(0,y.useState)(``),[yt,bt]=(0,y.useState)(``),[J,Y]=(0,y.useState)({isOpen:!1,title:``,message:``,onConfirm:()=>{}}),X=s({mutationFn:e=>r.createBOMItem(k,e),onSuccess:()=>{d.invalidateQueries({queryKey:[`project-bom`,k]}),d.invalidateQueries({queryKey:[`project`,k]}),rt(``),at(1),ot(``),ct(``),ut(``),H(!1),h(n(`projectDetail.toast.partAdded`),`success`)},onError:e=>h(e.message,`error`)}),Z=s({mutationFn:({itemId:e,data:t})=>r.updateBOMItem(k,e,t),onSuccess:()=>{d.invalidateQueries({queryKey:[`project-bom`,k]}),d.invalidateQueries({queryKey:[`project`,k]}),G(null)},onError:e=>h(e.message,`error`)}),xt=s({mutationFn:e=>r.deleteBOMItem(k,e),onSuccess:()=>{d.invalidateQueries({queryKey:[`project-bom`,k]}),d.invalidateQueries({queryKey:[`project`,k]}),h(n(`projectDetail.toast.partRemoved`),`success`)},onError:e=>h(e.message,`error`)}),St=e=>{e.preventDefault(),B.trim()&&X.mutate({name:B.trim(),quantity_needed:it,unit_price:V?parseFloat(V):void 0,sourcing_url:st.trim()||void 0,remarks:lt.trim()||void 0})},Ct=e=>{let t=e.is_complete?0:e.quantity_needed;Z.mutate({itemId:e.id,data:{quantity_acquired:t}})},wt=(e,t)=>{Y({isOpen:!0,title:n(`projectDetail.bom.deletePart`),message:n(`projectDetail.bom.deleteConfirm`,{name:t}),onConfirm:()=>{Y(e=>({...e,isOpen:!1})),xt.mutate(e)}})},Tt=e=>{G(e),pt(e.name),ht(e.quantity_needed),gt(e.unit_price?.toString()||``),vt(e.sourcing_url||``),bt(e.remarks||``)},Et=e=>{e.preventDefault(),!(!W||!K.trim())&&Z.mutate({itemId:W.id,data:{name:K.trim(),quantity_needed:mt,unit_price:q?parseFloat(q):void 0,sourcing_url:_t.trim()||void 0,remarks:yt.trim()||void 0}})},Dt=()=>{G(null)},Ot=async()=>{try{let{blob:e,filename:t}=await r.exportProjectZip(Number(k)),i=URL.createObjectURL(e),a=document.createElement(`a`);a.href=i,a.download=t||`${A?.name||`project`}_${new Date().toISOString().split(`T`)[0]}.zip`,a.click(),URL.revokeObjectURL(i),h(n(`projectDetail.toast.projectExported`),`success`)}catch(e){h(e.message,`error`)}},kt=s({mutationFn:()=>r.createTemplateFromProject(k),onSuccess:()=>{d.invalidateQueries({queryKey:[`projects`]}),h(n(`projectDetail.toast.templateCreated`),`success`)},onError:e=>h(e.message,`error`)}),At=e=>ue(e,$e,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`});if(We)return(0,b.jsx)(`div`,{className:`flex items-center justify-center py-24`,children:(0,b.jsx)(l,{className:`w-8 h-8 animate-spin text-bambu-green`})});if(j||!A)return(0,b.jsxs)(`div`,{className:`text-center py-24`,children:[(0,b.jsx)(`p`,{className:`text-bambu-gray`,children:j?`${n(`common.error`)}: ${j.message}`:n(`projectDetail.notFound`)}),(0,b.jsx)(m,{variant:`secondary`,className:`mt-4`,onClick:()=>t(`/projects`),children:n(`projectDetail.backToProjects`)})]});let Q=A.stats,jt=Q?.progress_percent??0,$=Q?.parts_progress_percent??0;return(0,b.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,b.jsx)(_,{to:`/projects`,className:`hover:text-white transition-colors`,children:n(`nav.projects`)}),(0,b.jsx)(ge,{className:`w-4 h-4`}),(0,b.jsx)(`span`,{className:`text-white`,children:A.name})]}),(0,b.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,b.jsx)(`button`,{onClick:()=>t(`/projects`),className:`p-2 rounded-lg bg-bambu-card hover:bg-bambu-dark-tertiary transition-colors`,children:(0,b.jsx)(ee,{className:`w-5 h-5 text-bambu-gray`})}),(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,b.jsx)(`div`,{className:`w-4 h-4 rounded-full shrink-0`,style:{backgroundColor:A.color||`#6b7280`}}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:A.name}),A.description&&(0,b.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:A.description})]})]}),(0,b.jsx)(Le,{status:A.status,t:n})]}),(0,b.jsxs)(`div`,{className:`flex gap-2`,children:[(0,b.jsxs)(m,{variant:`secondary`,onClick:Ot,disabled:!C(`projects:read`),title:C(`projects:read`)?n(`projectDetail.exportProject`):n(`projectDetail.noExportPermission`),children:[(0,b.jsx)(ke,{className:`w-4 h-4 mr-2`}),n(`projectDetail.export`)]}),(0,b.jsxs)(m,{onClick:()=>w(!0),disabled:!C(`projects:update`),title:C(`projects:update`)?void 0:n(`projectDetail.noEditPermission`),children:[(0,b.jsx)(ce,{className:`w-4 h-4 mr-2`}),n(`common.edit`)]})]})]}),(A.target_count||A.target_parts_count||A.target_sets)&&(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4 space-y-4`,children:[A.target_count&&(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,b.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.platesProgress`)}),(0,b.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[Q?.total_archives||0,` / `,A.target_count,` `,n(`projectDetail.progress.printJobs`)]})]}),(0,b.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,b.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(jt,100)}%`,backgroundColor:jt>=100?`#22c55e`:A.color||`#6b7280`}})}),(0,b.jsxs)(`div`,{className:`flex justify-between mt-1`,children:[(0,b.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.percentComplete`,{percent:jt.toFixed(0)})}),Q?.remaining_prints!=null&&Q.remaining_prints>0&&(0,b.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.remaining`,{count:Q.remaining_prints})})]})]}),A.target_parts_count&&(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,b.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.partsProgress`)}),(0,b.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[Q?.completed_prints||0,` / `,A.target_parts_count,` `,n(`projectDetail.progress.parts`)]})]}),(0,b.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,b.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min($,100)}%`,backgroundColor:$>=100?`#22c55e`:A.color||`#6b7280`}})}),(0,b.jsxs)(`div`,{className:`flex justify-between mt-1`,children:[(0,b.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.percentComplete`,{percent:$.toFixed(0)})}),Q?.remaining_parts!=null&&Q.remaining_parts>0&&(0,b.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.remaining`,{count:Q.remaining_parts})})]})]}),A.target_sets?(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,b.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.setsProgress`)}),(0,b.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[L??0,` / `,A.target_sets,` `,n(`projectDetail.progress.sets`)]})]}),(0,b.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,b.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min((L??0)/A.target_sets*100,100)}%`,backgroundColor:(L??0)>=A.target_sets?`#22c55e`:A.color||`#6b7280`}})}),(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:n(`projectDetail.progress.setsHint`)})]}):null]})}),Q&&(0,b.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,b.jsx)(p,{children:(0,b.jsx)(f,{className:`p-4`,children:(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,b.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark text-bambu-green`,children:(0,b.jsx)(u,{className:`w-5 h-5`})}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.printJobs`)}),(0,b.jsxs)(`p`,{className:`text-xl font-semibold text-white`,children:[Q.total_archives,` `,(0,b.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:n(`projectDetail.stats.total`)})]}),Q.failed_prints>0&&(0,b.jsx)(`p`,{className:`text-sm text-status-error`,children:n(`projectDetail.stats.failed`,{count:Q.failed_prints})}),(0,b.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.partsPrinted`,{count:Q.completed_prints})})]})]})})}),(0,b.jsx)(Re,{icon:ve,label:n(`projectDetail.stats.printTime`),value:fe(Q.total_print_time_hours),color:`text-yellow-600 dark:text-yellow-400`}),(0,b.jsx)(Re,{icon:g,label:n(`projectDetail.stats.filamentUsed`),value:x(Q.total_filament_grams),color:`text-purple-600 dark:text-purple-400`})]}),A.rollup_stats&&(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2 mb-3`,children:[(0,b.jsx)(v,{className:`w-5 h-5`}),n(`projectDetail.rollup.title`,{count:A.descendant_count})]}),(0,b.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.stats.printJobs`)}),(0,b.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:A.rollup_stats.total_archives}),(0,b.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.partsPrinted`,{count:A.rollup_stats.completed_prints})})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.stats.printTime`)}),(0,b.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:fe(A.rollup_stats.total_print_time_hours)})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.stats.filamentUsed`)}),(0,b.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:x(A.rollup_stats.total_filament_grams)})]}),(()=>{let e=A.rollup_stats.estimated_cost+A.rollup_stats.total_energy_cost+(A.rollup_stats.total_wear_cost??0)+A.rollup_stats.bom_cost;return e<=0?null:(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.totalCost`)}),(0,b.jsxs)(`p`,{className:`text-lg font-semibold text-bambu-green`,children:[R,e.toFixed(2)]})]})})()]}),A.rollup_stats.progress_percent!==null&&(0,b.jsxs)(`div`,{className:`mt-4`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,b.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.rollup.progress`)}),(0,b.jsx)(`span`,{className:`text-sm font-medium text-white`,children:n(`projectDetail.rollup.percentComplete`,{percent:A.rollup_stats.progress_percent.toFixed(0)})})]}),(0,b.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,b.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(A.rollup_stats.progress_percent,100)}%`,backgroundColor:A.rollup_stats.progress_percent>=100?`#22c55e`:A.color||`#6b7280`}})})]})]})}),Q&&(()=>{let e=Q.estimated_cost+Q.total_energy_cost+(Q.total_wear_cost??0)+Q.bom_cost;return Q.estimated_cost>0||e>0||A.budget!==null})()&&(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsx)(`h2`,{className:`text-lg font-semibold text-white mb-3`,children:n(`projectDetail.cost.title`)}),(0,b.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.filamentCost`)}),(0,b.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[R,Q.estimated_cost.toFixed(2)]})]}),Q.total_energy_kwh>0&&(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.energy`)}),(0,b.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[Q.total_energy_kwh.toFixed(3),` kWh`,Q.total_energy_cost>0&&(0,b.jsxs)(`span`,{className:`text-sm text-bambu-gray ml-1`,children:[`(`,R,Q.total_energy_cost.toFixed(2),`)`]})]})]}),(Q.total_wear_cost??0)>0&&(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.wear`)}),(0,b.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[R,Q.total_wear_cost.toFixed(2)]})]}),(()=>{let e=Q.estimated_cost+Q.total_energy_cost+(Q.total_wear_cost??0)+Q.bom_cost;return e<=0?null:(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.totalCost`)}),(0,b.jsxs)(`p`,{className:`text-lg font-semibold text-bambu-green`,children:[R,e.toFixed(2)]}),Q.bom_cost>0&&(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.cost.includesBom`)})]})})(),A.budget!==null&&(()=>{let e=Q.estimated_cost+Q.total_energy_cost+(Q.total_wear_cost??0)+Q.bom_cost,t=A.budget-e;return(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.budget`)}),(0,b.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[n(`projectDetail.cost.total`),`: `,(0,b.jsxs)(`span`,{className:`text-white font-semibold`,children:[R,A.budget.toFixed(2)]})]}),(0,b.jsxs)(`p`,{className:`text-sm ${t>=0?`text-bambu-green`:`text-red-700 dark:text-red-400`}`,children:[n(`projectDetail.cost.remaining`),`: `,(0,b.jsxs)(`span`,{className:`font-semibold`,children:[R,t.toFixed(2)]})]})]})})()]})]})}),A.children&&A.children.length>0&&(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2 mb-3`,children:[(0,b.jsx)(v,{className:`w-5 h-5`}),n(`projectDetail.subProjects.title`,{count:A.children.length})]}),(0,b.jsx)(`div`,{className:`space-y-2`,children:A.children.map(e=>(0,b.jsxs)(_,{to:`/projects/${e.id}`,className:`flex items-center justify-between gap-4 p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,b.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:e.color||`#6b7280`}}),(0,b.jsx)(`span`,{className:`text-white truncate`,children:e.name}),(0,b.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded flex-shrink-0 ${e.status===`completed`?`bg-status-ok/20 text-status-ok`:e.status===`archived`?`bg-bambu-gray/20 text-bambu-gray`:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`}`,children:e.status}),e.descendant_count>0&&(0,b.jsxs)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0 inline-flex items-center gap-1`,children:[(0,b.jsx)(v,{className:`w-3 h-3`}),e.descendant_count]})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-4 text-sm text-bambu-gray flex-shrink-0`,children:[e.total_archives>0&&(0,b.jsx)(`span`,{className:`hidden sm:inline`,children:n(`projectDetail.subProjects.jobs`,{count:e.total_archives})}),e.total_filament_grams>0&&(0,b.jsx)(`span`,{className:`hidden md:inline`,children:x(e.total_filament_grams)}),e.total_cost>0&&(0,b.jsxs)(`span`,{className:`hidden md:inline`,children:[R,e.total_cost.toFixed(2)]}),e.progress_percent!==null&&(0,b.jsxs)(`span`,{children:[e.progress_percent.toFixed(0),`%`]})]})]},e.id))})]})}),A.parent_id&&A.parent_name&&(0,b.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,b.jsx)(De,{className:`w-4 h-4 text-bambu-gray`}),(0,b.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.partOf`)}),(0,b.jsx)(_,{to:`/projects/${A.parent_id}`,className:`text-bambu-green hover:underline`,children:A.parent_name})]}),(A.tags||A.due_date||A.priority!==`normal`)&&(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[A.priority&&A.priority!==`normal`&&(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(`span`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.priorityLabel`)}),(0,b.jsx)(Be,{priority:A.priority,t:n})]}),A.due_date&&(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(ne,{className:`w-4 h-4 text-bambu-gray`}),(0,b.jsx)(`span`,{className:`text-sm text-white`,children:de(A.due_date,{year:`numeric`,month:`short`,day:`numeric`})}),S(A.due_date,n)&&(0,b.jsxs)(`span`,{className:`text-xs ${S(A.due_date,n).color}`,children:[`(`,S(A.due_date,n).label,`)`]})]}),A.tags&&(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(ye,{className:`w-4 h-4 text-bambu-gray`}),(0,b.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:A.tags.split(`,`).map((e,t)=>(0,b.jsx)(`span`,{className:`px-2 py-0.5 bg-bambu-dark-tertiary text-bambu-gray text-xs rounded`,children:e.trim()},t))})]})]}),(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(Ae,{className:`w-5 h-5`}),n(`projectDetail.notes.title`)]}),He?(0,b.jsxs)(`div`,{className:`flex gap-2`,children:[(0,b.jsxs)(m,{variant:`secondary`,size:`sm`,onClick:nt,disabled:z.isPending,children:[(0,b.jsx)(le,{className:`w-4 h-4 mr-1`}),n(`common.cancel`)]}),(0,b.jsxs)(m,{size:`sm`,onClick:tt,disabled:z.isPending,children:[z.isPending?(0,b.jsx)(l,{className:`w-4 h-4 animate-spin mr-1`}):(0,b.jsx)(xe,{className:`w-4 h-4 mr-1`}),n(`common.save`)]})]}):(0,b.jsxs)(m,{variant:`secondary`,size:`sm`,onClick:et,disabled:!C(`projects:update`),title:C(`projects:update`)?void 0:n(`projectDetail.notes.noEditPermission`),children:[(0,b.jsx)(ce,{className:`w-4 h-4 mr-1`}),n(`common.edit`)]})]}),He?(0,b.jsx)(te,{content:Ue,onChange:E,placeholder:n(`projectDetail.notes.placeholder`)}):A.notes?(0,b.jsx)(`div`,{className:`prose prose-invert prose-sm max-w-none`,dangerouslySetInnerHTML:{__html:Ne.sanitize(A.notes)}}):(0,b.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.notes.empty`)})]})}),(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsx)(`div`,{className:`flex items-center justify-between mb-3`,children:(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(Oe,{className:`w-5 h-5`}),n(`projectDetail.files.title`)]})}),(0,b.jsxs)(`p`,{className:`text-xs text-bambu-gray mb-3`,children:[(0,b.jsx)(_,{to:`/files`,className:`text-bambu-green hover:underline`,children:n(`projectDetail.files.linkFolders`)}),` `,n(`projectDetail.files.forQuickAccess`)]}),P&&P.length>0?(0,b.jsx)(`div`,{className:`space-y-4`,children:P.map(e=>{let t=Ze.get(e.id)??[],i=Xe;return(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(_,{to:`/files?folder=${e.id}`,className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors mb-2`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,b.jsx)(Oe,{className:`w-5 h-5 text-bambu-green shrink-0`}),(0,b.jsxs)(`div`,{className:`min-w-0`,children:[(0,b.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.name}),(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`projectDetail.files.fileCount`,{count:e.file_count})})]})]}),(0,b.jsx)(ge,{className:`w-4 h-4 text-bambu-gray shrink-0`})]}),i?(0,b.jsx)(`div`,{className:`flex items-center gap-2 px-3 py-2 text-bambu-gray text-sm`,children:(0,b.jsx)(l,{className:`w-4 h-4 animate-spin`})}):t.length===0?(0,b.jsx)(`p`,{className:`text-bambu-gray/60 text-xs italic px-3`,children:n(`projectDetail.files.noFiles`)}):(0,b.jsx)(`div`,{className:`space-y-1 pl-3`,children:t.map(e=>{let t=Pe(e);return(0,b.jsxs)(`div`,{className:`flex items-center gap-3 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,b.jsx)(`div`,{className:`w-10 h-10 shrink-0 rounded bg-bambu-dark overflow-hidden flex items-center justify-center`,children:e.thumbnail_path?(0,b.jsx)(`img`,{src:r.getLibraryFileThumbnailUrl(e.id),alt:e.print_name||e.filename,className:`w-full h-full object-cover`}):(0,b.jsx)(oe,{className:`w-5 h-5 text-bambu-gray/40`})}),(0,b.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,b.jsx)(`p`,{className:`text-sm text-white truncate`,title:e.print_name||e.filename,children:e.print_name||e.filename}),(0,b.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded font-medium ${e.file_type===`3mf`?`bg-bambu-green/20 text-bambu-green`:e.file_type===`gcode`||e.file_type===`gcode.3mf`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`:`bg-bambu-gray/20 text-bambu-gray`}`,children:e.file_type.toUpperCase()})]}),t&&(()=>{let t=I.get(e.id)??0,r=A.target_sets;if(!r)return t>0?(0,b.jsxs)(`span`,{className:`shrink-0 text-xs px-1.5 py-0.5 rounded-full bg-bambu-dark text-bambu-gray`,title:n(`projectDetail.files.printedCount`,{count:t}),children:[t,`×`]}):null;let i=Math.min(t/r*100,100),a=t>=r?`text-status-ok`:t>0?`text-status-warning`:`text-bambu-gray`,o=t>=r?`bg-status-ok`:t>0?`bg-status-warning`:`bg-bambu-gray`;return(0,b.jsxs)(`div`,{className:`shrink-0 w-20`,title:n(`projectDetail.files.progressTooltip`,{done:t,target:r}),children:[(0,b.jsxs)(`p`,{className:`text-xs font-medium text-right ${a}`,children:[t,` / `,r]}),(0,b.jsx)(`div`,{className:`h-1 bg-bambu-dark rounded-full overflow-hidden mt-1`,children:(0,b.jsx)(`div`,{className:`h-full ${o}`,style:{width:`${i}%`}})})]})})(),t&&(0,b.jsx)(`div`,{className:`flex items-center gap-1 shrink-0`,children:(0,b.jsx)(`button`,{onClick:()=>O(e),title:n(`common.print`),className:`p-1.5 rounded hover:bg-bambu-green/20 text-bambu-green transition-colors`,children:(0,b.jsx)(g,{className:`w-4 h-4`})})})]},e.id)})})]},e.id)})}):(0,b.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.files.empty`)})]})}),(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(Me,{className:`w-5 h-5`}),n(`projectDetail.bom.title`),Q&&Q.bom_total_items>0&&(0,b.jsxs)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:[`(`,n(`projectDetail.bom.acquired`,{completed:Q.bom_completed_items,total:Q.bom_total_items}),`)`]})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[M&&M.some(e=>e.is_complete)&&(0,b.jsx)(`button`,{onClick:()=>ft(!U),className:`text-xs px-2 py-1 rounded transition-colors ${U?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:n(U?`projectDetail.bom.showAll`:`projectDetail.bom.hideDone`)}),!dt&&(0,b.jsxs)(m,{variant:`secondary`,size:`sm`,onClick:()=>H(!0),disabled:!C(`projects:update`),title:C(`projects:update`)?void 0:n(`projectDetail.bom.noAddPermission`),children:[(0,b.jsx)(Ce,{className:`w-4 h-4 mr-1`}),n(`projectDetail.bom.addPart`)]})]})]}),dt&&(0,b.jsxs)(`form`,{onSubmit:St,className:`bg-bambu-dark rounded-lg p-4 mb-4 space-y-3`,children:[(0,b.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,b.jsx)(`input`,{type:`text`,value:B,onChange:e=>rt(e.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}),(0,b.jsxs)(`div`,{className:`flex gap-2`,children:[(0,b.jsx)(_e,{value:it,onChange:at,fallback: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`)}),(0,b.jsx)(`input`,{type:`number`,step:`0.01`,value:V,onChange:e=>ot(e.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:R})})]})]}),(0,b.jsx)(`input`,{type:`url`,value:st,onChange:e=>ct(e.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`)}),(0,b.jsx)(`input`,{type:`text`,value:lt,onChange:e=>ut(e.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`)}),(0,b.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,b.jsx)(m,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>H(!1),children:n(`common.cancel`)}),(0,b.jsx)(m,{type:`submit`,size:`sm`,disabled:!B.trim()||X.isPending,children:X.isPending?(0,b.jsx)(l,{className:`w-4 h-4 animate-spin`}):n(`projectDetail.bom.addPart`)})]})]}),qe?(0,b.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,b.jsx)(l,{className:`w-6 h-6 animate-spin text-bambu-green`})}):M&&M.length>0?(0,b.jsxs)(`div`,{className:`space-y-2`,children:[M.filter(e=>!U||!e.is_complete).map(e=>(0,b.jsx)(`div`,{className:`p-3 rounded-lg transition-colors ${e.is_complete?`bg-status-ok/10`:`bg-bambu-dark`}`,children:W?.id===e.id?(0,b.jsxs)(`form`,{onSubmit:Et,className:`space-y-3`,children:[(0,b.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,b.jsx)(`input`,{type:`text`,value:K,onChange:e=>pt(e.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}),(0,b.jsxs)(`div`,{className:`flex gap-2`,children:[(0,b.jsx)(_e,{value:mt,onChange:ht,fallback: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`)}),(0,b.jsx)(`input`,{type:`number`,step:`0.01`,value:q,onChange:e=>gt(e.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:R})})]})]}),(0,b.jsx)(`input`,{type:`url`,value:_t,onChange:e=>vt(e.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`)}),(0,b.jsx)(`input`,{type:`text`,value:yt,onChange:e=>bt(e.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`)}),(0,b.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,b.jsx)(m,{type:`button`,variant:`secondary`,size:`sm`,onClick:Dt,children:n(`common.cancel`)}),(0,b.jsx)(m,{type:`submit`,size:`sm`,disabled:!K.trim()||Z.isPending,children:Z.isPending?(0,b.jsx)(l,{className:`w-4 h-4 animate-spin`}):n(`common.save`)})]})]}):(0,b.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,b.jsx)(`button`,{onClick:()=>C(`projects:update`)&&Ct(e),disabled:Z.isPending||!C(`projects:update`),title:C(`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 shrink-0 ${e.is_complete?`bg-status-ok border-status-ok text-white`:C(`projects:update`)?`border-bambu-gray hover:border-bambu-green`:`border-bambu-gray/50 cursor-not-allowed`}`,children:e.is_complete&&(0,b.jsx)(c,{className:`w-3 h-3`})}),(0,b.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,b.jsxs)(`p`,{className:`text-sm font-medium ${e.is_complete?`text-bambu-gray line-through`:`text-white`}`,children:[e.name,(0,b.jsxs)(`span`,{className:`text-bambu-gray font-normal ml-2`,children:[`x`,e.quantity_needed]})]}),e.unit_price!==null&&(0,b.jsxs)(`span`,{className:`text-xs text-bambu-green whitespace-nowrap`,children:[R,(e.unit_price*e.quantity_needed).toFixed(2)]})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,b.jsx)(`button`,{onClick:()=>C(`projects:update`)&&Tt(e),disabled:!C(`projects:update`),className:`p-1 rounded transition-colors shrink-0 ${C(`projects:update`)?`hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:C(`projects:update`)?n(`common.edit`):n(`projectDetail.bom.noEditPermission`),children:(0,b.jsx)(pe,{className:`w-4 h-4`})}),(0,b.jsx)(`button`,{onClick:()=>C(`projects:update`)&&wt(e.id,e.name),disabled:!C(`projects:update`),className:`p-1 rounded transition-colors shrink-0 ${C(`projects:update`)?`hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-red-400`:`text-bambu-gray/50 cursor-not-allowed`}`,title:C(`projects:update`)?n(`common.delete`):n(`projectDetail.bom.noDeletePermission`),children:(0,b.jsx)(me,{className:`w-4 h-4`})})]})]}),e.sourcing_url&&(0,b.jsxs)(`a`,{href:e.sourcing_url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 mt-1 text-xs text-blue-700 dark:text-blue-400 hover:text-blue-900 dark:hover:text-blue-300 transition-colors`,onClick:e=>e.stopPropagation(),children:[(0,b.jsx)(he,{className:`w-3 h-3 shrink-0`}),(0,b.jsx)(`span`,{className:`truncate`,children:(()=>{try{return new URL(e.sourcing_url).hostname.replace(`www.`,``)}catch{return e.sourcing_url}})()})]}),e.remarks&&(0,b.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray/80 italic`,children:e.remarks})]})]})},e.id)),Q&&Q.bom_cost>0&&(0,b.jsxs)(`div`,{className:`pt-2 mt-2 border-t border-bambu-dark-tertiary flex justify-between text-sm`,children:[(0,b.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.bom.totalCost`)}),(0,b.jsxs)(`span`,{className:`text-white font-medium`,children:[R,Q.bom_cost.toFixed(2)]})]})]}):(0,b.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.bom.empty`)})]})}),(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsx)(`div`,{className:`flex items-center justify-between mb-3`,children:(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(se,{className:`w-5 h-5`}),n(`projectDetail.timeline.title`)]})}),Je?(0,b.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,b.jsx)(l,{className:`w-6 h-6 animate-spin text-bambu-green`})}):N&&N.length>0?(0,b.jsx)(`div`,{className:`space-y-3`,children:N.slice(0,10).map((e,t)=>(0,b.jsxs)(`div`,{className:`flex gap-3`,children:[(0,b.jsxs)(`div`,{className:`w-8 h-8 rounded-full flex items-center justify-center shrink-0 ${e.event_type===`print_completed`?`bg-status-ok/20 text-status-ok`:e.event_type===`print_failed`?`bg-status-error/20 text-status-error`:e.event_type===`print_started`?`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[e.event_type===`print_completed`&&(0,b.jsx)(c,{className:`w-4 h-4`}),e.event_type===`print_failed`&&(0,b.jsx)(re,{className:`w-4 h-4`}),e.event_type===`print_started`&&(0,b.jsx)(g,{className:`w-4 h-4`}),e.event_type===`queued`&&(0,b.jsx)(Ie,{className:`w-4 h-4`}),e.event_type===`project_created`&&(0,b.jsx)(Ce,{className:`w-4 h-4`})]}),(0,b.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,b.jsx)(`p`,{className:`text-sm text-white`,children:e.title}),e.description&&(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.description}),(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:At(e.timestamp)})]})]},t))}):(0,b.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.timeline.empty`)})]})}),!A.is_template&&(0,b.jsx)(`div`,{className:`flex justify-end`,children:(0,b.jsxs)(m,{variant:`secondary`,size:`sm`,onClick:()=>kt.mutate(),disabled:kt.isPending||!C(`projects:create`),title:C(`projects:create`)?void 0:n(`projectDetail.template.noCreatePermission`),children:[kt.isPending?(0,b.jsx)(l,{className:`w-4 h-4 animate-spin mr-2`}):(0,b.jsx)(ae,{className:`w-4 h-4 mr-2`}),n(`projectDetail.template.saveAsTemplate`)]})}),Q&&(Q.queued_prints>0||Q.in_progress_prints>0)&&(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(Ie,{className:`w-5 h-5`}),n(`projectDetail.queue.title`)]}),(0,b.jsx)(_,{to:`/queue?project=${k}`,className:`text-sm text-bambu-green hover:underline`,children:n(`projectDetail.queue.viewAll`)})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-4 text-sm`,children:[Q.in_progress_prints>0&&(0,b.jsx)(`span`,{className:`text-yellow-700 dark:text-yellow-400`,children:n(`projectDetail.queue.printing`,{count:Q.in_progress_prints})}),Q.queued_prints>0&&(0,b.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.queue.queued`,{count:Q.queued_prints})})]})]})}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`div`,{className:`flex items-center justify-between mb-4`,children:(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(u,{className:`w-5 h-5`}),n(`projectDetail.prints.title`,{count:Ge?.length||0})]})}),Ke?(0,b.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,b.jsx)(l,{className:`w-6 h-6 animate-spin text-bambu-green`})}):(0,b.jsx)(ze,{archives:Ge||[],t:n})]}),Ve&&(0,b.jsx)(Fe,{t:n,currencySymbol:R,project:{...A,archive_count:Q?.total_archives||0,total_items:Q?.total_items||0,completed_count:Q?.completed_prints||0,failed_count:Q?.failed_prints||0,queue_count:Q?.queued_prints||0,progress_percent:Q?.progress_percent||null,child_count:A.children?.length??0,archives:[]},onClose:()=>w(!1),onSave:e=>z.mutate(e),isLoading:z.isPending}),J.isOpen&&(0,b.jsx)(we,{title:J.title,message:J.message,confirmText:n(`common.delete`),variant:`danger`,onConfirm:J.onConfirm,onCancel:()=>Y(e=>({...e,isOpen:!1}))}),D&&(0,b.jsx)(Ee,{mode:`create`,libraryFileId:D.id,archiveName:D.print_name||D.filename,projectId:k,onClose:()=>O(null),onSuccess:()=>{O(null),d.invalidateQueries({queryKey:[`archives`]}),d.invalidateQueries({queryKey:[`queue`]})}})]})}export{C as ProjectDetailPage};