1import{u as I,r as x,j as s,I as T,B as v,F as b,cy as E,cz as O,bL as R,q as z,n as M}from"./elements-DVh2jUIM.js";import{M as _}from"./ModernPortalPage-C8UaH3aE.js";import{A as D}from"./authorization-CE7gncHO.js";import{M as G}from"./MobileCardButton-CebfhP3v.js";import{u as K,g as Q,a as U}from"./useMobileRedesignActive-BZoYJS32.js";import{p as P,a2 as A,B as f,G as H,am as V}from"./index-DeQvL4I7.js";import{u as L}from"./useMutation-CfDMVIpo.js";import"./useAuthorization-D7B2eQha.js";import"./useIsMobile-Davbtvz5.js";import"./useMobileRedesignBoardPages-CLS9im5M.js";import"./grids-DXrfAsUA.js";import"./startOfDay-AazlW55I.js";const h={all:["boardReports"],permissions:e=>[...h.all,"permissions",e],list:e=>[...h.all,"list",e]},J=e=>P({queryKey:h.permissions(e),queryFn:()=>f.getBoardReportPermissions(e),enabled:e>0}),W=e=>P({queryKey:h.list(e),queryFn:()=>f.getBoardReports(e),enabled:e>0}),X=e=>L({mutationFn:async({description:r,...o})=>({url:(await f.createBoardReportToken(e,o)).reportUrl,fileName:`${$(r)}.pdf`}),onSuccess:({url:r,fileName:o})=>{A({url:r,fileName:o},()=>{window.open(r,"reportviewer","width=900,height=700,noopener,noreferrer")})}}),Y=e=>L({mutationFn:async({reportId:r,description:o})=>({url:(await f.createBoardReportToken(e,{reportId:r})).reportUrl,fileName:`${$(o)}.pdf`}),onSuccess:({url:r,fileName:o})=>{A({url:r,fileName:o},()=>{const t=document.createElement("a");t.href=r,t.download=o,document.body.appendChild(t),t.click(),document.body.removeChild(t)})}}),Z=e=>e.reduce((r,o)=>{const t=o.categoryDescription;return r[t]||(r[t]=[]),r[t].push(o),r},{});function $(e){return e.replace(/[\\/:*?"<>|]/g,"-").trim()||"report"}const ee=()=>{const{t:e}=I(),{isMobileRedesignActive:r}=K(),o=H(),t=(o==null?void 0:o.id)??0,[n,c]=x.useState(""),{data:l,isLoading:p}=J(t),{data:N=[],isLoading:k}=W(t),y=X(t),w=Y(t),g=x.useMemo(()=>Z(N),[N]),j=x.useMemo(()=>{if(!n.trim())return g;const a=n.toLowerCase().trim(),i={};return Object.entries(g).forEach(([d,u])=>{const m=u.filter(q=>q.description.toLowerCase().includes(a)||d.toLowerCase().includes(a));m.length>0&&(i[d]=m)}),i},[g,n]),C=x.useMemo(()=>Object.keys(j).sort(),[j]),F=async a=>{try{await y.mutateAsync({reportId:a.reportId,description:a.description})}catch(i){console.error("Failed to view report:",i),M({type:"error",title:e("board.reports.error"),message:e("board.reports.viewError")})}},S=async a=>{try{await w.mutateAsync({reportId:a.reportId,description:a.description})}catch(i){console.error("Failed to download report:",i),M({type:"error",title:e("board.reports.error"),message:e("board.reports.downloadError")})}},B=p||k;return l&&!l.canView?s.jsx("div",{className:"w-full bg-base-fill rounded-xl px-6 py-6",children:s.jsx("div",{className:"text-center py-12 text-gray-500",children:e("board.reports.noPermission")})}):s.jsxs("div",{...Q(r,"w-full bg-base-fill rounded-xl px-9 py-6 max-mobile:px-4 space-y-6 relative"),children:[s.jsxs("div",{className:"flex justify-end items-center gap-2",children:[s.jsx(T,{type:"text",qaAttribute:"reports-search",placeholder:e("main.common.search"),className:"w-full mobile:w-96",value:n,onChange:a=>c(a.target.value)}),s.jsx(v,{variant:"primary",className:"h-9",children:s.jsx(b,{icon:E,className:"text-white"})})]}),s.jsx("div",{className:"space-y-4",children:C.length===0&&!B?s.jsx("div",{className:"text-center py-12 text-gray-500",children:e(n?"board.reports.noSearchResults":"board.reports.noReports")}):C.map((a,i)=>s.jsx(O,{title:a,defaultOpen:!!n.trim()||i===0,children:s.jsx("div",{className:"space-y-3",children:j[a].map(d=>{var u,m;return s.jsx(se,{report:d,useMobileCardLayout:r,onView:F,onDownload:S,isViewing:y.isPending&&((u=y.variables)==null?void 0:u.reportId)===d.reportId,isDownloading:w.isPending&&((m=w.variables)==null?void 0:m.reportId)===d.reportId},d.reportId)})})},n.trim()?`${a}-search`:a))}),B&&s.jsx("div",{className:"absolute inset-0 bg-white/50 flex items-center justify-center rounded-xl",children:s.jsx(b,{icon:R,className:"w-8 h-8 text-primary animate-spin"})})]})},se=({report:e,useMobileCardLayout:r,onView:o,onDownload:t,isViewing:n,isDownloading:c})=>{const{t:l}=I();
1if(r){const p=!!e.fileName;return s.jsx("div",{className:`flex items-center gap-3 px-4 py-3 ${U}`,children:s.jsx(G,{onClick:()=>{p?c||t(e):n||o(e)},"aria-label":p?`${l("board.reports.download")}: ${e.description}`:`${l("board.reports.view")}: ${e.description}`,className:"flex-1","data-qa":p?`report-download-${e.reportId}`:`report-view-${e.reportId}`,buttonClassName:z((p?c:n)&&"opacity-60 cursor-not-allowed"),children:s.jsxs("div",{className:"flex-1 flex flex-col gap-1 min-w-0",children:[s.jsx("span",{className:"text-base text-base-header break-words",children:e.description}),e.toolTip&&s.jsx("span",{className:"text-sm text-gray-500 break-words",children:e.toolTip})]})})})}return s.jsxs("div",{className:"flex items-center justify-between gap-3 py-3 border-b border-base-border last:border-b-0 max-mobile:flex-col max-mobile:items-start",children:[s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx("span",{className:"text-base text-base-header",children:e.description}),e.toolTip&&s.jsx("span",{className:"text-sm text-gray-500",children:e.toolTip})]}),s.jsxs("div",{className:"flex items-center gap-2 max-mobile:w-full max-mobile:justify-end",children:[s.jsx(v,{variant:"passiveOutline",size:"sm",onClick:()=>o(e),disabled:n,"data-qa":`report-view-${e.reportId}`,children:n?s.jsx(b,{icon:R,className:"animate-spin"}):l("board.reports.view")}),e.fileName&&s.jsx(v,{variant:"passiveOutline",size:"sm",onClick:()=>t(e),disabled:c,"data-qa":`report-download-${e.reportId}`,children:c?s.jsx(b,{icon:R,className:"animate-spin"}):l("board.reports.download")})]})]})},xe={title:"Reports",showPropertySelector:!0,showAi:!0,redesignPage:"reportsPage",redesignHandle:{customContentId:["Reports","Board_v2"]}};function be(){const e=V("reportsPage");return s.jsx(D,{controller:"Board_v2",action:"Reports",children:e?s.jsx(ee,{}):s.jsx(_,{action:"Reports",controller:"Board_v2"})})}export{be as Component,xe as handle};
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.