1import{d4 as F,c$ as Y,r as i,dU as I,dV as L,j as e,L as $,K as B,cf as _,cg as J,ch as O,ci as P,cj as T,bu as V,b5 as H,aI as x}from"./index-CpeGhXo5.js";import{a as G}from"./Panel-Cf_wAUzv.js";const j=["January","February","March","April","May","June","July","August","September","October","November","December"];function q(){const N=F(),{exchangeRates:v,rateUpdatedAt:w,setRate:S,setYearRates:u,resetYear:y}=Y(),[o,R]=i.useState(new Date().getFullYear()),{data:m=[]}=I(o),[k]=L();i.useEffect(()=>{if(m.length===0)return;const t={};for(const r of m)t[r.month]=Number(r.rate);u(o,t)},[m,o,u]);const[E,p]=i.useState({}),[h,l]=i.useState({}),g=v[o]||{},f=t=>{if(!/^\d+(\.\d{0,2})?$/.test(t))return{ok:!1,error:"Numbers only, max 2 decimals"};const r=parseFloat(t);return!Number.isFinite(r)||r<1?{ok:!1,error:"Must be ⥠1"}:{ok:!0,num:r}},C=(t,r)=>{l(a=>({...a,[t]:r}));const s=f(r);p(a=>{const n={...a};return s.ok?delete n[t]:n[t]=s.error,n})},D=t=>{const r=h[t];if(r===void 0)return;const s=f(r);s.ok&&s.num!==void 0&&(S(o,t,s.num),x.success(`${j[t-1]} rate updated`),l(a=>{const n={...a};return delete n[t],n}))},A=()=>{const t={};for(let s=1;s<=12;s++){const a=h[s],n=g[s];if(a!==void 0){const c=f(a);if(!c.ok){p(d=>({...d,[s]:c.error??"Invalid rate"}));return}t[s]=c.num}else n?t[s]=n:t[s]=84}u(o,t);const r=Object.entries(t).map(([s,a])=>({month:Number(s),rate:a}));k({fiscalYear:o,rates:r}).unwrap().then(()=>x.success("Exchange rates saved to server")).catch(()=>x.error("Failed to persist exchange rates")),l({})},M=()=>{y(o),l({}),p({}),x.success(`${o} rates reset to default â¹84.00`)};return e.jsxs("div",{className:"p-3 flex flex-col gap-3 min-h-full",children:[e.jsx(G,{title:"Exchange Rate Configuration",subtitle:"Set month-wise USD â INR rates used for currency conversion across all modules.",accent:"mod-finance",actions:e.jsxs($,{to:N,className:"h-7 px-2 rounded-[4px] border border-border bg-card hover:bg-accent text-[11px] inline-flex items-center gap-1",children:[e.jsx(B,{className:"w-3 h-3"})," Back"]})}),e.jsxs("div",{className:"flex items-center justify-between bg-white border border-border rounded-[6px] p-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("label",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Fiscal Year"}),e.jsxs(_,{value:String(o),onValueChange:t=>R(Number(t)),children:[e.jsx(J,{className:"h-8 px-2 text-[12px] border border-border rounded-[4px] bg-white focus:outline-none focus:ring-1 focus:ring-primary w-[100px]",children:e.jsx(O,{})}),e.jsx(P,{children:[2023,2024,2025,2026].map(t=>e.jsx(T,{value:String(t),children:t},t))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:M,className:"h-8 px-3 rounded-[4px] border border-border bg-white hover:bg-muted text-[11px] font-medium inline-flex items-center gap-1.5",children:[e.jsx(V,{className:"w-3.5 h-3.5"})," Reset to Defaults"]}),e.jsxs("button",{onClick:A,className:"h-8 px-3 rounded-[4px] bg-primary text-primary-foreground hover:bg-primary/90 text-[11px] font-medium inline-flex items-center gap-1.5",children:[e.jsx(H,{className:"w-3.5 h-3.5"})," Save All Rates"]})]})]}),e.jsx("div",{className:"bg-white border border-border rounded-[6px] overflow-auto flex-1 min-h-0",children:e.jsxs("table",{className:"w-full text-[12px]",children:[e.jsx("thead",{className:"bg-muted text-muted-foreground",children:e.jsxs("tr",{className:"text-left",children:[e.jsx("th",{className:"px-3 h-9 font-semibold uppercase text-[10px] tracking-wider w-40",children:"Month"}),e.jsx("th",{className:"px-3 h-9 font-semibold uppercase text-[10px] tracking-wider",children:"Exchange Rate (1 USD = â¹ ___)"}),e.jsx("th",{className:"px-3 h-9 font-semibold uppercase text-[10px] tracking-wider w-44",children:"Last Updated"})]})}),e.jsx("tbody",{children:j.map((t,r)=>{const s=r+1,a=g[s],n=h[s],c=n!==void 0?n:a!==void 0?String(a):"",d=E[s],b=w[o]?.[s];return e.jsxs("tr",{className:"border-t border-border hover:bg-muted/30",children:[e.jsx("td",{className:"px-3 h-12 font-medium",children:t}),e.jsx("td",{className:"px-3 h-12",children:e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground font-d
1ata",children:"â¹"}),e.jsx("input",{inputMode:"decimal",value:c,onChange:U=>C(s,U.target.value),onBlur:()=>D(s),placeholder:"84.00",className:`h-7 w-28 px-2 font-data text-[12px] border rounded-[4px] focus:outline-none focus:ring-1 ${d?"border-danger ring-danger":"border-border focus:ring-primary"}`}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"per 1 USD"})]}),d&&e.jsx("span",{className:"text-[10px] text-danger",children:d})]})}),e.jsx("td",{className:"px-3 h-12 text-muted-foreground font-data text-[11px]",children:b?new Date(b).toLocaleDateString("en-IN",{day:"2-digit",month:"short",year:"numeric"}):"â"})]},s)})})]})}),e.jsxs("div",{className:"text-[10px] text-muted-foreground px-1",children:["Tip: rates auto-save on blur. Use ",e.jsx("span",{className:"font-semibold",children:"Save All Rates"})," to persist any in-progress edits at once."]})]})}export{q 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.