import{u as b,a as v,f as C,bV as X,j as e,m as d,bW as $,bX as h,h as c,bY as Y,bZ as A,aB as S,y as J,a6 as ee,a7 as se,a8 as te,ah as ie,aA as ne,b_ as re,g as oe,p as f,av as le,d as ae,b$ as de,b as E,c0 as ce,c1 as me,c2 as a,ba as p,bn as ue,c3 as xe,c4 as he,F as pe,bA as be,c5 as je,bH as ye,O as fe,R as ge,N as _e,D as ve,i as B,I as Ce,a3 as $e,bg as Ne,c6 as ke,c7 as we,bR as P,c8 as Te,r as g,e as _,a4 as N,c9 as Se}from"./bundle.CHKSNOJF.js";import{u as Ee}from"./Actions-Cg-_a1t3.js";import{I as Pe}from"./InvoiceStatus-1S0ZEgN9.js";import{g as Re,I as Ae}from"./invoicePaymentAllocations-DCHktVYy.js";import{E as Be}from"./EmailRecord-BnH9Xgsc.js";import{C as Ie,V as ze}from"./CloudPlay-DAhKDxQn.js";import{H as Fe}from"./History-n6M92Y0g.js";import{C as He}from"./chevron-right-CHJ6fP-X.js";function Le(o){const{expenseId:n}=o,[s]=b(),l=v(),{dateFormat:r}=C(),{data:t}=X({id:n});return e.jsx(e.Fragment,{children:t&&e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsxs("span",{className:"text-sm",style:{color:l.$3},children:[d(t.date,r)," -"]}),e.jsx("span",{className:"text-sm",style:{color:l.$3},children:s("expense")}),e.jsx("div",{children:e.jsx($,{color:l.$17,size:"1.1rem"})}),e.jsxs(h,{to:c("/expenses/:id/edit",{id:n}),children:["# ",t.number]})]})})}function Ve(o){const{taskId:n}=o,[s]=b(),l=v(),{dateFormat:r}=C(),{data:t}=Y({id:n});return e.jsx(e.Fragment,{children:t&&e.jsxs("div",{className:"flex items-center space-x-1",children:[t.date&&e.jsxs("span",{className:"text-sm",style:{color:l.$3},children:[d(t.date,r)," -"]}),e.jsx("span",{className:"text-sm",style:{color:l.$3},children:s("task")}),e.jsx("div",{children:e.jsx($,{color:l.$17,size:"1.1rem"})}),e.jsxs(h,{to:c("/tasks/:id/edit",{id:n}),children:["# ",t.number]})]})})}const qe=A(null),De=A(!1);B.extend(Se);const R=N.div`
  background-color: ${({theme:o})=>o.backgroundColor};

  &:hover {
    background-color: ${({theme:o})=>o.hoverBackgroundColor};
  }
`,Oe=N.div`
  background-color: ${({theme:o})=>o.backgroundColor};

  &:hover {
    background-color: ${({theme:o})=>o.hoverBackgroundColor};
  }
`,Ge=N.div`
  background-color: ${({theme:o})=>o.backgroundColor};

  &:hover {
    background-color: ${({theme:o})=>o.hoverBackgroundColor};
  }
`;function Me(){const[o]=b();return n=>{let s=P(`activity_${n.activity_type_id}`,{});n.activity_type_id===10&&n.client&&(s=P("activity_10_online",{}).replace(":contact",":client")),n.activity_type_id===54&&n.client&&(s=s.replace(":user",":client"));const l={client:e.jsx(h,{to:c("/clients/:id",{id:n.client?.hashed_id}),children:n.client?.label}),user:n.user?.label??o("system"),invoice:e.jsx(h,{to:c("/invoices/:id/edit",{id:n.invoice?.hashed_id}),children:n?.invoice?.label}),recurring_invoice:e.jsx(h,{to:c("/recurring_invoices/:id/edit",{id:n?.recurring_invoice?.hashed_id}),children:n?.recurring_invoice?.label}),contact:e.jsx(h,{to:c("/clients/:id/edit",{id:n?.contact?.hashed_id}),children:n?.contact?.label}),notes:n?.notes&&e.jsxs(e.Fragment,{children:[e.jsx("br",{}),"'",n?.notes,"'"]}),payment_amount:n?.payment_amount?.label,payment:e.jsx(h,{to:c("/payments/:id/edit",{id:n?.payment?.hashed_id}),children:n?.payment?.label}),credit:e.jsx(h,{to:c("/credits/:id/edit",{id:n?.credit?.hashed_id}),children:n?.credit?.label})};for(const[r,t]of Object.entries(l))s=Te(s,`:${r}`,()=>t);return s}}function es(){const[o,n]=S(De),[s,l]=S(qe),[r]=b(),t=v(),I=J(),z=ee(),F=se(),H=te({withTimezone:!0,formatOnlyDate:!0}),L=ie(),V=ne(),q=re(),D=oe(),O=Me(),[j,G]=f.useState(!1),[k,M]=f.useState([]),Q=le(),y=ae(),{actions:W,modal:K}=Ee({showCommonBulkAction:!0,showEditAction:!0}),{timeFormat:w}=de(),{dateFormat:m}=C(),{data:u}=E({queryKey:["/api/v1/invoices",s?.id,"payments"],queryFn:()=>g("GET",_(`/api/v1/invoices/${s?.id}?include=paymentables,payments,activities.history&reminder_schedule=true&show_schedule=true`)).then(i=>i.data.data),enabled:s!==null&&o,staleTime:1/0}),T=Re(u),Z=async()=>{const i=await Q.fetchQuery(["/api/v1/invoices",s?.id,"emailHistory"],()=>g("POST",_("/api/v1/emails/entityHistory"),{entity:"invoice",entity_id:s?.id}),{staleTime:1/0}).then(x=>x.data);M(i)},{data:U}=E({queryKey:["/api/v1/activities/entity",s?.id],queryFn:()=>g("POST",_("/api/v1/activities/entity"),{entity:"invoice",entity_id:s?.id}).then(i=>i.data.data),enabled:s!==null&&o,staleTime:1/0});return f.useEffect(()=>{s&&Z()},[s]),e.jsxs(ce,{visible:o,onClose:()=>{n(!1),l(null)},size:"regular",title:`${r("invoice")} ${s?.number}`,topRight:s&&(V("edit_invoice")||q(s))?e.jsx(we,{label:r("actions"),resource:s,actions:W}):null,withoutActionContainer:!0,withoutHeaderBorder:!0,children:[e.jsxs(me,{tabs:[r("overview"),r("history"),r("activity"),r("email_history")],width:"full",withHorizontalPadding:!0,horizontalPaddingWidth:"1.5rem",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"px-6",children:[e.jsx(a,{className:"border-b border-dashed",leftSide:r("invoice_amount"),pushContentToRight:!0,withoutWrappingLeftSide:!0,noExternalPadding:!0,style:{borderColor:t.$20},children:s?y(s?.amount,s.client?.country_id,s.client?.settings.currency_id):null}),e.jsx(a,{className:"border-b border-dashed",leftSide:r("balance_due"),pushContentToRight:!0,withoutWrappingLeftSide:!0,noExternalPadding:!0,style:{borderColor:t.$20},children:s?y(s.balance,s.client?.country_id,s.client?.settings.currency_id):null}),e.jsx(a,{className:"border-b border-dashed",leftSide:r("date"),pushContentToRight:!0,noExternalPadding:!0,style:{borderColor:t.$20},children:s?d(s?.date,m):null}),e.jsx(a,{className:"border-b border-dashed",leftSide:r("due_date"),pushContentToRight:!0,noExternalPadding:!0,style:{borderColor:t.$20},children:s?d(s.due_date,m):null}),e.jsx(a,{leftSide:r("status"),pushContentToRight:!0,noExternalPadding:!0,children:s?e.jsx(Pe,{entity:s}):null})]}),e.jsx(p,{withoutPadding:!0,borderColor:t.$20}),e.jsxs("div",{className:"flex space-x-4 items-center justify-center px-6 py-5",children:[e.jsxs(R,{className:"flex flex-col items-center justify-center space-y-2 shadow-sm border px-14 py-5 cursor-pointer rounded-md",onClick:()=>s?ue(s):null,style:{borderColor:t.$20},theme:{backgroundColor:t.$1,hoverBackgroundColor:t.$4},children:[e.jsx(Ie,{color:t.$17,filledColor:t.$17,size:"1.3rem"}),e.jsx("span",{className:"font-medium whitespace-nowrap",style:{color:t.$3},children:r("view_portal")})]}),s?e.jsxs(R,{className:"flex flex-col items-center justify-center space-y-2 shadow-sm border px-14 py-5 cursor-pointer rounded-md",onClick:()=>{navigator.clipboard.writeText(he(s)??""),pe.success("copied_to_clipboard",{value:""})},style:{borderColor:t.$20},theme:{backgroundColor:t.$1,hoverBackgroundColor:t.$4},children:[e.jsx(xe,{color:t.$17,filledColor:t.$17,size:"1.3rem"}),e.jsx("span",{className:"font-medium whitespace-nowrap",style:{color:t.$3},children:r("copy_link")})]}):null]}),e.jsx(p,{withoutPadding:!0,borderColor:t.$20}),s&&s.next_send_date?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2 whitespace-nowrap px-6",children:[e.jsx(be,{size:"regular",width:"auto",tooltipElement:e.jsx("article",{className:fe("prose prose-sm",{"prose-invert":!I?.dark_mode}),dangerouslySetInnerHTML:{__html:ye(u?.reminder_schedule??"")}}),children:e.jsxs("h3",{className:"flex mt-2 italic",children:[r("reminders")," ",e.jsx(je,{className:"mt-1 ml-1"})]})}),e.jsx(a,{className:"border-b border-dashed",leftSide:r("next_send_date"),pushContentToRight:!0,noExternalPadding:!0,withoutWrappingLeftSide:!0,style:{borderColor:t.$20},children:s?H(s.next_send_date,"","",F(z(s.client,"timezone_id")).timeZone):null}),e.jsx(a,{className:"border-b border-dashed",leftSide:r("reminder_last_sent"),pushContentToRight:!0,noExternalPadding:!0,style:{borderColor:t.$20},children:s?d(s.reminder_last_sent,m):null}),s.reminder1_sent?e.jsx(a,{className:"border-b border-dashed",leftSide:r("first_reminder"),pushContentToRight:!0,noExternalPadding:!0,style:{borderColor:t.$20},children:s?d(s.reminder1_sent,m):null}):null,s.reminder2_sent?e.jsx(a,{className:"border-b border-dashed",leftSide:r("second_reminder"),pushContentToRight:!0,noExternalPadding:!0,style:{borderColor:t.$20},children:s?d(s.reminder2_sent,m):null}):null,s.reminder3_sent?e.jsx(a,{leftSide:r("third_reminder"),pushContentToRight:!0,noExternalPadding:!0,children:s?d(s.reminder3_sent,m):null}):null]}),e.jsx(p,{withoutPadding:!0,borderColor:t.$20})]}):null,s&&!!T.length&&e.jsx("div",{className:"flex flex-col space-y-4 px-6 py-5",children:T.map(i=>e.jsx(Ae,{row:i,invoice:s,dateFormat:m},i.paymentable.id))}),!!s?.line_items?.some(i=>i.expense_id||i.task_id)&&e.jsx(p,{withoutPadding:!0,borderColor:t.$20}),s&&e.jsx("div",{className:"flex flex-col px-6 py-5",children:s.line_items.map((i,x)=>(i.expense_id||i.task_id)&&e.jsxs(ge.Fragment,{children:[i.expense_id&&e.jsx(Le,{expenseId:i.expense_id}),i.task_id&&e.jsx(Ve,{taskId:i.task_id})]},x))}),!!s?.line_items?.length&&e.jsx(p,{withoutPadding:!0,borderColor:t.$20}),s&&!!s.line_items?.length&&e.jsx("div",{className:"flex flex-col space-y-3 px-6 py-5",children:s.line_items.map((i,x)=>e.jsx(ze,{lineItem:i,lineItemIndex:x,client:s.client,editHref:c("/invoices/:id/edit",{id:s.id})},x))})]}),e.jsxs("div",{children:[u?.activities&&u.activities.filter(({history:i})=>i?.id).length===0&&e.jsx(_e,{children:r("api_404")}),!!u?.activities?.length&&e.jsx("div",{className:"flex flex-col px-3 gap-3",children:u?.activities&&u.activities.filter(({history:i})=>i?.id).map(i=>e.jsxs(Oe,{className:"flex items-center justify-between p-4 rounded-md cursor-pointer",onClick:()=>L(c("/activities/:id",{id:i.id})),theme:{backgroundColor:t.$4,hoverBackgroundColor:t.$15},children:[e.jsxs("div",{className:"flex items-center justify-start space-x-3",children:[e.jsx("div",{className:"p-2 rounded-full",style:{backgroundColor:t.$20},children:e.jsx(Fe,{size:"1.3rem",color:t.$16,filledColor:t.$16})}),e.jsxs("div",{className:"flex flex-col items-start space-y-0.5 justify-center",children:[e.jsxs("div",{className:"flex space-x-1 text-sm",children:[e.jsx("span",{style:{color:t.$3},children:s?.client?y(i.history.amount,s?.client?.country_id,s?.client?.settings.currency_id):null}),e.jsx("div",{children:e.jsx($,{color:t.$17,size:"1.1rem"})}),e.jsx(ve,{to:`/clients/${i.client_id}`,renderSpan:D("client",s?.client),children:s?.client?.display_name})]}),e.jsxs("div",{className:"flex items-center space-x-1 text-xs",style:{color:t.$17},children:[e.jsx("span",{children:d(i.created_at,`${m} ${w}`)}),e.jsx("span",{children:B.unix(i.created_at).fromNow()})]})]})]}),e.jsx("div",{children:e.jsx(Ce,{element:He,size:16,color:t.$17})})]},i.id))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center border-b px-6 pb-4 justify-between",style:{borderColor:t.$20},children:[e.jsx($e,{label:r("comments_only"),checked:j,onValueChange:i=>G(i)}),e.jsx(Ne,{entity:"invoice",entityId:u?.id,label:u?.number||""})]}),e.jsx("div",{className:"flex flex-col pt-3 px-3",children:U?.filter(i=>j&&i.activity_type_id===141||!j).map(i=>e.jsxs(Ge,{className:"flex space-x-3 p-4 rounded-md flex-1 min-w-0",theme:{backgroundColor:t.$1,hoverBackgroundColor:t.$25},children:[e.jsx("div",{className:"flex items-center justify-center",children:e.jsx("div",{className:"p-2 rounded-full",style:{backgroundColor:t.$20},children:e.jsx(ke,{size:"1.3rem",color:t.$16,filledColor:t.$16})})}),e.jsxs("div",{className:"flex flex-col space-y-0.5 flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm",style:{color:t.$3},children:O(i)}),e.jsxs("div",{className:"flex w-full items-center space-x-1 text-xs truncate",style:{color:t.$17},children:[e.jsx("span",{className:"whitespace-nowrap",children:d(i.created_at,`${m} ${w}`)}),e.jsx("span",{children:"-"}),e.jsx("span",{children:i.ip})]})]})]},i.id))})]}),e.jsxs("div",{className:"flex flex-col space-y-2 px-6",children:[!k.length&&e.jsx("span",{className:"text-sm px-4",style:{color:t.$3},children:r("email_history_empty")}),k.map((i,x)=>e.jsx(Be,{className:"py-4",emailRecord:i,index:x,withAllBorders:!0},x))]})]}),K]})}export{es as I,De as a,qe as i,Me as u};
