import{a as e,t}from"./react-D0JuimcS.js";import{n,o as r}from"./utils-Dac180Gn.js";import{r as i}from"./api-NMlTtVre.js";import{t as a}from"./list-table-dcNbCPvq.js";import{t as o}from"./funnel-BDsPorMA.js";import{t as s}from"./plus-VCCEyniC.js";import{n as c,t as l}from"./filter-sheet-Baado-aR.js";import{Fo as u,ga as d,kr as f}from"./index-BP3TYB4i.js";import{t as p}from"./page-content-DDtdeMxM.js";import{t as m}from"./badge-Crg76WQE.js";import{a as h,i as g,n as _,o as v,t as y}from"./dialog-BeOPOVZK.js";import{t as b}from"./list-page-header-48VsPegf.js";import{t as x}from"./auth-status-badge-pVqOsTb5.js";import{t as S}from"./row-actions-_6H5dRTY.js";import{F as C,_ as w,k as T}from"./serviceApi-BlxU9Cj1.js";var E=e(t(),1),D=r(),O=[{value:`1`,label:`Pending`},{value:`2`,label:`Approved`},{value:`3`,label:`Rejected`}];function k(){let e=u(),[t,r]=(0,E.useState)(``),[k,A]=(0,E.useState)(`all`),[j,M]=(0,E.useState)(`all`),[N,P]=(0,E.useState)(`all`),[F,I]=(0,E.useState)(!1),L={};k!==`all`&&(L.service_request=k),j!==`all`&&(L.authorized_status=j),N!==`all`&&(L.branch=N),t&&(L.search=t);let{data:R=[],isLoading:z,refetch:B}=T(L),{data:V=[]}=C(),{data:H=[]}=f(),[U]=w(),[W,G]=(0,E.useState)(null),K=async()=>{W&&(await U(W).unwrap().catch(()=>{}),G(null),B())},q=()=>{A(`all`),M(`all`),P(`all`)},J=[k,j,N].filter(e=>e!==`all`).length;return(0,D.jsxs)(p,{children:[(0,D.jsx)(b,{title:`Service Daily Logs`,description:`Daily work records for service requests`,searchPlaceholder:`Search by code, description...`,searchValue:t,onSearchChange:r,action:(0,D.jsxs)(d,{onClick:()=>e(`/service-daily-logs/new`),children:[(0,D.jsx)(s,{className:`size-4 mr-2`}),` New Daily Log`]}),filter:(0,D.jsxs)(d,{variant:`outline`,size:`sm`,onClick:()=>I(!0),className:`relative`,children:[(0,D.jsx)(o,{className:`mr-2 h-4 w-4`}),` Filters`,J>0&&(0,D.jsx)(m,{variant:`destructive`,className:`ml-2 size-5 p-0 flex items-center justify-center text-[10px]`,children:J})]})}),(0,D.jsx)(a,{data:R,onRowClick:t=>e(`/service-daily-logs/${t.id}`),columns:[{key:`code`,label:`Code`,render:e=>(0,D.jsx)(`span`,{className:`font-mono`,children:e.code})},{key:`service_request_code`,label:`Service Request`,render:e=>(0,D.jsx)(`span`,{className:`font-mono text-xs`,children:e.service_request_code})},{key:`date`,label:`Date`,render:e=>n(e.date)},{key:`engineer_count`,label:`Engineers`},{key:`technician_count`,label:`Technicians`},{key:`work_description`,label:`Description`,render:e=>(0,D.jsx)(`span`,{className:`truncate max-w-[200px] block`,children:e.work_description})},{key:`created_by_name`,label:`Created By`,render:e=>e.created_by_name||`—`},{key:`authorized_status`,label:`Approval Status`,render:e=>(0,D.jsx)(x,{status:e.authorized_status})},{key:`actions`,label:`Actions`,sortable:!1,render:t=>(0,D.jsx)(S,{onView:()=>e(`/service-daily-logs/${t.id}`),onEdit:()=>e(`/service-daily-logs/${t.id}/edit`),onDelete:()=>G(t.id),approval:{entityType:`DailyLog`,objectId:t.id,contentTypeId:i.DAILY_LOG,authorizedStatus:t.authorized_status??1,onApprovalChange:()=>B()}})}],isLoading:z,rowKey:e=>e.id,emptyMessage:`No daily logs found`}),(0,D.jsxs)(c,{open:F,onOpenChange:I,onClear:q,children:[(0,D.jsx)(l,{label:`Service Request`,value:k,onChange:A,placeholder:`All Requests`,options:V.map(e=>({value:e.id,label:`${e.code} — ${e.client_name}`}))}),(0,D.jsx)(l,{label:`Auth Status`,value:j,onChange:M,placeholder:`All Status`,options:O}),(0,D.jsx)(l,{label:`Branch`,value:N,onChange:P,placeholder:`All Branches`,options:H.map(e=>({value:String(e.id),label:e.name}))})]}),(0,D.jsx)(y,{open:!!W,onOpenChange:e=>{e||G(null)},children:(0,D.jsxs)(_,{className:`sm:max-w-md`,children:[(0,D.jsx)(h,{children:(0,D.jsx)(v,{children:`Delete Daily Log`})}),(0,D.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Are you sure you want to delete this daily log?`}),(0,D.jsxs)(g,{children:[(0,D.jsx)(d,{variant:`outline`,size:`sm`,onClick:()=>G(null),children:`Cancel`}),(0,D.jsx)(d,{variant:`destructive`,size:`sm`,onClick:K,children:`Delete`})]})]})})]})}export{k as default};