import{i as e}from"./rolldown-runtime-Dd_uD5pT.js";import{t}from"./react-BatatxyT.js";import{s as n}from"./utils-BO1RPuol.js";import{t as r}from"./list-table-DNq_Jbx2.js";import{t as i}from"./page-content-DdXVZwik.js";import{t as a}from"./card-CBaLHc_f.js";import{t as o}from"./badge-DLCseWie.js";import{t as s}from"./form-field-4j0NqnRe.js";import{t as c}from"./form-select-ZXmIlaw9.js";import{F as l,M as u}from"./serviceApi-RIObRUm3.js";var d=e(t(),1),f=n(),p={draft:`Draft`,in_progress:`In Progress`,completed:`Completed`,cancelled:`Cancelled`,pending:`Pending`,settled:`Settled`,submitted:`Submitted`,approved:`Approved`,sent:`Sent`,paid:`Paid`,partially_paid:`Partially Paid`};function m(e){return p[e]||e?.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())||`—`}function h({value:e}){let t=m(e);return(0,f.jsx)(o,{variant:e===`completed`||e===`settled`||e===`paid`||e===`approved`?`default`:e===`cancelled`?`destructive`:`secondary`,children:t})}var g=[{key:`service_status`,label:`Service Status`},{key:`daily_work`,label:`Daily Work`},{key:`invoice_report`,label:`Invoice Report`},{key:`employee_expense`,label:`Employee Expense`},{key:`settlement`,label:`Settlement`},{key:`pending_vs_settled`,label:`Pending vs Settled`},{key:`profitability`,label:`Profitability`}];function _(){let[e,t]=(0,d.useState)(`service_status`),[n,o]=(0,d.useState)({}),{data:p=[]}=l(),{data:m=[],isLoading:_}=u({reportType:e,params:Object.keys(n).length?n:void 0}),v=(e,t)=>{o(n=>{let r={...n,[e]:t};return t||delete r[e],r})};return(0,f.jsxs)(i,{children:[(0,f.jsx)(`h1`,{className:`text-3xl font-bold`,children:`Service Reports`}),(0,f.jsx)(`div`,{className:`flex gap-1 border-b overflow-x-auto`,children:g.map(n=>(0,f.jsx)(`button`,{className:`px-4 py-2 text-sm font-medium border-b-2 transition-colors whitespace-nowrap ${e===n.key?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,onClick:()=>{t(n.key),o({})},children:n.label},n.key))}),(0,f.jsx)(a,{className:`p-4`,children:(0,f.jsxs)(`div`,{className:`flex items-end gap-4 flex-wrap`,children:[e===`daily_work`&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`div`,{className:`w-48`,children:(0,f.jsx)(c,{label:`Service Request`,value:n.service_request||``,onChange:e=>v(`service_request`,e.target.value),options:p.map(e=>({value:e.id,label:e.code})),placeholder:`All`})}),(0,f.jsx)(`div`,{className:`w-40`,children:(0,f.jsx)(s,{label:`Date From`,type:`date`,value:n.date_from||``,onChange:e=>v(`date_from`,e.target.value)})}),(0,f.jsx)(`div`,{className:`w-40`,children:(0,f.jsx)(s,{label:`Date To`,type:`date`,value:n.date_to||``,onChange:e=>v(`date_to`,e.target.value)})})]}),(e===`service_status`||e===`invoice_report`)&&(0,f.jsx)(`div`,{className:`w-48`,children:(0,f.jsx)(c,{label:`Status`,value:n.status||``,onChange:e=>v(`status`,e.target.value),options:[{value:`draft`,label:`Draft`},{value:`in_progress`,label:`In Progress`},{value:`completed`,label:`Completed`}],placeholder:`All`})})]})}),(0,f.jsx)(r,{data:m,columns:(()=>{switch(e){case`service_status`:return[{key:`code`,label:`Code`},{key:`client_name`,label:`Client`},{key:`service_type`,label:`Service Type`},{key:`location_name`,label:`Location`},{key:`status`,label:`Status`,render:e=>(0,f.jsx)(h,{value:e.status})},{key:`start_date`,label:`Start`},{key:`end_date`,label:`End`}];case`daily_work`:return[{key:`code`,label:`Log Code`},{key:`service_request_code`,label:`SR Code`},{key:`date`,label:`Date`},{key:`engineer_count`,label:`Engineers`},{key:`technician_count`,label:`Technicians`},{key:`work_description`,label:`Description`}];case`invoice_report`:return[{key:`code`,label:`Invoice Code`},{key:`client_name`,label:`Client`},{key:`invoice_date`,label:`Date`},{key:`total_amount`,label:`Total`,className:`text-center`},{key:`status`,label:`Status`,render:e=>(0,f.jsx)(h,{value:e.status})}];case`employee_expense`:return[{key:`employee_name`,label:`Employee`},{key:`total_amount`,label:`Total Amount`,className:`text-center`},{key:`expense_count`,label:`Expenses`}];case`settlement`:return[{key:`code`,label:`Code`},{key:`employee_name`,label:`Employee`},{key:`total_amount`,label:`Amount`,className:`text-center`},{key:`status`,label:`Status`,render:e=>(0,f.jsx)(h,{value:e.status})},{key:`settlement_date`,label:`Settled Date`}];case`pending_vs_settled`:return[{key:`expense_master_name`,label:`Expense Type`},{key:`pending_amount`,label:`Pending`,className:`text-center`},{key:`settled_amount`,label:`Settled`,className:`text-center`}];case`profitability`:return[{key:`service_request_code`,label:`SR Code`},{key:`client_name`,label:`Client`},{key:`invoice_total`,label:`Invoice Total`,className:`text-center`},{key:`expense_total`,label:`Expenses`,className:`text-center`},{key:`profit`,label:`Profit`,className:`text-center`}];default:return[]}})(),isLoading:_,rowKey:e=>e.id||e.code||JSON.stringify(e),emptyMessage:`No data available for this report`})]})}export{_ as default};