PageSourceSearch

https://reconcilia.ai/assets/index-B03fOAEb.js

js reconcilia.ai collected 2026-10-05 12:56:49 UTC 52,613 bytes, 2 lines download raw bytes

1import{u as ie,j as e,I as V,r as l,H as we}from"./index-ChEkzv_B.js";import{B as f}from"./Button-CoJi2g7X.js";import{I as re}from"./Input-C2TKLSFl.js";import{S as K}from"./Select-CZ0ojyrf.js";import{C as ke}from"./Checkbox-QFLBX1RM.js";import{A as ue}from"./aiActions.service-Cu0P45pB.js";import{a as Ie,l as Ae,d as De,u as me,c as Se}from"./entities.service-Dl6aPKzm.js";import{l as Te,u as Ee,d as Pe,a as Re}from"./documents.service-DOTZUyUl.js";import{u as _e}from"./FullAppRoutes-DUak_EFb.js";import"./useTheme-IIvREq4S.js";import"./BootstrapContext-XGikMoXs.js";import"./index-BhYmDm8j.js";import"./EChart-DcFwBBq4.js";const Fe=({entities:t,onEdit:u,onEnable:v,onDisable:d,onDelete:m,onDocuments:y,isGuided:s=!1,isExpert:x=!1,isSavingStatus:c=!1,onSort:p,renderSortIcon:S})=>{const{t:n,currentLanguage:I}=ie(),P=o=>o?new Date(o)?.toLocaleDateString(I):n("entities.common.unknown","Unknown"),q=o=>({EIN:"EIN",VAT:"VAT",RFC:"RFC",RUC:"RUC",CUIT:"CUIT",CPF:"CPF",CNPJ:"CNPJ",NIF:"NIF",DNI:"DNI",OTHER:n("entities.taxIdTypes.other","Other")})?.[o]||o,T=(o,R)=>e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 text-left hover:text-foreground",onClick:()=>p?.(o),"aria-label":n("entities.table.sortByAria","Sort entities by {{label}}",{label:R}),children:[e.jsx("span",{children:R}),S?.(o)]});return e.jsx("div",{className:"overflow-x-auto rounded-lg border border-border",children:e.jsxs("table",{className:"min-w-[980px] w-full border-collapse text-sm",children:[e.jsx("thead",{className:"sticky top-0 z-10 bg-card text-xs uppercase tracking-[0.08em] text-muted-foreground",children:e.jsxs("tr",{className:"border-b border-border",children:[e.jsx("th",{className:"px-4 py-[var(--app-table-header-padding-y)] text-left font-semibold",children:T("name",n("entities.table.name","Entity"))}),e.jsx("th",{className:"px-4 py-[var(--app-table-header-padding-y)] text-left font-semibold",children:n("entities.table.taxId","Tax ID")}),e.jsx("th",{className:"px-4 py-[var(--app-table-header-padding-y)] text-left font-semibold",children:T("currency",n("entities.table.currency","Currency"))}),e.jsx("th",{className:"px-4 py-[var(--app-table-header-padding-y)] text-left font-semibold",children:T("status",n("entities.table.status","Status"))}),e.jsx("th",{className:"px-4 py-[var(--app-table-header-padding-y)] text-left font-semibold",children:T("createdAt",n("entities.table.created","Created"))}),e.jsx("th",{className:"px-4 py-[var(--app-table-header-padding-y)] text-left font-semibold",children:T("updatedAt",n("entities.table.updated","Updated"))}),e.jsx("th",{className:"px-4 py-[var(--app-table-header-padding-y)] text-right font-semibold",children:n("entities.table.actions","Actions")})]})}),e.jsx("tbody",{children:t?.map(o=>e.jsxs("tr",{className:"border-b border-border last:border-b-0 hover:bg-muted/30",children:[e.jsx("td",{className:"px-4 py-[var(--app-row-padding-y)] align-top",children:e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx("div",{className:"w-8 h-8 bg-primary/10 rounded-lg flex items-center justify-center",children:e.jsx(V,{name:"Building",size:16,className:"text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-foreground",children:o?.name}),!x&&o?.activityDescription&&e.jsx("p",{className:"mt-1 max-w-sm truncate text-xs text-muted-foreground",children:o.activityDescription}),s&&e.jsx("p",{className:"text-xs text-muted-foreground",children:o?.id})]})]})}),e.jsx("td",{className:"px-4 py-[var(--app-row-padding-y)] align-top",children:e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:q(o?.taxIdType)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:o?.taxId})]})}),e.jsx("td",{className:"px-4 py-[var(--app-row-padding-y)] align-top",children:e.jsx("span",{className:"inline-flex items-center rounded-full border border-border px-2 py-0.5 text-xs text-muted-foreground",children:o?.currency})}),e.jsx("td",{className:"px-4 py-[var(--app-row-padding-y)] align-top",children:e.jsxs("span",{className:`inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium ${o?.isActive!==!1?"bg-success/10 text-success":"bg-warning/10 text-warning"}`,children:[e.jsx("div",{className:`w-1.5 h-1.5 rounded-full mr-1.5 ${o?.isActive!==!1?"bg-success":"bg-warning"}`}),o?.isActive!==!1?n("entities.status.active","Active"):n("entities.status.inactive","Inactive")]})}
1),e.jsx("td",{className:"px-4 py-[var(--app-row-padding-y)] align-top",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:P(o?.createdAt)})}),e.jsx("td",{className:"px-4 py-[var(--app-row-padding-y)] align-top",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:P(o?.updatedAt)})}),e.jsx("td",{className:"px-4 py-[var(--app-row-padding-y)] align-top",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[e.jsx(f,{variant:"ghost",size:"sm",onClick:()=>u(o?.id),iconName:"Edit","aria-label":n("entities.card.editAria","Edit {{name}}",{name:o?.name||n("entities.common.entity","entity")}),children:s?n("entities.table.edit","Edit"):null}),e.jsx(f,{variant:"ghost",size:"sm",onClick:()=>y?.(o),iconName:"FileText","aria-label":n("entities.card.documentsAria","Documents for {{name}}",{name:o?.name||n("entities.common.entity","entity")}),children:x?null:n("entities.table.documents","Documents")}),o?.isActive!==!1?e.jsx(f,{variant:"ghost",size:"sm",onClick:()=>d(o?.id),iconName:"XCircle",className:"text-warning hover:text-warning","aria-label":n("entities.card.disableAria","Deactivate {{name}}",{name:o?.name||n("entities.common.entity","entity")}),disabled:c,children:x?null:n("entities.card.disable","Disable")}):e.jsx(f,{variant:"ghost",size:"sm",onClick:()=>v(o?.id),iconName:"CheckCircle",className:"text-success hover:text-success","aria-label":n("entities.card.enableAria","Activate {{name}}",{name:o?.name||n("entities.common.entity","entity")}),disabled:c,children:x?null:n("entities.card.enable","Enable")}),o?.isActive===!1?e.jsx(f,{variant:"ghost",size:"sm",onClick:()=>m?.(o?.id),iconName:"Trash2",className:"text-error hover:text-error","aria-label":n("entities.card.deleteAria","Delete {{name}}",{name:o?.name||n("entities.common.entity","entity")}),disabled:c,children:x?null:n("entities.card.delete","Delete")}):null]})})]},o?.id))})]})})},Ue=({entity:t,onEdit:u,onEnable:v,onDisable:d,onDelete:m,onDocuments:y,isGuided:s=!1,isExpert:x=!1})=>{const{t:c,currentLanguage:p}=ie(),S=I=>I?new Date(I)?.toLocaleDateString(p):c("entities.common.unknown","Unknown"),n=I=>({EIN:"EIN",VAT:"VAT",RFC:"RFC",RUC:"RUC",CUIT:"CUIT",CPF:"CPF",CNPJ:"CNPJ",NIF:"NIF",DNI:"DNI",OTHER:c("entities.taxIdTypes.other","Other")})?.[I]||I;return e.jsxs("div",{className:"bg-card border border-border rounded-lg p-4 hover:shadow-md transition-shadow",children:[e.jsx("div",{className:"flex items-start justify-between mb-4",children:e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx("div",{className:"w-10 h-10 bg-primary/10 rounded-lg flex items-center justify-center",children:e.jsx(V,{name:"Building",size:20,className:"text-primary"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-foreground",children:t?.name}),e.jsxs("span",{className:`inline-flex items-center px-2 py-1 rounded-full text-xs font-medium ${t?.isActive!==!1?"bg-success/10 text-success":"bg-warning/10 text-warning"}`,children:[e.jsx("div",{className:`w-1.5 h-1.5 rounded-full mr-1.5 ${t?.isActive!==!1?"bg-success":"bg-warning"}`}),t?.isActive!==!1?c("entities.status.active","Active"):c("entities.status.inactive","Inactive")]})]})]})}),e.jsxs("div",{className:"space-y-3 mb-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:c("entities.card.taxId","Tax ID")}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:n(t?.taxIdType)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t?.taxId})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:c("entities.card.currency","Currency")}),e.jsx("span",{className:"inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-accent/10 text-accent",children:t?.currency})]}),t?.activityDescription&&e.jsxs("div",{children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:c("entities.card.activity","Activity")}),e.jsx("p",{className:"mt-1 text-sm text-foreground",children:t.activityDescription})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:c("entities.card.created","Created")}),e.jsx("span",{className:"text-sm text-foreground",children:S(t?.createdAt)})]}),s&&t?.updatedAt!==t?.createdAt&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:c("entities.card.updated","Updated")}),e.jsx("span",{className:"text-sm text-foreground",children:S(t?.updatedAt)})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 pt-4 border-t border-border",children:[e.jsx(f,{variant:"ghost",size:"sm",onClick:()=>u(t?.id),iconName:"Edit",iconPosition:"left","aria-label":c("entities.card.editAria","E
1dit {{name}}",{name:t?.name||c("entities.common.entity","entity")}),children:x?null:c("entities.card.edit","Edit")}),e.jsx(f,{variant:"ghost",size:"sm",onClick:()=>y?.(t),iconName:"FileText",iconPosition:"left","aria-label":c("entities.card.documentsAria","Documents for {{name}}",{name:t?.name||c("entities.common.entity","entity")}),children:x?null:c("entities.card.documents","Documents")}),t?.isActive!==!1?e.jsx(f,{variant:"ghost",size:"sm",onClick:()=>d(t?.id),iconName:"XCircle",iconPosition:"left",className:"text-warning hover:text-warning","aria-label":c("entities.card.disableAria","Deactivate {{name}}",{name:t?.name||c("entities.common.entity","entity")}),children:x?null:c("entities.card.disable","Disable")}):e.jsx(f,{variant:"ghost",size:"sm",onClick:()=>v(t?.id),iconName:"CheckCircle",iconPosition:"left",className:"text-success hover:text-success","aria-label":c("entities.card.enableAria","Activate {{name}}",{name:t?.name||c("entities.common.entity","entity")}),children:x?null:c("entities.card.enable","Enable")}),t?.isActive===!1?e.jsx(f,{variant:"ghost",size:"sm",onClick:()=>m?.(t?.id),iconName:"Trash2",iconPosition:"left",className:"text-error hover:text-error","aria-label":c("entities.card.deleteAria","Delete {{name}}",{name:t?.name||c("entities.common.entity","entity")}),children:x?null:c("entities.card.delete","Delete")}):null]})]})},ze=({isOpen:t,onClose:u,onSave:v,entity:d,isGuided:m=!1,isExpert:y=!1})=>{const{t:s,currentLanguage:x}=ie(),c=s("entities.ai.generalUnavailable","General AI configuration is not set."),[p,S]=l.useState({name:"",taxIdType:"",taxId:"",activityDescription:"",countryCode:"",currency:"USD",isActive:!0}),[n,I]=l.useState({}),[P,q]=l.useState(!1),[T,o]=l.useState({available:!1,reason:c}),[R,X]=l.useState(!1),[N,z]=l.useState(!1),[J,U]=l.useState(""),[L,_]=l.useState(null),[Y,C]=l.useState("suggested"),[O,A]=l.useState([]),[H,M]=l.useState(!1),B=l.useMemo(()=>{let i=null;try{i=new Intl.DisplayNames([x||"en"],{type:"region"})}catch{i=null}return O.map(b=>{const w=b?.alpha2Code||"",W=w&&i?.of(w)||b?.name||w;return{value:w,label:`${W} (${w})`}})},[O,x]),G=[{value:"EIN",label:"EIN"},{value:"VAT",label:"VAT"},{value:"RFC",label:"RFC"},{value:"RUC",label:"RUC"},{value:"CUIT",label:"CUIT"},{value:"CPF",label:"CPF"},{value:"CNPJ",label:"CNPJ"},{value:"NIF",label:"NIF"},{value:"DNI",label:"DNI"},{value:"OTHER",label:s("entities.taxIdTypes.other","Other")}],j=[{value:"USD",label:s("entities.currency.usd","USD - US Dollar")},{value:"EUR",label:s("entities.currency.eur","EUR - Euro")},{value:"GBP",label:s("entities.currency.gbp","GBP - British Pound")},{value:"CAD",label:s("entities.currency.cad","CAD - Canadian Dollar")},{value:"MXN",label:s("entities.currency.mxn","MXN - Mexican Peso")},{value:"BRL",label:s("entities.currency.brl","BRL - Brazilian Real")},{value:"COP",label:s("entities.currency.cop","COP - Colombian Peso")},{value:"ARS",label:s("entities.currency.ars","ARS - Argentine Peso")},{value:"CLP",label:s("entities.currency.clp","CLP - Chilean Peso")},{value:"PEN",label:s("entities.currency.pen","PEN - Peruvian Sol")},{value:"JPY",label:s("entities.currency.jpy","JPY - Japanese Yen")},{value:"CNY",label:s("entities.currency.cny","CNY - Chinese Yuan")}];l.useEffect(()=>{S(d?{name:d?.name||"",taxIdType:d?.taxIdType||"",taxId:d?.taxId||"",activityDescription:d?.activityDescription||"",countryCode:d?.countryCode||"",currency:d?.currency||"USD",isActive:d?.isActive??!0}:{name:"",taxIdType:"",taxId:"",activityDescription:"",countryCode:"",currency:"USD",isActive:!0}),I({}),U(""),_(null),C("suggested")},[d,t]),l.useEffect(()=>{if(!t)return;let i=!1;return M(!0),Ie().then(b=>{i||A(b?.items??[])}).catch(b=>{i||(console.error("Error loading countries:",b),A([]))}).finally(()=>{i||M(!1)}),()=>{i=!0}},[t]),l.useEffect(()=>{if(!t)return;let i=!1;const b=new AbortController;return X(!0),ue.getAvailability({taskType:"general"},{signal:b.signal}).then(w=>{i||o({available:!!w?.available,reason:w?.reason||null,providerName:w?.providerName||null,modelId:w?.modelId||null})}).catch(w=>{i||w?.name==="AbortError"||o({available:!1,reason:c})}).finally(()=>{i||X(!1)}),()=>{i=!0,b.abort()}},[t,c]);const Z=()=>{const i={};return p?.name?.trim()||(i.name=s("entities.validation.nameRequired","Entity name is required")),p?.countryCode||(i.countryCode=s("entities.validation.countryRequired","Country is required")),p?.taxId&&!p?.taxId?.trim()&&(i.taxId=s("entities.validation.taxIdValueRequired","Tax ID value is required when type is selected")),p?.taxId?.trim()&&!p?.taxIdType&&(i.taxIdType=s("entities.validation.taxIdTypeRequired","Tax ID type is required when value is provided")),I(i),Object.keys(i)?.length===0},F=async i=>{if(i?.preventDefault(),!!Z()){q(!0);try{await v(p)}catch(b){console.error("Error saving entity:",b)}finally{q(!1)}}},$=(i,b)=>{S(w=>({...w,[i]:b})),U(""),i==="activityDescription"&&(_(null),C("suggested")),n?.[i]&&I(w=>({...w,[i]:""}))},ee=async()=>
1{if(N)return;const i=p?.name?.trim();if(!i){U(s("entities.ai.enterName","Enter the entity name before using Reconcilia AI."));return}U(""),_(null),z(!0);try{const b=await ue.improveEntityActivityDescription({entityName:i,currency:p?.currency||null,taxIdType:p?.taxIdType||null,currentActivityDescription:p?.activityDescription||null});_(b),C("suggested")}catch(b){const w=b?.status===409?c:b?.status===502?b?.message&&b.message!=="ai_action_failed"?b.message:s("entities.ai.providerFailed","The AI provider could not create a suggestion. Test the General route and try again."):b?.message||s("entities.ai.suggestionFailed","Reconcilia AI could not create a suggestion.");U(w)}finally{z(!1)}},te=()=>{L?.suggestion&&(S(i=>({...i,activityDescription:L.suggestion})),_(null),C("suggested"))},r=()=>{_(null),C("suggested")};return t?e.jsx("div",{className:"fixed inset-0 z-50 overflow-y-auto",children:e.jsxs("div",{className:"flex min-h-screen items-center justify-center p-4",children:[e.jsx("div",{className:"fixed inset-0 bg-black/50 transition-opacity",onClick:u}),e.jsxs("div",{className:"relative flex max-h-[92dvh] w-full max-w-3xl flex-col overflow-hidden rounded-lg border border-border bg-card shadow-lg",children:[e.jsxs("div",{className:"flex shrink-0 items-center justify-between border-b border-border p-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-foreground",children:d?s("entities.modal.editTitle","Edit Entity"):s("entities.modal.createTitle","New Entity")}),e.jsx(f,{variant:"ghost",size:"sm",onClick:u,iconName:"X",className:"text-muted-foreground hover:text-foreground","aria-label":s("entities.modal.close","Close entity modal")})]}),e.jsxs("form",{onSubmit:F,className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:`grid min-h-0 gap-4 overflow-y-auto p-6 md:grid-cols-2 ${y?"md:gap-y-4":"md:gap-y-5"}`,children:[e.jsx("div",{className:"order-1 md:col-span-2",children:e.jsx(re,{label:s("entities.form.name","Entity Name"),placeholder:s("entities.form.namePlaceholder","Enter entity name"),value:p?.name,onChange:i=>$("name",i?.target?.value),error:n?.name,description:m?s("entities.form.nameDescription","Use the legal or operating name users expect to see in cash and reconciliation workflows."):void 0,required:!0})}),e.jsx("div",{className:"order-2",children:e.jsx(K,{label:s("entities.form.country","Country"),placeholder:H?s("entities.form.countryLoading","Loading countries..."):s("entities.form.countryPlaceholder","Select country"),value:p?.countryCode,onChange:i=>$("countryCode",i),error:n?.countryCode,options:B,searchable:!0,disabled:H,required:!0})}),e.jsxs("div",{className:"order-4",children:[e.jsx(K,{label:s("entities.form.taxIdType","Tax ID Type"),placeholder:s("entities.form.taxIdTypePlaceholder","Select tax ID type"),value:p?.taxIdType,onChange:i=>$("taxIdType",i),error:n?.taxIdType,options:G}),m&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:s("entities.form.taxIdTypeHint","Optional: Select the type of tax identification number")})]}),e.jsxs("div",{className:"order-5",children:[e.jsx(re,{label:s("entities.form.taxIdValue","Tax ID Value"),placeholder:s("entities.form.taxIdValuePlaceholder","Enter tax ID value"),value:p?.taxId,onChange:i=>$("taxId",i?.target?.value),error:n?.taxId,disabled:!p?.taxIdType}),m&&!p?.taxIdType&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:s("entities.form.taxIdValueDisabled","Select tax ID type first")})]}),e.jsxs("div",{className:"order-3",children:[e.jsx(K,{label:s("entities.form.currency","Currency"),placeholder:s("entities.form.currencyPlaceholder","Select currency"),value:p?.currency,onChange:i=>$("currency",i),options:j}),m&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:s("entities.form.currencyHint","Optional: Default currency for this entity")})]}),e.jsxs("div",{className:"order-6 md:col-span-2",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-3",children:[e.jsx("label",{className:"block text-sm font-medium text-foreground",children:s("entities.form.activityDescription","Activity Description")}),e.jsx("span",{className:"inline-flex",title:R?s("entities.ai.checkingConfiguration","Checking General AI configuration."):N?s("entities.ai.creatingSuggestion","Reconcilia AI 
1is creating a suggestion."):T?.available?p?.name?.trim()?s("entities.ai.improveActivity","Improve activity description with Reconcilia AI."):s("entities.ai.enterName","Enter the entity name before using Reconcilia AI."):T?.reason||c,children:e.jsx(f,{type:"button",variant:"outline",size:y?"icon":"xs",iconName:N?"ReconciliaAIThinking":"ReconciliaAIAction",iconSize:y?24:20,className:y?"!h-10 !w-10":"!h-9 px-3",onClick:ee,disabled:R||P||!T?.available||!p?.name?.trim(),"aria-busy":N,"aria-label":s("entities.ai.improveActivity","Improve activity description with Reconcilia AI."),children:y?null:N?s("entities.ai.thinking","Thinking"):s("entities.ai.improve","Improve")})})]}),e.jsxs("div",{className:"relative h-32",children:[e.jsx("textarea",{className:`h-full w-full resize-none rounded-md border border-border bg-input px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring ${N||L?.suggestion?"select-none text-transparent caret-transparent":""}`,placeholder:s("entities.form.activityPlaceholder","Describe the entity activity, treasury role, or operating context"),value:p?.activityDescription,onChange:i=>$("activityDescription",i?.target?.value),readOnly:N||!!L?.suggestion}),N&&e.jsxs("div",{className:"absolute inset-0 flex items-center justify-center rounded-md border border-primary/30 bg-card/95 p-4",children:[e.jsx("div",{className:"absolute inset-0 rounded-md bg-primary/5 backdrop-blur-[1px]"}),e.jsxs("div",{className:"relative flex items-center gap-3 text-sm text-foreground",children:[e.jsx("span",{className:"flex h-10 w-10 items-center justify-center rounded-md border border-primary/40 bg-primary/10",children:e.jsx(f,{type:"button",variant:"ghost",size:"icon",iconName:"ReconciliaAIThinking",iconSize:24,className:"pointer-events-none !h-9 !w-9","aria-hidden":"true",tabIndex:-1})}),e.jsxs("span",{children:[e.jsx("span",{className:"block font-medium",children:s("entities.ai.thinkingTitle","Reconcilia AI is thinking")}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s("entities.ai.thinkingDescription","The current text stays unchanged until you accept the suggestion.")})]})]})]}),L?.suggestion&&e.jsxs("div",{className:"absolute inset-0 flex flex-col rounded-md border border-primary/40 bg-card p-3 shadow-sm",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex rounded-md border border-border bg-muted/20 p-0.5",children:[e.jsx("button",{type:"button",className:`rounded px-2 py-1 text-xs font-medium ${Y==="suggested"?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>C("suggested"),children:s("entities.ai.suggestedTab","Suggested")}),e.jsx("button",{type:"button",className:`rounded px-2 py-1 text-xs font-medium ${Y==="current"?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>C("current"),children:s("entities.ai.currentTab","Current")})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(f,{type:"button",variant:"ghost",size:"icon",iconName:"RefreshCw",iconSize:14,className:"!h-7 !w-7",onClick:ee,"aria-label":s("entities.ai.tryAnother","Try another AI suggestion"),title:s("entities.ai.tryAgain","Try again")}),e.jsx(f,{type:"button",variant:"ghost",size:"icon",iconName:"X",iconSize:14,className:"!h-7 !w-7",onClick:r,"aria-label":s("entities.ai.keepCurrentDescription","Keep current activity description"),title:s("entities.ai.keepCurrent","Keep current")}),e.jsx(f,{type:"button",size:"xs",onClick:te,children:s("entities.ai.useSuggestion","Use")})]})]}),e.jsx("p",{className:"min-h-0 flex-1 overflow-y-auto text-sm text-foreground",children:Y==="current"?p?.activityDescription||s("entities.ai.noCurrentDescription","No current activity description."):L.suggestion})]})]}),J&&e.jsx("p",{className:"text-xs text-error mt-2",children:J}),m&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:s("entities.form.activityHint","This context helps AI-assisted setup suggest better categories, rules, and treasury controls.")})]}),e.jsx(ke,{className:"order-7 md:col-span-2",label:s("entities.form.isActive","Entity is active"),description:m?s("entities.form.isActiveDescription","Inactive entities remain available historically but should not be used for new setup."):void 0,checked:!!p?.isActive,onChange:i=>$("isActive",i?.target?.checked)})]}),e.jsxs("div",{className:"flex shrink-0 justify-end space-x-3 border-t border-border p-6 pt-4",children:[e.jsx(f,{type:"button",variant:"outline",onClick:u,disabled:P,children:s("entities.form.cancel","Cancel")}),e.jsx(f,{type:"submit",loading:P,iconName:"Save",iconPosition:"left",children:d?s("entities.form.update","Save changes"):s("entities.form.create","Create")})]})]})]})]})}):null},Le=({onCreateEntity:t})=>{const{t:u}=ie();return e.jsxs("div",{className:"bg-card border border-border rounded-lg p-12 text-center",children:[e.jsx("div",{className:"w-16 h-16 bg-primary/10 rounded-full flex items-center justify-center mx-auto mb-6",children:e.jsx(V,{name:"Building",size:32,className:"text-primary"})}),e.jsx("h3",{className:"text-lg font-semibold text-foreground mb-2",children:u("entities.empty.title","No entities yet")}),e.jsx("p",{className:"text-muted-foreground mb-6 max-w-md mx-auto",children:u("entities.empty.description","Create your first entity to start managing company information and linking bank accounts. Entities help organize your financial data by business unit.")}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(f,{onClick:t,iconName:"Plus",iconPosition:"left",size:"lg",children:u("entities.empty.createFirst","Create Your First Entity")}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:[e.jsx("p",{className:"mb-2",children:u("entities.empty.whatAreEntities","What are entities?")}
1),e.jsxs("ul",{className:"text-left max-w-md mx-auto space-y-1",children:[e.jsxs("li",{className:"flex items-start space-x-2",children:[e.jsx(V,{name:"CheckCircle",size:16,className:"text-success mt-0.5 flex-shrink-0"}),e.jsx("span",{children:u("entities.empty.benefit1","Organize bank accounts by business unit")})]}),e.jsxs("li",{className:"flex items-start space-x-2",children:[e.jsx(V,{name:"CheckCircle",size:16,className:"text-success mt-0.5 flex-shrink-0"}),e.jsx("span",{children:u("entities.empty.benefit2","Track tax identification numbers")})]}),e.jsxs("li",{className:"flex items-start space-x-2",children:[e.jsx(V,{name:"CheckCircle",size:16,className:"text-success mt-0.5 flex-shrink-0"}),e.jsx("span",{children:u("entities.empty.benefit3","Manage multi-currency operations")})]}),e.jsxs("li",{className:"flex items-start space-x-2",children:[e.jsx(V,{name:"CheckCircle",size:16,className:"text-success mt-0.5 flex-shrink-0"}),e.jsx("span",{children:u("entities.empty.benefit4","Improve financial reporting accuracy")})]})]})]})]})]})},Oe=[{value:"SUPPORTING_DOCUMENT",label:"Supporting document"},{value:"STATEMENT_PDF",label:"Statement PDF"}],Me={IMPORT_ARTIFACT:"Import artifact",STATEMENT_PDF:"Statement PDF",SUPPORTING_DOCUMENT:"Supporting document"},Be={USER_UPLOAD:"Uploaded",IMPORT_CAPTURE:"Import capture",SYSTEM_GENERATED:"System"};function $e(t){return new Promise((u,v)=>{const d=new FileReader;d.onload=()=>u(String(d.result||"")),d.onerror=()=>v(new Error("Failed to read file")),d.readAsDataURL(t)})}function Ve({blob:t,fileName:u,fallbackFileName:v}){const d=u||v,m=window.URL.createObjectURL(t),y=document.createElement("a");y.href=m,y.download=d,document.body.appendChild(y),y.click(),document.body.removeChild(y),window.URL.revokeObjectURL(m)}function xe(t){return!t||t<=0?"Size unavailable":t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function qe(t){if(!t)return"Unknown date";const u=new Date(t);return Number.isNaN(u.getTime())?"Unknown date":u.toLocaleString()}function Xe({title:t,description:u,scopeLabel:v,scopeKey:d,scopeOptions:m,initialScopeId:y=""}){const s=l.useRef(null),[x,c]=l.useState(y||""),[p,S]=l.useState([]),[n,I]=l.useState(!1),[P,q]=l.useState(!1),[T,o]=l.useState(null),[R,X]=l.useState(null),[N,z]=l.useState(null),[J,U]=l.useState(""),[L,_]=l.useState("SUPPORTING_DOCUMENT"),[Y,C]=l.useState(""),[O,A]=l.useState(""),[H,M]=l.useState(""),B=l.useMemo(()=>(m||[]).map(r=>({value:String(r.value),label:r.label})),[m]);l.useEffect(()=>{if(!B.length){c("");return}if(!B.some(i=>i.value===x)){if(y&&B.some(i=>i.value===String(y))){c(String(y));return}c(B[0].value)}},[y,B,x]);const G=async r=>{if(!r){S([]);return}I(!0),A("");try{const b=await Te(d==="entityId"?{entityId:r,pageSize:50}:{bankAccountId:r,pageSize:50});S(b?.items||[])}catch(i){A(i?.message||"Failed to load documents"),S([])}finally{I(!1)}};l.useEffect(()=>{G(x)},[x]);const j=()=>{s.current?.click()},Z=async r=>{const i=r.target.files?.[0]||null;if(i){A(""),M("");try{const b=await $e(i);z(i),U(b),Y||C(i.name.replace(/\.[^.]+$/,"")),((i.type||"").toLowerCase()==="application/pdf"||i.name.toLowerCase().endsWith(".pdf"))&&_("STATEMENT_PDF")}catch(b){A(b?.message||"Failed to read the selected file")}finally{r.target.value=""}}},F=()=>{z(null),U(""),M("")},$=async()=>{if(!x){A(`Select a ${v.toLowerCase()} first`);return}if(!N||!J){A("Choose a file before uploading");return}q(!0),A(""),M("");try{const r={[d]:x,title:Y||null,documentType:L,fileName:N.name,contentType:N.type||"application/octet-stream",fileContentBase64:J},i=await Ee(r);M(`${i?.title||N.name} uploaded`),z(null),U(""),C(""),await G(x)}catch(r){A(r?.message||"Failed to upload document")}finally{q(!1)}},ee=async r=>{if(r?.id){o(r.id),A("");try{const i=await Pe(r.id);Ve({blob:i.blob,fileName:i.fileName,fallbackFileName:r.originalFileName||r.title||"document"})}catch(i){A(i?.message||"Failed to download document")}finally{o(null)}}},te=async r=>{if(!(!r?.id||!window.confirm(`Delete "${r.title||r.originalFileName}"?`))){X(r.id),A(""),M("");
1try{await Re(r.id),M(`${r.title||r.originalFileName} deleted`),await G(x)}catch(b){A(b?.message||"Failed to delete document")}finally{X(null)}}};return e.jsxs("div",{className:"bg-card border border-border rounded-lg p-6 space-y-5",children:[e.jsxs("div",{className:"flex flex-col gap-2 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-foreground",children:t}),e.jsx("p",{className:"text-sm text-muted-foreground",children:u})]}),e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-border px-3 py-1 text-xs text-muted-foreground",children:[e.jsx(V,{name:"Shield",size:14}),"Private storage via tenant-scoped paths"]})]}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.2fr)_minmax(0,1fr)]",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(K,{label:v,options:B,value:x,onChange:c,placeholder:`Select ${v.toLowerCase()}`}),e.jsx(K,{label:"Document type",options:Oe,value:L,onChange:_})]}),e.jsx(re,{label:"Title",value:Y,onChange:r=>C(r.target.value),placeholder:"Optional title"}),e.jsxs("div",{className:"rounded-lg border border-dashed border-border p-4 space-y-3",children:[e.jsx("input",{ref:s,type:"file",className:"hidden",accept:".pdf,.csv,.txt,.xml,.json,.png,.jpg,.jpeg,.doc,.docx,.xls,.xlsx",onChange:Z}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(f,{variant:"outline",iconName:"Upload",onClick:j,children:"Choose file"}),N&&e.jsx(f,{variant:"ghost",iconName:"X",onClick:F,children:"Remove"}),e.jsx(f,{iconName:"ArrowUpFromLine",onClick:$,loading:P,disabled:!x||!N||!J,children:"Upload document"})]}),e.jsx("div",{className:"text-sm text-muted-foreground",children:N?e.jsxs(e.Fragment,{children:["Selected: ",e.jsx("span",{className:"text-foreground",children:N.name})," · ",xe(N.size)]}):"PDFs, import files, and supporting documents stay private and are scoped by tenant path plus API authorization."})]}),O&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm text-destructive",children:O}),H&&e.jsx("div",{className:"rounded-md border border-success/30 bg-success/10 px-3 py-2 text-sm text-success",children:H})]}),e.jsxs("div",{className:"rounded-lg border border-border overflow-hidden",children:[e.jsx("div",{className:"border-b border-border px-4 py-3",children:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground",children:"Documents"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Import artifacts and uploaded files linked to this ",v.toLowerCase(),"."]})]}),e.jsx(f,{variant:"ghost",size:"sm",iconName:"RefreshCw",onClick:()=>G(x),disabled:!x||n,children:"Refresh"})]})}),e.jsx("div",{className:"max-h-[26rem] overflow-auto",children:n?e.jsx("div",{className:"px-4 py-6 text-sm text-muted-foreground",children:"Loading documents..."}):x?p.length===0?e.jsxs("div",{className:"px-4 py-6 text-sm text-muted-foreground",children:["No documents are linked to this ",v.toLowerCase()," yet."]}):e.jsx("div",{className:"divide-y divide-border",children:p.map(r=>e.jsxs("div",{className:"px-4 py-3 space-y-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-foreground truncate",children:r.title||r.originalFileName}),e.jsx("div",{className:"text-xs text-muted-foreground truncate",children:r.originalFileName})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{size:"sm",variant:"outline",iconName:"Download",onClick:()=>ee(r),loading:T===r.id,disabled:!!T&&T!==r.id,children:"Download"}),e.jsx(f,{size:"sm",variant:"ghost",iconName:"Trash2",onClick:()=>te(r),loading:R===r.id,disabled:!!R&&R!==r.id,children:"Delete"})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{className:"rounded-full border border-border px-2 py-1",children:Me[r.documentType]||r.documentType}),e.jsx("span",{className:"rounded-full border border-border px-2 py-1",children:Be[r.source]||r.source}),e.jsx("span",{children:xe(r.sizeBytes)}),e.jsx("span",{children:qe(r.createdAt)})]})]},r.id))}):e.jsxs("div",{className:"px-4 py-6 text-sm text-muted-foreground",children:["Select a ",v.toLowerCase()," to load documents."]})})]})]})]})}const E="ALL",Q="rounded-full border border-border px-2 py-0.5 text-xs text-muted-foreground",Ye=[{value:"name:asc",key:"entities.sort.nameAsc",fallback:"Name A-Z"},{value:"name:desc",key:"entities.sort.nameDesc",fallback:"Name Z-A"},{value:"currency:asc",key:"entities.sort.currencyAsc",fallback:"Currency A-Z"},{value:"status:asc",key:"entities.sort.statusAsc",fallback:"Status"},{value:"createdAt:desc",key:"entities.sort.createdDesc",fallback:"Newest created"},{value:"createdAt:asc",key:"entities.sort.createdAsc",fallback:"Oldest created"},{value:"updatedAt:desc",key:"entities.sort.updatedDesc",fallback:"Recently updated"}];function pe(t){const[u="name",v="asc"]=String(t||"name:asc").split(":");return{key:u,direction:v}}function He(t,u){const v=t.reduce((d,m)=>{const y=m?.currency||u("entities.common.unknown","Unknown");return d[y]=(d[y]||0)+1,d},{});return Object.entries(v).sort(([d],[m])=>d.localeCompare(m)).map(([d,m])=>u("entities.summary.currencyBreakdownItem","{{currency}}: {{count}}",{currency:d,count:m})).join(", ")}const Je={bank_accounts:["entities.delete.blocker.bankAccounts","bank accounts"],bank_transactions:["entities.delete.blocker.bankTransactions","bank transactions"],bank_auxiliary_entries:["entities.delete.blocker.bankAuxiliaryEntries","bank auxiliary entries"],erp_documents:["entities.delete.blocker.erpDocuments","ERP documents"],chart_of_accounts:["entities.delete.blocker.chartOfAccounts","chart of accounts"],counterparties:["entities.delete.blocker.counterparties","counterparties"],ap_open_items:["entities.delete.blocker.apOpenItems","AP open items"],ar_open_items:["entities.delete.blocker.arOpenItems","AR open items"],cash_positions:["entities.delete.blocker.cashPositions","cash positions"],cash_position_entries:["entities.delete.blocker.cashPositionEntries","cash position entries"],cash_position_snapshots:["entities.delete.blocker.cashPositionSnapshots","cash position snapshots"],cash_position_adjustments:["entities.delete.blocker.cashPositionAdjustments","cash position adjustments"],cash_position_balance_variances:["entities.delete.blocker.cashPositionBalanceVariances","cash position balance variances"],cash_position_source_policies:["entities.delete.blocker.cashPositionSourcePolicies","cash position source policies"],forecasts:["entities.delete.blocker.forecasts","forecasts"],forecast_manual_inputs:["entities.delete.blocker.forecastManualInputs","forecast manual inputs"],forecast_routing_profiles:["entities.delete.blocker.forecastRoutingProfiles","forecast routing profiles"],categorization_rules:["entities.delete.blocker.categorizationRules","categorization rules"],categorization_rule_entities:["entities.delete.blocker.categorizationRuleEntities","categorization rule entity scopes"],categorization_review_runs:["entities.delete.blocker.categorizationReviewRuns","categorization review runs"],categorization_review_items:["entities.delete.blocker.categorizationReviewItems","categorization review items"],bank_reconciliation_rules:["entities.delete.blocker.bankReconciliationRules","bank reconciliation rules"],batches:["entities.delete.blocker.batches","reconciliation batches"],match_groups:["entities.delete.blocker.matchGroups","reconciliation match groups"],counterparty_category_defaults:["entities.delete.blocker.counterpartyCategoryDefaults","counterparty category defaults"],counterparty_settlement_profiles:["entities.delete.blocker.counterpartySettlementProfiles","counterparty settlement profiles"],open_item_settlements:["entities.delete.blocker.openItemSettlements","open item settlements"],settlement_behavior_observations:["entities.delete.blocker.settlementBehaviorObservations","settlement behavior history"],import_packages:["entities.delete.blocker.importPackages","import packages"],import_slice
1s:["entities.delete.blocker.importSlices","import file slices"],documents:["entities.delete.blocker.documents","documents"]};function Ke(t,u){return t.map(v=>{const[d,m]=String(v||"").split(":"),y=d.trim(),s=Number(m||0),[x,c]=Je[y]||[null,y.replace(/_/g," ")],p=x?u(x,c):c;return s>0?`${p} (${s})`:p}).join(", ")}function Ge(t,u){const v=t?.data?.error||"",d=t?.message||"";return v==="limit_exceeded"||d==="billing_limit_exceeded:entities"?u("entities.errors.limitReached","Entity limit reached. Upgrade your plan to add more active entities."):d||u("entities.errors.save","Failed to save entity")}const dt=()=>{const{t,currentLanguage:u}=ie(),{experienceMode:v,density:d}=_e(),m=v==="guided",y=v==="balanced",s=v==="expert",x=d==="compact",c=!s,p=x?"p-4":"p-5",S=x||s?"max-h-[calc(100vh-18rem)]":"max-h-[calc(100vh-23rem)]",[n,I]=l.useState([]),[P,q]=l.useState("table"),[T,o]=l.useState(!1),[R,X]=l.useState(null),[N,z]=l.useState(null),[J,U]=l.useState(!0),[L,_]=l.useState(!1),[Y,C]=l.useState(""),[O,A]=l.useState(1),[H,M]=l.useState(1),[B,G]=l.useState(0),[j,Z]=l.useState({search:"",currency:E,taxIdType:E,status:E,sort:"name:asc"}),F=l.useMemo(()=>pe(j.sort),[j.sort]),$=l.useMemo(()=>Ye.map(a=>({value:a.value,label:t(a.key,a.fallback)})),[t]),ee=l.useMemo(()=>Array.from(new Set(n.map(a=>a?.currency).filter(Boolean))).sort().map(a=>({value:a,label:a})),[n]),te=l.useMemo(()=>Array.from(new Set(n.map(a=>a?.taxIdType).filter(Boolean))).sort().map(a=>({value:a,label:a})),[n]),r=l.useMemo(()=>{const a=j.search.trim().toLowerCase(),h=n.filter(g=>{const se=!a||[g?.name,g?.taxId,g?.taxIdType,g?.currency,g?.activityDescription].some(Ce=>String(Ce||"").toLowerCase().includes(a)),ve=j.currency===E||g?.currency===j.currency,je=j.taxIdType===E||g?.taxIdType===j.taxIdType,Ne=j.status===E||(j.status==="ACTIVE"?g?.isActive!==!1:g?.isActive===!1);return se&&ve&&je&&Ne}),D=F.direction==="desc"?-1:1,k=g=>F.key==="status"?g?.isActive===!1?"inactive":"active":F.key==="createdAt"?g?.createdAt||"":F.key==="updatedAt"?g?.updatedAt||"":g?.[F.key]||"";return h.sort((g,se)=>String(k(g)).localeCompare(String(k(se)))*D)},[n,j,F]),i=l.useMemo(()=>{const a=n.filter(h=>h?.isActive!==!1).length;return{totalCount:B||n.length,activeCount:a,inactiveCount:n.length-a,currencyCount:new Set(n.map(h=>h?.currency).filter(Boolean)).size,currencyBreakdown:He(n,t)}},[n,B,t]),b=j.search||j.currency!==E||j.taxIdType!==E||j.status!==E,w=l.useMemo(()=>n.map(a=>({value:a?.id,label:a?.name||a?.id})),[n]),W=(a,h)=>{Z(D=>({...D,[a]:h}))},le=()=>{Z(a=>({...a,search:"",currency:E,taxIdType:E,status:E}))},ae=async()=>{U(!0),C("");try{const a=await Ae({page:O,pageSize:100,sortBy:"name",sortDir:"asc"}),h=a?.items??[];I(h),M(a?.totalPages??1),G(a?.total??h.length)}catch(a){C(a?.message||t("entities.errors.load","Failed to load entities"))}finally{U(!1)}};l.useEffect(()=>{ae()},[O]);const oe=()=>{X(null),o(!0)},ce=a=>{const h=n.find(D=>D?.id===a);X(h||null),o(!0)},he=async a=>{C("");try{R?await me(R.id,a):await Se(a),o(!1),X(null),await ae()}catch(h){throw C(Ge(h,t)),h}},ne=async(a,h)=>{_(!0),C("");try{await me(a,{isActive:h}),I(D=>D.map(k=>k?.id===a?{...k,isActive:h,updatedAt:new Date().toISOString()}:k))}catch(D){C(D?.message||t("entities.errors.statusUpdate","Failed to update entity status"))}finally{_(!1)}},de=async a=>{const h=n.find(k=>k?.id===a);if(!(!h||h?.isActive!==!1||!window.confirm(t("entities.delete.confirm","Delete {{name}}? This is only allowed when no related data exists.",{name:h.name||t("entities.common.entity","entity")})))){_(!0),C("");try{await De(a),I(k=>k.filter(g=>g?.id!==a)),await ae()}catch(k){const g=Array.isArray(k?.data?.blockers)?k.data.blockers:[];g.length?C(t("entities.delete.blockedMessage","This entity cannot be deleted yet because it is still used by {{blockers}}. Keep it inactive, or remove those links first.",{blockers:Ke(g,t)})):C(k?.message||t("entities.errors.delete","Failed to delete entity"))}finally{_(!1)}}},fe=()=>{const a=[[t("entities.export.entityName","Entity Name"),t("entities.export.taxIdType","Tax ID Type"),t("entities.export.taxIdValue","Tax ID Value"),t("entities.export.currency","Currency"),t("entities.export.activityDescription","Activity Description"),t("entities.export.status","Status"),t("entities.export.created","Created"),t("entities.export.updated","Updated")],...r.map(g=>[g?.name,g?.taxIdType,g?.taxId,g?.currency,g?.activityDescription,g?.isActive===!1?t("entities.status.inactive","Inactive"):t("entities.status.active","Active"),g?.createdAt?new Date(g.createdAt).toLocaleDateString(u):"",g?.updatedAt?new Date(g.updatedAt).toLocaleDateString(u):""])].map(g=>g.map(se=>`"${String(se??"").replace(/"/g,'""')}"`).join(",")).join(`
2`),h=new Blob([a],{type:"text/csv"}),D=URL.createObjectURL(h),k=document.createElement("a");k.href=D,k.download="entities.csv",k.click(),URL.revokeObjectURL(D)},ge=a=>{Z(h=>{const D=pe(h.sort),k=D.key===a&&D.direction==="asc"?"desc":"asc";return{...h,sort:`${a}:${k}`}})},be=a=>F.key!==a?e.jsx(V,{name:"ArrowUpDown",size:13,className:"text-muted-foreground"}):e.jsx(V,{name:F.direction==="asc"?"ArrowUp":"ArrowDown",size:13}),ye=()=>N?e.jsxs("div",{className:"fixed inset-0 z-[120] flex justify-end bg-black/40",children:[e.jsx("button",{className:"flex-1 cursor-default","aria-label":t("entities.documentsDrawer.close","Close documents"),onClick:()=>z(null)}),e.jsxs("aside",{className:"h-full w-full max-w-5xl overflow-y-auto border-l border-border bg-background shadow-card",children:[e.jsxs("div",{className:"sticky top-0 z-10 flex items-start justify-between gap-4 border-b border-border bg-background px-5 py-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-lg font-semibold text-foreground",children:t("entities.documentsDrawer.title","Entity Documents")}),c?e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:t("entities.documentsDrawer.description","Upload and review files linked to {{name}} without leaving the entity registry.",{name:N.name||t("entities.documentsDrawer.thisEntity","this entity")})}):null]}),e.jsx(f,{variant:"ghost",size:"icon",iconName:"X","aria-label":t("entities.documentsDrawer.close","Close documents"),onClick:()=>z(null)})]}),e.jsx("div",{className:"p-5",children:e.jsx(Xe,{title:t("entities.documentsDrawer.repositoryTitle","Entity document repository"),description:t("entities.documentsDrawer.repositoryDescription","Contextual entity attachments stay here. Broad upload review, search, and import investigation should live in Operations."),scopeLabel:t("entities.documentsDrawer.scopeLabel","Entity"),scopeKey:"entityId",scopeOptions:w,initialScopeId:N.id||""})})]})]}):null;return e.jsxs(e.Fragment,{children:[e.jsxs(we,{children:[e.jsx("title",{children:t("entities.seo.title","Entities - Reconcilia AI")}),e.jsx("meta",{name:"description",content:t("entities.seo.description","Manage legal entities, tax identity, currencies, and supporting documents in Reconcilia AI.")})]}),e.jsxs("div",{className:"space-y-[var(--app-section-gap)] text-[length:var(--app-body-font-size)]",children:[m&&e.jsx("div",{className:"rounded-lg border border-primary/20 bg-primary/10 p-4 text-sm text-foreground",children:e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold",children:t("entities.guided.setupTitle","Entity setup path")}),e.jsx("p",{className:"mt-1 text-muted-foreground",children:t("entities.guided.setupDescription","Create legal entities first, attach supporting documents when needed, then connect bank accounts to the right entity.")})]}),e.jsx("div",{className:"grid grid-cols-3 gap-2 text-xs lg:min-w-[30rem]",children:[[t("entities.guided.step1.title","1. Entity"),t("entities.guided.step1.description","
2Legal name, tax ID, currency")],[t("entities.guided.step2.title","2. Documents"),t("entities.guided.step2.description","Supporting files in context")],[t("entities.guided.step3.title","3. Accounts"),t("entities.guided.step3.description","Bank connections by entity")]].map(([a,h])=>e.jsxs("div",{className:"rounded-md border border-border bg-card/70 px-3 py-2",children:[e.jsx("span",{className:"block font-semibold",children:a}),e.jsx("span",{className:"text-muted-foreground",children:h})]},a))})]})}),y&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-lg border border-border bg-card px-4 py-2 text-sm text-muted-foreground",children:[e.jsx("span",{className:"font-medium text-foreground",children:t("entities.summary.registry","Entity registry")}),e.jsx("span",{className:Q,children:t("entities.summary.totalCount","{{count}} total",{count:i.totalCount})}),e.jsx("span",{className:Q,children:t("entities.summary.activeCount","{{count}} active",{count:i.activeCount})}),e.jsx("span",{className:Q,children:t("entities.summary.currencyCount","{{count}} currencies",{count:i.currencyCount})}),e.jsx("span",{className:"ml-auto hidden text-xs md:inline",children:t("entities.summary.description","Master data for legal entities and operating units.")})]}),Y&&e.jsx("div",{className:"rounded-md border border-error/30 bg-error/10 px-4 py-3 text-sm text-error",children:Y}),e.jsxs("div",{className:`bg-card border border-border rounded-lg ${p} space-y-4`,children:[e.jsx("div",{className:"flex flex-wrap items-center justify-end gap-2",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2 sm:justify-end lg:shrink-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs text-muted-foreground sm:justify-end",children:[e.jsx("span",{className:Q,children:t("entities.summary.totalCount","{{count}} total",{count:i.totalCount})}),e.jsx("span",{className:Q,children:t("entities.summary.activeCount","{{count}} active",{count:i.activeCount})}),e.jsx("span",{className:Q,children:t("entities.summary.inactiveCount","{{count}} inactive",{count:i.inactiveCount})}),m&&e.jsx("span",{className:Q,children:t("entities.summary.currencyCount","{{count}} currencies",{count:i.currencyCount})})]}),e.jsx(f,{variant:"outline",iconName:"Download",iconPosition:"left",onClick:fe,disabled:!r.length,children:t("entities.export.action","Export")}),e.jsx(f,{iconName:"Plus",iconPosition:"left",onClick:oe,children:t("entities.create","Add entity")})]})}),m&&i.currencyBreakdown&&e.jsx("div",{className:"rounded-lg border border-border bg-muted/20 px-4 py-3 text-sm text-muted-foreground",children:t("entities.summary.currencyCoverage","Current currency coverage: {{coverage}}",{coverage:i.currencyBreakdown})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-3 lg:grid-cols-[minmax(16rem,1fr)_12rem_13rem_12rem_13rem_auto]",children:[e.jsx(re,{label:m?t("entities.filters.searchLabel","Search entities"):void 0,"aria-label":t("entities.filters.searchLabel","Search entities"),placeholder:t("entities.filters.searchPlaceholderLong","Filter by name, tax ID, activity, or currency"),value:j.search,onChange:a=>W("search",a.target.value)}),e.jsx(K,{label:m?t("entities.filters.currency","Currency"):void 0,options:[{value:E,label:t("entities.filters.currencyPlaceholder","All currencies")},...ee],value:j.currency,onChange:a=>W("currency",a),"aria-label":t("entities.filters.currencyAria","Filter by currency")}),e.jsx(K,{label:m?t("entities.filters.taxIdTypeLabel","Tax ID type"):void 0,options:[{value:E,label:t("entities.filters.taxIdTypePlaceholder","All tax ID types")},...te],value:j.taxIdType,onChange:a=>W("taxIdType",a),"aria-label":t("entities.filters.taxIdTypeAria","Filter by tax ID type")}),e.jsx(K,{label:m?t("entities.filters.status","Status"):void 0,options:[{value:E,label:t("entities.filters.statusPlaceholder","All statuses")},{value:"ACTIVE",label:t("entities.status.active","Active")},{value:"INACTIVE",label:t("entities.status.inactive","Inactive")}],value:j.status,onChange:a=>W("status",a),"aria-label":t("entities.filters.statusAria","Filter by status")}),e.jsx(K,{label:m?t("entities.filters.sort","Sort"):void 0,options:$,value:j.sort,onChange:a=>W("sort",a),"aria-label":t("entities.filters.sortAria","Sort entities")}),e.jsx(f,{variant:"outline",iconName:"RefreshCw",iconPosition:"left",onClick:ae,loading:J,children:t("entities.refresh","Refresh")})]}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("div",{className:"flex flex-wrap items-center gap-2 text-sm text-muted-foreground",children:b?e.jsxs(e.Fragment,{children:[e.jsx("span",{children:t("entities.showingLoadedFiltered","{{filtered}} of {{total}} loaded entities shown",{filtered:r.length,total:n.length})}),e.jsx(f,{variant:"ghost",size:"sm",iconName:"X",iconPosition:"left",onClick:le,children:t("entities.filters.clearFilters","Clear filters")})]}):e.jsx("span",{children:t("entities.showingLoaded","{{count}} loaded entities shown",{count:n.length})})}),e.jsxs("div",{className:"flex items-center gap-1 rounded-md border border-border p-1",children:[e.jsx(f,{variant:P==="table"?"default":"ghost",size:"sm",iconName:"Table","aria-label":t("entities.view.tableAria","Table view"),onClick:()=>q("table"),children:m?t("entities.view.table","Table"):null}),e.jsx(f,{variant:P==="cards"?"default":"ghost",size:"sm",iconName:"Grid3X3","aria-label":t("entities.view.cardAria","Card view"),onClick:()=>q("cards"),children:m?t("entities.view.cards","Cards"):null})]})]})]}),e.jsx("div",{className:`overflow-y-auto pr-1 ${P==="table"?S:""}`,children:J&&!n.length?e.jsx("div",{className:"px-4 py-10 text-center text-sm text-muted-foreground",children:t("entities.loading","Loading entities...")}):n.length===0?e.jsx(Le,{onCreateEntity:oe}):r.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed border-border p-10 text-center",children:[e.jsx("div",{className:"mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted",children:e.jsx(V,{name:"Search",size:24,className:"text-muted-foreground"})}),e.jsx("h3",{className:"text-base font-semibold text-foreground",children:t("entities.noResults.filtersTitle","No entities match the current filters")}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:t("entities.noResults.filtersDescription","Clear filters or adju
2st the search to continue.")}),e.jsx(f,{className:"mt-4",variant:"outline",iconName:"X",iconPosition:"left",onClick:le,children:t("entities.clearFilters","Clear Filters")})]}):P==="table"?e.jsx(Fe,{entities:r,onEdit:ce,onEnable:a=>ne(a,!0),onDisable:a=>ne(a,!1),onDelete:de,onDocuments:a=>z(a),isGuided:m,isExpert:s,isSavingStatus:L,sort:F,onSort:ge,renderSortIcon:be}):e.jsx("div",{className:`grid grid-cols-1 gap-4 ${x?"md:grid-cols-2 xl:grid-cols-4":"md:grid-cols-2 xl:grid-cols-3"}`,children:r.map(a=>e.jsx(Ue,{entity:a,onEdit:ce,onEnable:h=>ne(h,!0),onDisable:h=>ne(h,!1),onDelete:de,onDocuments:h=>z(h),isGuided:m,isExpert:s},a?.id))})}),H>1&&e.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-border pt-4",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:t("entities.pagination.pageOf","Page {{page}} of {{totalPages}}",{page:O,totalPages:H})}),e.jsx(f,{variant:"outline",size:"sm",iconName:"ChevronLeft","aria-label":t("entities.pagination.previous","Previous page"),disabled:O<=1,onClick:()=>A(a=>Math.max(1,a-1))}),e.jsx(f,{variant:"outline",size:"sm",iconName:"ChevronRight","aria-label":t("entities.pagination.next","Next page"),disabled:O>=H,onClick:()=>A(a=>Math.min(H,a+1))})]})]}),e.jsx(ze,{isOpen:T,onClose:()=>{o(!1),X(null)},onSave:he,entity:R,isGuided:m,isExpert:s}),ye()]})]})};export{dt as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.