ruạṛ
import{c as e,H as T,bD as _,z as R,u as z,bq as k,p as u,r as E,dJ as I,e as H,j as f,ay as N,fr as U,fs as A,ft as L,fu as M,fv as $,S as B,T as F,bN as G,dv as O,bj as Q,a1 as q,bp as J,h as S,bO as V,W,bt as K,bQ as X,bA as Y,bR as Z,aA as ee,fw as se}from"./bundle.9abe88c8.js";import{P as te,a as ne,b as ae,r as re}from"./react-responsive-e0860c56.js";import{a as w}from"./InvoiceViewer-8cc71da3.js";import{P as oe}from"./PreviousNextNavigation-f6f14b66.js";function C(s){const{children:c,renderBasePanel:o}=s;return o?e(te,{defaultSize:50,minSize:25,children:c}):e(T,{children:c})}function ce(s){const{children:c,renderBasePanelGroup:o}=s;return o?e(ne,{direction:"horizontal",className:"gap-4 mt-4",children:c}):e("div",{className:"flex flex-col gap-4",children:c})}const ie=_(ae)` background-color: ${s=>s.theme.backgroundColor}; &:hover { background-color: ${s=>s.theme.hoverColor}; } `;function le(s){const c=R(),{renderBasePanelResizeHandler:o}=s;return o?e(ie,{className:"flex items-center",theme:{hoverColor:"#3366CC",backgroundColor:c.$5},style:{width:"2.5px"}}):e(T,{})}function ue(s){var l;const[c]=z(),o=k(),{documents:a}=s,x=u.useRef(null),[p,d]=u.useState(""),[h,y]=u.useState(!1),[i,m]=u.useState(0),[g,b]=u.useState(!1),n=()=>{var r;const t=(r=a[i])==null?void 0:r.type;return t==="png"||t==="jpg"||t==="gif"||t==="webp"||t==="tiff"},v=()=>{var r;return((r=a[i])==null?void 0:r.type)==="pdf"};return u.useEffect(()=>{var t;return a.length&&(y(!0),b(!1),a[i]?o.fetchQuery(["/api/v1/documents",(t=a[i])==null?void 0:t.hash],()=>{var r;return E("GET",H("/documents/:hash",{hash:(r=a[i])==null?void 0:r.hash}),{headers:I()},{responseType:"arraybuffer"})},{staleTime:1/0}).then(r=>{const P=new Blob([r.data],{type:r.headers["content-type"]});n()?d(URL.createObjectURL(P)):!w&&x.current&&v()?x.current.src=URL.createObjectURL(P):b(!0)}).finally(()=>y(!1)):m(0)),()=>{d(""),y(!1),b(!1)}},[a,i]),w?e("p",{children:"Unable to preview PDF. "}):f(T,{children:[a.length?f("div",{className:"flex flex-col",children:[!h&&f("div",{className:"flex self-end pb-1",children:[e(N,{className:"cursor-pointer",element:U,size:25,onClick:()=>m(0)}),e(N,{className:"cursor-pointer",element:A,size:25,onClick:()=>i!==0&&m(t=>t-1)}),e(N,{className:"cursor-pointer",element:L,size:25,onClick:()=>i!==a.length-1&&m(t=>t+1)}),e(N,{className:"cursor-pointer",element:M,size:25,onClick:()=>m(a.length-1)})]}),n()&&!h&&!g&&e("img",{className:"w-full",src:p}),e("iframe",{ref:x,width:"100%",height:h||!v()||g?0:1500}),g&&e("div",{className:"flex h-full justify-center items-center",children:e($,{type:(l=a[i])==null?void 0:l.type,size:150})})]}):f("div",{className:"flex justify-center",children:[c("no_records_found"),"."]}),h&&e("div",{className:"flex justify-center items-center h-full",children:e(B,{})})]})}function he(){const[s]=z(),{documentTitle:c}=F("edit_expense"),{id:o}=G(),a=O(),x=R(),{data:p}=Q({id:o}),d=re.useMediaQuery({query:"(min-width: 1024px)"}),h=q(),y=J(),i=[{name:s("expenses"),href:"/expenses"},{name:s("edit_expense"),href:S("/expenses/:id/edit",{id:o})}],m=[{name:s("edit"),href:S("/expenses/:id/edit",{id:o})},{name:s("documents"),href:S("/expenses/:id/documents",{id:o}),formatName:()=>e(V,{numberOfDocuments:n==null?void 0:n.documents.length})}],[g,b]=u.useState(),[n,v]=u.useState(),[l,t]=u.useState(!1),[r,P]=u.useState("by_rate"),D=se({setErrors:b});return u.useEffect(()=>{p&&(v(p),P(p.calculate_tax_by_amount?"by_amount":"by_rate"))},[p]),e(W,{title:c,breadcrumbs:i,...(h("edit_expense")||y(n))&&n&&{navigationTopRight:e(K,{resource:n,onSaveClick:()=>D(n),actions:a,disableSaveButton:!n,cypressRef:"expenseActionDropdown"})},afterBreadcrumbs:e(oe,{entity:"expense"}),children:n?f("div",{className:"space-y-4",children:[e(X,{tabs:m,rightSide:f("div",{className:"flex items-center justify-end space-x-3",children:[e("span",{className:"text-sm",children:s("preview")}),e(Y,{checked:l,onValueChange:j=>t(j)})]})}),f(ce,{renderBasePanelGroup:l&&d,children:[e(C,{renderBasePanel:l&&d,children:e(Z,{context:{errors:g,setErrors:b,expense:n,setExpense:v,taxInputType:r,setTaxInputType:P,isPreviewMode:l}})}),e(le,{renderBasePanelResizeHandler:l&&d}),l&&!d&&e(ee,{className:"pt-4",withoutPadding:!0,borderColor:x.$5}),e(C,{renderBasePanel:l&&d,children:l&&e(ue,{documents:n.documents})})]})]}):e(B,{})})}export{he as default};
cải xoăn