import{a as e,t}from"./react-DK-MTtD8.js";import{r as n,s as r}from"./utils-CXcsdpX-.js";import{r as i}from"./api-DcvYaav1.js";import{t as a}from"./list-table-CQD2C7IB.js";import{t as o}from"./funnel-BT4pjjO7.js";import{t as s}from"./plus-CuMPbIyn.js";import{n as c,t as l}from"./filter-sheet-omdfG0qY.js";import{Hr as u,rs as d,za as f}from"./index-Ct5uU080.js";import{t as p}from"./page-content-Bh5Zxb_Y.js";import{t as m}from"./badge-CL1e8lO_.js";import{a as h,i as g,n as _,o as v,t as y}from"./dialog-DuXDR687.js";import{t as b}from"./list-page-header-CePoWpko.js";import{t as x}from"./auth-status-badge-BlJK5R24.js";import{t as S}from"./row-actions-bhl00K6X.js";import{F as C,_ as w,k as T}from"./serviceApi-Bn3V4hja.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=d(),[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=[]}=u(),[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)(f,{onClick:()=>e(`/service-daily-logs/new`),children:[(0,D.jsx)(s,{className:`size-4 mr-2`}),` New Daily Log`]}),filter:(0,D.jsxs)(f,{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)(f,{variant:`outline`,size:`sm`,onClick:()=>G(null),children:`Cancel`}),(0,D.jsx)(f,{variant:`destructive`,size:`sm`,onClick:K,children:`Delete`})]})]})})]})}export{k as default};