1import{a as N,j as e,b as ft}from"./vendor-query-vPUuyXgA.js";import{P as yt,G as vt}from"./PageLayout-BBJPaOB1.js";import{c as bt,Q as z,V as Ie,F as $e,S as le,D as Z,T as re,q as Oe,U as ke,k as se,L as jt,j as Ue,t as Ve,g as De,X as _e,P as Qe,a2 as Ct,a5 as Nt,u as kt,W as St}from"./main-BS4kmGeo.js";import{D as _,g as ce}from"./timezone-utils-DlE61dgc.js";import{D as wt}from"./download-C1LdXia6.js";import{F as Rt}from"./file-spreadsheet-DGlBnmiO.js";import{A as F}from"./api-client-QA1cgNpJ.js";import{R as Se,A as Tt,L as Pt,C as qe,X as Ye,Y as Ge,T as we,a as $t,b as Dt,P as At,c as Lt,d as Ze,e as Ft,B as Ht,f as Wt}from"./vendor-charts-DGg6uklE.js";import{p as X,e as J}from"./exportToCSV-Cxci6gu4.js";import{E as Et}from"./jspdf.es.min-Yi0kPi9a.js";import{C as Re}from"./circle-alert-CK810ORF.js";import{R as ie}from"./rotate-ccw-BVuZpnKu.js";import{C as Ae}from"./chevron-up-CMljyQGw.js";import{L as Bt}from"./layers-De1SBZg9.js";import{U as Xe}from"./user-check-CQ-2eAxU.js";import{U as Je}from"./user-plus-CHAVQKrj.js";import{C as be}from"./circle-x-DXYHX12F.js";import{C as Mt}from"./chart-pie-CXdmSFvl.js";import{T as zt}from"./timer-CGowHrEy.js";import{R as Kt}from"./receipt-BRMxX37J.js";import{B as et}from"./banknote-BFG3ILvL.js";import{M as It}from"./message-circle-BVKDXLdx.js";import{L as Ot}from"./layout-dashboard-3kkmDIby.js";import{B as Ut}from"./briefcase-Ch2J3Lzj.js";import{W as Vt}from"./wallet-Cotzq0dT.js";import{T as _t}from"./triangle-alert-D0sNd4g-.js";import"./vendor-calendar-CPw2sWKN.js";import"./vendor-stripe-CRFGIoF7.js";import"./vendor-react-C0fns3RT.js";import"./gem-yKBi_i-w.js";import"./settings-zy6vZBeP.js";import"./link-BkNVk6Pq.js";import"./building-2-C1ww0-cr.js";import"./vendor-motion-UJclNK9x.js";import"./base-api-Cde4knEY.js";import"./timezone-constants-3HcCGWTp.js";/** 2 * @license lucide-react v0.552.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const Qt=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M16 8h-6a2 2 0 1 0 0 4h4a2 2 0 1 1 0 4H8",key:"1h4pet"}],["path",{d:"M12 18V6",key:"zqpxq5"}]],qt=bt("circle-dollar-sign",Qt);function Yt({value:a,onChange:t}){const{primaryColor:n,darkMode:s}=z(),r=localStorage.getItem("businessTimezone")||_,[i,l]=N.useState(a.preset==="custom"),c=[{value:"today",label:"Today"},{value:"yesterday",label:"Yesterday"},{value:"last7days",label:"Last 7 Days"},{value:"last30days",label:"Last 30 Days"},{value:"thisWeek",label:"This Week"},{value:"lastWeek",label:"Last Week"},{value:"thisMonth",label:"This Month"},{value:"lastMonth",label:"Last Month"},{value:"thisQuarter",label:"This Quarter"},{value:"lastQuarter",label:"Last Quarter"},{value:"yearToDate",label:"Year to Date"},{value:"custom",label:"Custom Range"}],u=d=>{d==="custom"?(l(!0),t({preset:d,from:a.from,to:a.to})):(l(!1),t({preset:d}))},o=(d,g)=>{const[p,y,x]=g.split("-").map(Number),v=new Date(Date.UTC(p,y-1,x,12,0,0));t({preset:"custom",from:d==="from"?v:a.from,to:d==="to"?v:a.to})};return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:c.map(d=>e.jsx("button",{onClick:()=>u(d.value),className:`px-4 py-2 rounded-lg text-sm font-medium transition-colors shadow-sm ${a.preset===d.value?"text-white":s?"bg-gray-700 text-gray-300 hover:bg-gray-600":"bg-gray-100 text-gray-700 hover:bg-gray-200"}`,style:{backgroundColor:a.preset===d.value?n:void 0},children:d.label},d.value))}),i&&e.jsxs("div",{className:`flex gap-3 items-center p-4 rounded-lg ${s?"bg-gray-700":"bg-gray-50"}`,children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{className:`block text-xs font-medium mb-1 ${s?"text-gray-300":"text-gray-700"}`,children:"From"}),e.jsx("input",{type:"date",value:a.from?ce(a.from,r):"",onChange:d=>o("from",d.target.value),className:`w-full px-3 py-2 border rounded-md focus:ring-2 focus:outline-none ${s?"bg-gray-800 border-gray-600 text-gray-200":"bg-white border-gray-300 text-gray-900"}`})]}),e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{className:`block text-xs font-medium mb-1 ${s?"text-gray-300":"text-gray-700"}`,children:"To"}
6),e.jsx("input",{type:"date",value:a.to?ce(a.to,r):"",onChange:d=>o("to",d.target.value),className:`w-full px-3 py-2 border rounded-md focus:ring-2 focus:outline-none ${s?"bg-gray-800 border-gray-600 text-gray-200":"bg-white border-gray-300 text-gray-900"}`})]})]})]})}function ae({onExport:a,disabled:t=!1}){const{primaryColor:n,darkMode:s}=z(),[r,i]=N.useState(!1),l=N.useRef(null);N.useEffect(()=>{const u=o=>{l.current&&!l.current.contains(o.target)&&i(!1)};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[]);const c=u=>{a(u),i(!1)};return e.jsxs("div",{className:"relative",ref:l,children:[e.jsxs("button",{onClick:()=>i(!r),disabled:t,className:`inline-flex items-center gap-2 px-4 py-2 rounded-lg font-medium transition-colors shadow-sm ${t?`${s?"bg-gray-700":"bg-gray-100"} text-gray-400 cursor-not-allowed`:`text-white ${s?"hover:opacity-90":""}`}`,style:{backgroundColor:t?void 0:n},children:[e.jsx(wt,{className:"w-4 h-4",strokeWidth:2}),e.jsx("span",{children:"Export"}),e.jsx(Ie,{className:"w-3 h-3",strokeWidth:2})]}),r&&e.jsxs("div",{className:`absolute right-0 mt-2 w-48 rounded-lg shadow-lg border py-1 z-10 ${s?"bg-gray-800 border-gray-700":"bg-white border-gray-200"}`,children:[e.jsxs("button",{onClick:()=>c("csv"),className:`w-full text-left px-4 py-2 text-sm flex items-center gap-3 ${s?"text-gray-300 hover:bg-gray-700":"text-gray-700 hover:bg-gray-100"}`,children:[e.jsx($e,{className:"w-4 h-4",strokeWidth:2}),e.jsx("span",{children:"Export as CSV"})]}),e.jsxs("button",{onClick:()=>c("pdf"),className:`w-full text-left px-4 py-2 text-sm flex items-center gap-3 ${s?"text-gray-300 hover:bg-gray-700":"text-gray-700 hover:bg-gray-100"}`,children:[e.jsx($e,{className:"w-4 h-4",strokeWidth:2}),e.jsx("span",{children:"Export as PDF"})]}),e.jsxs("button",{onClick:()=>c("excel"),className:`w-full text-left px-4 py-2 text-sm flex items-center gap-3 ${s?"text-gray-300 hover:bg-gray-700":"text-gray-700 hover:bg-gray-100"}`,children:[e.jsx(Rt,{className:"w-4 h-4",strokeWidth:2}),e.jsx("span",{children:"Export as Excel"})]})]})]})}function B(a,t){const[n,s]=N.useState(null),[r,i]=N.useState(!1),[l,c]=N.useState(null),u=N.useRef(a);u.current=a;const o=N.useRef(t.onError);o.current=t.onError;const d=N.useCallback(async()=>{try{i(!0),c(null);const g=localStorage.getItem("accessToken");if(!g)throw new Error("No access token found");const p=await u.current(t.dateFrom,t.dateTo,g);s(p)}catch(g){const p=g instanceof Error?g:new Error("Failed to load report");c(p),o.current&&o.current(p)}finally{i(!1)}},[t.dateFrom,t.dateTo]);return N.useEffect(()=>{d()},[d,t.locationId]),{data:n,loading:r,error:l,reload:d}}function ge(a,t=_){const n=ce(new Date,t),[s,r,i]=n.split("-").map(Number),l=(d,g,p)=>new Date(Date.UTC(d,g-1,p,12,0,0)),c=l(s,r,i);let u,o;switch(a){case"today":{u=c,o=c;break}case"yesterday":{const d=l(s,r,i-1);u=d,o=d;break}case"last7days":{u=l(s,r,i-6),o=c;break}case"last30days":{u=l(s,r,i-29),o=c;break}case"thisWeek":{const d=c.getUTCDay();u=l(s,r,i-d),o=c;break}case"lastWeek":{const d=c.getUTCDay(),g=l(s,r,i-d-1);u=l(s,r,i-d-7),o=g;break}case"thisMonth":{u=l(s,r,1),o=c;break}case"lastMonth":{u=l(s,r-1,1),o=l(s,r,0);break}case"thisQuarter":{const g=(Math.ceil(r/3)-1)*3+1;u=l(s,g,1),o=c;break}case"lastQuarter":{const d=Math.ceil(r/3),g=d===1?4:d-1,p=d===1?s-1:s,y=(g-1)*3+1,x=g*3;u=l(p,y,1),o=l(p,x+1,0);break}case"yearToDate":{u=l(s,1,1),o=c;break}default:{u=l(s,r,i-29),o=c;break}}return{from:u,to:o}}function j(a){return`$${(a/100).toFixed(2)}`}function Y(a,t=1){return`${a.toFixed(t)}%`}function $({title:a,subtitle:t,children:n,action:s,className:r=""}){const{darkMode:i}=z();return e.jsxs("div",{className:`rounded-lg shadow ${i?"bg-gray-800":"bg-white"} ${r}`,children:[e.jsx("div",{className:`px-6 py-4 border-b ${i?"border-gray-700":"border-gray-200"}`,children:e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx("h3",{className:`text-lg font-semibold ${i?"text-gray-100":"text-gray-900"}`,children:a}),t&&e.jsx("p",{className:`text-sm mt-1 ${i?"text-gray-400":"text-gray-600"}`,children:t})]}),s&&e.jsx("div",{children:s})]})}),e.jsx("div",{className:"p-6",children:n})]})}function R({label:a,value:t,change:n,trend:s,subtitle:r,icon:i,color:l="blue",useThemeColor:c=!1}){const{primaryColor:u,darkMode:o,iconColor:d}=z(),g={blue:"text-blue-600 bg-blue-50",green:"text-green-600 bg-green-50",purple:"text-purple-600 bg-purple-50",orange:"text-orange-600 bg-orange-50",red:"text-red-600 bg-red-50"},p={up:"text-green-600",down:"text-red-600",flat:"text-gray-600"},y={up:"â",down:"â",flat:"â"},x=c?{backgroundColor:`${u}
615`}:void 0,v=c?{color:u}:void 0,C=c?{color:d}:void 0;return e.jsxs("div",{className:`rounded-lg shadow p-6 hover:shadow-md transition-shadow ${o?"bg-gray-800 text-gray-100":"bg-white"}`,children:[i&&e.jsx("div",{className:`inline-flex p-3 rounded-lg mb-3 ${c?"":g[l]}`,style:x,children:ft.createElement(i,{className:"w-6 h-6",strokeWidth:2,style:C})}),e.jsx("div",{className:`text-sm font-medium mb-1 ${o?"text-gray-400":"text-gray-600"}`,children:a}),e.jsx("div",{className:`text-3xl font-bold ${c?"":g[l].split(" ")[0]}`,style:v,children:t}),(n!==void 0||r)&&e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[n!==void 0&&s&&e.jsxs("span",{className:`text-sm font-medium ${p[s]} flex items-center gap-1`,children:[e.jsx("span",{children:y[s]}),e.jsxs("span",{children:[Math.abs(n),"%"]})]}),r&&e.jsx("span",{className:"text-xs text-gray-500",children:r})]})]})}function tt({data:a,type:t="area",height:n=300,showGrid:s=!0,formatCurrency:r=i=>`$${(i/100).toFixed(0)}`}){const i=({active:u,payload:o})=>u&&o&&o.length?e.jsxs("div",{className:"bg-white p-3 border border-gray-200 rounded-lg shadow-lg",children:[e.jsx("p",{className:"text-sm font-medium text-gray-900",children:o[0].payload.label||o[0].payload.date}),e.jsx("p",{className:"text-lg font-bold text-blue-600 mt-1",children:r(o[0].value)})]}):null,l=t==="area"?Tt:Pt,c=t==="area"?$t:Dt;return e.jsx(Se,{width:"100%",height:n,children:e.jsxs(l,{data:a,children:[s&&e.jsx(qe,{strokeDasharray:"3 3",stroke:"#e5e7eb"}),e.jsx(Ye,{dataKey:"date",stroke:"#6b7280",tick:{fontSize:12},tickFormatter:u=>{const o=localStorage.getItem("businessTimezone")||_;return new Date(u).toLocaleDateString("en-US",{month:"short",day:"numeric",timeZone:o})}}),e.jsx(Ge,{stroke:"#6b7280",tick:{fontSize:12},tickFormatter:u=>r(u)}),e.jsx(we,{content:e.jsx(i,{})}),e.jsx(c,{type:"monotone",dataKey:"revenue",stroke:"#3b82f6",fill:"#3b82f6",fillOpacity:t==="area"?.2:1,strokeWidth:2})]})})}function Te({data:a,height:t=300,showLegend:n=!0,showLabels:s=!0,innerRadius:r=0,formatValue:i=l=>String(l)}){const{primaryColor:l,darkMode:c}=z(),u=[l,"#10b981","#8b5cf6","#f59e0b","#ef4444","#ec4899","#06b6d4","#84cc16"],o=({active:d,payload:g})=>{if(d&&g&&g.length){const p=a.reduce((x,v)=>x+v.value,0),y=(g[0].value/p*100).toFixed(1);return e.jsxs("div",{className:`p-3 border rounded-lg shadow-lg ${c?"bg-gray-800 border-gray-700":"bg-white border-gray-200"}`,children:[e.jsx("p",{className:`text-sm font-medium ${c?"text-gray-200":"text-gray-900"}`,children:g[0].name}),e.jsx("p",{className:"text-lg font-bold mt-1",style:{color:l},children:i(g[0].value)}),e.jsxs("p",{className:`text-xs mt-1 ${c?"text-gray-400":"text-gray-500"}`,children:[y,"% of total"]})]})}return null};return e.jsx(Se,{width:"100%",height:t,children:e.jsxs(At,{children:[e.jsx(Lt,{data:a,cx:"50%",cy:"50%",innerRadius:r,outerRadius:80,fill:"#8884d8",dataKey:"value",label:s?(d=>d.name&&d.percent?`${d.name} ${(d.percent*100).toFixed(0)}%`:""):!1,labelLine:s,children:a.map((d,g)=>e.jsx(Ze,{fill:d.color||u[g%u.length]},`cell-${g}`))}),e.jsx(we,{content:e.jsx(o,{})}),n&&e.jsx(Ft,{wrapperStyle:{color:c?"#d1d5db":"#374151"}})]})})}function M({columns:a,data:t,keyExtractor:n,emptyMessage:s="No data available"}){const{darkMode:r}=z(),[i,l]=N.useState(null),c=o=>{l(d=>(d==null?void 0:d.key)===o?d.direction==="asc"?{key:o,direction:"desc"}:null:{key:o,direction:"asc"})},u=[...t].sort((o,d)=>{if(!i)return 0;const g=o[i.key],p=d[i.key];if(g===p)return 0;const y=g>p?1:-1;return i.direction==="asc"?y:-y});return t.length===0?e.jsx("div",{className:`text-center py-12 ${r?"text-gray-400":"text-gray-500"}`,children:e.jsx("p",{children:s})}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:`min-w-full divide-y ${r?"divide-gray-700":"divide-gray-200"}`,children:[e.jsx("thead",{className:r?"bg-gray-700":"bg-gray-50",children:e.jsx("tr",{children:a.map(o=>e.jsx("th",{className:`px-6 py-3 text-xs font-medium uppercase tracking-wider ${r?"text-gray-300":"text-gray-500"} ${o.align==="right"?"text-right":o.align==="center"?"text-center":"text-left"} ${o.sortable!==!1?`cursor-pointer ${r?"hover:bg-gray-600":"hover:bg-gray-100"}`:""}`,onClick:()=>o.sortable!==!1&&c(String(o.key)),children:e.jsxs("div",{className:"flex items-center gap-2 justify-between",children:[e.jsx("span",{children:o.label}),o.sortable!==!1&&e.jsx("span",{className:r?"text-gray-500":"text-gray-400",children:(i==null?void 0:i.key)===o.key?i.direction==="asc"?"â
6":"â":"â"})]})},String(o.key)))})}),e.jsx("tbody",{className:`divide-y ${r?"bg-gray-800 divide-gray-700":"bg-white divide-gray-200"}`,children:u.map(o=>e.jsx("tr",{className:r?"hover:bg-gray-700":"hover:bg-gray-50",children:a.map(d=>e.jsx("td",{className:`px-6 py-4 whitespace-nowrap text-sm ${r?"text-gray-300":""} ${d.align==="right"?"text-right":d.align==="center"?"text-center":"text-left"}`,children:d.render?d.render(o):String(o[d.key]||"-")},String(d.key)))},n(o)))})]})})}function q({message:a="Loading...",size:t="md"}){const{primaryColor:n}=z(),s={sm:"h-6 w-6",md:"h-8 w-8",lg:"h-12 w-12"};return e.jsxs("div",{className:"flex flex-col items-center justify-center py-12",children:[e.jsx("div",{className:`${s[t]} animate-spin rounded-full border-4 border-solid border-r-transparent`,style:{borderColor:n,borderRightColor:"transparent"}}),a&&e.jsx("p",{className:"mt-4 text-gray-600 text-sm",children:a})]})}function at(a,t,n,s,r){s=s||{};var i=1.15,l=r.internal.scaleFactor,c=r.internal.getFontSize()/l,u=r.getLineHeightFactor?r.getLineHeightFactor():i,o=c*u,d=/\r\n|\r|\n/g,g="",p=1;if((s.valign==="middle"||s.valign==="bottom"||s.halign==="center"||s.halign==="right")&&(g=typeof a=="string"?a.split(d):a,p=g.length||1),n+=c*(2-i),s.valign==="middle"?n-=p/2*o:s.valign==="bottom"&&(n-=p*o),s.halign==="center"||s.halign==="right"){var y=c;if(s.halign==="center"&&(y*=.5),g&&p>=1){for(var x=0;x<g.length;x++)r.text(g[x],t-r.getStringUnitWidth(g[x])*y,n),n+=o;return r}t-=r.getStringUnitWidth(a)*y}return s.halign==="justify"?r.text(a,t,n,{maxWidth:s.maxWidth||100,align:"justify"}):r.text(a,t,n),r}var Le={},oe=(function(){function a(t){this.jsPDFDocument=t,this.userStyles={textColor:t.getTextColor?this.jsPDFDocument.getTextColor():0,fontSize:t.internal.getFontSize(),fontStyle:t.internal.getFont().fontStyle,font:t.internal.getFont().fontName,lineWidth:t.getLineWidth?this.jsPDFDocument.getLineWidth():0,lineColor:t.getDrawColor?this.jsPDFDocument.getDrawColor():0}}return a.setDefaults=function(t,n){n===void 0&&(n=null),n?n.__autoTableDocumentDefaults=t:Le=t},a.unifyColor=function(t){return Array.isArray(t)?t:typeof t=="number"?[t,t,t]:typeof t=="string"?[t]:null},a.prototype.applyStyles=function(t,n){var s,r,i;n===void 0&&(n=!1),t.fontStyle&&this.jsPDFDocument.setFontStyle&&this.jsPDFDocument.setFontStyle(t.fontStyle);var l=this.jsPDFDocument.internal.getFont(),c=l.fontStyle,u=l.fontName;if(t.font&&(u=t.font),t.fontStyle){c=t.fontStyle;var o=this.getFontList()[u];o&&o.indexOf(c)===-1&&this.jsPDFDocument.setFontStyle&&(this.jsPDFDocument.setFontStyle(o[0]),c=o[0])}if(this.jsPDFDocument.setFont(u,c),t.fontSize&&this.jsPDFDocument.setFontSize(t.fontSize),!n){var d=a.unifyColor(t.fillColor);d&&(s=this.jsPDFDocument).setFillColor.apply(s,d),d=a.unifyColor(t.textColor),d&&(r=this.jsPDFDocument).setTextColor.apply(r,d),d=a.unifyColor(t.lineColor),d&&(i=this.jsPDFDocument).setDrawColor.apply(i,d),typeof t.lineWidth=="number"&&this.jsPDFDocument.setLineWidth(t.lineWidth)}},a.prototype.splitTextToSize=function(t,n,s){return this.jsPDFDocument.splitTextToSize(t,n,s)},a.prototype.rect=function(t,n,s,r,i){return this.jsPDFDocument.rect(t,n,s,r,i)},a.prototype.getLastAutoTable=function(){return this.jsPDFDocument.lastAutoTable||null},a.prototype.getTextWidth=function(t){return this.jsPDFDocument.getTextWidth(t)},a.prototype.getDocument=function(){return this.jsPDFDocument},a.prototype.setPage=function(t){this.jsPDFDocument.setPage(t)},a.prototype.addPage=function(){return this.jsPDFDocument.addPage()},a.prototype.getFontList=function(){return this.jsPDFDocument.getFontList()},a.prototype.getGlobalOptions=function(){return Le||{}},a.prototype.getDocumentOptions=function(){return this.jsPDFDocument.__autoTableDocumentDefaults||{}},a.prototype.pageSize=function(){var t=this.jsPDFDocument.internal.pageSize;return t.width==null&&(t={width:t.getWidth(),height:t.getHeight()}),t},a.prototype.scaleFactor=function(){return this.jsPDFDocument.internal.scaleFactor},a.prototype.getLineHeightFactor=function(){var t=this.jsPDFDocument;return t.getLineHeightFactor?t.getLineHeightFactor():1.15},a.prototype.getLineHeight=function(t){return t/this.scaleFactor()*this.getLineHeightFactor()},a.prototype.pageNumber=function(){var t=this.jsPDFDocument.internal.getCurrentPageInfo();return t?t.pageNumber:this.jsPDFDocument.internal.getNumberOfPages()},a})(),je=function(a,t){return je=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,s){n.__proto__=s}||function(n,s){for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(n[r]=s[r])},je(a,t)};function rt(a,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");je(a,t);function n(){this.constructor=a}
6a.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}var st=(function(a){rt(t,a);function t(n){var s=a.call(this)||this;return s._element=n,s}return t})(Array);function Gt(a){return{font:"helvetica",fontStyle:"normal",overflow:"linebreak",fillColor:!1,textColor:20,halign:"left",valign:"top",fontSize:10,cellPadding:5/a,lineColor:200,lineWidth:0,cellWidth:"auto",minCellHeight:0,minCellWidth:0}}function Zt(a){var t={striped:{table:{fillColor:255,textColor:80,fontStyle:"normal"},head:{textColor:255,fillColor:[41,128,185],fontStyle:"bold"},body:{},foot:{textColor:255,fillColor:[41,128,185],fontStyle:"bold"},alternateRow:{fillColor:245}},grid:{table:{fillColor:255,textColor:80,fontStyle:"normal",lineWidth:.1},head:{textColor:255,fillColor:[26,188,156],fontStyle:"bold",lineWidth:0},body:{},foot:{textColor:255,fillColor:[26,188,156],fontStyle:"bold",lineWidth:0},alternateRow:{}},plain:{head:{fontStyle:"bold"},foot:{fontStyle:"bold"}}};return t[a]}function he(a,t,n){n.applyStyles(t,!0);var s=Array.isArray(a)?a:[a],r=s.map(function(i){return n.getTextWidth(i)}).reduce(function(i,l){return Math.max(i,l)},0);return r}function nt(a,t,n,s){var r=t.settings.tableLineWidth,i=t.settings.tableLineColor;a.applyStyles({lineWidth:r,lineColor:i});var l=it(r,!1);l&&a.rect(n.x,n.y,t.getWidth(a.pageSize().width),s.y-n.y,l)}function it(a,t){var n=a>0,s=t||t===0;return n&&s?"DF":n?"S":s?"F":null}function xe(a,t){var n,s,r,i;if(a=a||t,Array.isArray(a)){if(a.length>=4)return{top:a[0],right:a[1],bottom:a[2],left:a[3]};if(a.length===3)return{top:a[0],right:a[1],bottom:a[2],left:a[1]};if(a.length===2)return{top:a[0],right:a[1],bottom:a[0],left:a[1]};a.length===1?a=a[0]:a=t}return typeof a=="object"?(typeof a.vertical=="number"&&(a.top=a.vertical,a.bottom=a.vertical),typeof a.horizontal=="number"&&(a.right=a.horizontal,a.left=a.horizontal),{left:(n=a.left)!==null&&n!==void 0?n:t,top:(s=a.top)!==null&&s!==void 0?s:t,right:(r=a.right)!==null&&r!==void 0?r:t,bottom:(i=a.bottom)!==null&&i!==void 0?i:t}):(typeof a!="number"&&(a=t),{top:a,right:a,bottom:a,left:a})}function ot(a,t){var n=xe(t.settings.margin,0);return a.pageSize().width-(n.left+n.right)}function Xt(a,t,n,s,r){var i={},l=1.3333333333333333,c=pe(t,function(h){return r.getComputedStyle(h).backgroundColor});c!=null&&(i.fillColor=c);var u=pe(t,function(h){return r.getComputedStyle(h).color});u!=null&&(i.textColor=u);var o=ea(s,n);o&&(i.cellPadding=o);var d="borderTopColor",g=l*n,p=s.borderTopWidth;
6if(s.borderBottomWidth===p&&s.borderRightWidth===p&&s.borderLeftWidth===p){var y=(parseFloat(p)||0)/g;y&&(i.lineWidth=y)}else i.lineWidth={top:(parseFloat(s.borderTopWidth)||0)/g,right:(parseFloat(s.borderRightWidth)||0)/g,bottom:(parseFloat(s.borderBottomWidth)||0)/g,left:(parseFloat(s.borderLeftWidth)||0)/g},i.lineWidth.top||(i.lineWidth.right?d="borderRightColor":i.lineWidth.bottom?d="borderBottomColor":i.lineWidth.left&&(d="borderLeftColor"));var x=pe(t,function(h){return r.getComputedStyle(h)[d]});x!=null&&(i.lineColor=x);var v=["left","right","center","justify"];v.indexOf(s.textAlign)!==-1&&(i.halign=s.textAlign),v=["middle","bottom","top"],v.indexOf(s.verticalAlign)!==-1&&(i.valign=s.verticalAlign);var C=parseInt(s.fontSize||"");isNaN(C)||(i.fontSize=C/l);var b=Jt(s);b&&(i.fontStyle=b);var T=(s.fontFamily||"").toLowerCase();return a.indexOf(T)!==-1&&(i.font=T),i}function Jt(a){var t="";return(a.fontWeight==="bold"||a.fontWeight==="bolder"||parseInt(a.fontWeight)>=700)&&(t="bold"),(a.fontStyle==="italic"||a.fontStyle==="oblique")&&(t+="italic"),t}function pe(a,t){var n=lt(a,t);if(!n)return null;var s=n.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d*\.?\d*))?\)$/);if(!s||!Array.isArray(s))return null;var r=[parseInt(s[1]),parseInt(s[2]),parseInt(s[3])],i=parseInt(s[4]);return i===0||isNaN(r[0])||isNaN(r[1])||isNaN(r[2])?null:r}function lt(a,t){var n=t(a);return n==="rgba(0, 0, 0, 0)"||n==="transparent"||n==="initial"||n==="inherit"?a.parentElement==null?null:lt(a.parentElement,t):n}function ea(a,t){var n=[a.paddingTop,a.paddingRight,a.paddingBottom,a.paddingLeft],s=96/(72/t),r=(parseInt(a.lineHeight)-parseInt(a.fontSize))/t/2,i=n.map(function(c){return parseInt(c||"0")/s}),l=xe(i,0);return r>l.top&&(l.top=r),r>l.bottom&&(l.bottom=r),l}function dt(a,t,n,s,r){var i,l;s===void 0&&(s=!1),r===void 0&&(r=!1);var c;typeof t=="string"?c=n.document.querySelector(t):c=t;var u=Object.keys(a.getFontList()),o=a.scaleFactor(),d=[],g=[],p=[];if(!c)return console.error("Html table could not be found with input: ",t),{head:d,body:g,foot:p};for(var y=0;y<c.rows.length;y++){var x=c.rows[y],v=(l=(i=x==null?void 0:x.parentElement)===null||i===void 0?void 0:i.tagName)===null||l===void 0?void 0:l.toLowerCase(),C=ta(u,o,n,x,s,r);C&&(v==="thead"?d.push(C):v==="tfoot"?p.push(C):g.push(C))}return{head:d,body:g,foot:p}}function ta(a,t,n,s,r,i){for(var l=new st(s),c=0;c<s.cells.length;c++){var u=s.cells[c],o=n.getComputedStyle(u);if(r||o.display!=="none"){var d=void 0;i&&(d=Xt(a,u,t,o,n)),l.push({rowSpan:u.rowSpan,colSpan:u.colSpan,styles:d,_element:u,content:aa(u)})}}var g=n.getComputedStyle(s);if(l.length>0&&(r||g.display!=="none"))return l}function aa(a){var t=a.cloneNode(!0);return t.innerHTML=t.innerHTML.replace(/\n/g,"").replace(/ +/g," "),t.innerHTML=t.innerHTML.split(/<br.*?>/).map(function(n){return n.trim()}).join(` 7`),t.innerText||t.textContent||""}function ra(a,t,n){for(var s=0,r=[a,t,n];s<r.length;s++){var i=r[s];i&&typeof i!="object"&&console.error("The options parameter should be of type object, is: "+typeof i),i.startY&&typeof i.startY!="number"&&(console.error("Invalid value for startY option",i.startY),delete i.startY)}}function G(a,t,n,s,r){if(a==null)throw new TypeError("Cannot convert undefined or null to object");for(var i=Object(a),l=1;l<arguments.length;l++){var c=arguments[l];if(c!=null)for(var u in c)Object.prototype.hasOwnProperty.call(c,u)&&(i[u]=c[u])}return i}function ct(a,t){var n=new oe(a),s=n.getDocumentOptions(),r=n.getGlobalOptions();ra(r,s,t);var i=G({},r,s,t),l;typeof window<"u"&&(l=window);var c=sa(r,s,t),u=na(r,s,t),o=ia(n,i),d=la(n,i,l);return{id:t.tableId,content:d,hooks:u,styles:c,settings:o}}function sa(a,t,n){for(var s={styles:{},headStyles:{},bodyStyles:{},footStyles:{},alternateRowStyles:{},columnStyles:{}},r=function(u){if(u==="columnStyles"){var o=a[u],d=t[u],g=n[u];s.columnStyles=G({},o,d,g)}else{var p=[a,t,n],y=p.map(function(x){return x[u]||{}});s[u]=G({},y[0],y[1],y[2])}},i=0,l=Object.keys(s);i<l.length;i++){var c=l[i];r(c)}return s}function na(a,t,n){for(var s=[a,t,n],r={didParseCell:[],willDrawCell:[],didDrawCell:[],willDrawPage:[],didDrawPage:[]},i=0,l=s;i<l.length;i++){var c=l[i];c.didParseCell&&r.didParseCell.push(c.didParseCell),c.willDrawCell&&r.willDrawCell.push(c.willDrawCell),c.didDrawCell&&r.didDrawCell.push(c.didDrawCell),c.willDrawPage&&r.willDrawPage.push(c.willDrawPage),c.didDrawPage&&r.didDrawPage.push(c.didDrawPage)}return r}function ia(a,t){var n,s,r,i,l,c,u,o,d,g,p,y,x=xe(t.margin,40/a.scaleFactor()),v=(n=oa(a,t.startY))!==null&&n!==void 0?n:x.top,C;
7t.showFoot===!0?C="everyPage":t.showFoot===!1?C="never":C=(s=t.showFoot)!==null&&s!==void 0?s:"everyPage";var b;t.showHead===!0?b="everyPage":t.showHead===!1?b="never":b=(r=t.showHead)!==null&&r!==void 0?r:"everyPage";var T=(i=t.useCss)!==null&&i!==void 0?i:!1,h=t.theme||(T?"plain":"striped"),f=!!t.horizontalPageBreak,S=(l=t.horizontalPageBreakRepeat)!==null&&l!==void 0?l:null;return{includeHiddenHtml:(c=t.includeHiddenHtml)!==null&&c!==void 0?c:!1,useCss:T,theme:h,startY:v,margin:x,pageBreak:(u=t.pageBreak)!==null&&u!==void 0?u:"auto",rowPageBreak:(o=t.rowPageBreak)!==null&&o!==void 0?o:"auto",tableWidth:(d=t.tableWidth)!==null&&d!==void 0?d:"auto",showHead:b,showFoot:C,tableLineWidth:(g=t.tableLineWidth)!==null&&g!==void 0?g:0,tableLineColor:(p=t.tableLineColor)!==null&&p!==void 0?p:200,horizontalPageBreak:f,horizontalPageBreakRepeat:S,horizontalPageBreakBehaviour:(y=t.horizontalPageBreakBehaviour)!==null&&y!==void 0?y:"afterAllRows"}}function oa(a,t){var n=a.getLastAutoTable(),s=a.scaleFactor(),r=a.pageNumber(),i=!1;if(n&&n.startPageNumber){var l=n.startPageNumber+n.pageNumber-1;i=l===r}return typeof t=="number"?t:(t==null||t===!1)&&i&&(n==null?void 0:n.finalY)!=null?n.finalY+20/s:null}function la(a,t,n){var s=t.head||[],r=t.body||[],i=t.foot||[];if(t.html){var l=t.includeHiddenHtml;if(n){var c=dt(a,t.html,n,l,t.useCss)||{};s=c.head||s,r=c.body||s,i=c.foot||s}else console.error("Cannot parse html in non browser environment")}var u=t.columns||da(s,r,i);return{columns:u,head:s,body:r,foot:i}}function da(a,t,n){var s=a[0]||t[0]||n[0]||[],r=[];return Object.keys(s).filter(function(i){return i!=="_element"}).forEach(function(i){var l=1,c;Array.isArray(s)?c=s[parseInt(i)]:c=s[i],typeof c=="object"&&!Array.isArray(c)&&(l=(c==null?void 0:c.colSpan)||1);for(var u=0;u<l;u++){var o=void 0;Array.isArray(s)?o=r.length:o=i+(u>0?"_".concat(u):"");var d={dataKey:o};r.push(d)}}),r}var Ce=(function(){function a(t,n,s){this.table=n,this.pageNumber=n.pageNumber,this.settings=n.settings,this.cursor=s,this.doc=t.getDocument()}return a})(),ca=(function(a){rt(t,a);function t(n,s,r,i,l,c){var u=a.call(this,n,s,c)||this;return u.cell=r,u.row=i,u.column=l,u.section=i.section,u}return t})(Ce),ua=(function(){function a(t,n){this.pageNumber=1,this.id=t.id,this.settings=t.settings,this.styles=t.styles,this.hooks=t.hooks,this.columns=n.columns,this.head=n.head,this.body=n.body,this.foot=n.foot}return a.prototype.getHeadHeight=function(t){return this.head.reduce(function(n,s){return n+s.getMaxCellHeight(t)},0)},a.prototype.getFootHeight=function(t){return this.foot.reduce(function(n,s){return n+s.getMaxCellHeight(t)},0)},a.prototype.allRows=function(){return this.head.concat(this.body).concat(this.foot)},a.prototype.callCellHooks=function(t,n,s,r,i,l){for(var c=0,u=n;c<u.length;c++){var o=u[c],d=new ca(t,this,s,r,i,l),g=o(d)===!1;if(s.text=Array.isArray(s.text)?s.text:[s.text],g)return!1}return!0},a.prototype.callEndPageHooks=function(t,n){t.applyStyles(t.userStyles);for(var s=0,r=this.hooks.didDrawPage;s<r.length;s++){var i=r[s];i(new Ce(t,this,n))}},a.prototype.callWillDrawPageHooks=function(t,n){for(var s=0,r=this.hooks.willDrawPage;s<r.length;s++){var i=r[s];i(new Ce(t,this,n))}},a.prototype.getWidth=function(t){if(typeof this.settings.tableWidth=="number")return this.settings.tableWidth;if(this.settings.tableWidth==="wrap"){var n=this.columns.reduce(function(r,i){return r+i.wrappedWidth},0);return n}else{var s=this.settings.margin;return t-s.left-s.right}},a})(),ut=(function(){function a(t,n,s,r,i){i===void 0&&(i=!1),this.height=0,this.raw=t,t instanceof st&&(this.raw=t._element,this.element=t._element),this.index=n,this.section=s,this.cells=r,this.spansMultiplePages=i}return a.prototype.getMaxCellHeight=function(t){var n=this;return t.reduce(function(s,r){var i;return Math.max(s,((i=n.cells[r.index])===null||i===void 0?void 0:i.height)||0)},0)},a.prototype.hasRowSpan=function(t){var n=this;return t.filter(function(s){var r=n.cells[s.index];return r?r.rowSpan>1:!1}).length>0},a.prototype.canEntireRowFit=function(t,n){return this.getMaxCellHeight(n)<=t},a.prototype.getMinimumRowHeight=function(t,n){var s=this;return t.reduce(function(r,i){var l=s.cells[i.index];if(!l)return 0;var c=n.getLineHeight(l.styles.fontSize),u=l.padding("vertical"),o=u+c;return o>r?o:r},0)},a})(),gt=(function(){function a(t,n,s){var r;this.contentHeight=0,this.contentWidth=0,this.wrappedWidth=0,this.minReadableWidth=0,this.minWidth=0,this.width=0,this.height=0,this.x=0,this.y=0,this.styles=n,this.section=s,this.raw=t;var i=t;t!=null&&typeof t=="object"&&!Array.isArray(t)?(this.rowSpan=t.rowSpan||1,this.colSpan=t.colSpan||1,i=(r=t.content)!==null&&r!==void 0?r:t,t._element&&(this.raw=t._element)):(this.rowSpan=1,this.colSpan=1);var l=i!=null?""+i:"",c=/\r\n|\r|\n/g;this.text=l.split(c)}return a.prototype.getTextPos=function(){var t;if(this.styles.valign==="top")t=this.y+this.padding("top");else if(this.styles.valign==="bottom")t=this.y+this.height-this.padding("bottom");else{var n=this.height-this.padding("vertical");t=this.y+n/2+this.padding("top")}var s;if(this.styles.halign==="right")s=this.x+this.width-this.padding("right");else if(this.styles.halign==="center"){var r=this.width-this.padding("horizontal");s=this.x+r/2+this.padding("left")}else s=this.x+this.padding("left");return{x:s,y:t}},a.prototype.getContentHeight=function(t,n){n===void 0&&(n=1.15);var s=Array.isArray(this.text)?this.text.length:1,r=this.styles.fontSize/t*n,i=s*r+this.padding("vertical");return Math.max(i,this.styles.minCellHeight)},a.prototype.padding=function(t){var n=xe(this.styles.cellPadding,0);return t==="vertical"?n.top+n.bottom:t==="horizontal"?n.left+n.right:n[t]},a})(),ga=(function(){function a(t,n,s){this.wrappedWidth=0,this.minReadableWidth=0,this.minWidth=0,this.width=0,this.dataKey=t,this.raw=n,this.index=s}return a.prototype.getMaxCustomCellWidth=function(t){for(var n=0,s=0,r=t.allRows();s<r.length;s++){var i=r[s],l=i.cells[this.index];l&&typeof l.styles.cellWidth=="number"&&(n=Math.max(n,l.styles.cellWidth))}return n},a})();function ha(a,t){ma(a,t);var n=[],s=0;t.columns.forEach(function(i){var l=i.getMaxCustomCellWidth(t);l?i.width=l:(i.width=i.wrappedWidth,n.push(i)),s+=i.width});
7var r=t.getWidth(a.pageSize().width)-s;r&&(r=Ne(n,r,function(i){return Math.max(i.minReadableWidth,i.minWidth)})),r&&(r=Ne(n,r,function(i){return i.minWidth})),r=Math.abs(r),!t.settings.horizontalPageBreak&&r>.1/a.scaleFactor()&&(r=r<1?r:Math.round(r),console.log("Of the table content, ".concat(r," units width could not fit page"))),pa(t),fa(t,a),xa(t)}function ma(a,t){var n=a.scaleFactor(),s=t.settings.horizontalPageBreak,r=ot(a,t);t.allRows().forEach(function(i){for(var l=0,c=t.columns;l<c.length;l++){var u=c[l],o=i.cells[u.index];if(o){var d=t.hooks.didParseCell;t.callCellHooks(a,d,o,i,u,null);var g=o.padding("horizontal");o.contentWidth=he(o.text,o.styles,a)+g;var p=he(o.text.join(" ").split(/[^\S\u00A0]+/),o.styles,a);if(o.minReadableWidth=p+o.padding("horizontal"),typeof o.styles.cellWidth=="number")o.minWidth=o.styles.cellWidth,o.wrappedWidth=o.styles.cellWidth;else if(o.styles.cellWidth==="wrap"||s===!0)o.contentWidth>r?(o.minWidth=r,o.wrappedWidth=r):(o.minWidth=o.contentWidth,o.wrappedWidth=o.contentWidth);else{var y=10/n;o.minWidth=o.styles.minCellWidth||y,o.wrappedWidth=o.contentWidth,o.minWidth>o.wrappedWidth&&(o.wrappedWidth=o.minWidth)}}}}),t.allRows().forEach(function(i){for(var l=0,c=t.columns;l<c.length;l++){var u=c[l],o=i.cells[u.index];if(o&&o.colSpan===1)u.wrappedWidth=Math.max(u.wrappedWidth,o.wrappedWidth),u.minWidth=Math.max(u.minWidth,o.minWidth),u.minReadableWidth=Math.max(u.minReadableWidth,o.minReadableWidth);else{var d=t.styles.columnStyles[u.dataKey]||t.styles.columnStyles[u.index]||{},g=d.cellWidth||d.minCellWidth;g&&typeof g=="number"&&(u.minWidth=g,u.wrappedWidth=g)}o&&(o.colSpan>1&&!u.minWidth&&(u.minWidth=o.minWidth),o.colSpan>1&&!u.wrappedWidth&&(u.wrappedWidth=o.minWidth))}})}function Ne(a,t,n){for(var s=t,r=a.reduce(function(y,x){return y+x.wrappedWidth},0),i=0;i<a.length;i++){var l=a[i],c=l.wrappedWidth/r,u=s*c,o=l.width+u,d=n(l),g=o<d?d:o;t-=g-l.width,l.width=g}if(t=Math.round(t*1e10)/1e10,t){var p=a.filter(function(y){return t<0?y.width>n(y):!0});p.length&&(t=Ne(p,t,n))}return t}function xa(a){for(var t={},n=1,s=a.allRows(),r=0;r<s.length;r++)for(var i=s[r],l=0,c=a.columns;l<c.length;l++){var u=c[l],o=t[u.index];if(n>1)n--,delete i.cells[u.index];else if(o)o.cell.height+=i.height,n=o.cell.colSpan,delete i.cells[u.index],o.left--,o.left<=1&&delete t[u.index];else{var d=i.cells[u.index];if(!d)continue;if(d.height=i.height,d.rowSpan>1){var g=s.length-r,p=d.rowSpan>g?g:d.rowSpan;t[u.index]={cell:d,left:p,row:i}}}}}function pa(a){for(var t=a.allRows(),n=0;n<t.length;n++)for(var s=t[n],r=null,i=0,l=0,c=0;c<a.columns.length;c++){var u=a.columns[c];if(l-=1,l>1&&a.columns[c+1])i+=u.width,delete s.cells[u.index];else if(r){var o=r;delete s.cells[u.index],r=null,o.width=u.width+i}else{var o=s.cells[u.index];if(!o)continue;if(l=o.colSpan,i=0,o.colSpan>1){r=o,i+=u.width;continue}o.width=u.width+i}}}function fa(a,t){for(var n={count:0,height:0},s=0,r=a.allRows();s<r.length;s++){for(var i=r[s],l=0,c=a.columns;l<c.length;l++){var u=c[l],o=i.cells[u.index];if(o){t.applyStyles(o.styles,!0);var d=o.width-o.padding("horizontal");if(o.styles.overflow==="linebreak")o.text=t.splitTextToSize(o.text,d+1/t.scaleFactor(),{fontSize:o.styles.fontSize});else if(o.styles.overflow==="ellipsize")o.text=Fe(o.text,d,o.styles,t,"...");else if(o.styles.overflow==="hidden")o.text=Fe(o.text,d,o.styles,t,"");else if(typeof o.styles.overflow=="function"){var g=o.styles.overflow(o.text,d);typeof g=="string"?o.text=[g]:o.text=g}o.contentHeight=o.getContentHeight(t.scaleFactor(),t.getLineHeightFactor());var p=o.contentHeight/o.rowSpan;o.rowSpan>1&&n.count*n.height<p*o.rowSpan?n={height:p,count:o.rowSpan}:n&&n.count>0&&n.height>p&&(p=n.height),p>i.height&&(i.height=p)}}n.count--}}function Fe(a,t,n,s,r){return a.map(function(i){return ya(i,t,n,s,r)})}function ya(a,t,n,s,r){var i=1e4*s.scaleFactor();if(t=Math.ceil(t*i)/i,t>=he(a,n,s))return a;for(;t<he(a+r,n,s)&&!(a.length<=1);)a=a.substring(0,a.length-1);return a.trim()+r}function ht(a,t){var n=new oe(a),s=va(t,n.scaleFactor()),r=new ua(t,s);return ha(n,r),n.applyStyles(n.userStyles),r}function va(a,t){var n=a.content,s=ja(n.columns);if(n.head.length===0){var r=He(s,"head");r&&n.head.push(r)}if(n.foot.length===0){var r=He(s,"foot");r&&n.foot.push(r)}var i=a.settings.theme,l=a.styles;return{columns:s,head:fe("head",n.head,s,l,i,t),body:fe("body",n.body,s,l,i,t),foot:fe("foot",n.foot,s,l,i,t)}}function fe(a,t,n,s,r,i){var l={},c=t.map(function(u,o){for(var d=0,g={},p=0,y=0,x=0,v=n;x<v.length;x++){var C=v[x];if(l[C.index]==null||l[C.index].left===0)if(y===0){var b=void 0;Array.isArray(u)?b=u[C.index-p-d]:b=u[C.dataKey];var T={};typeof b=="object"&&!Array.isArray(b)&&(T=(b==null?void 0:b.styles)||{});var h=Ca(a,C,o,r,s,i,T),f=new gt(b,h,a);g[C.dataKey]=f,g[C.index]=f,y=f.colSpan-1,l[C.index]={left:f.rowSpan-1,times:y}}else y--,p++;else l[C.index].left--,y=l[C.index].times,d++}return new ut(u,o,a,g)});return c}function He(a,t){var n={};return a.forEach(function(s){if(s.raw!=null){var r=ba(t,s.raw);r!=null&&(n[s.dataKey]=r)}}),Object.keys(n).length>0?n:null}function ba(a,t){if(a==="head"){if(typeof t=="object")return t.header||null;if(typeof t=="string"||typeof t=="number")return t}else if(a==="foot"&&typeof t=="object")return t.footer;return null}function ja(a){return a.map(function(t,n){var s,r;return typeof t=="object"?r=(s=t.dataKey)!==null&&s!==void 0?s:n:r=n,new ga(r,t,n)})}function Ca(a,t,n,s,r,i,l){var c=Zt(s),u;a==="head"?u=r.headStyles:a==="body"?u=r.bodyStyles:a==="foot"&&(u=r.footStyles);var o=G({},c.table,c[a],r.styles,u),d=r.columnStyles[t.dataKey]||r.columnStyles[t.index]||{},g=a==="body"?d:{},p=a==="body"&&n%2===0?G({},c.alternateRow,r.alternateRowStyles):{},y=Gt(i),x=G({},y,o,p,g);return G(x,l)}function Na(a,t,n){var s;n===void 0&&(n={});var r=ot(a,t),i=new Map,l=[],c=[],u=[];Array.isArray(t.settings.horizontalPageBreakRepeat)?u=t.settings.horizontalPageBreakRepeat:(typeof t.settings.horizontalPageBreakRepeat=="string"||typeof t.settings.horizontalPageBreakRepeat=="number")&&(u=[t.settings.horizontalPageBreakRepeat]),u.forEach(function(p){var y=t.columns.find(function(x){return x.dataKey===p||x.index===p});y&&!i.has(y.index)&&(i.set(y.index,!0),l.push(y.index),c.push(t.columns[y.index]),r-=y.wrappedWidth)});for(var o=!0,d=(s=n==null?void 0:n.start)!==null&&s!==void 0?s:0;d<t.columns.length;){if(i.has(d)){d++;continue}var g=t.columns[d].wrappedWidth;
7if(o||r>=g)o=!1,l.push(d),c.push(t.columns[d]),r-=g;else break;d++}return{colIndexes:l,columns:c,lastIndex:d-1}}function ka(a,t){for(var n=[],s=0;s<t.columns.length;s++){var r=Na(a,t,{start:s});r.columns.length&&(n.push(r),s=r.lastIndex)}return n}function mt(a,t){var n=t.settings,s=n.startY,r=n.margin,i={x:r.left,y:s},l=t.getHeadHeight(t.columns)+t.getFootHeight(t.columns),c=s+r.bottom+l;if(n.pageBreak==="avoid"){var u=t.body,o=u.reduce(function(p,y){return p+y.height},0);c+=o}var d=new oe(a);(n.pageBreak==="always"||n.startY!=null&&c>d.pageSize().height)&&(pt(d),i.y=r.top),t.callWillDrawPageHooks(d,i);var g=G({},i);t.startPageNumber=d.pageNumber(),n.horizontalPageBreak?Sa(d,t,g,i):(d.applyStyles(d.userStyles),(n.showHead==="firstPage"||n.showHead==="everyPage")&&t.head.forEach(function(p){return ee(d,t,p,i,t.columns)}),d.applyStyles(d.userStyles),t.body.forEach(function(p,y){var x=y===t.body.length-1;me(d,t,p,x,g,i,t.columns)}),d.applyStyles(d.userStyles),(n.showFoot==="lastPage"||n.showFoot==="everyPage")&&t.foot.forEach(function(p){return ee(d,t,p,i,t.columns)})),nt(d,t,g,i),t.callEndPageHooks(d,i),t.finalY=i.y,a.lastAutoTable=t,d.applyStyles(d.userStyles)}function Sa(a,t,n,s){var r=ka(a,t),i=t.settings;if(i.horizontalPageBreakBehaviour==="afterAllRows")r.forEach(function(o,d){a.applyStyles(a.userStyles),d>0?de(a,t,n,s,o.columns,!0):We(a,t,s,o.columns),wa(a,t,n,s,o.columns),ye(a,t,s,o.columns)});else for(var l=-1,c=r[0],u=function(){var o=l;if(c){a.applyStyles(a.userStyles);var d=c.columns;l>=0?de(a,t,n,s,d,!0):We(a,t,s,d),o=Ee(a,t,l+1,s,d),ye(a,t,s,d)}var g=o-l;r.slice(1).forEach(function(p){a.applyStyles(a.userStyles),de(a,t,n,s,p.columns,!0),Ee(a,t,l+1,s,p.columns,g),ye(a,t,s,p.columns)}),l=o};l<t.body.length-1;)u()}function We(a,t,n,s){var r=t.settings;a.applyStyles(a.userStyles),(r.showHead==="firstPage"||r.showHead==="everyPage")&&t.head.forEac
7h(function(i){return ee(a,t,i,n,s)})}function wa(a,t,n,s,r){a.applyStyles(a.userStyles),t.body.forEach(function(i,l){var c=l===t.body.length-1;me(a,t,i,c,n,s,r)})}function Ee(a,t,n,s,r,i){a.applyStyles(a.userStyles),i=i??t.body.length;var l=Math.min(n+i,t.body.length),c=-1;return t.body.slice(n,l).forEach(function(u,o){var d=n+o===t.body.length-1,g=xt(a,t,d,s);u.canEntireRowFit(g,r)&&(ee(a,t,u,s,r),c=n+o)}),c}function ye(a,t,n,s){var r=t.settings;a.applyStyles(a.userStyles),(r.showFoot==="lastPage"||r.showFoot==="everyPage")&&t.foot.forEach(function(i){return ee(a,t,i,n,s)})}function Ra(a,t,n){var s=n.getLineHeight(a.styles.fontSize),r=a.padding("vertical"),i=Math.floor((t-r)/s);return Math.max(0,i)}function Ta(a,t,n,s){var r={};a.spansMultiplePages=!0,a.height=0;for(var i=0,l=0,c=n.columns;l<c.length;l++){var u=c[l],o=a.cells[u.index];if(o){Array.isArray(o.text)||(o.text=[o.text]);var d=new gt(o.raw,o.styles,o.section);d=G(d,o),d.text=[];var g=Ra(o,t,s);o.text.length>g&&(d.text=o.text.splice(g,o.text.length));var p=s.scaleFactor(),y=s.getLineHeightFactor();o.contentHeight=o.getContentHeight(p,y),o.contentHeight>=t&&(o.contentHeight=t,d.styles.minCellHeight-=t),o.contentHeight>a.height&&(a.height=o.contentHeight),d.contentHeight=d.getContentHeight(p,y),d.contentHeight>i&&(i=d.contentHeight),r[u.index]=d}}var x=new ut(a.raw,-1,a.section,r,!0);x.height=i;for(var v=0,C=n.columns;v<C.length;v++){var u=C[v],d=x.cells[u.index];d&&(d.height=x.height);var o=a.cells[u.index];o&&(o.height=a.height)}return x}function Pa(a,t,n,s){var r=a.pageSize().height,i=s.settings.margin,l=i.top+i.bottom,c=r-l;t.section==="body"&&(c-=s.getHeadHeight(s.columns)+s.getFootHeight(s.columns));var u=t.getMinimumRowHeight(s.columns,a),o=u<n;if(u>c)return console.log("Will not be able to print row ".concat(t.index," correctly since it's minimum height is larger than page height")),!0;if(!o)return!1;var d=t.hasRowSpan(s.columns),g=t.getMaxCellHeight(s.columns)>c;return g?(d&&console.log("The content of row ".concat(t.index," will not be drawn correctly since drawing rows with a height larger than the page height and has cells with rowspans is not supported.")),!0):!(d||s.settings.rowPageBreak==="avoid")}function me(a,t,n,s,r,i,l){var c=xt(a,t,s,i);if(n.canEntireRowFit(c,l))ee(a,t,n,i,l);else if(Pa(a,n,c,t)){var u=Ta(n,c,t,a);ee(a,t,n,i,l),de(a,t,r,i,l),me(a,t,u,s,r,i,l)}else de(a,t,r,i,l),me(a,t,n,s,r,i,l)}function ee(a,t,n,s,r){s.x=t.settings.margin.left;for(var i=0,l=r;i<l.length;i++){var c=l[i],u=n.cells[c.index];if(!u){s.x+=c.width;continue}a.applyStyles(u.styles),u.x=s.x,u.y=s.y;var o=t.callCellHooks(a,t.hooks.willDrawCell,u,n,c,s);if(o===!1){s.x+=c.width;continue}$a(a,u,s);var d=u.getTextPos();at(u.text,d.x,d.y,{halign:u.styles.halign,valign:u.styles.valign,maxWidth:Math.ceil(u.width-u.padding("left")-u.padding("right"))},a.getDocument()),t.callCellHooks(a,t.hooks.didDrawCell,u,n,c,s),s.x+=c.width}s.y+=n.height}function $a(a,t,n){var s=t.styles;if(a.getDocument().setFillColor(a.getDocument().getFillColor()),typeof s.lineWidth=="number"){var r=it(s.lineWidth,s.fillColor);r&&a.rect(t.x,n.y,t.width,t.height,r)}else typeof s.lineWidth=="object"&&(s.fillColor&&a.rect(t.x,n.y,t.width,t.height,"F"),Da(a,t,n,s.lineWidth))}function Da(a,t,n,s){var r,i,l,c;s.top&&(r=n.x,i=n.y,l=n.x+t.width,c=n.y,s.right&&(l+=.5*s.right),s.left&&(r-=.5*s.left),u(s.top,r,i,l,c)),s.bottom&&(r=n.x,i=n.y+t.height,l=n.x+t.width,c=n.y+t.height,s.right&&(l+=.5*s.right),s.left&&(r-=.5*s.left),u(s.bottom,r,i,l,c)),s.left&&(r=n.x,i=n.y,l=n.x,c=n.y+t.height,s.top&&(i-=.5*s.top),s.bottom&&(c+=.5*s.bottom),u(s.left,r,i,l,c)),s.right&&(r=n.x+t.width,i=n.y,l=n.x+t.width,c=n.y+t.height,s.top&&(i-=.5*s.top),s.bottom&&(c+=.5*s.bottom),u(s.right,r,i,l,c));function u(o,d,g,p,y){a.getDocument().setLineWidth(o),a.getDocument().line(d,g,p,y,"S")}}function xt(a,t,n,s){var r=t.settings.margin.bottom,i=t.settings.showFoot;return(i==="everyPage"||i==="lastPage"&&n)&&(r+=t.getFootHeight(t.columns)),a.pageSize().height-s.y-r}function de(a,t,n,s,r,i){r===void 0&&(r=[]),i===void 0&&(i=!1),a.applyStyles(a.userStyles),t.settings.showFoot==="everyPage"&&!i&&t.foot.forEach(function(c){return ee(a,t,c,s,r)}),t.callEndPageHooks(a,s);var l=t.settings.margin;nt(a,t,n,s),pt(a),t.pageNumber++,s.x=l.left,s.y=l.top,n.y=l.top,t.callWillDrawPageHooks(a,s),t.settings.showHead==="everyPage"&&(t.head.forEac
7h(function(c){return ee(a,t,c,s,r)}),a.applyStyles(a.userStyles))}function pt(a){var t=a.pageNumber();a.setPage(t+1);var n=a.pageNumber();return n===t?(a.addPage(),!0):!1}function Aa(a){a.API.autoTable=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var s=t[0],r=ct(this,s),i=ht(this,r);return mt(this,i),this},a.API.lastAutoTable=!1,a.API.autoTableText=function(t,n,s,r){at(t,n,s,r,this)},a.API.autoTableSetDefaults=function(t){return oe.setDefaults(t,this),this},a.autoTableSetDefaults=function(t,n){oe.setDefaults(t,n)},a.API.autoTableHtmlToJson=function(t,n){var s;if(n===void 0&&(n=!1),typeof window>"u")return console.error("Cannot run autoTableHtmlToJson in non browser environment"),null;var r=new oe(this),i=dt(r,t,window,n,!1),l=i.head,c=i.body,u=((s=l[0])===null||s===void 0?void 0:s.map(function(o){return o.content}))||[];return{columns:u,rows:c,data:c}}}var ve;function La(a,t){var n=ct(a,t),s=ht(a,n);mt(a,s)}try{if(typeof window<"u"&&window){var Be=window,Me=Be.jsPDF||((ve=Be.jspdf)===null||ve===void 0?void 0:ve.jsPDF);Me&&Aa(Me)}}catch(a){console.error("Could not apply autoTable plugin",a)}function te(a,t,n,s){if(!a||a.length===0){alert("No data to export");return}const r=new Et;r.setFontSize(18),r.setTextColor(40),r.text(n,14,22),r.setFontSize(11),r.setTextColor(100);const i=(()=>{try{return localStorage.getItem("businessTimezone")||_}catch{return _}})();r.text(`Generated: ${new Date().toLocaleDateString("en-US",{timeZone:i})}`,14,30);const l=s||Object.keys(a[0]||{}).map(o=>({header:Fa(o),dataKey:o})),c=a.map(o=>{const d={};for(const g of l){const p=o[g.dataKey];p==null?d[g.dataKey]="-":typeof p=="number"&&g.dataKey.includes("Cents")?d[g.dataKey]=`$${(p/100).toFixed(2)}`:typeof p=="number"&&g.dataKey.includes("Rate")?d[g.dataKey]=`${p}%`:p instanceof Date?d[g.dataKey]=p.toLocaleDateString("en-US",{timeZone:i}):d[g.dataKey]=String(p)}return d});La(r,{startY:35,head:[l.map(o=>o.header)],body:c.map(o=>l.map(d=>o[d.dataKey]||"-")),theme:"grid",styles:{fontSize:9,cellPadding:3},headStyles:{fillColor:[59,130,246],textColor:255,fontStyle:"bold"},alternateRowStyles:{fillColor:[249,250,251]}});const u=r.getNumberOfPages();for(let o=1;o<=u;o++)r.setPage(o),r.setFontSize(8),r.setTextColor(150),r.text(`Page ${o} of ${u}`,r.internal.pageSize.width/2,r.internal.pageSize.height-10,{align:"center"});r.save(`${t}.pdf`)}function Fa(a){return a.replace(/([A-Z])/g," $1").replace(/^./,t=>t.toUpperCase()).replace(/Cents$/,"").replace(/Id$/," ID").trim()}function ue({tab:a,dateFrom:t,dateTo:n,locationId:s}){const{primaryColor:r,darkMode:i}=z(),[l,c]=N.useState(null),[u,o]=N.useState(!1),[d,g]=N.useState(null),[p,y]=N.useState(""),x=N.useCallback(async()=>{const v=`${a}-${t}-${n}-${s}`;if(!(p===v&&l))try{o(!0),g(null);const C=localStorage.getItem("accessToken");if(!C)throw new Error("Not authenticated");const b=await F.getAiNarrative(t,n,a,C,s);c(b.data.narrative),y(v)}catch(C){g((C==null?void 0:C.message)||"Failed to generate")}finally{o(!1)}},[a,t,n,s,p,l]);return!l&&!u&&!d?e.jsxs("button",{onClick:x,className:`w-full flex items-center justify-center gap-2 py-3 px-4 rounded-lg text-sm transition-all border border-dashed ${i?"border-gray-600 text-gray-400 hover:border-gray-500 hover:text-gray-300":"border-gray-300 text-gray-500 hover:border-gray-400 hover:text-gray-700"}`,children:[e.jsx(le,{className:"w-4 h-4",style:{color:r}}),"Generate AI Summary"]}):e.jsxs("div",{className:`rounded-lg px-4 py-3 text-sm ${i?"bg-gray-700/40 text-gray-300":"bg-gray-50 text-gray-700"}`,children:[u&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-solid border-r-transparent",style:{borderColor:`${r} transparent ${r} ${r}`}}),e.jsx("span",{className:i?"text-gray-400":"text-gray-500",children:"Analyzing..."})]}),d&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-red-500 text-xs",children:d}),e.jsx("button",{onClick:x,className:"text-xs underline ml-2",style:{color:r},children:"Retry"})]}),l&&e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(le,{className:"w-4 h-4 mt-0.5 flex-shrink-0",style:{color:r}}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"leading-relaxed",children:l}),e.jsx("button",{onClick:()=>{c(null),y(""),g(null)},className:`text-xs mt-1 ${i?"text-gray-500 hover:text-gray-400":"text-gray-400 hover:text-gray-500"}`,children:"Dismiss"})]})]})]})}function Q(a){return`$${(a/100).toFixed(2)}`}const Ha=localStorage.getItem("businessTimezone")||_;
7function ze(a){return new Date(a).toLocaleString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit",hour12:!0,timeZone:Ha})}function Ke(a,t,n){const r={cash:"Cash",card:"Card",helcim_payjs:"Card",saved_card:"Card",terminal:"Terminal",gift_card:"Gift Card",membership:"Membership",other:"Other"}[a]??a;return t&&n?`${t} â¢â¢â¢â¢${n}`:n?`${r} â¢â¢â¢â¢${n}`:r}function Wa({dateFrom:a,dateTo:t,locationId:n,onExport:s}){const{primaryColor:r}=z(),[i,l]=N.useState("refundedAt"),[c,u]=N.useState("desc"),{data:o,loading:d,error:g}=B((b,T,h)=>F.getRefundsReport(b,T,h,n),{dateFrom:a,dateTo:t,locationId:n}),p=b=>{if(!(o!=null&&o.refunds.length)){alert("No refunds to export");return}const T=`refunds-${a}-to-${t}`,h=o.refunds.map(f=>({date:ze(f.refundedAt),client:f.clientName??"â",staff:f.staffName??"â",location:f.locationName??"â",method:Ke(f.paymentMethod,f.cardBrand,f.cardLastFour),original:Q(f.originalAmountCents),refunded:Q(f.totalRefundedCents),type:f.isFullRefund?"Full":"Partial",reason:f.refundReason??"â",processedBy:f.refundedByName??"â"}));if(b==="csv"){const f=X(h,{date:"Date",client:"Client",staff:"Staff",location:"Location",method:"Payment Method",original:"Original Amount",refunded:"Refunded Amount",type:"Refund Type",reason:"Reason",processedBy:"Processed By"});J(f,T)}else b==="pdf"?te(h,T,"Refunds Report",[{header:"Date",dataKey:"date"},{header:"Client",dataKey:"client"},{header:"Staff",dataKey:"staff"},{header:"Method",dataKey:"method"},{header:"Original",dataKey:"original"},{header:"Refunded",dataKey:"refunded"},{header:"Type",dataKey:"type"},{header:"Reason",dataKey:"reason"}]):alert("Excel export coming soon");s==null||s(b)};function y(b){i===b?u(T=>T==="asc"?"desc":"asc"):(l(b),u("desc"))}const x=o?[...o.refunds].sort((b,T)=>{let h=0;switch(i){case"refundedAt":h=new Date(b.refundedAt).getTime()-new Date(T.refundedAt).getTime();break;case"totalRefundedCents":h=b.totalRefundedCents-T.totalRefundedCents;break;case"clientName":h=(b.clientName??"").localeCompare(T.clientName??"");break;case"staffName":h=(b.staffName??"").localeCompare(T.staffName??"");break}return c==="asc"?h:-h}):[];if(d)return e.jsx(q,{message:"Loading refundsâ¦"});if(g)return e.jsxs("div",{className:"flex items-center gap-2 text-red-600 p-4",children:[e.jsx(Re,{className:"w-5 h-5 flex-shrink-0"}),e.jsxs("span",{children:["Failed to load refunds: ",g.message]})]});if(!o)return null;const{summary:v}=o;function C({field:b}){return i!==b?e.jsx(Ae,{className:"w-3 h-3 text-gray-300 ml-1 inline"}):c==="asc"?e.jsx(Ae,{className:"w-3 h-3 ml-1 inline",style:{color:r}}):e.jsx(Ie,{className:"w-3 h-3 ml-1 inline",style:{color:r}})}return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ie,{className:"w-5 h-5",style:{color:r}}),e.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:"Refunds"})]}),e.jsx(ae,{onExport:p,disabled:!o.refunds.length})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(R,{label:"Total Refunded",value:Q(v.totalRefundedCents),subtitle:`${v.refundCount} refund${v.refundCount!==1?"s":""}`,icon:ie,useThemeColor:!0}),e.jsx(R,{label:"Average Refund",value:v.refundCount>0?Q(v.averageRefundCents):"â",subtitle:"Per transaction",icon:ie,useThemeColor:!0}),e.jsx(R,{label:"Full Refunds",value:v.fullRefundCount,subtitle:`${v.partialRefundCount} partial`,icon:ie,useThemeColor:!0}),e.jsx(R,{label:"Tips Refunded",value:Q(v.totalRefundedTipCents),subtitle:`${Q(v.totalRefundedBaseCents)} base`,icon:ie,useThemeColor:!0})]}),e.jsx($,{title:`Refund Transactions (${v.refundCount})`,subtitle:`All refunds issued ${a} â ${t}`,children:x.length===0?e.jsxs("div",{className:"text-center py-12 text-gray-500",children:[e.jsx(ie,{className:"w-12 h-12 mx-auto mb-3 text-gray-300"}),e.jsx("p",{className:"font-medium",children:"No refunds in this period"}),e.jsx("p",{className:"text-sm mt-1",children:"Refunds issued during this date range will appear here."})]}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-200 text-sm",children:[e.jsx("thead",{className:"bg-gray-50",children:e.jsxs("tr",{children:[e.jsxs("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider cursor-pointer select-none",onClick:()=>y("refundedAt"),children:["Date ",e.jsx(C,{field:"refundedAt"})]}),e.jsxs("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider cursor-pointer select-none",onClick:()=>y("clientName"),children:["Client ",e.jsx(C,{field:"clientName"})]}),e.jsxs("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider cursor-pointer select-none",onClick:()=>y("staffName"),children:["Staff ",e.jsx(C,{field:"staffName"})]}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Method"}),e.jsx("th",{className:"px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Original"}),e.jsxs("th",{className:"px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider cursor-pointer select-none",onClick:()=>y("totalRefundedCents"),children:["Refunded ",e.jsx(C,{field:"totalRefundedCents"})]}),e.jsx("th",{className:"px-4 py-3 text-center text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Type"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Reason"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Processed By"})]})}),e.jsx("tbody",{className:"bg-white divide-y divide-gray-100",children:x.map(b=>e.jsxs("tr",{className:"hover:bg-gray-50 transition-colors",children:[e.jsx("td",{className:"px-4 py-3 whitespace-nowrap text-gray-700",children:ze(b.refundedAt)}),e.jsx("td",{className:"px-4 py-3 whitespace-nowrap font-medium text-gray-900",children:b.clientName??e.jsx("span",{className:"text-gray-400",children:"Walk-in"})}),e.jsx("td",{className:"px-4 py-3 whitespace-nowrap text-gray-700",children:b.staffName??e.jsx("span",{className:"text-gray-400",children:"â"})}),e.jsx("td",{className:"px-4 py-3 whitespace-nowrap text-gray-700",children:Ke(b.paymentMethod,b.cardBrand,b.cardLastFour)}),e.jsxs("td",{className:"px-4 py-3 whitespace-nowrap text-right text-gray-700",children:[Q(b.originalAmountCents),b.originalTipAmountCents>0&&e.jsxs("span",{className:"text-gray-400 text-xs ml-1",children:["+",Q(b.originalTipAmountCents)]})]}),e.jsxs("td",{className:"px-4 py-3 whitespace-nowrap text-right font-semibold text-red-600",children:["â",Q(b.totalRefundedCents),b.refundTipAmountCents>0&&e.jsxs("span",{className:"text-red-400 text-xs ml-1 font-normal",children:["(incl. ",Q(b.refundTipAmountCents)," tip)"]})]}),e.jsx("td",{className:"px-4 py-3 text-center",children:e.jsx("span",{className:`inline-block px-2 py-0.5 rounded-full text-xs font-medium ${b.isFullRefund?"bg-red-100 text-red-700":"bg-orange-100 text-orange-700"}`,children:b.isFullRefund?"Full":"Partial"})}),e.jsx("td",{className:"px-4 py-3 text-gray-600 max-w-[200px]",children:e.jsx("span",{className:"block truncate",title:b.refundReason??void 0,children:b.refundReason??e.jsx("span",{className:"text-gray-400",children:"â"})})}),e.jsx("td",{className:"px-4 py-3 whitespace-nowrap text-gray-600",children:b.refundedByName??e.jsx("span",{className:"text-gray-400",children:"â"})})]},b.paymentId))}),e.jsx("tfoot",{className:"bg-gray-50 border-t-2 border-gray-200",children:e.jsxs("tr",{children:[e.jsxs("td",{colSpan:5,className:"px-4 py-3 text-right font-semibold text-gray-700 text-sm",children:["Total (",v.refundCount," refunds)"]}),e.jsxs("td",{className:"px-4 py-3 text-right font-bold text-red-600",children:["â",Q(v.totalRefundedCents)]}),e.jsx("td",{colSpan:3})]})})]})})})]})}function Ea({dateFrom:a,dateTo:t,locationId:n,onExport:s}){var b,T;const{primaryColor:r}=z(),i=localStorage.getItem("businessTimezone")||_,l=[r,"#10b981","#8b5cf6","#f59e0b","#ef4444","#ec4899","#06b6d4","#84cc16"],c=h=>{if(!u){alert("No data to export");return}const f=`financial-report-${a}-to-${t}`;if(h==="csv"){const S=X(u.breakdown,{period:"Date",revenueCents:"Revenue",transactionCount:"Transactions",averageTransactionCents:"Avg Transaction",percentageOfTotal:"% of Total"});J(S,f)}else h==="pdf"?te(u.breakdown,f,"Financial Report",[{header:"Date",dataKey:"period"},{header:"Revenue",dataKey:"revenueCents"},{header:"Transactions",dataKey:"transactionCount"},{header:"Avg Transaction",dataKey:"averageTransactionCents"}]):alert("Excel export coming soon!");s==null||s(h)},{data:u,loading:o,error:d}=B((h,f,S)=>F.getSalesReport(h,f,S,{groupBy:"day",includePreviousPeriod:!0,locationId:n}),{dateFrom:a,dateTo:t,locationId:n}),{data:g,loading:p}=B((h,f,S)=>F.getServiceCategoryBreakdown(h,f,S,n),{dateFrom:a,dateTo:t,locationId:n}),{data:y,loading:x}=B((h,f,S)=>F.getTipsReport(h,f,S,{groupBy:"staff",locationId:n}),{dateFrom:a,dateTo:t,locationId:n}),{data:v,loading:C}=B((h,f,S)=>F.getPaymentTransactions(h,f,S,{locationId:n}),{dateFrom:a,dateTo:t,locationId:n});return o||p||x||C?e.jsx(q,{message:"Loading financial reports..."}):d||!u?e.jsx("div",{className:"text-center py-12",children:e.jsx("p",{className:"text-red-600",children:(d==null?void 0:d.message)||"Failed to load reports"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"flex justify-end mb-4",children:e.jsx(ae,{onExport:c,disabled:!u})}),e.jsx(ue,{tab:"financial",dateFrom:a,dateTo:t,locationId:n}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(R,{label:"Total Revenue",value:j(u.summary.totalRevenueCents),change:(b=u.comparison)==null?void 0:b.changePercentage,trend:(T=u.comparison)==null?void 0:T.trend,subtitle:`${u.summary.transactionCount} transactions`,icon:Z,useThemeColor:!0}),e.jsx(R,{label:"Average Transaction",value:j(u.summary.averageTransactionCents),subtitle:"Per transaction",icon:re,useThemeColor:!0}),e.jsx(R,{label:"Total Tips",value:y?j(y.summary.totalTipsCents):"$0.00",subtitle:`${(y==null?void 0:y.summary.tipRate)||0}% tip rate`,icon:Oe,useThemeColor:!0}),e.jsx(R,{label:"Service Categories",value:(g==null?void 0:g.categoryBreakdown.length)||0,subtitle:"Active categories",icon:Bt,useThemeColor:!0})]}),e.jsx($,{title:"Revenue Trend",subtitle:`Daily revenue from ${a} to ${t}`,children:e.jsx(tt,{data:u.breakdown.map(h=>({date:h.period||a,revenue:h.revenueCents,label:h.period})),type:"area",height:300})}),g&&g.categoryBreakdown.length>0&&e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx($,{title:"Service Categories",subtitle:"Revenue breakdown by service category",children:e.jsx(Te,{data:g.categoryBreakdown.map(h=>({name:h.categoryName,value:h.totalRevenueCents})),formatValue:j,height:300,showLabels:!1,showLegend:!1})}),e.jsx($,{title:"Category Details",subtitle:"Booking counts and revenue",children:e.jsx(M,{columns:[{key:"categoryName",label:"Category",render:h=>{const f=g.categoryBreakdown.indexOf(h),S=l[f%l.length];return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"inline-block w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:S}}),e.jsx("span",{children:h.categoryName})]})}},{key:"bookingCount",label:"Bookings",align:"right"},{key:"totalRevenueCents",label:"Revenue",align:"right",render:h=>j(h.totalRevenueCents)},{key:"percentageOfRevenue",label:"% of Revenue",align:"right",render:h=>`${h.percentageOfRevenue}%`}],data:g.categoryBreakdown,keyExtractor:h=>h.categoryName})})]}),y&&e.jsx($,{title:"Tips by Staff",subtitle:"Staff earnings from tips",children:e.jsx(M,{columns:[{key:"staffName",label:"Staff Member"},{key:"totalTipsCents",label:"Total Tips",align:"right",render:h=>j(h.totalTipsCents||0)},{key:"tipCount",label:"Tip Count",align:"right"},{key:"averageTipCents",label:"Avg Tip",align:"right",render:h=>j(h.averageTipCents||0)},{key:"tipRate",label:"Tip Rate",align:"right",render:h=>`${h.tipRate||0}%`}],data:y.breakdown||[],keyExtractor:h=>{var f;return((f=h.staffId)==null?void 0:f.toString())||"total"},emptyMessage:"No tips data for this period"})}),v&&v.transactions&&v.transactions.length>0&&e.jsx($,{title:"Payment Transactions",subtitle:`${v.summary.totalTransactions} transactions`,children:e.jsx(M,{columns:[{key:"createdAt",label:"Date",render:h=>new Date(h.createdAt).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit",timeZone:i})},{key:"clientName",label:"Client",render:h=>h.clientName||"-"},{key:"paymentMethod",label:"Payment Method",render:h=>{const f=h.paymentMethod.toUpperCase();return f==="GIFT_CARD"?e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:"GIFT CARD"}),h.giftCardNumber&&e.jsxs("div",{className:"text-sm text-gray-500",children:["#",h.giftCardNumber]})]}):e.jsx("span",{className:"font-medium",children:f})}},{key:"cardLastFour",label:"Card",render:h=>{const f=h.paymentMethod.toUpperCase();return(f==="CARD"||f==="SAVED_CARD"||f==="TERMINAL"||f==="STRIPE")&&h.cardBrand&&h.cardLastFour?e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:h.cardBrand.toUpperCase()}),e.jsxs("div",{className:"text-sm text-gray-500",children:["****",h.cardLastFour]})]}):"-"}},{key:"amountCents",label:"Amount",align:"right",render:h=>j(h.amountCents)},{key:"tipAmountCents",label:"Tip",align:"right",render:h=>h.tipAmountCents>0?j(h.tipAmountCents):"-"},{key:"paymentStatus",label:"Status",render:h=>e.jsx("span",{className:`inline-flex px-2 py-1 text-xs font-semibold rounded-full ${h.paymentStatus==="completed"?"bg-green-100 text-green-800":h.paymentStatus==="pending"?"bg-yellow-100 text-yellow-800":"bg-gray-100 text-gray-800"}`,children:h.paymentStatus.toUpperCase()})}],data:v.transactions,keyExtractor:h=>h.id.toString(),emptyMessage:"No transactions for this period"})}),e.jsx("div",{className:"border-t border-gray-200 pt-6",children:e.jsx(Wa,{dateFrom:a,dateTo:t,locationId:n})}),u.comparison&&e.jsx($,{title:"Period Comparison",subtitle:"vs. previous period",children:e.jsxs("div",{className:"grid grid-cols-3 gap-6",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-sm text-gray-600 mb-2",children:"Current Period"}),e.jsx("div",{className:"text-2xl font-bold text-gray-900",children:j(u.comparison.currentRevenueCents)})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-sm text-gray-600 mb-2",children:"Previous Per
7iod"}),e.jsx("div",{className:"text-2xl font-bold text-gray-600",children:j(u.comparison.previousRevenueCents)})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-sm text-gray-600 mb-2",children:"Change"}),e.jsxs("div",{className:`text-2xl font-bold ${u.comparison.trend==="up"?"text-green-600":u.comparison.trend==="down"?"text-red-600":"text-gray-600"}`,children:[u.comparison.trend==="up"?"â":u.comparison.trend==="down"?"â":"â"," ",Y(Math.abs(u.comparison.changePercentage))]})]})]})})]})}function ne({data:a,height:t=300,showGrid:n=!0,formatValue:s=i=>String(i),barColor:r}){const{primaryColor:i,darkMode:l}=z(),c=r||i,u=({active:o,payload:d})=>o&&d&&d.length?e.jsxs("div",{className:`p-3 border rounded-lg shadow-lg ${l?"bg-gray-800 border-gray-700":"bg-white border-gray-200"}`,children:[e.jsx("p",{className:`text-sm font-medium ${l?"text-gray-200":"text-gray-900"}`,children:d[0].payload.label}),e.jsx("p",{className:"text-lg font-bold mt-1",style:{color:i},children:s(d[0].value)})]}):null;return e.jsx(Se,{width:"100%",height:t,children:e.jsxs(Ht,{data:a,children:[n&&e.jsx(qe,{strokeDasharray:"3 3",stroke:l?"#4b5563":"#e5e7eb"}),e.jsx(Ye,{dataKey:"label",stroke:l?"#9ca3af":"#6b7280",tick:{fontSize:12,fill:l?"#9ca3af":"#6b7280"},angle:a.length>8?-45:0,textAnchor:a.length>8?"end":"middle",height:a.length>8?80:50}),e.jsx(Ge,{stroke:l?"#9ca3af":"#6b7280",tick:{fontSize:12,fill:l?"#9ca3af":"#6b7280"},tickFormatter:s}),e.jsx(we,{content:e.jsx(u,{})}),e.jsx(Wt,{dataKey:"value",fill:c,radius:[8,8,0,0],children:a.map((o,d)=>e.jsx(Ze,{fill:o.color||c},`cell-${d}`))})]})})}function Ba({dateFrom:a,dateTo:t,locationId:n,onExport:s}){const r=localStorage.getItem("businessTimezone")||_,{data:i,loading:l}=B((d,g,p)=>F.getClientRetentionReport(d,g,p,n),{dateFrom:a,dateTo:t,locationId:n}),{data:c,loading:u}=B((d,g,p)=>F.getClientLifetimeValueReport(p,{limit:10,locationId:n}),{dateFrom:a,dateTo:t,locationId:n}),o=d=>{const g=(c==null?void 0:c.topClientsByRevenue)||[];if(g.length===0){alert("No client data to export");return}const p=`client-analytics-${a}-to-${t}`,y=g.map(x=>{var v;return{client:x.clientName,lifetimeValue:(x.totalRevenueCents/100).toFixed(2),visits:x.totalVisits,tier:((v=x.tier)==null?void 0:v.toUpperCase())||"N/A"}});if(d==="csv"){const x=X(y,{client:"Client",lifetimeValue:"Lifetime Value",visits:"Visits",tier:"Tier"});J(x,p)}else d==="pdf"?te(y,p,"Client Analytics Report",[{header:"Client",dataKey:"client"},{header:"Lifetime Value",dataKey:"lifetimeValue"},{header:"Visits",dataKey:"visits"},{header:"Tier",dataKey:"tier"}]):alert("Excel export coming soon!");s==null||s(d)};return l||u?e.jsx(q,{message:"Loading client analytics..."}):e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(ae,{onExport:o,disabled:!c})}),e.jsx(ue,{tab:"clients",dateFrom:a,dateTo:t,locationId:n}),i&&e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(R,{label:"Total Clients",value:i.summary.totalClients,icon:ke,useThemeColor:!0}),e.jsx(R,{label:"Active Clients",value:i.summary.activeClients,subtitle:`${i.summary.retentionRate}% retention`,icon:Xe,useThemeColor:!0}),e.jsx(R,{label:"New Clients",value:i.summary.newClients,subtitle:"This period",icon:Je,useThemeColor:!0}),e.jsx(R,{label:"At Risk",value:i.summary.inactiveClients,subtitle:`${i.summary.churnRate}% churn`,icon:Re,color:"orange"})]}),c&&e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx($,{title:"Revenue by Client Tier",subtitle:"Client value distribution",children:e.jsx(ne,{data:c.revenueByTier.map(d=>({label:d.tier.toUpperCase(),value:d.totalRevenueCents,color:d.tier==="vip"?"#8b5cf6":d.tier==="premium"?"#3b82f6":d.tier==="regular"?"#10b981":"#6b7280"})),formatValue:j,height:250})}),e.jsx($,{title:"Top Clients by Revenue",subtitle:"Top 10 clients",children:e.jsx(M,{columns:[{key:"clientName",label:"Client"},{key:"totalRevenueCents",label:"Lifetime Value",align:"right",render:d=>j(d.totalRevenueCents)},{key:"totalVisits",label:"Visits",align:"right"},{key:"tier",label:"Tier",render:d=>e.jsx("span",{className:`px-2 py-1 rounded text-xs font-medium ${d.tier==="vip"?"bg-purple-100 text-purple-700":d.tier==="premium"?"bg-blue-100 text-blue-700":d.tier==="regular"?"bg-green-100 text-green-700":"bg-gray-100 text-gray-700"}`,children:d.tier.toUpperCase()})}],data:c.topClientsByRevenue,keyExtractor:d=>d.clientId.toString()})})]}),i&&i.inactiveClients.length>0&&e.jsx($,{title:"Inactive Clients",subtitle:"Clients who haven't visited recently",children:e.jsx(M,{columns:[{key:"clientName",label:"Client"},{key:"lastVisit",label:"Last Visit",render:d=>new Date(d.lastVisit).toLocaleDateString("en-US",{timeZone:r})},{key:"daysSinceLastVisit",label:"Days Ago",align:"right"},{key:"totalPastVisits",label:"Past Visits",align:"right"},{key:"totalLifetimeRevenueCents",label:"Lifetime Revenue",align:"right",render:d=>j(d.totalLifetimeRevenueCents)}],data:i.inactiveClients.slice(0,10),keyExtractor:d=>d.clientId.toString()})})]})}function Ma({dateFrom:a,dateTo:t,locationId:n,onExport:s}){var g,p,y;const{data:r,loading:i}=B((x,v,C)=>F.getStaffPerformanceReport(x,v,C,n),{dateFrom:a,dateTo:t,locationId:n}),{data:l}=B((x,v,C)=>F.getSalesReport(x,v,C,{groupBy:"staff",includePreviousPeriod:!0,locationId:n}),{dateFrom:a,dateTo:t,locationId:n}),c=x=>{if(!r)return;const v=`staff-performance-${a}-to-${t}`,C=r.staffPerformance.map(b=>({staffName:b.staffName,appointments:b.totalAppointments,completionRate:`${b.completionRate}%`,revenue:(b.totalRevenueCents/100).toFixed(2),tips:((b.totalTipsCents||0)/100).toFixed(2)}));if(x==="csv"){const b=X(C,{staffName:"Staff Member",appointments:"Appointments",completionRate:"Completion Rate",revenue:"Revenue",tips:"Tips"});J(b,v)}else x==="pdf"?te(C,v,"Staff Performance Report",[{header:"Staff Member",dataKey:"staffName"},{header:"Appointments",dataKey:"appointments"},{header:"Completion",dataKey:"completionRate"},{header:"Revenue",dataKey:"revenue"},{header:"Tips",dataKey:"tips"}]):alert("Excel export coming soon!");s==null||s(x)};if(i)return e.jsx(q,{message:"Loading staff performance..."});if(!r)return e.jsx("div",{className:"text-center py-12 text-gray-500",children:"No staff data available"});const u=r.staffPerformance.reduce((x,v)=>x+v.totalRevenueCents,0),o=((g=l==null?void 0:l.summary)==null?void 0:g.totalRevenueCents)??u,d=r.
7staffPerformance.reduce((x,v)=>x+v.totalAppointments,0);return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(ae,{onExport:c,disabled:!r})}),e.jsx(ue,{tab:"staff",dateFrom:a,dateTo:t,locationId:n}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[e.jsx(R,{label:"Total Revenue",value:j(o),change:(p=l==null?void 0:l.comparison)==null?void 0:p.changePercentage,trend:(y=l==null?void 0:l.comparison)==null?void 0:y.trend,icon:Z,useThemeColor:!0}),e.jsx(R,{label:"Total Appointments",value:d,icon:se,useThemeColor:!0}),e.jsx(R,{label:"Staff Members",value:r.staffPerformance.length,icon:jt,useThemeColor:!0})]}),e.jsx($,{title:"Revenue by Staff",subtitle:"Top performers",children:e.jsx(ne,{data:r.staffPerformance.slice(0,10).map(x=>({label:x.staffName,value:x.totalRevenueCents})),formatValue:j,height:300})}),e.jsx($,{title:"Staff Performance Details",subtitle:"All staff metrics",children:e.jsx(M,{columns:[{key:"rank",label:"#",align:"center"},{key:"staffName",label:"Staff Member"},{key:"totalAppointments",label:"Appointments",align:"right"},{key:"completionRate",label:"Completion %",align:"right",render:x=>`${x.completionRate}%`},{key:"totalRevenueCents",label:"Revenue",align:"right",render:x=>j(x.totalRevenueCents)},{key:"totalTipsCents",label:"Tips",align:"right",render:x=>j(x.totalTipsCents||0)}],data:r.staffPerformance,keyExtractor:x=>x.staffId.toString()})})]})}function za({dateFrom:a,dateTo:t,locationId:n,onExport:s}){const{data:r,loading:i}=B((o,d,g)=>F.getAppointmentVolumeReport(o,d,g,n),{dateFrom:a,dateTo:t,locationId:n}),{data:l,loading:c}=B((o,d,g)=>F.getCancellationAnalysisReport(o,d,g,{locationId:n}),{dateFrom:a,dateTo:t,locationId:n}),u=o=>{var y;if(!r)return;const d=`appointment-analytics-${a}-to-${t}`,g=r.volumeByDay.map(x=>({day:x.dayOfWeek,appointments:x.totalAppointments,completed:x.completedAppointments||0,cancelled:x.cancelledAppointments||0})),p=((y=l==null?void 0:l.highRiskClients)==null?void 0:y.slice(0,10).map(x=>({client:x.clientName,totalAppts:x.totalAppointments,cancelled:x.cancelledAppointments,noShows:x.noShowAppointments,reliabilityScore:x.reliabilityScore})))||[];if(o==="csv"){const x=X(g,{day:"Day of Week",appointments:"Total Appointments",completed:"Completed",cancelled:"Cancelled"});if(J(x,d),p.length>0){const v=X(p,{client:"Client",totalAppts:"Total Appts",cancelled:"Cancelled",noShows:"No-Shows",reliabilityScore:"Reliability Score"});J(v,`${d}-high-risk-clients`)}}else o==="pdf"?(te(g,d,"Appointment Analytics Report",[{header:"Day",dataKey:"day"},{header:"Appointments",dataKey:"appointments"},{header:"Completed",dataKey:"completed"},{header:"Cancelled",dataKey:"cancelled"}]),p.length>0&&te(p,`${d}-high-risk-clients`,"High-Risk Clients",[{header:"Client",dataKey:"client"},{header:"Total Appts",dataKey:"totalAppts"},{header:"Cancelled",dataKey:"cancelled"},{header:"No-Shows",dataKey:"noShows"},{header:"Reliability",dataKey:"reliabilityScore"}])):alert("Excel export coming soon!");s==null||s(o)};return i||c?e.jsx(q,{message:"Loading appointment analytics..."}):r?e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(ae,{onExport:u,disabled:!r})}),e.jsx(ue,{tab:"appointments",dateFrom:a,dateTo:t,locationId:n}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(R,{label:"Total Appointments",value:r.summary.totalAppointments,icon:se,useThemeColor:!0}),e.jsx(R,{label:"Completion Rate",value:`${r.summary.completedRate}%`,icon:Ue,useThemeColor:!0}),e.jsx(R,{label:"Cancellation Rate",value:`${(l==null?void 0:l.summary.cancellationRate)||0}%`,icon:be,color:"orange"}),e.jsx(R,{label:"No-Show Rate",value:`${(l==null?void 0:l.summary.noShowRate)||0}%`,icon:Re,color:"red"})]}),e.jsx($,{title:"Appointments by Day of Week",subtitle:"Weekly distribution",children:e.jsx(ne,{data:r.volumeByDay.map(o=>({label:o.dayOfWeek.substring(0,3),value:o.totalAppointments})),height:250})}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx($,{title:"Booking Lead Time",subtitle:"How far in advance clients book",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-center p-4 bg-blue-50 rounded-lg",children:[e.jsx("span",{className:"text-sm font-medium text-gray-700",children:"Average Lead Time"}),e.jsxs("span",{className:"text-lg font-bold text-blue-600",children:[r.bookingLeadTime.averageLeadTimeDays," days"]})]}),e.jsxs("div",{className:"flex justify-between items-center p-4 bg-gray-50 rounded-lg",children:[e.jsx("span",{className:"text-sm font-medium text-gray-700",children:"Same-Day Bookings"}),e.jsxs("span",{className:"text-lg font-bold text-gray-900",children:[r.bookingLeadTime.sameDayPercentage,"%"]})]})]})}),e.jsx($,{title:"Peak Periods",subtitle:"Busiest times",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-gray-700 mb-2",children:"Peak Days"}),e.jsx("div",{className:"flex gap-2",children:r.peakPeriods.peakDays.map(o=>e.jsx("span",{className:"px-3 py-1 bg-blue-100 text-blue-700 rounded text-sm font-medium",children:o},o))})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-gray-700 mb-2",children:"Peak Hours"}),e.jsx("div",{className:"flex gap-2",children:r.peakPeriods.peakH
7ours.map(o=>e.jsxs("span",{className:"px-3 py-1 bg-purple-100 text-purple-700 rounded text-sm font-medium",children:[o,":00"]},o))})]})]})})]}),l&&l.highRiskClients.length>0&&e.jsx($,{title:"High-Risk Clients",subtitle:"Frequent cancellers or no-shows",children:e.jsx(M,{columns:[{key:"clientName",label:"Client"},{key:"totalAppointments",label:"Total Appts",align:"right"},{key:"cancelledAppointments",label:"Cancelled",align:"right"},{key:"noShowAppointments",label:"No-Shows",align:"right"},{key:"reliabilityScore",label:"Reliability Score",align:"right",render:o=>e.jsx("span",{className:`px-2 py-1 rounded text-xs font-medium ${o.reliabilityScore>=80?"bg-green-100 text-green-700":o.reliabilityScore>=60?"bg-yellow-100 text-yellow-700":"bg-red-100 text-red-700"}`,children:o.reliabilityScore})}],data:l.highRiskClients.slice(0,10),keyExtractor:o=>o.clientId.toString()})})]}):e.jsx("div",{className:"text-center py-12 text-gray-500",children:"No appointment data available"})}function Ka({dateFrom:a,dateTo:t,locationId:n,onExport:s}){var g,p,y;const{data:r,loading:i}=B((x,v,C)=>F.getServicePerformanceReport(x,v,C,n),{dateFrom:a,dateTo:t,locationId:n}),{data:l}=B((x,v,C)=>F.getSalesReport(x,v,C,{groupBy:"service",includePreviousPeriod:!0,locationId:n}),{dateFrom:a,dateTo:t,locationId:n}),c=x=>{if(!r)return;const v=`service-performance-${a}-to-${t}`,C=r.servicePerformance.map(b=>({service:b.serviceName,bookings:b.totalBookings,completionRate:`${b.completionRate}%`,revenue:(b.totalRevenueCents/100).toFixed(2),avgDuration:`${b.averageDurationMinutes} min`}));if(x==="csv"){const b=X(C,{service:"Service",bookings:"Bookings",completionRate:"Completion Rate",revenue:"Revenue",avgDuration:"Avg Duration"});J(b,v)}else x==="pdf"?te(C,v,"Service Performance Report",[{header:"Service",dataKey:"service"},{header:"Bookings",dataKey:"bookings"},{header:"Completion",dataKey:"completionRate"},{header:"Revenue",dataKey:"revenue"},{header:"Avg Duration",dataKey:"avgDuration"}]):alert("Excel export coming soon!");s==null||s(x)};if(i)return e.jsx(q,{message:"Loading service analytics..."});if(!r)return e.jsx("div",{className:"text-center py-12 text-gray-500",children:"No service data available"});const u=r.servicePerformance.reduce((x,v)=>x+v.totalRevenueCents,0),o=((g=l==null?void 0:l.summary)==null?void 0:g.totalRevenueCents)??u,d=r.servicePerformance.reduce((x,v)=>x+v.totalBookings,0);return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(ae,{onExport:c,disabled:!r})}),e.jsx(ue,{tab:"services",dateFrom:a,dateTo:t,locationId:n}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[e.jsx(R,{label:"Total Service Revenue",value:j(o),change:(p=l==null?void 0:l.comparison)==null?void 0:p.changePercentage,trend:(y=l==null?void 0:l.comparison)==null?void 0:y.trend,icon:Z,useThemeColor:!0}),e.jsx(R,{label:"Total Bookings",value:d,icon:se,useThemeColor:!0}),e.jsx(R,{label:"Services Offered",value:r.servicePerformance.length,icon:Ve,useThemeColor:!0})]}),e.jsx($,{title:"Top Services by Revenue",subtitle:"Best performers",children:e.jsx(ne,{data:r.topServices.byRevenue.map(x=>({label:x.serviceName,value:x.revenueCents})),formatValue:j,height:300})}),e.jsx($,{title:"All Services Performance",subtitle:"Complete breakdown",children:e.jsx(M,{columns:[{key:"popularityRank",label:"#",align:"center"},{key:"serviceName",label:"Service"},{key:"totalBookings",label:"Bookings",align:"right"},{key:"completionRate",label:"Completion %",align:"right",render:x=>`${x.completionRate}%`},{key:"totalRevenueCents",label:"Revenue",align:"right",render:x=>j(x.totalRevenueCents)},{key:"averageDurationMinutes",label:"Avg Duration",align:"right",render:x=>`${x.averageDurationMinutes} min`}],data:r.servicePerformance,keyExtractor:x=>x.serviceId.toString()})}),r.underperformingServices&&r.underperformingServices.length>0&&e.jsx($,{title:"Underperforming Services",subtitle:"Services needing attention",children:e.jsx(M,{columns:[{key:"serviceName",label:"Service"},{key:"bookings",label:"Bookings",align:"right"},{key:"completionRate",label:"Completion %",align:"right",render:x=>`${x.completionRate}%`}],data:r.underperformingServices,keyExtractor:x=>x.serviceId.toString()})})]})}function Ia({dateFrom:a,dateTo:t,locationId:n}){var H,V;const{primaryColor:s,darkMode:r}=z(),[i,l]=N.useState("summary"),[c,u]=N.useState(void 0),[o,d]=N.useState(""),[g,p]=N.useState(null),[y,x]=N.useState(!1),[v,C]=N.useState(null),b=B((m,k,D)=>F.getPayrollSummaryReport(m,k,D,n),{dateFrom:a,dateTo:t,locationId:n});N.useEffect(()=>{(async()=>
7{if(i==="detailed")try{x(!0),C(null),p(null);const k=localStorage.getItem("accessToken");if(!k)throw new Error("No access token found");console.log("[PayrollDashboard] Fetching detailed report:",{dateFrom:a,dateTo:t,staffId:c});const D=await F.getDetailedPayrollReport(a,t,k,c,n);console.log("[PayrollDashboard] Received data:",D),p(D)}catch(k){const D=k instanceof Error?k:new Error("Failed to load detailed payroll");console.error("[PayrollDashboard] Error loading detailed data:",k),C(D)}finally{x(!1)}})()},[a,t,c,i,n]);const T=(m,k)=>{u(m),d(k),l("detailed")},h=()=>{u(void 0),d(""),l("summary"),p(null)},f=async m=>{if(!m){alert("Cannot remove POS transactions - only appointments");return}if(!confirm("Are you sure you want to remove this from payroll? This will permanently remove the entry from the report."))return;const k=localStorage.getItem("accessToken");if(!k){alert("Not authenticated");return}if(console.log("[PayrollDashboard] Removing appointment from payroll:",m),g&&"records"in g){const D=g.records.filter(K=>K.appointmentId!==m);p({...g,records:D})}try{await F.forceDeleteAppointmentFromPayroll(m,k),console.log("[PayrollDashboard] Successfully deleted appointment")}catch(D){console.log("[PayrollDashboard] Force-delete failed:",D.code||D.message)}console.log("[PayrollDashboard] Reloading data..."),x(!0);try{const D=await F.getDetailedPayrollReport(a,t,k,c,n);console.log("[PayrollDashboard] Reloaded data:",D),p(D)}catch(D){console.error("[PayrollDashboard] Error reloading:",D)}x(!1),console.log("[PayrollDashboard] Done")};if(b.loading||i==="detailed"&&y)return e.jsx(q,{message:"Loading payroll data..."});const w=(H=b.data)==null?void 0:H.summary,A=((V=b.data)==null?void 0:V.staffPayrolls)||[],U=g&&"records"in g?g.records:[];return i==="detailed"&&v&&console.error("Detailed payroll error:",v),w?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:`flex gap-2 border-b items-center ${r?"border-gray-700":"border-gray-200"}`,children:[c&&i==="detailed"&&e.jsx("button",{onClick:h,className:`px-4 py-2 flex items-center gap-2 ${r?"hover:text-gray-300":"hover:text-gray-700"}`,style:{color:s},children:"â Back to Summary"}),e.jsx("button",{onClick:()=>{u(void 0),d(""),l("summary")},className:`px-6 py-3 font-medium border-b-2 transition-colors ${i==="summary"?"":`border-transparent ${r?"text-gray-400 hover:text-gray-300":"text-gray-500 hover:text-gray-700"}`}`,style:{borderBottomColor:i==="summary"?s:void 0,color:i==="summary"?s:void 0},children:"Summary"}),e.jsx("button",{onClick:()=>{u(void 0),d("All Staff"),l("detailed")},className:`px-6 py-3 font-bold border-b-2 transition-colors rounded-t-lg ${i==="detailed"&&!c?"text-white":`border-transparent ${r?"text-gray-400 hover:text-gray-300":"text-gray-500 hover:text-gray-700"}`}`,style:{borderBottomColor:i==="detailed"&&!c?s:void 0,color:i==="detailed"&&!c?"white":void 0,backgroundColor:i==="detailed"&&!c?s:void 0},children:"ð View All Staff Details"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-6 gap-4",children:[e.jsx(R,{label:"Total Payroll",value:j(w.totalPayCents),icon:Z,useThemeColor:!0,subtitle:`${w.totalStaff} staff members`}),e.jsx(R,{label:"Total Hours",value:w.totalHoursWorked.toFixed(1),icon:De,useThemeColor:!0,subtitle:`${w.totalAppointments} appointments`}
7),e.jsx(R,{label:"Hourly Earnings",value:j(w.totalWagesCents),icon:De,useThemeColor:!0,subtitle:"Hourly staff only"}),e.jsx(R,{label:"Total Commissions",value:j(w.totalCommissionCents),icon:Z,useThemeColor:!0,subtitle:`${w.totalRevenueCents>0?(w.totalCommissionCents/w.totalRevenueCents*100).toFixed(1):"0.0"}% of revenue`}),e.jsx(R,{label:"Total Tips",value:j(w.totalTipsCents),icon:Oe,useThemeColor:!0,subtitle:`${(w.totalTipsCents/w.totalRevenueCents*100||0).toFixed(1)}% of revenue`}),e.jsx(R,{label:"Labor Cost %",value:`${w.laborCostPercentage.toFixed(1)}%`,icon:Mt,useThemeColor:!0,subtitle:`${j(w.totalPayCents-w.totalTipsCents)} base pay`})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsx($,{title:"Breakdown",subtitle:"Pay components",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex justify-between items-center py-2 border-b",children:[e.jsx("span",{className:"text-gray-600",children:"Hourly Wages"}),e.jsx("span",{className:"font-semibold",children:j(w.totalWagesCents)})]}),e.jsxs("div",{className:"flex justify-between items-center py-2 border-b",children:[e.jsx("span",{className:"text-gray-600",children:"Commissions"}),e.jsx("span",{className:"font-semibold",children:j(w.totalCommissionCents)})]}),e.jsxs("div",{className:"flex justify-between items-center py-2",children:[e.jsx("span",{className:"text-gray-600",children:"Tips"}),e.jsx("span",{className:"font-semibold",style:{color:s},children:j(w.totalTipsCents)})]})]})}),e.jsx($,{title:"Averages",subtitle:"Per staff & hour",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex justify-between items-center py-2 border-b",children:[e.jsx("span",{className:"text-gray-600",children:"Per Staff"}),e.jsx("span",{className:"font-semibold",children:j(w.averagePayPerStaffCents)})]}),e.jsxs("div",{className:"flex justify-between items-center py-2",children:[e.jsx("span",{className:"text-gray-600",children:"Per Hour"}),e.jsx("span",{className:"font-semibold",children:j(w.averagePayPerHourCents)})]})]})}),e.jsx($,{title:"Revenue",subtitle:"Total generated",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex justify-between items-center py-2 border-b",children:[e.jsx("span",{className:"text-gray-600",children:"Total Revenue"}),e.jsx("span",{className:"font-semibold",children:j(w.totalRevenueCents)})]}),e.jsxs("div",{className:"flex justify-between items-center py-2",children:[e.jsx("span",{className:"text-gray-600",children:"Appointments"}),e.jsx("span",{className:"font-semibold",children:w.totalAppointments})]})]})})]}),i==="summary"&&e.jsx($,{title:"Staff Payroll Summary",subtitle:"Click on a staff member to view detailed transactions",children:e.jsx(M,{columns:[{key:"staffName",label:"Staff Member",render:m=>e.jsx("button",{onClick:()=>T(m.staffId,m.staffName),className:"hover:underline font-medium text-left",style:{color:s},children:m.staffName})},{key:"payType",label:"Pay Type",render:m=>{var k,D;return m.hybridCalculation==="hourly_gap"?e.jsx("span",{className:"px-2 py-1 rounded text-xs font-medium bg-amber-100 text-amber-800",children:"Commission or Hourly"}):((k=m.payType)==null?void 0:k.charAt(0).toUpperCase())+((D=m.payType)==null?void 0:D.slice(1))||"Unknown"}},{key:"totalHoursWorked",label:"Hours",align:"right",render:m=>{var k;return m.hybridCalculation==="hourly_gap"&&m.idleHours!==void 0?e.jsxs("div",{children:[e.jsxs("div",{className:"font-medium",children:[m.totalHoursWorked.toFixed(1)," total"]}),e.jsxs("div",{className:"text-xs text-gray-500",children:[m.idleHours.toFixed(1)," idle · ",((k=m.serviceHours)==null?void 0:k.toFixed(1))||"0.0"," service"]})]}):m.totalHoursWorked.toFixed(1)}}
7,{key:"basePay.hourlyWagesCents",label:"Hourly Earnings",align:"right",render:m=>e.jsxs("div",{children:[e.jsx("span",{className:m.basePay.hourlyWagesCents>0?"font-medium":"text-gray-400",children:j(m.basePay.hourlyWagesCents)}),m.hybridCalculation==="hourly_gap"&&m.idleHours!==void 0&&m.basePay.hourlyWagesCents>0&&e.jsxs("div",{className:"text-xs text-gray-500",children:[m.idleHours.toFixed(1)," idle hrs"]})]})},{key:"completedAppointments",label:"Appts",align:"right"},{key:"totalRevenueCents",label:"Revenue",align:"right",render:m=>j(m.totalRevenueCents)},{key:"totalTipsCents",label:"Tips",align:"right",render:m=>e.jsx("span",{className:"font-medium",style:{color:s},children:j(m.totalTipsCents)})},{key:"basePay.commissionCents",label:"Commission",align:"right",render:m=>e.jsx("span",{className:m.basePay.commissionCents>0?"font-medium":"text-gray-400",children:j(m.basePay.commissionCents)})},{key:"totalPayCents",label:"Total Pay",align:"right",render:m=>e.jsx("span",{className:"font-bold",style:{color:s},children:j(m.totalPayCents)})}],data:A,keyExtractor:m=>m.staffId.toString()})}),i==="detailed"&&e.jsxs(e.Fragment,{children:[c&&e.jsxs("div",{className:`border rounded-lg p-4 mb-6 ${r?"bg-gray-700 border-gray-600":"bg-blue-50 border-blue-200"}`,style:{backgroundColor:r?void 0:`${s}15`,borderColor:r?void 0:`${s}40`},children:[e.jsxs("h3",{className:`text-lg font-semibold ${r?"text-gray-100":"text-blue-900"}`,children:[o,"'s Detailed Payroll"]}),e.jsx("p",{className:`text-sm mt-1 ${r?"text-gray-300":"text-blue-700"}`,children:"All transactions, commissions, and tips for this staff member"})]}),e.jsxs($,{title:c?`${o} - Transaction Details`:"All Staff - Detailed Payroll Report",subtitle:"Individual transactions with service cost, commission, and tips",children:[e.jsx(M,{columns:[{key:"actions",label:"",align:"center",render:m=>m.appointmentId?e.jsx("button",{onClick:()=>f(m.appointmentId),className:"p-1 text-red-500 hover:text-red-700 hover:bg-red-50 rounded transition-colors",title:"Unmark as paid",children:e.jsx(_e,{className:"w-4 h-4"})}):null},{key:"date",label:"Date",render:m=>{const[k,D,K]=m.date.split("-");return new Date(parseInt(k),parseInt(D)-1,parseInt(K)).toLocaleDateString("en-US",{month:"short",day:"numeric"})}},...c?[]:[{key:"staffName",label:"Staff"}],{key:"clientName",label:"Client"},{key:"serviceName",label:"Service/Product",render:m=>e.jsxs("div",{children:[e.jsx("div",{children:m.serviceName}),m.addOns&&m.addOns.length>0&&e.jsx("div",{className:"text-xs text-gray-500 mt-1",children:m.addOns.map((k,D)=>e.jsxs("div",{children:["+ ",k.name," (",k.durationMinutes," min, ",j(k.priceCents),")"]},D))})]})},{key:"durationMinutes",label:"Duration",align:"right",render:m=>m.durationMinutes?`${m.durationMinutes} min`:"-"},{key:"revenueCents",label:"Service Cost",align:"right",render:m=>j(m.revenueCents)},{key:"hourlyPayCents",label:"Appt Hourly",align:"right",render:m=>e.jsx("span",{className:m.hourlyPayCents>0?"font-medium":"text-gray-400",style:{color:m.hourlyPayCents>0?s:void 0},children:m.payType==="hourly"||m.payType==="hybrid"?"(clock)":j(m.hourlyPayCents||0)})},{key:"commissionPayCents",label:"Commission",align:"right",render:m=>e.jsxs("div",{className:m.commissionPayCents>0?"font-medium":"text-gray-400",style:{color:m.commissionPayCents>0?s:void 0},children:[e.jsx("div",{children:j(m.commissionPayCents||0)}),m.commissionRate!==null&&m.commissionRate!==void 0&&m.commissionPayCents>0&&e.jsxs("div",{className:"text-xs text-gray-500 font-normal",children:[(m.commissionRate/100).toFixed(0),"%"]})]})},{key:"tipCents",label:"Tip",align:"right",render:m=>e.jsx("span",{className:m.tipCents>0?"font-medium":"text-gray-400",style:{color:m.tipCents>0?s:void 0},children:j(m.tipCents)})},{key:"paymentMethod",label:"Payment",align:"center",render:m=>{var E;const k=()=>({backgroundColor:`${s}${Math.round(parseFloat(r?"0.2":"0.1")*255).toString(16).padStart(2,"0")}`,color:s,borderColor:s});if(m.isSplitPayment&&((E=m.paymentBreakdown)==null?void 0:E.length)>1){const I=k();return e.jsxs("div",{className:"flex flex-col items-center space-y-1",children:[e.jsx("span",{className:"px-2 py-0.5 rounded text-xs font-medium border",style:I,children:"SPLIT"}),e.jsx("div",{className:"text-xs text-gray-600 space-y-0.5",children:m.paymentBreakdown.map((O,P)=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-medium border",style:I,children:O.method}),e.jsxs("span",{className:"text-gray-500",children:["$",(O.amountCents/100).toFixed(2)]}),O.cardLastFour&&e.jsxs("span",{className:"text-gray-400",children:["â¢â¢",O.cardLastFour]})]},P))})]})}const D=m.paymentMethod||"N/A",K=k();return e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("span",{className:"px-2 py-0.5 rounded text-xs font-medium border",style:K,children:D}),m.cardLastFour&&e.jsxs("span",{className:"text-xs text-gray-500 mt-0.5",children:["â¢â¢â¢â¢ ",m.cardLastFour]})]})}},{key:"staffPayCents",label:"Total Earned",align:"right",render:m=>e.jsx("span",{className:"font-semibold",style:{color:s},children:j(m.staffPayCents+m.tipCents)})}],data:U,keyExtractor:m=>m.recordId?m.recordId:m.appointmentId?`appt-${m.appointmentId}`:m.posItemId?`pos-${m.posItemId}`:`${m.staffId}-${m.date}-${m.serviceName}-${m.revenueCents}`}),e.jsxs("div",{className:"mt-6 pt-4 border-t border-gray-200",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-6 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-gray-600",children:"Total Records"}),e.jsx("div",{className:"text-xl font-bold",children:g&&"summary"in g?g.summary.totalRecords:0})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-gray-600",children:"Service Revenue"}),e.jsx("div",{className:"text-xl font-bold",children:j(g&&"summary"in g?g.summary.totalRevenueCents:0)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-gray-600",children:"Hourly Pay"}),e.jsx("div",{className:"text-xl font-bold",style:{color:s},children:j(g&&"summary"in g&&g.summary.totalHourlyPayCents||0)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-gray-600",children:"Commission"}),e.jsx("div",{className:"text-xl font-bold",style:{color:s},children:j(g&&"summary"in g&&g.summary.totalCommissionPayCents||0)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-gray-600",children:"Tips"}),e.jsx("div",{className:"text-xl font-bold",style:{color:s},children:j(g&&"summary"in g?g.summary.totalTipsCents:0)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-gray-600",children:"Total Earnings"}),e.jsx("div",{className:"text-xl font-bold",style:{color:s},children:j(g&&"summary"in g?g.summary.totalStaffPayCents+g.summary.totalTipsCents:0)})]})]}),e.jsxs("div",{className:`pt-6 border-t ${r?"border-gray-700":"border-gray-200"}`,children:[e.jsx("h4",{className:`text-sm font-semibold mb-4 ${r?"text-gray-300":"text-gray-700"}`,children:"Payment Method Breakdown"}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-4",children:(()=>{const m={cash:0,card:0,stripe:0,terminal:0,gift_card:0,membership:0,standaloneTips:0,other:0};
7U.forEach(E=>{var L;const I=E.revenueCents||0,O=E.tipCents||0,P=I+O;if(!E.appointmentId&&O>0&&I===0){m.standaloneTips+=O;return}if(E.isSplitPayment&&((L=E.paymentBreakdown)==null?void 0:L.length)>0)E.paymentBreakdown.forEach(W=>{const Pe=W.method.toLowerCase();Pe in m?m[Pe]+=W.amountCents||0:m.other+=W.amountCents||0});else{const W=(E.paymentMethod||"other").toLowerCase();W in m?m[W]+=P:m.other+=P}});const k=Object.values(m).reduce((E,I)=>E+I,0),K=((E,I)=>{const O=parseInt(E.replace("#",""),16),P=Math.max(0,Math.floor((O>>16)*(1-I))),L=Math.max(0,Math.floor((O>>8&255)*(1-I))),W=Math.max(0,Math.floor((O&255)*(1-I)));return`#${(P<<16|L<<8|W).toString(16).padStart(6,"0")}`})(s,.2);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`p-4 rounded-lg border-2 ${r?"bg-gray-800":"bg-white"}`,style:{borderColor:s},children:[e.jsx("div",{className:`text-xs font-medium ${r?"text-gray-300":"text-gray-700"}`,children:"Cash"}),e.jsx("div",{className:"text-2xl font-bold mt-2",style:{color:s},children:j(m.cash)}),e.jsxs("div",{className:"text-xs text-gray-500 mt-1",children:[k>0?(m.cash/k*100).toFixed(1):0,"% of total"]})]}),e.jsxs("div",{className:`p-4 rounded-lg border-2 ${r?"bg-gray-800":"bg-white"}`,style:{borderColor:K},children:[e.jsx("div",{className:`text-xs font-medium ${r?"text-gray-300":"text-gray-700"}`,children:"Card/Stripe"}),e.jsx("div",{className:"text-2xl font-bold mt-2",style:{color:K},children:j(m.card+m.stripe+m.terminal)}),e.jsxs("div",{className:"text-xs text-gray-500 mt-1",children:[k>0?((m.card+m.stripe+m.terminal)/k*100).toFixed(1):0,"% of total"]})]}),e.jsxs("div",{className:`p-4 rounded-lg border-2 ${r?"bg-gray-800":"bg-white"}`,style:{borderColor:s},children:[e.jsx("div",{className:`text-xs font-medium ${r?"text-gray-300":"text-gray-700"}`,children:"Gift Card"}),e.jsx("div",{className:"text-2xl font-bold mt-2",style:{color:s}
7,children:j(m.gift_card)}),e.jsxs("div",{className:"text-xs text-gray-500 mt-1",children:[k>0?(m.gift_card/k*100).toFixed(1):0,"% of total"]})]}),e.jsxs("div",{className:`p-4 rounded-lg border-2 ${r?"bg-gray-800":"bg-white"}`,style:{borderColor:K},children:[e.jsx("div",{className:`text-xs font-medium ${r?"text-gray-300":"text-gray-700"}`,children:"Membership"}),e.jsx("div",{className:"text-2xl font-bold mt-2",style:{color:K},children:j(m.membership)}),e.jsxs("div",{className:"text-xs text-gray-500 mt-1",children:[k>0?(m.membership/k*100).toFixed(1):0,"% of total"]})]}),e.jsxs("div",{className:`p-4 rounded-lg border-2 ${r?"bg-gray-800":"bg-white"}`,style:{borderColor:s},children:[e.jsx("div",{className:`text-xs font-medium ${r?"text-gray-300":"text-gray-700"}`,children:"Standalone Tips"}),e.jsx("div",{className:"text-2xl font-bold mt-2",style:{color:s},children:j(m.standaloneTips)}),e.jsxs("div",{className:"text-xs text-gray-500 mt-1",children:[k>0?(m.standaloneTips/k*100).toFixed(1):0,"% of total"]})]}),e.jsxs("div",{className:`p-4 rounded-lg border-2 ${r?"bg-gray-800":"bg-white"}`,style:{borderColor:s},children:[e.jsx("div",{className:`text-xs font-medium ${r?"text-gray-300":"text-gray-700"}`,children:"Total"}),e.jsx("div",{className:"text-2xl font-bold mt-2",style:{color:s},children:j(k)}),e.jsxs("div",{className:"text-xs text-gray-500 mt-1",children:[U.length," transactions"]})]})]})})()})]})]})]}),(g==null?void 0:g.staffTimeClock)&&g.staffTimeClock.length>0&&e.jsxs($,{title:"Time Clock Hours",subtitle:"Clocked hours and hourly pay for staff",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4 text-sm text-gray-600",children:[e.jsx(zt,{className:"w-4 h-4"}),e.jsx("span",{children:"Staff members who have clocked in during this period (hourly pay calculated from time clock)"})]}),e.jsx(M,{columns:[{key:"staffName",label:"Staff Member"},{key:"payType",label:"Pay Type",render:m=>{var K,E;const k={hourly:"bg-blue-100 text-blue-800",commission:"bg-green-100 text-green-800",hybrid:"bg-purple-100 text-purple-800",hourly_gap:"bg-amber-100 text-amber-800"},D={hourly:"Hourly",commission:"Commission",hybrid:"Hybrid",hourly_gap:"Comm or Hourly"};return e.jsx("span",{className:`px-2 py-1 rounded text-xs font-medium ${k[m.payType]||"bg-gray-100 text-gray-800"}`,children:D[m.payType]||((K=m.payType)==null?void 0:K.charAt(0).toUpperCase())+((E=m.payType)==null?void 0:E.slice(1))||"Unknown"})}},{key:"totalHoursClockedIn",label:"Hours Clocked",align:"right",render:m=>{var k;return e.jsxs("div",{children:[e.jsxs("span",{className:"font-semibold",children:[m.totalHoursClockedIn.toFixed(2)," hrs"]}),m.payType==="hourly_gap"&&m.idleHours!==void 0&&e.jsxs("div",{className:"text-xs text-gray-500 mt-0.5",children:[m.idleHours.toFixed(1)," idle · ",((k=m.serviceHours)==null?void 0:k.toFixed(1))||"0.0"," service"]})]})}},{key:"hourlyRateCents",label:"Hourly Rate",align:"right",render:m=>m.hourlyRateCents?j(m.hourlyRateCents)+"/hr":"-"},{key:"clockedHourlyPayCents",label:"Hourly Pay",align:"right",render:m=>e.jsxs("div",{children:[e.jsx("span",{className:"font-bold text-green-600",children:j(m.clockedHourlyPayCents)}),m.payType==="hourly_gap"&&m.idleHours!==void 0&&e.jsx("div",{className:"text-xs text-gray-500 mt-0.5",children:"idle hrs only"})]})},{key:"timeEntries",label:"Entries",align:"center",render:m=>{var k;return e.jsxs("span",{className:"text-gray-500",children:[((k=m.timeEntries)==null?void 0:k.length)||0," shifts"]})}}],data:g.staffTimeClock,keyExtractor:m=>`timeclock-${m.staffId}`}),e.jsx("div",{className:"mt-4 pt-4 border-t border-gray-200",children:e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-gray-600",children:"Total Staff with Time Entries"}),e.jsx("div",{className:"text-xl font-bold",children:g.staffTimeClock.length})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-gray-600",children:"Total Hours Clocked"}),e.jsxs("div",{className:"text-xl font-bold",children:[g.staffTimeClock.reduce((m,k)=>m+k.totalHoursClockedIn,0).toFixed(2)," hrs"]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-gray-600",children:"Total Hourly Pay"}),e.jsx("div",{className:"text-xl font-bold text-green-600",children:j(g.staffTimeClock.reduce((m,k)=>m+k.clockedHourlyPayCents,0))})]})]})})]})]})]}):e.jsx("div",{className:"text-center py-12 text-gray-500",children:"No payroll data available for this period"})}function Oa({dateFrom:a,dateTo:t,locationId:n,onExport:s}){const{primaryColor:r,darkMode:i}
7=z(),[l,c]=N.useState("product"),u=h=>{if(!d){alert("No data to export");return}const f=`product-sales-report-${a}-to-${t}`;if(h==="csv"){const S=X(d.breakdown,{productName:"Product",category:"Category",quantitySold:"Quantity Sold",revenueCents:"Revenue",transactionCount:"Transactions",percentageOfTotalRevenue:"% of Revenue"});J(S,f)}else h==="pdf"?te(d.breakdown,f,"Product Sales Report",[{header:"Product",dataKey:"productName"},{header:"Quantity",dataKey:"quantitySold"},{header:"Revenue",dataKey:"revenueCents"},{header:"Transactions",dataKey:"transactionCount"}]):alert("Excel export coming soon!");s==null||s(h)},o=l==="day"||l==="week"||l==="month"?"date":l,{data:d,loading:g,error:p}=B((h,f,S)=>F.getProductSalesReport(h,f,S,{groupBy:o,locationId:n}),{dateFrom:a,dateTo:t,locationId:n});if(g)return e.jsx(q,{message:"Loading product sales..."});if(p||!d)return e.jsx("div",{className:"text-center py-12",children:e.jsx("p",{className:"text-red-600",children:(p==null?void 0:p.message)||"Failed to load product sales"})});const{summary:y,breakdown:x,topProducts:v}=d,C=()=>l==="product"?x.slice(0,10).map(h=>({label:h.productName||"Unknown",value:h.revenueCents/100})):l==="category"?x.map(h=>({label:h.category||"Uncategorized",value:h.revenueCents/100})):l==="staff"?x.map(h=>({label:h.staffName||"Unknown",value:h.revenueCents/100})):x.map(h=>({label:h.period,value:h.revenueCents/100})),T=l==="product"?{columns:[{key:"productName",label:"Product"},{key:"quantitySold",label:"Quantity Sold",align:"right"},{key:"revenue",label:"Revenue",align:"right"},{key:"avgPrice",label:"Avg Price",align:"right"},{key:"transactionCount",label:"Transactions",align:"right"},{key:"percentRevenue",label:"% of Revenue",align:"right"}],data:x.map((h,f)=>({id:f,productName:h.productName||"Unknown",quantitySold:h.quantitySold,revenue:j(h.revenueCents),avgPrice:j(h.averagePriceCents||0),transactionCount:h.transactionCount,percentRevenue:Y(h.percentageOfTotalRevenue||0)}))}:l==="category"?{columns:[{key:"category",label:"Category"},{key:"quantitySold",label:"Quantity Sold",align:"right"},{key:"revenue",label:"Revenue",align:"right"},{key:"transactionCount",label:"Transactions",align:"right"},{key:"percentTotal",label:"% of Total",align:"right"}],data:x.map((h,f)=>({id:f,category:h.category||"Uncategorized",quantitySold:h.quantitySold,revenue:j(h.revenueCents),transactionCount:h.transactionCount,percentTotal:Y(h.percentageOfTotal||0)}))}:l==="staff"?{columns:[{key:"staffName",label:"Staff Member"},{key:"quantitySold",label:"Quantity Sold",align:"right"},{key:"revenue",label:"Revenue",align:"right"},{key:"transactionCount",label:"Transactions",align:"right"},{key:"percentTotal",label:"% of Total",align:"right"}],data:x.map((h,f)=>({id:f,staffName:h.staffName||"Unknown",quantitySold:h.quantitySold,revenue:j(h.revenueCents),transactionCount:h.transactionCount,percentTotal:Y(h.percentageOfTotal||0)}))}:{columns:[{key:"period",label:"Period"},{key:"quantitySold",label:"Quantity Sold",align:"right"},{key:"revenue",label:"Revenue",align:"right"},{key:"transactionCount",label:"Transactions",align:"right"}],data:x.map((h,f)=>({id:f,period:h.period,quantitySold:h.quantitySold,revenue:j(h.revenueCents),transactionCount:h.transactionCount}))};return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(ae,{onExport:u})}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(R,{label:"Total Revenue",value:j(y.totalRevenueCents),icon:Z,useThemeColor:!0}),e.jsx(R,{label:"Products Sold",value:y.totalQuantitySold.toLocaleString(),icon:Qe,useThemeColor:!0}),e.jsx(R,{label:"Transactions",value:y.totalTransactions.toLocaleString(),icon:Ct,useThemeColor:!0}),e.jsx(R,{label:"Avg Transaction",value:j(y.averageTransactionCents),subtitle:`${y.averageItemsPerTransaction.toFixed(1)} items/transaction`,icon:re,useThemeColor:!0})]}),e.jsxs($,{title:"Product Sales Analysis",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Group By"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:["product","category","staff","day","week","month"].map(h=>e.jsx("button",{onClick:()=>c(h),className:`px-4 py-2 rounded-lg text-sm font-medium transition-colors ${l===h?"text-white":`${i?"bg-gray-700 text-gray-300 hover:bg-gray-600":"bg-gray-100 text-gray-700 hover:bg-gray-200"}`}`,style:{backgroundColor:l===h?r:void 0},children:h.charAt(0).toUpperCase()+h.slice(1)},h))})]}),e.jsxs("div",{className:"mb-6",children:[e.jsxs("h3",{className:"text-lg font-semibold mb-4",children:["Revenue by ",l.charAt(0).toUpperCase()+l.slice(1)]}),l==="category"||l==="staff"?e.jsx(Te,{data:C()}):e.jsx(ne,{data:C(),formatValue:h=>j(h*100)})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Detailed Breakdown"}),e.jsx(M,{columns:T.columns,data:T.data,keyExtractor:h=>String(h.id)})]})]}),v&&v.length>0&&e.jsx($,{title:"Top 10 Products",children:e.jsx(M,{columns:[{key:"rank",label:"Rank",align:"center"},{key:"product",label:"Product"},{key:"quantitySold",label:"Quantity Sold",align:"right"},{key:"revenue",label:"Revenue",align:"right"}],data:v.map((h,f)=>({id:f,rank:f+1,product:h.productName,quantitySold:h.quantitySold,revenue:j(h.revenueCents)})),keyExtractor:h=>String(h.id)})})]})}function Ua({dateFrom:a,dateTo:t,locationId:n,onExport:s}){const{darkMode:r,primaryColor:i}=z(),[l,c]=N.useState(null),[u,o]=N.useState(!0),[d,g]=N.useState(null),[p,y]=N.useState(0),x=50,v=localStorage.getItem("businessTimezone")||_;N.useEffect(()=>{C()},[a,t,n,p]);const C=async()=>{try{o(!0),g(null);const f=localStorage.getItem("accessToken");if(!f)throw new Error("No access token found");const S=await F.getCashTransactionsReport(a,t,f,{locationId:n,limit:x,offset:p*x});c(S)}catch(f){g(f instanceof Error?f.message:"Failed to load cash transactions")}finally{o(!1)}},b=async f=>{if(!l){alert("No data to export");return}const S=`cash-transactions-${a}-to-${t}`;try{const w=localStorage.getItem("accessToken");if(!w)return;const U=(await F.getCashTransactionsReport(a,t,w,{locationId:n,limit:1e4,offset:0})).transactions.map(H=>({date:new Date(H.createdAt).toLocaleDateString("en-US",{timeZone:v}),time:new Date(H.createdAt).toLocaleTimeString("en-US",{timeZone:v}),client:H.clientName||"Walk-in",staff:H.staffName||"N/A",service:H.serviceName||"N/A",location:H.locationName||"N/A",amount:(H.amountCents/100).toFixed(2),tip:(H.tipAmountCents/100).toFixed(2),total:((H.amountCents+H.tipAmountCents)/100).toFixed(2),notes:H.notes||""}));if(f==="csv"){const H=X(U,{date:"Date",time:"Time",client:"Client",staff:"Staff",service:"Service",location:"Location",amount:"Amount",tip:"Tip",total:"Total",notes:"Notes"});J(H,S)}else f==="pdf"?te(U,S,"Cash Transactions Report",[{header:"Date",dataKey:"date"},{header:"Client",dataKey:"client"},{header:"Staff",dataKey:"staff"},{header:"Service",dataKey:"service"},{header:"Amount",dataKey:"amount"},{header:"Tip",dataKey:"tip"},{header:"Total",dataKey:"total"}]):alert("Excel export coming soon!");s==null||s(f)}catch(w){console.error("Export failed:",w),alert("Failed to export data")}},T=f=>`$${(f/100).toFixed(2)}`;
7if(u&&!l)return e.jsx(q,{message:"Loading cash transactions..."});if(d)return e.jsxs("div",{className:`p-4 rounded-lg ${r?"bg-red-900/20 text-red-400":"bg-red-50 text-red-600"}`,children:[e.jsxs("p",{children:["Error: ",d]}),e.jsx("button",{onClick:C,className:"mt-2 px-4 py-2 rounded text-white",style:{backgroundColor:i},children:"Retry"})]});if(!l)return null;const h=Math.ceil(l.pagination.total/x);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsx(R,{label:"Total Transactions",value:l.summary.totalTransactions.toString(),icon:Kt,useThemeColor:!0}),e.jsx(R,{label:"Cash Collected",value:T(l.summary.totalAmountCents),icon:et,color:"green"}),e.jsx(R,{label:"Cash Tips",value:T(l.summary.totalTipsCents),icon:re,color:"orange"}),e.jsx(R,{label:"Total with Tips",value:T(l.summary.totalWithTipsCents),icon:Z,color:"purple"})]}),e.jsxs($,{title:"Cash Transactions",subtitle:`${l.pagination.total} transactions from ${a} to ${t}`,action:e.jsx(ae,{onExport:b}),children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:`min-w-full divide-y ${r?"divide-gray-700":"divide-gray-200"}`,children:[e.jsx("thead",{className:r?"bg-gray-800":"bg-gray-50",children:e.jsxs("tr",{children:[e.jsx("th",{className:`px-4 py-3 text-left text-xs font-medium uppercase tracking-wider ${r?"text-gray-400":"text-gray-500"}`,children:"Date/Time"}),e.jsx("th",{className:`px-4 py-3 text-left text-xs font-medium uppercase tracking-wider ${r?"text-gray-400":"text-gray-500"}`,children:"Client"}),e.jsx("th",{className:`px-4 py-3 text-left text-xs font-medium uppercase tracking-wider ${r?"text-gray-400":"text-gray-500"}`,children:"Staff"}),e.jsx("th",{className:`px-4 py-3 text-left text-xs font-medium uppercase tracking-wider ${r?"text-gray-400":"text-gray-500"}`,children:"Service"}),e.jsx("th",{className:`px-4 py-3 text-left text-xs font-medium uppercase tracking-wider ${r?"text-gray-400":"text-gray-500"}`,children:"Location"}),e.jsx("th",{className:`px-4 py-3 text-right text-xs font-medium uppercase tracking-wider ${r?"text-gray-400":"text-gray-500"}`,children:"Amount"}),e.jsx("th",{className:`px-4 py-3 text-right text-xs font-medium uppercase tracking-wider ${r?"text-gray-400":"text-gray-500"}`,children:"Tip"}),e.jsx("th",{className:`px-4 py-3 text-right text-xs font-medium uppercase tracking-wider ${r?"text-gray-400":"text-gray-500"}`,children:"Total"})]})}),e.jsx("tbody",{className:`divide-y ${r?"divide-gray-700":"divide-gray-200"}`,children:l.transactions.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:8,className:`px-4 py-8 text-center ${r?"text-gray-400":"text-gray-500"}`,children:"No cash transactions found for this period."})}):l.transactions.map(f=>{const S=new Date(f.createdAt);return e.jsxs("tr",{className:r?"hover:bg-gray-800":"hover:bg-gray-50",children:[e.jsxs("td",{className:`px-4 py-3 whitespace-nowrap text-sm ${r?"text-gray-300":"text-gray-900"}`,children:[e.jsx("div",{children:S.toLocaleDateString("en-US",{timeZone:v})}),e.jsx("div",{className:`text-xs ${r?"text-gray-500":"text-gray-400"}`,children:S.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",timeZone:v})})]}),e.jsx("td",{className:`px-4 py-3 whitespace-nowrap text-sm ${r?"text-gray-300":"text-gray-900"}`,children:f.clientName||e.jsx("span",{className:"italic text-gray-400",children:"Walk-in"})}),e.jsx("td",{className:`px-4 py-3 whitespace-nowrap text-sm ${r?"text-gray-300":"text-gray-900"}`,children:f.staffName||"-"}),e.jsx("td",{className:`px-4 py-3 text-sm ${r?"text-gray-300":"text-gray-900"}`,children:f.serviceName||"-"}),e.jsx("td",{className:`px-4 py-3 whitespace-nowrap text-sm ${r?"text-gray-300":"text-gray-900"}`,children:f.locationName||"-"}),e.jsx("td",{className:`px-4 py-3 whitespace-nowrap text-sm text-right ${r?"text-gray-300":"text-gray-900"}`,children:T(f.amountCents)}),e.jsx("td",{className:`px-4 py-3 whitespace-nowrap text-sm text-right ${f.tipAmountCents>0?"text-green-500":r?"text-gray-500":"text-gray-400"}`,children:f.tipAmountCents>0?T(f.tipAmountCents):"-"}),e.jsx("td",{className:`px-4 py-3 whitespace-nowrap text-sm text-right font-medium ${r?"text-gray-100":"text-gray-900"}`,children:T(f.amountCents+f.tipAmountCents)})]},f.paymentId)})})]})}),h>1&&e.jsxs("div",{className:`flex items-center justify-between px-4 py-3 border-t ${r?"border-gray-700":"border-gray-200"}`,children:[e.jsxs("div",{className:`text-sm ${r?"text-gray-400":"text-gray-500"}`,children:["Showing ",p*x+1," to ",Math.min((p+1)*x,l.pagination.total)," of ",l.pagination.total," transactions"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>y(Math.max(0,p-1)),disabled:p===0,className:`px-3 py-1 rounded text-sm ${p===0?"opacity-50 cursor-not-allowed":"hover:bg-gray-100 dark:hover:bg-gray-700"} ${r?"text-gray-300":"text-gray-700"}`,children:"Previous"}),e.jsxs("span",{className:`px-3 py-1 text-sm ${r?"text-gray-300":"text-gray-700"}`,children:["Page ",p+1," of ",h]}),e.jsx("button",{onClick:()=>y(Math.min(h-1,p+1)),disabled:p>=h-1,className:`px-3 py-1 rounded text-sm ${p>=h-1?"opacity-50 cursor-not-allowed":"hover:bg-gray-100 dark:hover:bg-gray-700"} ${r?"text-gray-300":"text-gray-700"}`,children:"Next"})]})]})]})]})}function Va(a){const t=a>=12?"PM":"AM";return`${a%12===0?12:a%12}:00 ${t}`}function _a({dateFrom:a,dateTo:t,locationId:n}){const s=localStorage.getItem("businessTimezone")||_,{data:r,loading:i,error:l}=B(async(g,p,y)=>{const x=new URLSearchParams({dateFrom:g,dateTo:p});n&&x.set("locationId",String(n));const v=await fetch(`/api/v1/reports/classes/performance?${x}`,{headers:{Authorization:`Bearer ${y}`}});if(!v.ok)throw new Error("Failed to load class performance report");return v.json()},{dateFrom:a,dateTo:t,locationId:n});if(i)return e.jsx(q,{message:"Loading class performance..."});if(l)return e.jsxs("div",{className:"text-center py-12 text-red-500",children:["Failed to load class report: ",l.message]});if(!r||!r.summary)return e.jsx("div",{className:"text-center py-12 text-gray-500",children:"No class data available for this period"});const{summary:c,classBreakdown:u,instructorBreakdown:o,popularTimeSlots:d}=r;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4",children:[e.jsx(R,{label:"Classes Held",value:c.totalClasses-c.cancelledClasses,icon:se,useThemeColor:!0}),e.jsx(R,{label:"Total Enrollments",value:c.totalEnrollments,icon:ke,useThemeColor:!0}),e.jsx(R,{label:"Total Revenue",value:j(c.totalRevenueCents),icon:Z,useThemeColor:!0}),e.jsx(R,{label:"Avg Attendance Rate",value:Y(c.avgAttendanceRate),icon:Xe,useThemeColor:!0}),e.jsx(R,{label:"Avg Fill Rate",value:Y(c.avgFillRate),icon:re,useThemeColor:!0}),e.jsx(R,{label:"No-Show Rate",value:Y(c.noShowRate),icon:be,useThemeColor:!1}),e.jsx(R,{label:"Waitlist Conversion",value:Y(c.waitlistConversionRate),icon:re,useThemeColor:!0}),e.jsx(R,{label:"Cancelled Classes",value:c.cancelledClasses,icon:be,useThemeColor:!1})]}),u.length>0&&e.jsx($,{title:"Class Breakdown",subtitle:`${u.length} class${u.length!==1?"es":""} in this period`,children:e.jsx(M,{columns:[{key:"className",label:"Class",sortable:!0},{key:"instructorName",label:"Instructor",sortable:!0},{key:"startTime",label:"Date",sortable:!0,render:g=>new Date(g.startTime).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",timeZone:s})},{key:"enrolled",label:"Enrolled",sortable:!0},{key:"maxCapacity",label:"Capacity"},{key:"fillRate",label:"Fill %",sortable:!0,render:g=>Y(g.fillRate)},{key:"checkedIn",label:"Checked In",sortable:!0},{key:"noShows",label:"No Shows",sortable:!0}
7,{key:"revenueCents",label:"Revenue",sortable:!0,render:g=>j(g.revenueCents)}],data:u,keyExtractor:g=>g.classId})}),o.length>0&&e.jsxs($,{title:"Instructor Performance",subtitle:"Classes taught and fill rates",children:[e.jsx(ne,{data:o.map(g=>({label:g.instructorName,value:g.classesHeld})),formatValue:g=>`${g} class${g!==1?"es":""}`,height:220}),e.jsx("div",{className:"mt-4",children:e.jsx(M,{columns:[{key:"instructorName",label:"Instructor",sortable:!0},{key:"classesHeld",label:"Classes",sortable:!0},{key:"totalEnrolled",label:"Total Enrolled",sortable:!0},{key:"avgFillRate",label:"Avg Fill %",sortable:!0,render:g=>Y(g.avgFillRate)},{key:"totalRevenueCents",label:"Revenue",sortable:!0,render:g=>j(g.totalRevenueCents)}],data:o,keyExtractor:g=>g.staffId})})]}),d.length>0&&e.jsx($,{title:"Popular Time Slots",subtitle:"Most frequently scheduled day + time combinations",children:e.jsx(ne,{data:d.map(g=>({label:`${g.dayName} ${Va(g.hour)}`,value:g.classCount})),formatValue:g=>`${g} class${g!==1?"es":""}`,height:220})}),u.length===0&&e.jsxs("div",{className:"text-center py-16 text-gray-400",children:[e.jsx(se,{className:"w-10 h-10 mx-auto mb-3 opacity-40"}),e.jsx("p",{className:"font-medium",children:"No classes in this date range"}),e.jsx("p",{className:"text-sm mt-1",children:"Try expanding the date range or create some classes."})]})]})}const Qa=["What was my best revenue day?","Which service category earns the most?","How are my cancellation rates?","Compare this period to last period","What are my peak booking hours?","How many new clients this period?"];function qa({dateFrom:a,dateTo:t,locationId:n}){const{primaryColor:s,darkMode:r}=z(),[i,l]=N.useState(!1),[c,u]=N.useState([]),[o,d]=N.useState(""),[g,p]=N.useState(!1),[y,x]=N.useState(null),v=N.useRef(null),C=N.useRef(null);N.useEffect(()=>{var f;(f=v.current)==null||f.scrollIntoView({behavior:"smooth"})},[c,g]),N.useEffect(()=>{i&&setTimeout(()=>{var f;return(f=C.current)==null?void 0:f.focus()},100)},[i]);const b=N.useCallback(async f=>{if(!f.trim()||g)return;const S={role:"user",content:f.trim()};u(w=>[...w,S]),d(""),x(null),p(!0);try{const w=localStorage.getItem("accessToken");if(!w)throw new Error("Not authenticated");const A=c.map(V=>({role:V.role,content:V.content})),H={role:"assistant",content:(await F.askReportQuestion(a,t,f.trim(),A,w,n)).data.reply};u(V=>[...V,H])}catch(w){x((w==null?void 0:w.message)||"Failed to get answer"),u(A=>A.slice(0,-1)),d(f.trim())}finally{p(!1)}},[a,t,n,g,c]),T=f=>{f.preventDefault(),b(o)},h=()=>{u([]),x(null),d("")};return i?e.jsxs("div",{className:`fixed bottom-6 right-6 z-50 w-96 max-h-[600px] rounded-2xl shadow-2xl border flex flex-col overflow-hidden ${r?"bg-gray-800 border-gray-700":"bg-white border-gray-200"}`,children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 text-white flex-shrink-0",style:{backgroundColor:s},children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(le,{className:"w-5 h-5"}),e.jsx("span",{className:"font-semibold text-sm",children:"Ask About Your Data"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[c.length>0&&e.jsx("button",{onClick:h,className:"p-1.5 rounded-lg hover:bg-white/20 transition-colors",title:"Clear conversation",children:e.jsx(Nt,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>l(!1),className:"p-1.5 rounded-lg hover:bg-white/20 transition-colors",children:e.jsx(_e,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-4 py-3 space-y-3 min-h-[200px] max-h-[420px]",children:[c.length===0&&!g&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:`text-center py-2 ${r?"text-gray-400":"text-gray-500"}`,children:[e.jsx(le,{className:"w-8 h-8 mx-auto mb-2 opacity-40"}),e.jsx("p",{className:"text-sm font-medium",children:"Ask me anything about your business data"}),e.jsxs("p",{className:`text-xs mt-1 ${r?"text-gray-500":"text-gray-400"}`,children:[a," â ",t]})]}),e.jsx("div",{className:"space-y-1.5",children:Qa.map(f=>e.jsx("button",{onClick:()=>b(f),className:`w-full text-left px-3 py-2 rounded-lg text-xs transition-colors ${r?"bg-gray-700/50 text-gray-300 hover:bg-gray-700":"bg-gray-50 text-gray-600 hover:bg-gray-100"}`,children:f},f))})]}),c.map((f,S)=>e.jsx("div",{className:`flex ${f.role==="user"?"justify-end":"justify-start"}`,children:e.jsx("div",{className:`max-w-[85%] px-3 py-2 rounded-2xl text-sm leading-relaxed ${f.role==="user"?"text-white rounded-br-md":r?"bg-gray-700 text-gray-200 rounded-bl-md":"bg-gray-100 text-gray-800 rounded-bl-md"}`,style:f.role==="user"?{backgroundColor:s}:void 0,children:f.content})},S)),g&&e.jsx("div",{className:"flex justify-start",children:e.jsx("div",{className:`px-4 py-3 rounded-2xl rounded-bl-md ${r?"bg-gray-700":"bg-gray-100"}`,children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-2 h-2 rounded-full animate-bounce",style:{backgroundColor:s,animationDelay:"0ms"}}),e.jsx("div",{className:"w-2 h-2 rounded-full animate-bounce",style:{backgroundColor:s,animationDelay:"150ms"}}),e.jsx("div",{className:"w-2 h-2 rounded-full animate-bounce",style:{backgroundColor:s,animationDelay:"300ms"}})]})})}),y&&e.jsx("div",{className:`px-3 py-2 rounded-lg text-xs ${r?"bg-red-900/20 text-red-400":"bg-red-50 text-red-600"}`,children:y}),e.jsx("div",{ref:v})]}),e.jsxs("form",{onSubmit:T,className:`flex items-center gap-2 px-3 py-3 border-t flex-shrink-0 ${r?"border-gray-700":"border-gray-200"}`,children:[e.jsx("input",{ref:C,type:"text",value:o,onChange:f=>d(f.target.value),placeholder:"Ask a question...",disabled:g,className:`flex-1 px-3 py-2 text-sm rounded-xl border focus:outline-none focus:ring-2 disabled:opacity-50 ${r?"bg-gray-700 border-gray-600 text-white placeholder-gray-400":"bg-gray-50 border-gray-200 text-gray-900 placeholder-gray-400"}`,style:{"--tw-ring-color":s}}),e.jsx("button",{type:"submit",disabled:!o.trim()||g,className:"p-2 rounded-xl text-white transition-all hover:opacity-90 disabled:opacity-30",style:{backgroundColor:s},children:e.jsx(kt,{className:"w-4 h-4"})})]})]}):e.jsxs("button",{onClick:()=>l(!0),className:"fixed bottom-6 right-6 z-50 flex items-center gap-2 px-5 py-3 rounded-full text-white shadow-lg hover:shadow-xl transition-all hover:scale-105",style:{backgroundColor:s},children:[e.jsx(It,{className:"w-5 h-5"}),e.jsx("span",{className:"font-medium text-sm",children:"Ask About Your Data"})]})}function Ar(){const{primaryColor:a,darkMode:t,iconColor:n,fontColor:s}=z(),[r,i]=N.useState("overview"),[l,c]=N.useState(),[u,o]=N.useState([]),[d,g]=N.useState(_),[p,y]=N.useState(new Date),[x,v]=N.useState({preset:"last30days",from:ge("last30days").from,to:ge("last30days").to});N.useEffect(()=>{(async()=>{try{const w=localStorage.getItem("accessToken");if(!w)return;const U=(await F.listLocations(w)).locations.filter(m=>m.isActive);o(U);const H=U.find(m=>m.isPrimary)||U[0],V=(H==null?void 0:H.timezone)||_;g(V),v(m=>{if(m.preset!=="custom"){const k=ge(m.preset,V);return{preset:m.preset,from:k.from,to:k.to}}return m})}catch(w){console.error("Failed to load locations:",w)}})()},[]);const C=S=>{if(S.preset!=="custom"){const w=ge(S.preset,d);v({preset:S.preset,from:w.from,to:w.to})}else v(S);y(new Date)},b=S=>{console.log("Export to",S,"for tab:",r),r==="overview"&&alert("Please select a specific report tab to export")},T=[{id:"overview",label:"Overview",icon:Ot},{id:"financial",label:"Financial",icon:qt},{id:"cash",label:"Cash Transactions",icon:et},{id:"products",label:"Product Sales",icon:Qe},{id:"clients",label:"Clients",icon:ke},{id:"staff",label:"Staff",icon:Ut},{id:"services",label:"Services",icon:Ve},{id:"appointments",label:"Appointments",icon:se},{id:"payroll",label:"Payroll",icon:Vt},{id:"classes",label:"Classes",icon:vt}],h=x.from?ce(x.from,d):"",f=x.to?ce(x.to,d):"";return e.jsxs(yt,{children:[e.jsx("div",{className:`py-12 px-4 ${t?"bg-gray-900":""}
7`,children:e.jsxs("div",{className:"max-w-7xl mx-auto space-y-6",children:[e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx("h1",{className:`text-3xl font-bold ${t?"text-gray-100":"text-gray-900"}`,style:{color:s},children:"Reports & Analytics"}),e.jsx("p",{className:`mt-2 ${t?"text-gray-400":"text-gray-600"}`,children:"Comprehensive business insights and performance metrics"})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("a",{href:"/reports/transactions",className:"px-4 py-2 text-white rounded-md transition-colors flex items-center gap-2 hover:opacity-90",style:{backgroundColor:a},children:[e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"})}),"Transaction Reconciliation"]}),e.jsx(ae,{onExport:b})]})]}),e.jsx("div",{className:`rounded-lg shadow p-4 ${t?"bg-gray-800":"bg-white"}`,children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h3",{className:`text-sm font-medium ${t?"text-gray-300":"text-gray-700"}`,children:"Filters"}),e.jsxs("span",{className:`text-xs ${t?"text-gray-500":"text-gray-400"}`,children:["Last updated: ",p.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})]})]}),u.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("select",{id:"location-filter",value:l||"",onChange:S=>{c(S.target.value?Number(S.target.value):void 0),y(new Date)},className:`px-3 py-1.5 text-sm border rounded-md shadow-sm focus:ring-2 focus:border-transparent ${t?"bg-gray-700 border-gray-600 text-white":"bg-white border-gray-300 text-gray-900"}`,style:{"--tw-ring-color":a},children:[e.jsx("option",{value:"",children:"All Locations"}),u.map(S=>e.jsx("option",{value:S.id,children:S.name},S.id))]}),l&&e.jsx("button",{onClick:()=>c(void 0),className:"text-xs font-medium hover:opacity-75 transition-opacity",style:{color:a},children:"Clear"})]})]}),e.jsx(Yt,{value:x,onChange:C})]})}),e.jsxs("div",{className:`rounded-lg shadow ${t?"bg-gray-800":"bg-white"}`,children:[e.jsx("div",{className:`border-b ${t?"border-gray-700":"border-gray-200"}`,children:e.jsx("nav",{className:"flex -mb-px overflow-x-auto",children:T.map(S=>{const w=S.icon;return e.jsxs("button",{onClick:()=>i(S.id),className:` 8 flex items-center gap-2 px-6 py-4 text-sm font-medium border-b-2 transition-colors whitespace-nowrap 9 ${r===S.id?`text-${t?"white":"gray-900"}`:`${t?"text-gray-400 hover:text-gray-200":"text-gray-500 hover:text-gray-700"} border-transparent hover:border-gray-300`} 10 `,style:{borderBottomColor:r===S.id?a:void 0,color:r===S.id?a:void 0},children:[e.jsx(w,{className:"w-5 h-5",strokeWidth:2,style:{color:r===S.id?a:n}}),e.jsx("span",{children:S.label})]},S.id)})})}),e.jsxs("div",{className:"p-6",children:[r==="overview"&&e.jsx(Ya,{dateFrom:h,dateTo:f,locationId:l}),r==="financial"&&e.jsx(Ea,{dateFrom:h,dateTo:f,locationId:l,onExport:b}),r==="cash"&&e.jsx(Ua,{dateFrom:h,dateTo:f,locationId:l,onExport:b}),r==="products"&&e.jsx(Oa,{dateFrom:h,dateTo:f,locationId:l,onExport:b}),r==="clients"&&e.jsx(Ba,{dateFrom:h,dateTo:f,locationId:l,onExport:b}),r==="staff"&&e.jsx(Ma,{dateFrom:h,dateTo:f,locationId:l,onExport:b}),r==="services"&&e.jsx(Ka,{dateFrom:h,dateTo:f,locationId:l,onExport:b}),r==="appointments"&&e.jsx(za,{dateFrom:h,dateTo:f,locationId:l,onExport:b}),r==="payroll"&&e.jsx(Ia,{dateFrom:h,dateTo:f,locationId:l}),r==="classes"&&e.jsx(_a,{dateFrom:h,dateTo:f,locationId:l})]})]})]})}),e.jsx(qa,{dateFrom:h,dateTo:f,locationId:l})]})}function Ya({dateFrom:a,dateTo:t,locationId:n}){var I,O;const{primaryColor:s,darkMode:r}=z(),[i,l]=N.useState(null),[c,u]=N.useState(!1),[o,d]=N.useState(null),[g,p]=N.useState(""),[y,x]=N.useState(null),[v,C]=N.useState(!1),[b,T]=N.useState(null),[h,f]=N.useState(""),S=N.useCallback(async()=>{const P=`forecast-${a}-${t}-${n}`;if(!(h===P&&y))try{C(!0),T(null);const L=localStorage.getItem("accessToken");if(!L)throw new Error("Not authenticated");const W=await F.getAiForecast(a,t,L,n);x(W.data),f(P)}catch(L){T((L==null?void 0:L.message)||"Failed to generate forecast")}finally{C(!1)}},[a,t,n,h,y]),w=N.useCallback(async()=>{const P=`${a}-${t}-${n}`;if(!(g===P&&i))try{u(!0),d(null);const L=localStorage.getItem("accessToken");if(!L)throw new Error("Not authenticated");const W=await F.getAiInsights(a,t,L,n);l(W.data),p(P)}catch(L){d((L==null?void 0:L.message)||"Failed to generate insights")}finally{u(!1)}},[a,t,n,g,i]),{data:A,loading:U}=B((P,L,W)=>F.getSalesReport(P,L,W,{groupBy:"day",includePreviousPeriod:!0,locationId:n}),{dateFrom:a,dateTo:t,locationId:n}),{data:H,loading:V}=B((P,L,W)=>F.getServiceCategoryBreakdown(P,L,W,n),{dateFrom:a,dateTo:t,locationId:n}),{data:m,loading:k}=B((P,L,W)=>F.getClientRetentionReport(P,L,W,n),{dateFrom:a,dateTo:t,locationId:n}),{data:D,loading:K}=B((P,L,W)=>F.getAppointmentVolumeReport(P,L,W,n),{dateFrom:a,dateTo:t,locationId:n});if(U||V||k||K)return e.jsx(q,{message:"Loading overview..."});const E=[s,"#10b981","#8b5cf6","#f59e0b","#ef4444","#ec4899","#06b6d4","#84cc16"];return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(R,{label:"Total Revenue",value:A?j(A.summary.totalRevenueCents):"$0.00",change:(I=A
10==null?void 0:A.comparison)==null?void 0:I.changePercentage,trend:(O=A==null?void 0:A.comparison)==null?void 0:O.trend,subtitle:`${(A==null?void 0:A.summary.transactionCount)||0} transactions`,icon:Z,useThemeColor:!0}),e.jsx(R,{label:"Avg Transaction",value:A?j(A.summary.averageTransactionCents):"$0.00",subtitle:"Per transaction",icon:re,useThemeColor:!0}),e.jsx(R,{label:"Appointments",value:(D==null?void 0:D.summary.totalAppointments)||0,subtitle:`${(D==null?void 0:D.summary.completedRate)||0}% completed`,icon:se,useThemeColor:!0}),e.jsx(R,{label:"New Clients",value:(m==null?void 0:m.summary.newClients)||0,subtitle:`${(m==null?void 0:m.summary.totalClients)||0} total`,icon:Je,useThemeColor:!0})]}),e.jsxs($,{title:"AI Business Insights",subtitle:"Powered by Claude",action:i?e.jsx("button",{onClick:()=>{l(null),p(""),d(null)},className:`text-sm ${r?"text-gray-400 hover:text-gray-200":"text-gray-500 hover:text-gray-700"}`,children:"Clear"}):e.jsxs("button",{onClick:w,disabled:c,className:"inline-flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium text-white transition-all hover:opacity-90 disabled:opacity-50",style:{backgroundColor:s},children:[e.jsx(le,{className:"w-4 h-4"}),c?"Analyzing...":"Generate Insights"]}),children:[!i&&!c&&!o&&e.jsxs("div",{className:`text-center py-8 ${r?"text-gray-400":"text-gray-500"}`,children:[e.jsx(le,{className:"w-10 h-10 mx-auto mb-3 opacity-30"}),e.jsx("p",{className:"text-sm",children:'Click "Generate Insights" to get an AI-powered analysis of your business performance for this period.'})]}),c&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"inline-block h-6 w-6 animate-spin rounded-full border-2 border-solid border-r-transparent mb-3",style:{borderColor:`${s} transparent ${s} ${s}`}}),e.jsx("p",{className:`text-sm ${r?"text-gray-400":"text-gray-500"}`,children:"Analyzing your data..."})]}),o&&e.jsxs("div",{className:`p-4 rounded-lg ${r?"bg-red-900/20 text-red-400":"bg-red-50 text-red-600"}`,children:[e.jsx("p",{className:"text-sm",children:o}),e.jsx("button",{onClick:w,className:"mt-2 text-sm font-medium underline",children:"Try again"})]}),i&&e.jsxs("div",{className:"space-y-5",children:[e.jsx("p",{className:`text-sm leading-relaxed ${r?"text-gray-300":"text-gray-700"}`,children:i.summary}),i.highlights.length>0&&e.jsxs("div",{children:[e.jsxs("h4",{className:`text-xs font-semibold uppercase tracking-wider mb-2 flex items-center gap-1.5 ${r?"text-gray-400":"text-gray-500"}`,children:[e.jsx(Ue,{className:"w-3.5 h-3.5"})," Key Highlights"]}),e.jsx("ul",{className:"space-y-1.5",children:i.highlights.map((P,L)=>e.jsxs("li",{className:`text-sm flex items-start gap-2 ${r?"text-gray-300":"text-gray-700"}`,children:[e.jsx("span",{className:"mt-1.5 w-1.5 h-1.5 rounded-full flex-shrink-0",style:{backgroundColor:s}}),P]},L))})]}),i.recommendations.length>0&&e.jsxs("div",{children:[e.jsxs("h4",{className:`text-xs font-semibold uppercase tracking-wider mb-2 flex items-center gap-1.5 ${r?"text-gray-400":"text-gray-500"}`,children:[e.jsx(St,{className:"w-3.5 h-3.5"})," Recommendations"]}),e.jsx("div",{className:"space-y-2",children:i.recommendations.map((P,L)=>e.jsxs("div",{className:`p-3 rounded-lg ${r?"bg-gray-700/50":"bg-gray-50"}`,children:[e.jsx("p",{className:`text-sm font-medium ${r?"text-gray-200":"text-gray-800"}`,children:P.action}),e.jsx("p",{className:`text-xs mt-1 ${r?"text-gray-400":"text-gray-500"}`,children:P.why})]},L))})]}),i.watchouts.length>0&&e.jsxs("div",{children:[e.jsxs("h4",{className:`text-xs font-semibold uppercase tracking-wider mb-2 flex items-center gap-1.5 ${r?"text-yellow-400/70":"text-yellow-600"}`,children:[e.jsx(_t,{className:"w-3.5 h-3.5"})," Data Notes"]}),e.jsx("ul",{className:"space-y-1",children:i.watchouts.map((P,L)=>e.jsxs("li",{className:`text-xs ${r?"text-gray-400":"text-gray-500"}`,children:["⢠",P]},L))})]})]})]}),A&&A.breakdown.length>0&&e.jsx($,{title:"Revenue Trend",subtitle:`${a} to ${t}`,children:e.jsx(tt,{data:A.breakdown.map(P=>({date:P.period||a,revenue:P.revenueCents,label:P.period})),type:"area",height:280})}),H&&H.categoryBreakdown.length>0&&e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx($,{title:"Revenue by Category",subtitle:"Service category breakdown",children:e.jsx(Te,{data:H.categoryBreakdown.map(P=>({name:P.categoryName,value:P.totalRevenueCents})),formatValue:j,height:280,showLabels:!1,showLegend:!1})}),e.jsx($,{title:"Top Categories",subtitle:"By revenue",children:e.jsx(M,{columns:[{key:"categoryName",label:"Category",render:P=>{const L=H.categoryBreakdown.indexOf(P),W=E[L%E.length];return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"inline-block w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:W}}),e.jsx("span",{children:P.categoryName})]})}},{key:"totalRevenueCents",label:"Revenue",align:"right",render:P=>j(P.totalRevenueCents)},{key:"percentageOfRevenue",label:"%",align:"right",render:P=>`${P.percentageOfRevenue}%`}],data:H.categoryBreakdown.slice(0,8),keyExtractor:P=>P.categoryName})})]}),(A==null?void 0:A.comparison)&&e.jsx($,{title:"Period Comparison",subtitle:"vs. previous period",children:e.jsxs("div",{className:"grid grid-cols-3 gap-6",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-sm text-gray-600 mb-2",children:"Current Period"}),e.jsx("div",{className:"text-2xl font-bold",style:{color:s},children:j(A.comparison.currentRevenueCents)})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-sm text-gray-600 mb-2",children:"Previous Per
10iod"}),e.jsx("div",{className:"text-2xl font-bold text-gray-500",children:j(A.comparison.previousRevenueCents)})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-sm text-gray-600 mb-2",children:"Change"}),e.jsxs("div",{className:`text-2xl font-bold ${A.comparison.trend==="up"?"text-green-600":A.comparison.trend==="down"?"text-red-600":"text-gray-600"}`,children:[A.comparison.trend==="up"?"â":A.comparison.trend==="down"?"â":"â"," ",Math.abs(A.comparison.changePercentage).toFixed(1),"%"]})]})]})}),e.jsxs($,{title:"Revenue Forecast",subtitle:"AI-projected revenue",action:y?e.jsx("button",{onClick:()=>{x(null),f(""),T(null)},className:`text-sm ${r?"text-gray-400 hover:text-gray-200":"text-gray-500 hover:text-gray-700"}`,children:"Clear"}):e.jsxs("button",{onClick:S,disabled:v,className:"inline-flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium text-white transition-all hover:opacity-90 disabled:opacity-50",style:{backgroundColor:s},children:[e.jsx(re,{className:"w-4 h-4"}),v?"Projecting...":"Generate Forecast"]}),children:[!y&&!v&&!b&&e.jsxs("div",{className:`text-center py-6 ${r?"text-gray-400":"text-gray-500"}`,children:[e.jsx(re,{className:"w-8 h-8 mx-auto mb-2 opacity-30"}),e.jsx("p",{className:"text-sm",children:'Click "Generate Forecast" to project revenue for the next 7 and 30 days based on your historical data.'})]}),v&&e.jsxs("div",{className:"text-center py-6",children:[e.jsx("div",{className:"inline-block h-5 w-5 animate-spin rounded-full border-2 border-solid border-r-transparent mb-2",style:{borderColor:`${s} transparent ${s} ${s}`}}),e.jsx("p",{className:`text-sm ${r?"text-gray-400":"text-gray-500"}`,children:"Analyzing trends..."})]}),b&&e.jsxs("div",{className:`p-3 rounded-lg ${r?"bg-red-900/20 text-red-400":"bg-red-50 text-red-600"}`,children:[e.jsx("p",{className:"text-sm",children:b}),e.jsx("button",{onClick:S,className:"mt-1 text-xs font-medium underline",children:"Try again"})]}),y&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:`text-sm ${r?"text-gray-300":"text-gray-700"}`,children:y.trend}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:`p-4 rounded-lg ${r?"bg-gray-700/50":"bg-blue-50"}`,children:[e.jsx("div",{className:`text-xs font-medium uppercase tracking-wider mb-1 ${r?"text-gray-400":"text-blue-600"}`,children:"Next 7 Days"}),e.jsx("div",{className:"text-2xl font-bold",style:{color:s},children:j(y.weekProjection.totalCents)}),e.jsx("div",{className:"flex items-center gap-2 mt-1",children:e.jsxs("span",{className:`inline-flex px-1.5 py-0.5 text-xs rounded font-medium ${y.weekProjection.confidence==="high"?"bg-green-100 text-green-700":y.weekProjection.confidence==="medium"?"bg-yellow-100 text-yellow-700":"bg-gray-100 text-gray-600"}`,children:[y.weekProjection.confidence," confidence"]})}),e.jsx("p",{className:`text-xs mt-2 ${r?"text-gray-400":"text-gray-500"}`,children:y.weekProjection.reasoning})]}),e.jsxs("div",{className:`p-4 rounded-lg ${r?"bg-gray-700/50":"bg-purple-50"}`,children:[e.jsx("div",{className:`text-xs font-medium uppercase tracking-wider mb-1 ${r?"text-gray-400":"text-purple-600"}`,children:"Next 30 Days"}),e.jsx("div",{className:"text-2xl font-bold",style:{color:s},children:j(y.monthProjection.totalCents)}),e.jsx("div",{className:"flex items-center gap-2 mt-1",children:e.jsxs("span",{className:`inline-flex px-1.5 py-0.5 text-xs rounded font-medium ${y.monthProjection.confidence==="high"?"bg-green-100 text-green-700":y.monthProjection.confidence==="medium"?"bg-yellow-100 text-yellow-700":"bg-gray-100 text-gray-600"}`,children:[y.monthProjection.confidence," confidence"]})}),e.jsx("p",{className:`text-xs mt-2 ${r?"text-gray-400":"text-gray-500"}`,children:y.monthProjection.reasoning})]})]})]})]})]})}export{Ar as EnhancedReportsPage}; 11//# sourceMappingURL=EnhancedReportsPage-CIXEEPeM.js.map
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.