PageSourceSearch

https://bizvanguard.ai/assets/Tips-Dc6ABmMv.js

js bizvanguard.ai collected 2026-10-05 13:47:32 UTC 61,073 bytes, 1 lines download raw bytes

1import{u as be,r as u,j as e}from"./vendor-react-zwv87yMD.js";import{u as Oe,a as he,b as me}from"./vendor-query-DYq8g7OI.js";import{a as oe}from"./api-client-wl3SCNAO.js";import{e as nt}from"./employees-BPFguWOi.js";import{p as _e}from"./positions-DqspSnNm.js";import{p as at}from"./payroll-CkTcIQY8.js";import{s as rt}from"./employeeAuthStore-lYSKMuhw.js";import{u as Fe}from"./authStore-Bv6p2Ne2.js";import{u as ot}from"./usePermissions-CBDKNj1w.js";import{u as lt}from"./useOrgTimezone-C1UagyKl.js";import{g as it,t as qe}from"./timezoneFormatters-Lg56xFv0.js";import"./vendor-charts-CtrTLS4K.js";import"./vendor-i18n-BdYkS11p.js";import"./vendor-ui-CfDMlrKu.js";import"./vendor-pdf-DQuePnfN.js";import"./vendor-state-ByI9XJey.js";import"./vendor-editor-C_dhmuey.js";import"./i18n-CwjSIy0a.js";import"./vendor-icons-bLSWzydc.js";const K={getPools:async()=>(await oe.get("/tips/pools")).data,createPool:async n=>(await oe.post("/tips/pools",n)).data,updatePool:async(n,t)=>(await oe.patch(`/tips/pools/${n}`,t)).data,deletePool:async n=>{await oe.delete(`/tips/pools/${n}`)},getEntries:async(n,t)=>(await oe.get("/tips/entries",{params:{start:n,end:t}})).data,upsertEntry:async n=>(await oe.post("/tips/entries",n)).data,deleteEntry:async n=>{await oe.delete(`/tips/entries/${n}`)},addOverride:async(n,t)=>(await oe.post(`/tips/entries/${n}/overrides`,t)).data,removeOverride:async(n,t)=>{await oe.delete(`/tips/entries/${n}/overrides/${t}`)},previewSplit:async n=>(await oe.post("/tips/split/preview",n)).data,splitDayTotal:async n=>(await oe.post("/tips/entries/split",n)).data,preview:async n=>(await oe.post("/tips/preview",n)).data,distribute:async n=>(await oe.post(`/tips/entries/${n}/distribute`)).data,getSummary:async n=>(await oe.get("/tips/summary",{params:{payrollPeriodId:n}})).data,rollup:async(n,t)=>(await oe.post(`/tips/rollup/${n}`,t!=null&&t.length?{skipEmployeeIds:t}:{})).data};function Pe(n){return new Date(`${n}T00:00:00.000Z`)}function ue(n){return n.toISOString().slice(0,10)}function Ke(n,t){const a=Pe(n);return a.setUTCDate(a.getUTCDate()+t),ue(a)}function dt(n,t){return Math.round((Pe(t).getTime()-Pe(n).getTime())/864e5)}function Ye(n,t){return new Date(Date.UTC(n,t+1,0)).getUTCDate()}function xe(n,t,a){if(n==="WEEKLY"||n==="BI_WEEKLY"){if(!t)return null;const c=n==="BI_WEEKLY"?14:7,h=dt(t,a),N=Math.floor(h/c),m=Ke(t,N*c);return{start:m,end:Ke(m,c-1)}}const f=Pe(a),r=f.getUTCFullYear(),p=f.getUTCMonth(),x=f.getUTCDate();return n==="SEMI_MONTHLY"?x<=15?{start:ue(new Date(Date.UTC(r,p,1))),end:ue(new Date(Date.UTC(r,p,15)))}:{start:ue(new Date(Date.UTC(r,p,16))),end:ue(new Date(Date.UTC(r,p,Ye(r,p))))}:{start:ue(new Date(Date.UTC(r,p,1))),end:ue(new Date(Date.UTC(r,p,Ye(r,p))))}}function ke(n,t,a,f){if(n==="WEEKLY"||n==="BI_WEEKLY")return xe(n,t,Ke(a,f*(n==="BI_WEEKLY"?14:7)));const r=Pe(a),p=r.getUTCFullYear(),x=r.getUTCMonth(),c=r.getUTCDate();if(n==="SEMI_MONTHLY"){const h=f===1?c<=15?ue(new Date(Date.UTC(p,x,16))):ue(new Date(Date.UTC(p,x+1,1))):c<=15?ue(new Date(Date.UTC(p,x-1,16))):ue(new Date(Date.UTC(p,x,1)));return xe(n,t,h)}return xe(n,t,ue(new Date(Date.UTC(p,x+f,1))))}function ct(n,t,a,f,r=200){const p=xe(n,t,a);if(!p)return[];const x=[];let c=p;for(;c&&c.start<=f&&x.length<r;)x.push(c),c=ke(n,t,c.start,1);return x}const mt=["EQUAL","HOURS","HOURS_X_POINTS"];function Me(n,t){const a=new Date(`${n}T00:00:00.000Z`);return a.setUTCDate(a.getUTCDate()+t),a.toISOString().slice(0,10)}function We(n){const t=new Date(`${n}T00:00:00.000Z`).getUTCDay();return Me(n,-t)}function ut(n,t){const a=[];let f=n;for(;f<=t&&a.length<62;)a.push(f),f=Me(f,1);return a}function pt(n){const t=[];for(let a=0;a<n.length;a+=7)t.push(n.slice(a,a+7));return t}function ce(n,t){return new Date(`${n}T00:00:00.000Z`).toLocaleDateString(t,{timeZone:"UTC",weekday:"short",month:"numeric",day:"numeric"})}function Xe(n,t){return new Date(`${n}T00:00:00.000Z`).toLocaleDateString(t,{timeZone:"UTC",weekday:"long",month:"short",day:"numeric",year:"numeric"})}function _(n){const t=parseFloat(n);return isNaN(t)||t<0?0:Math.round(t*100)}function pe(n){return n===0?"":(n/100).toFixed(2)}function Rt(){var Ne;const{t:n,i18n:t}=be("tips"),{hasPermission:a}=ot(),f=a("MANAGE_TIPS"),r=lt(),{currentOrganizationId:p}=Fe(),x=Oe(),c=u.useMemo(()=>new Intl.NumberFormat(t.language,{style:"currency",currency:"USD"}),[t.language]),[h,N]=u.useState("daily"),m=it(r),[$,H]=u.useState(()=>We(m)),{data:W}=he({queryKey:["settings",p],queryFn:rt.getSettings,enabled:!!p,staleTime:300*1e3}),{data:G=[]}=he({queryKey:["payroll-periods",p],queryFn:at.getPeriods,enabled:!!p,staleTime:60*1e3}),w=W==null?void 0:W.payrollPeriodType,A=((Ne=W==null?void 0:W.payrollScheduleStartDate)==null?void 0:Ne.split("T")[0])??null,B=!!w&&!!xe(w,A,m),ee=u.useMemo(()=>{const l=new Map;for(const T of G)l.set(qe(T.startDate,r),{id:T.id,isProcessed:T.isProcessed});return l},[G,r]),O=u.useMemo(()=>
1{if(!B||!w)return G.map(J=>({start:qe(J.startDate,r),end:qe(J.endDate,r),realId:J.id,isProcessed:J.isProcessed,virtual:!1})).sort((J,se)=>J.start.localeCompare(se.start));const l=[...ee.keys()].sort(),T=l[0]&&l[0]<m?l[0]:m;let Q=xe(w,A,T).start;for(let J=0;J<2;J++){const se=ke(w,A,Q,-1);se&&(Q=se.start)}let ve=xe(w,A,m).end;for(let J=0;J<3;J++){const se=ke(w,A,xe(w,A,ve).start,1);se&&(ve=se.end)}return ct(w,A,Q,ve).map(J=>{const se=ee.get(J.start);return{start:J.start,end:J.end,realId:(se==null?void 0:se.id)??null,isProcessed:(se==null?void 0:se.isProcessed)??!1,virtual:!se}})},[B,w,A,G,ee,r,m]),[Z,X]=u.useState("");u.useEffect(()=>{if(O.length!==0&&(!Z||!O.some(l=>l.start===Z))){const l=O.find(T=>m>=T.start&&m<=T.end);X((l??O[O.length-1]).start)}},[O]);const S=u.useMemo(()=>{if(!Z)return null;const l=ee.get(Z);if(B&&w){const T=xe(w,A,Z);if(T)return{start:T.start,end:T.end,realId:(l==null?void 0:l.id)??null,isProcessed:(l==null?void 0:l.isProcessed)??!1,virtual:!l}}return O.find(T=>T.start===Z)??null},[Z,B,w,A,ee,O]),j=l=>{if(S&&B&&w){const T=ke(w,A,S.start,l);T&&X(T.start)}else if(S){const T=O.findIndex(ve=>ve.start===S.start),Q=O[T+l];Q&&X(Q.start)}else H(Me($,l*7))},P=()=>{if(O.length>0||B){const l=O.find(T=>m>=T.start&&m<=T.end)??(B&&w?xe(w,A,m):null);l&&X(l.start)}else H(We(m))},C=u.useMemo(()=>S?ut(S.start,S.end):Array.from({length:7},(l,T)=>Me($,T)),[S,$]),F=C[0],i=C[C.length-1],v=C.some(l=>l<=m),[D,Y]=u.useState(null),[ne,I]=u.useState(null),[q,ye]=u.useState(null),[b,o]=u.useState(!1),[y,d]=u.useState(""),{data:g=[]}=he({queryKey:["tip-pools",p],queryFn:K.getPools,enabled:!!p,staleTime:300*1e3}),E=u.useMemo(()=>g.filter(l=>l.isActive),[g]),ae=u.useMemo(()=>new Set(E.filter(l=>l.splitPercent!=null).map(l=>l.id)),[E]),L=ae.size>0,{data:k=[]}=he({queryKey:["tips-entries",p,F,i],queryFn:()=>K.getEntries(F,i),enabled:!!p&&h==="daily"}),R=u.useMemo(()=>k.filter(l=>ae.has(l.tipPoolId)),[k,ae]),te=u.useMemo(()=>{const l=new Map;for(const T of k)l.set(`${T.tipPoolId}:${T.businessDate}`,T);return l},[k]),U=(S==null?void 0:S.realId)??"",{data:V}=he({queryKey:["tips-summary",p,U],queryFn:()=>K.getSummary(U),enabled:!!p&&!!U}),le=me({mutationFn:l=>K.rollup(U,l),onSuccess:()=>{je(null),x.invalidateQueries({queryKey:["tips-summary",p]})},onError:l=>{var T,Q;return d(((Q=(T=l.response)==null?void 0:T.data)==null?void 0:Q.message)||n("payroll.syncFailed"))}}),re=u.useMemo(()=>((V==null?void 0:V.employees)??[]).filter(l=>l.edited&&!l.inSync),[V]),[ie,je]=u.useState(null),we=()=>{d(""),re.length>0?je({list:re,keep:new Set(re.map(l=>l.employeeId))}):le.mutate(void 0)},ge=me({mutationFn:async l=>{if(l.amountCents==null){l.overrideId&&await K.removeOverride(l.entryId,l.overrideId);return}await K.addOverride(l.entryId,{employeeId:l.employeeId,type:"SET_AMOUNT",amountCents:l.amountCents})},onSuccess:()=>{x.invalidateQueries({queryKey:["tips-entries",p]}),x.invalidateQueries({queryKey:["tips-summary",p]})},onError:l=>{var T,Q;return d(((Q=(T=l.response)==null?void 0:T.data)==null?void 0:Q.message)||n("daily.pinFailed"))}}),z=u.useMemo(()=>{if(!S)return null;const l=C.filter(Q=>Q<=m);return l.length===0?null:{entered:[...new Set(k.filter(Q=>Q.totalCents>0).map(Q=>Q.businessDate))].filter(Q=>Q<=m).length,total:l.length}},[S,C,k,m]);return e.jsxs("div",{className:"p-4 sm:p-6 space-y-4",children:[e.jsx("div",{className:"flex flex-wrap items-center justify-between gap-2",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:n("title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:n("subtitle")})]})}),y&&e.jsxs("div",{className:"p-3 rounded-md bg-destructive/10 border border-destructive/20 text-destructive text-sm flex justify-between",children:[e.jsx("span",{children:y}),e.jsx("button",{onClick:()=>d(""),className:"font-bold px-2",children:"×"})]}),e.jsx("div",{className:"border-b flex gap-1",children:["daily","pools"].map(l=>e.jsx("button",{onClick:()=>N(l),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px ${h===l?"border-primary text-primary":"border-transparent text-muted-foreground hover:text-foreground"}`,children:n(`tabs.${l}`)},l))}),h==="daily"&&e.jsx(ht,{pools:E,splitPoolIds:ae,days:C,today:m,entryByPoolDate:te,canManage:f,money:c,locale:t.language,periodMode:S?{ranges:O,selectedStart:S.start,isProcessed:S.isProcessed,virtual:S.virtual,coverage:z,locale:t.language,onSelect:X}:null,onPrev:()=>j(-1),onNext:()=>j(1),onToday:P,onSetShare:l=>ge.mutate(l),isSavingShare:ge.isPending,payroll:{periodId:(S==null?void 0:S.realId)??null,summary:V,canSync:f,isSyncing:le.isPending,onSync:we},onOpenCell:(l,T)=>Y({pool:l,date:T}),onGoToPools:()=>N("pools"),onDayTotal:f&&L&&v?l=>ye({date:l}):void 0,onPeriodTotals:f&&L&&S&&v?()=>o(!0):void 0}),ie!==null&&e.jsx(jt,{state:ie,money:c,isApplying:le.isPending,onChange:je,onApply:l=>le.mutate(l)}),h==="pools"&&e.jsx(Nt,{pools:g,canManage:f,onAdd:()=>I({pool:null}),onEdit:l=>I({pool:l}),setError:d}),D&&e.jsx(gt,{pool:D.pool,date:D.date,existing:te.get(`${D.pool.id}:${D.date}`),sameDayEntries:k.filter(l=>l.businessDate===D.date),canManage:f,money:c,locale:t.language,timezone:r,onClose:()=>Y(null),onSaved:()=>
1{x.invalidateQueries({queryKey:["tips-entries",p]}),x.invalidateQueries({queryKey:["tips-summary",p]})},setError:d}),q&&e.jsx(ft,{days:C,today:m,initialDate:q.date,entries:R,money:c,locale:t.language,onClose:()=>ye(null),onSaved:()=>{x.invalidateQueries({queryKey:["tips-entries",p]}),x.invalidateQueries({queryKey:["tips-summary",p]})},setError:d}),b&&S&&e.jsx(bt,{days:C,today:m,entries:R,money:c,locale:t.language,onClose:()=>o(!1),onSaved:()=>{x.invalidateQueries({queryKey:["tips-entries",p]}),x.invalidateQueries({queryKey:["tips-summary",p]})}}),ne&&e.jsx(vt,{pool:ne.pool,onClose:()=>I(null),onSaved:()=>{x.invalidateQueries({queryKey:["tip-pools",p]}),I(null)},setError:d})]})}function xt(n,t,a){var r,p;const f=new Map;for(const x of t){const c=a.get(`${n}:${x}`);if(c){for(const h of c.overrides??[])h.type!=="EXCLUDE"&&(f.has(h.employeeId)||f.set(h.employeeId,{employeeId:h.employeeId,employeeName:h.employeeName,positionName:null,byDate:new Map,totalCents:0}));for(const h of c.shares){const N=f.get(h.employeeId)??{employeeId:h.employeeId,employeeName:h.employeeName,positionName:h.positionName,byDate:new Map,totalCents:0},m=((p=(r=h.breakdown)==null?void 0:r.employee)==null?void 0:p.hours)??null;N.byDate.set(x,{amountCents:h.amountCents,hours:typeof m=="number"?m:null,isStale:c.isStale}),N.totalCents+=h.amountCents,f.set(h.employeeId,N)}}}return[...f.values()].sort((x,c)=>x.employeeName.localeCompare(c.employeeName))}function ht(n){const{t}=be("tips"),{pools:a,splitPoolIds:f,days:r,today:p,entryByPoolDate:x,canManage:c,money:h,locale:N,periodMode:m,onPrev:$,onNext:H,onToday:W,onSetShare:G,isSavingShare:w,payroll:A,onOpenCell:B,onGoToPools:ee,onDayTotal:O,onPeriodTotals:Z}=n,X=u.useMemo(()=>pt(r),[r]),S=u.useMemo(()=>{const o=new Map;for(const y of x.values())for(const d of y.shares??[]){const g=`${d.employeeId}:${y.businessDate}`,E=o.get(g)??[];E.push({poolId:y.tipPoolId,poolName:y.poolName,amountCents:d.amountCents}),o.set(g,E)}return o},[x]),[j,P]=u.useState(new Set),C=o=>P(y=>{const d=new Set(y);return d.has(o)?d.delete(o):d.add(o),d}),[F,i]=u.useState(null),[v,D]=u.useState(""),Y=(o,y)=>{i(o),D((y/100).toFixed(2))},ne=(o,y,d)=>{const g=v.trim();if(i(null),g===""){d&&G({entryId:o.id,employeeId:y,amountCents:null,overrideId:d});return}const E=Number(g.replace(/[$,]/g,""));!Number.isFinite(E)||E<0||G({entryId:o.id,employeeId:y,amountCents:Math.round(E*100),overrideId:d})},I=A.summary,q=u.useMemo(()=>{const o=new Map,y=g=>({employeeName:g,byPool:new Map,totalCents:0,adjustmentCents:null,inSync:null}),d=I?I.entries.filter(g=>g.status==="DISTRIBUTED"&&!g.isStale):r.flatMap(g=>a.map(E=>x.get(`${E.id}:${g}`)).filter(Boolean));for(const g of d)for(const E of g.shares){const ae=o.get(E.employeeId)??y(E.employeeName);ae.byPool.set(g.tipPoolId,(ae.byPool.get(g.tipPoolId)??0)+E.amountCents),ae.totalCents+=E.amountCents,o.set(E.employeeId,ae)}if(I)for(const g of I.employees){const E=o.get(g.employeeId)??y(g.employeeName);E.employeeName=E.employeeName||g.employeeName,E.totalCents=g.totalCents,E.adjustmentCents=g.adjustmentCents,E.inSync=g.inSync,o.set(g.employeeId,E)}return[...o.entries()].map(([g,E])=>({employeeId:g,...E})).sort((g,E)=>g.employeeName.localeCompare(E.employeeName))},[I,r,a,x]),ye=!!I&&(I.period.startDate!==r[0]||I.period.endDate!==r[r.length-1]),b=u.useMemo(()=>{var y;const o=new Map;for(const d of r){let g=0;for(const E of a)f.has(E.id)&&(g+=((y=x.get(`${E.id}:${d}`))==null?void 0:y.totalCents)??0);o.set(d,g)}return o},[r,a,f,x]);return a.length===0?e.jsxs("div",{className:"border rounded-lg p-8 bg-card text-center space-y-2",children:[e.jsx("p",{className:"font-medium",children:t("daily.noPools")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("daily.noPoolsHint")}),e.jsx("button",{onClick:ee,className:"mt-2 px-4 py-2 text-sm bg-primary text-primary-foreground rounded-md hover:bg-primary/90",children:t("pools.add")})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("button",{onClick:$,className:"px-3 py-1.5 text-sm border rounded-md hover:bg-accent",children:["← ",t("daily.prevWeek")]}),e.jsx("button",{onClick:W,className:"px-3 py-1.5 text-sm border rounded-md hover:bg-accent",children:t("daily.today")}),e.jsxs("button",{onClick:H,className:"px-3 py-1.5 text-sm border rounded-md hover:bg-accent",children:[t("daily.nextWeek")," →"]}),m?e.jsxs(e.Fragment,{children:[e.jsx("select",{value:m.selectedStart,onCh
1ange:o=>m.onSelect(o.target.value),className:"px-2 py-1.5 border rounded-md bg-background text-sm","aria-label":t("daily.period"),children:[...m.ranges].reverse().map(o=>e.jsxs("option",{value:o.start,children:[ce(o.start,N)," – ",ce(o.end,N),o.isProcessed?` · ${t("payroll.processed")}`:"",o.virtual?` · ${t("daily.upcoming")}`:""]},o.start))}),m.isProcessed&&e.jsxs("span",{className:"text-sm text-muted-foreground",children:["🔒 ",t("payroll.processed")]}),m.coverage&&e.jsx("span",{className:"text-sm text-muted-foreground",children:t("daily.coverage",m.coverage)})]}):e.jsxs("span",{className:"text-sm text-muted-foreground ml-2",children:[ce(r[0],N)," – ",ce(r[r.length-1],N)]}),e.jsxs("div",{className:"ml-auto flex gap-2",children:[Z&&e.jsx("button",{onClick:Z,className:"px-3 py-1.5 text-sm bg-primary text-primary-foreground rounded-md hover:bg-primary/90",children:t("batch.button")}),O&&e.jsx("button",{onClick:()=>O(),className:"px-3 py-1.5 text-sm border rounded-md hover:bg-accent",children:t("split.button")})]})]}),I&&I.warnings.undistributed.length>0&&e.jsxs("div",{className:"p-3 rounded-md bg-amber-500/10 border border-amber-500/30 text-sm",children:[e.jsxs("p",{className:"font-medium mb-1",children:["⚠ ",t("payroll.undistributed")]}),e.jsx("ul",{className:"text-muted-foreground space-y-0.5",children:I.warnings.undistributed.map(o=>e.jsxs("li",{children:[o.businessDate," · ",o.poolName,o.isStale?` (${t("daily.statusStale")})`:""]},o.id))}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:t("payroll.undistributedHint")})]}),X.map((o,y)=>e.jsxs("div",{className:"border rounded-lg bg-card overflow-x-auto",children:[X.length>1&&e.jsxs("div",{className:"px-3 py-2 border-b bg-muted/30 text-sm font-medium",children:[t("daily.weekLabel",{number:y+1}),e.jsxs("span",{className:"ml-2 font-normal text-muted-foreground",children:[ce(o[0],N)," –"," ",ce(o[o.length-1],N)]})]}),e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b bg-muted/50",children:[e.jsx("th",{className:"text-left p-3 font-medium min-w-[180px]",children:t("daily.pool")}),o.map(d=>e.jsx("th",{className:`p-2 text-center font-medium min-w-[104px] ${d===p?"text-primary":""}`,children:ce(d,N)},d)),e.jsx("th",{className:"p-2 text-right font-medium min-w-[92px]",children:t("daily.total")})]})}),e.jsxs("tbody",{children:[O&&e.jsxs("tr",{className:"border-b bg-muted/30",children:[e.jsxs("td",{className:"p-3 font-medium",children:[t("daily.dayTotal"),e.jsx("div",{className:"text-xs text-muted-foreground font-normal",children:t("daily.dayTotalHint")})]}),o.map(d=>{const g=d>p;return e.jsx("td",{className:"p-1 text-center",children:e.jsx("button",{disabled:g,onClick:()=>O(d),className:`w-full rounded-md px-2 py-2 border text-sm font-semibold transition-colors ${g?"opacity-30 cursor-not-allowed border-transparent":"hover:bg-accent"} ${b.get(d)?"border-border":"border-dashed border-muted-foreground/40 text-muted-foreground"}`,children:b.get(d)?h.format((b.get(d)??0)/100):"+"})},d)}),e.jsx("td",{className:"p-3 text-right font-semibold",children:h.format(o.reduce((d,g)=>d+(b.get(g)??0),0)/100)})]}),a.map(d=>{const g=j.has(d.id),E=g?xt(d.id,o,x):[],ae=o.reduce((L,k)=>{var R;return L+(((R=x.get(`${d.id}:${k}`))==null?void 0:R.totalCents)??0)},0);return e.jsxs(u.Fragment,{children:[e.jsxs("tr",{className:"border-b last:border-b-0",children:[e.jsx("td",{className:"p-0 font-medium align-middle",children:e.jsxs("button",{onClick:()=>C(d.id),"aria-expanded":g,className:"w-full text-left p-3 flex items-start gap-2 hover:bg-accent transition-colors",children:[e.jsx("span",{className:"text-muted-foreground select-none leading-5",children:g?"▼":"▶"}),e.jsxs("span",{children:[d.name,e.jsx("span",{className:"block text-xs text-muted-foreground font-normal",children:t(`pools.methods.${d.distributionMethod}`)})]})]})}),o.map(L=>{const k=x.get(`${d.id}:${L}`),R=L>p,te=((k==null?void 0:k.overrides)??[]).filter(le=>le.type==="CARVE_OUT").reduce((le,re)=>le+(re.amountCents??0),0),U=((k==null?void 0:k.shares)??[]).reduce((le,re)=>le+re.amountCents,0),V=k?Math.max(0,k.totalCents-U):0;return e.jsx("td",{className:"p-1 text-center",children:e.jsx("button",{disabled:R,onClick:()=>B(d,L),className:`w-full rounded-md px-2 py-2 border text-sm transition-colors ${R?"opacity-30 curs
1or-not-allowed border-transparent":"hover:bg-accent"} ${k?"border-border":"border-dashed border-muted-foreground/30 text-muted-foreground"}`,children:k?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"font-medium",children:h.format(k.totalCents/100)}),te>0&&e.jsx("div",{className:"text-[10px] text-muted-foreground leading-tight",children:t("adjustments.carvedOff",{amount:h.format(te/100)})}),V>0&&k.status==="DISTRIBUTED"&&e.jsx("div",{className:"text-[10px] text-amber-600 leading-tight",children:t("adjustments.unallocated",{amount:h.format(V/100)})}),e.jsx(yt,{entry:k})]}):e.jsx("span",{children:"+"})})},L)}),e.jsx("td",{className:"p-3 text-right font-semibold",children:ae>0?h.format(ae/100):"—"})]}),g&&E.length===0&&e.jsx("tr",{className:"border-b last:border-b-0 bg-accent/30",children:e.jsx("td",{colSpan:o.length+2,className:"px-3 py-2 pl-10 text-sm text-muted-foreground",children:t("daily.noBreakdown")})}),g&&E.map(L=>e.jsxs("tr",{className:"border-b last:border-b-0 bg-accent/30",children:[e.jsxs("td",{className:"py-2 pl-10 pr-3",children:[L.employeeName,L.positionName&&e.jsx("span",{className:"block text-xs text-muted-foreground",children:L.positionName})]}),o.map(k=>{var ge;const R=L.byDate.get(k),te=x.get(`${d.id}:${k}`);if(!R){const z=!!te&&te.status!=="DISTRIBUTED";return e.jsx("td",{className:"py-2 px-1 text-center text-muted-foreground/60",title:z?t("daily.statusOpen"):void 0,children:z?"—":"·"},k)}const U=`${d.id}:${k}:${L.employeeId}`,V=(ge=te==null?void 0:te.overrides)==null?void 0:ge.find(z=>z.type==="SET_AMOUNT"&&z.employeeId===L.employeeId),le=c&&!!te;if(F===U)return e.jsx("td",{className:"py-1 px-1 text-center",children:e.jsx("input",{autoFocus:!0,t
1ype:"text",inputMode:"decimal",value:v,disabled:w,onChange:z=>D(z.target.value),onBlur:()=>ne(te,L.employeeId,V==null?void 0:V.id),onKeyDown:z=>{z.key==="Enter"?ne(te,L.employeeId,V==null?void 0:V.id):z.key==="Escape"&&i(null)},className:"w-20 px-1 py-1 text-center border rounded-md bg-background","aria-label":t("daily.editShare",{name:L.employeeName,date:ce(k,N)})})},k);const re=S.get(`${L.employeeId}:${k}`)??[],ie=re.filter(z=>z.poolId!==d.id&&z.amountCents>0),je=re.reduce((z,Ne)=>z+Ne.amountCents,0),we=e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:R.isStale?"text-amber-600 dark:text-amber-500":"",children:[h.format(R.amountCents/100),R.isStale&&" ⟳",V&&" ✎"]}),R.hours!=null&&R.hours>0&&e.jsx("span",{className:"block text-xs text-muted-foreground",children:t("daily.hoursShort",{hours:R.hours})}),ie.map(z=>e.jsx("span",{className:"block text-xs text-primary font-medium leading-tight",children:t("daily.alsoFromPool",{amount:h.format(z.amountCents/100),pool:z.poolName})},z.poolId)),ie.length>0&&e.jsx("span",{className:"block text-xs font-semibold leading-tight mt-0.5",children:t("daily.dayAcrossPools",{amount:h.format(je/100)})})]});return e.jsx("td",{className:"py-2 px-1 text-center",children:le?e.jsx("button",{onClick:()=>Y(U,R.amountCents),title:t(V?"daily.pinnedHint":"daily.editHint"),className:`w-full rounded px-1 py-0.5 hover:bg-background transition-colors ${V?"ring-1 ring-primary/40":""}`,children:we}):e.jsx("span",{title:R.isStale?t("daily.statusStale"):void 0,children:we})},k)}),e.jsx("td",{className:"py-2 px-3 text-right font-medium",children:h.format(L.totalCents/100)})]},`${d.id}:${L.employeeId}`))]},d.id)})]})]})]},o[0])),q.length>0&&e.jsxs("div",{className:"border rounded-lg bg-card overflow-x-auto",children:[e.jsxs("div",{className:"px-3 py-2 border-b bg-muted/30 flex flex-wrap items-center gap-x-3 gap-y-1",children:[e.jsx("span",{className:"text-sm font-medium",children:t("daily.periodTotal")}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[ce(r[0],N)," – ",ce(r[r.length-1],N)]}),I?I.inSync?e.jsxs("span",{className:"text-sm text-green-600 dark:text-green-500",children:["✓ ",t("payroll.inSyncBadge")]}):e.jsxs("span",{className:"text-sm text-amber-600 dark:text-amber-500",children:["⚠ ",t("payroll.outOfSyncBadge")]}):e.jsx("span",{className:"text-sm text-muted-foreground",children:t("payroll.noPeriodYet")}),I&&A.canSync&&e.jsx("button",{onClick:A.onSync,disabled:A.isSyncing,className:"ml-auto px-4 py-1.5 text-sm bg-primary text-primary-foreground rounded-md hover:bg-primary/90 disabled:opacity-50",children:A.isSyncing?"…":t("payroll.sync")})]}),!I&&e.jsx("p",{className:"px-3 py-2 text-xs text-muted-foreground border-b",children:t("payroll.noPeriodYetHint")}),(I==null?void 0:I.period.isProcessed)&&e.jsxs("p",{className:"px-3 py-2 text-xs text-amber-600 dark:text-amber-500 border-b",children:["🔒 ",t("payroll.processedWarning")]}),ye&&e.jsxs("p",{className:"px-3 py-2 text-xs text-amber-600 dark:text-amber-500 border-b",children:["⚠"," ",t("payroll.periodMismatch",{start:ce(I.period.startDate,N),end:ce(I.period.endDate,N)})]}),e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b bg-muted/50",children:[e.jsx("th",{className:"text-left p-3 font-medium min-w-[180px]",children:t("daily.employee")}),a.map(o=>e.jsx("th",{className:"p-2 text-right font-medium min-w-[120px]",children:o.name},o.id)),e.jsx("th",{className:"p-2 text-right font-medium min-w-[100px]",children:t("daily.total")}),I&&e.jsxs(e.Fragment,{children:[e.jsx("th",{className:"p-2 text-right font-medium min-w-[120px]",children:t("payroll.adjustment")}),e.jsx("th",{className:"p-2 pr-3 text-right font-medium",children:t("payroll.status")})]})]})}),e.jsxs("tbody",{children:[q.map(o=>e.jsxs("tr",{className:"border-b last:border-b-0",children:[e.jsx("td",{className:"p-3",children:o.employeeName||o.employeeId}),a.map(y=>{const d=o.byPool.get(y.id)??0;return e.jsx("td",{className:`p-2 text-right ${d?"":"text-muted-foreground/60"}`,children:d?h.format(d/100):"—"},y.id)}),e.jsx("td",{className:"p-2 text-right font-semibold",children:h.format(
1o.totalCents/100)}),I&&e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"p-2 text-right",children:o.adjustmentCents==null?"—":h.format(o.adjustmentCents/100)}),e.jsx("td",{className:"p-2 pr-3 text-right",children:o.inSync?e.jsx("span",{className:"text-green-600 dark:text-green-500",children:"✓"}):e.jsx("span",{className:"text-amber-600 dark:text-amber-500",children:"⚠"})})]})]},o.employeeId)),e.jsxs("tr",{className:"border-t bg-muted/30",children:[e.jsx("td",{className:"p-3 font-medium",children:t("daily.total")}),a.map(o=>e.jsx("td",{className:"p-2 text-right font-semibold",children:h.format(q.reduce((y,d)=>y+(d.byPool.get(o.id)??0),0)/100)},o.id)),e.jsx("td",{className:"p-2 text-right font-semibold",children:h.format(q.reduce((o,y)=>o+y.totalCents,0)/100)}),I&&e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"p-2 text-right font-semibold",children:h.format(q.reduce((o,y)=>o+(y.adjustmentCents??0),0)/100)}),e.jsx("td",{})]})]})]})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("daily.legend")})]})}function yt({entry:n}){const{t}=be("tips"),a=n.isLocked?" 🔒":"";return n.status==="DISTRIBUTED"&&!n.isStale?e.jsxs("div",{className:"text-xs text-green-600 dark:text-green-500",children:["✓ ",t("daily.statusDistributed"),a]}):n.isStale?e.jsxs("div",{className:"text-xs text-amber-600 dark:text-amber-500",children:["⟳ ",t("daily.statusStale"),a]}):e.jsxs("div",{className:"text-xs text-amber-600 dark:text-amber-500",children:["● ",t("daily.statusOpen"),a]})}function gt(n){var He,Be;const{t}=be("tips"),{pool:a,date:f,existing:r,sameDayEntries:p,canManage:x,money:c,locale:h,onClose:N,onSaved:m}=n,[$,H]=u.useState(pe((r==null?void 0:r.cashCents)??0)),[W,G]=u.useState(pe((r==null?void 0:r.cardCents)??0)),[w,A]=u.useState(pe((r==null?void 0:r.otherCents)??0)),[B,ee]=u.useState((r==null?void 0:r.notes)??""),[O,Z]=u.useState(0),[X,S]=u.useState(""),[j,P]=u.useState(""),C=_($)+_(W)+_(w),[F,i]=u.useState(C);u.useEffect(()=>{const s=setTimeout(()=>i(C),350);return()=>clearTimeout(s)},[C]);const v=(r==null?void 0:r.isLocked)??!1,D=(r==null?void 0:r.status)==="DISTRIBUTED"&&!r.isStale,Y=!r||_($)!==r.cashCents||_(W)!==r.cardCents||_(w)!==r.otherCents,{currentOrganizationId:ne}=Fe(),I=Oe(),[q,ye]=u.useState("INCLUDE"),[b,o]=u.useState(""),[y,d]=u.useState(""),[g,E]=u.useState(""),[ae,L]=u.useState(""),{data:k=[]}=he({queryKey:["employees",ne],queryFn:()=>nt.getAll(),enabled:!!ne&&x,staleTime:300*1e3}),R=s=>{var de,fe;const M=((fe=(de=s==null?void 0:s.response)==null?void 0:de.data)==null?void 0:fe.message)||t("entry.saveFailed");S(Array.isArray(M)?M.join("; "):M)},te=!!b&&(q==="CARVE_OUT"?_(g)>0:q==="SET_AMOUNT"?g.trim()!=="":!0),U=u.useMemo(()=>{if(!te)return null;const s=parseFloat(y);return{employeeId:b,type:q,...q==="INCLUDE"&&!isNaN(s)?{points:s}:{},...q==="CARVE_OUT"||q==="SET_AMOUNT"?{amountCents:_(g)}:{},...ae?{reason:ae}:{}}},[te,b,q,y,g,ae]),[V,le]=u.useState(null);u.useEffect(()=>{const s=setTimeout(()=>le(U),350);return()=>clearTimeout(s)},[U]);const re=!!r&&D&&!Y&&O===0&&!U,{data:ie,isFetching:je,isError:we,error:ge}=he({queryKey:["tips-preview",a.id,f,F,O,V],queryFn:()=>K.preview({tipPoolId:a.id,businessDate:f,totalCents:F,...V?{pendingOverrides:[V]}:{}}),enabled:F>0&&!re,staleTime:30*1e3,retry:!1}),z=async()=>(r==null?void 0:r.id)??(await K.upsertEntry({tipPoolId:a.id,businessDate:f,cashCents:_($),cardCents:_(W),otherCents:_(w)})).id,Ne=me({mutationFn:async s=>{const M=await K.upsertEntry({tipPoolId:a.id,businessDate:f,cashCents:_($),cardCents:_(W),otherCents:_(w),...B?{notes:B}:{}});U&&await K.addOverride(M.id,U),s&&await K.distribute(M.id)},onSuccess:()=>{m(),N()},onError:R}),l=me({mutationFn:()=>K.deleteEntry(r.id),onSuccess:()=>{m(),N()},onError:R}),T=me({mutationFn:async()=>{U&&await K.addOverride(r.id,U),await K.distribute(r.id)},onSuccess:()=>{m(),N()},onError:R}),Q=()=>{m(),I.invalidateQueries({queryKey:["tips-preview"]})},ve=me({mutationFn:async()=>{if(!U)return;const s=await z();await K.addOverride(s,U)},onSuccess:()=>{S(""),o(""),d(""),E(""),L(""),Z(s=>s+1),Q()},onError:R}),J=me({mutationFn:async s=>{const M=await z();
1await K.addOverride(M,{employeeId:s.employeeId,type:"CARVE_OUT",amountCents:s.amountCents})},onSuccess:()=>{S(""),P(""),Z(s=>s+1),Q()},onError:R}),se=me({mutationFn:s=>K.removeOverride(r.id,s),onSuccess:()=>{S(""),Z(s=>s+1),Q()},onError:R}),Ue=re?r.shares??[]:(ie==null?void 0:ie.shares)??(r==null?void 0:r.shares)??[],Se=re||ie==null?void 0:ie.warnings,$e=Math.max(0,C-Ue.reduce((s,M)=>s+M.amountCents,0)),Le=we?((Be=(He=ge==null?void 0:ge.response)==null?void 0:He.data)==null?void 0:Be.message)||t("entry.saveFailed"):"",Ee=Ne.isPending||l.isPending||T.isPending||J.isPending,Ve=k.filter(s=>s.isActive&&(q==="EXCLUDE"||!s.excludeFromTipPools)),Ze=k.filter(s=>s.isActive&&!s.excludeFromTipPools),Ge=u.useMemo(()=>{const s=new Map;for(const M of p)if(M.tipPoolId!==a.id)for(const de of M.shares??[]){if(de.amountCents<=0)continue;const fe=s.get(de.employeeId)??[];fe.push({poolName:M.poolName,amountCents:de.amountCents}),s.set(de.employeeId,fe)}return s},[p,a.id]),Ae=k.find(s=>s.id===b),De=Ae?`${Ae.firstName} ${Ae.lastName}`:"",[Ie,Je]=u.useState(()=>({w:Math.min(720,typeof window<"u"?window.innerWidth-24:720),h:Math.min(800,typeof window<"u"?window.innerHeight-24:800)})),Ce=u.useRef(null),et=s=>{s.preventDefault(),s.currentTarget.setPointerCapture(s.pointerId),Ce.current={x:s.clientX,y:s.clientY,w:Ie.w,h:Ie.h}},tt=s=>{Ce.current&&Je({w:Math.min(Math.max(320,Ce.current.w+(s.clientX-Ce.current.x)),window.innerWidth-16),h:Math.min(Math.max(420,Ce.current.h+(s.clientY-Ce.current.y)),window.innerHeight-16)})},Re=()=>{Ce.current=null};return e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center p-2 sm:p-4 z-50",children:e.jsxs("div",{className:"bg-card border rounded-lg shadow-lg flex flex-col overflow-hidden relative",style:{width:Ie.w,height:Ie.h},children:[e.jsxs("div",{className:"p-4 border-b shrink-0",children:[e.jsx("h3",{className:"text-lg font-semibold",children:a.name}),e.jsx("p",{className:"text-sm text-muted-foreground",children:Xe(f,h)}),v&&e.jsxs("p",{className:"text-sm text-amber-600 mt-1",children:["🔒 ",t("entry.locked")]}),(X||Le)&&e.jsx("p",{className:"text-sm text-destructive mt-2",children:X||Le})]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"p-4 space-y-4 shrink-0 overflow-y-auto max-h-[48%]",children:[e.jsx("div",{className:"grid grid-cols-3 gap-3",children:[["cash",$,H],["card",W,G],["other",w,A]].map(([s,M,de])=>e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:t(`entry.${s}`)}),e.jsx("input",{type:"number",min:"0",step:"0.01",inputMode:"decimal",placeholder:"0.00",value:M,disabled:!x,onChange:fe=>de(fe.target.value),className:"w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-primary disabled:opacity-50"})]},s))}),e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:t("entry.total")}),e.jsx("span",{className:"font-semibold",children:c.format(C/100)})]}),e.jsx("p",{className:"text-xs text-muted-foreground -mt-2",children:t("entry.potHint")}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:t("entry.notes")}),e.jsx("textarea",{value:B,disabled:!x,onChange:s=>ee(s.target.value),rows:2,className:"w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-primary disabled:opacity-50"})]}),Se&&Se.openTimeEntries.length>0&&e.jsxs("p",{className:"text-xs text-amber-600",children:["⚠ ",t("entry.warnOpenEntries",{names:Se.openTimeEntries.join(", ")})]}),Se&&Se.workedButNotEligible.length>0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t("entry.warnNotEligible",{names:Se.workedButNotEligible.map(s=>`${s.name}${s.position?` (${s.position})`:""}`).join(", ")})}),x&&e.jsxs("div",{className:"border rounded-md p-3 space-y-2 bg-muted/30",children:[e.jsx("h4",{className:"text-sm font-medium",children:t("adjustments.heading")}),((r==null?void 0:r.overrides)??[]).map(s=>e.jsxs("div",{className:"flex justify-between items-center text-sm",children:[e.jsxs("span",{children:[s.type==="INCLUDE"&&e.jsxs(e.Fragment,{children:["+ ",s.employeeName,s.points!=null&&` (${s.points}pt)`]}),s.type==="EXCLUDE"&&e.jsxs(e.Fragment,{children:["− ",s.employeeName]}
1),s.type==="CARVE_OUT"&&e.jsxs(e.Fragment,{children:[c.format((s.amountCents??0)/100)," →"," ",s.employeeName]}),s.type==="SET_AMOUNT"&&e.jsxs(e.Fragment,{children:["✎ ",s.employeeName," ="," ",c.format((s.amountCents??0)/100),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[" ","(",t("adjustments.pinnedTag"),")"]})]}),s.reason&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:[" — ",s.reason]})]}),e.jsx("button",{onClick:()=>se.mutate(s.id),disabled:se.isPending,className:"text-destructive hover:underline text-xs px-2",children:t("adjustments.remove")})]},s.id)),U&&De&&e.jsx("div",{className:"flex justify-between items-center text-sm rounded-md border border-dashed px-2 py-1 bg-background",children:e.jsxs("span",{children:[U.type==="INCLUDE"&&e.jsxs(e.Fragment,{children:["+ ",De,U.points!=null&&` (${U.points}pt)`]}),U.type==="EXCLUDE"&&e.jsxs(e.Fragment,{children:["− ",De]}),U.type==="CARVE_OUT"&&e.jsxs(e.Fragment,{children:[c.format((U.amountCents??0)/100)," →"," ",De]}),U.type==="SET_AMOUNT"&&e.jsxs(e.Fragment,{children:["✎ ",De," ="," ",c.format((U.amountCents??0)/100),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[" ","(",t("adjustments.pinnedTag"),")"]})]}),e.jsxs("span",{className:"text-xs text-amber-700 dark:text-amber-400",children:[" ","(",t("adjustments.unsaved"),")"]})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("select",{value:q,onChange:s=>ye(s.target.value),className:"px-2 py-1.5 border rounded-md bg-background text-sm",children:[e.jsx("option",{value:"INCLUDE",children:t("adjustments.types.INCLUDE")}),e.jsx("option",{value:"EXCLUDE",children:t("adjustments.types.EXCLUDE")}),e.jsx("option",{value:"CARVE_OUT",children:t("adjustments.types.CARVE_OUT")}),e.jsx("option",{value:"SET_AMOUNT",children:t("adjustments.types.SET_AMOUNT")})]}),e.jsxs("select",{value:b,onChange:s=>o(s.target.value),className:"px-2 py-1.5 border rounded-md bg-background text-sm",children:[e.jsx("option",{value:"",children:t("adjustments.selectEmployee")}),Ve.map(s=>e.jsxs("option",{value:s.id,children:[s.firstName," ",s.lastName,s.position?` (${s.position})`:""]},s.id))]}),q==="INCLUDE"&&a.distributionMethod==="HOURS_X_POINTS"&&e.jsx("input",{type:"number",min:"0.01",step:"0.5",placeholder:t("adjustments.points"),value:y,onChange:s=>d(s.target.value),className:"px-2 py-1.5 border rounded-md text-sm"}),(q==="CARVE_OUT"||q==="SET_AMOUNT")&&e.jsx("input",{type:"number",min:q==="SET_AMOUNT"?"0":"0.01",step:"0.01",inputMode:"decimal",placeholder:t("adjustments.amount"),value:g,onChange:s=>E(s.target.value),className:"px-2 py-1.5 border rounded-md text-sm"}),e.jsx("input",{type:"text",placeholder:t("adjustments.reason"),value:ae,onChange:s=>L(s.target.value),className:"px-2 py-1.5 border rounded-md text-sm col-span-2"})]}),e.jsx("button",{onClick:()=>ve.mutate(),disabled:!te||ve.isPending,className:"px-3 py-1.5 text-sm bg-primary text-primary-foreground rounded-md hover:bg-primary/90 disabled:opacity-50",children:t("adjustments.add")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("adjustments.addHint")}),e.jsx("div",{className:"rounded-md border bg-background px-3 py-2 text-sm text-foreground",children:t(`adjustments.typeHint.${q}`)})]})]}),e.jsxs("div",{className:"flex flex-col flex-1 min-h-0 px-4 pb-2",children:[e.jsxs("h4",{className:"text-sm font-medium mb-2 shrink-0",children:[t(U?"entry.previewPending":re?"entry.shares":"entry.preview"),je&&e.jsx("span",{className:"text-muted-foreground",children:" …"})]}),Ue.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:F>0&&!je&&ie?t("entry.noEligible"):t("entry.previewEmpty")}):e.jsxs("div",{className:"border rounded-md divide-y flex-1 overflow-y-auto",children:[Ue.map(s=>{var ze,Qe;const M=s.breakdown,de=Ge.get(s.employeeId)??[],fe=s.amountCents+de.reduce((Te,st)=>Te+st.amountCents,0);return e.jsxs("div",{className:`flex justify-between items-center px-3 py-2 text-sm ${(U==null?void 0:U.employeeId)===s.employeeId?"bg-amber-50/80 dark:bg-amber-950/20":""}`,children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:s.employeeName}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[s.positionName,((ze=M==null?void 0:M.employee)==null?void 0:ze.hours)!=null&&e.jsxs(e.Fragment,{children:[" · ",M.employee.hours,"h"]}),(M==null?void 0:M.method)==="HOURS_X_POINTS"&&((Qe=M==null?void 0:M.employee)==null?void 0:Qe.points)!=null&&e.jsxs(e.Fragment,{children:[" · ",M.employee.points,"pt"]}),(M==null?void 0:M.carveOutCents)>0&&e.jsxs(e.Fragment,{children:[" ","· ",c.format(M.carveOutCents/100)," ",t("adjustments.fixedTag")]}),(M==null?void 0:M.manuallyIncluded)&&e.jsxs(e.Fragment,{children:[" · ",t("adjustments.includedTag")]})]}),de.map(Te=>e.jsx("div",{className:"text-xs text-primary font-medium",children:t("daily.alsoFromPool",{amount:c.format(Te.amountCents/100),pool:Te.poolName})},Te.poolName))]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"font-semibold",children:c.format(s.amountCents/100)}),de.length>0&&e.jsx("div",{className:"text-xs font-semibold",children:t("daily.dayAcrossPools",{amount:c.format(fe/100)})})]})]},s.employeeId)}),$e>0&&e.jsxs("div",{className:"px-3 py-2 text-sm text-amber-700 bg-amber-50 dark:bg-amber-950/30 dark:text-amber-400 space-y-2",children:[e.jsxs("div",{className:"flex justify-between items-center gap-2",children:[e.jsx("span",{children:t("adjustments.unallocatedLabel")}),e.jsx("span",{className:"font-semibold shrink-0",children:c.format($e/100)})]}),x&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs("select",{value:j,onChange:s=>P(s.target.value),className:"flex-1 min-w-[10rem] px-2 py-1.5 border rounded-md bg-background text-sm text-foreground",children:[e.jsx("option",{value:"",children:t("adjustments.selectEmployee")}),Ze.map(s=>e.jsxs("option",{value:s.id,children:[s.firstName," ",s.lastName,s.position?` (${s.position})`:""]},s.id))]}),e.jsx("button",{onClick:()=>J.mutate({employeeId:j,amountCents:$e}
1),disabled:!j||J.isPending,className:"px-3 py-1.5 text-sm bg-primary text-primary-foreground rounded-md hover:bg-primary/90 disabled:opacity-50",children:t("adjustments.payLeftover")})]})]})]})]})]}),e.jsxs("div",{className:"p-4 border-t flex flex-wrap justify-between gap-2 shrink-0",children:[e.jsx("div",{children:r&&x&&e.jsx("button",{onClick:()=>{confirm(t("entry.confirmDelete"))&&l.mutate()},disabled:Ee,className:"px-3 py-2 text-sm border border-destructive text-destructive rounded-md hover:bg-destructive/10 disabled:opacity-50",children:t("entry.delete")})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:N,className:"px-4 py-2 text-sm border rounded-md hover:bg-accent",children:t("entry.cancel")}),x&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>Ne.mutate(!1),disabled:Ee,className:"px-4 py-2 text-sm border rounded-md hover:bg-accent disabled:opacity-50",children:t("entry.save")}),r&&!Y&&!D?e.jsx("button",{onClick:()=>T.mutate(),disabled:Ee||C===0,className:"px-4 py-2 text-sm bg-primary text-primary-foreground rounded-md hover:bg-primary/90 disabled:opacity-50",children:t("entry.distribute")}):e.jsx("button",{onClick:()=>Ne.mutate(!0),disabled:Ee||C===0,className:"px-4 py-2 text-sm bg-primary text-primary-foreground rounded-md hover:bg-primary/90 disabled:opacity-50",children:t("entry.saveDistribute")})]})]})]}),e.jsx("div",{role:"separator","aria-label":t("entry.resize"),onPointerDown:et,onPointerMove:tt,onPointerUp:Re,onPointerCancel:Re,className:"absolute bottom-0 right-0 w-5 h-5 cursor-nwse-resize touch-none",children:e.jsx("svg",{viewBox:"0 0 16 16",className:"w-4 h-4 text-muted-foreground absolute bottom-1 right-1","aria-hidden":!0,children:e.jsx("path",{d:"M15 8 L8 15 M15 12 L12 15",stroke:"currentColor",strokeWidth:"1.5",fill:"none"})})})]})})}function ft(n){var q,ye;const{t}=be("tips"),{days:a,today:f,initialDate:r,entries:p,money:x,locale:c,onClose:h,onSaved:N,setError:m}=n,$=a.filter(b=>b<=f),[H,W]=u.useState(r&&$.includes(r)?r:$.length>0?$[$.length-1]:f),G=(b,o)=>p.filter(y=>y.businessDate===b).reduce((y,d)=>y+d[o],0),[w,A]=u.useState(()=>pe(G(H,"cashCents"))),[B,ee]=u.useState(()=>pe(G(H,"cardCents"))),[O,Z]=u.useState(()=>pe(G(H,"otherCents"))),X=b=>{W(b),A(pe(G(b,"cashCents"))),ee(pe(G(b,"cardCents"))),Z(pe(G(b,"otherCents")))},S=_(w)+_(B)+_(O),[j,P]=u.useState(S);u.useEffect(()=>{const b=setTimeout(()=>P(S),350);return()=>clearTimeout(b)},[S]);const{data:C,isFetching:F,error:i}=he({queryKey:["tips-split-preview",H,j,_(w),_(B)],queryFn:()=>K.previewSplit({businessDate:H,cashCents:_(w),cardCents:_(B),otherCents:_(O)}),enabled:j>0,staleTime:30*1e3,retry:!1}),v=(ye=(q=i==null?void 0:i.response)==null?void 0:q.data)==null?void 0:ye.message,D=me({mutationFn:async b=>{const o=await K.splitDayTotal({businessDate:H,cashCents:_(w),cardCents:_(B),otherCents:_(O)});if(b)for(const y of o)await K.distribute(y.id)},onSuccess:()=>{N(),h()},onError:b=>{var o,y;return m(((y=(o=b.response)==null?void 0:o.data)==null?void 0:y.message)||t("entry.saveFailed"))}}),Y=p.filter(b=>b.businessDate===H),ne=me({mutationFn:async()=>{for(const b of Y)await K.deleteEntry(b.id)},onSuccess:()=>{N(),h()},onError:b=>{var o,y;return m(((y=(o=b.response)==null?void 0:o.data)==null?void 0:y.message)||t("entry.saveFailed"))}}),I=D.isPending||ne.isPending;return e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center p-2 sm:p-4 z-50",children:e.jsxs("div",{className:"bg-card border rounded-lg max-w-lg w-full max-h-[92vh] overflow-y-auto",children:[e.jsxs("div",{className:"p-4 border-b",children:[e.jsx("h3",{className:"text-lg font-semibold",children:t("split.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("split.subtitle")})]}),e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:t("split.date")}),e.jsx("select",{value:H,onChange:b=>X(b.target.value),className:"px-3 py-2 border rounded-md bg-background text-sm",children:$.map(b=>e.jsx("option",{value:b,children:Xe(b,c)},b))})]}),e.jsx("div",{className:"grid grid-cols-3 gap-3",children:[["cash",w,A],["card",B,ee],["other",O,Z]].map(([b,o,y])=>e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:t(`entry.${b}`)}),e.jsx("input",{type:"number",min:"0",step:"0.01",inputMode:"decimal",placeholder:"0.00",value:o,onChange:d=>y(d.target.value),className:"w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-primary"})]},b))}),e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:t("entry.total")}),e.jsx("span",{className:"font-semibold",children:x.format(S/100)})]}),v&&e.jsx("p",{className:"text-sm text-destructive",children:v}),j>0&&C&&e.jsx("div",{className:"space-y-3",children:C.pools.map(b=>e.jsxs("div",{className:"border rounded-md",children:[e.jsxs("div",{className:"flex justify-between items-center px-3 py-2 bg-muted/50 text-sm",children:[e.jsxs("span",{className:"font-medium",children:[b.poolName," ",e.jsxs("span",{className:"text-muted-foreground font-normal",children:["· ",b.splitPercent,"%"]})]}),e.jsx("span",{className:"font-semibold",children:x.format(b.totalCents/100)})]}),b.distribution&&b.distribution.shares.length>0?e.jsx("div",{className:"divide-y",children:b.distribution.shares.map(o=>{var d;const y=o.breakdown;return e.jsxs("div",{className:"flex justify-between items-center px-3 py-1.5 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{children:o.employeeName}),e.jsxs("span",{className:"text-xs text-muted-foreground ml-2",children:[o.positionName,((d=y==null?void 0:y.employee)==null?void 0:d.hours)!=null&&e.jsxs(e.Fragment,{children:[" · ",y.employee.hours,"h"]})]})]}
1),e.jsx("span",{className:"font-medium",children:x.format(o.amountCents/100)})]},o.employeeId)})}):e.jsx("p",{className:"px-3 py-2 text-sm text-muted-foreground",children:t("entry.noEligible")})]},b.tipPoolId))}),F&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"…"})]}),e.jsxs("div",{className:"p-4 border-t flex flex-wrap justify-between gap-2",children:[e.jsx("div",{children:Y.length>0&&e.jsx("button",{onClick:()=>{confirm(t("split.confirmClear"))&&ne.mutate()},disabled:I,className:"px-3 py-2 text-sm border border-destructive text-destructive rounded-md hover:bg-destructive/10 disabled:opacity-50",children:ne.isPending?"…":t("split.clear")})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:h,className:"px-4 py-2 text-sm border rounded-md hover:bg-accent",children:t("entry.cancel")}),e.jsx("button",{onClick:()=>D.mutate(!1),disabled:I||S===0||!!v,className:"px-4 py-2 text-sm border rounded-md hover:bg-accent disabled:opacity-50",children:t("entry.save")}),e.jsx("button",{onClick:()=>D.mutate(!0),disabled:I||S===0||!!v,className:"px-4 py-2 text-sm bg-primary text-primary-foreground rounded-md hover:bg-primary/90 disabled:opacity-50",children:t("entry.saveDistribute")})]})]})]})})}function bt(n){const{t}=be("tips"),{days:a,today:f,entries:r,money:p,locale:x,onClose:c,onSaved:h}=n,N=u.useMemo(()=>{const j=new Map;for(const P of r)j.set(P.businessDate,[...j.get(P.businessDate)??[],P]);return j},[r]),m=u.useMemo(()=>{const j=new Map;for(const P of a){const C=N.get(P)??[];j.set(P,{cash:C.reduce((F,i)=>F+i.cashCents,0),card:C.reduce((F,i)=>F+i.cardCents,0),other:C.reduce((F,i)=>F+i.otherCents,0)})}return j},[]),[$,H]=u.useState(()=>new Map(a.map(j=>{const P=m.get(j);return[j,{cash:pe(P.cash),card:pe(P.card),other:pe(P.other)}]}))),[W,G]=u.useState(new Map),[w,A]=u.useState(!1),B=(j,P,C)=>{H(F=>new Map(F).set(j,{...F.get(j),[P]:C}))},ee=a.filter(j=>j<=f),O=j=>{const P=$.get(j),C=_(P.cash),F=_(P.card),i=_(P.other),v=C+F+i,D=m.get(j),Y=C!==D.cash||F!==D.card||i!==D.other;return{cash:C,card:F,other:i,total:v,dirty:Y}},Z=j=>{const P=N.get(j)??[];return P.length===0?null:P.some(C=>C.isStale)?"⟳":P.some(C=>C.status==="OPEN")?"●":"✓"},X=async j=>{var C,F;A(!0);const P=new Map;for(const i of ee){const v=O(i);if(v.total===0)continue;const D=j&&(v.dirty||(N.get(i)??[]).some(Y=>Y.status==="OPEN"||Y.isStale));if(!(!v.dirty&&!D))try{let Y;if(v.dirty?Y=(await K.splitDayTotal({businessDate:i,cashCents:v.cash,cardCents:v.card,otherCents:v.other})).map(I=>I.id):Y=(N.get(i)??[]).map(ne=>ne.id),j)for(const ne of Y)await K.distribute(ne)}catch(Y){P.set(i,((F=(C=Y.response)==null?void 0:C.data)==null?void 0:F.message)||t("entry.saveFailed"))}}A(!1),G(P),h(),P.size===0&&c()},S=ee.some(j=>O(j).total>0);return e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center p-2 sm:p-4 z-50",children:e.jsxs("div",{className:"bg-card border rounded-lg max-w-3xl w-full max-h-[92vh] overflow-y-auto",children:[e.jsxs("div",{className:"p-4 border-b",children:[e.jsx("h3",{className:"text-lg font-semibold",children:t("batch.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("batch.subtitle")})]}),e.jsxs("div",{className:"p-4 overflow-x-auto",children:[e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b text-muted-foreground",children:[e.jsx("th",{className:"text-left py-2 font-medium",children:t("batch.day")}),e.jsx("th",{className:"text-left py-2 font-medium",children:t("entry.cash")}),e.jsx("th",{className:"text-left py-2 font-medium",children:t("entry.card")}),e.jsx("th",{className:"text-left py-2 font-medium",children:t("entry.other")}),e.jsx("th",{className:"text-right py-2 font-medium",children:t("entry.total")}),e.jsx("th",{className:"text-right py-2 font-medium w-8"})]})}),e.jsx("tbody",{children:a.map(j=>{const P=ee.includes(j),C=$.get(j),F=O(j),i=W.get(j);return e.jsxs("tr",{className:`border-b last:border-b-0 ${P?"":"opacity-40"}`,children:[e.jsxs("td",{className:`py-1.5 pr-2 ${j===f?"text-primary font-medium":""}`,children:[e.jsx("span",{className:"whitespace-nowrap",children:ce(j,x)}),i&&e.jsx("div",{className:"text-xs text-destructive whitespace-normal max-w-[180px]",children:i})]}
1),["cash","card","other"].map(v=>e.jsx("td",{className:"py-1.5 pr-2",children:e.jsx("input",{type:"number",min:"0",step:"0.01",inputMode:"decimal",placeholder:"0.00",value:C[v],disabled:!P||w,onChange:D=>B(j,v,D.target.value),className:"w-24 px-2 py-1.5 border rounded-md disabled:opacity-50"})},v)),e.jsx("td",{className:"py-1.5 text-right font-medium whitespace-nowrap",children:F.total>0?p.format(F.total/100):"—"}),e.jsx("td",{className:"py-1.5 text-right",children:Z(j)})]},j)})})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-3",children:t("batch.hint")})]}),e.jsxs("div",{className:"p-4 border-t flex justify-end gap-2",children:[e.jsx("button",{onClick:c,className:"px-4 py-2 text-sm border rounded-md hover:bg-accent",children:t("entry.cancel")}),e.jsx("button",{onClick:()=>X(!1),disabled:w||!S,className:"px-4 py-2 text-sm border rounded-md hover:bg-accent disabled:opacity-50",children:w?"…":t("batch.saveAll")}),e.jsx("button",{onClick:()=>X(!0),disabled:w||!S,className:"px-4 py-2 text-sm bg-primary text-primary-foreground rounded-md hover:bg-primary/90 disabled:opacity-50",children:w?"…":t("batch.saveDistributeAll")})]})]})})}function jt(n){const{t}=be("tips"),{state:a,money:f,isApplying:r,onChange:p,onApply:x}=n;return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",children:e.jsxs("div",{className:"w-full max-w-lg rounded-lg bg-card shadow-lg border",children:[e.jsxs("div",{className:"p-5 border-b",children:[e.jsx("h3",{className:"font-semibold",children:t("payroll.conflictTitle")}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:t("payroll.conflictBody")})]}),e.jsxs("div",{className:"p-5 max-h-[50vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex justify-end gap-3 mb-2 text-xs",children:[e.jsx("button",{className:"underline text-muted-foreground hover:text-foreground",onClick:()=>p(c=>c&&{...c,keep:new Set(c.list.map(h=>h.employeeId))}),children:t("payroll.conflictKeepAll")}),e.jsx("button",{className:"underline text-muted-foreground hover:text-foreground",onClick:()=>p(c=>c&&{...c,keep:new Set}),children:t("payroll.conflictOverwriteAll")})]}),e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-muted-foreground border-b",children:[e.jsx("th",{className:"text-left py-1 font-medium",children:t("payroll.conflictEmployee")}),e.jsx("th",{className:"text-right py-1 font-medium",children:t("payroll.conflictCurrent")}),e.jsx("th",{className:"text-right py-1 font-medium",children:t("payroll.conflictCalculated")}),e.jsx("th",{className:"text-right py-1 font-medium",children:t("payroll.conflictKeepCol")})]})}),e.jsx("tbody",{children:a.list.map(c=>e.jsxs("tr",{className:"border-b last:border-b-0",children:[e.jsx("td",{className:"py-2",children:c.employeeName||c.employeeId}),e.jsx("td",{className:"py-2 text-right",children:f.format((c.adjustmentCents??0)/100)}),e.jsx("td",{className:"py-2 text-right",children:f.format(c.totalCents/100)}),e.jsx("td",{className:"py-2 text-right",children:e.jsx("input",{type:"checkbox","aria-label":t("payroll.conflictKeepCol"),checked:a.keep.has(c.employeeId),onChange:h=>p(N=>{if(!N)return N;const m=new Set(N.keep);return h.target.checked?m.add(c.employeeId):m.delete(c.employeeId),{...N,keep:m}})})})]},c.employeeId))})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-3",children:t("payroll.conflictHint")})]}),e.jsxs("div",{className:"p-4 border-t flex justify-end gap-3",children:[e.jsx("button",{className:"px-4 py-2 text-sm rounded-md border hover:bg-accent",onClick:()=>p(()=>null),children:t("payroll.conflictCancel")}),e.jsx("button",{className:"px-4 py-2 text-sm rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50",disabled:r,onClick:()=>x(Array.from(a.keep)),children:t("payroll.conflictApply")})]})]})})}function Nt(n){const{t}=be("tips"),{pools:a,canManage:f,onAdd:r,onEdit:p,setError:x}=n,{currentOrganizationId:c}=Fe(),h=Oe(),N=me({mutationFn:K.deletePool,onSuccess:()=>{h.invalidateQueries({queryKey:["tip-pools",c]})},onError:m=>{var $,H;return x(((H=($=m.response)==null?void 0:$.data)==null?void 0:H.message)||t("pools.deleteFailed"))}});return e.jsxs("div",{className:"border rounded-lg p-6 bg-card space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-semibold",children:t("pools.heading")}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:t("pools.subheading")})]}),f&&e.jsx("button",{onClick:r,className:"px-3 py-1 text-sm bg-primary text-primary-foreground rounded-md hover:bg-primary/90",children:t("pools.add")})]}),a.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-4",children:t("daily.noPoolsHint")}):e.jsx("div",{className:"space-y-2",children:a.map(m=>e.jsxs("div",{className:"flex flex-wrap justify-between items-center gap-2 p-4 border rounded-md hover:bg-accent/50",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"font-medium",children:[m.name,m.splitPercent!=null&&e.jsxs("span",{className:"ml-2 text-xs px-2 py-0.5 rounded-full bg-primary/10 text-primary",children:[m.splitPercent,"%"]}),!m.isActive&&e.jsx("span",{className:"ml-2 text-xs px-2 py-0.5 rounded-full bg-muted text-muted-foreground",children:t("pools.inactive")})]}),e.jsxs("div",{className:"text-sm text-muted-foreground mt-1",children:[t(`pools.methods.${m.distributionMethod}`)," ·"," ",m.positions.map($=>`${$.name??"?"}${m.distributionMethod==="HOURS_X_POINTS"?` (${$.points})`:""}
1`).join(", ")]})]}),f&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>p(m),className:"px-3 py-1 text-sm border rounded hover:bg-accent",children:t("pools.edit")}),e.jsx("button",{onClick:()=>{confirm(t("pools.confirmDelete",{name:m.name}))&&N.mutate(m.id)},disabled:N.isPending,className:"px-3 py-1 text-sm border border-destructive text-destructive rounded hover:bg-destructive/10 disabled:opacity-50",children:t("pools.delete")})]})]},m.id))})]})}function vt(n){const{t}=be("tips"),{pool:a,onClose:f,onSaved:r,setError:p}=n,{currentOrganizationId:x}=Fe(),c=Oe(),{data:h=[]}=he({queryKey:["positions",x],queryFn:_e.getAll,enabled:!!x}),{data:N}=he({queryKey:["position-suggestions",x],queryFn:_e.getSuggestions,enabled:!!x,staleTime:300*1e3}),m=(N==null?void 0:N.suggestions)??[],$=me({mutationFn:i=>_e.bulkCreate([i]),onSuccess:i=>{c.invalidateQueries({queryKey:["positions",x]}),c.invalidateQueries({queryKey:["position-suggestions",x]}),i[0]&&S(v=>new Map(v).set(i[0].id,1))},onError:i=>{var v,D;return p(((D=(v=i.response)==null?void 0:v.data)==null?void 0:D.message)||t("pools.saveFailed"))}}),H=u.useMemo(()=>h.filter(i=>i.isActive||(a==null?void 0:a.positions.some(v=>v.positionId===i.id))),[h,a]),[W,G]=u.useState((a==null?void 0:a.name)??""),[w,A]=u.useState((a==null?void 0:a.distributionMethod)??"HOURS"),[B,ee]=u.useState((a==null?void 0:a.splitPercent)!=null?String(a.splitPercent):""),[O,Z]=u.useState((a==null?void 0:a.isActive)??!0),[X,S]=u.useState(()=>new Map(((a==null?void 0:a.positions)??[]).map(i=>[i.positionId,i.points]))),j=i=>{S(v=>{const D=new Map(v);return D.has(i)?D.delete(i):D.set(i,1),D})},P=(i,v)=>{S(D=>new Map(D).set(i,v))},C=me({mutationFn:()=>{const i=parseFloat(B),v={name:W,distributionMethod:w,isActive:O,positions:[...X.entries()].map(([D,Y])=>({positionId:D,points:Y})),...a?{splitPercent:isNaN(i)?null:i}:isNaN(i)?{}:{splitPercent:i}};return a?K.updatePool(a.id,v):K.createPool(v)},onSuccess:r,onError:i=>{var v,D;return p(((D=(v=i.response)==null?void 0:v.data)==null?void 0:D.message)||t("pools.saveFailed"))}}),F=W.trim().length>0&&X.size>0;return e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center p-2 sm:p-4 z-50",children:e.jsxs("div",{className:"bg-card border rounded-lg max-w-md w-full max-h-[92vh] overflow-y-auto",children:[e.jsxs("div",{className:"p-4 border-b",children:[e.jsx("h3",{className:"text-lg font-semibold",children:t(a?"pools.editTitle":"pools.addTitle")}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:t("pools.intro")})]}),e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:t("pools.name")}),e.jsx("input",{value:W,onChange:i=>G(i.target.value),placeholder:t("pools.namePlaceholder"),className:"w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-primary"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:t("pools.method")}),e.jsx("select",{value:w,onChange:i=>A(i.target.value),className:"w-full px-3 py-2 border rounded-md bg-background",children:mt.map(i=>e.jsx("option",{value:i,children:t(`pools.methods.${i}`)},i))}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:t(`pools.methodHints.${w}`)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:t("pools.splitPercent")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",min:"0.01",max:"100",step:"0.5",placeholder:"—",value:B,onChange:i=>ee(i.target.value),className:"w-28 px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-primary"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"%"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:t("pools.splitPercentHint")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:t("pools.positions")}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:t("pools.positionsHint")}),H.length===0&&m.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:t("pools.noPositions")}):H.length===0?null:e.jsx("div",{className:"border rounded-md divide-y max-h-56 overflow-y-auto",children:H.map(i=>{const v=X.has(i.id);return e.jsxs("div",{className:"flex items-center justify-between px-3 py-2",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:v,onChange:()=>j(i.id)}),i.name]}),w==="HOURS_X_POINTS"&&v&&e.jsx("input",{type:"number",min:"0.01",step:"0.5",value:X.get(i.id),onChange:D=>P(i.id,parseFloat(D.target.value)||1),className:"w-20 px-2 py-1 border rounded-md text-sm text-right",title:t("pools.points")})]},i.id)})}),w==="HOURS_X_POINTS"&&X.size>0&&e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:t("pools.pointsHint")}),m.length>0&&e.jsxs("div",{className:"mt-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:t("pools.suggested")}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:m.map(i=>e.jsxs("button",{type:"button",onClick:()=>$.mutate(i),disabled:$.isPending,className:"px-2.5 py-1 text-xs border rounded-full hover:bg-accent disabled:opacity-50",children:["+ ",i]},i))})]})]}),a&&e.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:O,onChange:i=>Z(i.target.checked)}),t("pools.active")]})]}),e.jsxs("div",{className:"p-4 border-t flex justify-end gap-2",children:[e.jsx("button",{onClick:f,className:"px-4 py-2 text-sm border rounded-md hover:bg-accent",children:t("pools.cancel")}),e.jsx("button",{onClick:()=>C.mutate(),disabled:!F||C.isPending,className:"px-4 py-2 text-sm bg-primary text-primary-foreground rounded-md hover:bg-primary/90 disabled:opacity-50",children:t("pools.save")})]})]})})}export{Rt 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.