1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3149,6919],{20067:function(){},72061:function(){},86431:function(e,t,r){"use strict";r.r(t),r.d(t,{CustomReportsTab:function(){return tk}});var n=r(57437),l=r(2265),i=r(99376),o=r(23738),a=r(55972),s=r(62878),d=r(25964),c=r(16325),u=r(16919),p=r(53739),f=r(15048),v=r(27147),x=r(72643),h=r(54891),m=r(1098),g=r(8799),b=r(74283),y=r(14803),j=r(8932),k=r(80778),w=r(52618),S=r(17166),C=r(10353),z=r(56562),M=r(41119),I=r(35617),F=r(20562),A=r(19150),R=r(8940),T=r(39888),D=r(2093),Z=r(11066),E=r(45681),B=r(72912),O=r(54887),N=r(15728),L=r(88434),W=r(5840),P=r(11466),U=r(18753),H=r(1192),G=r(50607),V=r(81002),Q=r(73283),_=r(10887),Y=r(46297),q=r(11491);function K(e){return!e||!e.facilityIds||0===e.facilityIds.length}var $=r(72796),J=r(39469);let X=l.useLayoutEffect;function ee(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"left",r=(0,l.useRef)(null),n=(0,l.useRef)(null),[i,o]=(0,l.useState)({top:-9999,left:-9999}),[a,s]=(0,l.useState)(!1),d=(0,l.useCallback)(()=>{var e,l,i,a;let d=r.current;if(!d)return;let c=d.getBoundingClientRect(),u=function(e){var t;for(let r=null!==(t=null==e?void 0:e.parentElement)&&void 0!==t?t:null;r&&r!==document.body;r=r.parentElement){let{overflow:e,overflowY:t,overflowX:n}=getComputedStyle(r);if(/(auto|scroll|overlay)/.test(e+t+n))return r.getBoundingClientRect()}return null}(d);s(!!u&&(c.bottom<u.top||c.top>u.bottom||c.right<u.left||c.left>u.right));let p=null!==(i=null===(e=n.current)||void 0===e?void 0:e.offsetHeight)&&void 0!==i?i:0,f=null!==(a=null===(l=n.current)||void 0===l?void 0:l.offsetWidth)&&void 0!==a?a:280,v=window.innerHeight-c.bottom,x=c.top,h=p+8>v&&x>v?c.top-p-4:c.bottom+4,m="right"===t?c.right-f:c.left;m+f>window.innerWidth-8&&(m=window.innerWidth-f-8),m<8&&(m=8),o({top:Math.max(8,h),left:m})},[t]);return(0,l.useEffect)(()=>{let t=t=>{n.current&&n.current.contains(t.target)||e()},r=t=>{"Escape"===t.key&&e()},l=e=>{n.current&&n.current.contains(e.target)||d()};return document.addEventListener("pointerdown",t,!0),document.addEventListener("keydown",r),document.addEventListener("scroll",l,!0),window.addEventListener("resize",d),()=>{document.removeEventListener("pointerdown",t,!0),document.removeEventListener("keydown",r),document.removeEventListener("scroll",l,!0),window.removeEventListener("resize",d)}},[e,d]),X(()=>{d()},[d]),X(()=>{let e=n.current;if(!e||"undefined"==typeof ResizeObserver)return;let t=new ResizeObserver(()=>d());return t.observe(e),()=>t.disconnect()},[d]),{anchorRef:r,boxRef:n,pos:i,clipped:a}}function et(e,t){return"percentage"===t.kind?"".concat(Math.round(100*e)/100,"%"):e.toFixed(t.decimals)}let er={value:"Value",comparison:"Comparison",deviation:"Deviation"},en={value:"CY",comparison:"PY",deviation:"Î%"};function el(e,t){return null==e?"deviation"===t?"-":"NO DATA":"deviation"===t?"".concat(e>=0?"+":"").concat(e.toFixed(1),"%"):(0,_.fmtCompact)(String(e))}function ei(e){return{...e,filter:e.filter?{...e.filter,months:e.filter.months?[...e.filter.months]:void 0,facilityIds:e.filter.facilityIds?[...e.filter.facilityIds]:void 0}:void 0}}function eo(e,t){var r;return null!==(r=e[t])&&void 0!==r?r:"FY index ".concat(t)}function ea(e,t){if(!e)return null;let r=[];return null!=e.fyIndex&&0!==e.fyIndex&&r.push(eo(t,e.fyIndex)),e.months&&e.months.length&&e.months.length<12&&r.push("".concat(e.months.length,"mo")),e.facilityIds&&e.facilityIds.length&&r.push("".concat(e.facilityIds.length," fac")),r.length?r.join(" \xb7 "):null}function es(e,t,r){var n;let l=eo(r,null!==(n=null==e?void 0:e.fyIndex)&&void 0!==n?n:0),i=(null==e?void 0:e.months)&&e.months.length&&e.months.length<12?e.months.map(e=>E.gg[e]).join(", "):"Full year",o="All facilities";if((null==e?void 0:e.facilityIds)&&e.facilityIds.length){let r=t.filter(t=>e.facilityIds.includes(t.id)).map(e=>e.name);o=r.length<=3?r.join(", "):"".concat(r.length," facilities")}return"".concat(l," \xb7 ").concat(i," \xb7 ").concat(o)}let ed={"#PARSE":"This formula couldn't be read - check for a typo or a missing operator.","#NAME":"Unknown function name - pick one from the Calculate list (SUM, AVG, ROUND, â¦).","#ARGS":"Wrong number of inputs for this function - check how many values it needs.","#CIRCULAR":"This cell refers back to itself (directly or via another cell).","#DEPTH":"The formula chain is too deep to calculate.","#NAN":"The result isn't a number - check for text or an empty cell in the formula.","#NUM":"The result isn't a finite number (e.g. dividing by zero).",no_value:"No value for this metric under the current filter.",not_refreshed:"This cell hasnât been refreshed yet - use Refresh values to pull real numbers."};function ec(e){var t,r,i,o;let{sheet:a,onChange:s,readOnly:d,metricOptions:u,facilityOptions:v,fyLabels:x,resolvedValues:h,valuesFetchedAt:m,viewFilterable:g,viewColFilters:y,viewRowFilters:j,onViewColFilterChange:F,onViewRowFilterChange:A,viewFilterPeriodEnabled:R,viewFilterLoading:T}=e,D=(0,l.useRef)(null),[Z,E]=(0,l.useState)({r:0,c:0}),[B,O]=(0,l.useState)({r:0,c:0}),[Q,$]=(0,l.useState)(null),[X,ee]=(0,l.useState)(""),[en,eo]=(0,l.useState)(null),[ec,ef]=(0,l.useState)(""),[ew,eM]=(0,l.useState)(!1),[eI,eF]=(0,l.useState)(null),[eA,eR]=(0,l.useState)(null),[eT,eD]=(0,l.useState)(null),[eZ,eE]=(0,l.useState)(!1),[eB,eO]=(0,l.useState)(!1),[eN,eL]=(0,l.useState)(null),[eW,eP]=(0,l.useState)(""),[eU,eH]=(0,l.useState)(null),[eG,eV]=(0,l.useState)(""),[eQ,e_]=(0,l.useState)(null),[eY,eq]=(0,l.useState)(null),[eK,e$]=(0,l.useState)(null),[eJ,eX]=(0,l.useState)(null),[e0,e1]=(0,l.useState)(null),[e2,e6]=(0,l.useState)(null),[e3,e4]=(0,l.useState)(null),[e8,e5]=(0,l.useState)(null),e9=(0,l.useRef)(!1),e7=(0,l.useRef)(null),te=(0,l.useRef)(null),[tt,tr]=(0,l.useState)(null),[tn,tl]=(0,l.useState)(!1),ti=(0,Y.Qk)({col:Z.c,row:Z.r}),to=a.cells[ti],ta={r1:Math.min(Z.r,B.r),c1:Math.min(Z.c,B.c),r2:Math.max(Z.r,B.r),c2:Math.max(Z.c,B.c)},ts=ta.r1!==ta.r2||ta.c1!==ta.c2,td=(0,l.useMemo)(()=>{var e;return null!==(e=a.hiddenCols)&&void 0!==e?e:[]},[a.hiddenCols]),tc=(0,l.useMemo)(()=>{var e;return null!==(e=a.hiddenRows)&&void 0!==e?e:[]},[a.hiddenRows]),[tu,tp]=(0,l.useState)(void 0),tf=(0,l.useRef)(h);h!==tf.current&&(tf.current=h,void 0!==tu&&tp(void 0));let tv=null!=tu?tu:h,tx=(0,l.useMemo)(()=>{var e;return null!==(e=a.merges)&&void 0!==e?e:[]},[a.merges]),th=(0,l.useMemo)(()=>{var e;return null!==(e=a.headerMerges)&&void 0!==e?e:[]},[a.headerMerges]),tm=(0,l.useMemo)(()=>Array.from({length:a.cols},(e,t)=>t).filter(e=>!td.includes(e)),[a.cols,td]),tg=(0,l.useMemo)(()=>Array.from({length:a.rows},(e,t)=>t).filter(e=>!tc.includes(e)),[a.rows,tc]);(0,l.useEffect)(()=>
1{if(!tn)return;let e=setTimeout(()=>tl(!1),3500);return()=>clearTimeout(e)},[tn]),(0,l.useEffect)(()=>{let e=()=>{e9.current=!1,e7.current=null};return window.addEventListener("mouseup",e),()=>window.removeEventListener("mouseup",e)},[]),(0,l.useEffect)(()=>{var e;null===Q&&(null===(e=D.current)||void 0===e||e.focus())},[Q]);let tb=e=>s({...a,...e}),ty=e=>{var t,r;let n=a.cells[e];if(null==n?void 0:n.filter)return n.filter;let l=(0,Y.PM)(e);if(!l)return;let i=null===(t=a.rowFilters)||void 0===t?void 0:t[l.row],o=null===(r=a.colFilters)||void 0===r?void 0:r[l.col];if(i||o)return{...i,...o}},tj=(0,l.useMemo)(()=>{let e=new Map;for(let t of tx){let r=(0,Y.PM)(t.anchor);if(r)for(let n=r.row;n<r.row+t.rowSpan;n++)for(let l=r.col;l<r.col+t.colSpan;l++){let r=(0,Y.Qk)({col:l,row:n});r!==t.anchor&&e.set(r,t.anchor)}}return e},[tx]),tk=e=>tx.find(t=>t.anchor===e),tw=(0,l.useMemo)(()=>{let e=new Set;for(let t of th)for(let r=t.anchorCol+1;r<t.anchorCol+t.span;r++)e.add(r);return e},[th]),tS=e=>th.find(t=>t.anchorCol===e),tC=(e,t,r,n)=>{let l=0;for(let i=e;i<=r;i++)for(let e=t;e<=n;e++){let t=a.cells[(0,Y.Qk)({col:e,row:i})];t&&(t.value||t.formula||t.metricId)&&l++}return l},tz=(e,t)=>{e>=2?tr({count:e,onConfirm:()=>{tr(null),t()}}):t()},tM=(0,l.useMemo)(()=>{let e={};for(let[r,n]of Object.entries(a.cells))if(n.metricId){var t;let n=null==tv?void 0:null===(t=tv[r])||void 0===t?void 0:t.raw;e[r]={value:null==n?"":String(n)}}else e[r]={value:n.value,formula:n.formula};return e},[a.cells,tv]),tI=(0,l.useMemo)(()=>{let e=new Map;for(let n=0;n<a.rows;n++)for(let l=0;l<a.cols;l++){var t,r;let i=(0,Y.Qk)({col:l,row:n}),o=a.cells[i];if(!o){e.set(i,{display:"",value:null});continue}if(o.metricId){let r=null!==(t=o.metricMode)&&void 0!==t?t:"value",n=null==tv?void 0:tv[i];if(n){let t=null!=n.raw&&o.numberFormat?et(n.raw,o.numberFormat):null==n.raw?"deviation"===r?"-":"NO DATA":n.display;e.set(i,{display:t,isMetric:!0,error:null==n.raw?"no_value":void 0,value:n.raw})}else e.set(i,{display:"Not refreshed",isMetric:!0,error:"not_refreshed",value:null})}else if(o.formula){let t=(0,Y.Bj)(i,tM),r="number"==typeof t.value&&o.numberFormat?et(t.value,o.numberFormat):(0,Y.hK)(t.value,t.error);e.set(i,{display:r,error:t.error,value:t.value})}else{let t=null!==(r=o.value)&&void 0!==r?r:"",n=o.numberFormat&&""!==t&&!Number.isNaN(Number(t))?et(Number(t),o.numberFormat):t;e.set(i,{display:n,value:null})}}return e},[a,tM,tv]),tF=null!==(t=null==to?void 0:to.formula)&&void 0!==t?t:"",tA=null!==(r=null==to?void 0:to.value)&&void 0!==r?r:"",tR=(e,t)=>{let r=t.trim(),n={...a.cells};""===r?delete n[e]:r.startsWith("=")?n[e]={formula:r}:n[e]={value:r},tb({cells:n})},tT=(e,t)=>{tR(e,t),$(null)},tD=(e,t)=>{E({r:e,c:t}),O({r:e,c:t})},tZ=()=>{eF(null),eR(null),eD(null),eE(!1),eO(!1),eL(null),e_(null),eH(null),eq(null),e1(null),e6(null)},tE=e=>{if(!tv)return;let t={};for(let[r,n]of Object.entries(tv)){let l=(0,Y.PM)(r);if(!l)continue;let i=e(l.col,l.row);i&&(t[(0,Y.Qk)({col:i.c,row:i.r})]=n)}tp(t)},tB=e=>{let t={};for(let[r,n]of Object.entries(a.cells)){let l=(0,Y.PM)(r),i=e(l.col,l.row);i&&(t[(0,Y.Qk)({col:i.c,row:i.r})]=n)}return t},tO=(e,t)=>{if(!e)return e;let r={};for(let[n,l]of Object.entries(e)){let e=t(Number(n));null!=e&&(r[e]=l)}return r},tN=(e,t)=>{var r,n;let l="right"===t?e+1:e,i={};for(let t=0;t<a.rows;t++){let r=a.cells[(0,Y.Qk)({col:e,row:t})];r&&(i[t]=ei(r))}let o=null!==(n=a.headers[e])&&void 0!==n?n:(0,Y.nP)(e),s=null===(r=a.colFilters)||void 0===r?void 0:r[e],d=tB((e,t)=>({c:e>=l?e+1:e,r:t}));for(let[e,t]of Object.entries(i))d[(0,Y.Qk)({col:l,row:Number(e)})]=t;if(tv){let t={};for(let[e,r]of Object.entries(tv)){let n=(0,Y.PM)(e);n&&(t[(0,Y.Qk)({col:n.col>=l?n.col+1:n.col,row:n.row})]=r)}for(let r=0;r<a.rows;r++){let n=tv[(0,Y.Qk)({col:e,row:r})];n&&(t[(0,Y.Qk)({col:l,row:r})]=n)}tp(t)}let c=[...a.headers];c.splice(l,0,o);let u=tO(a.colFilters,e=>e>=l?e+1:e);s&&(u={...null!=u?u:{},[l]:{...s,months:s.months?[...s.months]:void 0,facilityIds:s.facilityIds?[...s.facilityIds]:void 0}});let p=td.map(e=>e>=l?e+1:e);
1(tx.length||th.length)&&tl(!0),tb({cols:a.cols+1,cells:d,headers:c,colFilters:u,hiddenCols:p,merges:[],headerMerges:[]}),tZ(),tD(Z.r,l)},tL=(e,t)=>{var r,n,l;let i=e+t;if(i<0||i>=a.cols)return;let o=(t,r)=>({c:t===e?i:t===i?e:t,r}),s=tB(o);tE(o);let d=[...a.headers];[d[e],d[i]]=[null!==(r=d[i])&&void 0!==r?r:(0,Y.nP)(i),null!==(n=d[e])&&void 0!==n?n:(0,Y.nP)(e)];let c={...null!==(l=a.colFilters)&&void 0!==l?l:{}},u=c[e],p=c[i];delete c[e],delete c[i],p&&(c[e]=p),u&&(c[i]=u);let f=td.map(t=>t===e?i:t===i?e:t);(tx.length||th.length)&&tl(!0),tb({cells:s,headers:d,colFilters:c,hiddenCols:f,merges:[],headerMerges:[]}),tZ(),tD(Z.r,i)},tW=e=>{if(a.cols<=1)return;let t=(t,r)=>t===e?null:{c:t>e?t-1:t,r},r=tB(t);tE(t);let n=a.headers.filter((t,r)=>r!==e),l=tO(a.colFilters,t=>t===e?null:t>e?t-1:t),i=td.filter(t=>t!==e).map(t=>t>e?t-1:t);(tx.length||th.length)&&tl(!0),tb({cols:a.cols-1,cells:r,headers:n,colFilters:l,hiddenCols:i,merges:[],headerMerges:[]}),tZ(),tD(Z.r,Math.max(0,e-1))},tP=(e,t)=>{var r;let n=e+t;if(n<0||n>=a.rows)return;let l=(t,r)=>({c:t,r:r===e?n:r===n?e:r}),i=tB(l);tE(l);let o={...null!==(r=a.rowFilters)&&void 0!==r?r:{}},s=o[e],d=o[n];delete o[e],delete o[n],d&&(o[e]=d),s&&(o[n]=s);let c=tc.map(t=>t===e?n:t===n?e:t);tx.length&&tl(!0),tb({cells:i,rowFilters:o,hiddenRows:c,merges:[]}),tZ(),tD(n,Z.c)},tU=e=>{if(a.rows<=1)return;let t=(t,r)=>r===e?null:{c:t,r:r>e?r-1:r},r=tB(t);tE(t);let n=tO(a.rowFilters,t=>t===e?null:t>e?t-1:t),l=tc.filter(t=>t!==e).map(t=>t>e?t-1:t);tx.length&&tl(!0),tb({rows:a.rows-1,cells:r,rowFilters:n,hiddenRows:l,merges:[]}),tZ(),tD(Math.max(0,e-1),Z.c)},tH=(e,t)=>{var r;let n="below"===t?e+1:e,l={};for(let t=0;t<a.cols;t++){let r=a.cells[(0,Y.Qk)({col:t,row:e})];r&&(l[t]=ei(r))}let i=null===(r=a.rowFilters)||void 0===r?void 0:r[e],o=tB((e,t)=>({c:e,r:t>=n?t+1:t}));for(let[e,t]of Object.entries(l))o[(0,Y.Qk)({col:Number(e),row:n})]=t;if(tv){let t={};for(let[e,r]of Object.entries(tv)){let l=(0,Y.PM)(e);l&&(t[(0,Y.Qk)({col:l.col,row:l.row>=n?l.row+1:l.row})]=r)}for(let r=0;r<a.cols;r++){let l=tv[(0,Y.Qk)({col:r,row:e})];l&&(t[(0,Y.Qk)({col:r,row:n})]=l)}tp(t)}let s=tO(a.rowFilters,e=>e>=n?e+1:e);i&&(s={...null!=s?s:{},[n]:{...i,months:i.months?[...i.months]:void 0,facilityIds:i.facilityIds?[...i.facilityIds]:void 0}});let d=tc.map(e=>e>=n?e+1:e);tx.length&&tl(!0),tb({rows:a.rows+1,cells:o,rowFilters:s,hiddenRows:d,merges:[]}),tZ(),tD(n,Z.c)},tG=e=>{tb({hiddenCols:[...td,e].sort((e,t)=>e-t)}),tZ()},tV=e=>{tb({hiddenRows:[...tc,e].sort((e,t)=>e-t)}),tZ()},tQ=e=>tb({hiddenCols:td.filter(t=>t!==e)}),t_=e=>tb({hiddenRows:tc.filter(t=>t!==e)}),tY=()=>{let e={...a.cells};delete e[ti],tb({cells:e})},tq=e=>null==e.fyIndex&&(!e.months||12===e.months.length||0===e.months.length)&&(!e.facilityIds||0===e.facilityIds.length),tK=(e,t)=>{var r;let n={...null!==(r=a.colFilters)&&void 0!==r?r:{}};tq(t)?delete n[e]:n[e]=t,tb({colFilters:n})},t$=(e,t)=>{var r;let n={...null!==(r=a.rowFilters)&&void 0!==r?r:{}};tq(t)?delete n[e]:n[e]=t,tb({rowFilters:n})},tJ=e=>tb({merges:tx.filter(t=>t.anchor!==e)}),tX=e=>tb({headerMerges:th.filter(t=>t.anchorCol!==e)}),t0=e=>{let t,r;if(eE(!1),"ROUND"===e){tR(ti,"=ROUND(".concat(ti,", 2)"));return}let n="".concat((0,Y.Qk)({col:ta.c1,row:ta.r1}),":").concat((0,Y.Qk)({col:ta.c2,row:ta.r2}));ta.c1===ta.c2?(t=ta.r2+1,r=ta.c1):(t=ta.r1,r=ta.c2+1);let l={};t>=a.rows&&(l.rows=t+1),r>=a.cols&&(l.cols=r+1,l.headers=[...a.headers,(0,Y.nP)(a.cols)]);let i={...a.cells};i[(0,Y.Qk)({col:r,row:t})]={formula:"=".concat(e,"(").concat(n,")")},s({...a,...l,cells:i}),tD(t,r)},t1=e=>{let t={...a.cells};for(let r=ta.r1;r<=ta.r2;r++)for(let n=ta.c1;n<=ta.c2;n++){let l=(0,Y.Qk)({col:n,row:r}),i=t[l];if(i){if(e)t[l]={...i,numberFormat:e};else{let{numberFormat:e,...r}=i;t[l]=r}}}tb({cells:t}),eO(!1)},t2=(e,t)=>{let r=t.trim();if(r.startsWith("=")&&(r=r.slice(1)),!r)return;let n={...a.cells};for(let t=0;t<a.rows;t++){let l=t+1,i="="+r.replace(/\b([A-Z]{1,2})\b(?!\s*\()/g,(e,t)=>{var r;let n=null===(r=(0,Y.PM)("".concat(t,"1")))||void 0===r?void 0:r.col;return null!=n&&n<a.cols?"".concat(t).concat(l):e});n[(0,Y.Qk)({col:e,row:t})]={formula:i}}tb({cells:n}),eL(null),eP("")},t6=e=>{var t;let r=null===(t=a.cells[(0,Y.Qk)({col:e,row:0})])||void 0===t?void 0:t.formula;return r?r.replace(/^=/,"").replace(/\b([A-Z]{1,2})1\b/g,"$1"):""},t3=(e,t)=>
1{let r=t.trim();if(r.startsWith("=")&&(r=r.slice(1)),!r)return;let n={...a.cells};for(let t=0;t<a.cols;t++){let l=(0,Y.nP)(t),i="="+r.replace(/\bR(\d+)\b/gi,(e,t)=>"".concat(l).concat(t));n[(0,Y.Qk)({col:t,row:e})]={formula:i}}tb({cells:n}),eH(null),eV("")},t4=e=>{var t;let r=null===(t=a.cells[(0,Y.Qk)({col:0,row:e})])||void 0===t?void 0:t.formula;return r?r.replace(/^=/,"").replace(/\bA(\d+)\b/g,"R$1"):""},t8=(e,t)=>{let r={...a.cells};for(let n=0;n<a.rows;n++){let l=(0,Y.Qk)({col:e,row:n}),i=r[l];if(i){if(t)r[l]={...i,numberFormat:t};else{let{numberFormat:e,...t}=i;r[l]=t}}}tb({cells:r}),e_(null)},t5=(e,t)=>{let r={...a.cells};for(let n=0;n<a.cols;n++){let l=(0,Y.Qk)({col:n,row:e}),i=r[l];if(i){if(t)r[l]={...i,numberFormat:t};else{let{numberFormat:e,...t}=i;r[l]=t}}}tb({cells:r}),e1(null)},t9=e=>{var t;for(let r=0;r<a.cols;r++)if(null===(t=a.cells[(0,Y.Qk)({col:r,row:e})])||void 0===t?void 0:t.metricId)return!0;return!1},t7=(e,t)=>{let r=[...a.headers];for(;r.length<a.cols;)r.push((0,Y.nP)(r.length));r[e]=t.trim()||(0,Y.nP)(e),tb({headers:r}),eo(null)},re=(e,t)=>e>=ta.r1&&e<=ta.r2&&t>=ta.c1&&t<=ta.c2;return(0,n.jsxs)("div",{ref:D,tabIndex:0,onKeyDown:e=>{var t,r;let n=e.target;if(n&&("INPUT"===n.tagName||"TEXTAREA"===n.tagName||"SELECT"===n.tagName||n.isContentEditable)||Q||null!=en||d)return;if((e.metaKey||e.ctrlKey)&&("c"===e.key||"C"===e.key)){e.preventDefault(),te.current=to?ei(to):null;return}if((e.metaKey||e.ctrlKey)&&("v"===e.key||"V"===e.key)){if(e.preventDefault(),!te.current)return;let t={...a.cells};t[ti]=ei(te.current),tb({cells:t});return}let l=(e,t)=>{tD(Math.min(a.rows-1,Math.max(0,Z.r+e)),Math.min(a.cols-1,Math.max(0,Z.c+t)))};if("ArrowRight"===e.key)e.preventDefault(),l(0,1);else if("ArrowLeft"===e.key)e.preventDefault(),l(0,-1);else if("ArrowUp"===e.key)e.preventDefault(),l(-1,0);else if("ArrowDown"===e.key||"Enter"===e.key)e.preventDefault(),l(1,0);else if("Delete"===e.key||"Backspace"===e.key){if(e.preventDefault(),!a.cells[ti])return;let t={...a.cells};delete t[ti],tb({cells:t})}else if(/^[\d\w=+\-./*]$/.test(e.key)){if(null===(t=a.cells[ti])||void 0===t?void 0:t.metricId)return;e.preventDefault(),$(ti),ee(e.key)}else if("F2"===e.key){if(e.preventDefault(),null===(r=a.cells[ti])||void 0===r?void 0:r.metricId)return;$(ti),ee(tF||tA)}},style:{outline:"none",userSelect:"none",WebkitUserSelect:"none"},children:[!d&&(0,n.jsxs)("div",{style:{display:"flex",gap:6,alignItems:"center",flexWrap:"wrap",padding:"8px 0",marginBottom:8},children:[(0,n.jsxs)(ej,{onClick:()=>tb({rows:a.rows+1}),children:[(0,n.jsx)(c.Z,{size:11})," Row"]}),(0,n.jsxs)(ej,{onClick:()=>tb({cols:a.cols+1,headers:[...a.headers,(0,Y.nP)(a.cols)]}),children:[(0,n.jsx)(c.Z,{size:11})," Column"]}),(0,n.jsx)("span",{style:ek}),ts&&(0,n.jsxs)(ej,{onClick:()=>{if(!ts)return;let e=(0,Y.Qk)({col:ta.c1,row:ta.r1});tz(tC(ta.r1,ta.c1,ta.r2,ta.c2),()=>{tb({merges:[...tx.filter(e=>{let t=(0,Y.PM)(e.anchor);return t.row+e.rowSpan<=ta.r1||t.row>=ta.r2+1||t.col+e.colSpan<=ta.c1||t.col>=ta.c2+1}),{anchor:e,rowSpan:ta.r2-ta.r1+1,colSpan:ta.c2-ta.c1+1}]}),tD(ta.r1,ta.c1)})},accent:"accent",children:[(0,n.jsx)(N.Z,{size:11})," Merge ",ta.r2-ta.r1+1,"\xd7",ta.c2-ta.c1+1]}),tk(ti)&&(0,n.jsxs)(ej,{onClick:()=>tJ(ti),accent:"warn",children:[(0,n.jsx)(N.Z,{size:11})," Unmerge"]}),e8&&e8.c1!==e8.c2&&(0,n.jsxs)(ej,{onClick:()=>{var e;if(!e8||e8.c1===e8.c2)return;let{c1:t,c2:r}=e8,n=0;for(let l=t;l<=r;l++)(null!==(e=a.headers[l])&&void 0!==e?e:"").trim()&&n++;tz(n,()=>{tb({headerMerges:[...th.filter(e=>e.anchorCol+e.span<=t||e.anchorCol>=r+1),{anchorCol:t,span:r-t+1}]}),e5(null)})},accent:"accent",children:[(0,n.jsx)(N.Z,{size:11})," Merge titles \xd7",e8.c2-e8.c1+1]}),(0,n.jsxs)("div",{style:{position:"relative"},children:[(0,n.jsxs)(ej,{onClick:()=>{tZ(),eE(!eZ)},children:[(0,n.jsx)(L.Z,{size:11})," Calc"]}),eZ&&(0,n.jsxs)(em,{onClose:()=>eE(!1),children:[(0,n.jsx)(eg,{icon:(0,n.jsx)(L.Z,{size:12}),label:ts?"Sum of selection":"Sum - select a range first",disabled:!ts,onClick:()=>t0("SUM")}),(0,n.jsx)(eg,{icon:(0,n.jsx)(L.Z,{size:12}),label:ts?"Average of selection":"Average - select a range first",disabled:!ts,onClick:()=>t0("AVG")}
1),(0,n.jsx)(eg,{icon:(0,n.jsx)(L.Z,{size:12}),label:"Round ".concat(ti," to 2 dp"),onClick:()=>t0("ROUND")})]})]}),(0,n.jsxs)("div",{style:{position:"relative"},children:[(0,n.jsxs)(ej,{onClick:()=>{tZ(),eO(!eB)},children:[(0,n.jsx)(W.Z,{size:11})," Format"]}),eB&&(0,n.jsx)(ex,{label:ts?"the selection":"cell ".concat(ti),onApply:e=>t1(e),onClose:()=>eO(!1)})]}),(0,n.jsx)("span",{style:ek}),(null==to?void 0:to.metricId)?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ey,{value:null!==(i=to.metricMode)&&void 0!==i?i:"value",onChange:e=>{let t={...a.cells};t[ti]={...t[ti],metricMode:e},tb({cells:t})}}),(0,n.jsxs)(ej,{onClick:tY,accent:"warn",children:[(0,n.jsx)(P.Z,{size:11})," Unmap ",ti]})]}):(0,n.jsxs)(ej,{onClick:()=>eM(!0),accent:"accent",children:[(0,n.jsx)(U.Z,{size:11})," Map metric to ",ti]}),(0,n.jsx)("span",{style:{flex:1}}),(td.length>0||tc.length>0)&&(0,n.jsxs)("div",{style:{position:"relative"},children:[(0,n.jsxs)(ej,{onClick:()=>{let e=!!e2;tZ(),e6(e?null:td.length?"col":"row")},children:[(0,n.jsx)(f.Z,{size:11})," ",td.length+tc.length," hidden"]}),e2&&(0,n.jsxs)(em,{onClose:()=>e6(null),align:"right",children:[td.map(e=>{var t;return(0,n.jsx)(eg,{icon:(0,n.jsx)(f.Z,{size:12}),label:"Show column ".concat(null!==(t=a.headers[e])&&void 0!==t?t:(0,Y.nP)(e)),onClick:()=>tQ(e)},"c".concat(e))}),tc.map(e=>(0,n.jsx)(eg,{icon:(0,n.jsx)(f.Z,{size:12}),label:"Show row ".concat(e+1),onClick:()=>t_(e)},"r".concat(e)))]})]}),(0,n.jsxs)(_.Caps,{children:[a.rows," \xd7 ",a.cols," \xb7 ",Object.keys(a.cells).length," CELLS"]})]}),!d&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 10px",marginBottom:8,background:(null==to?void 0:to.metricId)?"var(--accent-subtle)":"var(--bg-sunken)",border:"1px solid ".concat((null==to?void 0:to.metricId)?"var(--accent)":"var(--border-subtle)"),borderRadius:"var(--radius-sm)"},children:[(0,n.jsx)(_.NumMono,{size:12,weight:600,color:"var(--accent)",children:ti}),(0,n.jsx)("span",{style:{color:"var(--text-tertiary)",fontFamily:"var(--font-mono)",fontSize:11},children:"Æx"}),(null==to?void 0:to.metricId)?(()=>{var e,t,r,l,i,o;let a=null!==(e=to.metricMode)&&void 0!==e?e:"value",s=ty(ti),d=u.find(e=>e.id===to.metricId),c=null==tv?void 0:tv[ti],p=null!==(t=null==c?void 0:c.raw)&&void 0!==t?t:null,f=null!==(l=null!==(r=null==c?void 0:c.unit)&&void 0!==r?r:null==d?void 0:d.outputUnit)&&void 0!==l?l:"";return(0,n.jsxs)("div",{style:{flex:1,display:"flex",alignItems:"center",gap:8},children:[(0,n.jsx)(H.Z,{size:11,color:"var(--accent)"}),(0,n.jsxs)("span",{style:{fontSize:12.5,fontWeight:500,color:"var(--accent)"},children:["METRIC \xb7 ",null!==(i=null==d?void 0:d.name)&&void 0!==i?i:"Unknown metric"]}),(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)",fontSize:10.5,color:"var(--text-tertiary)"},children:null!==(o=null==d?void 0:d.code)&&void 0!==o?o:""}),(0,n.jsx)(_.Caps,{size:9.5,color:"deviation"===a?"var(--warning)":"var(--accent)",children:er[a]}),(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:3,fontSize:10.5,color:"var(--text-tertiary)"},title:"The filter this value was resolved with (row + column filters combined)",children:[(0,n.jsx)(k.Z,{size:9})," ",es(s,v,x)]}),(0,n.jsx)("span",{style:{flex:1}}),(0,n.jsx)(_.NumMono,{size:12,weight:600,color:c?"var(--text-primary)":"var(--text-tertiary)",children:c?el(p,a):"Not refreshed"}),(0,n.jsx)(_.Caps,{size:9.5,children:f})]})})():(0,n.jsx)("input",{value:tF||tA,onChange:e=>tR(ti,e.target.value),placeholder:"Type value, text, or =formula (e.g. =A1+B2, =SUM(A1:A5), =ROUND(A1, 2))",style:{flex:1,border:"none",outline:"none",background:"transparent",fontFamily:"var(--font-mono)",fontSize:12.5,color:"var(--text-primary)",userSelect:"text",WebkitUserSelect:"text"}})]}),!d&&tn&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:11,color:"var(--accent)",background:"var(--accent-subtle)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",padding:"5px 9px",marginBottom:8},children:[(0,n.jsx)(N.Z,{size:12})," Merged cells were reset after the row/column change - re-merge if needed."]}),m&&(0,n.jsxs)("div",{style:{fontSize:10.5,color:"var(--text-tertiary)",marginBottom:6},children:["Values as of ",function(e){let t=Math.round((Date.now()-new Date(e).getTime())/6e4);if(t<1)return"just now";if(t<60)return"".concat(t," min").concat(1===t?"":"s"," ago");let r=Math.round(t/60);if(r<24)return"".concat(r," hour").concat(1===r?"":"s"," ago");let n=Math.round(r/24);return"".concat(n," day").concat(1===n?"":"s"," ago")}(m)]}),(0,n.jsx)("div",{className:"cr-sheet-scroll",style:{border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-md)",overflow:"auto",maxHeight:520,background:"var(--bg-elevated)"},children:(0,n.jsxs)("table",{style:{borderCollapse:"collapse",tableLayout:"fixed",width:"100%"},children:[(0,n.jsxs)("thead",{children:[(0,n.jsxs)("tr",{className:"cr-sheet-colletters",style:{background:"var(--bg-sunken)",position:"sticky",top:0,zIndex:2},children:[(0,n.jsx)("th",{className:"cr-sheet-rowhead",style:eS,children:"\xb7"}),tm.map(e=>(0,n.jsx)("th",{style:eC,children:(0,Y.nP)(e)},e))]}),(0,n.jsxs)("tr",{style:{background:"var(--bg-base)"},children:[(0,n.jsx)("th",{className:"cr-sheet-rowhead",style:{...ez,height:30}}),tm.map(e=>{var t,r,l,i,o;if(tw.has(e))return null;let s=null===(t=a.colFilters)||void 0===t?void 0:t[e],c=function(e,t){var r;let n=!1,l=!1;for(let r=0;r<e.rows;r++){let i=e.cells[(0,Y.Qk)({col:t,row:r})];i&&(i.filter&&(n=!0),i.formula&&(l=!0))}return{hasColFilter:!!(null===(r=e.colFilters)||void 0===r?void 0:r[t]),hasCellFilter:n,hasFormula:l}}(a,e),u=c.hasColFilter||c.hasCellFilter||c.hasFormula,f=[s?"Column filter: ".concat(null!==(l=ea(s,x))&&void 0!==l?l:es(s,v,x)):null,c.hasCellFilter?"One or more cells have their own filter override":null,c.hasFormula?"One or more cells have a Calculate formula applied":null].filter(
1Boolean).join(" \xb7 "),h=tS(e),m=h?tm.filter(t=>t>=e&&t<e+h.span).length:1,j=!d&&!!e8&&e>=e8.c1&&e<=e8.c2,w=!!(d&&g&&F&&eu(a,e)),A=!K(null==y?void 0:y[e]);return(0,n.jsxs)("th",{colSpan:m,style:{padding:0,borderRight:"1px solid var(--border-subtle)",borderBottom:"1px solid var(--border-subtle)",position:"relative",background:j?"color-mix(in srgb, var(--accent) 10%, transparent)":void 0},children:[en===e?(0,n.jsx)("input",{autoFocus:!0,value:ec,onChange:e=>ef(e.target.value),onBlur:()=>t7(e,ec),onKeyDown:t=>{"Enter"===t.key?(t.preventDefault(),t7(e,ec)):"Escape"===t.key&&(t.preventDefault(),eo(null))},style:{width:"100%",boxSizing:"border-box",padding:"5px 8px",border:"none",outline:"2px solid var(--accent)",background:"var(--bg-elevated)",fontFamily:"var(--font-mono)",fontSize:10.5,color:"var(--text-primary)",userSelect:"text",WebkitUserSelect:"text"}}):(0,n.jsxs)("button",{type:"button",onMouseDown:()=>{d||(e7.current=e,e5({c1:e,c2:e}),tZ())},onMouseEnter:()=>{if(null!=e7.current){let t=e7.current;e5({c1:Math.min(t,e),c2:Math.max(t,e)})}},onMouseUp:()=>{if(d){w&&e$(e);return}if(null==e7.current)return;let t=e7.current;e7.current=null,t===e&&(e5(null),eF(e),tD(Z.r,e))},onDoubleClick:()=>{var t;d||(eF(null),e5(null),eo(e),ef(null!==(t=a.headers[e])&&void 0!==t?t:(0,Y.nP)(e)))},title:d?w?A?"Filtered \xb7 ".concat(null!==(i=ea(null==y?void 0:y[e],x))&&void 0!==i?i:""):"Click to filter this column by facility":u?f:void 0:"Click for column menu \xb7 double-click to rename \xb7 drag across titles to merge",style:{width:"100%",display:"flex",alignItems:"center",gap:4,padding:"5px 8px",background:eI===e||eK===e?"var(--accent-subtle)":"transparent",border:"none",cursor:d?w?"pointer":u?"help":"default":"pointer",font:"inherit",fontFamily:"var(--font-mono)",fontSize:10.5,color:"var(--text-tertiary)",fontWeight:500,letterSpacing:"0.04em",textAlign:h?"center":"left"},children:[(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:null!==(o=a.headers[e])&&void 0!==o?o:(0,Y.nP)(e)}),d&&w&&(T?(0,n.jsx)(J.bw,{size:"xs",tone:"current",px:9,style:{color:"var(--text-tertiary)"}}):(0,n.jsx)(k.Z,{size:9,color:A?"var(--accent)":"var(--text-tertiary)"})),d&&!w&&u&&(0,n.jsx)(G.Z,{size:9,color:"var(--accent)"}),!d&&u&&(0,n.jsx)(k.Z,{size:9,color:"var(--accent)"}),h&&(0,n.jsx)(N.Z,{size:9,style:{opacity:.5}}),!d&&!h&&(0,n.jsx)(S.Z,{size:9,style:{opacity:.4}})]}),eK===e&&w&&(0,n.jsx)(ep,{label:"Column ".concat((0,Y.nP)(e)),filter:null==y?void 0:y[e],facilityOnly:!R,hasMetric:!0,facilityOptions:v,fyLabels:x,onChange:t=>null==F?void 0:F(e,t),onClose:()=>e$(null)}),eI===e&&(0,n.jsxs)(em,{onClose:()=>eF(null),children:[(0,n.jsx)(eg,{icon:(0,n.jsx)(C.Z,{size:12}),label:"Rename",onClick:()=>{var t;eF(null),eo(e),ef(null!==(t=a.headers[e])&&void 0!==t?t:(0,Y.nP)(e))}}),(0,n.jsx)(eg,{icon:(0,n.jsx)(k.Z,{size:12}),label:ea(s,x)?"Filter \xb7 ".concat(ea(s,x)):"Filterâ¦",onClick:()=>{eF(null),eD(e)}}),(0,n.jsx)(eg,{icon:(0,n.jsx)(V.Z,{size:12}),label:"Calculateâ¦",onClick:()=>{eF(null),eP(t6(e)),eL(e)}}),(0,n.jsx)(eg,{icon:(0,n.jsx)(W.Z,{size:12}),label:"Formatâ¦",onClick:()=>{eF(null),e_(e)}}),h&&(0,n.jsx)(eg,{icon:(0,n.jsx)(N.Z,{size:12}),label:"Unmerge title",onClick:()=>{eF(null),tX(e)}}),(0,n.jsx)(eb,{}),(0,n.jsx)(eg,{icon:(0,n.jsx)(b.Z,{size:12}),label:"Copy to left",onClick:()=>tN(e,"left")}),(0,n.jsx)(eg,{icon:(0,n.jsx)(b.Z,{size:12}),label:"Copy to right",onClick:()=>tN(e,"right")}),(0,n.jsx)(eg,{icon:(0,n.jsx)(z.Z,{size:12}),label:"Move left",disabled:0===e,onClick:()=>tL(e,-1)}),(0,n.jsx)(eg,{icon:(0,n.jsx)(M.Z,{size:12}),label:"Move right",disabled:e===a.cols-1,onClick:()=>tL(e,1)}),(0,n.jsx)(eg,{icon:(0,n.jsx)(I.Z,{size:12}),label:"Hide column",onClick:()=>tG(e)}),(0,n.jsx)(eb,{}),(0,n.jsx)(eg,{icon:(0,n.jsx)(p.Z,{size:12}),label:"Delete column",danger:!0,disabled:a.cols<=1,onClick:()=>tW(e)})]}),eT===e&&(0,n.jsx)(ep,{label:"Column ".concat((0,Y.nP)(e)),filter:null===(r=a.colFilters)||void 0===r?void 0:r[e],hasMetric:eu(a,e),facilityOptions:v,fyLabels:x,onChange:t=>tK(e,t),onClose:()=>eD(null)}),eN===e&&(0,n.jsx)(ev,{label:"column ".concat((0,Y.nP)(e)),draft:eW,onDraftChange:eP,onApply:()=>t2(e,eW),onClose:()=>{eL(null),eP("")},placeholder:"Custom formula - e.g. E+F or ROUND(E/F, 2)",hint:(0,n.jsxs)(n.Fragment,{children:["Column letters mean this row's cells; the formula fills every row. ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)"},children:"E+F"})," â ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)"},children:"=E1+F1"}),", ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)"},children:"=E2+F2"}),", â¦"]})}),eQ===e&&(0,n.jsx)(ex,{label:"column ".concat((0,Y.nP)(e)),onApply:t=>t8(e,t),onClose:()=>e_(null)})]},e)})]})]}),(0,n.jsx)("tbody",{children:tg.map(e=>{var t,r,l,i,o,s,c,u;let f=!!(d&&g&&A&&t9(e)),h=!K(null==j?void 0:j[e]);return(0,n.jsxs)("tr",{children:[(0,n.jsxs)("th",{className:"cr-sheet-rowhead",style:{...ez,curs
1or:d?f?"pointer":"default":"pointer",background:eA===e||eJ===e?"var(--accent-subtle)":"var(--bg-sunken)",position:"relative"},onClick:()=>{if(d){f&&eX(e);return}tZ(),eR(e),tD(e,Z.c)},title:d?f?h?"Filtered \xb7 ".concat(null!==(c=ea(null==j?void 0:j[e],x))&&void 0!==c?c:""):"Click to filter this row by facility":(null===(t=a.rowFilters)||void 0===t?void 0:t[e])?"Filter applied: ".concat(null!==(u=ea(a.rowFilters[e],x))&&void 0!==u?u:es(a.rowFilters[e],v,x)):void 0:"Row menu",children:[(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:3},children:[e+1,d&&f&&(T?(0,n.jsx)(J.bw,{size:"xs",tone:"current",px:8,style:{color:"var(--text-tertiary)"}}):(0,n.jsx)(k.Z,{size:8,color:h?"var(--accent)":"var(--text-tertiary)"})),d&&!f&&(null===(r=a.rowFilters)||void 0===r?void 0:r[e])&&(0,n.jsx)(G.Z,{size:8,color:"var(--accent)"}),!d&&(null===(l=a.rowFilters)||void 0===l?void 0:l[e])&&(0,n.jsx)(k.Z,{size:8,color:"var(--accent)"})]}),eJ===e&&f&&(0,n.jsx)(ep,{label:"Row ".concat(e+1),filter:null==j?void 0:j[e],facilityOnly:!R,hasMetric:!0,facilityOptions:v,fyLabels:x,onChange:t=>null==A?void 0:A(e,t),onClose:()=>eX(null)}),eA===e&&(0,n.jsxs)(em,{onClose:()=>eR(null),align:"left",children:[(0,n.jsx)(eg,{icon:(0,n.jsx)(k.Z,{size:12}),label:ea(null===(i=a.rowFilters)||void 0===i?void 0:i[e],x)?"Filter \xb7 ".concat(ea(null===(o=a.rowFilters)||void 0===o?void 0:o[e],x)):"Filterâ¦",onClick:()=>{eR(null),eq(e)}}),(0,n.jsx)(eg,{icon:(0,n.jsx)(V.Z,{size:12}),label:"Calculateâ¦",onClick:()=>{eR(null),eV(t4(e)),eH(e)}}),(0,n.jsx)(eg,{icon:(0,n.jsx)(W.Z,{size:12}),label:"Formatâ¦",onClick:()=>{eR(null),e1(e)}}),(0,n.jsx)(eb,{}),(0,n.jsx)(eg,{icon:(0,n.jsx)(b.Z,{size:12}),label:"Copy above",onClick:()=>tH(e,"above")}),(0,n.jsx)(eg,{icon:(0,n.jsx)(b.Z,{size:12}),label:"Copy below",onClick:()=>tH(e,"below")}),(0,n.jsx)(eg,{icon:(0,n.jsx)(w.Z,{size:12}),label:"Move up",disabled:0===e,onClick:()=>tP(e,-1)}),(0,n.jsx)(eg,{icon:(0,n.jsx)(S.Z,{size:12}),label:"Move down",disabled:e===a.rows-1,onClick:()=>tP(e,1)}),(0,n.jsx)(eg,{icon:(0,n.jsx)(I.Z,{size:12}),label:"Hide row",onClick:()=>tV(e)}),(0,n.jsx)(eb,{}),(0,n.jsx)(eg,{icon:(0,n.jsx)(p.Z,{size:12}),label:"Delete row",danger:!0,disabled:a.rows<=1,onClick:()=>tU(e)})]}),eY===e&&(0,n.jsx)(ep,{label:"Row ".concat(e+1),filter:null===(s=a.rowFilters)||void 0===s?void 0:s[e],hasMetric:t9(e),facilityOptions:v,fyLabels:x,onChange:t=>t$(e,t),onClose:()=>eq(null)}),e0===e&&(0,n.jsx)(ex,{label:"row ".concat(e+1),onApply:t=>t5(e,t),onClose:()=>e1(null)}),eU===e&&(0,n.jsx)(ev,{label:"row ".concat(e+1),draft:eG,onDraftChange:eV,onApply:()=>t3(e,eG),onClose:()=>{eH(null),eV("")},placeholder:"Custom formula - e.g. R1+R2 or SUM(R1:R4)",hint:(0,n.jsxs)(n.Fragment,{children:["Use ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)"},children:"R<n>"})," for row n's cell in this column (bare numbers would be ambiguous with literals); the formula fills every column. ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)"},children:"R1+R2"})," â column A gets ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)"},children:"=A1+A2"}),", column B gets ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)"}
1,children:"=B1+B2"}),", â¦"]})})]}),tm.map(t=>{var r,l,i;let o=(0,Y.Qk)({col:t,row:e});if(tj.has(o))return null;let s=tk(o),c=o===Q,u=null!==(r=tI.get(o))&&void 0!==r?r:{display:"",value:null},p=a.cells[o],f=!!(null==p?void 0:p.formula),v=!!(null==p?void 0:p.metricId),x=!!u.error,h=o===ti&&!d,m=!d&&re(e,t),g=1,b=1;return s&&(g=tm.filter(e=>e>=t&&e<t+s.colSpan).length,b=tg.filter(t=>t>=e&&t<e+s.rowSpan).length),(0,n.jsx)("td",{colSpan:g,rowSpan:b,onMouseDown:()=>{d||c||(e9.current=!0,E({r:e,c:t}),O({r:e,c:t}),tZ())},onMouseEnter:()=>{e9.current&&O({r:e,c:t})},onMouseUp:()=>{e9.current=!1},onClick:()=>{var e;d&&v&&(null==p?void 0:p.metricId)&&e4({ref:o,metricId:p.metricId,mode:null!==(e=p.metricMode)&&void 0!==e?e:"value",filter:ty(o)})},onDoubleClick:()=>{var e,t;d||v||($(o),ee(null!==(t=null!==(e=null==p?void 0:p.formula)&&void 0!==e?e:null==p?void 0:p.value)&&void 0!==t?t:""))},title:x?(l=u.error)?null!==(i=ed[l])&&void 0!==i?i:"Could not calculate (".concat(l,")."):void 0:u.display?String(u.display):void 0,style:{padding:0,minWidth:110,height:30,borderRight:"1px solid var(--border-subtle)",borderBottom:"1px solid var(--border-subtle)",position:"relative",background:h?"var(--accent-subtle)":m?"color-mix(in srgb, var(--accent) 8%, transparent)":v?"color-mix(in srgb, var(--accent) 4%, transparent)":"var(--bg-elevated)",boxShadow:h?"inset 0 0 0 2px var(--accent)":"none",cursor:d?v?"pointer":"default":"cell"},children:c?(0,n.jsx)("input",{autoFocus:!0,value:X,onChange:e=>ee(e.target.value),onBlur:()=>tT(o,X),onKeyDown:r=>{"Enter"===r.key?(r.preventDefault(),tT(o,X),tD(Math.min(a.rows-1,e+1),t)):"Escape"===r.key?(r.preventDefault(),$(null)):"Tab"===r.key&&(r.preventDefault(),tT(o,X),tD(e,Math.min(a.cols-1,t+1)))},style:{width:"100%",height:"100%",boxSizing:"border-box",padding:"0 8px",border:"none",outline:"none",background:"var(--bg-elevated)",fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text-primary)",userSelect:"text",WebkitUserSelect:"text"}}):(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,padding:"0 8px",lineHeight:"30px",width:"100%",boxSizing:"border-box",overflow:"hidden",fontFamily:"var(--font-mono)",fontSize:12,fontVariantNumeric:"tabular-nums",color:x?v?"var(--warning)":"var(--error)":v?"var(--accent)":f?"var(--accent)":"var(--text-primary)",fontWeight:v?600:400},children:[v&&(0,n.jsx)(H.Z,{size:9,style:{flexShrink:0}}),(0,n.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u.display})]})},t)})]},e)})})]})}),!d&&(0,n.jsxs)("div",{style:{marginTop:8,fontSize:11,color:"var(--text-tertiary)"},children:["Click a header for column tools (rename \xb7 filter \xb7 copy \xb7 move \xb7 hide \xb7 delete) \xb7 drag across titles to merge them \xb7 click a row number for row tools \xb7 drag to select body cells, then Merge or Calc \xb7 double-click or F2 to edit \xb7 formulas: ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)"},children:"=A1+B2"}),", ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)"},children:"=SUM(A1:A5)"})," \xb7 the drill-down opens from the ",(0,n.jsx)("strong",{children:"Overview"})," table"]}),tt&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{onClick:()=>tr(null),style:{position:"fixed",inset:0,zIndex:210,background:"var(--scrim)"}}),(0,n.jsxs)("div",{style:{position:"fixed",top:"32vh",left:"50%",transform:"translateX(-50%)",zIndex:211,width:"min(380px, calc(100vw - 32px))",background:"var(--bg-elevated)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-lg)",boxShadow:"var(--shadow-xl)",padding:18},children:[(0,n.jsxs)("div",{style:{fontSize:14,fontWeight:600,marginBottom:6},children:["Merge ",tt.count," filled cells?"]}),(0,n.jsxs)("div",{style:{fontSize:12.5,color:"var(--text-secondary)",marginBottom:16},children:["Merging keeps only the top-left cell's content. The other ",tt.count-1," filled cell",tt.count-1==1?"":"s"," will be cleared. This can't be undone."]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[(0,n.jsx)("button",{onClick:()=>tr(null),style:{padding:"6px 14px",borderRadius:"var(--radius-sm)",background:"var(--bg-elevated)",border:"1px solid var(--border-subtle)",color:"var(--text-secondary)",fontSize:12.5,cursor:"pointer"},children:"Cancel"}),(0,n.jsx)("button",{onClick:tt.onConfirm,style:{padding:"6px 14px",borderRadius:"var(--radius-sm)",background:"var(--warning)",border:"none",color:"var(--fg-on-solid)",fontSize:12.5,cursor:"pointer",fontWeight:500},children:"Merge anyway"})]})]})]}),ew&&(0,n.jsx)(q.c,{title:"Map metric to cell ".concat(ti),subtitle:"Value = current FY, Comparison = prior FY, Deviation = % change. The column's f
1ilter (year / months / facilities) applies.",metrics:u,selectedId:null!==(o=null==to?void 0:to.metricId)&&void 0!==o?o:null,onClose:()=>eM(!1),onPick:e=>{var t,r;let n={...a.cells};n[ti]={metricId:e,metricMode:null!==(r=null===(t=n[ti])||void 0===t?void 0:t.metricMode)&&void 0!==r?r:"value"},tb({cells:n}),eM(!1)},onUnmap:()=>{tY(),eM(!1)}}),e3&&(0,n.jsx)(eh,{metricId:e3.metricId,mode:e3.mode,filter:e3.filter,metricOptions:u,fyLabels:x,resolved:null==tv?void 0:tv[e3.ref],onClose:()=>e4(null)})]})}function eu(e,t){var r;for(let n=0;n<e.rows;n++)if(null===(r=e.cells[(0,Y.Qk)({col:t,row:n})])||void 0===r?void 0:r.metricId)return!0;return!1}function ep(e){var t,r,l,i;let{label:o,filter:a,hasMetric:s,facilityOptions:d,fyLabels:c,onChange:u,onClose:p,facilityOnly:f}=e,{anchorRef:v,boxRef:x,pos:h,clipped:m}=ee(p),g=null!=a?a:{},b=g.months&&g.months.length?g.months:Array.from({length:12},(e,t)=>t),y=null!==(r=g.facilityIds)&&void 0!==r?r:[],j=null!==(l=null===(t=Object.entries(E.Mi).find(e=>{let[,t]=e;return t.length===b.length&&t.every(e=>b.includes(e))}))||void 0===t?void 0:t[0])&&void 0!==l?l:12===b.length?"all":"custom";return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{ref:v,style:{position:"absolute",inset:0,pointerEvents:"none"}}),(0,O.createPortal)((0,n.jsxs)("div",{ref:x,onClick:e=>e.stopPropagation(),style:{position:"fixed",top:h.top,left:h.left,visibility:m?"hidden":"visible",pointerEvents:m?"none":"auto",width:260,maxHeight:"calc(100vh - 24px)",overflowY:"auto",background:"var(--bg-elevated)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",boxShadow:"0 4px 16px rgba(0,0,0,0.15)",zIndex:300,padding:10,display:"flex",flexDirection:"column",gap:8},children:[(0,n.jsxs)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-secondary)",display:"flex",alignItems:"center",gap:5},children:[(0,n.jsx)(k.Z,{size:11})," ",o," filter"]}),f&&(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-tertiary)",lineHeight:1.4},children:"Recomputes this value from the facilities already fetched. Year/period stay as configured in Setup."}),!f&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-tertiary)",lineHeight:1.4},children:"Recomputes live - may take a moment."}),(0,n.jsxs)("label",{style:{fontSize:10.5,color:"var(--text-tertiary)"},children:["Year",(0,n.jsx)("select",{value:null!==(i=g.fyIndex)&&void 0!==i?i:0,onChange:e=>u({...g,fyIndex:Number(e.target.value)}),style:ew,children:c.map((e,t)=>(0,n.jsxs)("option",{value:t,children:[e,0===t?" (current)":""]},t))})]}),(0,n.jsxs)("label",{style:{fontSize:10.5,color:"var(--text-tertiary)"},children:["Period",(0,n.jsxs)("select",{value:j,onChange:e=>{let t=e.target.value;"all"===t?u({...g,months:void 0}):"custom"!==t&&u({...g,months:E.Mi[t]})},style:ew,children:[(0,n.jsx)("option",{value:"all",children:"Full year"}),(0,n.jsx)("option",{value:"q1",children:"Q1 (AprâJun)"}),(0,n.jsx)("option",{value:"q2",children:"Q2 (JulâSep)"}),(0,n.jsx)("option",{value:"q3",children:"Q3 (OctâDec)"}),(0,n.jsx)("option",{value:"q4",children:"Q4 (JanâMar)"}),(0,n.jsx)("option",{value:"custom",disabled:!0,hidden:!0,children:"Custom"})]})]}),(0,n.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:3},children:E.gg.map((e,t)=>(0,n.jsx)("button",{type:"button",onClick:()=>{let e=new Set(b);e.has(t)?e.delete(t):e.add(t);let r=Array.from(e).sort((e,t)=>e-t);u({...g,months:12===r.length?void 0:r})},style:{padding:"2px 5px",fontSize:9.5,borderRadius:"var(--radius-sm)",cursor:"pointer",fontFamily:"var(--font-sans)",border:"1px solid ".concat(b.includes(t)?"var(--accent)":"var(--border-subtle)"),background:b.includes(t)?"var(--accent-subtle)":"var(--bg-elevated)",color:b.includes(t)?"var(--accent)":"var(--text-primary)"},children:e},t))})]}),(0,n.jsx)(ef,{selected:y,options:d,onChange:e=>u({...g,facilityIds:e})}),!s&&!f&&(0,n.jsx)("div",{style:{fontSize:10.5,color:"var(--text-tertiary)",fontStyle:"italic"},children:"Applies once a metric is mapped here."}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",paddingTop:4,borderTop:"1px solid var(--border-subtle)"},children:[(0,n.jsx)("button",{onClick:()=>{u({})},style:{background:"none",border:"none",color:"var(--text-tertiary)",fontSize:11,cursor:"pointer"},children:"Clear"}),(0,n.jsx)("button",{onClick:p,style:{background:"var(--accent)",color:"var(--fg-on-solid)",border:"none",borderRadius:"var(--radius-sm)",padding:"4px 12px",fontSize:11.5,cursor:"pointer"},children:"Done"})]})]}),document.body)]})}function ef(e){var t,r;let{selected:i,options:o,onChange:a}=e,[s,d]=(0,l.useState)(!1),c=0===i.length?"All facilities":1===i.length?null!==(r=null===(t=o.find(e=>e.id===i[0]))||void 0===t?void 0:t.name)&&void 0!==r?r:"1 facility":"".concat(i.length," facilities");return(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:10.5,color:"var(--text-tertiary)",marginBottom:4},children:"Facilities"}),(0,n.jsxs)("button",{type:"button",onClick:()=>d(e=>!e),title:c,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",gap:6,height:28,padding:"0 8px",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",background:"var(--bg-elevated)",color:"var(--text-primary)",fontSize:11.5,cursor:"pointer",fontFamily:"var(--font-sans)"},children:[(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c}),(0,n.jsx)(S.Z,{size:12,style:{transform:s?"rotate(180deg)":"none",transition:"transform .12s",opacity:.6,flexShrink:0}})]}),s&&(0,n.jsx)("div",{style:{marginTop:4,border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",background:"var(--bg-elevated)",overflow:"hidden"},children:(0,n.jsx)($.l,{facilities:o,selected:i,onChange:a,autoFocusSearch:!1,listMaxHeight:112})})]})}function ev(e){let{label:t,draft:r,onDraftChange:i,onApply:o,onClose:a,placeholder:s,hint:d}=e,{anchorRef:c,boxRef:u,pos:p,clipped:f}=ee(a),v=(0,l.useRef)(null),x=e=>{var t,n;let l=v.current;if(!l){i(r+e);return}let o=null!==(t=l.selectionStart)&&void 0!==t?t:r.length,a=null!==(n=l.selectionEnd)&&void 0!==n?n:r.length;
1i(r.slice(0,o)+e+r.slice(a));let s=e.indexOf("("),d=o+(s>=0?s+1:e.length);requestAnimationFrame(()=>{l.focus(),l.setSelectionRange(d,d)})};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{ref:c,style:{position:"absolute",inset:0,pointerEvents:"none"}}),(0,O.createPortal)((0,n.jsxs)("div",{ref:u,onClick:e=>e.stopPropagation(),style:{position:"fixed",top:p.top,left:p.left,visibility:f?"hidden":"visible",pointerEvents:f?"none":"auto",width:300,maxHeight:"calc(100vh - 24px)",overflowY:"auto",background:"var(--bg-elevated)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",boxShadow:"0 4px 16px rgba(0,0,0,0.15)",zIndex:300,padding:10,display:"flex",flexDirection:"column",gap:8},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,n.jsxs)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-secondary)",display:"flex",alignItems:"center",gap:5},children:[(0,n.jsx)(V.Z,{size:11})," Calculate ",t]}),(0,n.jsxs)("div",{style:{display:"flex",gap:6,flexShrink:0},children:[(0,n.jsx)("button",{onClick:a,style:{background:"var(--bg-elevated)",border:"1px solid var(--border-subtle)",color:"var(--text-secondary)",borderRadius:"var(--radius-sm)",padding:"4px 10px",fontSize:11,cursor:"pointer"},children:"Cancel"}),(0,n.jsxs)("button",{onClick:o,disabled:!r.trim(),style:{background:"var(--accent)",color:"var(--fg-on-solid)",border:"none",borderRadius:"var(--radius-sm)",padding:"4px 10px",fontSize:11,cursor:r.trim()?"pointer":"not-allowed",opacity:r.trim()?1:.5,fontWeight:500},children:["Fill ",t]})]})]}),(0,n.jsx)("input",{ref:v,value:r,onChange:e=>i(e.target.value),autoFocus:!0,onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),o()):"Escape"===e.key&&(e.preventDefault(),a())},placeholder:s,style:{height:30,border:"1px solid var(--accent)",borderRadius:"var(--radius-sm)",background:"var(--bg-elevated)",color:"var(--text-primary)",fontSize:12,fontFamily:"var(--font-mono)",padding:"0 8px"}}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-tertiary)"},children:"Functions - click to insert:"}),Y.kR.map(e=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:9,textTransform:"uppercase",letterSpacing:"0.05em",color:"var(--text-tertiary)",marginBottom:3},children:e.group}),(0,n.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:4},children:e.fns.map(e=>(0,n.jsx)("button",{type:"button",title:e.hint,onClick:()=>x(e.insert),style:{fontFamily:"var(--font-mono)",fontSize:10.5,fontWeight:600,color:"var(--accent)",background:"var(--accent-subtle)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",padding:"3px 7px",cursor:"pointer"},children:e.name},e.name))})]},e.group)),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-tertiary)"},children:d})]}),document.body)]})}function ex(e){let{label:t,onApply:r,onClose:i}=e,{anchorRef:o,boxRef:a,pos:s,clipped:d}=ee(i),[c,u]=(0,l.useState)("2"),p={display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 10px",fontSize:12.5,fontFamily:"var(--font-sans)",background:"none",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",textAlign:"left",cursor:"pointer",color:"var(--text-primary)"};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{ref:o,style:{position:"absolute",inset:0,pointerEvents:"none"}}),(0,O.createPortal)((0,n.jsxs)("div",{ref:a,onClick:e=>e.stopPropagation(),style:{position:"fixed",top:s.top,left:s.left,visibility:d?"hidden":"visible",pointerEvents:d?"none":"auto",width:240,maxHeight:"calc(100vh - 24px)",overflowY:"auto",background:"var(--bg-elevated)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",boxShadow:"0 4px 16px rgba(0,0,0,0.15)",zIndex:300,padding:10,display:"flex",flexDirection:"column",gap:8},children:[(0,n.jsxs)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-secondary)",display:"flex",alignItems:"center",gap:5},children:[(0,n.jsx)(W.Z,{size:11})," Format ",t]}),(0,n.jsxs)("button",{type:"button",style:p,onClick:()=>r(null),children:[(0,n.jsx)(Q.Z,{size:12})," Normal (default)"]}),(0,n.jsxs)("button",{type:"button",style:p,onClick:()=>r({kind:"percentage"}),children:[(0,n.jsx)(W.Z,{size:12})," Percentage (append %)"]}),(0,n.jsxs)("div",{style:{border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",padding:8,display:"flex",flexDirection:"column",gap:6},children:[(0,n.jsxs)("div",{style:{fontSize:11.5,display:"flex",alignItems:"center",gap:6,color:"var(--text-primary)"},children:[(0,n.jsx)(L.Z,{size:12})," Round to",(0,n.jsx)("input",{type:"number",min:0,max:10,value:c,onChange:e=>u(e.target.value),style:{width:54,height:26,border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",background:"var(--bg-elevated)",color:"var(--text-primary)",fontSize:12,padding:"0 6px"}}),"decimals"]}
1),(0,n.jsx)("button",{type:"button",onClick:()=>r({kind:"round",decimals:Math.max(0,Math.min(10,Math.round(Number(c)||0)))}),style:{background:"var(--accent)",color:"var(--fg-on-solid)",border:"none",borderRadius:"var(--radius-sm)",padding:"5px 12px",fontSize:11.5,cursor:"pointer",fontWeight:500},children:"Apply round"})]}),(0,n.jsxs)("div",{style:{fontSize:10,color:"var(--text-tertiary)"},children:["Applies to every cell in ",t,"."]})]}),document.body)]})}function eh(e){var t,r,l,i;let{metricId:o,mode:a,filter:s,metricOptions:d,fyLabels:c,resolved:u,onClose:p}=e,f=d.find(e=>e.id===o),v=null!==(t=null==s?void 0:s.fyIndex)&&void 0!==t?t:0,x=[null!==(r=null==u?void 0:u.fyPeriodCode)&&void 0!==r?r:eo(c,v),(null==s?void 0:s.months)&&s.months.length&&s.months.length<12?"".concat(s.months.map(e=>E.gg[e]).join(", ")):"Full year",(null==s?void 0:s.facilityIds)&&s.facilityIds.length?"".concat(s.facilityIds.length," facilities"):"All facilities"].join(" \xb7 "),m={tab:"Formula Tree",kpi:o};(null==u?void 0:u.fyPeriodCode)&&(m.period=u.fyPeriodCode),(null==s?void 0:s.facilityIds)&&1===s.facilityIds.length&&(m.facility=s.facilityIds[0]);let g="/app/projects/dashboards?".concat(new URLSearchParams(m).toString());return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{onClick:p,style:{position:"fixed",inset:0,zIndex:200,background:"var(--scrim)"}}),(0,n.jsxs)("div",{style:{position:"fixed",top:"16vh",left:"50%",transform:"translateX(-50%)",zIndex:201,width:"min(480px, calc(100vw - 32px))",background:"var(--bg-elevated)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-xl)",boxShadow:"var(--shadow-xl)",display:"flex",flexDirection:"column",maxHeight:"72vh"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:10,padding:"14px 18px",borderBottom:"1px solid var(--border-subtle)"},children:[(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsxs)("div",{style:{fontSize:14,fontWeight:600,display:"flex",alignItems:"center",gap:6,minWidth:0},children:[(0,n.jsx)(H.Z,{size:13,color:"var(--accent)",style:{flexShrink:0}}),(0,n.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:null==f?void 0:f.name,children:null!==(l=null==f?void 0:f.name)&&void 0!==l?l:"Unknown metric"})]}),(0,n.jsxs)("div",{style:{fontSize:11,color:"var(--text-tertiary)",marginTop:3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:"".concat(er[a]," \xb7 ").concat(x),children:[er[a]," \xb7 ",x]})]}),(0,n.jsx)("button",{onClick:p,style:{flexShrink:0,background:"none",border:"none",color:"var(--text-tertiary)",cursor:"pointer",padding:4},children:(0,n.jsx)(h.Z,{size:15})})]}),u?(0,n.jsxs)("div",{style:{padding:"10px 18px",overflowY:"auto"},children:[(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:10},children:[(0,n.jsxs)(_.Caps,{size:10,children:["Total (",a,")"]}),(0,n.jsxs)(_.NumMono,{size:18,weight:700,color:"var(--accent)",children:[el(u.raw,a)," ",(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-tertiary)"},children:u.unit})]})]}),(0,n.jsx)("div",{style:{border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",overflow:"hidden"},children:(null!==(i=u.breakdown)&&void 0!==i?i:[]).map((e,t)=>(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",gap:8,padding:"7px 10px",background:t%2?"var(--bg-sunken)":"transparent",fontSize:12},children:[(0,n.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e.facility,children:e.facility}),(0,n.jsx)(_.NumMono,{size:12,color:"var(--text-primary)",style:{flexShrink:0},children:el(e.value,a)})]},e.facilityId))}),(0,n.jsxs)("div",{style:{fontSize:10.5,color:"var(--text-tertiary)",marginTop:8},children:["Facility contributions under the current filter","deviation"!==a?" - sum to the total above":" - each facilityâs own % change","."]})]}):(0,n.jsx)("div",{style:{padding:"18px",fontSize:12.5,color:"var(--text-tertiary)"},children:"This cell hasnât been refreshed yet - use Refresh values to pull real numbers before drilling in."}),(0,n.jsx)("div",{style:{padding:"10px 18px",borderTop:"1px solid var(--border-subtle)",background:"var(--bg-base)"},children:(0,n.jsxs)("a",{href:g,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-flex",alignItems:"center",gap:6,color:"var(--accent)",fontSize:12.5,fontWeight:500},children:["Open in Formula Tree - real breakdown by node ",(0,n.jsx)(R.Z,{size:12})]})})]})]})}function em(e){let{children:t,onClose:r,align:l="left"}=e,{anchorRef:i,boxRef:o,pos:a,clipped:s}=ee(r,l);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{ref:i,style:{position:"absolute",inset:0,pointerEvents:"none"}}),(0,O.createPortal)((0,n.jsx)("div",{ref:o,onClick:e=>
1e.stopPropagation(),style:{position:"fixed",top:a.top,left:a.left,visibility:s?"hidden":"visible",pointerEvents:s?"none":"auto",minWidth:180,background:"var(--bg-elevated)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",boxShadow:"0 4px 16px rgba(0,0,0,0.15)",padding:4,zIndex:300},children:t}),document.body)]})}function eg(e){let{icon:t,label:r,onClick:l,disabled:i,danger:o}=e;return(0,n.jsxs)("button",{type:"button",disabled:i,onClick:e=>{e.stopPropagation(),l()},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 10px",fontSize:12.5,fontFamily:"var(--font-sans)",background:"none",border:"none",borderRadius:"var(--radius-sm)",textAlign:"left",cursor:i?"not-allowed":"pointer",color:i?"var(--text-tertiary)":o?"var(--error)":"var(--text-primary)",opacity:i?.5:1},onMouseEnter:e=>{i||(e.currentTarget.style.background="var(--bg-sunken)")},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[t,r]})}function eb(){return(0,n.jsx)("div",{style:{height:1,background:"var(--border-subtle)",margin:"4px 2px"}})}function ey(e){let{value:t,onChange:r}=e;return(0,n.jsx)("span",{style:{display:"inline-flex",alignItems:"center",border:"1px solid var(--accent)",borderRadius:"var(--radius-sm)",background:"var(--bg-elevated)",overflow:"hidden"},children:["value","comparison"].map((e,l)=>(0,n.jsx)("button",{onClick:()=>r(e),title:er[e],style:{padding:"3px 9px",background:t===e?"var(--accent)":"transparent",color:t===e?"var(--fg-on-solid)":"var(--accent)",border:"none",borderLeft:0===l?"none":"1px solid var(--accent)",cursor:"pointer",fontSize:10.5,fontFamily:"var(--font-mono)",fontWeight:600,letterSpacing:"0.06em"},children:en[e]},e))})}function ej(e){let{onClick:t,disabled:r,children:l,accent:i}=e,o="accent"===i?{bg:"var(--accent-subtle)",bd:"var(--accent)",fg:"var(--accent)"}:"warn"===i?{bg:"var(--warning-bg)",bd:"var(--warning)",fg:"var(--warning)"}:{bg:"var(--bg-sunken)",bd:"var(--border-subtle)",fg:"var(--text-secondary)"};return(0,n.jsx)("button",{onClick:t,disabled:r,style:{display:"inline-flex",alignItems:"center",gap:4,padding:"4px 9px",background:o.bg,border:"1px solid ".concat(o.bd),borderRadius:"var(--radius-sm)",fontSize:11,fontFamily:"var(--font-sans)",color:o.fg,cursor:r?"not-allowed":"pointer",opacity:r?.5:1,fontWeight:i?500:400},children:l})}let ek={width:1,height:18,background:"var(--border-subtle)",margin:"0 4px"},ew={width:"100%",marginTop:3,height:28,border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",background:"var(--bg-elevated)",color:"var(--text-primary)",fontSize:12,fontFamily:"var(--font-sans)",padding:"0 6px"},eS={padding:"4px 10px",width:32,background:"var(--bg-sunken)",borderRight:"1px solid var(--border-subtle)",borderBottom:"1px solid var(--border-subtle)",fontSize:10,color:"var(--text-tertiary)"},eC={padding:"4px 8px",textAlign:"center",borderRight:"1px solid var(--border-subtle)",borderBottom:"1px solid var(--border-subtle)",background:"var(--bg-sunken)",fontSize:10.5,fontFamily:"var(--font-mono)",color:"var(--text-tertiary)",fontWeight:600,letterSpacing:"0.06em",width:200},ez={padding:"0 8px",minWidth:32,background:"var(--bg-sunken)",borderRight:"1px solid var(--border-subtle)",borderBottom:"1px solid var(--border-subtle)",fontFamily:"var(--font-mono)",fontSize:10.5,color:"var(--text-tertiary)",fontWeight:600,textAlign:"center",position:"sticky",left:0};var eM=r(6144),eI=r(5015),eF=r(54603),eA=r(78234),eR=r(65318),eT=r(13694),eD=r(70570),eZ=r(24475),eE=r(71190),eB=r(54816),eO=r(44342),eN=r(53971),eL=r(48904),eW=r(64313),eP=r(5172),eU=r(52237),eH=r(53871),eG=r(51815),eV=r(13567),eQ=r(8324),e_=r(79769),eY=r(72277),eq=r(69481),eK=r(73546),e$=r(7763),eJ=r(35399),eX=r(14389),e0=r(71016),e1=r(68080),e2=r(94318),e6=r(13826),e3=r(46129),e4=r(77086),e8=r(55227),e5=r(70831),e9=r(78322),e7=r(40959);let te=eT.Z.extend({addAttributes:()=>({fontSize:{default:null,parseHTML:e=>e.style.fontSize||null,renderHTML:e=>e.fontSize?{style:"font-size:".concat(e.fontSize)}:{}}})}),tt=["8px","9px","10px","11px","12px","14px","16px","18px","20px","24px","28px","32px","36px","48px","60px","72px"],tr=[{label:"Default",css:""},{label:"Inter / Sans",css:"var(--font-sans), Arial, sans-serif"},{label:"Arial",css:"Arial, sans-serif"},{label:"Helvetica",css:"Helvetica, Arial, sans-serif"},{label:"Verdana",css:"Verdana, Geneva, sans-serif"}
1,{label:"Tahoma",css:"Tahoma, Geneva, sans-serif"},{label:"Trebuchet MS",css:'"Trebuchet MS", sans-serif'},{label:"Georgia",css:"Georgia, serif"},{label:"Times New Roman",css:'"Times New Roman", Times, serif'},{label:"Garamond",css:"Garamond, serif"},{label:"Courier New / Mono",css:'"Courier New", var(--font-mono), monospace'},{label:"Comic Sans MS",css:'"Comic Sans MS", cursive'}];function tn(e){var t,r,l,i;let{html:o,onChange:a}=e,s=(0,eI.jE)({immediatelyRender:!1,extensions:[eF.Z,eA.Z,te,eD.Z,eZ.Z,eE.ZP.configure({multicolor:!0}),eO.Z,eN.Z,eL.Z,eW.ZP.configure({nested:!0}),eB.ZP.configure({openOnClick:!1,autolink:!0,HTMLAttributes:{rel:"noopener noreferrer",target:"_blank"}}),eR.Z.configure({types:["heading","paragraph"]}),eP.Z.configure({placeholder:"Write here⦠use the toolbar to format."})],content:o||"<p></p>",onUpdate:e=>{let{editor:t}=e;return a(t.getHTML())},editorProps:{attributes:{class:"cr-richtext",style:"outline:none;min-height:80px;font-size:13px;line-height:1.6;"}}});return s?(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:ta,children:[(0,n.jsx)(ti,{onClick:()=>s.chain().focus().undo().run(),disabled:!s.can().undo(),title:"Undo",children:(0,n.jsx)(eU.Z,{size:12})}),(0,n.jsx)(ti,{onClick:()=>s.chain().focus().redo().run(),disabled:!s.can().redo(),title:"Redo",children:(0,n.jsx)(eH.Z,{size:12})}),(0,n.jsx)(to,{}),(0,n.jsx)(eM.D,{value:function(e){for(let t of[1,2,3,4])if(e.isActive("heading",{level:t}))return"h".concat(t);return"p"}(s),onChange:e=>(function(e,t){let r=e.chain().focus();"p"===t?r.setParagraph().run():r.setHeading({level:Number(t.slice(1))}).run()})(s,e),title:"Text style",style:ts,options:[{value:"p",label:"Body text"},{value:"h1",label:"Heading 1"},{value:"h2",label:"Heading 2"},{value:"h3",label:"Heading 3"},{value:"h4",label:"Heading 4"}],size:"sm"}),(0,n.jsx)(eM.D,{value:null!==(t=s.getAttributes("textStyle").fontFamily)&&void 0!==t?t:"",onChange:e=>{e?s.chain().focus().setFontFamily(e).run():s.chain().focus().unsetFontFamily().run()},title:"Font",style:ts,options:tr.map(e=>({value:e.css,label:e.label})),size:"sm"}),(0,n.jsx)(eM.D,{value:null!==(r=s.getAttributes("textStyle").fontSize)&&void 0!==r?r:"",onChange:e=>{s.chain().focus().setMark("textStyle",{fontSize:e||null}).run()},title:"Font size",style:ts,options:[{value:"",label:"Size"},...tt.map(e=>({value:e,label:String(parseInt(e,10))}))],size:"sm"}),(0,n.jsx)(to,{}),(0,n.jsx)(ti,{active:s.isActive("bold"),onClick:()=>s.chain().focus().toggleBold().run(),title:"Bold",children:(0,n.jsx)(eG.Z,{size:12})}),(0,n.jsx)(ti,{active:s.isActive("italic"),onClick:()=>s.chain().focus().toggleItalic().run(),title:"Italic",children:(0,n.jsx)(eV.Z,{size:12})}),(0,n.jsx)(ti,{active:s.isActive("underline"),onClick:()=>s.chain().focus().toggleUnderline().run(),title:"Underline",children:(0,n.jsx)(eQ.Z,{size:12})}),(0,n.jsx)(ti,{active:s.isActive("strike"),onClick:()=>s.chain().focus().toggleStrike().run(),title:"Strikethrough",children:(0,n.jsx)(e_.Z,{size:12})}),(0,n.jsx)(ti,{active:s.isActive("code"),onClick:()=>s.chain().focus().toggleCode().run(),title:"Inline code",children:(0,n.jsx)(eY.Z,{size:12})}),(0,n.jsx)(to,{}),(0,n.jsxs)("label",{title:"Text color",style:{...tl,position:"relative",padding:0,overflow:"hidden"},children:[(0,n.jsx)("span",{style:{fontSize:11,fontWeight:700,color:null!==(l=s.getAttributes("textStyle").color)&&void 0!==l?l:"var(--text-secondary)"},children:"A"}),(0,n.jsx)("input",{type:"color",value:null!==(i=s.getAttributes("textStyle").color)&&void 0!==i?i:"#000000",onChange:e=>s.chain().focus().setColor(e.target.value).run(),style:{position:"absolute",inset:0,opacity:0,cursor:"pointer"}})]}),(0,n.jsx)(ti,{active:s.isActive("highlight"),onClick:()=>s.chain().focus().toggleHighlight().run(),title:"Highlight",children:(0,n.jsx)(eq.Z,{size:12})}),(0,n.jsx)(ti,{active:s.isActive("subscript"),onClick:()=>s.chain().focus().toggleSubscript().run(),title:"Subscript",children:(0,n.jsx)(eK.Z,{size:12})}),(0,n.jsx)(ti,{active:s.isActive("superscript"),onClick:()=>s.chain().focus().toggleSuperscript().run(),title:"Superscript",children:(0,n.jsx)(e$.Z,{size:12})}),(0,n.jsx)(to,{}),(0,n.jsx)(ti,{active:s.isActive("link"),onClick:()=>{let e=s.getAttributes("link").href,t=window.prompt("Link URL",null!=e?e:"https://");if(null!==t){if(""===t){s.chain().focus().extendMarkRange("link").unsetLink().run();return}s.chain().focus().extendMarkRange("link").setLink({href:t}).run()}},title:"Add / edit link",children:(0,n.jsx)(eJ.Z,{size:12})}),(0,n.jsx)(ti,{onClick:()=>s.chain().focus().unsetLink().run(),disabled:!s.isActive("link"),title:"Remove link",children:(0,n.jsx)(eX.Z,{size:12})}),(0,n.jsx)(to,{}),(0,n.jsx)(ti,{active:s.isActive("bulletList"),onClick:()=>s.chain().focus().toggleBulletList().run(),title:"Bulleted list",children:(0,n.jsx)(d.Z,{size:12})}),(0,n.jsx)(ti,{active:s.isActive("orderedList"),onClick:()=>s.chain().focus().toggleOrderedList().run(),title:"Numbered list",children:(0,n.jsx)(e0.Z,{size:12})}),(0,n.jsx)(ti,{active:s.isActive("taskList"),onClick:()=>s.chain().focus().toggleTaskList().run(),title:"Checklist",children:(0,n.jsx)(e1.Z,{size:12})}),(0,n.jsx)(to,{}),(0,n.jsx)(ti,{active:s.isActive("blockquote"),onClick:()=>s.chain().focus().toggleBlockquote().run(),title:"Quote",children:(0,n.jsx)(e2.Z,{size:12})}),(0,n.jsx)(ti,{active:s.isActive("codeBlock"),onClick:()=>s.chain().focus().toggleCodeBlock().run(),title:"Code block",children:(0,n.jsx)(e6.Z,{size:12})}),(0,n.jsx)(ti,{onClick:()=>s.chain().focus().setHorizontalRule().run(),title:"Divider",children:(0,n.jsx)(e3.Z,{size:12})}),(0,n.jsx)(to,{}),(0,n.jsx)(ti,{active:s.isActive({textAlign:"left"}),onClick:()=>s.chain().focus().setTextAlign("left").run(),title:"Align left",children:(0,n.jsx)(e4.Z,{size:12})}),(0,n.jsx)(ti,{active:s.isActive({textAlign:"center"}),onClick:()=>s.chain().focus().setTextAlign("center").run(),title:"Align center",children:(0,n.jsx)(e8.Z,{size:12})}),(0,n.jsx)(ti,{active:s.isActive({textAlign:"right"}),onClick:()=>s.chain().focus().setTextAlign("right").run(),title:"Align right",children:(0,n.jsx)(e5.Z,{size:12})}),(0,n.jsx)(ti,{active:s.isActive({textAlign:"justify"}),onClick:()=>s.chain().focus().setTextAlign("justify").run(),title:"Justify",children:(0,n.jsx)(e9.Z,{size:12})}),(0,n.jsx)(to,{}),(0,n.jsx)(ti,{onClick:()=>s.chain().focus().unsetAllMarks().clearNodes().run(),title:"Clear formatting",children:(0,n.jsx)(e7.Z,{size:12})})]}),(0,n.jsx)(eI.kg,{editor:s})]}):(0,n.jsx)("div",{style:{minHeight:120}})}let tl={display:"flex",alignItems:"center",justifyContent:"center",width:26,height:26,borderRadius:"var(--radius-sm)",border:"1px solid var(--border-subtle)",background:"var(--bg-elevated)",color:"var(--text-secondary)",cursor:"pointer"};function ti(e){let{active:t,onClick:r,title:l,disabled:i,children:o}=e;return(0,n.jsx)("button",{type:"button",onClick:r,title:l,disabled:i,style:{...tl,border:"1px solid ".concat(t?"var(--accent)":"var(--border-subtle)"),background:t?"var(--accent-subtle)":"var(--bg-elevated)",color:i?"var(--text-tertiary)":t?"var(--accent)":"var(--text-secondary)",cursor:i?"not-allowed":"pointer",opacity:i?.5:1},children:o})}function to(){return(0,n.jsx)("span",{style:{width:1,height:18,background:"var(--border-subtle)",margin:"0 2px"}})}let ta={display:"flex",gap:4,marginBottom:8,paddingBottom:8,borderBottom:"1px solid var(--border-subtle)",flexWrap:"wrap",alignItems:"center"},ts={height:26,border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",background:"var(--bg-elevated)",color:"var(--text-secondary)",fontSize:11.5,fontFamily:"var(--font-sans)",padding:"0 4px",cursor:"pointer"};r(83079);var td=r(12119),tc=(0,td.$)("c7a6572fe2822a82895bb6b4ddc4f90c2662cf94"),tu=(0,td.$)("a65c098f99a5b1d6d93c8e9b3487af991bede658"),tp=(0,td.$)("c2d335f47825b330d9a419379427163d5c4db119"),tf=(0,td.$)("178dc07eaa7c66e9c43e9895faab658f00f88392"),tv=(0,td.$)("defe0a818ea5ef45ae2a88f45fef2fbed5d2280a"),tx=(0,td.$)("41c9b509ad1cb6665b3ddfa56e97a0fbcb098333"),th=(0,td.$)("6b77c57687d6a7419027f31182191a947ede5dee"),tm=(0,td.$)("c6e4653ba98b1ce38e19f7573ba3ee366c6a0b3a"),tg=(0,td.$)("b67c3e7383f6013fd6a38e42b0a44bbc689b3a33");(0,td.$)("d2e51fbf5c28533d1593701ec9d54da48ce3f7b3");var tb=(0,td.$)("de488e82838564a24009f3bdb0dbc6deb08d336a");(0,td.$)("b686678252015ef6af8e930ece50d39df417b153"),(0,td.$)("f0d9d81872ca1443ff3a5e72923e969071f97dfe");let ty=(0,l.createContext)({metrics:[],facilities:[],fyLabels:[]}),tj={sum:"Sum",average:"Average",count:"Count",multiply:"Multiply",divide:"Divide",percentage:"Percentage",percentOfTotal:"% of Grand Total"};function tk(){let e=(0,o.t)(),t=(0,i.usePathname)(),r=(0,i.useSearchParams)(),a=(0,l.useMemo)(()=>(function(e){let t=e.get("report");return t?{view:"detail",detailSource:{kind:"existing",id:t}}:"picker"===e.get("view")?{view:"templatePicker",detailSource:null}:"new"===e.get("view")?{view:"detail",detailSource:{kind:"new",cloneFromId:e.get("tmpl")}}:{view:"list",detailSource:null}})(r),[]),[s,d]=(0,l.useState)(a.view),[c,u]=(0,l.useState)(a.detailSource),[p,f]=(0,l.useState)(null),[v,x]=(0,l.useState)({metrics:[],facilities:[],fyLabels:[]});function h(e){f(e),setTimeout(()=>f(null),3200)}function m(n){var l,i;d(n.view),u(n.detailSource);let o=new URLSearchParams(r.toString());o.delete("report"),o.delete("view"),o.delete("tmpl"),o.delete("sub"),"templatePicker"===n.view?o.set("view","picker"):"detail"===n.view&&(null===(l=n.detailSource)||void 0===l?void 0:l.kind)==="existing"?o.set("report",n.detailSource.id):"detail"===n.view&&(null===(i=n.detailSource)||void 0===i?void 0:i.kind)==="new"&&(o.set("view","new"),n.detailSource.cloneFromId&&o.set("tmpl",n.detailSource.cloneFromId)),e.replace("".concat(t,"?").concat(o.toString()),{scroll:!1})}return(0,l.useEffect)(()=>
1{if("detail"!==s)return;let e=!1;return tx().then(t=>{e||(t.ok?x({metrics:t.metrics,facilities:t.facilities,fyLabels:t.fyLabels}):h("â ".concat(t.error)))}),()=>{e=!0}},[s]),(0,n.jsx)(ty.Provider,{value:v,children:(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-4)",position:"relative"},children:["list"===s&&(0,n.jsx)(tI,{onOpen:e=>m({view:"detail",detailSource:{kind:"existing",id:e}}),onNew:()=>m({view:"templatePicker",detailSource:null}),showToast:h}),"templatePicker"===s&&(0,n.jsx)(tF,{onBack:()=>m({view:"list",detailSource:null}),onPick:e=>m({view:"detail",detailSource:{kind:"new",cloneFromId:e}}),showToast:h}),"detail"===s&&c&&(0,n.jsx)(tD,{source:c,onBack:()=>m({view:"list",detailSource:null}),onReportReady:n=>{u({kind:"existing",id:n});let l=new URLSearchParams(r.toString());l.delete("view"),l.delete("tmpl"),l.set("report",n),e.replace("".concat(t,"?").concat(l.toString()),{scroll:!1})},showToast:h}),p&&(0,n.jsx)("div",{style:{position:"fixed",bottom:24,left:"50%",transform:"translateX(-50%)",background:"var(--text-primary)",color:"var(--bg-elevated)",padding:"10px 18px",borderRadius:"var(--radius-md)",fontSize:12,boxShadow:"var(--shadow-lg)",zIndex:60,maxWidth:"90vw"},children:p})]})})}function tw(e){return new Date(e).toLocaleDateString("en-GB",{day:"numeric",month:"short"})}function tS(e){let{status:t}=e,r="published"===t;return(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:11,fontWeight:600,borderRadius:"var(--radius-pill)",padding:"2px 10px",background:r?"var(--success-bg)":"var(--warning-bg)",color:r?"var(--success)":"var(--warning)",border:"1px solid ".concat(r?"var(--success)":"var(--warning)"),borderColor:r?"color-mix(in srgb, var(--success) 30%, transparent)":"color-mix(in srgb, var(--warning) 30%, transparent)"},children:[(0,n.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:"currentColor"}}),r?"Published":"Draft"]})}function tC(e){let{textCount:t,sheetCount:r}=e;return(0,n.jsxs)("div",{style:{display:"flex",gap:4,alignItems:"center"},children:[r>0&&(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:3,padding:"1px 6px",borderRadius:"var(--radius-sm)",fontSize:10,fontWeight:600,background:"var(--accent-subtle)",color:"var(--accent)"},children:[r," sheet",1!==r?"s":""]}),t>0&&(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:3,padding:"1px 6px",borderRadius:"var(--radius-sm)",fontSize:10,fontWeight:600,background:"var(--bg-sunken)",color:"var(--text-secondary)"},children:[t," text"]})]})}function tz(e){let{iso:t}=e;return t?(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:10,fontWeight:500,padding:"2px 8px",borderRadius:"var(--radius-pill)",background:"var(--success-bg)",color:"var(--success)"},children:[(0,n.jsx)(a.Z,{size:10})," Refreshed ",tw(t)]}):null}function tM(e){let{view:t,onChange:r}=e,l=e=>({display:"flex",alignItems:"center",justifyContent:"center",width:30,height:28,cursor:"pointer",border:"none",padding:0,fontFamily:"var(--font-sans)",background:e?"var(--bg-sunken)":"transparent",color:e?"var(--text-primary)":"var(--text-tertiary)"});return(0,n.jsxs)("div",{style:{display:"inline-flex",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-md)",overflow:"hidden"},children:[(0,n.jsx)("button",{type:"button",title:"Tile view",onClick:()=>r("tile"),style:l("tile"===t),children:(0,n.jsx)(s.Z,{size:14})}),(0,n.jsx)("button",{type:"button",title:"List view",onClick:()=>r("list"),style:{...l("list"===t),borderLeft:"1px solid var(--border-subtle)"},children:(0,n.jsx)(d.Z,{size:14})})]})}function tI(e){var t;let{onOpen:r,onNew:i,showToast:o}=e,[a,s]=(0,l.useState)(null),[d,u]=(0,l.useState)(null),[p,f]=(0,l.useState)(null),[v,x]=(0,l.useTransition)(),[h,m]=(0,l.useState)("tile");(0,l.useEffect)(()=>{let e=!1;return tu().then(t=>{e||(t.ok?s(t.reports):u(t.error))}),()=>{e=!0}},[]);let g=null!==(t=null==a?void 0:a.length)&&void 0!==t?t:0;return(0,n.jsxs)("div",{children:[d&&(0,n.jsx)("div",{style:{fontSize:12,color:"var(--error)",marginBottom:12},children:d}),null===a&&!d&&(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-tertiary)",marginBottom:12},children:"Loading reports..."}),null!==a&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:14},children:[(0,n.jsxs)("span",{style:{fontSize:12,fontWeight:500,color:"var(--text-tertiary)"},children:[g," report",1!==g?"s":""]}),(0,n.jsx)("div",{style:{display:"flex",gap:6,alignItems:"center"},children:(0,n.jsx)(tM,{view:h,onChange:m})})]}),"tile"===h?(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(300px, 1fr))",gap:14},children:[a.map(e=>(0,n.jsxs)("div",{style:{background:"var(--bg-elevated)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-lg)",padding:18,dis
1play:"flex",flexDirection:"column",gap:12,cursor:"pointer"},onClick:()=>r(e.id),children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"var(--space-2)"},children:[(0,n.jsx)("div",{style:{fontSize:14,fontWeight:600},children:e.name}),(0,n.jsx)(tS,{status:e.status})]}),e.description?(0,n.jsx)("div",{style:{fontSize:13,color:"var(--text-secondary)",lineHeight:1.45},children:e.description}):(0,n.jsx)("div",{style:{fontSize:13,color:"var(--text-tertiary)",fontStyle:"italic"},children:"No description"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,fontSize:11,paddingTop:4,borderTop:"1px solid var(--bg-sunken)",color:"var(--text-tertiary)"},children:[(0,n.jsx)(tC,{textCount:e.textCount,sheetCount:e.sheetCount}),(0,n.jsx)("span",{style:{flex:1}}),(0,n.jsxs)("span",{children:["Updated ",tw(e.updatedAt)]})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,marginTop:"auto"},children:[(0,n.jsx)(tz,{iso:e.lastRefreshedAt}),(0,n.jsx)("span",{style:{flex:1}}),(0,n.jsx)(tA,{title:'Delete "'.concat(e.name,'"'),onClick:t=>{t.stopPropagation(),f({id:e.id,name:e.name})}})]})]},e.id)),(0,n.jsxs)("button",{type:"button",onClick:i,style:{border:"1px dashed var(--border-strong)",borderRadius:"var(--radius-lg)",display:"flex",alignItems:"center",justifyContent:"center",flexDirection:"column",gap:6,color:"var(--text-secondary)",cursor:"pointer",padding:16,minHeight:160,background:"transparent",fontFamily:"var(--font-sans)",fontSize:13,fontWeight:500},children:[(0,n.jsx)("span",{style:{width:36,height:36,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:18,fontWeight:300,background:"var(--bg-sunken)",color:"var(--text-secondary)"},children:"+"}),"New report"]})]}):(0,n.jsxs)("div",{style:{border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-lg)",overflow:"hidden",background:"var(--bg-elevated)"},children:[(0,n.jsx)("div",{style:{overflowX:"auto"},children:(0,n.jsxs)("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:[(0,n.jsx)("thead",{children:(0,n.jsx)("tr",{children:["Name","Status","Blocks","Updated","Refreshed",""].map(e=>(0,n.jsx)("th",{style:{textAlign:""===e?"right":"left",padding:"8px 12px",fontSize:11,fontWeight:600,letterSpacing:"0.03em",textTransform:"uppercase",color:"var(--text-tertiary)",borderBottom:"1px solid var(--border-subtle)",whiteSpace:"nowrap"},children:e},e))})}),(0,n.jsx)("tbody",{children:a.map(e=>(0,n.jsxs)("tr",{style:{cursor:"pointer"},onClick:()=>r(e.id),children:[(0,n.jsxs)("td",{style:{padding:"12px 12px",borderBottom:"1px solid var(--bg-sunken)",verticalAlign:"middle"},children:[(0,n.jsx)("div",{style:{fontWeight:600,fontSize:13},children:e.name}),e.description?(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-tertiary)",marginTop:2},children:e.description}):(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-tertiary)",fontStyle:"italic",marginTop:2},children:"No description"})]}),(0,n.jsx)("td",{style:{padding:"12px 12px",borderBottom:"1px solid var(--bg-sunken)",verticalAlign:"middle"},children:(0,n.jsx)(tS,{status:e.status})}),(0,n.jsx)("td",{style:{padding:"12px 12px",borderBottom:"1px solid var(--bg-sunken)",verticalAlign:"middle"},children:(0,n.jsx)(tC,{textCount:e.textCount,sheetCount:e.sheetCount})}),(0,n.jsx)("td",{style:{padding:"12px 12px",borderBottom:"1px solid var(--bg-sunken)",verticalAlign:"middle",fontSize:12,color:"var(--text-secondary)",whiteSpace:"nowrap"},children:tw(e.updatedAt)}),(0,n.jsx)("td",{style:{padding:"12px 12px",borderBottom:"1px solid var(--bg-sunken)",verticalAlign:"middle"},children:e.lastRefreshedAt?(0,n.jsx)(tz,{iso:e.lastRefreshedAt}):(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-tertiary)"},children:"--"})}),(0,n.jsx)("td",{style:{padding:"12px 12px",borderBottom:"1px solid var(--bg-sunken)",verticalAlign:"middle",textAlign:"right"},children:(0,n.jsxs)("div",{style:{display:"flex",gap:4,alignItems:"center",justifyContent:"flex-end"},children:[(0,n.jsx)(Z.Btn,{variant:"primary",size:"sm",onClick:t=>{t.stopPropagation(),r(e.id)},children:"Open"}),(0,n.jsx)(tA,{title:'Delete "'.concat(e.name,'"'),onClick:t=>{t.stopPropagation(),f({id:e.id,name:e.name})}})]})})]},e.id))})]})}),a.length>0&&(0,n.jsx)("div",{style:{padding:"10px 12px",borderTop:"1px solid var(--border-subtle)"},children:(0,n.jsxs)("button",{type:"button",onClick:i,style:{background:"none",border:"none",cursor:"pointer",fontFamily:"var(--font-sans)",fontSize:12,fontWeight:500,color:"var(--text-secondary)",display:"flex",alignItems:"center",gap:4,padding:0},children:[(0,n.jsx)(c.Z,{size:13})," New report"]})})]})]}),p&&(0,n.jsx)(tR,{title:"Delete report?",body:(0,n.jsxs)(n.Fragment,{children:["This permanently deletes ",(0,n.jsx)("strong",{children:p.name}),", including every content block and its refreshed values. This cannot be undone."]}),confirmLabel:v?"Deleting...":"Delete report",busy:v,onCancel:()=>f(null),onConfirm:function(){p&&x(async()=>{let e=await tb(p.id);e.ok?(s(e=>(null!=e?e:[]).filter(e=>e.id!==p.id)),o('Deleted "'.concat(p.name,'"'))):o("".concat(e.error)),f(null)})}})]})}function tF(e){let{onBack:t,onPick:r,showToast:i}=e,[o,a]=(0,l.useState)(null),[s,d]=(0,l.useState)(null),[p,f]=(0,l.useState)(null),[v,x]=(0,l.useTransition)();return(0,l.useEffect)(()=>{let e=!1;return tp().then(t=>{e||(t.ok?a(t.templates):d(t.error))}),()=>{e=!0}},[]),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)",marginBottom:12,fontSize:13},children:[(0,n.jsx)("button",{onClick:t,style:{background:"none",border:"none",color:"var(--text-secondary)",cursor:"pointer",fontWeight:600,padding:0,font:"inherit"},children:"Custom Reports"}),(0,n.jsx)("span",{style:{color:"var(--border-strong)"},children:"/"}),(0,n.jsx)("span",{style:{color:"var(--text-primary)",fontWeight:600},children:"Choose a starting point"})]}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-secondary)",marginBottom:16},children:"Every new report starts from a template - pick one to clone and customize, or start from a blank one."}),s&&(0,n.jsxs)("div",{style:{fontSize:12,color:"var(--error)",marginBottom:12},children:["â ",s]}),null===o&&!s&&(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-tertiary)",marginBottom:12},children:"Loading templatesâ¦"}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(240px, 1fr))",gap:"var(--space-4)"},children:[(null!=o?o:[]).map(e=>(0,n.jsxs)("div",{style:{position:"relative"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>r(e.id),style:{width:"100%",height:"100%",textAlign:"left",background:"var(--bg-elevated)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-md)",boxShadow:"var(--shadow-sm)",padding:16,display:"flex",flexDirection:"column",gap:"var(--space-2)",cursor:"pointer",fontFamily:"var(--font-sans)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,paddingRight:"org"===e.scope?28:0},children:[(0,n.jsx)(u.Z,{size:14,color:"var(--accent)"}),(0,n.jsx)("span",{style:{fontSize:14,fontWeight:600,color:"var(--text-primary)"},children:e.name})]}),e.description&&(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-secondary)"},children:e.description}),(0,n.jsx)("div",{style:{fontSize:10,fontFamily:"var(--font-mono)",color:"var(--text-tertiary)",textTransform:"uppercase"},children:"universal"===e.scope?"Universal template":"Your template"})]}),"org"===e.scope&&(0,n.jsx)("div",{style:{position:"absolute",top:10,right:10},children:(0,n.jsx)(tA,{title:'Delete template "'.concat(e.name,'"'),onClick:()=>f({id:e.id,name:e.name})})})]},e.id)),(0,n.jsxs)("button",{type:"button",onClick:()=>r(null),style:{textAlign:"left",border:"1px dashed var(--border-strong)",borderRadius:"var(--radius-md)",display:"flex",flexDirection:"column",gap:"var(--space-2)",padding:16,background:"transparent",curs
1or:"pointer",fontFamily:"var(--font-sans)",color:"var(--text-secondary)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,n.jsx)(c.Z,{size:14}),(0,n.jsx)("span",{style:{fontSize:14,fontWeight:600,color:"var(--text-primary)"},children:"Blank report"})]}),(0,n.jsx)("div",{style:{fontSize:12},children:"Start with a single empty text block and build from scratch."})]})]}),p&&(0,n.jsx)(tR,{title:"Delete template?",body:(0,n.jsxs)(n.Fragment,{children:["This permanently deletes your template ",(0,n.jsx)("strong",{children:p.name}),". Reports already created from it are not affected. This cannot be undone."]}),confirmLabel:v?"Deletingâ¦":"Delete template",busy:v,onCancel:()=>f(null),onConfirm:function(){p&&x(async()=>{let e=await tb(p.id);e.ok?(a(e=>(null!=e?e:[]).filter(e=>e.id!==p.id)),i('â Deleted template "'.concat(p.name,'"'))):i("â ".concat(e.error)),f(null)})}})]})}function tA(e){let{title:t,onClick:r}=e,[i,o]=(0,l.useState)(!1);return(0,n.jsx)("button",{type:"button",title:t,"aria-label":t,onClick:r,onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:26,height:26,padding:0,borderRadius:"var(--radius-sm)",border:"1px solid ".concat(i?"var(--error)":"var(--border-subtle)"),background:i?"color-mix(in srgb, var(--error) 8%, transparent)":"var(--bg-elevated)",color:i?"var(--error)":"var(--text-tertiary)",cursor:"pointer",transition:"color 90ms ease-out, border-color 90ms ease-out, background 90ms ease-out"},children:(0,n.jsx)(p.Z,{size:13})})}function tR(e){let{title:t,body:r,confirmLabel:i,busy:o,onConfirm:a,onCancel:s}=e;return(0,l.useEffect)(()=>{let e=e=>{"Escape"!==e.key||o||s()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[s,o]),(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{onClick:()=>{o||s()},style:{position:"fixed",inset:0,zIndex:200,background:"var(--scrim)"}}),(0,n.jsxs)("div",{role:"dialog","aria-modal":"true",style:{position:"fixed",top:"24vh",left:"50%",transform:"translateX(-50%)",zIndex:201,width:"min(420px, calc(100vw - 32px))",background:"var(--bg-elevated)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-xl)",boxShadow:"var(--shadow-xl)",padding:18},children:[(0,n.jsx)("div",{style:{fontSize:15,fontWeight:600,marginBottom:8},children:t}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-secondary)",lineHeight:1.55,marginBottom:18},children:r}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:"var(--space-2)"},children:[(0,n.jsx)(Z.Btn,{variant:"default",size:"sm",disabled:o,onClick:s,children:"Cancel"}),(0,n.jsx)(Z.Btn,{variant:"danger",size:"sm",disabled:o,onClick:a,children:i})]})]})]})}function tT(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:6;return e.length<=t?e.map(e=>e.name).join(", "):e.slice(0,t).map(e=>e.name).join(", ")+", +".concat(e.length-t," more")}function tD(e){let{source:t,onBack:s,showToast:d,onReportReady:c}=e,u=(0,o.t)(),p=(0,i.usePathname)(),h=(0,i.useSearchParams)(),[m,g]=(0,l.useState)(null),[b,y]=(0,l.useState)(!0),[j,k]=(0,l.useState)(null),[w,S]=(0,l.useState)(()=>{let e=h.get("sub");return"overview"===e||"setup"===e?e:"new"===t.kind?"setup":"overview"});function C(){if(null===G.current)return;let e=JSON.parse(G.current);M(e.name),F(e.description),O(e.blocks),Q(!1)}let[z,M]=(0,l.useState)(""),[I,F]=(0,l.useState)(""),[A,R]=(0,l.useState)("draft"),[T,O]=(0,l.useState)([]),[N,L]=(0,l.useState)({}),[W,P]=(0,l.useTransition)(),[U,H]=(0,l.useTransition)(),G=(0,l.useRef)(null),[V,Q]=(0,l.useState)(!1),[_,q]=(0,l.useState)(!1),{viewFilters:$,liveLoading:J,setViewColFilter:X,setViewRowFilter:ee,displayValuesFor:et,exportBlockValues:er}=function(e,t){let[r,n]=(0,l.useState)({}),[i,o]=(0,l.useState)({}),[a,s]=(0,l.useState)({}),d=e=>{var n,l,o,a;if("table"!==e.type||"sheet"!==e.mode||!e.sheet)return null===(n=t[e.id])||void 0===n?void 0:n.values;let s=function(e,t,r,n){if(!t||!(r&&Object.keys(r).length>0||n&&Object.keys(n).length>0))return t;let l={};
1for(let[o,a]of Object.entries(t)){var i;let t=e.cells[o],s=(0,Y.PM)(o);if(!(null==t?void 0:t.metricId)||!s){l[o]=a;continue}let d=function(e,t,r,n){var l;return null!==(l=null==r?void 0:r[e])&&void 0!==l?l:null==n?void 0:n[t]}(s.col,s.row,r,n);if(K(d)||!a.breakdown){l[o]=a;continue}let c=a.breakdown.filter(e=>d.facilityIds.includes(e.facilityId)).map(e=>e.value).filter(e=>null!=e);if(0===c.length){l[o]={...a,raw:null,display:""};continue}let u="deviation"===(null!==(i=t.metricMode)&&void 0!==i?i:"value")?c.reduce((e,t)=>e+t,0)/c.length:c.reduce((e,t)=>e+t,0);l[o]={...a,raw:u,display:function(e,t){if(null==e)return"";let r=Math.abs(e),n=r>=1e6?"".concat((e/1e6).toFixed(1),"M"):r>=1e3?"".concat((e/1e3).toFixed(1),"k"):String(Math.round(100*e)/100);return"%"===t?"".concat(e>=0?"+":"").concat(n,"%"):n}(u,a.unit)}}return l}(e.sheet,null===(l=t[e.id])||void 0===l?void 0:l.values,null===(o=r[e.id])||void 0===o?void 0:o.col,null===(a=r[e.id])||void 0===a?void 0:a.row),d=i[e.id];return d&&s?{...s,...d}:s};return{viewFilters:r,liveLoading:a,setViewColFilter:(e,t,l)=>{var i;let o={...r[e],col:{...null===(i=r[e])||void 0===i?void 0:i.col,[t]:l}};n(t=>({...t,[e]:o}))},setViewRowFilter:(e,t,l)=>{var i;let o={...r[e],row:{...null===(i=r[e])||void 0===i?void 0:i.row,[t]:l}};n(t=>({...t,[e]:o}))},displayValuesFor:d,exportBlockValues:()=>Object.fromEntries(e.map(e=>{let r=t[e.id];if(!r)return[e.id,r];let n=d(e);return[e.id,n?{...r,values:n}:r]}))}}(T,N);function en(e,t){O(r=>r.map(r=>r.id===e&&"table"===r.type?{...r,...t}:r))}(0,l.useEffect)(()=>{let e=!1;return async function(){y(!0),k(null);let r="existing"===t.kind?t.id:null;if("new"===t.kind){let n=t.cloneFromId?await tm(t.cloneFromId):await th();if(e)return;if(!n.ok){k(n.error),y(!1);return}r=n.id}let[n,l]=await Promise.all([tf(r),tv(r)]);if(e)return;if(!n.ok){k(n.error),y(!1);return}let i=n.blocks.length?n.blocks:[{id:"b1",type:"text",html:""}];g(r),M(n.report.name),F(n.report.description),R("published"===n.report.status?"published":"draft"),O(i),l.ok&&L(l.values),y(!1),G.current=JSON.stringify({name:n.report.name,description:n.report.description,blocks:i}),Q(!1),"new"===t.kind&&c(r)}(),()=>{e=!0}},[]),(0,l.useEffect)(()=>{null!==G.current&&Q(JSON.stringify({name:z,description:I,blocks:T})!==G.current)},[z,I,T]),(0,l.useEffect)(()=>{if(!V)return;let e=e=>{e.preventDefault(),e.returnValue=""};return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[V]);let el=T.some(e=>"text"===e.type?e.html.trim().length>0:"sheet"===e.mode?!!e.sheet&&Object.keys(e.sheet.cells).length>0:"freeform"===e.mode?e.rows.some(e=>e.some(e=>e.trim())):e.metricFields.length>0),ei=T.filter(e=>{var t;return"table"===e.type&&"sheet"===e.mode&&e.sheet&&Object.keys(e.sheet.cells).length>0&&!(null===(t=e.sheet.title)||void 0===t?void 0:t.trim())});return b||j?(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)",marginBottom:16,fontSize:13},children:(0,n.jsx)("button",{onClick:s,style:{background:"none",border:"none",color:"var(--text-secondary)",cursor:"pointer",fontWeight:600,padding:0,font:"inherit"},children:"Custom Reports"})}),(0,n.jsx)("div",{style:{fontSize:12,color:j?"var(--error)":"var(--text-tertiary)"},children:j?"â ".concat(j):"Loading reportâ¦"})]}):(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{position:"sticky",top:0,zIndex:10,background:"var(--bg-base)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)",marginBottom:8,fontSize:12},children:[(0,n.jsx)("button",{onClick:function(){if(V){if(!window.confirm("You have unsaved changes. Leave this report and discard them?"))return;C()}s()},style:{background:"none",border:"none",color:"var(--text-tertiary)",cursor:"pointer",fontWeight:500,padding:0,font:"inherit"},children:"Custom Reports"}),(0,n.jsx)("span",{style:{color:"var(--border-strong)",fontSize:10},children:"/"}),(0,n.jsx)("span",{style:{color:"var(--text-primary)",fontWeight:600},children:z||"New report"})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:0},children:[(0,n.jsx)("h2",{style:{fontSize:20,fontWeight:700,letterSpacing:"-0.02em",margin:0},children:z||"New report"}),(0,n.jsx)(tS,{status:A})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--border-subtle)",marginTop:12},children:[["overview","setup"].map(e=>(0,n.jsx)("button",{onClick:()=>(function(e){if(e===w)return;
1if(V){if(!window.confirm("You have unsaved changes in Setup. Switch tabs and discard them?"))return;C()}S(e);let t=new URLSearchParams(h.toString());t.set("sub",e),u.replace("".concat(p,"?").concat(t.toString()),{scroll:!1})})(e),style:{padding:"10px 16px",fontSize:13,border:"none",cursor:"pointer",fontFamily:"var(--font-sans)",textTransform:"capitalize",background:"transparent",marginBottom:-1,borderBottom:w===e?"2px solid var(--accent)":"2px solid transparent",color:w===e?"var(--accent)":"var(--text-secondary)",fontWeight:w===e?600:500},children:e},e)),(0,n.jsxs)("div",{style:{marginLeft:"auto",display:"flex",gap:"var(--space-2)",padding:"6px 0"},children:[(0,n.jsx)(Z.Btn,{variant:"default",size:"sm",disabled:W||U,icon:(0,n.jsx)(a.Z,{size:13}),onClick:function(){m&&H(async()=>{let e=await tc(m);if(!e.ok){d("â ".concat(e.error));return}let t=await tv(m);t.ok?(L(t.values),d("â Refreshed ".concat(e.refreshed," block").concat(1===e.refreshed?"":"s"))):d("â ".concat(t.error))})},children:U?"Fetching...":"Fetch latest"}),"overview"===w&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(Z.Btn,{variant:"default",size:"sm",icon:(0,n.jsx)(f.Z,{size:13}),onClick:()=>q(!0),children:"Preview"}),(0,n.jsx)(Z.Btn,{variant:"default",size:"sm",icon:(0,n.jsx)(v.Z,{size:13}),onClick:()=>(function(e,t,r,n){let l=D.utils.book_new();D.utils.book_append_sheet(l,D.utils.aoa_to_sheet([["Report",e||"(untitled)"],["Description",t||""],["Generated",new Date().toLocaleString()]]),"Report Info");let i=0,o=new Set;for(let e of r){var a,s,d,c;let t,r;if("table"!==e.type)continue;if(i++,"sheet"===e.mode){let l=e.sheet;if(!l)continue;let i=null===(d=n[e.id])||void 0===d?void 0:d.values,o={};for(let[e,t]of Object.entries(l.cells))if(t.metricId){let t=null==i?void 0:null===(c=i[e])||void 0===c?void 0:c.raw;o[e]={value:null==t?"":String(t)}}else o[e]={value:t.value,formula:t.formula};let a=e=>{var t,r;let n=l.cells[e];if(!n)return"";if(n.metricId){let t=null==i?void 0:i[e];return t?null==t.raw?"":t.raw:"(not refreshed)"}if(n.formula){let r=(0,B.Bj)(e,o);return r.error?r.error:null!==(t=r.value)&&void 0!==t?t:""}return null!==(r=n.value)&&void 0!==r?r:""},s=Array.from({length:l.rows},(e,t)=>Array.from({length:l.cols},(e,r)=>a((0,B.Qk)({col:r,row:t}))));t=[l.headers.slice(0,l.cols),...s],r=1}else if("freeform"===e.mode)t=[e.columns.map(e=>e.label),...e.rows],r=1;else{let n=(0,E._Z)(e),l=n.groupHeader?[["",...n.groupHeader.flatMap(e=>Array(e.span).fill(e.label))],...n.headerRows]:n.headerRows;t=[...l,...n.bodyRows],r=l.length}let u=D.utils.aoa_to_sheet(t),p=Array.from({length:r},(e,t)=>t).flatMap(e=>(function(e,t){let r=[],n=1;for(let l=2;l<=t.length;l++)(l===t.length||t[l]!==t[n])&&(l-n>1&&""!==t[n]&&r.push({s:{r:e,c:n},e:{r:e,c:l-1}}),n=l);return r})(e,t[e]));p.length&&(u["!merges"]=p);let f=((null===(a="sheet"===e.mode?null===(s=e.sheet)||void 0===s?void 0:s.title:void 0)||void 0===a?void 0:a.trim())||"Table ".concat(i)).replace(/[\\/?*[\]:]/g," ").trim().slice(0,31)||"Table ".concat(i),v=f,x=2;for(;o.has(v);)v="".concat(f.slice(0,28)," ").concat(x),x++;o.add(v),D.utils.book_append_sheet(l,u,v)}let u=(e||"report").trim().replace(/[^a-z0-9]+/gi,"-").toLowerCase()||"report";D.writeFile(l,"".concat(u,".xlsx"))})(z,I,T,er()),children:"Excel"}),(0,n.jsx)(Z.Btn,{variant:"default",size:"sm",icon:(0,n.jsx)(x.Z,{size:13}),onClick:async()=>{try{let{downloadReportPdf:e}=await Promise.all([r.e(7448),r.e(7282),r.e(249),r.e(292),r.e(2811)]).then(r.bind(r,13279));await e(z,I,T,er(),new Date().toLocaleDateString())}catch(e){console.error("PDF export failed",e)}},children:"PDF"})]}),"setup"===w&&(0,n.jsx)(Z.Btn,{variant:"primary",size:"sm",disabled:W||U||!V,onClick:function(){if(m){if(!z||!el){d("â Add a name and some content before saving");return}if(ei.length){d("â Add a table name before saving - ".concat(ei.length," table").concat(1===ei.length?"":"s"," missing one"));return}P(async()=>{let e=await tg(m,{name:z,description:I,blocks:T,status:"published"});if(!e.ok){d("â ".concat(e.error));return}let t=function(e,t){let r=new Map;return(e.forEach((e,n)=>{let l=t[n];l&&l.id!==e.id&&r.set(e.id,l.id)}),0===r.size)?e:e.map(e=>{let t=r.get(e.id);return t?{...e,id:t}:e})}(T,e.blocks);t!==T&&O(t),R("published"),G.current=JSON.stringify({name:z,description:I,blocks:t}),Q(!1);let r=await tc(m);if(!r.ok){d("â Saved, but refresh failed: ".concat(r.error));return}let n=await tv(m);n.ok?(L(n.values),d('â Saved "'.concat(z,'" \xb7 refreshed ').concat(r.refreshed," block").concat(1===r.refreshed?"":"s"))):d("â Saved, but reloading values failed: ".concat(n.error))})}},children:W?"Saving...":"Save report"})]})]})]}),(0,n.jsx)("div",{style:{paddingTop:16},children:"overview"===w?(0,n.jsx)(tE,{blocks:T,blockValues:N,updateTableBlock:en,viewFilters:$,liveLoading:J,setViewColFilter:X,setViewRowFilter:ee,displayValuesFor:et}):(0,n.jsx)(tB,{name:z,description:I,setName:M,setDescription:F,blocks:T,blockValues:N,addBlock:function(e,t){let r="b".concat(Date.now()),n="heading"===e?{id:r,type:"text",html:"<h2></h2>"}:"text"===e?{id:r,type:"text",html:""}:(0,E.sv)(r);O(e=>null!=t?[...e.slice(0,t),n,...e.slice(t)]:[...e,n])},updateTextBlock:function(e,t){O(r=>r.map(r=>r.id===e&&"text"===r.type?{...r,html:t}:r))},updateTableBlock:en,deleteBlock:function(e){O(t=>t.filter(t=>t.id!==e))},duplicateBlock:function(e){O(t=>{var r;let n=t.findIndex(t=>t.id===e);if(-1===n)return t;let l={...structuredClone(t[n]),id:"b".concat(Date.now())};return"table"===l.type&&(null===(r=l.sheet)||void 0===r?void 0:r.title)&&(l.sheet={...l.sheet,title:"".concat(l.sheet.title," (copy)")}),[...t.slice(0,n+1),l,...t.slice(n+1)]})},reorderBlocks:function(e,t){O(r=>{let n=r.findIndex(t=>t.id===e),l=r.findIndex(e=>e.id===t);if(-1===n||-1===l||n===l)return r;let i=[...r],[o]=i.splice(n,1);return i.splice(l,0,o),i})}})}),_&&(0,n.jsx)(tZ,{name:z,description:I,blocks:T,blockValues:er(),onClose:()=>q(!1)})]})}function tZ(e){let{name:t,description:i,blocks:o,blockValues:a,onClose:s}=e,[d,c]=(0,l.useState)({});return(0,l.useEffect)(()=>{let e=!1;return Promise.all([r.e(7448),r.e(7282),r.e(249),r.e(292),r.e(2811)]).then(r.bind(r,13279)).then(t=>{let{sheetDisplay:r}=t;if(e)return;let n={};for(let e of o)if("table"===e.type&&"sheet"===e.mode&&e.sheet){var l;n[e.id]=r(e.sheet,null===(l=a[e.id])||void 0===l?void 0:l.values)}c(n)}),()=>{e=!0}},[o,a]),(0,n.jsx)("div",{onClick:s,style:{position:"fixed",inset:0,zIndex:1e3,background:"var(--scrim)",display:"flex",alignItems:"flex-start",justifyContent:"center",padding:"40px 20px",overflowY:"auto"},children:(0,n.jsxs)("div",{onClick:e=>e.stopPropagation(),style:{width:"100%",maxWidth:800,background:"#fff",borderRadius:8,boxShadow:"0 8px 32px rgba(0,0,0,.18)",position:"relative",color:"#1f2430"},children:[(0,n.jsx)("div",{style:{position:"sticky",top:0,zIndex:1,display:"flex",justifyContent:"flex-end",padding:"12px 16px 0"},children:(0,n.jsx)("button",{type:"button",onClick:s,style:{background:"none",border:"none",cursor:"pointer",color:"#5b6170",padding:4},children:(0,n.jsx)(h.Z,{size:18})})}),(0,n.jsxs)("div",{style:{padding:"0 48px 48px",fontFamily:"Helvetica, Arial, sans-serif",fontSize:10},children:[(0,n.jsx)("style",{children:tW}),(0,n.jsxs)("div",{style:{marginBottom:18,paddingBottom:12,borderBottom:"2px s
1olid #0D08DD"},children:[(0,n.jsx)("div",{style:{fontSize:20,fontWeight:700,color:"#11162a"},children:t||"Untitled report"}),i&&(0,n.jsx)("div",{style:{fontSize:10.5,color:"#5b6170",marginTop:4},children:i}),(0,n.jsxs)("div",{style:{fontSize:8.5,color:"#9aa0ad",marginTop:6},children:["Generated ",new Date().toLocaleDateString()]})]}),o.map(e=>{var t;return(0,n.jsx)("div",{style:{marginBottom:16},children:"text"===e.type?(0,n.jsx)("div",{className:"cr-richtext",style:{fontSize:13,lineHeight:1.6},dangerouslySetInnerHTML:{__html:e.html||""}}):"sheet"===e.mode&&e.sheet&&d[e.id]?(0,n.jsxs)(n.Fragment,{children:[(null===(t=e.sheet.title)||void 0===t?void 0:t.trim())&&(0,n.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"#1f2430",marginBottom:3},children:e.sheet.title}),(0,n.jsx)("div",{style:{overflowX:"auto"},children:(0,n.jsxs)("table",{style:{borderCollapse:"collapse",border:"1px solid #e3e6ed",borderRadius:3,fontSize:9.5,minWidth:"100%"},children:[(0,n.jsx)("thead",{children:(0,n.jsx)("tr",{style:{background:"#eef1fb"},children:d[e.id].headers.map((t,r)=>(0,n.jsx)("th",{style:{padding:"6px 8px",fontSize:9,fontWeight:700,color:"#2b3350",borderBottom:"1px solid #e3e6ed",borderRight:r<d[e.id].headers.length-1?"1px solid #e3e6ed":"none",textAlign:"left",whiteSpace:"nowrap"},children:t},r))})}),(0,n.jsx)("tbody",{children:d[e.id].rows.map((e,t)=>(0,n.jsx)("tr",{style:{background:t%2==1?"#fafbfe":"#fff"},children:e.map((t,r)=>(0,n.jsx)("td",{style:{padding:"5px 8px",color:"#1f2430",borderBottom:"1px solid #e3e6ed",borderRight:r<e.length-1?"1px solid #e3e6ed":"none",textAlign:t.numeric?"right":"left",whiteSpace:"nowrap"},children:t.text},r))},t))})]})})]}):null},e.id)})]})]})})}function tE(e){let{blocks:t,blockValues:r,updateTableBlock:i,viewFilters:o,liveLoading:s,setViewColFilter:d,setViewRowFilter:c,displayValuesFor:u}=e,{metrics:p,facilities:f,fyLabels:v}=(0,l.useContext)(ty);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-4)"},children:[(0,n.jsx)("style",{children:"\n @media print {\n @page { margin: 12mm; }\n body * { visibility: hidden; }\n .custom-report-print-root, .custom-report-print-root * { visibility: visible; }\n .custom-report-print-root { position: absolute; left: 0; top: 0; width: 100%; }\n .print-hide { display: none !important; }\n /* Plan \xa718.10 - the spreadsheet renders in a 520px scroll box on screen; for PDF it must\n expand fully (no clip, no inner scroll) and shed its spreadsheet chrome so it prints as a\n clean report table, not a cropped grid. */\n .cr-sheet-scroll { max-height: none !important; overflow: visible !important; border: none !important; border-radius: 0 !important; }\n .cr-sheet-colletters { display: none !important; }\n .cr-sheet-rowhead { display: none !important; }\n .custom-report-print-root table { width: 100% !important; }\n .custom-report-print-root tr { break-inside: avoid; }\n .custom-report-print-root thead { display: table-header-group; }\n }\n "}),(0,n.jsx)("div",{className:"custom-report-print-root",style:{display:"flex",flexDirection:"column",gap:14},children:t.map(e=>{var t,l,x,h;let g=o[e.id],b=u(e);return(0,n.jsxs)("div",{style:{background:"var(--bg-elevated)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-lg)",overflow:"hidden"},children:[(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"10px 16px",borderBottom:"1px solid var(--bg-sunken)",background:"color-mix(in srgb, var(--bg-base) 60%, var(--bg-elevated))",fontSize:12,fontWeight:600,color:"var(--text-secondary)"},children:"text"===e.type?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{style:{width:20,height:20,borderRadius:"var(--radius-sm)",display:"flex",alignItems:"center",justifyContent:"center",fontSize:11,background:"var(--bg-sunken)",color:"var(--text-secondary)"},children:"T"}),"Text block"]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{style:{width:20,height:20,borderRadius:"var(--radius-sm)",display:"flex",alignItems:"center",justifyContent:"center",fontSize:11,background:"var(--accent-subtle)",color:"var(--accent)"},children:(0,n.jsx)(m.Z,{size:12})}),(null===(l=e.sheet)||void 0===l?void 0:null===(t=l.title)||void 0===t?void 0:t.trim())||"Sheet block",(null===(x=r[e.id])||void 0===x?void 0:x.fetchedAt)&&(0,n.jsxs)("span",{style:{marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:4,fontSize:10,fontWeight:500,padding:"2px 8px",borderRadius:"var(--radius-pill)",background:"var(--success-bg)",color:"var(--success)"},children:[(0,n.jsx)(a.Z,{size:10})," ",tw(r[e.id].fetchedAt)]})]})}),(0,n.jsx)("div",{style:{padding:"text"===e.type?16:0},children:"text"===e.type?(0,n.jsx)(tP,{html:e.html}
1):"sheet"===e.mode?e.sheet?(0,n.jsx)(ec,{sheet:e.sheet,onChange:()=>{},readOnly:!0,metricOptions:p,facilityOptions:f,fyLabels:v,resolvedValues:b,valuesFetchedAt:null===(h=r[e.id])||void 0===h?void 0:h.fetchedAt,viewFilterable:!0,viewColFilters:null==g?void 0:g.col,viewRowFilters:null==g?void 0:g.row,onViewColFilterChange:(t,r)=>d(e.id,t,r),onViewRowFilterChange:(t,r)=>c(e.id,t,r),viewFilterPeriodEnabled:!1,viewFilterLoading:!!s[e.id]}):null:"freeform"===e.mode?(0,n.jsx)(t_,{block:e,onChange:()=>{},onDelete:()=>{},showDelete:!1,readOnly:!0}):(0,n.jsx)(t1,{block:e,onChange:i,onDelete:()=>{},showDelete:!1,readOnly:!0})})]},e.id)})})]})}function tB(e){let{name:t,description:r,setName:i,setDescription:o,blocks:a,blockValues:s,addBlock:d,updateTextBlock:c,updateTableBlock:u,deleteBlock:f,duplicateBlock:v,reorderBlocks:x}=e,[h,y]=(0,l.useState)(null),[j,k]=(0,l.useState)(null);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-5)"},children:[(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-2)"},children:[(0,n.jsx)("input",{type:"text",value:t,onChange:e=>i(e.target.value),placeholder:"Untitled report",style:{...tO,fontSize:16,fontWeight:600}}),(0,n.jsx)("textarea",{value:r,onChange:e=>o(e.target.value),placeholder:"What is this report for? (optional)",style:{...tO,fontSize:12,color:"var(--text-secondary)",minHeight:32,resize:"vertical"}})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[a.map((e,t)=>(0,n.jsxs)(l.Fragment,{children:[t>0&&(0,n.jsx)(tH,{onSelectBlock:e=>d(e,t)}),(0,n.jsxs)("div",{onDragOver:t=>{h&&h!==e.id&&(t.preventDefault(),k(e.id))},onDragLeave:()=>k(t=>t===e.id?null:t),onDrop:t=>{t.preventDefault(),h&&h!==e.id&&x(h,e.id),y(null),k(null)},style:{opacity:h===e.id?.4:1,borderTop:j===e.id?"2px solid var(--accent)":"2px solid transparent",paddingTop:j===e.id?6:0,transition:"opacity .1s, padding-top .1s",background:"var(--bg-elevated)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-lg)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 12px",borderBottom:"1px solid var(--bg-sunken)",background:"color-mix(in srgb, var(--bg-base) 60%, var(--bg-elevated))",fontSize:12,fontWeight:600,color:"var(--text-secondary)"},children:[(0,n.jsx)("span",{draggable:!0,onDragStart:t=>{y(e.id),t.dataTransfer.effectAllowed="move"},onDragEnd:()=>{y(null),k(null)},title:"Drag to reorder",style:{cursor:"grab",color:"var(--text-tertiary)",flexShrink:0,touchAction:"none",display:"flex"},children:(0,n.jsx)(g.Z,{size:14})}),"text"===e.type?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{style:{width:20,height:20,borderRadius:"var(--radius-sm)",display:"flex",alignItems:"center",justifyContent:"center",fontSize:11,background:"var(--bg-sunken)",color:"var(--text-secondary)"},children:"T"}),"Text block"]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{style:{width:20,height:20,borderRadius:"var(--radius-sm)",display:"flex",alignItems:"center",justifyContent:"center",fontSize:11,background:"var(--accent-subtle)",color:"var(--accent)"},children:(0,n.jsx)(m.Z,{size:12})}),"Sheet block"]}),(0,n.jsxs)("span",{style:{marginLeft:"auto",display:"flex",alignItems:"center",gap:4},children:[(0,n.jsx)(Z.Btn,{variant:"ghost",size:"sm",icon:(0,n.jsx)(b.Z,{size:12}),onClick:()=>v(e.id)}),(0,n.jsx)(Z.Btn,{variant:"ghost",size:"sm",icon:(0,n.jsx)(p.Z,{size:12}),onClick:()=>f(e.id),style:{color:"var(--error)"}})]})]}),(0,n.jsx)("div",{style:{minWidth:0},children:"text"===e.type?(0,n.jsx)(tU,{block:e,onChange:c,onDelete:f,showDelete:!1}):(0,n.jsx)(tG,{block:e,blockValues:s[e.id],onChange:u,onDelete:f,showDelete:!1,onDuplicate:v})})]})]},e.id)),(0,n.jsx)(tH,{onSelectBlock:e=>d(e)})]})]})}let tO={fontFamily:"var(--font-sans)",fontSize:13,padding:"10px 12px",background:"var(--bg-sunken)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-md)",color:"var(--text-primary)",width:"100%"};function tN(e){let{onClick:t}=e;return(0,n.jsx)("button",{type:"button",onClick:t,title:"Remove block",style:{position:"absolute",top:-8,right:-8,width:22,height:22,borderRadius:"50%",background:"var(--bg-elevated)",border:"1px solid var(--border-subtle)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-tertiary)",zIndex:1},children:(0,n.jsx)(h.Z,{size:11})})}function tL(e){let{onClick:t}=e;return(0,n.jsx)("button",{type:"button",onClick:t,title:"Duplicate table",style:{position:"absolute",top:-8,right:18,width:22,height:22,borderRadius:"50%",background:"var(--bg-elevated)",border:"1px solid var(--border-subtle)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-tertiary)",zIndex:1},children:(0,n.jsx)(b.Z,{size:11})})}let tW='\n.cr-richtext h1 { font-size: 22px; font-weight: 700; margin: 10px 0 4px; line-height: 1.25; }\n.cr-richtext h2 { font-size: 18px; font-weight: 600; margin: 8px 0 4px; line-height: 1.3; }\n.cr-richtext h3 { font-size: 15px; font-weight: 600; margin: 6px 0 3px; line-height: 1.35; }\n.cr-richtext h4 { font-size: 13px; font-weight: 600; margin: 6px 0 3px; line-height: 1.35; }\n.cr-richtext p { margin: 4px 0; }\n.cr-richtext ul, .cr-richtext ol { margin: 4px 0; padding-left: 22px; }\n.cr-richtext a { color: var(--accent); text-decoration: underline; }\n.cr-richtext blockquote { border-left: 3px solid var(--border-strong); margin: 6px 0; padding: 2px 0 2px 12px; color: var(--text-secondary); font-style: italic; }\n.cr-richtext code { font-family: var(--font-mono); font-size: 0.9em; background: var(--bg-sunken); padding: 1px 4px; border-radius: 4px; }\n.cr-richtext pre { background: var(--bg-sunken); border: 1px solid var(--border-subtle); border-radius: 6px; padding: 8px 10px; margin: 6px 0; overflow-x: auto; }\n.cr-richtext pre code { background: none; padding: 0; }\n.cr-richtext hr { border: none; border-top: 1px solid var(--border-subtle); margin: 10px 0; }\n.cr-richtext mark { background: #fde68a; border-radius: 2px; padding: 0 1px; }\n.cr-richtext ul[data-type="taskList"] { list-style: none; padding-left: 4px; }\n.cr-richtext ul[data-type="taskList"] li { display: flex; align-items: flex-start; gap: 6px; }\n.cr-richtext ul[data-type="taskList"] li > label { margin-top: 2px; }\n.cr-richtext:focus { outline: none; }\n.cr-richtext p.is-editor-empty:first-child::before { content: attr(data-placeholder); color: var(--text-tertiary); float: left; height: 0; pointer-events: none; }\n';function tP(e){let{html:t}=e;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("style",{children:tW}),(0,n.jsx)("div",{className:"cr-richtext",style:{fontSize:13,lineHeight:1.6,color:"var(--text-primary)"},dangerouslySetInnerHTML:{__html:t||'<p style="color:var(--text-tertiary)">(empty)</p>'}})]})}function tU(e){let{block:t,onChange:r,onDelete:l,showDelete:i}=e;return(0,n.jsxs)("div",{style:{position:"relative",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-md)",background:"var(--bg-elevated)",padding:12},children:[(0,n.jsx)("style",{children:tW}),i&&(0,n.jsx)(tN,{onClick:()=>l(t.id)}),(0,n.jsx)(tn,{html:t.html,onChange:e=>r(t.id,e)})]})}function tH(e){let{onSelectBlock:t}=e,[r,i]=(0,l.useState)(!1),o=(0,l.useRef)(null);(0,l.useEffect)(()=>
1{if(r)return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e);function e(e){o.current&&!o.current.contains(e.target)&&i(!1)}},[r]);let a=e=>{t(e),i(!1)},s=(e,t,r)=>(0,n.jsxs)("button",{type:"button",onClick:()=>a(e),style:{display:"flex",alignItems:"center",gap:8,padding:"8px 12px",background:"transparent",border:"none",cursor:"pointer",color:"var(--text-secondary)",fontFamily:"var(--font-sans)",fontSize:12,width:"100%",borderRadius:"var(--radius-sm)"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-sunken)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[(0,n.jsx)(t,{size:14}),r]});return(0,n.jsxs)("div",{ref:o,style:{display:"flex",justifyContent:"center",position:"relative"},children:[(0,n.jsx)("button",{type:"button",onClick:()=>i(e=>!e),style:{width:28,height:28,borderRadius:"50%",border:"1px dashed var(--border-strong)",background:r?"var(--bg-sunken)":"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-tertiary)",transition:"background .15s, color .15s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-sunken)",e.currentTarget.style.color="var(--text-secondary)"},onMouseLeave:e=>{r||(e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-tertiary)")},title:"Add block",children:(0,n.jsx)(c.Z,{size:14})}),r&&(0,n.jsxs)("div",{style:{position:"absolute",top:34,zIndex:20,background:"var(--bg-elevated)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-md)",boxShadow:"0 4px 12px rgba(0,0,0,.1)",padding:4,minWidth:160},children:[s("heading",y.Z,"Add heading"),s("text",j.Z,"Add text"),s("sheet",m.Z,"Add table")]})]})}function tG(e){let{block:t,blockValues:r,onChange:l,onDelete:i,showDelete:o,onDuplicate:a}=e;return"sheet"===t.mode?(0,n.jsx)(tQ,{block:t,blockValues:r,onChange:l,onDelete:i,showDelete:o,onDuplicate:a}):"freeform"===t.mode?(0,n.jsx)(t_,{block:t,onChange:l,onDelete:i,showDelete:o}):(0,n.jsx)(t1,{block:t,onChange:l,onDelete:i,showDelete:o})}function tV(e){var t,r,n,l;let i={};for(let[n,l]of Object.entries(e.cells))l.metricId&&(i[n]={metricId:l.metricId,metricMode:null!==(t=l.metricMode)&&void 0!==t?t:"value",filter:null!==(r=l.filter)&&void 0!==r?r:null});return JSON.stringify({bindings:i,colFilters:null!==(n=e.colFilters)&&void 0!==n?n:{},rowFilters:null!==(l=e.rowFilters)&&void 0!==l?l:{}})}function tQ(e){var t,r,i;let{block:o,blockValues:a,onChange:s,onDelete:d,showDelete:c,onDuplicate:u}=e,p=null!==(r=o.sheet)&&void 0!==r?r:(0,E.sv)(o.id).sheet,{metrics:f,facilities:v,fyLabels:x}=(0,l.useContext)(ty),h=(0,l.useRef)(null),m=(0,l.useRef)(void 0),g=null==a?void 0:a.bindingHash;g&&g!==m.current&&(m.current=g,h.current=tV(p)),a||(h.current=null,m.current=void 0);let b=(0,l.useMemo)(()=>tV(p),[p]),y=null!==h.current&&b!==h.current,j=y?void 0:null==a?void 0:a.values,k=y?void 0:null==a?void 0:a.fetchedAt;return(0,n.jsxs)("div",{style:{position:"relative",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-md)",padding:12,background:"var(--bg-base)"},children:[c&&(0,n.jsx)(tN,{onClick:()=>d(o.id)}),u&&(0,n.jsx)(tL,{onClick:()=>u(o.id)}),(0,n.jsx)("input",{type:"text",value:null!==(i=p.title)&&void 0!==i?i:"",onChange:e=>s(o.id,{sheet:{...p,title:e.target.value}}),placeholder:"Table name (required for export)",style:{...tO,fontSize:13,fontWeight:600,marginBottom:10,borderColor:(null===(t=p.title)||void 0===t?void 0:t.trim())?"var(--border-subtle)":"var(--warning)"}}),(0,n.jsx)(ec,{sheet:p,onChange:e=>s(o.id,{sheet:e}),metricOptions:f,facilityOptions:v,fyLabels:x,resolvedValues:j,valuesFetchedAt:k})]})}function t_(e){var t,r;let{block:i,onChange:o,onDelete:a,showDelete:s,readOnly:d}=e,[u,p]=(0,l.useState)(!1),[f,v]=(0,l.useState)(null!==(r=null===(t=i.columns[0])||void 0===t?void 0:t.id)&&void 0!==r?r:""),[x,m]=(0,l.useState)("contains"),[g,b]=(0,l.useState)(""),[y,j]=(0,l.useState)(null),w=(0,l.useRef)(!1);(0,l.useEffect)(()=>{function e(){w.current=!1}return window.addEventListener("mouseup",e),()=>window.removeEventListener("mouseup",e)},[]);let S=(0,l.useMemo)(()=>i.rows.map((e,t)=>t).filter(e=>{let t=i.rows[e];return i.filters.every(e=>{var r;let n=i.columns.findIndex(t=>t.id===e.columnId);if(-1===n)return!0;let l=(null!==(r=t[n])&&void 0!==r?r:"").trim().toLowerCase();return"is_empty"===e.op?""===l:"equals"===e.op?l===e.value.trim().toLowerCase():l.includes(e.value.trim().toLowerCase())})}),[i.rows,i.columns,i.filters]),C={border:"1px solid var(--border-subtle)",padding:"6px 10px",background:"var(--bg-sunken)",fontSize:11,fontWeight:600,textAlign:"left",whiteSpace:"nowrap",position:"sticky",top:0,zIndex:1};return(0,n.jsxs)("div",{style:{position:"relative",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-md)",background:"var(--bg-elevated)",padding:12},children:[s&&(0,n.jsx)(tN,{onClick:()=>a(i.id)}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:10,flexWrap:"wrap",gap:"var(--space-2)"},children:[(0,n.jsx)("span",{style:{fontSize:11,textTransform:"uppercase",letterSpacing:"0.05em",color:"var(--text-tertiary)"},children:"Table"}),!d&&(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsxs)(Z.Btn,{variant:"ghost",size:"sm",icon:(0,n.jsx)(k.Z,{size:11}),onClick:()=>p(e=>!e),children:["Filter",i.filters.length?" (".concat(i.filters.length,")"):""]}),(0,n.jsx)(Z.Btn,{variant:"ghost",size:"sm",icon:(0,n.jsx)(c.Z,{size:11}),onClick:function(){o(i.id,{rows:[...i.rows,Array(i.columns.length).fill("")]})},children:"Row"}),(0,n.jsx)(Z.Btn,{variant:"ghost",size:"sm",icon:(0,n.jsx)(c.Z,{size:11}
1),onClick:function(){let e={id:"c".concat(Date.now()),label:"Column ".concat(i.columns.length+1)};o(i.id,{columns:[...i.columns,e],rows:i.rows.map(e=>[...e,""])})},children:"Column"})]})]}),!d&&(i.filters.length>0||u)&&(0,n.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",gap:6,alignItems:"center",marginBottom:10,padding:"8px 10px",background:"var(--bg-sunken)",borderRadius:"var(--radius-sm)"},children:[i.filters.map(e=>{var t;let r=i.columns.find(t=>t.id===e.columnId);return(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:"var(--space-1)",fontSize:11,padding:"var(--space-1) var(--space-2)",borderRadius:"var(--radius-pill)",background:"var(--accent-subtle)",color:"var(--accent)",border:"1px solid var(--accent)"},children:[null!==(t=null==r?void 0:r.label)&&void 0!==t?t:"?"," ","is_empty"===e.op?"is empty":"equals"===e.op?"=":"contains"," ","is_empty"!==e.op&&(0,n.jsx)("strong",{children:e.value}),(0,n.jsx)("button",{type:"button",onClick:()=>{var t;return t=e.id,void o(i.id,{filters:i.filters.filter(e=>e.id!==t)})},style:{background:"none",border:"none",cursor:"pointer",color:"inherit",display:"inline-flex",padding:0},children:(0,n.jsx)(h.Z,{size:10})})]},e.id)}),u&&(0,n.jsxs)("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[(0,n.jsx)(eM.D,{value:f,onChange:v,options:i.columns.map(e=>({value:e.id,label:e.label})),size:"sm",style:{minWidth:90,height:26}}),(0,n.jsx)(eM.D,{value:x,onChange:e=>m(e),options:[{value:"contains",label:"contains"},{value:"equals",label:"equals"},{value:"is_empty",label:"is empty"}],size:"sm",style:{minWidth:80,height:26}}),"is_empty"!==x&&(0,n.jsx)("input",{value:g,onChange:e=>b(e.target.value),placeholder:"value",style:{...tO,width:90,padding:"var(--space-1) var(--space-2)",fontSize:11}}),(0,n.jsx)(Z.Btn,{variant:"primary",size:"sm",onClick:function(){f&&(o(i.id,{filters:[...i.filters,{id:"f".concat(Date.now()),columnId:f,op:x,value:g}]}),p(!1),b(""))},children:"Add"})]})]}),(0,n.jsx)("div",{style:{overflow:"auto",maxHeight:340},onKeyDown:function(e){var t,r,n,l;if(!y)return;let a=e.metaKey||e.ctrlKey,s=Math.min(y.r1,y.r2),c=Math.max(y.r1,y.r2),u=Math.min(y.f1,y.f2),p=Math.max(y.f1,y.f2);if(a&&"c"===e.key.toLowerCase()){e.preventDefault();let l=[];for(let e=s;e<=c;e++){let t=S[e],o=[];for(let e=u;e<=p;e++)o.push(null!==(n=null===(r=i.rows[t])||void 0===r?void 0:r[e])&&void 0!==n?n:"");l.push(o.join(" "))}null===(t=navigator.clipboard)||void 0===t||t.writeText(l.join("\n")).catch(()=>{})}!d&&a&&"v"===e.key.toLowerCase()&&(e.preventDefault(),null===(l=navigator.clipboard)||void 0===l||l.readText().then(e=>{if(!e)return;let t=e.replace(/\r/g,"").split("\n").map(e=>e.split(" ")),r=i.rows.map(e=>[...e]);t.forEach((e,t)=>{let n=S[s+t];void 0!==n&&e.forEach((e,t)=>{let l=u+t;if(!(l>=i.columns.length)){for(;r[n].length<=l;)r[n].push("");r[n][l]=e}})}),o(i.id,{rows:r})}).catch(()=>{}))},tabIndex:0,children:(0,n.jsxs)("table",{style:{width:"100%",borderCollapse:"collapse"},children:[(0,n.jsx)("thead",{children:(0,n.jsx)("tr",{children:i.columns.map(e=>(0,n.jsx)("th",{style:C,children:(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-1)"},children:[(0,n.jsx)("span",{style:{flex:1},children:e.label}),!d&&(0,n.jsx)("button",{type:"button",onClick:()=>(function(e){let t=i.columns.findIndex(t=>t.id===e);-1!==t&&o(i.id,{columns:i.columns.filter(t=>t.id!==e),rows:i.rows.map(e=>e.filter((e,r)=>r!==t)),filters:i.filters.filter(t=>t.columnId!==e)})})(e.id),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-tertiary)",display:"inline-flex",padding:0},children:(0,n.jsx)(h.Z,{size:10})})]})},e.id))})}),(0,n.jsx)("tbody",{children:0===S.length?(0,n.jsx)("tr",{children:(0,n.jsx)("td",{colSpan:i.columns.length||1,style:{padding:16,textAlign:"center",color:"var(--text-tertiary)",fontSize:12},children:"No rows match the active filter."})}):S.map((e,t)=>(0,n.jsx)("tr",{style:{background:t%2?"var(--bg-sunken)":"transparent"},children:i.columns.map((r,l)=>{var a,s;let c=!!y&&t>=Math.min(y.r1,y.r2)&&t<=Math.max(y.r1,y.r2)&&l>=Math.min(y.f1,y.f2)&&l<=Math.max(y.f1,y.f2),u=null!==(s=null===(a=i.rows[e])||void 0===a?void 0:a[l])&&void 0!==s?s:"";return(0,n.jsx)("td",{onMouseDown:e=>{var r;return r=e.shiftKey,void(j(e=>r&&e?{...e,r2:t,f2:l}:{r1:t,f1:l,r2:t,f2:l}),w.current=!0)},onMouseEnter:()=>{w.current&&j(e=>e?{...e,r2:t,f2:l}:e)},style:{border:"1px solid var(--border-subtle)",padding:0,minWidth:90,background:c?"var(--accent-subtle)":void 0,outline:c?"2px solid var(--accent)":"none",outlineOffset:-2},children:d?(0,n.jsx)("div",{style:{padding:"8px 10px",fontSize:12,color:"var(--text-primary)"},children:u||"-"}):(0,n.jsx)("input",{value:u,onChange:t=>(function(e,t,r){let n=i.rows.map(e=>[...e]);for(;n[e].length<=t;)n[e].push("");n[e][t]=r,o(i.id,{rows:n})})(e,l,t.target.value),placeholder:"Enter dataâ¦",style:{width:"100%",border:"none",background:"transparent",outline:"none",padding:"8px 10px",fontSize:12,color:"var(--text-primary)",fontFamily:"var(--font-sans)"}})},r.id)})},e))})]})}
1),!d&&(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-tertiary)",marginTop:6},children:"Click a cell, or click-drag / Shift-click for a range, then Cmd/Ctrl+C / Cmd/Ctrl+V to copy or paste."})]})}function tY(e){let{title:t,summary:r,isOpen:l,onToggle:i,children:o}=e;return(0,n.jsxs)("div",{style:{border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",overflow:"hidden"},children:[(0,n.jsxs)("button",{type:"button",onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",gap:"var(--space-2)",padding:"var(--space-2) var(--space-3)",background:l?"var(--bg-sunken)":"transparent",border:"none",cursor:"pointer",textAlign:"left",fontFamily:"var(--font-sans)"},children:[(0,n.jsxs)("span",{style:{display:"flex",alignItems:"baseline",gap:"var(--space-2)",minWidth:0},children:[(0,n.jsx)("span",{style:{fontSize:11,fontWeight:600,color:"var(--text-primary)",whiteSpace:"nowrap"},children:t}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-tertiary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r})]}),l?(0,n.jsx)(w.Z,{size:13,color:"var(--text-tertiary)"}):(0,n.jsx)(S.Z,{size:13,color:"var(--text-tertiary)"})]}),l&&(0,n.jsx)("div",{style:{padding:12,borderTop:"1px solid var(--border-subtle)"},children:o})]})}function tq(e){let{columns:t,onToggle:r,bordered:l=!0}=e;return(0,n.jsx)("div",{style:{display:"flex",gap:"var(--space-1)",paddingLeft:l?8:0,borderLeft:l?"1px solid var(--border-subtle)":"none"},children:[{key:"value",label:"V",title:"Value"},{key:"comparison",label:"C",title:"Comparison"},{key:"deviation",label:"D",title:"Deviation"}].map(e=>{let{key:l,label:i,title:o}=e,a=t[l];return(0,n.jsx)("button",{type:"button",title:o,onClick:()=>r(l),style:{width:20,height:20,fontSize:10,fontWeight:700,borderRadius:"var(--radius-sm)",cursor:"pointer",fontFamily:"var(--font-mono)",border:"1px solid ".concat(a?"var(--accent)":"var(--border-subtle)"),background:a?"var(--accent-subtle)":"transparent",color:a?"var(--accent)":"var(--text-tertiary)"},children:i},l)})})}let tK={background:"none",border:"none",cursor:"pointer",padding:3,color:"var(--text-tertiary)",display:"flex"};function t$(e){let{icon:t,label:r,onClick:l,disabled:i,danger:o}=e;return(0,n.jsxs)("button",{type:"button",disabled:i,onClick:e=>{e.stopPropagation(),l()},style:{display:"flex",alignItems:"center",gap:"var(--space-2)",width:"100%",padding:"7px 10px",fontSize:12,fontFamily:"var(--font-sans)",background:"none",border:"none",borderRadius:"var(--radius-sm)",textAlign:"left",cursor:i?"not-allowed":"pointer",color:i?"var(--text-tertiary)":o?"var(--error)":"var(--text-primary)",opacity:i?.5:1},onMouseEnter:e=>{i||(e.currentTarget.style.background="var(--bg-sunken)")},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[t,r]})}function tJ(e){let{label:t,isOpen:r,onToggle:l,onClose:i,vertical:o,canMoveEarlier:a,canMoveLater:s,onMoveEarlier:d,onMoveLater:c,onRename:u,onDuplicate:p,onSetPeriod:v,hidden:x,onToggleHidden:m,onRemove:g}=e;return(0,n.jsxs)("div",{style:{position:"relative",display:"inline-flex",flex:1,minWidth:0},children:[(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),l()},style:{flex:1,minWidth:0,textAlign:"left",background:"none",border:"none",padding:0,cursor:"pointer",font:"inherit",color:r?"var(--accent)":"inherit",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t}),r&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{onClick:e=>{e.stopPropagation(),i()},style:{position:"fixed",inset:0,zIndex:20}}),(0,n.jsxs)("div",{style:{position:"absolute",top:"100%",left:0,marginTop:4,minWidth:200,background:"var(--bg-elevated)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",boxShadow:"0 4px 16px rgba(0,0,0,0.15)",padding:4,zIndex:21},children:[u&&(0,n.jsx)(t$,{icon:(0,n.jsx)(C.Z,{size:13}),label:"Rename",onClick:u}),o?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t$,{icon:(0,n.jsx)(w.Z,{size:13}),label:"Move up",onClick:d,disabled:!a}),(0,n.jsx)(t$,{icon:(0,n.jsx)(S.Z,{size:13}),label:"Move down",onClick:c,disabled:!s}
1)]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t$,{icon:(0,n.jsx)(z.Z,{size:13}),label:"Move left",onClick:d,disabled:!a}),(0,n.jsx)(t$,{icon:(0,n.jsx)(M.Z,{size:13}),label:"Move right",onClick:c,disabled:!s})]}),(0,n.jsx)(t$,{icon:x?(0,n.jsx)(f.Z,{size:13}):(0,n.jsx)(I.Z,{size:13}),label:x?"Show column":"Hide column",onClick:m}),(p||v)&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{height:1,background:"var(--border-subtle)",margin:"4px 2px"}}),p&&(0,n.jsx)(t$,{icon:(0,n.jsx)(b.Z,{size:13}),label:"Duplicate",onClick:p}),v&&(0,n.jsx)(t$,{icon:(0,n.jsx)(F.Z,{size:13}),label:"Set a different period",onClick:v})]}),(0,n.jsx)("div",{style:{height:1,background:"var(--border-subtle)",margin:"4px 2px"}}),(0,n.jsx)(t$,{icon:(0,n.jsx)(h.Z,{size:13}),label:"Remove",onClick:g,danger:!0})]})]})]})}function tX(e){var t,r;let{periodOverride:l,blockDefault:i,onChange:o}=e,a=null!==l,s=null!=l?l:i;return(0,n.jsxs)("div",{style:{padding:"8px 10px",background:"var(--bg-sunken)",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-subtle)",display:"flex",flexDirection:"column",gap:"var(--space-2)"},children:[(0,n.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:6,fontSize:11,cursor:"pointer"},children:[(0,n.jsx)("input",{type:"checkbox",checked:a,onChange:e=>o(e.target.checked?{...i}:null)}),"Use a different period for this column"]}),a&&(0,n.jsxs)("div",{style:{display:"flex",gap:"var(--space-2)",flexWrap:"wrap",alignItems:"center"},children:[(0,n.jsx)(eM.D,{value:String(s.fyIndex),onChange:e=>o({...s,fyIndex:Number(e)}),options:E.jH.map((e,t)=>({value:String(t),label:e})),size:"sm"}),(0,n.jsx)(eM.D,{value:12===s.selectedMonths.length?"all":null!==(r=null===(t=Object.entries(E.Mi).find(e=>{let[,t]=e;return t.length===s.selectedMonths.length&&t.every(e=>s.selectedMonths.includes(e))}))||void 0===t?void 0:t[0])&&void 0!==r?r:"custom",onChange:e=>{"all"===e?o({...s,selectedMonths:Array.from({length:12},(e,t)=>t)}):"custom"!==e&&o({...s,selectedMonths:E.Mi[e]})},options:[{value:"all",label:"Full year"},{value:"q1",label:"Q1 (AprâJun)"},{value:"q2",label:"Q2 (JulâSep)"},{value:"q3",label:"Q3 (OctâDec)"},{value:"q4",label:"Q4 (JanâMar)"},{value:"custom",label:"Custom months",disabled:!0}],size:"sm"}),(0,n.jsx)("div",{style:{display:"flex",gap:"var(--space-1)",flexWrap:"wrap"},children:E.gg.map((e,t)=>(0,n.jsx)("button",{type:"button",onClick:()=>{let e=new Set(s.selectedMonths);e.has(t)?e.delete(t):e.add(t),o({...s,selectedMonths:Array.from(e).sort((e,t)=>e-t)})},style:{padding:"3px 6px",fontSize:10,borderRadius:"var(--radius-sm)",cursor:"pointer",fontFamily:"var(--font-sans)",border:"1px solid ".concat(s.selectedMonths.includes(t)?"var(--accent)":"var(--border-subtle)"),background:s.selectedMonths.includes(t)?"var(--accent-subtle)":"var(--bg-elevated)",color:s.selectedMonths.includes(t)?"var(--accent)":"var(--text-primary)"},children:e},t))}),(0,n.jsx)(eM.D,{value:"rolling"===s.comparisonMode?"yoy":s.comparisonMode,onChange:e=>o({...s,comparisonMode:e}),options:[{value:"yoy",label:"vs Previous Year, Same Period"},{value:"none",label:"No comparison"}],size:"sm"})]})]})}function t0(e){let{search:t,onSearchChange:r,alreadyIncluded:i,onPickMetric:o,onPickBlank:a,onClose:s,align:d="left"}=e,[c,u]=(0,l.useState)({value:!0,comparison:!1,deviation:!1}),p=(0,l.useMemo)(()=>E.Em.filter(e=>!t||e.name.toLowerCase().includes(t.toLowerCase())),[t]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{onClick:s,style:{position:"fixed",inset:0,zIndex:20}}),(0,n.jsxs)("div",{style:{position:"absolute",top:"100%",[d]:0,marginTop:4,width:280,maxHeight:360,display:"flex",flexDirection:"column",background:"var(--bg-elevated)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",boxShadow:"0 4px 16px rgba(0,0,0,0.15)",zIndex:21},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"6px 8px",borderBottom:"1px solid var(--border-subtle)"},children:[(0,n.jsx)(A.Z,{size:12,color:"var(--text-tertiary)"}),(0,n.jsx)("input",{autoFocus:!0,value:t,onChange:e=>r(e.target.value),placeholder:"Search metricsâ¦",style:{border:"none",background:"transparent",fontSize:12,outline:"none",width:"100%",color:"var(--text-primary)",fontFamily:"var(--font-sans)"}})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:6,padding:"6px 8px",borderBottom:"1px solid var(--border-subtle)"},children:[(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-tertiary)"},children:"Include on add:"}),(0,n.jsx)(tq,{columns:c,onToggle:function(e){u(t=>({...t,[e]:!t[e]}))},bordered:!1})]}),(0,n.jsx)("div",{style:{overflowY:"auto",flex:1},children:0===p.length?(0,n.jsx)("div",{style:{padding:"12px 10px",textAlign:"center",color:"var(--text-tertiary)",fontSize:12},children:"No metrics match this search."}):p.map(e=>{let t=i(e.id);return(0,n.jsxs)("button",{type:"button",disabled:t,onClick:()=>o(e.id,c),style:{display:"flex",alignItems:"center",gap:"var(--space-2)",width:"100%",padding:"6px 10px",fontSize:12,fontFamily:"var(--font-sans)",background:"none",border:"none",textAlign:"left",cursor:t?"default":"pointer",opacity:t?.5:1},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-sunken)")},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:[(0,n.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(0,n.jsx)("span",{style:{fontSize:9,color:"var(--text-tertiary)",fontFamily:"var(--font-mono)",whiteSpace:"nowrap"},children:t?"Added":e.outputUnit})]},e.id)})}),(0,n.jsx)("div",{style:{borderTop:"1px solid var(--border-subtle)",padding:4},children:(0,n.jsx)(t$,{icon:(0,n.jsx)(j.Z,{size:13}),label:"Blank column (free text)",onClick:()=>a(c)})})]})]})}function t1(e){var t,r;let{block:i,onChange:o,onDelete:a,showDelete:s,readOnly:d}=e,[u,p]=(0,l.useState)(null),[v,x]=(0,l.useState)(""),[m,g]=(0,l.useState)(new Set),[b,y]=(0,l.useState)(""),[j,w]=(0,l.useState)("all"),[C,z]=(0,l.useState)(""),[F,D]=(0,l.useState)(!1),[B,O]=(0,l.useState)(null),[N,L]=(0,l.useState)(null),[W,P]=(0,l.useState)(null),[U,H]=(0,l.useState)(""),[G,V]=(0,l.useState)(null);(0,l.useEffect)(()=>
1{if(!G)return;let e=setTimeout(()=>V(null),3200);return()=>clearTimeout(e)},[G]);let[Q,_]=(0,l.useState)(null),[Y,q]=(0,l.useState)(""),[K,$]=(0,l.useState)(new Set),[J,X]=(0,l.useState)(null),[ee,et]=(0,l.useState)(null),er=(0,l.useRef)(!1);(0,l.useEffect)(()=>{0===i.metricFields.length&&null===u&&p("metrics")},[]),(0,l.useEffect)(()=>{function e(){er.current=!1}return window.addEventListener("mouseup",e),()=>window.removeEventListener("mouseup",e)},[]);let en=d&&i.snapshot?{...i,...i.snapshot.config}:i,el=!!i.snapshot&&JSON.stringify((0,E.fU)(i))!==JSON.stringify(i.snapshot.config),ei=(0,l.useMemo)(()=>(0,E.t)(en),[en.facilityScopeMode,en.facilityIds,en.facilityAttribute,en.facilityAttributeValue,en.facilityTagIds,en.facilityTagMatchMode]),eo=(0,l.useMemo)(()=>(0,E.oC)(en),[en.facilityScopeMode,en.facilityIds,en.facilityAttribute,en.facilityAttributeValue,en.facilityTagIds,en.facilityTagMatchMode,en.fyIndex,en.selectedMonths,en.comparisonMode,en.trendYears]),ea=i.selectedMonths,es=(0,E.oG)(i.fyIndex,ea),ed=!!es&&!es.unavailable;function ec(e,t){o(i.id,{metricFields:i.metricFields.map(r=>r.id===e?{...r,columns:{...r.columns,[t]:!r.columns[t]}}:r)})}(0,l.useEffect)(()=>{d||ed||"rolling"!==i.comparisonMode||o(i.id,{comparisonMode:"yoy"})},[ed,i.comparisonMode,d]);let eu=(0,l.useMemo)(()=>{if(!v)return E.ur;let e=v.toLowerCase();return E.ur.filter(t=>t.name.toLowerCase().includes(e)||t.code.toLowerCase().includes(e))},[v]),ep=(0,l.useMemo)(()=>{let e=[],t=new Map;for(let r of eu)t.has(r.region)||(t.set(r.region,[]),e.push(r.region)),t.get(r.region).push(r);return e.map(e=>({region:e,facilities:t.get(e)}))},[eu]),ef=(0,l.useMemo)(()=>E.Em.filter(e=>(!b||!!e.name.toLowerCase().includes(b.toLowerCase()))&&("all"===j||e.category===j)),[b,j]),ev={value:!0,comparison:!0,deviation:!0}
1;function ex(e){return i.metricFields.some(t=>"raw"===t.kind&&t.metricConfigId===e)}let[eh,em]=(0,l.useState)("sum"),[eg,eb]=(0,l.useState)([]),[ey,ej]=(0,l.useState)(""),[ek,ew]=(0,l.useState)(null);function eS(e,t){let r=i.metricFields,n=t?r.findIndex(e=>e.id===t):-1;if(-1===n){o(i.id,{metricFields:[...r,e]});return}o(i.id,{metricFields:[...r.slice(0,n+1),e,...r.slice(n+1)]})}let eC="percentOfTotal"===eh?1===eg.length:"multiply"===eh||"divide"===eh||"percentage"===eh?2===eg.length:eg.length>=2,ez=(0,l.useMemo)(()=>{if("sum"!==eh&&"average"!==eh)return null;let e=new Set(eg.map(e=>i.metricFields.find(t=>t.id===e)).filter(e=>!!e).map(function e(t){var r,n;if("raw"===t.kind)return null!==(n=null===(r=E.Em.find(e=>e.id===t.metricConfigId))||void 0===r?void 0:r.outputUnit)&&void 0!==n?n:"?";if("manual"===t.kind)return"?";if("count"===t.op)return"count";if("percentage"===t.op)return"%";let l=i.metricFields.find(e=>e.id===t.inputIds[0]);return l?e(l):"?"}));return e.size>1?Array.from(e):null},[eh,eg,i.metricFields]),[eI,eF]=(0,l.useState)(""),[eA,eR]=(0,l.useState)(null);function eT(e,t){if(("facility_rows"===i.orientation?"column":"row")===t){eS(e,null);return}V(t),o(i.id,{orientation:"column"===t?"facility_rows":"facility_columns",metricFields:[...i.metricFields,e]})}function eD(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{value:!0,comparison:!1,deviation:!1};eT({id:"x".concat(Date.now()),kind:"manual",label:"Custom ".concat(e),values:{},columns:t},e)}function eZ(e,t,r){ex(e)||(eT({id:"m".concat(Date.now()),kind:"raw",metricConfigId:e,columns:r,periodOverride:null},t),_(null),q(""))}function eE(e){o(i.id,{metricFields:i.metricFields.filter(t=>t.id!==e).map(t=>"formula"===t.kind?{...t,inputIds:t.inputIds.filter(t=>t!==e)}:t),hiddenFieldIds:i.hiddenFieldIds.filter(t=>t!==e)})}function eB(e,t){let r=i.metricFields,n=r.findIndex(t=>t.id===e),l=n+t;if(-1===n||l<0||l>=r.length)return;let a=[...r];[a[n],a[l]]=[a[l],a[n]],o(i.id,{metricFields:a})}function eO(e){o(i.id,{hiddenFieldIds:i.hiddenFieldIds.includes(e)?i.hiddenFieldIds.filter(t=>t!==e):[...i.hiddenFieldIds,e]})}function eN(){if(W){let e=U.trim();o(i.id,{metricFields:i.metricFields.map(t=>t.id!==W?t:"raw"===t.kind?e?{...t,labelOverride:e}:{...t,labelOverride:void 0}:{...t,label:e||t.label})})}P(null)}let eL=(0,l.useMemo)(()=>[...ei.map(e=>e.name),"Grand Total"],[ei]),eW=en.metricFields,eP=en.cellOverrides;function eU(e){var t,r,n;return"formula"===e.kind||"manual"===e.kind?e.label:null!==(n=null!==(r=e.labelOverride)&&void 0!==r?r:null===(t=E.Em.find(t=>t.id===e.metricConfigId))||void 0===t?void 0:t.name)&&void 0!==n?n:"Unknown metric"}function eH(e){return"raw"!==e.kind?null:"/app/projects/dashboards?".concat(new URLSearchParams({tab:"Formula Tree",kpi:e.metricConfigId}).toString())}function eG(e,t){let r=i.metricFields.findIndex(t=>t.id===e.id),l=W===e.id;return(0,n.jsxs)("span",{style:{position:"relative",display:"inline-flex",alignItems:"center",gap:"var(--space-1)",width:"100%"},children:[l?(0,n.jsx)("input",{autoFocus:!0,value:U,onChange:e=>H(e.target.value),onBlur:eN,onKeyDown:e=>{"Enter"===e.key&&eN(),"Escape"===e.key&&P(null)},onClick:e=>e.stopPropagation(),style:{fontSize:11,fontFamily:"var(--font-sans)",fontWeight:600,border:"1px solid var(--accent)",borderRadius:2,padding:"1px 4px",minWidth:90,background:"var(--bg-elevated)",color:"var(--text-primary)"}}):d?(0,n.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis"},children:eU(e)}):(0,n.jsx)(tJ,{label:eU(e),isOpen:N===e.id,onToggle:()=>L(t=>t===e.id?null:e.id),onClose:()=>L(null),vertical:t,canMoveEarlier:r>0,canMoveLater:r<i.metricFields.length-1,onMoveEarlier:()=>eB(e.id,-1),onMoveLater:()=>eB(e.id,1),onRename:()=>{L(null),P(e.id),H(eU(e))},onDuplicate:"manual"!==e.kind?()=>{!function(e){let t=i.metricFields.find(t=>t.id===e);if(!t||"manual"===t.kind)return;let r="".concat(eU(t)," (copy)"),n={fyIndex:i.fyIndex,selectedMonths:i.selectedMonths,comparisonMode:i.comparisonMode,trendYears:i.trendYears},l="raw"===t.kind?{...t,id:"r".concat(Date.now()),labelOverride:r,periodOverride:n}:{...t,id:"f".concat(Date.now()),label:r,periodOverride:n};eS(l,e),O(l.id)}(e.id),L(null)}:void 0,onSetPeriod:"manual"!==e.kind?()=>{O(e.id),L(null)}:void 0,hidden:i.hiddenFieldIds.includes(e.id),onToggleHidden:()=>{eO(e.id),L(null)},onRemove:()=>{eE(e.id),L(null)}}),!l&&function(e){let t=eH(e);return t?(0,n.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),title:"Open in Formula Tree (new tab) - best-effort: mock data may not match a real KPI id",style:{display:"inline-flex",color:"inherit",opacity:.6},children:(0,n.jsx)(R.Z,{size:10})},"drilldown"):null}(e),B===e.id&&"manual"!==e.kind&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{onClick:e=>{e.stopPropagation(),O(null)},style:{position:"fixed",inset:0,zIndex:20}}),(0,n.jsx)("div",{onClick:e=>e.stopPropagation(),style:{position:"absolute",top:"100%",right:0,marginTop:4,zIndex:21,width:320,background:"var(--bg-elevated)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",boxShadow:"0 4px 16px rgba(0,0,0,0.15)",padding:10},children:(0,n.jsx)(tX,{periodOverride:e.periodOverride,blockDefault:{fyIndex:i.fyIndex,selectedMonths:i.selectedMonths,comparisonMode:i.comparisonMode,trendYears:i.trendYears},onChange:t=>{var r;return r=e.id,void o(i.id,{metricFields:i.metricFields.map(e=>e.id===r&&"manual"!==e.kind?{...e,periodOverride:t}:e)})}})})]})]})}let eV=(0,l.useMemo)(()=>{let e=new Map;for(let t of eW)if("manual"!==t.kind&&t.periodOverride){let r=t.periodOverride;
1e.set(t.id,(0,E.oC)({...en,fyIndex:r.fyIndex,selectedMonths:r.selectedMonths,comparisonMode:r.comparisonMode,trendYears:r.trendYears}))}return e},[eW,en.facilityScopeMode,en.facilityIds,en.facilityAttribute,en.facilityAttributeValue,en.facilityTagIds,en.facilityTagMatchMode]),eQ=(0,l.useMemo)(()=>{let e=new Map;for(let r of eW){var t;let n=null!==(t=eV.get(r.id))&&void 0!==t?t:eo,l=new Map;for(let e of eL){let t="Grand Total"===e?null:E.vU.find(t=>t.name===e)?e:null;l.set(e,(0,E.rF)(eW,r.id,n,t))}e.set(r.id,l)}return e},[eW,eo,eL,eV]);function e_(e,t){var r,n;return null!==(n=null===(r=eQ.get(t.id))||void 0===r?void 0:r.get(e))&&void 0!==n?n:null}let eY=(0,l.useMemo)(()=>(0,E.uz)(eW).filter(e=>{let{i:t}=e;return!en.hiddenFieldIds.includes(eW[t].id)}),[eW,en.hiddenFieldIds]);function eq(e){$(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})}let eK="facility_rows"===en.orientation,e$=eK?eL:eW.map(eU),eJ=(0,l.useMemo)(()=>{let e=C.trim().toLowerCase(),t=t=>!e||e$[t].toLowerCase().includes(e),r=e=>!F||!function(e){for(let t of eK?eL:eW){let r=eK?t:e$[e],n=eK?eW[e]:t;if(!n)continue;let l=e_(r,n);if(l&&null!=l.value&&0!==l.value)return!1}return!0}(e);return eK?e$.map((e,t)=>t).filter(e=>t(e)&&r(e)):eY.filter(e=>{let{cat:t}=e;return!K.has(t)}).map(e=>{let{i:t}=e;return t}).filter(e=>t(e)&&r(e))},[e$,C,eK,eY,K,F,eo]),eX=eW.some(e=>{var t;return(null!==(t=eV.get(e.id))&&void 0!==t?t:eo).hasComparison&&(e.columns.comparison||e.columns.deviation)}),e0=(0,l.useMemo)(()=>{let e=[];for(let{i:t,cat:r}of eY)e.length&&e[e.length-1].cat===r?e[e.length-1].members.push(t):e.push({cat:r,members:[t]});return e.flatMap(e=>K.has(e.cat)?[{kind:"collapsedGroup",cat:e.cat,hiddenCount:e.members.length}]:e.members.map(e=>({kind:"metric",fieldIdx:e})))},[eY,K]),e1=(0,l.useMemo)(()=>{let e=eX?3:1,t=[];for(let r of e0){let n="collapsedGroup"===r.kind?r.cat:(0,E.J$)(eW[r.fieldIdx]),l="collapsedGroup"===r.kind?1:e;t.push({cat:n,colSpan:l,collapsed:"collapsedGroup"===r.kind})}return t},[e0,eX]),e2=eK&&e1.length>0,e6=(0,l.useMemo)(()=>{let e=[],t=new Map;for(let{i:r,cat:n}of eY)t.has(n)||(t.set(n,[]),e.push(n)),t.get(n).push(r);return e.map(e=>({cat:e,members:t.get(e)}))},[eY]),e3=(0,l.useMemo)(()=>eK?e0.flatMap(e=>"collapsedGroup"===e.kind?[{kind:"collapsedGroup",cat:e.cat}]:Array.from({length:eX?3:1},(t,r)=>({kind:"field",index:e.fieldIdx,sub:r}))):eL.flatMap((e,t)=>Array.from({length:eX?3:1},(e,r)=>({kind:"field",index:t,sub:r}))),[eK,e0,eL,eX]);function e4(e,t){return"".concat(e.id,"::").concat(t)}function e8(e,t){let r=e3[t];if("collapsedGroup"===r.kind)return{text:"â¯"};let n=eK?e$[e]:eL[r.index],l=eK?eW[r.index]:eW[e];if(!l)return{text:"-"};let i="Grand Total"===n;if("manual"===l.kind)return 0!==r.sub||i?{text:"-"}:{text:l.values[n]||"-"};if(0===r.sub&&!l.columns.value||1===r.sub&&!l.columns.comparison||2===r.sub&&!l.columns.deviation)return{text:"-"};if(0===r.sub&&!i){let e=eP[e4(l,n)];if(void 0!==e)return{text:e||"-"}}let o=e_(n,l);if(!o)return{text:"-"};if(0===r.sub)return{text:(0,E.q1)(o.value,o.uom)};if(1===r.sub)return{text:null!=o.cmpValue?(0,E.q1)(o.cmpValue,o.uom):"-"};let a=(0,E.Mo)(o.value,o.cmpValue,o.isPct);return{text:a.text,cls:a.cls}}function e5(e,t,r){let n=e3[t];if("collapsedGroup"===n.kind)return;let l=eK?e$[e]:eL[n.index],a=eK?eW[n.index]:eW[e];if(a){if("manual"===a.kind){o(i.id,{metricFields:i.metricFields.map(e=>e.id===a.id&&"manual"===e.kind?{...e,values:{...e.values,[l]:r}}:e)});return}o(i.id,{cellOverrides:{...i.cellOverrides,[e4(a,l)]:r}})}}function e9(e,t){let r=eK&&"Grand Total"===e$[e];return(0,n.jsxs)("tr",{style:{background:r?void 0:t%2?"var(--bg-sunken)":"transparent"},children:[(0,n.jsx)("td",{style:{border:"1px solid var(--border-subtle)",padding:"7px 10px",fontWeight:r?600:500,position:"sticky",left:0,zIndex:1,background:r?"var(--accent-subtle)":"var(--bg-elevated)",color:r?"var(--accent)":void 0},children:eK?(0,n.jsx)("span",{style:{display:"inline-flex",alignItems:"center",gap:"var(--space-1)"},children:e$[e]}):eG(eW[e],!0)}),e3.map((l,a)=>{if("collapsedGroup"===l.kind)return(0,n.jsx)("td",{onClick:()=>eq(l.cat),title:"Expand ".concat(l.cat),style:{border:"1px solid var(--border-subtle)",padding:"7px 10px",textAlign:"center",color:"var(--text-tertiary)",cursor:"pointer"},children:"â¯"},a);let s=!eK&&"Grand Total"===eL[l.index],{text:c,cls:u}=e8(e,a),p=!!J&&t>=Math.min(J.r1,J.r2)&&t<=Math.max(J.r1,J.r2)&&a>=Math.min(J.f1,J.f2)&&a<=Math.max(J.f1,J.f2),f=function(e,t){if(d)return!1;let r=e3[t];return"collapsedGroup"!==r.kind&&0===r.sub&&"Grand Total"!==(eK?e$[e]:eL[r.index])&&!!(eK?eW[r.index]:eW[e])}(e,a),v=function(e,t){let r=e3[t];
1if("collapsedGroup"===r.kind||0!==r.sub)return!1;let n=eK?e$[e]:eL[r.index],l=eK?eW[r.index]:eW[e];return!!l&&("raw"===l.kind||"formula"===l.kind)&&void 0!==eP[e4(l,n)]}(e,a),x=(null==ee?void 0:ee.rowIdx)===e&&(null==ee?void 0:ee.colIdx)===a,h=eK?eW[l.index]:eW[e],m=(null==h?void 0:h.kind)==="manual";return x?(0,n.jsx)("td",{style:{border:"1px solid var(--accent)",padding:0,background:"var(--bg-elevated)"},children:(0,n.jsx)("input",{autoFocus:!0,value:ee.value,onChange:t=>et({rowIdx:e,colIdx:a,value:t.target.value}),onBlur:()=>{e5(e,a,ee.value),et(null)},onKeyDown:t=>{"Enter"===t.key&&(e5(e,a,ee.value),et(null)),"Escape"===t.key&&et(null)},style:{width:"100%",border:"none",outline:"none",padding:"7px 10px",fontFamily:"var(--font-mono)",fontSize:12,textAlign:m?"left":"right",background:"transparent",color:"var(--text-primary)"}})},a):(0,n.jsxs)("td",{onMouseDown:e=>{var r;return r=e.shiftKey,void(X(e=>r&&e?{...e,r2:t,f2:a}:{r1:t,f1:a,r2:t,f2:a}),er.current=!0)},onMouseEnter:()=>{er.current&&X(e=>e?{...e,r2:t,f2:a}:e)},onDoubleClick:()=>{f&&et({rowIdx:e,colIdx:a,value:"-"===c?"":c})},title:v?"Manually overridden - double-click to edit, or click the ⺠to revert to the computed value":f?"Double-click to edit":void 0,style:{position:"relative",border:"1px solid var(--border-subtle)",padding:"7px 10px",textAlign:m?"left":"right",fontFamily:m?"var(--font-sans)":"var(--font-mono)",fontSize:12,background:p?"var(--accent-subtle)":v?"var(--accent-subtle)":r||s?"var(--accent-subtle)":void 0,outline:p?"2px solid var(--accent)":v?"1px dashed var(--accent)":"none",outlineOffset:-2,color:"pos"===u?"var(--success)":"neg"===u?"var(--error)":r||s?"var(--accent)":"var(--text-primary)",fontWeight:0!==l.sub||m?400:600,cursor:f?"text":void 0},children:[c,v&&(0,n.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),function(e,t){let r=e3[t];if("collapsedGroup"===r.kind)return;let n=eK?e$[e]:eL[r.index],l=eK?eW[r.index]:eW[e];if(!l)return;let a=e4(l,n),s={...i.cellOverrides};delete s[a],o(i.id,{cellOverrides:s})}(e,a)},title:"Revert to computed value",style:{position:"absolute",top:1,right:1,width:13,height:13,lineHeight:"13px",fontSize:9,border:"none",borderRadius:2,background:"var(--accent)",color:"var(--bg-elevated)",cursor:"pointer",padding:0},children:"âº"})]},a)})]},e)}let e7={border:"1px solid var(--border-subtle)",padding:"6px 10px",background:"var(--bg-sunken)",fontSize:11,fontWeight:600,textAlign:"left",whiteSpace:"nowrap",position:"sticky",top:0,zIndex:2},te=function(){var e;if(!J)return null;let t=e3[J.f1];if(!t)return null;if("collapsedGroup"===t.kind)return"".concat(t.cat," \xb7 collapsed");let r=eK?e$[J.r1]:eL[t.index],n=eK?eW[t.index]:eW[null!==(e=eJ[J.r1])&&void 0!==e?e:J.r1];if(!n)return null;let l=0===t.sub?"Value":1===t.sub?"Comparison":"Deviation";return"".concat(r," â ").concat(eU(n)," \xb7 ").concat(l)}(),tt=function(){var e;if(!J||J.r1!==J.r2||J.f1!==J.f2)return null;let t=e3[J.f1];if(!t||"collapsedGroup"===t.kind||0!==t.sub)return null;let r=eK?e$[J.r1]:eL[t.index],n=eK?eW[t.index]:eW[null!==(e=eJ[J.r1])&&void 0!==e?e:J.r1];if(!n||"manual"===n.kind)return null;if("Grand Total"===r){let e=ei.map(e=>{let t=e_(e.name,n);return(null==t?void 0:t.value)!=null?"".concat(e.name," ").concat((0,E.q1)(t.value,t.uom)):null}).filter(e=>!!e);return e.length?{text:"= ".concat(e.join(" + ")),mf:n}:null}if("formula"===n.kind){let e=n.inputIds.map(e=>i.metricFields.find(t=>t.id===e)).filter(e=>!!e).map(e=>{let t=e_(r,e);return(null==t?void 0:t.value)!=null?"".concat(eU(e)," ").concat((0,E.q1)(t.value,t.uom)):null}).filter(e=>!!e);return e.length?{text:"".concat(tj[n.op],": ").concat(e.join(", ")),mf:n}:null}return null}();return(0,n.jsxs)("div",{style:{position:"relative",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-md)",background:"var(--bg-elevated)",padding:12},children:[s&&(0,n.jsx)(tN,{onClick:()=>a(i.id)}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:10,flexWrap:"wrap",gap:"var(--space-2)"},children:[(0,n.jsxs)("span",{style:{fontSize:11,textTransform:"uppercase",letterSpacing:"0.05em",color:"var(--text-tertiary)",display:"flex",alignItems:"center",gap:"var(--space-1)"},children:[(0,n.jsx)(T.Z,{size:11,color:"var(--accent)"})," Smart Table"]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)",flexWrap:"wrap"},children:[!d&&(0,n.jsxs)(Z.Btn,{variant:"ghost",size:"sm",icon:(0,n.jsx)(T.Z,{size:11}),onClick:function(){o(i.id,{orientation:"facility_columns"===i.orientation?"facility_rows":"facility_columns"})}
1,title:"Transpose - swap which axis facilities occupy",children:["Facility as ",eK?"Rows":"Columns"]}),(0,n.jsxs)("span",{style:{fontSize:11,color:el?"var(--accent)":"var(--text-tertiary)",display:"flex",alignItems:"center",gap:"var(--space-1)"},children:[el&&(0,n.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:"var(--accent)",flexShrink:0}}),i.snapshot?"Overview last fetched ".concat(function(e){let t=Math.round((Date.now()-new Date(e).getTime())/6e4);if(t<1)return"just now";if(t<60)return"".concat(t," min").concat(1===t?"":"s"," ago");let r=Math.round(t/60);if(r<24)return"".concat(r," hour").concat(1===r?"":"s"," ago");let n=Math.round(r/24);return"".concat(n," day").concat(1===n?"":"s"," ago")}(i.snapshot.fetchedAt)):"Overview: not yet fetched",el?" \xb7 setup has changed since":""]}),(0,n.jsxs)(Z.Btn,{variant:!i.snapshot||el?"primary":"default",size:"sm",onClick:()=>o(i.id,{snapshot:{fetchedAt:new Date().toISOString(),fetchedBy:"You",config:(0,E.fU)(i)}}),title:"Freeze the current Setup configuration into what Overview shows",children:["Fetch",d?"":" to Overview"]})]})]}),G&&(0,n.jsxs)("div",{style:{fontSize:11,color:"var(--accent)",background:"var(--accent-subtle)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",padding:"6px 10px",marginBottom:10,display:"flex",alignItems:"center",gap:6},children:[(0,n.jsx)(T.Z,{size:12}),"Transposed the table so ","column"===G?"columns":"rows"," hold your fields, then added the new ",G,"."]}),d&&!i.snapshot?(0,n.jsxs)("div",{style:{padding:24,textAlign:"center",color:"var(--text-tertiary)",fontSize:12},children:["This Smart Table hasn't been fetched yet - Overview only shows explicitly-fetched data.",(0,n.jsx)("br",{}),"Click ",(0,n.jsx)("strong",{children:"Fetch to Overview"})," above (or from Setup) to pull in the current configuration."]}):d&&0===eW.length?(0,n.jsx)("div",{style:{padding:16,textAlign:"center",color:"var(--text-tertiary)",fontSize:12},children:"No metrics were mapped when this was last fetched."}):(0,n.jsxs)(n.Fragment,{children:[!d&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-2)",marginBottom:12},children:[(0,n.jsxs)(tY,{title:"".concat(eK?"Rows":"Columns",": Facility"),summary:"explicit"===i.facilityScopeMode?"Specific - ".concat(i.facilityIds.length," of ").concat(E.ur.length):"attribute"===i.facilityScopeMode?"".concat(i.facilityAttribute," = ").concat(i.facilityAttributeValue||"-"," \xb7 ").concat(ei.length," facilit").concat(1===ei.length?"y":"ies"):"Tag \xb7 ".concat(ei.length," facilit").concat(1===ei.length?"y":"ies"),isOpen:"facility"===u,onToggle:()=>p(e=>"facility"===e?null:"facility"),children:[(0,n.jsx)("div",{style:{display:"flex",gap:14,flexWrap:"wrap",marginBottom:10},children:["explicit","attribute","tag"].map(e=>(0,n.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:"var(--space-1)",fontSize:12},children:[(0,n.jsx)("input",{type:"radio",checked:i.facilityScopeMode===e,onChange:()=>o(i.id,{facilityScopeMode:e})}),"explicit"===e?"Specific facilities":"attribute"===e?"By attribute":"By tag"]},e))}),"explicit"===i.facilityScopeMode?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{display:"flex",gap:"var(--space-2)",alignItems:"center",marginBottom:8,flexWrap:"wrap"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,background:"var(--bg-base)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",padding:"4px 10px",flex:1,minWidth:160},children:[(0,n.jsx)(A.Z,{size:12,color:"var(--text-tertiary)"}),(0,n.jsx)("input",{value:v,onChange:e=>x(e.target.value),placeholder:"Search facilities (name or code)â¦",style:{border:"none",background:"transparent",fontSize:12,outline:"none",width:"100%",color:"var(--text-primary)",fontFamily:"var(--font-sans)"}})]}),(0,n.jsxs)(Z.Btn,{variant:"ghost",size:"sm",onClick:function(){o(i.id,{facilityIds:Array.from(new Set([...i.facilityIds,...eu.map(e=>e.id)]))})},children:["Select all",v?" filtered":""]}),(0,n.jsxs)(Z.Btn,{variant:"ghost",size:"sm",onClick:function(){let e=new Set(eu.map(e=>e.id));o(i.id,{facilityIds:i.facilityIds.filter(t=>!e.has(t))})},children:["Clear",v?" filtered":""]})]}),(0,n.jsx)("div",{style:{maxHeight:220,overflowY:"auto",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)"},children:0===ep.length?(0,n.jsxs)("div",{style:{padding:16,textAlign:"center",color:"var(--text-tertiary)",fontSize:12},children:['No facilities match "',v,'"']}):ep.map(e=>{let{region:t,facilities:r}=e,l=m.has(t),a=r.filter(e=>i.facilityIds.includes(e.id)).length;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("button",{type:"button",onClick:()=>g(e=>{let r=new Set(e);return r.has(t)?r.delete(t):r.add(t),r}),style:{display:"flex",alignItems:"center",gap:6,width:"100%",background:"var(--bg-sunken)",border:"none",borderBottom:"1px solid var(--border-subtle)",padding:"6px 10px",cursor:"pointer",font:"inherit",textAlign:"left"},children:[l?(0,n.jsx)(M.Z,{size:11,color:"var(--text-tertiary)"}):(0,n.jsx)(S.Z,{size:11,color:"var(--text-tertiary)"}),(0,n.jsx)("span",{style:{fontSize:12,fontWeight:600},children:t}
1),(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-tertiary)",fontFamily:"var(--font-mono)"},children:[a,"/",r.length]})]}),!l&&r.map(e=>(0,n.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)",padding:"6px 10px 6px 26px",cursor:"pointer",fontSize:12},children:[(0,n.jsx)("input",{type:"checkbox",checked:i.facilityIds.includes(e.id),onChange:()=>o(i.id,{facilityIds:i.facilityIds.includes(e.id)?i.facilityIds.filter(t=>t!==e.id):[...i.facilityIds,e.id]})}),(0,n.jsx)("span",{style:{flex:1},children:e.name}),(0,n.jsx)("span",{style:{fontSize:10,color:"var(--text-tertiary)",fontFamily:"var(--font-mono)"},children:e.code})]},e.id))]},t)})})]}):"attribute"===i.facilityScopeMode?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{display:"flex",gap:"var(--space-2)",alignItems:"center",flexWrap:"wrap",marginBottom:6},children:[(0,n.jsx)(eM.D,{value:i.facilityAttribute,onChange:e=>{o(i.id,{facilityAttribute:e,facilityAttributeValue:E.vo[e][0]})},options:[{value:"region",label:"Region"},{value:"kind",label:"Facility type"},{value:"status",label:"Status"}],size:"sm"}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-secondary)"},children:"="}),(0,n.jsx)(eM.D,{value:i.facilityAttributeValue,onChange:e=>o(i.id,{facilityAttributeValue:e}),options:E.vo[i.facilityAttribute].map(e=>({value:e,label:e})),size:"sm"})]}),(0,n.jsxs)("div",{style:{fontSize:11,color:"var(--text-tertiary)"},children:["Resolves to: ",tT(ei)]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:"var(--space-3)",marginBottom:6},children:E.o8.map(e=>{let t=i.facilityTagIds.includes(e.id);return(0,n.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:6,fontSize:12},children:[(0,n.jsx)("input",{type:"checkbox",checked:t,onChange:()=>o(i.id,{facilityTagIds:t?i.facilityTagIds.filter(t=>t!==e.id):[...i.facilityTagIds,e.id]})}),e.name]},e.id)})}),(0,n.jsxs)("div",{style:{fontSize:11,color:"var(--text-tertiary)"},children:["Resolves to: ",tT(ei)]})]})]}),(0,n.jsxs)(tY,{title:"".concat(eK?"Columns":"Rows",": Metrics"),summary:(()=>{let e=eW.filter(e=>"raw"===e.kind).length,t=eW.filter(e=>"formula"===e.kind).length,r=eW.filter(e=>"manual"===e.kind).length;return e||t||r?"".concat(e," metric").concat(1===e?"":"s").concat(t?", ".concat(t," formula column").concat(1===t?"":"s"):"").concat(r?", ".concat(r," custom column").concat(1===r?"":"s"):""):"None mapped"})(),isOpen:"metrics"===u,onToggle:()=>p(e=>"metrics"===e?null:"metrics"),children:[(0,n.jsxs)("div",{style:{display:"flex",gap:10,alignItems:"center",marginBottom:8,flexWrap:"wrap"},children:[(0,n.jsx)("div",{style:{display:"flex",gap:2,padding:2,background:"var(--bg-sunken)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)"},children:["all","Environmental","Social"].map(e=>(0,n.jsx)("button",{onClick:()=>w(e),style:{padding:"var(--space-1) var(--space-2)",fontSize:11,border:"none",borderRadius:"var(--radius-sm)",cursor:"pointer",fontFamily:"var(--font-sans)",background:j===e?"var(--bg-elevated)":"transparent",color:j===e?"var(--accent)":"var(--text-secondary)",fontWeight:j===e?600:400},children:"all"===e?"All":e},e))}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,background:"var(--bg-base)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",padding:"4px 10px",flex:1,minWidth:160},children:[(0,n.jsx)(A.Z,{size:12,color:"var(--text-tertiary)"}),(0,n.jsx)("input",{value:b,onChange:e=>y(e.target.value),placeholder:"Search metricsâ¦",style:{border:"none",background:"transparent",fontSize:12,outline:"none",width:"100%",color:"var(--text-primary)",fontFamily:"var(--font-sans)"}})]}),(0,n.jsxs)(Z.Btn,{variant:"ghost",size:"sm",onClick:function(){let e=new Set(i.metricFields.filter(e=>"raw"===e.kind).map(e=>e.metricConfigId)),t=ef.filter(t=>!e.has(t.id)).map(e=>({id:"m".concat(Date.now(),"-").concat(e.id),kind:"raw",metricConfigId:e.id,columns:ev,periodOverride:null}));o(i.id,{metricFields:[...i.metricFields,...t]})},children:["Select all",b||"all"!==j?" filtered":""]}),(0,n.jsxs)(Z.Btn,{variant:"ghost",size:"sm",onClick:function(){let e=new Set(ef.map(e=>e.id));o(i.id,{metricFields:i.metricFields.filter(t=>!("raw"===t.kind&&e.has(t.metricConfigId)))})},children:["Clear",b||"all"!==j?" filtered":""]})]}),(0,n.jsxs)("div",{style:{fontSize:11,color:"var(--text-tertiary)",marginBottom:6},children:[ef.length," of ",E.Em.length," metrics match this filter"]}),(0,n.jsx)("div",{style:{maxHeight:260,overflowY:"auto",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)"},children:0===ef.length?(0,n.jsx)("div",{style:{padding:16,textAlign:"center",color:"var(--text-tertiary)",fontSize:12},children:"No metrics match this search/filter."}):ef.map(e=>{let t=i.metricFields.find(t=>"raw"===t.kind&&t.metricConfigId===e.id);return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)",padding:"6px 10px",borderBottom:"1px solid var(--border-subtle)"},children:[(0,n.jsx)("input",{type:"checkbox",checked:!!t,onChange:()=>{var t;ex(t=e.id)?o(i.id,{metricFields:i.metricFields.filter(e=>!("raw"===e.kind&&e.metricConfigId===t))}):o(i.id,{metricFields:[...i.metricFields,{id:"m".concat(Date.now()),kind:"raw",metricConfigId:t,columns:ev,periodOverride:null}]})}}),(0,n.jsx)("span",{style:{fontSize:12,flex:1},children:e.name}),(0,n.jsx)("span",{style:{fontSize:9,color:"var(--text-tertiary)",fontFamily:"var(--font-mono)"},children:e.subcategory}
1),(0,n.jsx)("span",{style:{fontSize:10,color:"var(--text-tertiary)",fontFamily:"var(--font-mono)",minWidth:40,textAlign:"right"},children:e.outputUnit}),t&&(0,n.jsx)(tq,{columns:t.columns,onToggle:e=>ec(t.id,e)})]},e.id)})}),(0,n.jsxs)("div",{style:{borderTop:"1px solid var(--border-subtle)",marginTop:12,paddingTop:12},children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-secondary)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:6},children:"Formula columns"}),i.metricFields.filter(e=>"formula"===e.kind).length>0&&(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-1)",marginBottom:8},children:i.metricFields.filter(e=>"formula"===e.kind).map(e=>{let t=i.hiddenFieldIds.includes(e.id);return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)",padding:"6px 10px",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",background:"var(--bg-sunken)",opacity:t?.55:1},children:[(0,n.jsx)("span",{style:{fontSize:10,fontWeight:700,color:"var(--accent)",fontFamily:"var(--font-mono)",textTransform:"uppercase",background:"var(--accent-subtle)",padding:"2px 6px",borderRadius:"var(--radius-sm)"},children:tj[e.op]}),(0,n.jsxs)("span",{style:{fontSize:12,flex:1},children:[e.label,t&&" (hidden)"]}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-tertiary)"},children:e.inputIds.map(e=>i.metricFields.find(t=>t.id===e)).filter(Boolean).map(e=>eU(e)).join(" \xb7 ")}),(0,n.jsx)(tq,{columns:e.columns,onToggle:t=>ec(e.id,t)}),(0,n.jsx)("button",{type:"button",onClick:()=>eO(e.id),title:t?"Show in grid":"Hide from grid (keeps its config)",style:tK,children:t?(0,n.jsx)(I.Z,{size:13}):(0,n.jsx)(f.Z,{size:13})}),(0,n.jsx)("button",{type:"button",onClick:()=>eE(e.id),title:"Remove formula column",style:tK,children:(0,n.jsx)(h.Z,{size:13})})]},e.id)})}),0===i.metricFields.length?(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-tertiary)"},children:"Map at least 1 metric above before building a formula column."}):(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-2)",padding:10,border:"1px dashed var(--border-subtle)",borderRadius:"var(--radius-sm)"},children:[(0,n.jsx)("div",{style:{display:"flex",gap:2,padding:2,background:"var(--bg-sunken)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",width:"fit-content",flexWrap:"wrap"},children:Object.keys(tj).map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>{em(e),eb([])},style:{padding:"var(--space-1) var(--space-2)",fontSize:11,border:"none",borderRadius:"var(--radius-sm)",cursor:"pointer",fontFamily:"var(--font-sans)",background:eh===e?"var(--bg-elevated)":"transparent",color:eh===e?"var(--accent)":"var(--text-secondary)",fontWeight:eh===e?600:400},children:tj[e]},e))}),(0,n.jsxs)("div",{style:{fontSize:11,color:"var(--text-tertiary)"},children:["percentOfTotal"===eh?"Pick exactly 1 field":"multiply"===eh||"divide"===eh||"percentage"===eh?"Pick exactly 2 fields":"Pick 2 or more fields","divide"===eh&&" - first \xf7 second","percentage"===eh&&" - first \xf7 second \xd7 100","percentOfTotal"===eh&&" - this field \xf7 its own org-wide Grand Total \xd7 100 (Q10)"]}),(0,n.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:6,maxHeight:120,overflowY:"auto"},children:i.metricFields.filter(e=>"manual"!==e.kind).map(e=>(0,n.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:"var(--space-1)",fontSize:12,border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",padding:"var(--space-1) var(--space-2)",cursor:"pointer",background:eg.includes(e.id)?"var(--accent-subtle)":"transparent"},children:[(0,n.jsx)("input",{type:"checkbox",checked:eg.includes(e.id),onChange:()=>{var t;return t=e.id,void eb(e=>"percentOfTotal"===eh?e[0]===t?[]:[t]:e.includes(t)?e.filter(e=>e!==t):[...e,t])}}),eU(e)]},e.id))}),(0,n.jsxs)("div",{style:{display:"flex",gap:"var(--space-2)",alignItems:"center",flexWrap:"wrap"},children:[(0,n.jsx)("input",{value:ey,onChange:e=>ej(e.target.value),placeholder:"Column name (optional)",style:{...tO,padding:"var(--space-1) var(--space-2)",fontSize:12,flex:1,minWidth:140}}
1),(0,n.jsx)(eM.D,{value:null!=ek?ek:"",onChange:e=>ew(e||null),options:[{value:"",label:"Insert at the end"},...i.metricFields.map(e=>({value:e.id,label:"After: ".concat(eU(e))}))],size:"sm",style:{height:30}}),(0,n.jsx)(Z.Btn,{variant:"primary",size:"sm",onClick:function(){if(!eC)return;let e="percentOfTotal"===eh?(()=>{let e=i.metricFields.find(e=>e.id===eg[0]);return e?"".concat(eU(e)," - % of Grand Total"):"Percent of Grand Total"})():"".concat(tj[eh]," of ").concat(eg.length," field").concat(1===eg.length?"":"s"),t=ey.trim()||e;eS({id:"f".concat(Date.now()),kind:"formula",label:t,op:eh,inputIds:eg,columns:ev,periodOverride:null},ek),eb([]),ej(""),ew(null)},disabled:!eC,children:"Add formula column"})]}),!eC&&eg.length>0&&(0,n.jsx)("div",{style:{fontSize:11,color:"var(--accent)"},children:"percentOfTotal"===eh?"This operation needs exactly 1 field selected.":"multiply"===eh||"divide"===eh||"percentage"===eh?"This operation needs exactly 2 fields selected.":"Select at least 2 fields."}),ez&&(0,n.jsxs)("div",{style:{fontSize:11,color:"var(--accent)",display:"flex",alignItems:"center",gap:"var(--space-1)"},children:["â Selected fields use different units (",ez.join(", "),") - the ","sum"===eh?"sum":"average"," may not be meaningful across them."]})]})]}),(0,n.jsxs)("div",{style:{borderTop:"1px solid var(--border-subtle)",marginTop:12,paddingTop:12},children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-secondary)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:6},children:"Custom columns"}),i.metricFields.filter(e=>"manual"===e.kind).length>0&&(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-1)",marginBottom:8},children:i.metricFields.filter(e=>"manual"===e.kind).map(e=>{let t=i.hiddenFieldIds.includes(e.id);return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)",padding:"6px 10px",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",background:"var(--bg-sunken)",opacity:t?.55:1},children:[(0,n.jsx)("span",{style:{fontSize:10,fontWeight:700,color:"var(--text-secondary)",fontFamily:"var(--font-mono)",textTransform:"uppercase",background:"var(--bg-elevated)",padding:"2px 6px",borderRadius:"var(--radius-sm)",border:"1px solid var(--border-subtle)"},children:"Free text"}),(0,n.jsxs)("span",{style:{fontSize:12,flex:1},children:[e.label,t&&" (hidden)"]}),(0,n.jsx)("button",{type:"button",onClick:()=>eO(e.id),title:t?"Show in grid":"Hide from grid (keeps its config)",style:tK,children:t?(0,n.jsx)(I.Z,{size:13}):(0,n.jsx)(f.Z,{size:13})}),(0,n.jsx)("button",{type:"button",onClick:()=>eE(e.id),title:"Remove custom column",style:tK,children:(0,n.jsx)(h.Z,{size:13})})]},e.id)})}),(0,n.jsxs)("div",{style:{display:"flex",gap:"var(--space-2)",alignItems:"center",flexWrap:"wrap"},children:[(0,n.jsx)("input",{value:eI,onChange:e=>eF(e.target.value),placeholder:'Column name, e.g. "Auditor remarks"',style:{...tO,padding:"var(--space-1) var(--space-2)",fontSize:12,flex:1,minWidth:160}}),(0,n.jsx)(eM.D,{value:null!=eA?eA:"",onChange:e=>eR(e||null),options:[{value:"",label:"Insert at the end"},...i.metricFields.map(e=>({value:e.id,label:"After: ".concat(eU(e))}))],size:"sm",style:{height:30}}),(0,n.jsx)(Z.Btn,{variant:"primary",size:"sm",onClick:function(){let e=eI.trim()||"Custom column";eS({id:"x".concat(Date.now()),kind:"manual",label:e,values:{},columns:{value:!0,comparison:!1,deviation:!1}},eA),eF(""),eR(null)},children:"Add custom column"})]}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-tertiary)",marginTop:6},children:"Double-click any cell in a custom column to type its text - it never has Comparison/Deviation or a Grand Total, since there's nothing to compute."})]})]}),(0,n.jsxs)(tY,{title:"Period & comparison",summary:"".concat(E.jH[i.fyIndex]," \xb7 ").concat(12===ea.length?"Full year":1===ea.length?E.gg[ea[0]]:"".concat(ea.length," months")," \xb7 ").concat("rolling"===i.comparisonMode?"Same Year, Previous Period":"yoy"===i.comparisonMode?"Previous Year, Same Period":"No comparison"),isOpen:"period"===u,onToggle:()=>p(e=>"period"===e?null:"period"),children:[(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-secondary)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:6}
1,children:"1. Period"}),(0,n.jsxs)("div",{style:{display:"flex",gap:"var(--space-2)",flexWrap:"wrap"},children:[(0,n.jsx)(eM.D,{value:String(i.fyIndex),onChange:e=>o(i.id,{fyIndex:Number(e)}),options:E.jH.map((e,t)=>({value:String(t),label:e})),size:"sm",style:{height:30}}),(0,n.jsx)(eM.D,{value:12===ea.length?"all":null!==(r=null===(t=Object.entries(E.Mi).find(e=>{let[,t]=e;return t.length===ea.length&&t.every(e=>ea.includes(e))}))||void 0===t?void 0:t[0])&&void 0!==r?r:"custom",onChange:e=>{"all"===e?o(i.id,{selectedMonths:Array.from({length:12},(e,t)=>t)}):"custom"!==e&&o(i.id,{selectedMonths:E.Mi[e]})},options:[{value:"all",label:"Full year"},{value:"q1",label:"Q1 (AprâJun)"},{value:"q2",label:"Q2 (JulâSep)"},{value:"q3",label:"Q3 (OctâDec)"},{value:"q4",label:"Q4 (JanâMar)"},{value:"custom",label:"Custom months",disabled:!0}],size:"sm",style:{height:30}})]}),(0,n.jsxs)("div",{style:{marginTop:8},children:[(0,n.jsxs)("div",{style:{fontSize:11,color:"var(--text-tertiary)",marginBottom:4},children:["Or pick specific months - ",ea.length," selected",1===ea.length?" (single-month comparison)":""]}),(0,n.jsx)("div",{style:{display:"flex",gap:"var(--space-1)",flexWrap:"wrap"},children:E.gg.map((e,t)=>(0,n.jsx)("button",{type:"button",onClick:()=>(function(e){let t=new Set(ea);t.has(e)?t.delete(e):t.add(e),o(i.id,{selectedMonths:Array.from(t).sort((e,t)=>e-t)})})(t),style:{padding:"var(--space-1) var(--space-2)",fontSize:11,borderRadius:"var(--radius-sm)",cursor:"pointer",fontFamily:"var(--font-sans)",border:"1px solid ".concat(ea.includes(t)?"var(--accent)":"var(--border-subtle)"),background:ea.includes(t)?"var(--accent-subtle)":"var(--bg-elevated)",color:ea.includes(t)?"var(--accent)":"var(--text-primary)"},children:e},t))})]})]}),(0,n.jsxs)("div",{style:{borderTop:"1px solid var(--border-subtle)",paddingTop:12},children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-secondary)",textTransform:"uppercase",letterSpacing:"0.04em",marginBottom:6},children:"2. Compare against"}),(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[{value:"rolling",label:"Previous period, same year",hint:ed?1===ea.length?"vs ".concat(E.gg[(ea[0]+11)%12]):"vs the immediately preceding period":"Not available for this selection",disabled:!ed},{value:"yoy",label:"Same period, previous year",hint:"vs the equivalent months last FY",disabled:!1},{value:"none",label:"No comparison",hint:"Just show this periodâs values",disabled:!1}].map(e=>{let t=i.comparisonMode===e.value;return(0,n.jsxs)("button",{type:"button",disabled:e.disabled,onClick:()=>o(i.id,{comparisonMode:e.value}),style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:10,textAlign:"left",padding:"var(--space-2) var(--space-3)",borderRadius:"var(--radius-sm)",fontFamily:"var(--font-sans)",cursor:e.disabled?"not-allowed":"pointer",opacity:e.disabled?.5:1,border:"1px solid ".concat(t?"var(--accent)":"var(--border-subtle)"),background:t?"var(--accent-subtle)":"var(--bg-elevated)"},children:[(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)"},children:[(0,n.jsx)("span",{style:{width:14,height:14,borderRadius:"50%",flexShrink:0,border:"1.5px solid ".concat(t?"var(--accent)":"var(--text-tertiary)"),display:"flex",alignItems:"center",justifyContent:"center"},children:t&&(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:"var(--accent)"}})}),(0,n.jsx)("span",{style:{fontSize:12,fontWeight:500,color:t?"var(--accent)":"var(--text-primary)"},children:e.label})]}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-tertiary)",whiteSpace:"nowrap"},children:e.hint})]},e.value)})}),"yoy"===i.comparisonMode&&(()=>{let e=Math.max(0,E.jH.length-1-i.fyIndex);return(0,n.jsx)("div",{style:{marginTop:8,paddingLeft:4},children:0===e?(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-tertiary)"},children:"No prior year available for this financial year."}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-tertiary)",marginBottom:4},children:"Average across how many previous years?"}),(0,n.jsx)("div",{style:{display:"flex",gap:"var(--space-1)"},children:Array.from({length:e},(e,t)=>t+1).map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>o(i.id,{trendYears:e}),style:{padding:"4px 10px",fontSize:11,borderRadius:"var(--radius-sm)",cursor:"pointer",fontFamily:"var(--font-sans)",border:"1px solid ".concat(i.trendYears===e?"var(--accent)":"var(--border-subtle)"),background:i.trendYears===e?"var(--accent-subtle)":"var(--bg-elevated)",color:i.trendYears===e?"var(--accent)":"var(--text-primary)"},children:[e," year",1===e?"":"s"]},e))})]})})})()]})]}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-secondary)",marginTop:10,padding:"6px 10px",background:"var(--bg-sunken)",borderRadius:"var(--radius-sm)"},children:eo.hasComparison?"Comparing against ".concat(eo.cmpLabel):"No comparison for this selection"})]})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap",marginBottom:8},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,background:"var(--bg-base)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",padding:"4px 10px",maxWidth:260,flex:1,minWidth:180},children:[(0,n.jsx)(k.Z,{size:11,color:"var(--text-tertiary)"}),(0,n.jsx)("input",{value:C,onChange:e=>z(e.target.value),placeholder:"Filter ".concat(eK?"facility":"metric"," rows shown belowâ¦"),style:{border:"none",background:"transparent",fontSize:11,outline:"none",width:"100%",color:"var(--text-primary)",fontFamily:"var(--font-sans)"}})]}),(0,n.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:"var(--space-1)",fontSize:11,color:"var(--text-secondary)",cursor:"pointer",whiteSpace:"nowrap"},children:[(0,n.jsx)("input",{type:"checkbox",checked:F,onChange:e=>D(e.target.checked)}),"Hide zero/empty rows"]})]})]}),J&&te&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap",fontSize:11,fontFamily:"var(--font-mono)",color:"var(--text-secondary)",background:"var(--bg-sunken)",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",padding:"var(--space-1) var(--space-2)",marginBottom:8},children:[(0,n.jsx)("span",{children:te}),tt&&(0,n.jsx)("span",{style:{color:"var(--text-tertiary)"},children:tt.text}),tt&&eH(tt.mf)&&(0,n.jsxs)("a",{href:eH(tt.mf),target:"_blank",rel:"noopener noreferrer",style:{marginLeft:"auto",display:"flex",alignItems:"center",gap:"var(--space-1)",color:"var(--accent)",fontFamily:"var(--font-sans)",whiteSpace:"nowrap"},children:["Open in Formula Tree",(0,n.jsx)(R.Z,{size:11})]})]}),(0,n.jsxs)("div",{style:{position:"relative"},children:[!d&&(0,n.jsxs)("div",{style:{position:"absolute",top:2,right:2,zIndex:4},children:[(0,n.jsx)("button",{type:"button",onClick:()=>_(e=>"column"===e?null:"column"),title:eK?"Add a column, right here":"Add a column (transposes the table so columns hold your fields)",style:{width:22,height:22,display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid var(--border-subtle)",borderRadius:"var(--radius-sm)",background:"var(--bg-elevated)",color:"var(--accent)",cursor:"pointer"},children:(0,n.jsx)(c.Z,{size:13})}),"column"===Q&&(0,n.jsx)(t0,{align:"right",search:Y,onSearchChange:q,alreadyIncluded:ex,onPickMetric:(e,t)=>eZ(e,"column",t),onPickBlank:e=>{eD("column",e),_(null),q("")},onClose:()=>{_(null),q("")}})]}),(0,n.jsx)("div",{style:{overflow:"auto",maxHeight:360},onKeyDown:function(e){var t;if(!J||!(e.metaKey||e.ctrlKey)||"c"!==e.key.toLowerCase())return;e.preventDefault();let r=Math.min(J.r1,J.r2),n=Math.max(J.r1,J.r2),l=Math.min(J.f1,J.f2),i=Math.max(J.f1,J.f2),o=[];for(let e=r;e<=n;e++){let t=eJ[e],r=[];for(let e=l;e<=i;e++)r.push(e8(t,e).text);o.push(r.join(" "))}null===(t=navigator.clipboard)||void 0===t||t.writeText(o.join("\n")).catch(()=>{})},tabIndex:0,children:(0,n.jsxs)("table",{style:{width:"100%",borderCollapse:"collapse",fontVariantNumeric:"tabular-nums"},children:[(0,n.jsxs)("thead",{children:[eK&&e1.length>0&&(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{style:{...e7,position:"sticky",left:0,top:0,zIndex:3}}),e1.map((e,t)=>(0,n.jsx)("th",{colSpan:e.colSpan,onClick:()=>eq(e.cat),style:{...e7,top:0,cursor:"pointer"},title:e.collapsed?"Expand ".concat(e.cat):"Collapse ".concat(e.cat),children:(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:"var(--space-1)"},children:[e.collapsed?(0,n.jsx)(M.Z,{size:11,color:"var(--text-tertiary)"}):(0,n.jsx)(S.Z,{size:11,color:"var(--text-tertiary)"}),e.cat]})},"".concat(e.cat,"-").concat(t)))]}),(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{style:{...e7,position:"sticky",left:0,top:e2?32:0,zIndex:3},children:eK?"Facility":"Metric"}),eK?e0.map((e,t)=>"collapsedGroup"===e.kind?(0,n.jsx)("th",{colSpan:1,onClick:()=>eq(e.cat),style:{...e7,top:e2?32:0,color:"var(--text-tertiary)",textAlign:"center",cursor:"pointer"},title:"Expand ".concat(e.cat," (").concat(e.hiddenCount," hidden)"),children:"â¯"},"collapsed-".concat(e.cat,"-").concat(t)):(0,n.jsx)("th",{colSpan:eX?3:1,style:{...e7,top:e2?32:0,overflow:"visible"},children:eG(eW[e.fieldIdx],!1)},eW[e.fieldIdx].id)):eL.map(e=>(0,n.jsx)("th",{colSpan:eX?3:1,style:{...e7,top:0,background:"Grand Total"===e?"var(--accent-subtle)":e7.background,color:"Grand Total"===e?"var(--accent)":void 0},children:e},e))]}),eX&&(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{style:{...e7,position:"sticky",left:0,top:(e2?32:0)+32,zIndex:3}}),e3.map((e,t)=>(0,n.jsx)("th",{style:{...e7,top:(e2?32:0)+32,fontWeight:500,fontSize:10},children:"collapsedGroup"===e.kind?"":0===e.sub?"Value":1===e.sub?"Comparison":"Deviation"},t))]})]}),(0,n.jsxs)("tbody",{children:[eK?0===eJ.length?(0,n.jsx)("tr",{children:(0,n.jsx)("td",{colSpan:e3.length+1,style:{padding:16,textAlign:"center",color:"var(--text-tertiary)",fontSize:12},children:"No rows match this search."})}):eJ.map((e,t)=>e9(e,t)):(()=>{let e=new Set(eJ),t=0,r=[];for(let l of e6){let i=l.members.filter(t=>e.has(t)),o=K.has(l.cat);if(o||0!==i.length)for(let e of(r.push((0,n.jsx)("tr",{children:(0,n.jsx)("td",{colSpan:e3.length+1,onClick:()=>eq(l.cat),style:{cursor:"pointer",background:"var(--bg-sunken)",borderBottom:"1px solid var(--border-subtle)",padding:"5px 10px"},children:(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:11,fontWeight:600},children:[o?(0,n.jsx)(M.Z,{size:12,color:"var(--text-tertiary)"}):(0,n.jsx)(S.Z,{size:12,color:"var(--text-tertiary)"}),l.cat,(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text-tertiary)",fontWeight:400,fontSize:10},children:l.members.length})]})})}
1,"grp-".concat(l.cat))),i))r.push(e9(e,t)),t++}return 0===r.length?(0,n.jsx)("tr",{children:(0,n.jsx)("td",{colSpan:e3.length+1,style:{padding:16,textAlign:"center",color:"var(--text-tertiary)",fontSize:12},children:"No rows match this search."})}):r})(),!d&&(0,n.jsx)("tr",{children:(0,n.jsx)("td",{colSpan:e3.length+1,style:{padding:0,borderTop:"1px dashed var(--border-subtle)"},children:(0,n.jsxs)("div",{style:{position:"relative"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>_(e=>"row"===e?null:"row"),title:eK?"Adding a row transposes the table so rows hold your fields":void 0,style:{display:"flex",alignItems:"center",gap:"var(--space-1)",fontSize:11,width:"100%",textAlign:"left",cursor:"pointer",color:"var(--accent)",padding:"6px 10px",background:"none",border:"none",fontFamily:"var(--font-sans)"},children:[(0,n.jsx)(c.Z,{size:12})," Add a row"]}),"row"===Q&&(0,n.jsx)(t0,{search:Y,onSearchChange:q,alreadyIncluded:ex,onPickMetric:(e,t)=>eZ(e,"row",t),onPickBlank:e=>{eD("row",e),_(null),q("")},onClose:()=>{_(null),q("")}})]})})})]})]})})]}
1),!d&&(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-tertiary)",marginTop:6},children:"Grand Total always reflects the whole org, computed independently of the Facility field above. Click a cell, or click-drag / Shift-click for a range, then Cmd/Ctrl+C to copy - Smart Table cells are computed, so paste is disabled."})]})]})}},72912:function(e,t,r){"use strict";function n(e){let t="",r=e+1;for(;r>0;)t=String.fromCharCode(65+(r-1)%26)+t,r=Math.floor((r-1)/26);return t}function l(e){let t=e.toUpperCase().match(/^([A-Z]+)(\d+)$/);return t?{col:function(e){let t=0;for(let r of e.toUpperCase())t=26*t+(r.charCodeAt(0)-64);return t-1}(t[1]),row:parseInt(t[2],10)-1}:null}function i(e){return"".concat(n(e.col)).concat(e.row+1)}function o(e,t){return t||(null==e?"":Math.abs(e)>=1e3?e.toLocaleString("en-IN",{maximumFractionDigits:2}):1>Math.abs(e)&&0!==e?e.toFixed(3):e.toLocaleString("en-IN",{maximumFractionDigits:3}))}r.d(t,{Bj:function(){return function e(t,r){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:new Set;if(n>24)return{value:null,error:"#DEPTH"};if(o.has(t))return{value:null,error:"#CIRCULAR"};let a=r[t];if(!a)return{value:null};if(a.formula){o.add(t);try{return{value:function t(r,n,o,a){let s=r.trim(),d=0;for(;d++<30;){let r;let d=s.match(/(SUM|AVG|MIN|MAX|ROUND)\s*\(([^()]*)\)/i);if(!d)break;let c=d[1].toUpperCase(),u=d[2];if("ROUND"===c){let e=u.split(",").map(e=>e.trim());if(2!==e.length)throw Error("#ARGS");let l=t(e[0],n,o+1,a),i=Math.pow(10,Math.round(t(e[1],n,o+1,a)));r=Math.round(l*i)/i}else{let t=u.match(/^([A-Za-z]+\d+):([A-Za-z]+\d+)$/),s=t?function(e,t){let r=l(e),n=l(t);if(!r||!n)return[];let o=[];for(let e=Math.min(r.row,n.row);e<=Math.max(r.row,n.row);e++)for(let t=Math.min(r.col,n.col);t<=Math.max(r.col,n.col);t++)o.push(i({col:t,row:e}));return o}(t[1],t[2]):u.split(",").map(e=>e.trim()),d=[];for(let t of s)if(/^[A-Z]+\d+$/i.test(t)){let r=e(t.toUpperCase(),n,o+1,a);null!=r.value&&d.push(r.value)}else{let e=Number(t);isNaN(e)||d.push(e)}r=0===d.length?0:"SUM"===c?d.reduce((e,t)=>e+t,0):"AVG"===c?d.reduce((e,t)=>e+t,0)/d.length:"MIN"===c?Math.min(...d):Math.max(...d)}s=s.slice(0,d.index)+String(r)+s.slice(d.index+d[0].length)}if(s=s.replace(/[A-Z]+\d+/gi,t=>{var r;return String(null!==(r=e(t.toUpperCase(),n,o+1,a).value)&&void 0!==r?r:0)}),!/^[\d+\-*/().\s]+$/.test(s))throw Error("#PARSE");try{let e=Function('"use strict"; return ('.concat(s,")"))();if("number"!=typeof e||isNaN(e))throw Error("#NAN");return e}catch(e){throw Error("#PARSE")}}(a.formula.replace(/^=/,""),r,n+1,new Set(o))}}catch(e){return{value:null,error:e.message}}finally{o.delete(t)}}if(null==a.value||""===a.value)return{value:null};let s=Number(a.value);return{value:isNaN(s)?null:s}}},PM:function(){return l},Qk:function(){return i},hK:function(){return o},nP:function(){return n}})},46297:function(e,t,r){"use strict";r.d(t,{Bj:function(){return function e(t,r){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:new Set;if(a>24)return{value:null,error:"#DEPTH"};if(s.has(t))return{value:null,error:"#CIRCULAR"};let d=r[t];if(!d)return{value:null};if(d.formula){s.add(t);try{return{value:function t(r,a,s,d){let c=r.trim(),u=0;for(;u++<100;){let r;let u=c.match(/([A-Za-z][A-Za-z0-9]*)\s*\(([^()]*)\)/);if(!u)break;let p=u[1].toUpperCase(),f=u[2],v=""===f.trim()?[]:f.split(",").map(e=>e.trim());if("ROUND"===p){if(v.length<1||v.length>2)throw Error("#ARGS");let e=t(v[0],a,s+1,d),n=Math.pow(10,null!=v[1]?Math.round(t(v[1],a,s+1,d)):0);r=Math.round(e*n)/n}else if("LOG"===p){if(1===v.length)r=Math.log10(t(v[0],a,s+1,d));else if(2===v.length)r=Math.log(t(v[0],a,s+1,d))/Math.log(t(v[1],a,s+1,d));else throw Error("#ARGS")}else if(l.has(p)){let l=[];for(let r of v){let i=r.match(/^([A-Za-z]+\d+):([A-Za-z]+\d+)$/);if(i)for(let t of function(e,t){let r=(0,n.PM)(e),l=(0,n.PM)(t);if(!r||!l)return[];let i=[];for(let e=Math.min(r.row,l.row);e<=Math.max(r.row,l.row);e++)for(let t=Math.min(r.col,l.col);t<=Math.max(r.col,l.col);t++)i.push((0,n.Qk)({col:t,row:e}));return i}(i[1],i[2])){let r=e(t.toUpperCase(),a,s+1,d);if(r.error)throw Error(r.error);null!=r.value&&l.push(r.value)}else{let e=t(r,a,s+1,d);isNaN(e)||l.push(e)}}r=function(e,t){if(0===t.length)return 0;switch(e){case"SUM":return t.reduce((e,t)=>
1e+t,0);case"AVG":case"AVERAGE":return t.reduce((e,t)=>e+t,0)/t.length;case"MIN":return Math.min(...t);case"MAX":return Math.max(...t);case"COUNT":return t.length;case"PRODUCT":return t.reduce((e,t)=>e*t,1);case"MEDIAN":{let e=[...t].sort((e,t)=>e-t),r=Math.floor(e.length/2);return e.length%2?e[r]:(e[r-1]+e[r])/2}default:return 0}}(p,l)}else if(p in o){if(2!==v.length)throw Error("#ARGS");r=o[p](t(v[0],a,s+1,d),t(v[1],a,s+1,d))}else if(p in i){if(1!==v.length)throw Error("#ARGS");r=i[p](t(v[0],a,s+1,d))}else throw Error("#NAME");if(!isFinite(r))throw Error("#NUM");c=c.slice(0,u.index)+String(r)+c.slice(u.index+u[0].length)}if(c=c.replace(/[A-Z]+\d+/gi,t=>{var r;let n=e(t.toUpperCase(),a,s+1,d);if(n.error)throw Error(n.error);return"(".concat(null!==(r=n.value)&&void 0!==r?r:0,")")}),!/^[\d+\-*/().\s]+$/.test(c))throw Error("#PARSE");try{let e=Function('"use strict"; return ('.concat(c,")"))();if("number"!=typeof e||isNaN(e))throw Error("#NAN");return e}catch(e){throw Error("#PARSE")}}(d.formula.replace(/^=/,""),r,a+1,new Set(s))}}catch(e){return{value:null,error:e.message}}finally{s.delete(t)}}if(null==d.value||""===d.value)return{value:null};let c=Number(d.value);return{value:isNaN(c)?null:c}}},PM:function(){return n.PM},Qk:function(){return n.Qk},hK:function(){return n.hK},kR:function(){return a},nP:function(){return n.nP}});var n=r(72912);let l=new Set(["SUM","AVG","AVERAGE","MIN","MAX","COUNT","PRODUCT","MEDIAN"]),i={ABS:Math.abs,SQRT:Math.sqrt,CBRT:Math.cbrt,FLOOR:Math.floor,CEIL:Math.ceil,TRUNC:Math.trunc,SIGN:Math.sign,EXP:Math.exp,LN:Math.log,LOG10:Math.log10,LOG2:Math.log2,SIN:Math.sin,COS:Math.cos,TAN:Math.tan,ASIN:Math.asin,ACOS:Math.acos,ATAN:Math.atan,SINH:Math.sinh,COSH:Math.cosh,TANH:Math.tanh},o={POW:Math.pow,ATAN2:Math.atan2,HYPOT:Math.hypot,MOD:(e,t)=>e%t,ADD:(e,t)=>e+t,SUB:(e,t)=>e-t,MUL:(e,t)=>e*t,MULT:(e,t)=>e*t,MULTIPLY:(e,t)=>e*t,DIV:(e,t)=>e/t,DIVIDE:(e,t)=>e/t},a=[{group:"Aggregate",fns:[{name:"SUM",insert:"SUM()",hint:"SUM(A1:E1) â add a range or list"},{name:"AVG",insert:"AVG()",hint:"AVG(A1:E1) â average"},{name:"MIN",insert:"MIN()",hint:"MIN(A1:E1) â smallest"},{name:"MAX",insert:"MAX()",hint:"MAX(A1:E1) â largest"},{name:"COUNT",insert:"COUNT()",hint:"COUNT(A1:E1) â how many numbers"}]},{group:"Arithmetic",fns:[{name:"ADD",insert:"ADD(,)",hint:"ADD(E,F) = E+F"},{name:"SUB",insert:"SUB(,)",hint:"SUB(E,F) = EâF"},{name:"MULT",insert:"MULT(,)",hint:"MULT(E,F) = E\xd7F"},{name:"DIVIDE",insert:"DIVIDE(,)",hint:"DIVIDE(E,F) = E\xf7F"}]},{group:"Rounding",fns:[{name:"ROUND",insert:"ROUND(,2)",hint:"ROUND(E/F, 2) â round to N decimals"},{name:"FLOOR",insert:"FLOOR()",hint:"FLOOR(E) â round down"},{name:"CEIL",insert:"CEIL()",hint:"CEIL(E) â round up"},{name:"ABS",insert:"ABS()",hint:"ABS(E) â absolute value"},{name:"SQRT",insert:"SQRT()",hint:"SQRT(E) â square root"}]}]}}]);
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.