1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["js/index-DcmnhvKq.js","js/vendor-mui-BhcdUMHY.js","js/vendor-react-9_80szc8.js","js/vendor-firebase-gcvaeGOS.js","js/vendor-charts-DytGfyBM.js","css/index-AyqOnGIm.css","js/index.esm-BWsmbe8i.js"])))=>i.map(i=>d[i]); 2import{u as at,I as S,E as ne,M as ie,a as ot,C as lt,_ as f,F as T}from"./index-DcmnhvKq.js";import{j as e,L as j,T as a,S as x,O as v,A as ct,B as h,z as R,E as V,F as W,w as m,H as U,G as dt,Q as ut,R as ht,I as ve,U as pt}from"./vendor-mui-BhcdUMHY.js";import{u as xt,h as gt,f as mt,r as l}from"./vendor-react-9_80szc8.js";import{f as P}from"./dateFormat-DNzrl98o.js";import{E as ft}from"./EventsTable-B7YwJDxO.js";import"./ScrollX-B1lveYkT.js";import{u as yt}from"./useFirebaseAllFindings-B7WIHI3V.js";import{g as jt,d as vt}from"./useFirebaseFindings-DaS6LUyB.js";import{F as bt,P as be}from"./FindingsStickyBarModal-BjROqZzX.js";import{U as K}from"./UserDisplay-DdDb006V.js";import{H as Ie,a as It}from"./HistoryOutlined-C7jiO3J9.js";import{u as wt}from"./useAuditHistory-fRfQZXiq.js";import{C as Dt,i as Ct,a as St,b as Et}from"./CalendarStyled-CumcsMxi.js";import{T as kt,i as At}from"./index-j8jCwDPF.js";import{n as ae,g as we}from"./issueState-C5MXbz7J.js";import Ft from"./index-CXGymlBT.js";import{D as N}from"./DeleteOutlined-9vwINnlv.js";import{E as De}from"./EyeOutlined-xhVJA5Ye.js";import{E as _t}from"./EnvironmentOutlined-BaZL6YZ-.js";import{D as Ce}from"./DownloadOutlined-CP2bDY5p.js";import"./vendor-firebase-gcvaeGOS.js";import"./vendor-charts-DytGfyBM.js";import"./TablePagination-CLfoOTyV.js";import"./LinearWithLabel-BBLtQxwU.js";import"./getImageUrl-8YN5-ypD.js";import"./MinusOutlined-BpTKCLZT.js";import"./CaretUpOutlined-Bod8Zhyt.js";import"./dataCache-BHBYso3_.js";import"./UnorderedListOutlined-YYgIjJok.js";import"./useFirebaseUsers-CyC3Rmz5.js";import"./CheckOutlined-vemLyd1e.js";import"./ReloadOutlined-CEQEFksD.js";import"./mobileFormStyles-B38K1dbh.js";import"./AdapterDateFns-B_Ynpur6.js";import"./DatePicker-CYy5HxvZ.js";import"./index.esm-BWsmbe8i.js";import"./LeftOutlined-C-_ZnA3d.js";function mr(){const{findings:w,events:D,findingsLoading:E,findingsError:$,currentPage:Se,hasNextPage:Ee,hasPrevPage:ke,goToNextPage:Ae,goToPrevPage:Fe}=yt(),{user:c}=at(),_e=xt(),oe=gt(),[G,Oe]=mt(),[le,z]=l.useState(!1),[L,B]=l.useState(null),[Te,J]=l.useState(null),[Pe,q]=l.useState(!1),[k,Q]=l.useState(null),[Z,b]=l.useState(!1),[i,A]=l.useState(null),[ze,X]=l.useState(!1),[C,Le]=l.useState(null),[Be,F]=l.useState(!1),[H,Y]=l.useState("choose"),[He,ce]=l.useState(!1),[Ot,Me]=l.useState(null),de=l.useRef(!1),_=l.useRef(null),[ue,ee]=l.useState(new Date),[he,Re]=l.useState("dayGridMonth"),{history:Ve,loading:We,error:Ue,fetchHistory:Ke}=wt("issues",c?.organizationId),pe=t=>{Me(t),ce(!0),Ke(t)},g=c&&c.role&&["owner","admin","manager"].includes(c.role.toLowerCase()),xe=c?.role?.toLowerCase()==="member",O=l.useMemo(()=>{if(!xe||!w)return w;const t=c?.id||c?.uid||"",r=new Set;return(D||[]).forEach(s=>{(s.participants||[]).includes(t)&&r.add(s.id)}),w.filter(s=>{const n=s.eventId;return n?r.has(n):!1})},[w,D,xe,c]);l.useEffect(()=>{(async()=>{const r=G.get("issueId"),s=oe.state?.openIssueId||r,n=()=>{if(!r)return;const o=new URLSearchParams(G);o.delete("issueId"),Oe(o,{replace:!0})};if(s&&c?.organizationId){const o=s,d=w.find(u=>u.id===o);if(d){A(d),b(!0),window.history.replaceState({},document.title),n();return}if(!E){try{const u=await f(()=>import("./index-DcmnhvKq.js").then(y=>y.aJ),__vite__mapDeps([0,1,2,3,4,5]));await f(()=>import("./index.esm-BWsmbe8i.js"),__vite__mapDeps([6,0,1,2,3,4,5]));const I=u?.default??u;if(!I?.firestore)return;const p=await I.firestore().collection("issues").doc(c.organizationId).collection("issues").doc(o).get();if(p.exists){const y={id:p.id,...p.data()},je=ae(y.state||y.status||"Open");A({...y,state:je,status:je}),b(!0)}}catch{}window.history.replaceState({},document.title),n()}}})()},[oe.state,G,w,E,c?.organizationId]),l.useEffect(()=>{if(!Z||!i?.attachments?.length||!c?.organizationId)return;const t=new Date(Date.now()+3600*1e3);if(!i.attachments.some(n=>n.signedUrlExpiry?new Date(n.signedUrlExpiry)<=t:!0))return;let s=!1;return(async()=>{try{const n=await Promise.all(i.attachments.map(async o=>{if(!o.s3Path)return o;const d=o.signedUrlExpiry?new Date(o.signedUrlExpiry):null;if(d&&d>t)return o;try{const u=await jt(o.s3Path,c.organizationId,c,86400);return{...o,signedUrl:u,signedUrlExpiry:new Date(Date.now()+864e5).toISOString()}}catch{return o}}));s||A(o=>o&&{...o,attachments:n})}catch{}})(),()=>{s=!0}},[Z,i?.id]);const Ne=()=>{g&&(J(null),Y("choose"),F(!0))},$e=t=>{B({id:t.id,title:t.title,departmentId:t.departmentId}),F(!1),z(!0)},Ge=()=>{B({id:"generic",title:"Generic",departmentId:null}),F(!1),z(!0)},Je=l.useMemo(()=>
2{if(!D)return[];const t=r=>{const s=(r||"").replace(/\s*Gemba Walk\s*$/i,"").trim();return{"Daily Department":"#1890ff","Weekly Leadership Team":"#52c41a","Value Stream":"#fa8c16","Office Walk":"#722ed1",Office:"#722ed1",Executive:"#f5222d","Outside Executive":"#f5222d"}[s]||"#1890ff"};return D.map(r=>{let s=r.start;s instanceof Date?s=s.toISOString():s?.toDate&&(s=s.toDate().toISOString());let n=r.end;n instanceof Date?n=n.toISOString():n?.toDate&&(n=n.toDate().toISOString());const o=t(r.mainCategory);return{id:r.id,title:r.title||"Untitled Event",start:s,end:n,allDay:!1,backgroundColor:o,borderColor:o}})},[D]),qe=()=>{const t=_.current;if(t){const r=t.getApi();r.today(),ee(r.getDate())}},Qe=t=>{const r=_.current;r&&(r.getApi().changeView(t),Re(t))},Ze=()=>{const t=_.current;if(t){const r=t.getApi();r.prev(),ee(r.getDate())}},Xe=()=>{const t=_.current;if(t){const r=t.getApi();r.next(),ee(r.getDate())}},Ye=t=>{const r=t.event.id,s=D.find(n=>n.id===r);s&&$e(s)},M=t=>{if(!g)return;const r=t.eventId||"generic";B({id:r,title:t.eventTitle||"Generic",departmentId:t.eventDepartmentId||t.departmentId}),J(t.id),z(!0)},te=t=>{g&&(Q(t),q(!0))},et=async()=>{if(!(!k||!g))try{const t=await f(()=>import("./index-DcmnhvKq.js").then(d=>d.aJ),__vite__mapDeps([0,1,2,3,4,5]));await f(()=>import("./index.esm-BWsmbe8i.js"),__vite__mapDeps([6,0,1,2,3,4,5]));const r=t?.default??t;if(!r?.firestore)throw new Error("Firestore is unavailable");const s=r.firestore(),n=c?.organizationId;if(!n)return;if(await s.collection("issues").doc(n).collection("issues").doc(k.id).delete(),k.eventId)try{const d=s.collection("events").doc(n).collection("events").doc(k.eventId).collection("findings").doc(k.id);(await d.get()).exists&&await d.delete()}catch{}const{openSnackbar:o}=await f(async()=>{const{openSnackbar:d}=await import("./index-DcmnhvKq.js").then(u=>u.aK);return{openSnackbar:d}},__vite__mapDeps([0,1,2,3,4,5]));o({open:!0,message:"Issue deleted successfully.",variant:"alert",alert:{color:"success"}}),setTimeout(()=>{window.location.reload()},1e3)}catch(t){const{openSnackbar:r}=await f(async()=>{const{openSnackbar:s}=await import("./index-DcmnhvKq.js").then(n=>n.aK);return{openSnackbar:s}},__vite__mapDeps([0,1,2,3,4,5]));r({open:!0,message:t.message||"Failed to delete issue.",variant:"alert",alert:{color:"error"}})}finally{q(!1),Q(null)}},ge=()=>{q(!1),Q(null)},me=async t=>{if(!i||!g||!c?.organizationId)return;const r=i.attachments[t];if(r)try{const s=await f(()=>import("./index-DcmnhvKq.js").then(p=>p.aJ),__vite__mapDeps([0,1,2,3,4,5]));await f(()=>import("./index.esm-BWsmbe8i.js"),__vite__mapDeps([6,0,1,2,3,4,5]));const n=s?.default??s;if(!n?.firestore)throw new Error("Firestore is unavailable");const d=n.firestore().collection("issues").doc(c.organizationId).collection("issues").doc(i.id),u=r.s3Key||r.s3Path;if(u)try{await vt(u,c.organizationId,c)}catch{}const I=i.attachments.filter((p,y)=>y!==t);await d.update({attachments:I,hasAttachments:I.length>0,attachmentCount:I.length,updatedAt:n.firestore.FieldValue.serverTimestamp()}),A(p=>p&&{...p,attachments:I});const{openSnackbar:ye}=await f(async()=>{const{openSnackbar:p}=await import("./index-DcmnhvKq.js").then(y=>y.aK);return{openSnackbar:p}},__vite__mapDeps([0,1,2,3,4,5]));ye({open:!0,message:"Attachment deleted.",variant:"alert",alert:{color:"success"}})}catch{const{openSnackbar:n}=await f(async()=>{const{openSnackbar:o}=await import("./index-DcmnhvKq.js").then(d=>d.aK);return{openSnackbar:o}},__vite__mapDeps([0,1,2,3,4,5]));n({open:!0,message:"Failed to delete attachment.",variant:"alert",alert:{color:"error"}})}},re=t=>{A(t),b(!0)},tt=(t,r)=>{Le({url:t,name:r}),X(!0)},rt=t=>{if(t===0)return"0 Bytes";const r=1024,s=["Bytes","KB","MB","GB"],n=Math.floor(Math.log(t)/Math.log(r));return parseFloat((t/Math.pow(r,n)).toFixed(2))+" "+s[n]},st=t=>t?t.startsWith("image/")?e.jsx(be,{style:{color:"#4caf50"}}):t==="application/pdf"?e.jsx(T,{style:{color:"#f44336"}}):t.includes("document")||t.includes("word")?e.jsx(T,{style:{color:"#1976d2"}}):t.includes("spreadsheet")||t.includes("excel")?e.jsx(T,{style:{color:"#4caf50"}}):e.jsx(T,{style:{color:"#666"}}):e.jsx(T,{}),se=t=>{switch(t){case"defects":return"error";
2case"overproduction":return"warning";case"waiting":return"success";case"not-utilized-talent":return"info";case"transportation":return"primary";case"inventory":return"secondary";case"motion":return"default";case"extra-processing":return"warning";case"other":return"default";default:return"default"}},nt=l.useMemo(()=>[{header:"Issue Type",accessorKey:"mainCategory",id:"mainCategory",filterFn:"textSearch",cell:({row:t})=>{const r=t.original.category||"defects";return e.jsx(j,{label:r.toUpperCase(),color:se(r),size:"small"})}},{header:"Title",accessorKey:"title",id:"title",filterFn:"textSearch",cell:({row:t})=>{const r=t.original.title||"";return e.jsx(a,{variant:"subtitle2",sx:{maxWidth:220,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r||"-"})}},{header:"Walk",accessorKey:"eventTitle",filterFn:"textSearch",enableHiding:!0,meta:{initiallyHidden:!0},cell:({getValue:t})=>e.jsx(a,{variant:"body2",children:t()||"-"})},{header:"Department",accessorKey:"department",id:"department",filterFn:"departmentFilter",cell:({row:t})=>{const r=t.original.eventDepartment,s=t.original.eventDepartmentId,n=!r||r===s||r&&r.length>15&&/^[a-zA-Z0-9]+$/.test(r);return e.jsx(j,{label:n?"-":r,color:"secondary",size:"small",variant:"outlined"})}},{header:"State",accessorKey:"state",filterFn:"stateFilter",cell:({getValue:t,row:r})=>{const s=ae(t()||r.original?.status||"Open");return e.jsx(j,{label:s,color:we(s),size:"small"})}},{header:"Description",accessorKey:"description",filterFn:"textSearch",enableHiding:!0,meta:{initiallyHidden:!0},cell:({getValue:t})=>{const n=(t()||"").replace(/<[^>]*>/g,"").split(/\s+/).filter(u=>u.length>0),o=n.slice(0,10).join(" "),d=n.length>10?`${o}...`:o;return e.jsx(a,{variant:"body2",sx:{maxWidth:300,overflow:"hidden",textOverflow:"ellipsis"},children:d||"-"})}},{header:"Walk Date",accessorKey:"eventDate",filterFn:"dateRangeFilter",enableHiding:!0,meta:{initiallyHidden:!0},cell:({getValue:t})=>{const r=t();return e.jsx(a,{variant:"body2",children:P(r)})}},{header:"Location",accessorKey:"location",filterFn:"textSearch",enableHiding:!0,meta:{initiallyHidden:!0},cell:({getValue:t})=>e.jsx(a,{variant:"body2",children:t()||"-"})},{header:"Created By",accessorKey:"createdBy",id:"createdBy",filterFn:"textSearch",enableHiding:!0,meta:{initiallyHidden:!0},cell:({row:t})=>e.jsx(K,{userId:t.original.createdBy})},{header:"Last Modified By",accessorKey:"lastModifiedBy",id:"lastModifiedBy",filterFn:"textSearch",enableHiding:!0,meta:{initiallyHidden:!0},cell:({row:t})=>{const r=t.original.lastModifiedBy;return r?e.jsx(K,{userId:r}):e.jsx(a,{variant:"body2",color:"text.secondary",children:"â"})}},{header:"Actions",meta:{className:"cell-center"},disableSortBy:!0,cell:({row:t})=>{const r=t.original;return e.jsxs(x,{direction:"row",sx:{alignItems:"center",justifyContent:"center",gap:.5},children:[e.jsx(v,{title:"View History",children:e.jsx(S,{color:"secondary",onClick:s=>{s.stopPropagation(),pe(r.id)},children:e.jsx(Ie,{})})}),e.jsx(v,{title:"View Issue Details",children:e.jsx(S,{color:"info",onClick:s=>{s.stopPropagation(),re(r)},children:e.jsx(De,{})})}),g?e.jsxs(e.Fragment,{children:[e.jsx(v,{title:"Edit Issue",children:e.jsx(S,{color:"primary",onClick:s=>{s.stopPropagation(),M(r)},children:e.jsx(ne,{})})}),e.jsx(v,{title:"Delete Issue",children:e.jsx(S,{color:"error",onClick:s=>{s.stopPropagation(),te(r)},children:e.jsx(N,{})})})]}):e.jsx(v,{title:"Only Admins and Managers can edit issues",children:e.jsx("span",{children:e.jsx(S,{color:"primary",disabled:!0,children:e.jsx(ne,{})})})})]})}}],[g,M,te,re,se]),it=l.useMemo(()=>O?O.map(t=>({...t,mainCategory:t.category,department:t.eventDepartment})):[],[O]);!E&&!$&&(de.current=!0);const fe=!de.current;return E&&fe?e.jsx(ie,{title:"Issues",content:!1,children:e.jsx(x,{sx:{p:3,alignItems:"center"},children:e.jsx(a,{variant:"body2",color:"text.secondary",children:"Loading issues..."})})}):$&&fe?e.jsx(ie,{title:"Issues",content:!1,children:e.jsxs(x,{sx:{p:3,alignItems:"center"},children:[e.jsx(a,{color:"error",variant:"h6",children:"Error loading issues"}),e.jsx(a,{variant:"body2",color:"text.secondary",children:$.message||"Unable to fetch issues from database"})]})}):e.jsxs(e.Fragment,{children:[e.jsxs(ie,{title:"Issues",content:!1,secondary:g&&e.jsx(h,{variant:"contained",startIcon:e.jsx(ot,{}),"data-tutorial":"create-issue",onClick:Ne,children:"Add Issue"}),children:[e.jsx(ct,{severity:"info",sx:{m:2,mb:0},children:"Track problems found during walks or generic issues. Use AI-powered Speech-To-Text to de
2scribe an issue and add photos/videos."}),O&&O.length>0?e.jsx(ft,{data:it,columns:nt,loading:E,disableExpand:!0,serverPagination:{currentPage:Se-1,hasNextPage:Ee,hasPrevPage:ke,goToNextPage:Ae,goToPrevPage:Fe},onRowClick:t=>{g?M(t):re(t)}}):e.jsxs(x,{sx:{p:3,alignItems:"center"},children:[e.jsx(a,{variant:"h6",color:"text.secondary",children:"No issues found"}),e.jsx(a,{variant:"body2",color:"text.secondary",children:"Issues will appear here from your walks"})]})]}),e.jsxs(R,{open:Be,onClose:()=>F(!1),maxWidth:H==="calendar"?"lg":"sm",fullWidth:!0,"aria-labelledby":"event-selection-dialog-title",children:[e.jsx(V,{id:"event-selection-dialog-title",children:H==="choose"?"Create New Issue":"Select Walk from Calendar"}),e.jsx(W,{children:H==="choose"?e.jsxs(x,{spacing:2,sx:{pt:1},children:[e.jsx(a,{variant:"body2",color:"text.secondary",children:"Choose the type of issue to create:"}),e.jsx(h,{variant:"outlined",size:"large",onClick:Ge,sx:{justifyContent:"flex-start",textAlign:"left",textTransform:"none",py:2,width:"100%"},children:e.jsxs(x,{children:[e.jsx(a,{variant:"subtitle1",children:"Generic Issue"}),e.jsx(a,{variant:"caption",color:"text.secondary",children:"Create an issue not linked to a specific walk"})]})}),e.jsx(h,{variant:"contained",size:"large",onClick:()=>Y("calendar"),sx:{justifyContent:"flex-start",textAlign:"left",textTransform:"none",py:2,width:"100%"},children:e.jsxs(x,{children:[e.jsx(a,{variant:"subtitle1",sx:{color:"inherit"},children:"Walk Issue"}),e.jsx(a,{variant:"caption",sx:{color:"inherit",opacity:.8},children:"Link this issue to a specific walk on the calendar"})]})})]}):e.jsx(m,{sx:{minHeight:500},children:e.jsxs(Dt,{children:[e.jsx(kt,{date:ue,view:he,onClickNext:Xe,onClickPrev:Ze,onClickToday:qe,onChangeView:Qe}),e.jsx(Ft,{weekends:!0,editable:!1,droppable:!1,selectable:!1,events:Je,eventClick:Ye,ref:_,rerenderDelay:10,initialDate:ue,initialView:he,dayMaxEvents:3,eventDisplay:"block",headerToolbar:!1,height:500,plugins:[Ct,St,At,Et]})]})})}),e.jsxs(U,{children:[H==="calendar"&&e.jsx(h,{onClick:()=>Y("choose"),color:"inherit",children:"Back"}),e.jsx(h,{onClick:()=>F(!1),color:"inherit",children:"Cancel"})]})]}),le&&L&&e.jsx(bt,{open:le,onClose:()=>{z(!1),B(null),J(null)},eventId:L.id,eventTitle:L.title,eventDepartmentId:L.departmentId,findingId:Te}),e.jsxs(R,{open:Pe,onClose:ge,"aria-labelledby":"delete-issue-dialog-title","aria-describedby":"delete-issue-dialog-description",children:[e.jsx(V,{id:"delete-issue-dialog-title",children:"Delete Issue"}),e.jsx(W,{children:e.jsx(dt,{id:"delete-issue-dialog-description",children:"Are you sure you want to delete this issue? This action cannot be undone."})}),e.jsxs(U,{children:[e.jsx(h,{onClick:ge,color:"primary",children:"Cancel"}),e.jsx(h,{onClick:et,color:"error",variant:"contained",children:"Delete"})]})]}),e.jsxs(R,{open:Z,onClose:()=>b(!1),maxWidth:"md",fullWidth:!0,"aria-labelledby":"view-finding-dialog-title",children:[e.jsxs(V,{id:"view-finding-dialog-title",sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(De,{style:{color:"#1976d2"}}),"View Issue Details"]}),e.jsx(W,{children:i&&e.jsxs(x,{spacing:3,children:[e.jsxs(m,{children:[e.jsx(a,{variant:"h6",gutterBottom:!0,children:i.title}),e.jsxs(x,{direction:"row",spacing:1,sx:{mb:2,flexWrap:"wrap"},children:[e.jsx(j,{icon:e.jsx(_t,{}),label:i.location||"No location",size:"small",variant:"outlined",color:"default"}),e.jsx(j,{label:i.priority||"Normal",size:"small",color:i.priority==="High"?"error":i.priority==="Medium"?"warning":"success"}),e.jsx(j,{label:i.category||"General",size:"small",variant:"outlined",color:se(i.category||"defects")}),e.jsx(j,{label:ae(i.state||i.status||"Open"),size:"small",color:we(i.state||i.status||"Open")}),e.jsx(j,{icon:e.jsx(lt,{}),label:P(i.createdAt),size:"small",variant:"outlined"})]})]}),e.jsxs(m,{children:[e.jsx(a,{variant:"subtitle2",gutterBottom:!0,children:"Event Information"}),e.jsxs(x,{spacing:1,children:[e.jsxs(a,{variant:"body2",children:[e.jsx("strong",{children:"Event:"})," ",i.eventTitle?e.jsx(h,{size:"small",onClick:()=>_e(`/apps/events/reporting/${i.eventId}`),sx:{textTransform:"none",p:0,minWidth:"auto",verticalAlign:"baseline"},children:i.eventTitle}):"N/A"]}),e.jsxs(a,{variant:"body2",children:[e.jsx("strong",{children:"Event Date:"})," ",P(i.eventDate)]}),e.jsxs(a,{variant:"body2",children:[e.jsx("strong",{children:"Department:"})," ",i.eventDepartment||"N/A"]})]})]}),e.jsxs(m,{children:[e.jsx(a,{variant:"subtitle2",gutterBottom:!0,children:"Description"}),e.jsx(a,{variant:"body2",color:"text.secondary",children:i.description?i.description.replace(/<[^>]*>/g,""):"No description provided"})]}),e.jsxs(m,{children:[e.jsx(a,{variant:"subtitle2",gutterBottom:!0,children:"Audit Information"}),e.jsxs(x,{spacing:1,children:[e.jsxs(a,{variant:"body2",component:"div",children:[e.jsx("strong",{children:"Created by:"}
2)," ",e.jsx(K,{userId:i.createdBy,variant:"span"})]}),e.jsxs(a,{variant:"body2",children:[e.jsx("strong",{children:"Created on:"})," ",P(i.createdAt)]}),i.updatedAt&&e.jsxs(e.Fragment,{children:[e.jsxs(a,{variant:"body2",component:"div",children:[e.jsx("strong",{children:"Last updated by:"})," ",e.jsx(K,{userId:i.updatedBy,variant:"span"})]}),e.jsxs(a,{variant:"body2",children:[e.jsx("strong",{children:"Last updated:"})," ",P(i.updatedAt)]})]})]})]}),i.comments&&i.comments.length>0&&e.jsxs(m,{children:[e.jsxs(a,{variant:"subtitle2",gutterBottom:!0,children:["Comments (",i.comments.length,")"]}),e.jsx(x,{spacing:1.5,children:i.comments.map((t,r)=>{const s=t.createdAt?.toDate?t.createdAt.toDate():t.createdAt instanceof Date?t.createdAt:t.createdAt?.seconds?new Date(t.createdAt.seconds*1e3):null,n=t.updatedAt?.toDate?t.updatedAt.toDate():t.updatedAt instanceof Date?t.updatedAt:t.updatedAt?.seconds?new Date(t.updatedAt.seconds*1e3):null,o=n&&s&&n.getTime()!==s.getTime();return e.jsxs(m,{sx:{p:1.5,border:"1px solid",borderColor:"divider",borderRadius:1,bgcolor:"grey.50"},children:[e.jsxs(x,{direction:"row",justifyContent:"space-between",alignItems:"center",sx:{mb:.5},children:[e.jsx(a,{variant:"subtitle2",sx:{fontWeight:600},children:t.authorName||"Unknown"}),e.jsxs(a,{variant:"caption",color:"text.secondary",children:[s?s.toLocaleString():"Unknown date",o&&" (edited)"]})]}),e.jsx(a,{variant:"body2",sx:{whiteSpace:"pre-wrap"},children:t.text})]},t.id||r)})})]}),i.attachments&&i.attachments.length>0&&e.jsxs(m,{children:[e.jsxs(a,{variant:"subtitle2",gutterBottom:!0,sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(be,{style:{color:"#1976d2"}}),"Attached Files (",i.attachments.length,")"]}),i.attachments.filter(t=>t.type&&t.type.startsWith("image/")).length>0&&e.jsx(ut,{cols:3,rowHeight:164,sx:{mb:2},children:i.attachments.map((t,r)=>({attachment:t,origIdx:r})).filter(({attachment:t})=>t.type&&t.type.startsWith("image/")).map(({attachment:t,origIdx:r})=>{const s=t.signedUrl||t.url||t.thumbnailUrl;return s?e.jsxs(ht,{sx:{position:"relative"},children:[e.jsx(m,{component:"img",src:s,alt:t.name,loading:"lazy",sx:{cursor:"pointer",borderRadius:1,objectFit:"cover",height:"100%","&:hover":{opacity:.8}},onClick:()=>tt(s,t.name),onError:n=>{n.target.onerror=null,n.target.src="",n.target.alt="Image unavailable",n.target.style.background="#f0f0f0",n.target.style.display="flex"}}),g&&e.jsx(v,{title:"Delete attachment",children:e.jsx(ve,{size:"small",onClick:()=>me(r),sx:{position:"absolute",top:4,right:4,bgcolor:"rgba(255,255,255,0.85)","&:hover":{bgcolor:"error.lighter"}},children:e.jsx(N,{style:{fontSize:14,color:"#f44336"}})})})]},t.s3Key||`attachment-${r}`):null})}),i.attachments.map((t,r)=>({attachment:t,origIdx:r})).filter(({attachment:t})=>!t.type||!t.type.startsWith("image/")).map(({attachment:t,origIdx:r})=>e.jsxs(m,{sx:{display:"flex",alignItems:"center",p:1,border:"1px solid",borderColor:"grey.200",borderRadius:1,bgcolor:"grey.50",mb:1},children:[st(t.type),e.jsxs(m,{sx:{flex:1,minWidth:0,ml:1},children:[e.jsx(a,{variant:"body2",noWrap:!0,children:t.name}),e.jsx(a,{variant:"caption",color:"text.secondary",children:rt(t.size)})]}),(t.signedUrl||t.url)&&e.jsx(v,{title:"Download file",children:e.jsx(S,{size:"small",component:"a",href:t.signedUrl||t.url,target:"_blank",rel:"noopener noreferrer",sx:{ml:1},children:e.jsx(Ce,{})})}),g&&e.jsx(v,{title:"Delete attachment",children:e.jsx(ve,{size:"small",onClick:()=>me(r),sx:{ml:.5},children:e.jsx(N,{style:{fontSize:14,color:"#f44336"}})})})]},t.s3Key||`non-image-${r}`))]})]})}),e.jsxs(U,{children:[e.jsx(h,{onClick:()=>b(!1),color:"inherit",children:"Close"}),i&&e.jsx(h,{startIcon:e.jsx(Ie,{}),onClick:()=>pe(i.id),color:"secondary",variant:"outlined",children:"View History"}),i&&g&&e.jsxs(e.Fragment,{children:[e.jsx(h,{startIcon:e.jsx(ne,{}),onClick:()=>{b(!1),M(i)},color:"primary",variant:"outlined",children:"Edit"}),e.jsx(h,{startIcon:e.jsx(N,{}),onClick:()=>{b(!1),te(i)},color:"error",variant:"outlined",children:"Delete"})]})]})]}),e.jsxs(R,{open:ze,onClose:()=>X(!1),maxWidth:"lg",fullWidth:!0,"aria-labelledby":"image-viewer-dialog-title",children:[e.jsx(V,{id:"image-viewer-dialog-title",children:C?.name||"Image Viewer"}),e.jsx(W,{sx:{display:"flex",justifyContent:"center",p:2},children:C&&e.jsx(pt,{component:"img",image:C.url,alt:C.name,sx:{maxWidth:"100%",maxHeight:"70vh",objectFit:"contain",borderRadius:1}})}),e.jsxs(U,{children:[e.jsx(h,{onClick:()=>X(!1),color:"inherit",children:"Close"}),C&&e.jsx(h,{startIcon:e.jsx(Ce,{}),component:"a",href:C.url,target:"_blank",rel:"noopener noreferrer",color:"primary",variant:"outlined",children:"Download"})]})]}),e.jsx(It,{open:He,onClose:()=>ce(!1),history:Ve,loading:We,error:Ue,title:"Issue History"})]})}
2export{mr as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.