import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{t}from"./react-Augu_vA3.js";import{Dt as n,Si as r,Ut as i,Vi as a,_t as o,st as s,vn as c,zt as l}from"./forms-CL2ODv4X.js";import{t as u}from"./useTranslation-B_YCgyrR.js";import{l as d,o as f}from"./enterprise-plan-7ejkapqa.js";import{t as p}from"./jsx-runtime-CTknu7_t.js";import{t as m}from"./Modal-C4GWc9Ry.js";var h=e(t(),1),g=e(p(),1),_={geoPostalCode:`ZIP`,geoCity:`City`,geoCounty:`County`,geoState:`State`,taxSales:`Sales Tax`,taxUse:`Use Tax`};function v({resourceId:e,resourceType:t,taxData:p,refetchInvoices:v,buttonClassName:y,buttonType:b=`minimal`}){let[x]=u(),S=i(),C=a(),w=o(),T=r(),[E,D]=(0,h.useState)(!1),[O,k]=(0,h.useState)(!1),A=()=>{k(!1)},j=()=>{if(!E){c.processing(),D(!0);let r=`/api/v1/clients/:id/updateTaxData`;t===`company`&&(r=`/api/v1/companies/updateOriginTaxData/:id`),l(`POST`,n(r,{id:e})).then(e=>{t===`client`?S([`clients`]):t===`company`&&(C(d({object:`company`,data:e.data.data})),C(f(`company`))),v&&S([`invoices`]),c.success(`updated_tax_data`),A()}).finally(()=>D(!1))}},M=(e,t)=>e===`taxSales`||e===`taxUse`?`${(t||0)*100} %`:t,N=(0,h.useMemo)(()=>Object.entries(p||{}).filter(([e])=>_[e]),[p]);return T?.settings.country_id!==`840`||!T?.calculate_taxes?null:(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(s,{type:b,behavior:`button`,onClick:()=>k(!0),className:y,children:x(`tax_details`)}),(0,g.jsx)(m,{title:x(`tax_details`),visible:O,onClose:A,size:N.length&&N.every(([e,t])=>t)?`small`:`extraSmall`,disableClosing:E,children:N.length&&N.every(([,e])=>e)?(0,g.jsx)(`div`,{className:`grid grid-cols-2 gap-4`,children:N.map(([e,t])=>(0,g.jsxs)(`div`,{className:`flex items-center gap-x-2`,children:[(0,g.jsxs)(`span`,{className:`text-sm font-medium`,style:{color:w.$3},children:[_[e],`:`]}),(0,g.jsx)(`span`,{className:`text-sm`,style:{color:w.$3},children:M(e,t)})]},e))}):(0,g.jsx)(s,{className:`w-full`,behavior:`button`,onClick:j,children:x(`update_tax_details`)})})]})}export{v as t};