PageSourceSearch

https://ducktipsbr.com/assets/js/TeamManagement-D22xeNBv.js

js ducktipsbr.com collected 2026-09-24 14:43:38 UTC 157,936 bytes, 1 lines download raw bytes

1import{r as s,j as e,R as ot,d as it}from"./vendor-react-DmWheyfZ.js";import{c as Aa,l as ue,L as ce,T as da,F as _r,a7 as Ra,ab as Ma,a4 as z,$ as nt,E as dt,p as ur,q as br,u as Cr,a2 as ct,a$ as mt,t as A,ax as He,R as xt,aq as pt,K as De,H as Sa,ay as Da,w as Mr,f as Sr,m as ut,g as bt,b0 as vt,ag as ht,s as yt,X as La,h as ft,D as gt,a5 as jt,x as za}from"./index-DRXyCgM7.js";import{A as Nt,U as kt}from"./user-minus-BkLv6lfZ.js";import{T as Dr}from"./trending-down-CTBuqQ-S.js";import{W as ca,M as wt}from"./wallet-cards-N0XldOLG.js";import{T as zr}from"./target--KbjjZ8j.js";import{B as $a}from"./building-2-Xl-FPLnN.js";import{L as Ba}from"./landmark-Cf4Fv_ir.js";import{H as Ta}from"./history-DjFZFsb5.js";import{C as _t}from"./calendar-days-ChRnBsbR.js";import{T as Ct}from"./TutorialAvailableButton-BbGsFuvd.js";import{p as _a}from"./financialSummary-wHMm0XJs.js";import{g as vr,s as Mt}from"./personalFinancialGoals-5pF-716k.js";import{P as St}from"./pie-chart-5CjfsN7M.js";import{F as hr}from"./filter-CBYR-oXO.js";import{M as Dt,G as zt}from"./mail-plus-D_-Be0k9.js";import{P as Ea}from"./plus-5F7IGrVf.js";import{T as yr}from"./trophy-DOVLJ3NZ.js";import{S as fr}from"./sparkles-BXs2zbtH.js";import{P as Et}from"./pencil-DpHUPasE.js";import"./vendor-security-2FREwzWT.js";import"./vendor-supabase-BNI3IFP-.js";import"./lightbulb-BijGDW5h.js";import"./balanceManager-X9CvMpWD.js";const Pt=Aa("Goal",[["path",{d:"M12 13V2l8 4-8 4",key:"5wlwwj"}],["path",{d:"M20.561 10.222a9 9 0 1 1-12.55-5.29",key:"1c0wjv"}],["path",{d:"M8.002 9.997a5 5 0 1 0 8.9 2.02",key:"gb1g7m"}]]);const Oa=Aa("ReceiptText",[["path",{d:"M4 2v20l2-1 2 1 2-1 2 1 2-1 2 1 2-1 2 1V2l-2 1-2-1-2 1-2-1-2 1-2-1-2 1Z",key:"q3az6g"}],["path",{d:"M14 8H8",key:"1l3xfs"}],["path",{d:"M16 12H8",key:"1fr5h0"}],["path",{d:"M13 16H8",key:"wsln4y"}]]);const Ft=Aa("UserRoundCog",[["path",{d:"M2 21a8 8 0 0 1 10.434-7.62",key:"1yezr2"}],["circle",{cx:"10",cy:"8",r:"5",key:"o932ke"}],["circle",{cx:"18",cy:"18",r:"3",key:"1xkwt0"}],["path",{d:"m19.5 14.3-.4.9",key:"1eb35c"}],["path",{d:"m16.9 20.8-.4.9",key:"dfjc4z"}],["path",{d:"m21.7 19.5-.9-.4",key:"q4dx6b"}],["path",{d:"m15.2 16.9-.9-.4",key:"1r0w5f"}],["path",{d:"m21.7 16.5-.9.4",key:"1knoei"}],["path",{d:"m15.2 19.1-.9.4",key:"j188fs"}],["path",{d:"m19.5 21.7-.4-.9",key:"1tonu5"}],["path",{d:"m16.9 15.2-.4-.9",key:"699xu"}]]),he=new Intl.NumberFormat("pt-BR",{style:"currency",currency:"BRL",maximumFractionDigits:2}),Pe=new Intl.NumberFormat("pt-BR",{style:"currency",currency:"BRL",notation:"compact",maximumFractionDigits:1}),Ca=new Intl.NumberFormat("pt-BR"),At=["Jan","Fev","Mar","Abr","Mai","Jun","Jul","Ago","Set","Out","Nov","Dez"],gr={owner:"Proprietário",manager:"Gestor",operator:"Operador",viewer:"Visualizador"};function ia(c){return`${c.getFullYear()}-${String(c.getMonth()+1).padStart(2,"0")}-${String(c.getDate()).padStart(2,"0")}`}function Rt(c){const l=new Date;if(c==="30d"){const h=new Date(l);return h.setDate(h.getDate()-29),{start:ia(h),end:ia(l)}}return c==="year"?{start:`${l.getFullYear()}-01-01`,end:ia(l)}:{start:`${l.getFullYear()}-${String(l.getMonth()+1).padStart(2,"0")}-01`,end:ia(l)}}function Fe({label:c,value:l,sub:h,tone:t="neutral",icon:n}){const p=t==="good"?"#22d3a6":t==="bad"?"#fb7185":"var(--text-primary)";return e.jsxs("div",{className:"rounded-2xl border p-4",style:{background:"var(--bg-surface)",borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("div",{className:"text-[10px] font-black uppercase tracking-wider",style:{color:"var(--text-muted)"},children:c}),e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-lg",style:{background:"var(--primary-muted)",color:"var(--primary)"},children:n})]}),e.jsx("div",{className:"mt-2 text-xl font-black",style:{color:p},children:l}),e.jsx("div",{className:"mt-1 text-[10px]",style:{color:"var(--text-muted)"},children:h})]})}function Lt({workspaceId:c,workspaceName:l,member:h,viewerRole:t,onBack:n,onOpenBet:p}){const[v,x]=s.useState("month"),[R,r]=s.useState(!0),[C,M]=s.useState(null),[y,i]=s.useState(null),[u,X]=s.useState(null);s.useEffect(()=>{let d=!1;return(async()=>{r(!0),M(null);try{const F=Rt(v),[B,H]=await Promise.all([z.getManagerOperatorView(c,h.user_id,F.start,F.end),z.getFinancialDetails(c,h.user_id
1)]);d||(i(B),X(H))}catch(F){d||M(F?.message||"Não foi possível abrir o Modo Gestor.")}finally{d||r(!1)}})(),()=>{d=!0}},[c,h.user_id,v]);const w=s.useMemo(()=>Math.max(1,...(y?.monthly||[]).map(d=>Math.abs(Number(d.net_profit||0)))),[y?.monthly]),L=s.useMemo(()=>{const d=y?.goal;if(!d||!y)return null;const _=d.goal_type==="bets"?y.summary.bet_count:y.summary.net_profit;return Math.max(0,Math.min(100,Number(_)/Math.max(1,Number(d.target_value||1))*100))},[y]),V=u?.houses.reduce((d,_)=>d+Number(_.balance_brl||0),0)||0,K=u?.banks.reduce((d,_)=>d+Number(_.balance_brl||0),0)||0,N=u?.pending.reduce((d,_)=>d+Number(_.pending_capital_brl||0),0)||0;return e.jsxs("div",{className:"mx-auto w-full max-w-[1500px] space-y-4",children:[e.jsx("div",{className:"rounded-2xl border px-4 py-3",style:{background:"var(--primary-muted)",borderColor:"var(--primary-border)"},children:e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl",style:{background:"var(--bg-surface)",color:"var(--primary)"},children:e.jsx(Ft,{size:19})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"rounded-full border px-2 py-1 text-[9px] font-black uppercase tracking-wider",style:{borderColor:"var(--primary-border)",color:"var(--primary)"},children:"Modo Gestor"}),e.jsxs("span",{className:"text-[10px]",style:{color:"var(--text-muted)"},children:["Somente visualização — sua sessão continua sendo ",gr[t]]})]}),e.jsx("div",{className:"mt-2 text-lg font-black",style:{color:"var(--text-primary)"},children:h.email}),e.jsxs("div",{className:"text-[10px]",style:{color:"var(--text-muted)"},children:[gr[h.role]," em ",l]})]})]}),e.jsxs("button",{onClick:n,className:"inline-flex items-center justify-center gap-2 rounded-xl border px-4 py-2.5 text-xs font-black",style:{borderColor:"var(--border-subtle)",background:"var(--bg-surface)",color:"var(--text-primary)"},children:[e.jsx(Nt,{size:14})," Voltar para Minha Equipe"]})]})}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ue,{size:18,style:{color:"var(--primary)"}}),e.jsx("h2",{className:"text-xl font-black",style:{color:"var(--text-primary)"},children:"Dashboard do operador"})]}),e.jsx("div",{className:"mt-1 text-xs",style:{color:"var(--text-muted)"},children:"Espelho operacional dos dados deste membro dentro da equipe."})]}),e.jsx("div",{className:"flex rounded-xl border p-1",style:{background:"var(--bg-elevated)",borderColor:"var(--border-subtle)"},children:[["month","Este mês"],["30d","30 dias"],["year","Ano"]].map(([d,_])=>e.jsx("button",{onClick:()=>x(d),className:"rounded-lg px-3 py-2 text-[10px] font-black",style:{background:v===d?"var(--primary)":"transparent",color:v===d?"var(--primary-foreground)":"var(--text-muted)"},children:_},d))})]}),R&&e.jsx("div",{className:"flex min-h-[360px] items-center justify-center",children:e.jsx(ce,{className:"animate-spin",style:{color:"var(--primary)"}})}),!R&&C&&e.jsx("div",{className:"rounded-2xl border border-red-400/20 bg-red-400/10 p-5 text-sm text-red-200",children:C}),!R&&!C&&y&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2.5 sm:grid-cols-3 xl:grid-cols-6",children:[e.jsx(Fe,{label:"Lucro líquido",value:Pe.format(y.summary.net_profit),sub:"Após gastos e ajustes",tone:y.summary.net_profit>=0?"good":"bad",icon:e.jsx(da,{size:15})}),e.jsx(Fe,{label:"Lucro bruto",value:Pe.format(y.summary.gross_profit),sub:"Antes dos gastos",icon:e.jsx(_r,{size:15})}),e.jsx(Fe,{label:"Gastos",value:Pe.format(y.summary.expenses),sub:"No período",tone:"bad",icon:e.jsx(Dr,{size:15})}),e.jsx(Fe,{label:"Apostas",value:Ca.format(y.summary.bet_count),sub:"Operações encerradas",icon:e.jsx(Ra,{size:15})}),e.jsx(Fe,{label:"Banca atual",value:Pe.format(y.financial.current_bankroll),sub:"Casas + bancos + pendentes",tone:y.financial.current_bankroll>=0?"good":"bad",icon:e.jsx(ca,{size:15})}),e.jsx(Fe,{label:"Ajustes",value:Pe.format(y.summary.adjustments),sub:"Ajustes manuais",icon:e.jsx(Oa,{size:15})})]}),y.goal&&e.jsxs("div",{className:"rounded-2xl border p-4",style:{background:"var(--bg-surface)",borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{className:"flex items-end justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-black uppercase tracking-widest",style:{color:"var(--text-muted)"},children:[e.jsx(zr,{size:12})," Meta individual"]}),e.jsxs("div",{className:"mt-1 text-lg font-black",style:{color:"var(--text-primary)"},children:[y.goal.goal_type==="bets"?Ca.format(y.summary.bet_count):he.format(y.summary.net_profit),e.jsxs("span",{className:"ml-2 text-xs font-medium",style:{color:"var(--text-muted)"},children:["de ",y.goal.goal_type==="bets"?Ca.format(y.goal.target_value):he.format(y.goal.target_value)]})]})]}),e.jsxs("div",{className:"text-sm font-black",style:{color:"var(--primary)"},children:[(L||0).toFixed(1),"%"]})]}),e.jsx("div",{className:"mt-3 h-2 overflow-hidden rounded-full bg-white/5",children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${L||0}%`,background:"var(--primary)"}})})]}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[1.15fr_.85fr]",children:[e.jsxs("div",{className:"rounded-2xl border",style:{background:"var(--bg-surface)",borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{className:"border-b px-4 py-3",style:{borderColor:"var(--border-subtle)"},children:[e.jsx("div",{className:"text-sm font-black",style:{color:"var(--text-primary)"},children:"Onde está o dinheiro"}),e.jsx("div",{className:"text-[10px]",style:{color:"var(--text-muted)"},children:"Composição real da banca deste operador."})]}),e.jsxs("div",{className:"grid gap-3 p-4 lg:grid-cols-3",children:[e.jsxs("div",{className:"rounded-xl border p-3",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-black",style:{color:"var(--text-primary)"},children:[e.jsx($a,{size:13,style:{color:"var(--primary)"}})," Casas"]}),e.jsx("div",{className:"text-xs font-black",style:{color:"var(--primary)"},children:he.format(V)})]}),e.jsxs("div",{className:"mt-3 max-h-56 space-y-2 overflow-y-auto pr-1",children:[(u?.houses||[]).map(d=>e.jsxs("div",{className:"rounded-lg border px-2.5 py-2",style:{borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"truncate text-[10px] font-bold",style:{color:"var(--text-primary)"},children:d.casa}),e.jsx("span",{className:"shrink-0 text-[10px] font-black",style:{color:d.resolved?"var(--text-primary)":"#fbbf24"},children:d.resolved?he.format(Number(d.balance_brl||0)):"Sem conversão"})]}),d.dono_da_conta&&e.jsxs("div",{className:"mt-0.5 truncate text-[9px]",style:{color:"var(--text-muted)"},children:["Conta: ",d.dono_da_conta]})]},d.id)),!u?.houses.length&&e.jsx("div",{className:"py-4 text-center text-[10px]",style:{color:"var(--text-muted)"},children:"Nenhuma casa."})]})]}),e.jsxs("div",{className:"rounded-xl border p-3",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-black",style:{color:"var(--text-primary)"},children:[e.jsx(Ba,{size:13,style:{color:"var(--primary)"}})," Bancos"]}),e.jsx("div",{className:"text-xs font-black",style:{color:"var(--primary)"},children:he.format(K)})]}),e.jsxs("div",{className:"mt-3 max-h-56 space-y-2 overflow-y-auto pr-1",children:[(u?.banks||[]).map(d=>e.jsxs("div",{className:"rounded-lg border px-2.5 py-2",style:{borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"truncate text-[10px] font-bold",style:{color:"var(--text-primary)"},children:d.name}),e.jsx("span",{className:"shrink-0 text-[10px] font-black",style:{color:d.resolved?"var(--text-primary)":"#fbbf24"},children:d.resolved?he.format(Number(d.balance_brl||0)):"Sem conversão"})]}),e.jsx("div",{className:"mt-0.5 text-[9px]",style:{color:"var(--text-muted)"},children:d.currency_code||"BRL"})]},d.id)),!u?.banks.length&&e.jsx("div",{className:"py-4 text-center text-[10px]",style:{color:"var(--text-muted)"},children:"Nenhum banco."})]})]}),e.jsxs("div",{className:"rounded-xl border p-3",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-black",style:{color:"var(--text-primary)"},children:[e.jsx(Ta,{size:13,style:{color:"var(--primary)"}})," Pendente"]}),e.jsx("div",{className:"text-xs font-black",style:{color:"var(--primary)"},children:he.format(N)})]}),e.jsxs("div",{className:"mt-3 max-h-56 space-y-2 overflow-y-auto pr-1",children:[(u?.pen
1ding||[]).map(d=>e.jsxs("button",{onClick:()=>p(d.id),className:"w-full rounded-lg border px-2.5 py-2 text-left transition hover:bg-white/[0.035]",style:{borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"truncate text-[10px] font-bold",style:{color:"var(--text-primary)"},children:d.event_name}),e.jsx("span",{className:"shrink-0 text-[10px] font-black",style:{color:"var(--primary)"},children:he.format(Number(d.pending_capital_brl||0))})]}),e.jsx("div",{className:"mt-0.5 text-[9px]",style:{color:"var(--text-muted)"},children:"Abrir bilhete completo"})]},d.id)),!u?.pending.length&&e.jsx("div",{className:"py-4 text-center text-[10px]",style:{color:"var(--text-muted)"},children:"Nenhum capital pendente."})]})]})]}),y.financial.unresolved_values>0&&e.jsxs("div",{className:"border-t px-4 py-3 text-[10px] text-amber-300",style:{borderColor:"var(--border-subtle)"},children:[y.financial.unresolved_values," valor(es) sem conversão persistida não foram inventados no total."]})]}),e.jsxs("div",{className:"rounded-2xl border",style:{background:"var(--bg-surface)",borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{className:"border-b px-4 py-3",style:{borderColor:"var(--border-subtle)"},children:[e.jsx("div",{className:"text-sm font-black",style:{color:"var(--text-primary)"},children:"Evolução mensal"}),e.jsxs("div",{className:"text-[10px]",style:{color:"var(--text-muted)"},children:["Resultado líquido do operador em ",new Date().getFullYear(),"."]})]}),e.jsx("div",{className:"grid grid-cols-4 gap-2 p-4 sm:grid-cols-6 xl:grid-cols-4",children:(y.monthly||[]).map(d=>{const _=Math.max(5,Math.round(Math.abs(d.net_profit)/w*54));return e.jsxs("div",{className:"rounded-xl border p-2",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[e.jsx("div",{className:"text-[9px] font-bold",style:{color:"var(--text-muted)"},children:At[Math.max(0,d.month-1)]}),e.jsx("div",{className:"mt-2 flex h-14 items-end",children:e.jsx("div",{className:"w-full rounded-md",style:{height:`${_}px`,background:d.net_profit>=0?"#22d3a6":"#fb7185",opacity:.78}})}),e.jsx("div",{className:"mt-1 truncate text-[9px] font-black",style:{color:d.net_profit>=0?"#22d3a6":"#fb7185"},children:Pe.format(d.net_profit)})]},d.month)})})]})]}),e.jsxs("div",{className:"rounded-2xl border overflow-hidden",style:{background:"var(--bg-surface)",borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-4 py-3",style:{borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-black",style:{color:"var(--text-primary)"},children:"Últimas apostas"}),e.jsx("div",{className:"text-[10px]",style:{color:"var(--text-muted)"},children:"Abra qualquer registro para auditar o bilhete completo."})]}),e.jsx(Ma,{size:16,style:{color:"var(--primary)"}})]}),e.jsxs("div",{className:"max-h-[520px] overflow-y-auto overscroll-contain",children:[(y.recent_history||[]).map(d=>e.jsxs("button",{onClick:()=>p(d.id),className:"grid w-full grid-cols-[minmax(0,1fr)_auto] items-center gap-3 border-b px-4 py-3 text-left transition last:border-b-0 hover:bg-white/[0.035] sm:grid-cols-[minmax(0,1fr)_120px_110px_100px]",style:{borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-xs font-bold",style:{color:"var(--text-primary)"},children:d.event_name}),e.jsxs("div",{className:"mt-0.5 text-[9px]",style:{color:"var(--text-muted)"},children:[d.bet_type||"Aposta"," · ",d.operation_date?new Date(`${d.operation_date}T12:00:00`).toLocaleDateString("pt-BR"):"Sem data"]})]}),e.jsxs("div",{className:"hidden text-right sm:block",children:[e.jsx("div",{className:"text-[9px]",style:{color:"var(--text-muted)"},children:"Investimento"}),e.jsx("div",{className:"text-[10px] font-bold",style:{color:"var(--text-primary)"},children:he.format(Number(d.total_amount||0))})]}),e.jsxs("div",{className:"hidden text-right sm:block",children:[e.jsx("div",{className:"text-[9px]",style:{color:"var(--text-muted)"},children:"Resultado"}),e.jsx("div",{className:"text-[10px] font-black",style:{color:Number(d.actual_profit||0)>=0?"#22d3a6":"#fb7185"},children:d.actual_profit==null?"Pendente":he.format(Number(d.actual_profit))})]}),e.jsx("div",{className:"text-right text-[10px] font-black",style:{color:"var(--primary)"},children:"Ver bilhete"})]},d.id)),!y.recent_history.length&&e.jsx("div",{className:"p-8 text-center text-xs",style:{color:"var(--text-muted)"},children:"Nenhuma aposta registrada para este operador."})]})]}),e.jsxs("div",{className:"flex items-start gap-2 rounded-xl border px-3 py-2.5 text-[10px]",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)",color:"var(--text-muted)"},children:[e.jsx(Ma,{size:13,className:"mt-0.5 shrink-0",style:{color:"var(--primary)"}}
1),e.jsxs("span",{children:["O Modo Gestor é um espelho somente de leitura. Ele não troca o login, não altera ",e.jsx("code",{children:"auth.uid()"})," e qualquer ação administrativa continua registrada como feita pelo Owner/Gestor — nunca como se fosse o operador."]})]})]})]})}const jr=["Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro"],$t=["Jan","Fev","Mar","Abr","Mai","Jun","Jul","Ago","Set","Out","Nov","Dez"],Bt=["DOM","SEG","TER","QUA","QUI","SEX","SÁB"],Se=new Intl.NumberFormat("pt-BR",{style:"currency",currency:"BRL"}),Tt=new Intl.NumberFormat("pt-BR",{notation:"compact",maximumFractionDigits:1});function Ot({workspaceId:c,operatorUserId:l,operatorLabel:h}){const{privacy:t}=nt(),n=new Date,[p,v]=s.useState(n.getMonth()),[x,R]=s.useState(n.getFullYear()),[r,C]=s.useState("week"),[M,y]=s.useState(Math.max(1,n.getDate()-2)),[i,u]=s.useState(1),[X,w]=s.useState(n.getDate()),[L,V]=s.useState(!0),[K,N]=s.useState([]),[d,_]=s.useState(!0),[F,B]=s.useState(""),H=!t&&L,G=new Date(x,p+1,0).getDate();s.useEffect(()=>{let m=!0;return _(!0),B(""),z.getDailyResults(c,p+1,x,l).then(f=>{m&&N(f)}).catch(f=>{m&&(N([]),B(f?.message||"Não foi possível carregar os resultados diários."))}).finally(()=>{m&&_(!1)}),()=>{m=!1}},[c,l,p,x]),s.useEffect(()=>{const m=x===n.getFullYear()&&p===n.getMonth()?Math.max(1,n.getDate()-2):1;y(Math.min(m,Math.max(1,G-6))),u(1),w(x===n.getFullYear()&&p===n.getMonth()?n.getDate():G)},[p,x,G]);const ze=s.useMemo(()=>new Map(K.map(m=>[Number(m.day.slice(-2)),m])),[K]),T=s.useMemo(()=>Array.from({length:G},(m,f)=>{const W=f+1;return ze.get(W)||{day:`${x}-${String(p+1).padStart(2,"0")}-${String(W).padStart(2,"0")}`,bet_profit:0,adjustments:0,expenses:0,net_profit:0,bet_count:0,manual_count:0,pending_count:0}}),[G,p,ze,x]),re=s.useMemo(()=>r==="month"?T:r==="range"?T.slice(Math.max(0,i-1),Math.min(G,X)):T.slice(M-1,Math.min(G,M+6)),[T,G,X,i,r,M]),Z=s.useMemo(()=>{const m=re.filter(O=>O.bet_count+O.manual_count+O.pending_count>0||O.net_profit!==0||O.expenses!==0),f=re.reduce((O,ke)=>O+ke.net_profit,0),W=re.filter(O=>O.net_profit>0),le=re.reduce((O,ke)=>!O||ke.net_profit>O.net_profit?ke:O,null);let ie=0,Ne=0;return re.forEach(O=>{O.net_profit>0?(ie+=1,Ne=Math.max(Ne,ie)):O.net_profit<0&&(ie=0)}),{total:f,average:m.length?f/m.length:0,best:le,streak:Ne,positiveCount:W.length}},[re]),We=Math.max(1,...re.map(m=>Math.abs(m.bet_profit+m.adjustments))),ye=re.reduce((m,f)=>m+f.bet_count,0),Be=re.reduce((m,f)=>m+f.manual_count,0),me=ye+Be,Te=me?ye/me*100:0,Ye=new Date(x,p,1).getDay(),Ue=m=>{const f=new Date(x,p+m,1);v(f.getMonth()),R(f.getFullYear())};return e.jsxs("section",{className:"overflow-hidden rounded-2xl border",style:{background:"var(--bg-surface)",borderColor:"var(--primary-border)"},children:[e.jsxs("header",{className:"flex flex-col gap-3 border-b px-4 py-3 sm:flex-row sm:items-center sm:justify-between",style:{borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-xl border",style:{background:"var(--primary-muted)",borderColor:"var(--primary-border)",color:"var(--primary)"},children:e.jsx(_t,{size:17})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-black",style:{color:"var(--text-primary)"},children:"Resultados por Dia do Mês"}),e.jsxs("div",{className:"text-[10px]",style:{color:"var(--text-muted)"},children:[jr[p]," ",x," · ",h||"Equipe completa"," · somente leitura"]})]})]}),d&&e.jsx(ce,{size:15,className:"animate-spin",style:{color:"var(--primary)"}})]}),e.jsxs("div",{className:"space-y-3 p-3 sm:p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("select",{value:p,onChange:m=>v(Number(m.target.value)),className:"rounded-lg border px-2 py-1.5 text-[11px] font-bold",style:{background:"var(--bg-elevated)",borderColor:"var(--border-subtle)",color:"var(--text-primary)"},children:$t.map((m,f)=>e.jsx("option",{value:f,children:m},m))}),e.jsx("select",{value:x,onChange:m=>R(Number(m.target.value)),className:"rounded-lg border px-2 py-1.5 text-[11px] font-bold",style:{background:"var(--bg-elevated)",borderColor:"var(--border-subtle)",color:"var(--text-primary)"},children:Array.from({length:5},(m,f)=>n.getFullYear()-f).map(m=>e.jsx("option",{children:m},m))}),e.jsx("div",{className:"flex rounded-lg border p-0.5",style:{background:"var(--bg-elevated)",borderColor:"var(--border-subtle)"},children:["month","week","range"].map(m=>e.jsx("button",{type:"button",onClick:()=>C(m),className:"rounded-md px-2.5 py-1.5 text-[10px] font-black",style:{background:r===m?"var(--primary)":"transparent",color:r===m?"var(--primary-foreground)":"var(--text-muted)"},children:m==="month"?"Mês":m==="week"?"7 dias":"Período"},m))}),r==="range"&&e.jsxs("div",{className:"flex items-center gap-1 rounded-lg border px-1.5 py-1",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[e.jsx("span",{className:"text-[9px]",style:{color:"var(--text-muted)"},children:"Dia"}),e.jsx("select",{value:i,onChange:m=>u(Math.min(Number(m.target.value),X)),className:"bg-transparent text-[10px] font-bold",style:{color:"var(--text-primary)"},children:T.map((m,f)=>e.jsx("option",{value:f+1,children:f+1},f+1))}),e.jsx("span",{className:"text-[9px]",style:{color:"var(--text-muted)"},children:"até"}),e.jsx("select",{value:X,onChange:m=>w(Math.max(Number(m.target.value),i)),className:"bg-transparent text-[10px] font-bold",style:{color:"var(--text-primary)"},children:T.map((m,f)=>e.jsx("option",{value:f+1,children:f+1},f+1))})]}),e.jsxs("button",{type:"button",disabled:t,onClick:()=>{t||V(m=>!m)},className:"ml-auto inline-flex items-center gap-1.5 rounded-lg border px-2.5 py-1.5 text-[10px] font-bold disabled:opacity-60",style:{background:"var(--primary-muted)",borderColor:"var(--primary-border)",color:"var(--primary)"},children:[H?e.jsx(ue,{size:12}):e.jsx(dt,{size:12})," ",H?"Valores visíveis":"Valores ocultos"]})]}),F&&e.jsxs("div",{className:"rounded-xl border border-amber-400/20 bg-amber-400/10 px-3 py-2 text-[10px] text-amber-200",children:[F," Publique a migration ",e.jsx("code",{children:"20260810_workspace_daily_results.sql"})," no Supabase."]}),e.jsx("div",{className:"grid grid-cols-2 gap-2 lg:grid-cols-4",children:[["Lucro líquido",Se.format(Z.total),Z.total],["Média diária",Se.format(Z.average),Z.average],["Melhor dia",Z.best?Se.format(Z.best.net_profit):Se.format(0),Z.best?.net_profit||0],["Sequência",`${Z.streak} dia${Z.streak===1?"":"s"}`,Z.streak]].map(([m,f,W])=>e.jsxs("div",{className:"rounded-xl border p-3",style:{background:"var(--bg-elevated)",borderColor:Number(W)>=0?"rgba(34,211,166,.25)":"rgba(251,113,133,.25)"},children:[e.jsx("div",{className:"text-[8px] font-black uppercase tracking-wider",style:{color:"var(--text-muted)"},children:m}),e.jsx("div",{"data-sensitive":"hard",className:"mt-1 text-sm font-black",style:{color:Number(W)>=0?"#22d3a6":"#fb7185"},children:H?f:"•••••"})]},String(m)))}),e.jsxs("div",{className:"grid gap-3 xl:grid-cols-[minmax(0,1fr)_290px]",children:[e.jsxs("div",{className:"min-w-0 rounded-2xl border p-3","data-sensitive-chart":"",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[r==="week"&&e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("button",{type:"button",disabled:M<=1,onClick:()=>y(Math.max(1,M-7)),className:"rounded-lg border p-1.5 disabled:opacity-30",style:{borderColor:"var(--primary-border)",color:"var(--primary)"},children:e.jsx(ur,{size:14})}),e.jsxs("span",{className:"rounded-lg px-4 py-1.5 text-[10px] font-black",style:{background:"var(--primary-muted)",color:"var(--text-muted)"},children:["Dias ",M,"–",Math.min(G,M+6)]}),e.jsx("button",{type:"button",disabled:M+7>G,onClick:()=>y(Math.min(G-6,M+7)),className:"rounded-lg border p-1.5 disabled:opacity-30",style:{borderColor:"var(--primary-border)",color:"var(--primary)"},children:e.jsx(br,{size:14})})]}),e.jsx("div",{className:"w-full overflow-x-auto overscroll-x-contain",children:e.jsx("div",{className:"flex h-64 min-w-[420px] items-end gap-2 border-b px-2 pb-0",style:{borderColor:"var(--border-subtle)"},children:re.map(m=>{const f=Number(m.day.slice(-2)),W=m.bet_profit+m.adjustments,le=Math.max(W===0?2:8,Math.abs(W)/We*78),ie=H?`${m.day}: operações ${Se.format(W)}; gastos ${Se.format(m.expenses)}; líquido ${Se.format(m.net_profit)}`:`${m.day}
1: valores ocultos`;return e.jsxs("div",{className:"flex h-full min-w-[42px] flex-1 flex-col items-center justify-end",children:[e.jsx("div",{className:"mb-1 h-8 text-center text-[9px] font-black",style:{color:W>=0?"#22d3a6":"#fb7185"},children:H&&W!==0?Tt.format(W):""}),e.jsx("div",{className:"w-full max-w-16 rounded-t-lg",title:ie,style:{height:`${le}%`,background:W<0?"linear-gradient(180deg,#fb7185,#9f1239)":"linear-gradient(180deg,#22d3a6,#059669)",opacity:W===0?.18:1}}),e.jsx("div",{className:"mt-2 text-[9px] font-black",style:{color:"var(--text-primary)"},children:f}),e.jsx("div",{className:"mb-1 text-[8px]",style:{color:"var(--text-muted)"},children:new Date(x,p,f).toLocaleDateString("pt-BR",{weekday:"short"}).replace(".","")})]},m.day)})})}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-3 text-[9px]",style:{color:"var(--text-muted)"},children:[e.jsxs("span",{children:[e.jsx("i",{className:"mr-1 inline-block h-2 w-2 rounded-sm bg-emerald-400"}),"Resultado das operações"]}),e.jsxs("span",{children:[e.jsx("i",{className:"mr-1 inline-block h-0.5 w-3 bg-sky-400"}),"Líquido inclui gastos"]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"rounded-2xl border p-3",style:{borderColor:"var(--primary-border)",background:"var(--bg-elevated)"},children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx("button",{type:"button",onClick:()=>Ue(-1),className:"rounded-lg border p-1",style:{borderColor:"var(--border-subtle)",color:"var(--text-muted)"},children:e.jsx(ur,{size:13})}),e.jsxs("div",{className:"text-[11px] font-black",style:{color:"var(--text-primary)"},children:[jr[p]," ",x]}),e.jsx("button",{type:"button",onClick:()=>Ue(1),className:"rounded-lg border p-1",style:{borderColor:"var(--border-subtle)",color:"var(--text-muted)"},children:e.jsx(br,{size:13})})]}),e.jsxs("div",{className:"grid grid-cols-7 gap-1",children:[Bt.map(m=>e.jsx("div",{className:"py-1 text-center text-[7px] font-black",style:{color:"var(--text-muted)"},children:m},m)),Array.from({length:Ye},(m,f)=>e.jsx("span",{},`blank-${f}`)),T.map(m=>{const f=Number(m.day.slice(-2)),W=m.bet_count+m.manual_count>0,le=r==="week"&&f>=M&&f<=M+6||r==="range"&&f>=i&&f<=X;return e.jsx("button",{type:"button",onClick:()=>{C("week"),y(Math.min(Math.max(1,f-2),Math.max(1,G-6)))},className:"aspect-square rounded-lg border text-[9px] font-black",style:{background:le?"var(--primary-muted)":W?m.net_profit>=0?"rgba(34,211,166,.12)":"rgba(251,113,133,.12)":"transparent",borderColor:le?"var(--primary)":W?m.net_profit>=0?"rgba(34,211,166,.25)":"rgba(251,113,133,.25)":"var(--border-subtle)",color:le?"var(--primary)":W?m.net_profit>=0?"#22d3a6":"#fb7185":"var(--text-muted)"},children:f},m.day)})]})]}),e.jsxs("div",{className:"rounded-2xl border p-3","data-sensitive-chart":"",style:{borderColor:"var(--primary-border)",background:"var(--bg-elevated)"},children:[e.jsx("div",{className:"text-[8px] font-black uppercase tracking-wider",style:{color:"var(--primary)"},children:"Origem dos registros"}),e.jsxs("div",{className:"mt-3 flex items-center gap-3",children:[e.jsx("div",{className:"relative h-16 w-16 shrink-0 rounded-full",style:{background:`conic-gradient(#4ade80 0 ${Te}%,#60a5fa ${Te}% 100%)`},children:e.jsx("div",{className:"absolute inset-2 flex items-center justify-center rounded-full text-[10px] font-black",style:{background:"var(--bg-elevated)",color:"var(--text-primary)"},children:H?`${Math.round(Te)}%`:"•••"})}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-2 text-[9px]",children:[e.jsxs("div",{className:"flex justify-between gap-2",children:[e.jsx("span",{style:{color:"var(--text-muted)"},children:"Apostas"}),e.jsx("b",{style:{color:"#4ade80"},children:H?ye:"••"})]}),e.jsxs("div",{className:"flex justify-between gap-2",children:[e.jsx("span",{style:{color:"var(--text-muted)"},children:"Manuais"}),e.jsx("b",{style:{color:"#60a5fa"},children:H?Be:"••"})]}),e.jsxs("div",{className:"flex justify-between gap-2",children:[e.jsx("span",{style:{color:"var(--text-muted)"},children:"Positivos"}),e.jsx("b",{style:{color:"var(--text-primary)"},children:H?Z.positiveCount:"••"})]})]})]})]})]})]})]})]})}const $e={owner:"Proprietário",manager:"Gestor",operator:"Operador",viewer:"Visualizador"},Nr={pending:"Pendente",accepted:"Aceito",cancelled:"Cancelado",expired:"Expirado",declined:"Recusado"},qt=[{id:"overview",label:"Visão geral",icon:e.jsx(_r,{size:15})},{id:"members",label:"Operadores",icon:e.jsx(He,{size:15})},{id:"goals",label:"Metas",icon:e.jsx(zr,{size:15})},{id:"history",label:"Histórico",icon:e.jsx(Ra,{size:15})},{id:"finance",label:"Financeiro",icon:e.jsx(gt,{size:15})},{id:"analytics",label:"Análises",icon:e.jsx(da,{size:15})},{id:"activity",label:"Atividades",icon:e.jsx(Sa,{size:15})},{id:"plan",label:"Plano",icon:e.jsx(ca,{size:15})}],b=new Intl.NumberFormat("pt-BR",{style:"currency",currency:"BRL",maximumFractionDigits:2}),I=new Intl.NumberFormat("pt-BR",{style:"currency",currency:"BRL",notation:"compact",maximumFractionDigits:1}),q=new Intl.NumberFormat("pt-BR"),na=new Intl.DateTimeFormat("pt-BR",{dateStyle:"short",timeStyle:"short"});function It(){const c=new Date,l=new Date(c.getFullYear(),c.getMonth(),1),h=new Date(c.getFullYear(),c.getMonth()+1,0),t=n=>`${n.getFullYear()}
1-${String(n.getMonth()+1).padStart(2,"0")}-${String(n.getDate()).padStart(2,"0")}`;return{start:t(l),end:t(h)}}function j(c){return c==="owner"||c==="manager"}function Gt(c){return c==="owner"}function Pa(c){const l=Number(c||0);return l>0?l.toLocaleString("pt-BR",{minimumFractionDigits:2,maximumFractionDigits:2}):""}function kr(c={}){return za.reduce((l,h)=>(l[h.key]=Pa(c[h.key]),l),{})}function Ae(c){return{workspace_created:"Equipe criada",workspace_activated:"Workspace selecionado",subscription_activated:"Plano Equipe ativado",subscription_renewed:"Plano Equipe renovado",seats_upgraded:"Assentos adicionados",renewal_seats_changed:"Assentos da próxima renovação alterados",member_invited:"Operador convidado",invite_accepted:"Convite aceito",personal_data_migrated:"Dados pessoais migrados para a equipe",member_role_changed:"Permissão alterada",member_removed:"Membro removido",goal_saved:"Meta criada/alterada",goal_deleted:"Meta removida",surebets_insert:"Aposta registrada",surebets_update:"Aposta atualizada",surebets_delete:"Aposta removida",expense_management_insert:"Gasto registrado",expense_management_update:"Gasto atualizado",expense_management_delete:"Gasto removido",house_balances_insert:"Casa adicionada",house_balances_update:"Saldo de casa atualizado",house_balances_delete:"Casa removida",external_banks_insert:"Banco adicionado",external_banks_update:"Saldo de banco atualizado",external_banks_delete:"Banco removido",daily_manual_adjustments_insert:"Ajuste manual registrado",daily_manual_adjustments_update:"Ajuste manual atualizado",daily_manual_adjustments_delete:"Ajuste manual removido",punter_bets_insert:"Aposta Punter registrada",punter_bets_update:"Aposta Punter atualizada",punter_bets_delete:"Aposta Punter removida"}[c]||c.replace(/_/g," ")}function E({children:c,className:l=""}){return e.jsx("section",{className:`rounded-2xl border ${l}`,style:{background:"var(--bg-surface)",borderColor:"var(--primary-border)"},children:c})}function Re({label:c,value:l,sub:h,icon:t,tone:n="default",onClick:p}){const v=n==="good"?"#22d3a6":n==="bad"?"#fb7185":"var(--text-primary)",x=e.jsxs("div",{className:"flex items-start justify-between gap-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[10px] font-black uppercase tracking-[0.12em]",style:{color:"var(--text-muted)"},children:c}),e.jsx("div",{className:"mt-1.5 truncate text-base font-black leading-none sm:mt-2 sm:text-lg xl:text-xl",style:{color:v},children:l}),h&&e.jsx("div",{className:"mt-1 text-[9px] leading-4 sm:text-[10px]",style:{color:"var(--text-muted)",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},children:h}),p&&e.jsxs("div",{className:"mt-1.5 inline-flex items-center gap-1 text-[9px] font-bold leading-none",style:{color:"var(--primary)"},children:[e.jsx(ue,{size:10})," Ver composição"]})]}),e.jsx("div",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-lg sm:h-8 sm:w-8",style:{background:"var(--primary-muted)",color:"var(--primary)"},children:t})]});return p?e.jsx("button",{type:"button",onClick:p,className:"min-w-0 rounded-2xl text-left transition hover:-translate-y-0.5 hover:brightness-110 focus:outline-none focus:ring-2",style:{"--tw-ring-color":"var(--primary)"},children:e.jsx(E,{className:"h-full p-3 sm:p-3.5",children:x})}):e.jsx(E,{className:"min-w-0 p-3 sm:p-3.5",children:x})}function we({label:c,data:l}){const h=Number(l?.realized_profit||0),t=Number(l?.projected_profit||0),n=Number(l?.pen
1ding_profit||0),p=Number(l?.expenses||0),v=h>=0?"#22d3a6":"#fb7185",x=t>=0?"#22d3a6":"#fb7185";return e.jsxs(E,{className:"min-w-0 p-3 sm:p-3.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-[10px] font-black uppercase tracking-[0.12em]",style:{color:"var(--text-muted)"},children:c}),e.jsxs("div",{className:"rounded-md px-2 py-1 text-[8px] font-black uppercase",style:{background:"var(--primary-muted)",color:"var(--primary)"},children:[Number(l?.pending_bets||0)," pend."]})]}),e.jsxs("div",{className:"mt-2.5 grid grid-cols-2 gap-2.5 sm:mt-3 sm:gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[9px] font-bold uppercase tracking-wide",style:{color:"var(--text-muted)"},children:"Realizado"}),e.jsx("div",{className:"mt-1 truncate text-[15px] font-black leading-none sm:text-lg",title:b.format(h),style:{color:v},children:I.format(h)})]}),e.jsxs("div",{className:"min-w-0 border-l pl-3",style:{borderColor:"var(--border-subtle)"},children:[e.jsx("div",{className:"text-[9px] font-bold uppercase tracking-wide",style:{color:"var(--text-muted)"},children:"Previsto"}),e.jsx("div",{className:"mt-1 truncate text-[15px] font-black leading-none sm:text-lg",title:b.format(t),style:{color:x},children:I.format(t)})]})]}),e.jsxs("div",{className:"mt-2.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[9px] sm:mt-3",style:{color:"var(--text-muted)"},children:[e.jsxs("span",{children:[Number(l?.completed_bets||0)," concluídas"]}),e.jsxs("span",{children:["Pendente: ",e.jsx("strong",{style:{color:n>=0?"var(--primary)":"#fb7185"},children:b.format(n)})]}),p>0&&e.jsxs("span",{children:["Gastos: ",e.jsx("strong",{className:"text-red-300",children:b.format(p)})]})]})]})}function Le({label:c,value:l,tone:h="default"}){const n={default:{background:"var(--bg-elevated)",color:"var(--text-primary)"},good:{background:"rgba(34,211,166,.12)",color:"#22d3a6"},bad:{background:"rgba(251,113,133,.12)",color:"#fb7185"},warning:{background:"rgba(251,191,36,.12)",color:"#fbbf24"}}[h];return e.jsxs("div",{className:"inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 text-[10px] font-bold",style:{background:n.background,color:n.color},children:[e.jsx("span",{style:{color:"var(--text-muted)"},children:c}),e.jsx("span",{style:{color:n.color},children:l})]})}function de({label:c,value:l,sub:h,tone:t="default"}){const n=t==="good"?"#22d3a6":t==="bad"?"#fb7185":t==="warning"?"#fbbf24":"var(--text-primary)";return e.jsxs("div",{className:"rounded-xl border p-3",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[e.jsx("div",{className:"text-[9px] font-black uppercase tracking-[0.14em]",style:{color:"var(--text-muted)"},children:c}),e.jsx("div",{className:"mt-1.5 truncate text-lg font-black leading-none",style:{color:n},children:l}),h&&e.jsx("div",{className:"mt-1 text-[10px] leading-4",style:{color:"var(--text-muted)"},children:h})]})}function Vt({title:c,owner:l,targetLabel:h,currentLabel:t,progress:n,period:p,onEdit:v,onDelete:x}){return e.jsx(E,{className:"group overflow-hidden",children:e.jsxs("div",{className:"p-4",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-[10px] font-black uppercase tracking-[0.14em]",style:{color:"var(--primary)"},children:l}),e.jsx("div",{className:"mt-1 text-sm font-black",style:{color:"var(--text-primary)"},children:c})]}),(v||x)&&e.jsxs("div",{className:"flex items-center gap-1 opacity-100 sm:opacity-0 sm:transition sm:group-hover:opacity-100",children:[v&&e.jsx("button",{onClick:v,className:"rounded-lg p-1.5",style:{color:"var(--text-muted)"},children:e.jsx(Et,{size:13})}),x&&e.jsx("button",{onClick:x,className:"rounded-lg p-1.5 text-red-300",children:e.jsx(Sr,{size:13})})]})]}),e.jsxs("div",{className:"mt-4 flex items-end justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px]",style:{color:"var(--text-muted)"},children:"Meta"}),e.jsx("div",{className:"mt-1 text-2xl font-black leading-none",style:{color:"var(--primary)"},children:h})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"text-[10px]",style:{color:"var(--text-muted)"},children:"Atual"}),e.jsx("div",{className:"mt-1 text-sm font-black",style:{color:"var(--text-primary)"},children:t})]})]}),e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 text-[10px]",children:[e.jsx("span",{style:{color:"var(--text-muted)"},children:"Progresso"}),e.jsxs("span",{className:"font-black",style:{color:"var(--text-primary)"},children:[n.toFixed(0),"%"]})]}),e.jsx("div",{className:"mt-2 h-2 overflow-hidden rounded-full bg-white/5",children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${n}%`,background:"linear-gradient(90deg, var(--primary), rgba(110,211,255,.78))"}})}),e.jsx("div",{className:"mt-4 text-[10px]",style:{color:"var(--text-muted)"},children:p})]})})}function Ht(c){if(Array.isArray(c))return c;if(typeof c=="string")try{const l=JSON.parse(c);return Array.isArray(l)?l:[]}catch{return[]}return[]}function Fa(c,l="BRL"){try{return new Intl.NumberFormat("pt-BR",{style:"currency",currency:l||"BRL",maximumFractionDigits:2}).format(Number(c||0))}
1catch{return`${Number(c||0).toLocaleString("pt-BR",{maximumFractionDigits:2})} ${l||""}`.trim()}}function Wt({open:c,onClose:l,loading:h,data:t,section:n,onSectionChange:p,operatorEmail:v}){if(!c)return null;const x=(t?.houses||[]).reduce((i,u)=>i+Number(u.balance_brl||0),0),R=(t?.banks||[]).reduce((i,u)=>i+Number(u.balance_brl||0),0),r=(t?.pending||[]).reduce((i,u)=>i+Number(u.pending_capital_brl||0),0),C=(t?.expenses||[]).reduce((i,u)=>i+Math.abs(Number(u.amount_brl||0)),0),M=[{id:"all",label:"Tudo"},{id:"houses",label:"Casas",count:t?.houses?.length||0},{id:"banks",label:"Bancos",count:t?.banks?.length||0},{id:"pending",label:"Pendentes",count:t?.pending?.length||0},{id:"expenses",label:"Gastos",count:t?.expenses?.length||0}],y=i=>n==="all"||n===i;return e.jsx("div",{className:"fixed inset-0 z-[1100] flex items-center justify-center bg-black/75 p-3 backdrop-blur-sm",onMouseDown:i=>{i.target===i.currentTarget&&l()},children:e.jsxs("div",{className:"flex max-h-[90vh] w-full max-w-6xl flex-col overflow-hidden rounded-2xl border shadow-2xl",style:{background:"var(--bg-surface)",borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 border-b px-4 py-4 sm:px-5",style:{borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 text-base font-black",style:{color:"var(--text-primary)"},children:[e.jsx(ca,{size:18,style:{color:"var(--primary)"}})," Composição financeira"]}),e.jsxs("div",{className:"mt-1 text-[11px]",style:{color:"var(--text-muted)"},children:[v?`Responsável: ${v}`:"Todos os responsáveis da equipe"," · valores detalhados por origem"]})]}),e.jsx("button",{onClick:l,className:"rounded-lg border p-2",style:{borderColor:"var(--border-subtle)",color:"var(--text-muted)"},children:e.jsx(La,{size:16})})]}),e.jsxs("div",{className:"border-b px-4 py-3 sm:px-5",style:{borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-4",children:[e.jsxs("div",{className:"rounded-xl border p-3",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[e.jsx("div",{className:"text-[9px] font-black uppercase",style:{color:"var(--text-muted)"},children:"Casas"}),e.jsx("div",{className:"mt-1 text-sm font-black",style:{color:"var(--text-primary)"},children:b.format(x)})]}),e.jsxs("div",{className:"rounded-xl border p-3",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[e.jsx("div",{className:"text-[9px] font-black uppercase",style:{color:"var(--text-muted)"},children:"Bancos"}),e.jsx("div",{className:"mt-1 text-sm font-black",style:{color:"var(--text-primary)"},children:b.format(R)})]}),e.jsxs("div",{className:"rounded-xl border p-3",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[e.jsx("div",{className:"text-[9px] font-black uppercase",style:{color:"var(--text-muted)"},children:"Pendente"}),e.jsx("div",{className:"mt-1 text-sm font-black",style:{color:"var(--text-primary)"},children:b.format(r)})]}),e.jsxs("div",{className:"rounded-xl border p-3",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[e.jsx("div",{className:"text-[9px] font-black uppercase",style:{color:"var(--text-muted)"},children:"Gastos do mês"}),e.jsx("div",{className:"mt-1 text-sm font-black text-red-300",children:b.format(C)})]})]}),e.jsx("div",{className:"mt-3 flex gap-1.5 overflow-x-auto",children:M.map(i=>e.jsxs("button",{onClick:()=>p(i.id),className:"shrink-0 rounded-lg border px-3 py-1.5 text-[10px] font-bold",style:{borderColor:n===i.id?"var(--primary)":"var(--border-subtle)",background:n===i.id?"var(--primary-muted)":"var(--bg-elevated)",color:n===i.id?"var(--primary)":"var(--text-muted)"},children:[i.label,i.count!=null?` · ${i.count}`:""]},i.id))})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-4 sm:p-5",children:[h&&e.jsx("div",{className:"flex min-h-56 items-center justify-center",children:e.jsx(ce,{size:24,className:"animate-spin",style:{color:"var(--primary)"}})}),!h&&t&&e.jsxs("div",{className:"space-y-5",children:[y("houses")&&e.jsxs("section",{children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2 text-sm font-black",style:{color:"var(--text-primary)"},children:[e.jsx($a,{size:15,style:{color:"var(--primary)"}})," Casas de apostas"]}),e.jsx("div",{className:"overflow-hidden rounded-xl border",style:{borderColor:"var(--border-subtle)"},children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[760px] text-left",children:[e.jsx("thead",{children:e.jsx("tr",{className:"text-[9px] uppercase tracking-wider",style:{color:"var(--text-muted)"},children:["Casa","Dono da conta","Operador","Saldo original","Convert
1ido BRL"].map(i=>e.jsx("th",{className:"px-3 py-2.5 font-black",children:i},i))})}),e.jsxs("tbody",{children:[(t.houses||[]).map(i=>e.jsxs("tr",{className:"border-t text-[11px]",style:{borderColor:"var(--border-subtle)"},children:[e.jsx("td",{className:"px-3 py-2.5 font-bold",style:{color:"var(--text-primary)"},children:i.casa}),e.jsx("td",{className:"px-3 py-2.5",style:{color:"var(--text-muted)"},children:i.dono_da_conta||"—"}),e.jsx("td",{className:"px-3 py-2.5",style:{color:"var(--text-muted)"},children:i.operator_email}),e.jsx("td",{className:"px-3 py-2.5",style:{color:"var(--text-primary)"},children:Fa(i.montante,i.currency_code)}),e.jsx("td",{className:"px-3 py-2.5 font-black",style:{color:i.resolved?"var(--primary)":"#fbbf24"},children:i.balance_brl==null?"Sem conversão":b.format(i.balance_brl)})]},i.id)),!t.houses.length&&e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"p-6 text-center text-xs",style:{color:"var(--text-muted)"},children:"Nenhuma casa encontrada."})})]})]})})})]}),y("banks")&&e.jsxs("section",{children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2 text-sm font-black",style:{color:"var(--text-primary)"},children:[e.jsx(Ba,{size:15,style:{color:"var(--primary)"}})," Bancos e carteiras"]}),e.jsx("div",{className:"overflow-hidden rounded-xl border",style:{borderColor:"var(--border-subtle)"},children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[680px] text-left",children:[e.jsx("thead",{children:e.jsx("tr",{className:"text-[9px] uppercase tracking-wider",style:{color:"var(--text-muted)"}
1,children:["Banco","Operador","Saldo original","Convertido BRL"].map(i=>e.jsx("th",{className:"px-3 py-2.5 font-black",children:i},i))})}),e.jsxs("tbody",{children:[(t.banks||[]).map(i=>e.jsxs("tr",{className:"border-t text-[11px]",style:{borderColor:"var(--border-subtle)"},children:[e.jsx("td",{className:"px-3 py-2.5 font-bold",style:{color:"var(--text-primary)"},children:i.name}),e.jsx("td",{className:"px-3 py-2.5",style:{color:"var(--text-muted)"},children:i.operator_email}),e.jsx("td",{className:"px-3 py-2.5",style:{color:"var(--text-primary)"},children:Fa(i.balance,i.currency_code)}),e.jsx("td",{className:"px-3 py-2.5 font-black",style:{color:i.resolved?"var(--primary)":"#fbbf24"},children:i.balance_brl==null?"Sem conversão":b.format(i.balance_brl)})]},i.id)),!t.banks.length&&e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"p-6 text-center text-xs",style:{color:"var(--text-muted)"},children:"Nenhum banco encontrado."})})]})]})})})]}),y("pending")&&e.jsxs("section",{children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2 text-sm font-black",style:{color:"var(--text-primary)"},children:[e.jsx(Ta,{size:15,style:{color:"var(--primary)"}})," Capital pendente"]}),e.jsxs("div",{className:"overflow-hidden rounded-xl border",style:{borderColor:"var(--border-subtle)"}
1,children:[(t.pending||[]).map(i=>e.jsxs("div",{className:"flex flex-col gap-1 border-b px-3 py-3 last:border-b-0 sm:flex-row sm:items-center sm:justify-between",style:{borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-xs font-bold",style:{color:"var(--text-primary)"},children:i.event_name}),e.jsxs("div",{className:"mt-0.5 text-[9px]",style:{color:"var(--text-muted)"},children:[i.operator_email," · ",i.operation_date?new Date(i.operation_date).toLocaleDateString("pt-BR"):new Date(i.created_at).toLocaleDateString("pt-BR")]})]}),e.jsx("div",{className:"text-xs font-black",style:{color:i.pending_capital_brl==null?"#fbbf24":"var(--primary)"},children:i.pending_capital_brl==null?"Sem conversão":b.format(i.pending_capital_brl)})]},i.id)),!t.pending.length&&e.jsx("div",{className:"p-6 text-center text-xs",style:{color:"var(--text-muted)"},children:"Nenhum capital pendente."})]})]}),y("expenses")&&e.jsxs("section",{children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2 text-sm font-black",style:{color:"var(--text-primary)"},children:[e.jsx(Oa,{size:15,style:{color:"var(--primary)"}})," Gastos do mês"]}),e.jsxs("div",{className:"overflow-hidden rounded-xl border",style:{borderColor:"var(--border-subtle)"},children:[(t.expenses||[]).map(i=>e.jsxs("div",{className:"flex items-center gap-3 border-b px-3 py-3 last:border-b-0",style:{borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-xs font-bold",style:{color:"var(--text-primary)"},children:i.supplier||i.category||"Gasto"}),e.jsxs("div",{className:"mt-0.5 text-[9px]",style:{color:"var(--text-muted)"},children:[new Date(i.expense_date).toLocaleDateString("pt-BR")," · ",i.operator_email,i.source_type?` · origem ${i.source_type}`:""]})]}),e.jsxs("div",{className:"shrink-0 text-xs font-black text-red-300",children:["− ",b.format(Math.abs(i.amount_brl))]})]},i.id)),!t.expenses.length&&e.jsx("div",{className:"p-6 text-center text-xs",style:{color:"var(--text-muted)"},children:"Nenhum gasto no período."})]})]})]})]})]})})}function wr({open:c,onClose:l,loading:h,bet:t}){if(!c)return null;const n=Ht(t?.bets_data),p=n.length?n:t?[t.bookmaker_a?{bookmaker:t.bookmaker_a,bookmaker_owner:t.bookmaker_a_owner,market:t.market,odd:t.odd_a,investment:t.bet_a_amount,currency_code:t.currency_code||"BRL"}:null,t.bookmaker_b?{bookmaker:t.bookmaker_b,bookmaker_owner:t.bookmaker_b_owner,market:t.market,odd:t.odd_b,investment:t.bet_b_amount,currency_code:t.currency_code||"BRL"}:null].filter(Boolean):[],v=async()=>{if(t?.id)try{await navigator.clipboard.writeText(t.id),A.success("ID da aposta copiado.")}catch{}};return e.jsx("div",{className:"fixed inset-0 z-[1110] flex items-center justify-center bg-black/80 p-3 backdrop-blur-sm",onMouseDown:x=>{x.target===x.currentTarget&&l()},children:e.jsxs("div",{className:"flex max-h-[92vh] w-full max-w-4xl flex-col overflow-hidden rounded-2xl border shadow-2xl",style:{background:"var(--bg-surface)",borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 border-b px-4 py-4 sm:px-5",style:{borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-black",style:{color:"var(--text-primary)"},children:[e.jsx(Ra,{size:17,style:{color:"var(--primary)"}})," Bilhete completo"]}),e.jsx("div",{className:"mt-1 truncate text-[10px]",style:{color:"var(--text-muted)"},children:t?.operator_email||"Carregando responsável..."})]}),e.jsx("button",{onClick:l,className:"rounded-lg border p-2",style:{borderColor:"var(--border-subtle)",color:"var(--text-muted)"},children:e.jsx(La,{size:16})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-4 sm:p-5",children:[h&&e.jsx("div",{className:"flex min-h-64 items-center justify-center",children:e.jsx(ce,{className:"animate-spin",size:24,style:{color:"var(--primary)"}})}),!h&&t&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("section",{children:[e.jsx("div",{className:"text-[10px] font-black uppercase tracking-wider",style:{color:"var(--text-muted)"},children:"Evento"}),e.jsxs("div",{className:"mt-1 text-xl font-black",style:{color:"var(--text-primary)"},children:[t.sport_emoji?`${t.sport_emoji} `:"",t.event_name]}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-2 text-[10px]",style:{color:"var(--text-muted)"},children:[t.bet_type&&e.jsx("span",{className:"rounded-lg border px-2 py-1",style:{borderColor:"var(--border-subtle)"},children:t.bet_type}),t.strategy_name&&e.jsxs("span",{className:"rounded-lg border px-2 py-1",style:{borderColor:"var(--border-subtle)"},children:[t.strategy_emoji," ",t.strategy_name]}),t.promotion_name&&e.jsxs("span",{className:"rounded-lg border px-2 py-1",style:{borderColor:"var(--border-subtle)"},children:[t.promotion_emoji," ",t.promotion_name]}),t.status&&e.jsxs("span",{className:"rounded-lg border px-2 py-1",style:{borderColor:"var(--border-subtle)"},children:["Status: ",t.status]}),t.result_type&&e.jsxs("span",{className:"rounded-lg border px-2 py-1",style:{borderColor:"var(--border-subtle)"},children:["Resultado: ",t.result_type]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-4",children:[e.jsxs("div",{className:"rounded-xl border p-3",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[e.jsx("div",{className:"text-[9px] uppercase",style:{color:"var(--text-muted)"},children:"Investimento"}),e.jsx("div",{className:"mt-1 text-sm font-black",style:{color:"var(--text-primary)"},children:b.format(Number(t.total_amount||0))})]}),e.jsxs("div",{className:"rounded-xl border p-3",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[e.jsx("div",{className:"text-[9px] uppercase",style:{color:"var(--text-muted)"},children:"Lucro projetado"}),e.jsx("div",{className:"mt-1 text-sm font-black",style:{color:"var(--primary)"},children:b.format(Number(t.profit_amount||0))})]}),e.jsxs("div",{className:"rounded-xl border p-3",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[e.jsx("div",{className:"text-[9px] uppercase",style:{color:"var(--text-muted)"},children:"Resultado real"}),e.jsx("div",{className:"mt-1 text-sm font-black",style:{color:Number(t.actual_profit||0)>=0?"#22d3a6":"#fb7185"},children:t.actual_profit==null?"Pendente":b.format(Number(t.actual_profit))})]}),e.jsxs("div",{className:"rounded-xl border p-3",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[e.jsx("div",{className:"text-[9px] uppercase",style:{color:"var(--text-muted)"},children:"ROI projetado"}),e.jsxs("div",{className:"mt-1 text-sm font-black",style:{color:"var(--text-primary)"}
1,children:[Number(t.profit_percentage||0).toLocaleString("pt-BR",{maximumFractionDigits:2}),"%"]})]})]}),e.jsxs("section",{children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx("div",{className:"text-sm font-black",style:{color:"var(--text-primary)"},children:"Linhas do bilhete"}),e.jsxs("div",{className:"text-[10px]",style:{color:"var(--text-muted)"},children:[p.length," ",p.length===1?"linha":"linhas"]})]}),e.jsxs("div",{className:"space-y-2",children:[p.map((x,R)=>{const r=x.original_currency_code||x.currency_code||t.currency_code||"BRL",C=Number(x.original_investment??x.investment??0),M=Number(x.return_brl??x.return??0);return e.jsxs("div",{className:"rounded-xl border p-3",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"text-xs font-black",style:{color:"var(--text-primary)"},children:[R+1,". ",x.bookmaker||`Linha ${R+1}`]}),e.jsx("div",{className:"mt-0.5 text-[9px]",style:{color:"var(--text-muted)"},children:x.bookmaker_owner||x.bookmakerData?.owner?`Conta: ${x.bookmaker_owner||x.bookmakerData?.owner}`:"Conta não informada"})]}),e.jsxs("div",{className:"text-xs font-black",style:{color:"var(--primary)"},children:["Odd ",Number(x.odd||x.net_odd||0).toLocaleString("pt-BR",{minimumFractionDigits:2,maximumFractionDigits:3})]})]}),e.jsxs("div",{className:"mt-3 grid grid-cols-2 gap-2 sm:grid-cols-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[8px] uppercase",style:{color:"var(--text-muted)"},children:"Mercado"}),e.jsx("div",{className:"mt-0.5 text-[10px] font-bold",style:{color:"var(--text-primary)"},children:x.market||t.market||"—"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[8px] uppercase",style:{color:"var(--text-muted)"},children:"Stake"}),e.jsx("div",{className:"mt-0.5 text-[10px] font-bold",style:{color:"var(--text-primary)"},children:Fa(C,r)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[8px] uppercase",style:{color:"var(--text-muted)"},children:"Retorno"}),e.jsx("div",{className:"mt-0.5 text-[10px] font-bold",style:{color:"var(--text-primary)"},children:M?b.format(M):"—"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[8px] uppercase",style:{color:"var(--text-muted)"},children:"Ajustes"}),e.jsx("div",{className:"mt-0.5 text-[10px] font-bold",style:{color:"var(--text-primary)"},children:x.commission?`Comissão ${x.commission}`:x.cashback?`Cashback ${x.cashback}`:x.boost?`Boost ${x.boost}`:"—"})]})]})]},R)}),!p.length&&e.jsx("div",{className:"rounded-xl border p-6 text-center text-xs",style:{borderColor:"var(--border-subtle)",color:"var(--text-muted)"},children:"Este registro antigo não possui linhas persistidas no bilhete."})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("section",{className:"rounded-xl border p-3",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[e.jsx("div",{className:"text-[9px] font-black uppercase",style:{color:"var(--text-muted)"},children:"Datas"}),e.jsxs("div",{className:"mt-2 space-y-1 text-[10px]",style:{color:"var(--text-primary)"},children:[e.jsxs("div",{children:["Operação: ",t.operation_date?new Date(t.operation_date).toLocaleDateString("pt-BR"):"—"]}),e.jsxs("div",{children:["Evento: ",t.event_date?new Date(t.event_date).toLocaleDateString("pt-BR"):"—",t.event_time?` · ${t.event_time}`:""]}),e.jsxs("div",{children:["Criado: ",na.format(new Date(t.created_at))]})]})]}),e.jsxs("section",{className:"rounded-xl border p-3",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[e.jsx("div",{className:"text-[9px] font-black uppercase",style:{color:"var(--text-muted)"},children:"Responsável"}),e.jsx("div",{className:"mt-2 text-[10px] font-bold",style:{color:"var(--text-primary)"},children:t.operator_email}),e.jsxs("button",{onClick:v,className:"mt-2 inline-flex items-center gap-1 text-[9px] font-bold",style:{color:"var(--primary)"},children:[e.jsx(Mr,{size:10})," Copiar ID do registro"]})]})]}),t.notes&&e.jsxs("section",{className:"rounded-xl border p-3",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[e.jsx("div",{className:"text-[9px] font-black uppercase",style:{color:"var(--text-muted)"},children:"Observações"}),e.jsx("div",{className:"mt-2 whitespace-pre-wrap text-xs leading-5",style:{color:"var(--text-primary)"},children:t.notes})]}),!!t.tags?.length&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.tags.map(x=>e.jsxs("span",{className:"rounded-lg border px-2 py-1 text-[9px]",style:{borderColor:"var(--border-subtle)",color:"var(--text-muted)"},children:["#",x]},x))})]})]})]})})}function Yt({onCreated:c}){const[l,h]=s.useState("Minha Equipe"),[t,n]=s.useState(!1),p=async()=>
1{if(l.trim()){n(!0);try{const v=await z.createTeam(l.trim());await z.setActive(v),A.success("Equipe criada. Agora escolha os assentos e ative o plano."),c(v)}catch(v){A.error(v?.message||"Não foi possível criar a equipe.")}finally{n(!1)}}};return e.jsx("div",{className:"mx-auto max-w-4xl py-4 sm:py-10",children:e.jsxs(E,{className:"overflow-hidden",children:[e.jsxs("div",{className:"border-b p-5 sm:p-7",style:{borderColor:"var(--border-subtle)",background:"linear-gradient(135deg,var(--primary-muted),transparent)"},children:[e.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-2xl",style:{background:"var(--primary-muted)",color:"var(--primary)"},children:e.jsx(He,{size:24})}),e.jsx("h2",{className:"mt-4 text-2xl font-black",style:{color:"var(--text-primary)"},children:"Transforme sua DuckTips em uma operação de equipe"}),e.jsx("p",{className:"mt-2 max-w-2xl text-sm leading-6",style:{color:"var(--text-muted)"},children:"Adicione operadores com login próprio, acompanhe resultados consolidados, metas, gastos, histórico e desempenho individual sem compartilhar senha."})]}),e.jsxs("div",{className:"grid gap-5 p-5 sm:grid-cols-[1fr_320px] sm:p-7",children:[e.jsx("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[["Painel consolidado","Lucro, gastos e apostas da equipe"],["Permissões","Owner, gestor, operador e visualizador"],["Metas","Equipe e metas individuais"],["Auditoria","Quem criou, editou e removeu"]].map(([v,x])=>e.jsxs("div",{className:"rounded-xl border p-3",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[e.jsx(De,{size:15,className:"mb-2",style:{color:"var(--primary)"}}),e.jsx("div",{className:"font-bold",style:{color:"var(--text-primary)"},children:v}),e.jsx("div",{className:"mt-1 text-xs",style:{color:"var(--text-muted)"},children:x})]},v))}),e.jsxs("div",{className:"rounded-2xl border p-4",style:{borderColor:"var(--primary-border)",background:"var(--primary-muted)"},children:[e.jsx("div",{className:"text-xs font-black uppercase tracking-widest",style:{color:"var(--primary)"},children:"Criar workspace"}),e.jsx("label",{className:"mt-4 block text-xs font-bold",style:{color:"var(--text-muted)"},children:"Nome da operação"}),e.jsx("input",{value:l,onChange:v=>h(v.target.value),maxLength:80,className:"mt-2 w-full rounded-xl border px-3 py-2.5 text-sm outline-none",style:{background:"var(--bg-surface)",borderColor:"var(--border-subtle)",color:"var(--text-primary)"}}),e.jsxs("button",{onClick:p,disabled:t||!l.trim(),className:"mt-3 inline-flex w-full items-center justify-center gap-2 rounded-xl px-4 py-2.5 text-sm font-black disabled:opacity-50",style:{background:"var(--primary)",color:"var(--primary-foreground)"},children:[t?e.jsx(ce,{size:16,className:"animate-spin"}):e.jsx(Ea,{size:16})," Criar minha equipe"]}),e.jsx("div",{className:"mt-3 text-[10px] leading-4",style:{color:"var(--text-muted)"},children:"O workspace é criado primeiro. O acesso dos operadores só é liberado após a ativação do Plano Equipe."})]})]})]})})}
1function Ut({memberships:c,current:l,onChange:h}){const[t,n]=s.useState(!1);return e.jsxs("div",{className:"relative max-w-full",children:[e.jsxs("button",{type:"button",onClick:()=>n(p=>!p),className:"inline-flex max-w-full items-center gap-2 rounded-xl border px-2.5 py-2 text-left sm:px-3",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[e.jsx("div",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-lg sm:h-8 sm:w-8",style:{background:"var(--primary-muted)",color:"var(--primary)"},children:e.jsx(He,{size:15})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-xs font-black",style:{color:"var(--text-primary)"},children:l.name}),e.jsx("div",{className:"text-[10px]",style:{color:"var(--text-muted)"},children:$e[l.role]})]}),e.jsx(ft,{size:14,style:{color:"var(--text-muted)"}})]}),t&&e.jsx("div",{className:"absolute right-0 top-[calc(100%+6px)] z-40 w-[min(18rem,calc(100vw-1rem))] overflow-hidden rounded-xl border p-1.5 shadow-2xl",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:c.map(p=>e.jsxs("button",{onClick:()=>{n(!1),h(p.workspace_id)},className:"flex w-full items-center justify-between rounded-lg px-3 py-2 text-left hover:bg-white/5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-xs font-bold",style:{color:"var(--text-primary)"},children:p.name}),e.jsxs("div",{className:"text-[10px]",style:{color:"var(--text-muted)"},children:[p.workspace_type==="team"?"Equipe":"Pessoal"," · ",$e[p.role]]})]}),p.workspace_id===l.workspace_id&&e.jsx(De,{size:14,style:{color:"var(--primary)"}})]},p.workspace_id))})]})}function Jt({workspace:c,member:l,currentUserId:h,onChanged:t}){const[n,p]=s.useState(!1),[v,x]=s.useState({top:0,left:0,width:208,maxHeight:320}),R=s.useRef(null),r=s.useRef(null),C=Gt(c.role)&&l.role!=="owner",M=j(c.role)&&l.role!=="owner"&&l.user_id!==h,y=s.useCallback(()=>{const w=R.current;if(!w||typeof window>"u")return;const L=w.getBoundingClientRect(),V=window.innerWidth,K=window.innerHeight,N=8,d=8,F=Math.min(208,Math.max(160,V-d*2)),B=r.current?.offsetHeight||176;let H=L.right-F;H=Math.max(d,Math.min(H,V-F-d));const G=K-L.bottom-d,ze=L.top-d,T=G<B+N&&ze>G;let re=T?L.top-B-N:L.bottom+N;re=Math.max(d,Math.min(re,K-B-d));const Z=T?Math.max(120,L.top-N-d):Math.max(120,K-L.bottom-N-d);x({top:re,left:H,width:F,maxHeight:Math.min(320,Z)})},[]);if(s.useEffect(()=>{if(!n)return;y();const w=window.requestAnimationFrame(y),L=N=>{const d=N.target;d&&(r.current?.contains(d)||R.current?.contains(d)||p(!1))},V=N=>{N.key==="Escape"&&p(!1)},K=()=>y();return document.addEventListener("mousedown",L),document.addEventListener("touchstart",L,{passive:!0}),document.addEventListener("keydown",V),window.addEventListener("resize",K),window.addEventListener("scroll",K,!0),()=>{window.cancelAnimationFrame(w),document.removeEventListener("mousedown",L),document.removeEventListener("touchstart",L),document.removeEventListener("keydown",V),window.removeEventListener("resize",K),window.removeEventListener("scroll",K,!0)}},[n,y]),!C&&!M)return null;const i=async w=>{p(!1);try{await z.updateMemberRole(c.workspace_id,l.user_id,w),A.success("Permissão atualizada."),t()}catch(L){A.error(L?.message||"Erro ao atualizar permissão.")}},u=async()=>{if(p(!1),!!window.confirm(`Remover ${l.email} da equipe? O histórico será preservado.`))try{await z.removeMember(c.workspace_id,l.user_id),A.success("Membro removido. O histórico foi preservado."),t()}catch(w){A.error(w?.message||"Erro ao remover membro.")}},X=n&&typeof document<"u"?it.createPortal(e.jsxs("div",{ref:r,role:"menu","aria-label":`Ações de ${l.email}`,className:"fixed z-[9999] overflow-y-auto overscroll-contain rounded-xl border p-1.5 shadow-2xl",style:{top:v.top,left:v.left,width:v.width,maxHeight:v.maxHeight,background:"var(--bg-elevated)",borderColor:"var(--border-subtle)"},children:[C&&["manager","operator","viewer"].map(w=>e.jsxs("button",{role:"menuitem",onClick:()=>i(w),className:"w-full rounded-lg px-3 py-2 text-left text-xs hover:bg-white/5",style:{color:l.role===w?"var(--primary)":"var(--text-primary)"},children:["Definir como ",$e[w]]},w)),M&&e.jsxs("button",{role:"menuitem",onClick:u,className:"mt-1 flex w-full items-center gap-2 rounded-lg px-3 py-2 text-left text-xs text-red-300 hover:bg-red-500/10",children:[e.jsx(kt,{size:13})," Remover da equipe"]})]}),document.body):null;return e.jsxs(e.Fragment,{children:[e.jsx("button",{ref:R,type:"button","aria-haspopup":"menu","aria-expanded":n,"aria-label":`Abrir ações de ${l.email}`,onClick:()=>{n||y(),p(w=>!w)},className:"rounded-lg border p-2",style:{borderColor:"var(--border-subtle)",color:"var(--text-muted)"},children:e.jsx(wt,{size:15})}),X]})}function Kt({open:c,onClose:l,workspace:h,members:t,editing:n,onSaved:p}){const v=It(),[x,R]=s.useState(n?.operator_user_id||"team"),[r,C]=s.useState(n?.goal_type||"profit"),[M,y]=s.useState(String(n?.target_value||"")),[i,u]=s.useState(n?.period_start?.slice(0,10)||v.start),[X,w]=s.useState(n?.period_end?.slice(0,10)||v.end),[L,V]=s.useState(!1);if(s.useEffect(()=>{c&&(R(n?.operator_user_id||"team"),C(n?.goal_type||"profit"),y(n?.target_value?String(n.target_value):""),u(n?.period_start?.slice(0,10)||v.start),w(n?.period_end?.slice(0,10)||v.end))},[c,n]),!c)return null;const K=async()=>{const N=Number(String(M).replace(",","."));if(!Number.isFinite(N)||N<=0)return A.error("Informe uma meta válida.");V(!0);try{await z.saveGoal({workspaceId:h.workspace_id,goalId:n?.id,operatorUserId:x==="team"?null:x,goalType:r,periodType:"monthly",targetValue:N,periodStart:i,periodEnd:X}),A.success("Meta salva."),p(),l()}catch(d){A.error(d?.message||"Erro ao salvar meta.")}finally{V(!1)}};return e.jsx("div",{className:"fixed inset-0 z-[1000] flex items-center justify-center bg-black/70 p-4 backdrop-blur-sm",onMouseDown:N=>{N.target===N.currentTarget&&l()},children:e.jsxs("div",{className:"w-full max-w-md rounded-2xl border p-5",style:{background:"var(--bg-surface)",borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"font-black",style:{color:"var(--text-primary)"},children:n?"Editar meta":"Nova meta"}),e.jsx("button",{onClick:l,style:{color:"var(--text-muted)"},children:e.jsx(La,{size:18})})]}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsxs("label",{className:"text-xs font-bold",style:{color:"var(--text-muted)"},children:["Aplicar para",e.jsxs("select",{value:x,onChange:N=>R(N.target.value),className:"mt-1.5 w-full rounded-xl border px-3 py-2.5 text-sm",style:{background:"var(--bg-elevated)",borderColor:"var(--border-subtle)",color:"var(--text-primary)"},children:[e.jsx("option",{value:"team",children:"Equipe inteira"}),t.filter(N=>N.status==="active").map(N=>e.jsx("option",{value:N.user_id,children:N.email}
1,N.user_id))]})]}),e.jsxs("label",{className:"text-xs font-bold",style:{color:"var(--text-muted)"},children:["Indicador",e.jsxs("select",{value:r,onChange:N=>C(N.target.value),className:"mt-1.5 w-full rounded-xl border px-3 py-2.5 text-sm",style:{background:"var(--bg-elevated)",borderColor:"var(--border-subtle)",color:"var(--text-primary)"},children:[e.jsx("option",{value:"profit",children:"Lucro líquido"}),e.jsx("option",{value:"bets",children:"Quantidade de apostas"})]})]}),e.jsxs("label",{className:"text-xs font-bold",style:{color:"var(--text-muted)"},children:["Valor da meta",e.jsx("input",{value:M,onChange:N=>y(N.target.value),inputMode:"decimal",placeholder:r==="bets"?"500":"15000",className:"mt-1.5 w-full rounded-xl border px-3 py-2.5 text-sm outline-none",style:{background:"var(--bg-elevated)",borderColor:"var(--border-subtle)",color:"var(--text-primary)"}})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("label",{className:"text-xs font-bold",style:{color:"var(--text-muted)"},children:["Início",e.jsx("input",{type:"date",value:i,onChange:N=>u(N.target.value),className:"mt-1.5 w-full rounded-xl border px-2 py-2 text-xs",style:{background:"var(--bg-elevated)",borderColor:"var(--border-subtle)",color:"var(--text-primary)"}})]}),e.jsxs("label",{className:"text-xs font-bold",style:{color:"var(--text-muted)"},children:["Fim",e.jsx("input",{type:"date",value:X,onChange:N=>w(N.target.value),className:"mt-1.5 w-full rounded-xl border px-2 py-2 text-xs",style:{background:"var(--bg-elevated)",borderColor:"var(--border-subtle)",color:"var(--text-primary)"}})]})]})]}),e.jsxs("button",{onClick:K,disabled:L,className:"mt-5 inline-flex w-full items-center justify-center gap-2 rounded-xl px-4 py-2.5 text-sm font-black disabled:opacity-50",style:{background:"var(--primary)",color:"var(--primary-foreground)"},children:[L&&e.jsx(ce,{size:15,className:"animate-spin"})," Salvar meta"]})]})})}function Xt({workspace:c,value:l,current:h,onSaved:t}){const{user:n}=Cr(),p=c.role==="owner",[v,x]=s.useState(l.dailyEnabled),[R,r]=s.useState(Pa(l.dailyTarget)),[C,M]=s.useState(()=>kr(l.dailyTargetsByWeekday)),[y,i]=s.useState(!1),[u,X]=s.useState(!0),[w,L]=s.useState(!1);s.useEffect(()=>{x(l.dailyEnabled),r(Pa(l.dailyTarget)),M(kr(l.dailyTargetsByWeekday))},[l.goalId,l.updatedAt,l.dailyEnabled,l.dailyTarget,l.dailyTargetsByWeekday]),s.useEffect(()=>{if(!n?.id)return;let _=!1;return vr(n.id).then(F=>{_||X(F.celebrationEnabled)}).catch(()=>{}),()=>{_=!0}},[n?.id]);const V=jt(l,new Date),K=V>0?Math.max(0,Math.min(100,Number(h||0)/V*100)):0,N=async()=>{if(!p)return;const _=_a(R);if(v&&_<=0){A.error("Informe um valor válido para a meta diária padrão da equipe.");return}const F=za.reduce((B,H)=>{const G=_a(C[H.key]);return G>0&&(B[H.key]=G),B},{});i(!0);try{const B=await z.saveTeamDailyFinancialGoals(c.workspace_id,{dailyEnabled:v,dailyTarget:_,dailyTargetsByWeekday:F},l.goalId);t(B),A.success(v?"Metas diárias da equipe atualizadas.":"Meta diária da equipe desativada.")}catch(B){A.error(B?.message||"Não foi possível salvar as metas diárias da equipe.")}finally{i(!1)}},d=async()=>{if(!n?.id||w)return;const _=!u;X(_),L(!0);try{const F=await vr(n.id),B=await Mt({...F,celebrationEnabled:_},n.id);X(B.celebrationEnabled),A.success(B.celebrationEnabled?"Comemoração premium ativada.":"Comemoração premium desativada.")}catch(F){X(!_),A.error(F?.message||"Não foi possível atualizar a preferência do confete.")}finally{L(!1)}};return e.jsxs(E,{className:"overflow-hidden",children:[e.jsxs("div",{className:"flex flex-col gap-3 border-b px-4 py-4 sm:flex-row sm:items-start sm:justify-between",style:{borderColor:"var(--border-subtle)",background:"linear-gradient(135deg,var(--primary-muted),transparent 70%)"},children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl",style:{background:"var(--primary-muted)",color:"var(--primary)",border:"1px solid var(--primary-border)"},children:e.jsx(yr,{size:18})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"text-sm font-black",style:{color:"var(--text-primary)"},children:"Meta diária da equipe"}),e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full px-2 py-1 text-[8px] font-black uppercase tracking-wider",style:{color:"#facc15",background:"rgba(250,204,21,.1)",border:"1px solid rgba(250,204,21,.22)"},children:[e.jsx(fr,{size:9})," Confete premium"]})]}),e.jsx("p",{className:"mt-1 max-w-2xl text-[10px] leading-relaxed",style:{color:"var(--text-muted)"},children:"A meta padrão vale todos os dias. As exceções de Seg a Dom são opcionais e substituem o valor padrão somente naquele dia."})]})]}),p?e.jsx("button",{type:"button",role:"switch","aria-checked":v,onClick:()=>x(_=>!_),className:"relative h-7 w-12 shrink-0 rounded-full border transition",style:{background:v?"var(--primary-muted)":"var(--bg-elevated)",borderColor:v?"var(--primary)":"var(--border-subtle)"},children:e.jsx("span",{className:"absolute top-[4px] h-[18px] w-[18px] rounded-full transition-all",style:{left:v?25:4,background:v?"var(--primary)":"var(--text-muted)"}})}):e.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1.5 rounded-full border px-2.5 py-1.5 text-[9px] font-black",style:{borderColor:"var(--border-subtle)",color:l.dailyEnabled?"#4ade80":"var(--text-muted)",background:"var(--bg-elevated)"},children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{background:l.dailyEnabled?"#4ade80":"var(--text-muted)"}}),l.dailyEnabled?"Ativa":"Desativada"]})]}),e.jsxs("div",{className:"grid gap-4 p-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 rounded-xl border p-3 sm:flex-row sm:items-center sm:justify-between",style:{borderColor:"rgba(250,204,21,.2)",background:"linear-gradient(135deg,rgba(250,204,21,.08),transparent)"},children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-2.5",children:[e.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg",style:{color:"#facc15",background:"rgba(250,204,21,.12)"},children:e.jsx(fr,{size:15})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[10px] font-black",style:{color:"var(--text-primary)"},children:"Comemorar com animação premium"}),e.jsx("div",{className:"mt-0.5 text-[9px] leading-relaxed",style:{color:"var(--text-muted)"},children:"Mensagens e efeitos variados. Afeta somente a sua tela e não altera a meta da equipe."})]})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":u,"aria-label":"Exibir comemoração premium ao atingir a meta da equipe",disabled:w,onClick:()=>void d(),className:"relative h-7 w-12 shrink-0 self-end rounded-full border transition disabled:opacity-50 sm:self-auto",style:{background:u?"var(--primary-muted)":"var(--bg-elevated)",borderColor:u?"var(--primary)":"var(--border-subtle)"},children:e.jsx("span",{className:"absolute top-[4px] h-[18px] w-[18px] rounded-full transition-all",style:{left:u?25:4,background:u?"var(--primary)":"var(--text-muted)"}})})]}),e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(220px,.7fr)_minmax(0,1.3fr)]",children:[e.jsxs("label",{className:"grid gap-1.5 text-[10px] font-black",style:{color:"var(--text-muted)"},children:["Meta diária padrão",e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-xs font-black",style:{color:"var(--text-muted)"},children:"R$"}),e.jsx("input",{value:R,disabled:!p||!v,onChange:_=>r(_.target.value),inputMode:"decimal",placeholder:"500,00",className:"h-10 w-full rounded-xl border pl-9 pr-3 text-sm font-black outline-none disabled:cursor-not-allowed disabled:opacity-60",style:{background:"var(--bg-elevated)",borderColor:"var(--border-subtle)",color:"var(--text-primary)",fontVariantNumeric:"tabular-nums"}})]})]}),e.jsxs("div",{className:"rounded-xl border p-3",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[9px] font-black uppercase tracking-wider",style:{color:"var(--text-muted)"},children:"Progresso de hoje"}),e.jsx("div",{className:"mt-1 text-sm font-black",style:{color:Number(h||0)>=0?"#4ade80":"#fb7185"},children:b.format(Number(h||0))})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"text-[9px] font-black uppercase tracking-wider",style:{color:"var(--text-muted)"},children:"Meta vigente"}),e.jsx("div",{className:"mt-1 text-sm font-black",style:{color:"var(--text-primary)"},children:V>0?b.format(V):"Não definida"})]})]}),e.jsx("div",{className:"mt-3 h-2 overflow-hidden rounded-full",style:{background:"var(--bg-surface)"},children:e.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${K}%`,background:K>
1=100?"linear-gradient(90deg,#16c784,#4ade80)":"linear-gradient(90deg,var(--primary),#60a5fa)"}})})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-black",style:{color:"var(--text-primary)"},children:"Exceções por dia da semana"}),e.jsx("div",{className:"mt-0.5 text-[9px]",style:{color:"var(--text-muted)"},children:"Campo vazio = usa a meta diária padrão."})]}),!p&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[9px] font-bold",style:{color:"var(--text-muted)"},children:[e.jsx(Da,{size:10,style:{color:"#facc15"}})," Definida pelo proprietário"]})]}),e.jsx("div",{className:"mt-3 grid grid-cols-2 gap-2 sm:grid-cols-4 xl:grid-cols-7",children:za.map(_=>{const F=C[_.key],B=_a(R);return e.jsxs("label",{className:"grid min-w-0 gap-1.5 rounded-xl border p-2.5",style:{borderColor:F?"var(--primary-border)":"var(--border-subtle)",background:F?"var(--primary-muted)":"var(--bg-elevated)"},title:_.label,children:[e.jsxs("span",{className:"flex items-center justify-between gap-1 text-[9px] font-black",style:{color:F?"var(--primary)":"var(--text-secondary)"},children:[e.jsx("span",{children:_.shortLabel}),e.jsx("span",{className:"text-[7px]",style:{color:"var(--text-muted)"},children:F?"EXCEÇÃO":"PADRÃO"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"pointer-events-none absolute left-2 top-1/2 -translate-y-1/2 text-[9px] font-black",style:{color:"var(--text-muted)"},children:"R$"}),e.jsx("input",{value:F,disabled:!p||!v,onChange:H=>M(G=>({...G,[_.key]:H.target.value})),inputMode:"decimal","aria-label":`Meta da equipe para ${_.label}`,placeholder:B>0?B.toLocaleString("pt-BR",{minimumFractionDigits:2,maximumFractionDigits:2}):"Padrão",className:"h-8 w-full min-w-0 rounded-lg border pl-7 pr-1.5 text-[10px] font-black outline-none disabled:cursor-not-allowed disabled:opacity-60",style:{background:"var(--bg-surface)",borderColor:"var(--border-subtle)",color:"var(--text-primary)",fontVariantNumeric:"tabular-nums"}})]})]},_.key)})})]}),p&&e.jsx("div",{className:"flex justify-end border-t pt-3",style:{borderColor:"var(--border-subtle)"},children:e.jsxs("button",{type:"button",onClick:()=>void N(),disabled:y,className:"inline-flex w-full items-center justify-center gap-2 rounded-xl px-4 py-2.5 text-xs font-black disabled:opacity-50 sm:w-auto",style:{background:"var(--primary)",color:"var(--primary-foreground)",boxShadow:"var(--shadow-primary)"},children:[y?e.jsx(ce,{size:14,className:"animate-spin"}):e.jsx(yr,{size:14}),y?"Salvando...":"Salvar metas diárias"]})})]})]})}function Qt(){const{user:c}=Cr(),{loading:l,memberships:h,activeWorkspace:t,refresh:n,setActiveWorkspace:p}=ct(),v=s.useMemo(()=>h.filter(a=>a.workspace_type==="team"&&a.status==="active"),[h]),[x,R]=s.useState(null),r=s.useMemo(()=>v.find(a=>a.workspace_id===x)||(t?.workspace_type==="team"?t:v[0])||null,[v,x,t]),[C,M]=s.useState("overview"),[y,i]=s.useState(!1),[u,X]=s.useState(null),[w,L]=s.useState([]),[V,K]=s.useState([]),[N,d]=s.useState([]),[_,F]=s.useState({...mt,dailyTargetsByWeekday:{}}),[B,H]=s.useState([]),[G,ze]=s.useState([]),[T,re]=s.useState([]),[Z,We]=s.useState("all"),[ye,Be]=s.useState("all"),[me,Te]=s.useState(null),[Ye,Ue]=s.useState(null),[m,f]=s.useState("all"),[W,le]=s.useState(null),[ie,Ne]=s.useState(!1),[O,ke]=s.useState(null),[Je,ma]=s.useState(!1),[U,Er]=s.useState(null),[Ke,qa]=s.useState(""),[Ia,Pr]=s.useState("operator"),[Ga,Va]=s.useState(!1),[Xe,Ha]=s.useState("all"),[xa,Fr]=s.useState(""),[Oe,Ar]=s.useState("all"),[Rr,pa]=s.useState(!1),[Lr,Wa]=s.useState(!1),[$r,Br]=s.useState(null),[Tr,Ya]=s.useState("all"),[Ua,Or]=s.useState(null),[Ja,Qe]=s.useState(!1),[Ka,Xa]=s.useState(!1),[Qa,Za]=s.useState(null),[qr,ua]=s.useState(!1),[Ir,ba]=s.useState(null),[Gr,va]=s.useState(!1),[oe,Ze]=s.useState(1),[ee,er]=s.useState(null),[ar,rr]=s.useState(!1),[Vr,tr]=s.useState(!1),[sr,Hr]=s.useState(0),[lr,qe]=s.useState(null);s.useEffect(()=>{t?.workspace_type==="team"&&R(t.workspace_id)},[t?.workspace_id,t?.workspace_type]),s.useEffect(()=>{We("all"),Be("all")},[r?.workspace_id]),s.useEffect(()=>{qe(null)},[r?.workspace_id]),s.useEffect(()=>{f("all"),Ha("all"),le(null),ke(null)},[r?.workspace_id]),s.useEffect(()=>{if(!r){le(null),Ne(!1),ke(null),ma(!1);return}const a=m==="all"?null:m;if(a&&!j(r.role)){f("all");return}let o=!1;return ma(!0),a?(Ne(!0),le(null)):(Ne(!1),le(null)),Promise.all([a?z.getFinancialOverviewFiltered(r.workspace_id,a):Promise.resolve(null),z.getFinancialProfitPeriods(r.workspace_id,a)]).then(([g,D])=>{o||(g&&le(g),ke(D))}).catch(g=>{o||(A.error(g?.message||"Não foi possível carregar os resultados financeiros por período."),a&&f("all"))}).finally(()=>{o||(Ne(!1),ma(!1))}),()=>{o=!0}},[r?.workspace_id,r?.role,m,me]);const Wr=s.useMemo(()=>Array.from(new Set(T.map(o=>
1o.action).filter(Boolean))).sort((o,g)=>Ae(o).localeCompare(Ae(g),"pt-BR")),[T]),Yr=s.useMemo(()=>{const a=new Set;return w.forEach(o=>{o.email&&a.add(o.email.toLowerCase())}),T.forEach(o=>{o.actor_email&&a.add(o.actor_email.toLowerCase())}),Array.from(a).sort((o,g)=>o.localeCompare(g,"pt-BR"))},[T,w]),Ie=s.useMemo(()=>T.filter(a=>{const o=Z==="all"||a.action===Z,g=a.actor_email?.toLowerCase()||"";return o&&(ye==="all"||(ye==="system"?!g:g===ye))}),[T,Z,ye]),ea=s.useMemo(()=>{const a=xa.trim().toLowerCase();return B.filter(o=>{const g=String(o.result_type||o.status||"").toLowerCase(),D=Oe==="all"||(Oe==="pending"?g==="pending"||String(o.status||"").toLowerCase()==="pending":g===Oe),ae=!a||String(o.event_name||"").toLowerCase().includes(a)||String(o.operator_email||"").toLowerCase().includes(a)||String(o.bet_type||"").toLowerCase().includes(a);return D&&ae})},[B,xa,Oe]),xe=s.useCallback(async()=>{if(r){i(!0);try{const a=new Date().getFullYear(),[o,g,D,ae,$,pe,se,ge,ka,oa,Ce,Ge]=await Promise.all([z.getDashboard(r.workspace_id),z.getMembers(r.workspace_id),j(r.role)?z.listInvites(r.workspace_id):Promise.resolve([]),z.getGoals(r.workspace_id),z.getTeamDailyFinancialGoals(r.workspace_id),z.getHistory(r.workspace_id,Xe==="all"?null:Xe,250),z.getMonthlyPerformance(r.workspace_id,a),r.role==="operator"?Promise.resolve([]):z.getActivities(r.workspace_id,100),z.getFinancialOverview(r.workspace_id),j(r.role)?z.getFinancialDetails(r.workspace_id,null).catch(()=>null):Promise.resolve(null),z.getTeamPlan(),r.subscription_active?z.getMigrationPreview(r.workspace_id).catch(()=>null):Promise.resolve(null)]);X(o),L(g),K(D),d(ae),F($),H(pe),ze(se),re(ge),Te(ka),Ue(oa),Er(Ce),Hr(Number(Ge?.total||0));const Me=Math.max(Number(o?.seats?.total||0),Ce.included_seats);if(r.role==="owner"){const ve=await z.getTeamBillingPreview(r.workspace_id,Me).catch(()=>null);er(ve),Ze(Math.max(Ce.included_seats,Number(ve?.renewal_seat_count||Me)))}else Ze(Me)}catch(a){A.error(a?.message||"Não foi possível carregar o painel da equipe.")}finally{i(!1)}}},[r?.workspace_id,r?.role,Xe]);if(s.useEffect(()=>{xe()},[xe]),s.useEffect(()=>{if(!r||r.role!=="owner"||!U)return;const a=window.setTimeout(()=>{z.getTeamBillingPreview(r.workspace_id,oe).then(er).catch(()=>{})},180);return()=>window.clearTimeout(a)},[r?.workspace_id,r?.role,oe,U?.price,U?.extra_seat_price]),l&&!h.length)return e.jsx("div",{className:"flex min-h-[45vh] items-center justify-center",children:e.jsx(ce,{className:"animate-spin",style:{color:"var(--primary)"}})});if(!r)return e.jsx(Yt,{onCreated:async a=>{R(a),await n()}});const Ur=async a=>{R(a),await p(a)},Jr=async()=>{if(Ke.trim()){Va(!0);try{const a=await z.createInvite(r.workspace_id,Ke.trim().toLowerCase(),Ia),o=z.buildInviteUrl(a.invite_code);qa("");try{await navigator.clipboard.writeText(o),A.success("Convite criado. O usuário verá no painel e o link foi copiado.")}catch{A.success("Convite criado. O usuário verá no painel; o link continua disponível na lista.")}await xe()}catch(a){A.error(a?.message||"Não foi possível criar o convite.")}finally{Va(!1)}}},Kr=async a=>{const o=z.buildInviteUrl(a);try{await navigator.clipboard.writeText(o),A.success("Link do convite copiado.")}catch{window.prompt("Copie o link do convite:",o)}},Xr=async a=>{if(window.confirm("Remover esta meta?"))try{await z.deleteGoal(r.workspace_id,a.id),A.success("Meta removida."),await xe()}catch(o){A.error(o?.message||"Erro ao remover meta.")}},te=async(a="all",o)=>{if(j(r.role)){Ya(a),Or(o||null),pa(!0),Wa(!0);try{const g=await z.getFinancialDetails(r.workspace_id,o||null);Br(g)}catch(g){A.error(g?.message||"Não foi possível carregar a composição financeira."),pa(!1)}finally{Wa(!1)}}},ha=async a=>{if(j(r.role)){Qe(!0),Za(null),Xa(!0);try{const o=await z.getBetDetail(r.workspace_id,a);Za(o)}catch(o){A.error(o?.message||"Não foi possível abrir o bilhete completo."),Qe(!1)}finally{Xa(!1)}}},S=m==="all"?null:m,Qr=(()=>{const a=S&&w.find(k=>k.user_id===S)||null,o=S?W:me,g=S&&u?.members?.find(k=>k.user_id===S)||null,D={betCount:Number(S?g?.bet_count||0:u?.bet_count||0),grossProfit:Number(S?g?.gross_profit||0:u?.gross_profit||0),expenses:Number(S?g?.expenses||0:u?.expenses||0),adjustments:Number(S?g?.adjustments||0:u?.adjustments||0),netProfit:Number(S?g?.net_profit||0:u?.net_profit||0)},ae=D.betCount>0?D.netProfit/D.betCount:0,$=[...me?.members||[]].sort((k,J)=>Number(J.total_available||0)-Number(k.total_available||0)),pe=$.reduce((k,J)=>k+Number(J.total_available||0),0),se=$[0]||null,ge=pe>0&&se?Number(se.total_available||0)/pe*100:0,ka=(Ye?.houses||[]).filter(k=>!S||k.operator_user_id===S),oa=(Ye?.pending||[]).filter(k=>!S||k.operator_user_id===S),Ce=new Map;
1ka.forEach(k=>{const J=String(k.casa||"Casa não identificada").trim()||"Casa não identificada",Ee=Ce.get(J)||{name:J,value:0,accounts:0};Ee.value+=k.resolved?Number(k.balance_brl||0):0,Ee.accounts+=1,Ce.set(J,Ee)});const Ge=[...Ce.values()].sort((k,J)=>J.value-k.value),Me=Ge.reduce((k,J)=>k+J.value,0),ve=Ge[0]||null,Ve=Me>0&&ve?ve.value/Me*100:0,mr=Date.now(),je=oa.filter(k=>{const J=k.operation_date||k.created_at,Ee=J?new Date(J).getTime():NaN;return Number.isFinite(Ee)&&mr-Ee>=7*24*60*60*1e3}).sort((k,J)=>new Date(k.operation_date||k.created_at).getTime()-new Date(J.operation_date||J.created_at).getTime()),xr=je.length?Math.max(7,Math.floor((mr-new Date(je[0].operation_date||je[0].created_at).getTime())/(24*60*60*1e3))):0,st=new Set((u?.members||[]).filter(k=>Number(k.bet_count||0)>0).map(k=>k.user_id)),wa=w.filter(k=>k.status==="active"&&k.role==="operator"&&!st.has(k.user_id)),pr=[...u?.members||[]].sort((k,J)=>Number(J.net_profit||0)-Number(k.net_profit||0)),lt=pr.filter(k=>Number(k.net_profit||0)<0).sort((k,J)=>Number(k.net_profit||0)-Number(J.net_profit||0)),ne=[];return S?(je.length&&ne.push({tone:"danger",title:"Pendência antiga",detail:`${je.length} ${je.length===1?"aposta está":"apostas estão"} pendente(s) há 7 dias ou mais; a mais antiga tem cerca de ${xr} dias.`,operatorId:S}),D.netProfit<0&&ne.push({tone:"danger",title:"Resultado negativo no período",detail:`${a?.email||"Operador"} está em ${b.format(D.netProfit)} no período selecionado.`,operatorId:S}),ve&&Ve>=60&&ne.push({tone:"warning",title:"Concentração em uma casa",detail:`${ve.name} concentra ${Ve.toFixed(0)}% do saldo em casas deste operador.`,operatorId:S}),Number(o?.pending_capital||0)>0&&ne.push({tone:"warning",title:"Capital pendente",detail:`${b.format(Number(o?.pending_capital||0))} ainda está imobilizado em apostas pendentes.`,operatorId:S}),D.betCount===0&&ne.push({tone:"info",title:"Sem operações no período",detail:"Nenhuma aposta foi registrada para este operador no período atual.",operatorId:S})):(je.length&&ne.push({tone:"danger",title:"Pendências antigas",detail:`${je.length} ${je.length===1?"aposta está":"apostas estão"} pendente(s) há 7 dias ou mais; a mais antiga tem cerca de ${xr} dias.`}),lt.slice(0,2).forEach(k=>ne.push({tone:"danger",title:"Operador com resultado negativo",detail:`${k.email}: ${b.format(Number(k.net_profit||0))} no período.`,operatorId:k.user_id})),se&&ge>=50&&ne.push({tone:"warning",title:"Concentração de capital",detail:`${se.email} concentra ${ge.toFixed(0)}% do capital disponível entre os operadores.`,operatorId:se.user_id}),ve&&Ve>=60&&ne.push({tone:"warning",title:"Concentração em uma casa",detail:`${ve.name} concentra ${Ve.toFixed(0)}% do saldo mantido em casas de apostas.`}),Number(me?.pending_capital||0)>0&&ne.push({tone:"warning",title:"Capital pendente da equipe",detail:`${b.format(Number(me?.pending_capital||0))} está imobilizado em apostas pendentes.`}),wa.length&&ne.push({tone:"info",title:"Operadores sem registros no período",detail:`${wa.length} ${wa.length===1?"membro ativo não registrou":"membros ativos não registraram"} apostas no período.`})),{financeSelectedOperator:a,displayedFinancial:o,dashboardScope:D,profitPerBet:ae,totalAvailableByMembers:pe,mostExposedMember:se,mostExposedShare:ge,topHouseExposure:ve,topHouseShare:Ve,scopedPendingDetails:oa,houseExposure:Ge,totalHouseExposure:Me,attentionItems:ne.slice(0,4),rankedDashboardMembers:pr,rankedFinancialMembers:$}})(),{financeSelectedOperator:Y,displayedFinancial:P,dashboardScope:Q,profitPerBet:fe,totalAvailableByMembers:aa,mostExposedMember:ya,mostExposedShare:or,topHouseExposure:be,topHouseShare:fa,scopedPendingDetails:ir,attentionItems:ra,rankedDashboardMembers:ga,rankedFinancialMembers:Zr}=Qr,_e=a=>{f(a),Ha(a)},et=Ua&&w.find(a=>a.user_id===Ua)?.email||null,ta=U?Math.max(0,oe-U.included_seats):0,sa=U?U.price+ta*U.extra_seat_price:0,nr=ee?.payment_amount??sa,dr=U?{id:"team_monthly",name:U.name,price:nr,durationDays:U.interval_days,kind:"team",includedSeats:U.included_seats,extraSeatPrice:U.extra_seat_price,description:ee?.action==="seat_upgrade"?`Adicionar ${Math.max(1,oe-ee.current_seats)} assento(s) até a validade atual`:`${oe} ${oe===1?"assento":"assentos"} · ${b.format(sa)}/mês`,features:["Painel consolidado","Metas por operador","Permissões","Auditoria"]}:null,at=async()=>
1{if(!(!r||ee?.action!=="reduction")){rr(!0);try{await z.setRenewalSeatCount(r.workspace_id,oe),A.success(`Próxima renovação configurada para ${oe} assento${oe===1?"":"s"}.`),await xe()}catch(a){A.error(a?.message||"Não foi possível salvar a quantidade da próxima renovação.")}finally{rr(!1)}}},cr=N.find(a=>!a.operator_user_id&&a.goal_type==="profit"),rt=c?.id?N.find(a=>a.operator_user_id===c.id&&a.goal_type==="profit"):null,la=r.role==="operator"&&rt||cr,ja=la&&u?Math.max(0,Math.min(100,u.net_profit/Number(la.target_value||1)*100)):null,tt=Math.max(1,...G.map(a=>Math.abs(Number(a.net_profit||0)))),Na=a=>!j(r.role)||a.user_id===c?.id?!1:r.role==="owner"?!0:a.role==="operator"||a.role==="viewer";return lr&&j(r.role)?e.jsxs(e.Fragment,{children:[e.jsx(Lt,{workspaceId:r.workspace_id,workspaceName:r.name,member:lr,viewerRole:r.role,onBack:()=>qe(null),onOpenBet:a=>void ha(a)}),e.jsx(wr,{open:Ja,onClose:()=>Qe(!1),loading:Ka,bet:Qa})]}):e.jsxs("div",{className:"mx-auto w-full max-w-[1500px] space-y-3 sm:space-y-4",children:[e.jsxs("div",{className:"flex flex-col gap-2.5 sm:gap-3 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(He,{size:21,style:{color:"var(--primary)"}}),e.jsx("h1",{className:"text-xl font-black sm:text-2xl",style:{color:"var(--text-primary)"},children:"Minha Equipe"})]}),e.jsx("p",{className:"mt-1 text-xs sm:text-sm",style:{color:"var(--text-muted)"},children:"Operadores, metas, histórico consolidado e desempenho da operação."})]}),e.jsxs("div",{className:"flex items-center gap-2 self-start lg:self-auto",children:[e.jsx(Ct,{tutorialId:"teammanagement-tutorial",label:"Minha Equipe",size:36}),e.jsx("button",{onClick:()=>void xe(),title:"Atualizar",className:"rounded-xl border p-2 sm:p-2.5",style:{borderColor:"var(--border-subtle)",color:"var(--text-muted)"},children:e.jsx(xt,{size:15,className:y?"animate-spin":""})}),e.jsx(Ut,{memberships:v,current:r,onChange:Ur})]})]}),!r.subscription_active&&e.jsxs("div",{className:"flex flex-col gap-3 rounded-2xl border border-amber-400/20 bg-amber-400/10 p-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-black text-amber-200",children:"Equipe criada — falta ativar os assentos"}),e.jsx("div",{className:"mt-1 text-xs text-amber-100/70",children:"O proprietário precisa ativar o Plano Equipe para liberar convites e o acesso Premium dos operadores."})]}),r.role==="owner"&&e.jsx("button",{onClick:()=>M("plan"),className:"shrink-0 rounded-xl bg-amber-300 px-4 py-2 text-xs font-black text-amber-950",children:"Ativar equipe"})]}),e.jsx("div",{className:"overflow-x-auto rounded-xl border p-1",style:{background:"var(--bg-elevated)",borderColor:"var(--border-subtle)"},children:e.jsx("div",{className:"flex min-w-max gap-1",children:qt.filter(a=>a.id==="plan"?r.role==="owner":!(r.role==="operator"&&(a.id==="members"||a.id==="activity"))).map(a=>e.jsxs("button",{onClick:()=>M(a.id),className:"inline-flex items-center gap-1.5 whitespace-nowrap rounded-lg px-2.5 py-2 text-[11px] font-bold transition-colors sm:px-3 sm:text-xs",style:{background:C===a.id?"var(--primary)":"transparent",color:C===a.id?"var(--primary-foreground)":"var(--text-muted)"},children:[a.icon,a.label]},a.id))})}),j(r.role)&&(C==="overview"||C==="finance"||C==="analytics"||C==="history")&&e.jsxs("div",{className:"flex flex-col gap-2.5 rounded-2xl border px-3 py-3 sm:flex-row sm:items-center sm:justify-between sm:px-3.5",style:{background:"var(--bg-surface)",borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-2.5",children:[e.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg",style:{background:"var(--primary-muted)",color:"var(--primary)"},children:e.jsx(ue,{size:14})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[10px] font-black uppercase tracking-[0.12em]",style:{color:"var(--text-muted)"},children:"Visualização gerencial"}),e.jsx("div",{className:"mt-0.5 truncate text-xs font-black",style:{color:"var(--text-primary)"},children:Y?Y.email:"Equipe completa"})]})]}),e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto 
1sm:flex-row sm:items-center",children:[e.jsx("span",{className:"hidden text-[9px] font-black uppercase tracking-wider sm:block",style:{color:"var(--text-muted)"},children:"Visualizando"}),e.jsxs("select",{value:m,onChange:a=>_e(a.target.value),className:"w-full min-w-0 rounded-xl border px-3 py-2 text-xs font-bold outline-none sm:min-w-[220px] sm:max-w-full",style:{background:"var(--bg-elevated)",borderColor:"var(--border-subtle)",color:"var(--text-primary)"},children:[e.jsx("option",{value:"all",children:"Equipe completa"}),w.map(a=>e.jsxs("option",{value:a.user_id,children:[a.email,a.status!=="active"?" (removido)":""]},a.user_id))]}),(ie||Je)&&e.jsx(ce,{size:14,className:"animate-spin self-end sm:self-auto",style:{color:"var(--primary)"}})]})]}),C==="overview"&&e.jsxs("div",{className:"space-y-3",children:[r.subscription_active&&sr>0&&e.jsxs("div",{className:"flex flex-col gap-2.5 rounded-2xl border px-3 py-2.5 sm:flex-row sm:items-center sm:justify-between",style:{background:"var(--primary-muted)",borderColor:"var(--primary-border)"},children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg",style:{background:"var(--bg-surface)",color:"var(--primary)"},children:e.jsx(pt,{size:15})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-[11px] font-black",style:{color:"var(--text-primary)"},children:"Trazer meus dados pessoais para esta equipe"}),e.jsxs("div",{className:"mt-0.5 line-clamp-1 text-[9px]",style:{color:"var(--text-muted)"},children:[q.format(sr)," registros disponíveis no workspace pessoal. A migração é opcional."]})]})]}),e.jsx("button",{onClick:()=>tr(!0),className:"w-full shrink-0 rounded-lg px-3 py-2 text-[10px] font-black sm:w-auto",style:{background:"var(--primary)",color:"var(--primary-foreground)"},children:"Migrar dados"})]}),e.jsxs("div",{className:`grid gap-3 xl:grid-cols-[minmax(0,1fr)_auto] ${ie?"pointer-events-none opacity-60":""}`,children:[e.jsx(E,{className:"overflow-hidden",children:e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 xl:grid-cols-6",children:[{label:"Banca atual",value:I.format(Number(P?.current_bankroll||0)),fullValue:b.format(Number(P?.current_bankroll||0)),color:Number(P?.current_bankroll||0)>=0?"#22d3a6":"#fb7185",sub:"Capital disponível",onClick:j(r.role)?()=>void te("all",S):void 0},{label:"Lucro líquido",value:I.format(Q.netProfit),fullValue:b.format(Q.netProfit),color:Q.netProfit>=0?"#22d3a6":"#fb7185",sub:"Após gastos e ajustes"},{label:"Apostas",value:q.format(Q.betCount),fullValue:q.format(Q.betCount),color:"var(--text-primary)",sub:"No período atual"},{label:"Pendente",value:I.format(Number(P?.pending_capital||0)),fullValue:b.format(Number(P?.pending_capital||0)),color:Number(P?.pending_capital||0)>0?"#fbbf24":"var(--text-primary)",sub:"Capital imobilizado",onClick:j(r.role)?()=>void te("pending",S):void 0},{label:"Gastos",value:I.format(Q.expenses),fullValue:b.format(Q.expenses),color:Q.expenses>0?"#fb7185":"var(--text-primary)",sub:"No período atual"},{label:"Lucro/operação",value:b.format(fe),fullValue:b.format(fe),color:fe>0?"#22d3a6":fe<0?"#fb7185":"var(--text-primary)",sub:Q.betCount?"Eficiência média":"Sem operações"}].map((a,o)=>e.jsxs("button",{type:"button",disabled:!a.onClick,onClick:a.onClick,title:a.fullValue,className:`min-w-0 border-t p-3 text-left transition enabled:hover:bg-white/[0.035] sm:p-3.5 ${o%2?"border-l":""} sm:border-l sm:first:border-l-0 xl:border-t-0`,style:{borderColor:"var(--border-subtle)"},children:[e.jsx("div",{className:"text-[8px] font-black uppercase tracking-[0.12em]",style:{color:"var(--text-muted)"},children:a.label}),e.jsx("div",{className:"mt-1.5 truncate text-[15px] font-black leading-none sm:text-base xl:text-lg",style:{color:a.color},children:a.value}),e.jsx("div",{className:"mt-1 truncate text-[8px]",style:{color:"var(--text-muted)"},children:a.sub})]},a.label))})}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 xl:w-[250px]",children:[j(r.role)&&e.jsxs("button",{type:"button",onClick:()=>void te("all",S),className:"inline-flex min-h-[58px] items-center justify-center gap-2 rounded-2xl border px-3 text-[10px] font-black",style:{borderColor:"var(--primary-border)",background:"var(--primary-muted)",color:"var(--primary)"},children:[e.jsx(St,{size:14})," Composição"]}),e.jsxs("button",{type:"button",onClick:()=>M("members"),className:"inline-flex min-h-[58px] items-center justify-center gap-2 rounded-2xl border px-3 text-[10px] font-black",style:{borderColor:"var(--border-subtle)",background:"var(--bg-surface)",color:"var(--text-primary)"},children:[e.jsx(He,{size:14})," Operadores"]})]})]}),e.jsxs("div",{className:"grid gap-3 xl:grid-cols-[minmax(0,1fr)_320px]",children:[e.jsxs(E,{className:"min-w-0 overflow-hidden",children:[e.jsxs("div",{className:"flex flex-col gap-2 border-b px-3.5 py-3 sm:flex-row sm:items-center sm:justify-between",style:{borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xs font-black",style:{color:"var(--text-primary)"},children:Y?"Indicadores do operador":"Operadores e indicadores"}),e.jsx("div",{className:"mt-0.5 truncate text-[9px]",style:{color:"var(--text-muted)"},children:Y?Y.email:"Resultado, capital e eficiência na mesma matriz."})]}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[e.jsx(Le,{label:"Membros",value:q.format(w.filter(a=>a.status==="active").length)}),e.jsx(Le,{label:"Pendências",value:q.format(ir.length),tone:ir.length?"warning":"default"})]})]}),Y?e.jsxs("div",{className:"grid gap-2 p-3 sm:grid-cols-2 lg:grid-cols-4",children:[e.jsx(de,{label:"Lucro bruto",value:I.format(Q.grossProfit),sub:b.format(Q.grossProfit),tone:Q.grossProfit>=0?"good":"bad"}),e.jsx(de,{label:"Ajustes",value:I.format(Q.adjustments),sub:b.format(Q.adjustments)}),e.jsx(de,{label:"Casas + bancos",value:I.format(Number(P?.house_balances||0)+Number(P?.bank_balances||0)),sub:"Capital disponível"}),e.jsx(de,{label:"Contas",value:`${Number(P?.members?.[0]?.house_count||0)} casas`,sub:`${Number(P?.members?.[0]?.bank_count||0)} bancos`}),Na(Y)&&e.jsxs("button",{type:"button",onClick:()=>qe(Y),className:"inline-flex items-center justify-center gap-2 rounded-xl border px-3 py-2.5 text-[10px] font-black sm:col-span-2 lg:col-span-4",style:{borderColor:"var(--primary-border)",background:"var(--primary-muted)",color:"var(--primary)"},children:[e.jsx(ue,{size:13})," Abrir dashboard completa em Modo Gestor"]})]}):e.jsx("div",{className:"max-h-[310px] overflow-auto",children:e.jsxs("table",{className:"w-full min-w-[760px] text-left",children:[e.jsx("thead",{className:"sticky top-0 z-10",style:{background:"var(--bg-surface)"},children:e.jsx("tr",{className:"text-[8px] uppercase tracking-[0.12em]",style:{color:"var(--text-muted)"},children:["#","Operador","Apostas","Capital","Resultado","Eficiência","Ações"].map(a=>e.jsx("th",{className:"border-b px-3 py-2.5 font-black",style:{borderColor:"var(--border-subtle)"},children:a},a))})}),e.jsxs("tbody",{children:[ga.map((a,o)=>{const g=w.find(se=>
1se.user_id===a.user_id),D=me?.members?.find(se=>se.user_id===a.user_id),ae=Number(a.bet_count||0)>0?Number(a.net_profit||0)/Number(a.bet_count):0,$=Number(D?.total_available||0),pe=aa>0?$/aa*100:0;return e.jsxs("tr",{className:"border-b text-[10px]",style:{borderColor:"var(--border-subtle)"},children:[e.jsxs("td",{className:"px-3 py-2.5 font-black",style:{color:o<3?"var(--primary)":"var(--text-muted)"},children:[o+1,"º"]}),e.jsxs("td",{className:"max-w-[220px] px-3 py-2.5",children:[e.jsx("div",{className:"truncate font-bold",style:{color:"var(--text-primary)"},children:a.email}),e.jsx("div",{className:"mt-0.5 text-[8px]",style:{color:"var(--text-muted)"},children:$e[a.role]})]}),e.jsx("td",{className:"px-3 py-2.5 font-bold",style:{color:"var(--text-primary)"},children:q.format(Number(a.bet_count||0))}),e.jsxs("td",{className:"px-3 py-2.5",children:[e.jsx("div",{className:"font-black",style:{color:"var(--primary)"},children:I.format($)}),e.jsxs("div",{className:"mt-0.5 text-[8px]",style:{color:"var(--text-muted)"},children:[pe.toFixed(0),"%"]})]}),e.jsx("td",{className:"px-3 py-2.5 font-black",style:{color:Number(a.net_profit||0)>=0?"#22d3a6":"#fb7185"},children:I.format(Number(a.net_profit||0))}),e.jsx("td",{className:"px-3 py-2.5 font-bold",style:{color:ae>=0?"#22d3a6":"#fb7185"},children:b.format(ae)}),e.jsx("td",{className:"px-3 py-2.5",children:e.jsxs("div",{className:"flex justify-end gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>
1_e(a.user_id),title:"Filtrar painel por este operador",className:"rounded-lg border p-1.5",style:{borderColor:"var(--border-subtle)",color:"var(--text-muted)"},children:e.jsx(hr,{size:11})}),g&&Na(g)&&e.jsx("button",{type:"button",onClick:()=>qe(g),title:"Abrir dashboard em Modo Gestor",className:"rounded-lg border p-1.5",style:{borderColor:"var(--primary-border)",color:"var(--primary)"},children:e.jsx(ue,{size:11})})]})})]},a.user_id)}),!ga.length&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"p-7 text-center text-xs",style:{color:"var(--text-muted)"},children:"Ainda não há desempenho registrado neste período."})})]})]})})]}),e.jsxs(E,{className:"overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-3.5 py-3",style:{borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-black",style:{color:"var(--text-primary)"},children:"Alertas"}),e.jsx("div",{className:"mt-0.5 text-[9px]",style:{color:"var(--text-muted)"},children:"Somente exceções e metas."})]}),e.jsx(Le,{label:"Ativos",value:q.format(ra.length),tone:ra.length?"warning":"good"})]}),e.jsxs("div",{className:"max-h-[310px] overflow-y-auto",children:[la&&!S&&ja!==null&&e.jsxs("div",{className:"border-b px-3.5 py-3",style:{borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 text-[9px]",children:[e.jsx("span",{className:"font-black uppercase tracking-wider",style:{color:"var(--text-muted)"},children:"Meta da equipe"}),e.jsxs("strong",{style:{color:"var(--primary)"},children:[ja.toFixed(1),"%"]})]}),e.jsx("div",{className:"mt-1.5 h-1.5 overflow-hidden rounded-full",style:{background:"var(--bg-elevated)"},children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${ja}%`,background:"var(--primary)"}})}),e.jsxs("div",{className:"mt-1.5 truncate text-[8px]",style:{color:"var(--text-muted)"},children:[b.format(u?.net_profit||0)," de ",b.format(Number(la.target_value||0))]})]}),e.jsxs("div",{className:"divide-y",style:{borderColor:"var(--border-subtle)"},children:[ra.map((a,o)=>e.jsxs("button",{type:"button",onClick:()=>a.operatorId&&_e(a.operatorId),disabled:!a.operatorId,className:"flex w-full items-start gap-2.5 px-3.5 py-2.5 text-left enabled:hover:bg-white/[0.035]",children:[e.jsx("div",{className:"mt-1 h-2 w-2 shrink-0 rounded-full",style:{background:a.tone==="danger"?"#fb7185":a.tone==="warning"?"#fbbf24":"var(--primary)"}}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-[10px] font-black",style:{color:"var(--text-primary)"},children:a.title}),e.jsx("div",{className:"mt-0.5 line-clamp-2 text-[8px] leading-3.5",style:{color:"var(--text-muted)"},children:a.detail})]})]},`${a.title}-${o}`)),!ra.length&&e.jsxs("div",{className:"p-5 text-center",children:[e.jsx(De,{size:17,className:"mx-auto",style:{color:"#22d3a6"}}),e.jsx("div",{className:"mt-2 text-[10px] font-black",style:{color:"var(--text-primary)"},children:"Nenhum alerta importante"})]})]})]})]})]}),e.jsxs("div",{className:"grid gap-3 xl:grid-cols-2",children:[e.jsxs(E,{className:"overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-3.5 py-3",style:{borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-black",style:{color:"var(--text-primary)"},children:"Composição financeira"}),e.jsx("div",{className:"mt-0.5 text-[9px]",style:{color:"var(--text-muted)"},children:"Casas, bancos, pendentes e maior exposição."})]}),e.jsx("button",{type:"button",onClick:()=>j(r.role)&&void te("all",S),disabled:!j(r.role),className:"rounded-lg border px-2.5 py-1.5 text-[9px] font-black",style:{borderColor:"var(--primary-border)",color:"var(--primary)"},children:"Detalhes"})]}),(()=>{const a=Math.max(0,Number(P?.house_balances||0)),o=Math.max(0,Number(P?.bank_balances||0)),g=Math.max(0,Number(P?.pending_capital||0)),D=Math.max(1,a+o+g),ae=[{label:"Casas",value:a,section:"houses"},{label:"Bancos",value:o,section:"banks"},{label:"Pendentes",value:g,section:"pending"}];return e.jsxs("div",{className:"grid gap-2.5 p-3 sm:grid-cols-3",children:[ae.map($=>e.jsxs("button",{type:"button",onClick:()=>j(r.role)&&void te($.section,S),className:"min-w-0 rounded-xl border p-3 text-left",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[8px] font-black uppercase tracking-wider",style:{color:"var(--text-muted)"},children:$.label}),e.jsxs("span",{className:"text-[8px] font-bold",style:{color:"var(--text-muted)"},children:[($.value/D*100).toFixed(0),"%"]})]}),e.jsx("div",{className:"mt-1.5 truncate text-sm font-black",style:{color:$.section==="pending"&&$.value>0?"#fbbf24":"var(--text-primary)"},children:I.format($.value)}),e.jsx("div",{className:"mt-2 h-1.5 overflow-hidden rounded-full",style:{background:"var(--bg-surface)"},children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${Math.min(100,$.value/D*100)}%`,background:"var(--primary)"}})})]},$.label)),e.jsxs("div",{className:"sm:col-span-3 flex min-w-0 items-center justify-between gap-3 rounded-xl border px-3 py-2",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[8px] font-black uppercase tracking-wider",style:{color:"var(--text-muted)"},children:"Maior exposição em casa"}),e.jsx("div",{className:"mt-1 truncate text-[10px] font-bold",style:{color:"var(--text-primary)"},children:be?`${be.name} · ${be.accounts} ${be.accounts===1?"conta":"contas"}`:"Sem saldos de casas disponíveis"})]}),e.jsxs("div",{className:"shrink-0 text-right",children:[e.jsx("div",{className:"text-[11px] font-black",style:{color:"var(--primary)"},children:be?I.format(be.value):I.format(0)}),e.jsxs("div",{className:"mt-0.5 text-[8px]",style:{color:"var(--text-muted)"},children:[fa.toFixed(0),"% das casas"]})]})]})]})})()]}),e.jsxs(E,{className:"overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-3.5 py-3",style:{borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-black",style:{color:"var(--text-primary)"},children:"Atividade recente"}),e.jsx("div",{className:"mt-0.5 text-[9px]",style:{color:"var(--text-muted)"},children:"Últimas movimentações da equipe."})]}),e.jsx("button",{type:"button",onClick:()=>M("activity"),className:"rounded-lg border px-2.5 py-1.5 text-[9px] font-black",style:{borderColor:"var(--border-subtle)",color:"var(--text-muted)"},children:"Ver tudo"})]}),e.jsxs("div",{className:"max-h-[220px] divide-y overflow-y-auto",style:{borderColor:"var(--border-subtle)"},children:[T.slice(0,6).map(a=>e.jsxs("div",{className:"grid grid-cols-[30px_minmax(0,1fr)_auto] items-center gap-2.5 px-3.5 py-2.5",children:[e.jsx("div",{className:"flex h-7 w-7 items-center justify-center rounded-lg",style:{background:"var(--primary-muted)",color:"var(--primary)"},children:e.jsx(Sa,{size:12})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-[10px] font-black",style:{color:"var(--text-primary)"},children:Ae(a.action)}),e.jsx("div",{className:"mt-0.5 truncate text-[8px]",style:{color:"var(--text-muted)"},children:a.actor_email||a.target_email||"Sistema"})]}),e.jsx("div",{className:"shrink-0 text-right text-[8px]",style:{color:"var(--text-muted)"},children:na.format(new Date(a.created_at))})]},a.id)),!T.length&&e.jsx("div",{className:"p-6 text-center text-xs",style:{color:"var(--text-muted)"},children:"Nenhuma atividade recente registrada."})]})]})]})]}),C==="members"&&e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[1fr_340px]",children:[e.jsxs(E,{className:"overflow-hidden",children:[e.jsx("div",{className:"border-b px-4 py-4",style:{borderColor:"var(--border-subtle)"},children:e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-black",style:{color:"var(--text-primary)"},children:"Operadores e responsáveis"}),e.jsx("div",{className:"mt-0.5 text-[10px]",style:{color:"var(--text-muted)"},children:"Mais contexto operacional para decidir sem abrir cada dashboard individualmente."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(Le,{label:"Ativos",value:q.format(w.filter(a=>a.status==="active").length)}),e.jsx(Le,{label:"Usados",value:q.format(u?.seats?.used||0)}),e.jsx(Le,{label:"Disponíveis",value:q.format(u?.seats?.available||0),tone:Number(u?.seats?.available||0)>0?"good":"default"})]})]})}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[980px] text-left",children:[e.jsx("thead",{children:e.jsx("tr",{className:"text-[9px] uppercase tracking-[0.14em]",style:{color:"var(--text-muted)"},children:["Operador","Função","Última atividade","Banca","Re
1sultado","Status","Ações"].map(a=>e.jsx("th",{className:"px-4 py-3 font-black",children:a},a))})}),e.jsxs("tbody",{children:[w.filter(a=>a.status==="active").map(a=>{const o=u?.members?.find($=>$.user_id===a.user_id),g=me?.members?.find($=>$.user_id===a.user_id),D=T.find($=>$.actor_email?.toLowerCase()===a.email?.toLowerCase()),ae=Number(o?.net_profit||0)<0?"#fb7185":Number(o?.bet_count||0)>0?"#22d3a6":"var(--text-muted)";return e.jsxs("tr",{className:"border-t text-xs",style:{borderColor:"var(--border-subtle)"},children:[e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl text-xs font-black",style:{background:"var(--primary-muted)",color:"var(--primary)"},children:a.email?.slice(0,1).toUpperCase()}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate font-bold",style:{color:"var(--text-primary)"},children:a.email}),e.jsxs("div",{className:"mt-0.5 text-[10px]",style:{color:"var(--text-muted)"},children:["ID ",a.user_id.slice(0,8),"…"]})]})]})}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"inline-flex items-center gap-1 rounded-full px-2.5 py-1 text-[10px] font-bold",style:{background:"var(--bg-elevated)",color:"var(--text-primary)"},children:[a.role==="owner"?e.jsx(Da,{size:10}):e.jsx(Ma,{size:10}),$e[a.role]]})}),e.jsxs("td",{className:"px-4 py-3",children:[e.jsx("div",{className:"font-bold",style:{color:"var(--text-primary)"},children:D?Ae(D.action):"Sem atividade"}),e.jsx("div",{className:"mt-0.5 text-[10px]",style:{color:"var(--text-muted)"},children:D?na.format(new Date(D.created_at)):"Nenhum registro recente"})]}),e.jsx("td",{className:"px-4 py-3 font-black",style:{color:"var(--primary)"},children:b.format(Number(g?.total_available||0))}),e.jsxs("td",{className:"px-4 py-3",children:[e.jsx("div",{className:"font-black",style:{color:Number(o?.net_profit||0)>=0?"#22d3a6":"#fb7185"},children:b.format(Number(o?.net_profit||0))}),e.jsxs("div",{className:"mt-0.5 text-[10px]",style:{color:"var(--text-muted)"},children:[q.format(Number(o?.bet_count||0))," aposta(s)"]})]}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 text-[10px] font-bold",style:{background:"var(--bg-elevated)",color:ae},children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{background:ae}}),Number(o?.net_profit||0)<0?"Atenção":Number(o?.bet_count||0)>0?"Ativo":"Sem operação"]})}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex justify-end gap-1.5",children:[Na(a)&&e.jsxs("button",{type:"button",onClick:()=>qe(a),className:"inline-flex items-center gap-1.5 rounded-lg border px-2.5 py-2 text-[10px] font-black transition hover:bg-white/[0.035]",style:{borderColor:"var(--primary-border)",color:"var(--primary)"},title:`Visualizar dashboard de ${a.email} em Modo Gestor`,children:[e.jsx(ue,{size:12}),e.jsx("span",{children:"Ver dashboard"})]}),e.jsx(Jt,{workspace:r,member:a,currentUserId:c?.id||"",onChanged:()=>void xe()})]})})]},a.user_id)}),!w.filter(a=>a.status==="active").length&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"p-8 text-center text-xs",style:{color:"var(--text-muted)"},children:"Nenhum membro ativo encontrado."})})]})]})})]}),e.jsxs("div",{className:"space-y-4",children:[j(r.role)&&e.jsxs(E,{className:"overflow-hidden",children:[e.jsxs("div",{className:"border-b px-4 py-3",style:{borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-black",style:{color:"var(--text-primary)"},children:[e.jsx(Dt,{size:16,style:{color:"var(--primary)"}})," Convidar operador"]}),e.jsx("div",{className:"mt-0.5 text-[10px]",style:{color:"var(--text-muted)"},children:"Fluxo rápido para trazer um novo membro sem ocupar uma coluna inteira da tela."})]}),e.jsxs("div",{className:"grid gap-2 p-4",children:[e.jsx("input",{type:"email",placeholder:"[email protected]",value:Ke,onChange:a=>qa(a.target.value),className:"rounded-xl border px-3 py-2.5 text-xs outline-none",style:{background:"var(--bg-elevated)",borderColor:"var(--border-subtle)",color:"var(--text-primary)"}}),e.jsxs("select",{value:Ia,onChange:a=>Pr(a.target.value),className:"rounded-xl border px-3 py-2.5 text-xs",style:{background:"var(--bg-elevated)",borderColor:"var(--border-subtle)",color:"var(--text-primary)"},children:[e.jsx("option",{value:"operator",children:"Operador"}),e.jsx("option",{value:"manager",children:"Gestor"}),e.jsx("option",{value:"viewer",children:"Visualizador"})]}),e.jsxs("button",{onClick:Jr,disabled:Ga||!Ke.trim()||!r.subscription_active,className:"inline-flex items-center justify-center gap-2 rounded-xl px-3 py-2.5 text-xs font-black disabled:opacity-40",style:{background:"var(--primary)",color:"var(--primary-foreground)"},children:[Ga?e.jsx(ce,{size:14,className:"animate-spin"}):e.jsx(Ea,{size:14})," Criar convite"]}),!r.subscription_active&&e.jsx("div",{className:"text-[10px] text-amber-300",children:"Ative o Plano Equipe antes de convidar operadores."})]})]}),j(r.role)&&e.jsxs(E,{className:"overflow-hidden",children:[e.jsxs("div",{className:"border-b px-4 py-3",style:{borderColor:"var(--border-subtle)",color:"var(--text-primary)"},children:[e.jsx("div",{className:"text-sm font-black",children:"Convites"}),e.jsx("div",{className:"text-[10px]",style:{color:"var(--text-muted)"},children:V.length?`${V.length}
1 registro(s)`:"Sem convites ativos no momento."})]}),V.slice(0,8).map(a=>e.jsxs("div",{className:"flex items-center gap-2 border-b px-4 py-3 last:border-b-0",style:{borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[11px] font-bold",style:{color:"var(--text-primary)"},children:a.email}),e.jsxs("div",{className:"mt-0.5 text-[9px]",style:{color:"var(--text-muted)"},children:[$e[a.role]," · ",Nr[a.status]||a.status]})]}),e.jsx("div",{className:"shrink-0 rounded-full px-2 py-1 text-[9px] font-black",style:{background:"var(--bg-elevated)",color:a.status==="accepted"?"#22d3a6":a.status==="pending"?"#fbbf24":"var(--text-muted)"},children:Nr[a.status]||a.status}),a.status==="pending"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>Kr(a.invite_code),className:"p-1.5",style:{color:"var(--text-muted)"},children:e.jsx(Mr,{size:13})}),e.jsx("button",{onClick:async()=>{try{await z.cancelInvite(r.workspace_id,a.id),await xe()}catch(o){A.error(ut(o,"Não foi possível cancelar o convite."))}},className:"p-1.5 text-red-300",children:e.jsx(Sr,{size:13})})]})]},a.id)),!V.length&&e.jsx("div",{className:"p-5 text-center text-[10px]",style:{color:"var(--text-muted)"},children:"Nenhum convite."})]})]})]}),C==="goals"&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(Xt,{workspace:r,value:_,current:Number(O?.today?.projected_profit||0),onSaved:F}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-black",style:{color:"var(--text-primary)"},children:"Metas da operação"}),e.jsx("div",{className:"text-[10px]",style:{color:"var(--text-muted)"},children:"Metas apresentadas em formato mais escaneável, com foco em leitura rápida e progresso."})]}),j(r.role)&&e.jsxs("button",{onClick:()=>{ba(null),ua(!0)},className:"inline-flex items-center gap-1.5 self-start rounded-xl px-3 py-2 text-xs font-black",style:{background:"var(--primary)",color:"var(--primary-foreground)"},children:[e.jsx(Ea,{size:14})," Nova meta"]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-3",children:[N.map(a=>{const o=w.find(ge=>ge.user_id===a.operator_user_id),g=a.operator_user_id?u?.members?.find(ge=>ge.user_id===a.operator_user_id):null,D=a.goal_type==="profit"?g?.net_profit??u?.net_profit??0:a.goal_type==="bets"?g?.bet_count??u?.bet_count??0:0,ae=Math.max(0,Math.min(100,Number(D)/Math.max(1,Number(a.target_value))*100)),$=a.goal_type==="bets"?q.format(a.target_value):a.goal_type==="roi"?`${a.target_value}%`:b.format(a.target_value),pe=a.goal_type==="profit"?"Lucro líquido":a.goal_type==="bets"?"Apostas":a.goal_type==="volume"?"Volume":a.goal_type==="roi"?"ROI":"Limite de perda",se=a.goal_type==="bets"?q.format(Number(D||0)):a.goal_type==="roi"?`${Number(D||0).toFixed(1)}%`:b.format(Number(D||0));return e.jsx(Vt,{title:pe,owner:a.operator_user_id?o?.email||"Operador":"Equipe",targetLabel:$,currentLabel:se,progress:a.goal_type==="profit"||a.goal_type==="bets"||a.goal_type==="roi"?ae:0,period:`${new Date(a.period_start).toLocaleDateString("pt-BR")} — ${new Date(a.period_end).toLocaleDateString("pt-BR")}`,onEdit:j(r.role)?()=>{ba(a),ua(!0)}:void 0,onDelete:j(r.role)?()=>void Xr(a):void 0},a.id)}),!N.length&&e.jsxs(E,{className:"col-span-full p-8 text-center",children:[e.jsx(Pt,{className:"mx-auto",size:24,style:{color:"var(--text-muted)"}}),e.jsx("div",{className:"mt-2 text-xs",style:{color:"var(--text-muted)"},children:"Nenhuma meta cadastrada."})]})]})]}),C==="finance"&&e.jsxs("div",{className:"space-y-4",children:[Y&&e.jsxs("div",{className:"flex flex-col gap-2 rounded-xl border px-3 py-2.5 sm:flex-row sm:flex-wrap sm:items-center sm:justify-between",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[9px] font-black uppercase tracking-widest",style:{color:"var(--primary)"},children:"Filtro ativo"}),e.jsx("div",{className:"truncate text-xs font-black",style:{color:"var(--text-primary)"},children:Y.email})]}),e.jsx("button",{type:"button",onClick:()=>_e("all"),className:"w-full rounded-lg border px-3 py-2 text-[10px] font-black sm:w-auto 
1sm:py-1.5",style:{borderColor:"var(--border-subtle)",color:"var(--text-muted)"},children:"Ver equipe total"})]}),e.jsxs(E,{className:`overflow-hidden ${Je?"opacity-60":""}`,children:[e.jsxs("div",{className:"flex flex-col gap-1 border-b px-4 py-3 sm:flex-row sm:items-center sm:justify-between",style:{borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-black",style:{color:"var(--text-primary)"},children:[e.jsx(da,{size:15,style:{color:"var(--primary)"}}),"Lucro por período"]}),e.jsxs("div",{className:"mt-0.5 text-[10px]",style:{color:"var(--text-muted)"},children:[Y?`Resultados de ${Y.email}.`:"Resultado consolidado da equipe."," Realizado já desconta gastos e soma ajustes manuais; previsto inclui também o lucro esperado das apostas pendentes."]})]}),Je&&e.jsx(ce,{size:14,className:"animate-spin shrink-0",style:{color:"var(--primary)"}})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2.5 p-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx(we,{label:"Hoje",data:O?.today}),e.jsx(we,{label:"Esta semana",data:O?.week}),e.jsx(we,{label:"Este mês",data:O?.month}),e.jsx(we,{label:"Este ano",data:O?.year})]})]}),e.jsxs("div",{className:`grid grid-cols-2 gap-2.5 sm:grid-cols-3 xl:grid-cols-6 ${ie?"pointer-events-none opacity-55":""}`,children:[e.jsx(Re,{label:"Banca atual",value:I.format(Number(P?.current_bankroll||0)),sub:"Casas + bancos + pendentes − gastos agregados",tone:Number(P?.current_bankroll||0)>=0?"good":"bad",icon:e.jsx(ca,{size:15}),onClick:j(r.role)?()=>void te("all",S):void 0}),e.jsx(Re,{label:"Casas",value:I.format(Number(P?.house_balances||0)),sub:"Saldos convertidos para BRL",icon:e.jsx($a,{size:15}),onClick:j(r.role)?()=>void te("houses",S):void 0}),e.jsx(Re,{label:"Bancos",value:I.format(Number(P?.bank_balances||0)),sub:"Saldos externos",icon:e.jsx(Ba,{size:15}),onClick:j(r.role)?()=>void te("banks",S):void 0}),e.jsx(Re,{label:"Pendente",value:I.format(Number(P?.pending_capital||0)),sub:"Capital já deduzido",icon:e.jsx(Ta,{size:15}),onClick:j(r.role)?()=>void te("pending",S):void 0}),e.jsx(Re,{label:"Gastos do mês",value:I.format(Number(P?.month_expenses||0)),sub:Y?"Gastos deste operador":"Todos os gastos",tone:"bad",icon:e.jsx(Dr,{size:15}),onClick:j(r.role)?()=>void te("expenses",S):void 0}),e.jsx(Re,{label:"Gastos agregados",value:I.format(Number(P?.aggregate_unlinked_expenses||0)),sub:"Ainda reduzem a banca",tone:"bad",icon:e.jsx(Oa,{size:15}),onClick:j(r.role)?()=>void te("expenses",S):void 0})]}),Number(P?.unresolved_values||0)>0&&e.jsxs("div",{className:"rounded-xl border border-amber-400/20 bg-amber-400/10 px-4 py-3 text-xs text-amber-100/80",children:[P?.unresolved_values," valor(es) em moeda estrangeira ou capital pendente não possuem conversão persistida completa",Y?" para este operador":"",". Eles não são inventados no total da banca."]}),e.jsxs("div",{className:`grid gap-4 xl:grid-cols-[1fr_420px] ${ie?"pointer-events-none opacity-55":""}`,children:[e.jsxs(E,{className:"overflow-hidden",children:[e.jsx("div",{className:"border-b px-4 py-3",style:{borderColor:"var(--border-subtle)"},children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-black",style:{color:"var(--text-primary)"},children:Y?"Financeiro do operador":"Financeiro por operador"}),e.jsx("div",{className:"text-[10px]",style:{color:"var(--text-muted)"},children:Y?`Composição financeira de ${Y.email}.`:"Casas, bancos e gastos do mês separados por responsável."})]}),j(r.role)&&e.jsxs("div",{className:"hidden items-center gap-1 text-[9px] font-bold sm:flex",style:{color:"var(--primary)"},children:[e.jsx(ue,{size:11})," Clique para detalhar"]})]})}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[760px] text-left",children:[e.jsx("thead",{children:e.jsx("tr",{className:"text-[10px] uppercase tracking-wider",style:{color:"var(--text-muted)"},children:["Operador","Casas","Bancos","Disponível","Gastos/mês","Contas",""].map(a=>e.jsx("th",{className:"px-4 py-3 font-black",children:a},a||"acoes"))})}),e.jsxs("tbody",{children:[(P?.members||[]).map(a=>e.jsxs("tr",{onClick:j(r.role)?()=>
1void te("all",a.user_id):void 0,className:`border-t text-xs ${j(r.role)?"cursor-pointer transition hover:bg-white/[0.035]":""}`,style:{borderColor:"var(--border-subtle)"},children:[e.jsx("td",{className:"max-w-[190px] truncate px-4 py-3 font-bold",style:{color:"var(--text-primary)"},children:a.email}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("button",{disabled:!j(r.role),onClick:o=>{o.stopPropagation(),j(r.role)&&te("houses",a.user_id)},className:"text-left disabled:cursor-default",style:{color:"var(--text-primary)"},children:b.format(Number(a.house_balance||0))})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("button",{disabled:!j(r.role),onClick:o=>{o.stopPropagation(),j(r.role)&&te("banks",a.user_id)},className:"text-left disabled:cursor-default",style:{color:"var(--text-primary)"},children:b.format(Number(a.bank_balance||0))})}),e.jsx("td",{className:"px-4 py-3 font-black",style:{color:"var(--primary)"},children:b.format(Number(a.total_available||0))}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("button",{disabled:!j(r.role),onClick:o=>{o.stopPropagation(),j(r.role)&&te("expenses",a.user_id)},className:"text-left text-red-300 disabled:cursor-default",children:b.format(Number(a.month_expenses||0))})}),e.jsxs("td",{className:"px-4 py-3",style:{color:"var(--text-muted)"},children:[Number(a.house_count||0)," casas · ",Number(a.bank_count||0)," bancos"]}),e.jsx("td",{className:"px-4 py-3",children:j(r.role)&&e.jsx(ue,{size:13,style:{color:"var(--primary)"}})})]},a.user_id)),!P?.members?.length&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"p-8 text-center text-xs",style:{color:"var(--text-muted)"},children:ie?"Carregando financeiro...":"Nenhum saldo financeiro encontrado."})})]})]})})]}),e.jsxs(E,{className:"overflow-hidden",children:[e.jsxs("div",{className:"border-b px-4 py-3",style:{borderColor:"var(--border-subtle)"},children:[e.jsx("div",{className:"text-sm font-black",style:{color:"var(--text-primary)"},children:"Gastos recentes"}),e.jsx("div",{className:"text-[10px]",style:{color:"var(--text-muted)"},children:Y?`Últimos lançamentos de ${Y.email}.`:"Últimos lançamentos financeiros do workspace."})]}),e.jsxs("div",{className:"divide-y",style:{borderColor:"var(--border-subtle)"},children:[(P?.recent_expenses||[]).slice(0,12).map(a=>e.jsxs("button",{type:"button",disabled:!j(r.role),onClick:()=>j(r.role)&&void te("expenses",a.operator_user_id),className:"flex w-full items-center gap-3 px-4 py-3 text-left transition enabled:hover:bg-white/[0.035]",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-xs font-bold",style:{color:"var(--text-primary)"},children:a.supplier||a.category}),e.jsxs("div",{className:"mt-0.5 truncate text-[9px]",style:{color:"var(--text-muted)"},children:[new Date(a.expense_date).toLocaleDateString("pt-BR")," · ",a.operator_email||"Usuário"," · ",a.category]})]}),e.jsxs("div",{className:"shrink-0 text-xs font-black text-red-300",children:["− ",b.format(Math.abs(Number(a.amount_brl||0)))]}),j(r.role)&&e.jsx(ue,{size:12,style:{color:"var(--primary)"}})]},a.id)),!P?.recent_expenses?.length&&e.jsx("div",{className:"p-8 text-center text-xs",style:{color:"var(--text-muted)"},children:ie?"Carregando gastos...":"Nenhum gasto cadastrado."})]})]})]})]}),C==="history"&&e.jsxs(E,{className:"overflow-hidden",children:[e.jsxs("div",{className:"border-b p-4",style:{borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-end lg:justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-black",style:{color:"var(--text-primary)"},children:["Histórico consolidado ",j(r.role)&&e.jsx("span",{className:"rounded-lg px-2 py-1 text-[9px] font-black",style:{background:"var(--primary-muted)",color:"var(--primary)"},children:"CONTROLE COMPLETO"})]}),e.jsx("div",{className:"mt-0.5 text-[10px]",style:{color:"var(--text-muted)"},children:j(r.role)?"Filtre por responsável e abra qualquer registro para visualizar o bilhete completo, linhas, odds, stakes e resultados.":"Últimos registros do workspace, identificados por operador."})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-[minmax(180px,1fr)_170px_170px]",children:[e.jsxs("label",{className:"relative min-w-0",children:[e.jsx(bt,{size:13,className:"absolute left-3 top-1/2 -translate-y-1/2",style:{color:"var(--text-muted)"}}),e.jsx("input",{value:xa,onChange:a=>Fr(a.target.value),placeholder:"Buscar evento, tipo...",className:"w-full rounded-xl border py-2 pl-9 pr-3 text-xs outline-none",style:{background:"var(--bg-elevated)",borderColor:"var(--border-subtle)",color:"var(--text-primary)"}})]}),e.jsxs("select",{value:Xe,onChange:a=>_e(a.target.value),className:"rounded-xl border px-3 py-2 text-xs",style:{background:"var(--bg-elevated)",borderColor:"var(--border-subtle)",color:"var(--text-primary)"},children:[e.jsx("option",{value:"all",children:"Todos operadores"}),w.map(a=>e.jsxs("option",{value:a.user_id,children:[a.email,a.status!=="active"?" (removido)":""]}
1,a.user_id))]}),e.jsxs("select",{value:Oe,onChange:a=>Ar(a.target.value),className:"rounded-xl border px-3 py-2 text-xs",style:{background:"var(--bg-elevated)",borderColor:"var(--border-subtle)",color:"var(--text-primary)"},children:[e.jsx("option",{value:"all",children:"Todos resultados"}),e.jsx("option",{value:"green",children:"Green"}),e.jsx("option",{value:"red",children:"Red"}),e.jsx("option",{value:"void",children:"Void"}),e.jsx("option",{value:"cashout",children:"Cashout"}),e.jsx("option",{value:"pending",children:"Pendente"})]})]})]}),e.jsxs("div",{className:"mt-2 text-[9px]",style:{color:"var(--text-muted)"},children:[q.format(ea.length)," de ",q.format(B.length)," registros exibidos",ea.length>8?" · role dentro do histórico para ver os demais":""]})]}),e.jsx("div",{className:"overflow-auto overscroll-contain",style:{maxHeight:"432px",scrollbarGutter:"stable"},children:e.jsxs("table",{className:"w-full min-w-[860px] text-left",children:[e.jsx("thead",{className:"sticky top-0 z-10",style:{background:"var(--bg-card)"},children:e.jsx("tr",{className:"text-[10px] uppercase tracking-wider",style:{color:"var(--text-muted)"},children:["Data","Operador","Evento","Tipo","Investimento","Resultado",""].map(a=>e.jsx("th",{className:"px-4 py-3 font-black",style:{background:"var(--bg-card)"},children:a},a||"abrir"))})}),e.jsxs("tbody",{children:[ea.map(a=>e.jsxs("tr",{onClick:j(r.role)?()=>void ha(a.id):void 0,className:`border-t text-xs ${j(r.role)?"cursor-pointer transition hover:bg-white/[0.035]":""}`,style:{borderColor:"var(--border-subtle)"},children:[e.jsx("td",{className:"px-4 py-3",style:{color:"var(--text-muted)"},children:a.operation_date?new Date(a.operation_date).toLocaleDateString("pt-BR"):new Date(a.created_at).toLocaleDateString("pt-BR")}),e.jsx("td",{className:"max-w-[180px] truncate px-4 py-3 font-bold",style:{color:"var(--text-primary)"},children:a.operator_email||"—"}),e.jsx("td",{className:"max-w-[300px] truncate px-4 py-3",style:{color:"var(--text-primary)"},children:a.event_name}),e.jsx("td",{className:"px-4 py-3",style:{color:"var(--text-muted)"},children:a.bet_type||"—"}),e.jsx("td",{className:"px-4 py-3",style:{color:"var(--text-primary)"},children:b.format(Number(a.total_amount||0))}),e.jsx("td",{className:"px-4 py-3 font-black",style:{color:a.actual_profit==null?"#fbbf24":Number(a.actual_profit)>=0?"#22d3a6":"#fb7185"},children:a.actual_profit==null?"Pendente":b.format(Number(a.actual_profit||0))}),e.jsx("td",{className:"px-4 py-3",children:j(r.role)&&e.jsxs("button",{type:"button",onClick:o=>{o.stopPropagation(),ha(a.id)},title:"Ver bilhete completo",className:"inline-flex items-center gap-1 rounded-lg border px-2 py-1 text-[9px] font-bold",style:{borderColor:"var(--primary-border)",background:"var(--primary-muted)",color:"var(--primary)"},children:[e.jsx(ue,{size:11})," Bilhete"]})})]},a.id)),!ea.length&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"p-8 text-center text-xs",style:{color:"var(--text-muted)"},children:B.length?"Nenhum registro corresponde aos filtros selecionados.":"Nenhum registro encontrado."})})]})]})})]}),C==="analytics"&&e.jsxs("div",{className:"space-y-4",children:[j(r.role)&&e.jsx(Ot,{workspaceId:r.workspace_id,operatorUserId:S,operatorLabel:Y?.email||null}),Y?e.jsxs(e.Fragment,{children:[e.jsxs(E,{className:`overflow-hidden ${Je?"opacity-60":""}`,children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-4 py-3",style:{borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{children:[e.jsxs("div",{className:"text-sm font-black",style:{color:"var(--text-primary)"},children:["Resultado de ",Y.email]}),e.jsx("div",{className:"text-[10px]",style:{color:"var(--text-muted)"},children:"A análise individual usa os agregados confiáveis disponíveis para este operador."})]}),e.jsx(zt,{size:16,style:{color:"var(--primary)"}})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2.5 p-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx(we,{label:"Hoje",data:O?.today}),e.jsx(we,{label:"Esta semana",data:O?.week}),e.jsx(we,{label:"Este mês",data:O?.month}),e.jsx(we,{label:"Este ano",data:O?.year})]})]}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-3",children:[e.jsxs(E,{className:"p-3 sm:p-4",children:[e.jsx("div",{className:"text-[10px] font-black uppercase tracking-widest",style:{color:"var(--text-muted)"},children:"Eficiência por operação"}),e.jsx("div",{className:"mt-2 text-2xl font-black",style:{color:fe>=0?"#22d3a6":"#fb7185"},children:b.format(fe)}),e.jsxs("div",{className:"mt-1 text-[10px]",style:{color:"var(--text-muted)"},children:[q.format(Q.betCount)," operações registradas no período."]})]}),e.jsxs(E,{className:"p-3 sm:p-4",children:[e.jsx("div",{className:"text-[10px] font-black uppercase tracking-widest",style:{color:"var(--text-muted)"},children:"Banca atual"}),e.jsx("div",{className:"mt-2 text-2xl font-black",style:{color:"var(--primary)"},children:b.format(Number(P?.current_bankroll||0))}),e.jsx("div",{className:"mt-1 text-[10px]",style:{color:"var(--text-muted)"},children:"Inclui casas, bancos e capital pendente conforme regra financeira atual."})]}),e.jsxs(E,{className:"p-3 sm:p-4",children:[e.jsx("div",{className:"text-[10px] font-black uppercase tracking-widest",style:{color:"var(--text-muted)"},children:"Capital pendente"}),e.jsx("div",{className:"mt-2 text-2xl font-black",style:{color:Number(P?.pending_capital||0)>0?"#fbbf24":"var(--text-primary)"},children:b.format(Number(P?.pending_capital||0))}),e.jsx("div",{className:"mt-1 text-[10px]",style:{color:"var(--text-muted)"}
1,children:"Capital atualmente imobilizado em apostas pendentes."})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.1fr)_minmax(340px,.9fr)]",children:[e.jsxs(E,{className:"p-4 sm:p-5",children:[e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"text-sm font-black",style:{color:"var(--text-primary)"},children:["Evolução mensal ",new Date().getFullYear()]}),e.jsx("div",{className:"text-[10px]",style:{color:"var(--text-muted)"},children:"Resultado líquido consolidado da equipe: lucro + ajustes − gastos. Meses sem movimentação ficam discretos e o período mais relevante ganha destaque."})]}),e.jsx(da,{size:17,style:{color:"var(--primary)"}})]}),e.jsx("div",{className:"mt-5 grid h-60 grid-cols-12 items-end gap-2",children:Array.from({length:12},(a,o)=>{const g=G.find(pe=>Number(pe.month)===o+1),D=Number(g?.net_profit||0),ae=Math.max(6,Math.abs(D)/tt*100),$=new Date(new Date().getFullYear(),o,1).toLocaleDateString("pt-BR",{month:"short"}).replace(".","");return e.jsxs("div",{className:"flex h-full min-w-0 flex-col items-center justify-end gap-2",children:[e.jsx("div",{className:"w-full max-w-12 rounded-2xl border border-white/5 px-1 pb-1 pt-2",style:{background:"rgba(255,255,255,.015)"},children:e.jsx("div",{title:`${new Date(new Date().getFullYear(),o,1).toLocaleDateString("pt-BR",{month:"long"})}: ${b.format(D)}`,className:"w-full rounded-xl",style:{height:`${ae}%`,minHeight:6,background:D<0?"linear-gradient(180deg, rgba(251,113,133,.9), rgba(251,113,133,.55))":"linear-gradient(180deg, rgba(110,211,255,.95), var(--primary))",opacity:g?1:.22}})}),e.jsx("div",{className:"text-[8px] font-bold sm:text-[10px]",style:{color:g?"var(--text-primary)":"var(--text-muted)"},children:$})]},o)})})]}),e.jsxs(E,{className:"overflow-hidden",children:[e.jsxs("div",{className:"border-b px-4 py-3",style:{borderColor:"var(--border-subtle)"},children:[e.jsx("div",{className:"text-sm font-black",style:{color:"var(--text-primary)"},children:"Leituras rápidas"}),e.jsx("div",{className:"text-[10px]",style:{color:"var(--text-muted)"},children:"Resumo executivo para identificar cenário, destaque e concentração sem precisar cruzar os números manualmente."})]}),e.jsxs("div",{className:"grid gap-3 p-4",children:[e.jsx(de,{label:"Lucro líquido",value:I.format(Q.netProfit),sub:"Período atual",tone:Q.netProfit>0?"good":Q.netProfit<0?"bad":"default"}),e.jsx(de,{label:"Eficiência média",value:b.format(fe),sub:`${q.format(Q.betCount)} operação(ões)`,tone:fe>0?"good":fe<0?"bad":"default"}),e.jsx(de,{label:"Maior concentração",value:ya?`${or.toFixed(0)}%`:"0%",sub:ya?ya.email:"Sem concentração relevante",tone:or>=50?"warning":"default"}),e.jsx(de,{label:"Casa mais exposta",value:be?I.format(be.value):I.format(0),sub:be?`${be.name} · ${fa.toFixed(0)}% do total`:"Sem dados suficientes",tone:fa>=60?"warning":"default"})]})]})]}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1fr)_380px]",children:[e.jsxs(E,{className:"overflow-hidden",children:[e.jsxs("div",{className:"border-b px-4 py-3",style:{borderColor:"var(--border-subtle)"},children:[e.jsx("div",{className:"text-sm font-black",style:{color:"var(--text-primary)"},children:"Ranking e eficiência"}),e.jsx("div",{className:"text-[10px]",style:{color:"var(--text-muted)"},children:"Lucro líquido e lucro médio por operação, sem estimar ROI."})]}),e.jsxs("div",{className:"divide-y",style:{borderColor:"var(--border-subtle)"},children:[ga.map((a,o)=>{const g=Number(a.bet_count||0)>0?Number(a.net_profit||0)/Number(a.bet_count):0;return e.jsxs("button",{type:"button",onClick:()=>
1_e(a.user_id),className:"grid w-full grid-cols-[30px_minmax(0,1fr)_100px_100px] items-center gap-2 px-4 py-3 text-left hover:bg-white/[0.035]",children:[e.jsxs("div",{className:"text-xs font-black",style:{color:o<3?"var(--primary)":"var(--text-muted)"},children:[o+1,"º"]}),e.jsx("div",{className:"truncate text-xs font-bold",style:{color:"var(--text-primary)"},children:a.email}),e.jsx("div",{className:"text-right text-[10px] font-black",style:{color:Number(a.net_profit)>=0?"#22d3a6":"#fb7185"},children:I.format(Number(a.net_profit||0))}),e.jsxs("div",{className:"text-right text-[10px] font-bold",style:{color:g>=0?"#22d3a6":"#fb7185"},children:[b.format(g),"/op."]})]},a.user_id)}),!u?.members?.length&&e.jsx("div",{className:"p-8 text-center text-xs",style:{color:"var(--text-muted)"},children:"Sem dados suficientes para montar o ranking."})]})]}),e.jsxs(E,{className:"overflow-hidden",children:[e.jsxs("div",{className:"border-b px-4 py-3",style:{borderColor:"var(--border-subtle)"},children:[e.jsx("div",{className:"text-sm font-black",style:{color:"var(--text-primary)"},children:"Concentração financeira"}),e.jsx("div",{className:"text-[10px]",style:{color:"var(--text-muted)"},children:"Participação no capital disponível entre operadores."})]}),e.jsxs("div",{className:"space-y-3 p-4",children:[Zr.slice(0,6).map(a=>{const o=aa>0?Number(a.total_available||0)/aa*100:0;return e.jsxs("button",{type:"button",onClick:()=>
1_e(a.user_id),className:"block w-full text-left",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 text-[10px]",children:[e.jsx("span",{className:"truncate font-bold",style:{color:"var(--text-primary)"},children:a.email}),e.jsxs("span",{className:"shrink-0 font-black",style:{color:"var(--primary)"},children:[o.toFixed(0),"%"]})]}),e.jsx("div",{className:"mt-1.5 h-1.5 overflow-hidden rounded-full",style:{background:"var(--bg-elevated)"},children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${Math.min(100,o)}%`,background:"var(--primary)"}})})]},a.user_id)}),!me?.members?.length&&e.jsx("div",{className:"py-5 text-center text-xs",style:{color:"var(--text-muted)"},children:"Sem saldos disponíveis."})]})]})]})]})]}),C==="activity"&&e.jsxs(E,{className:"overflow-hidden",children:[e.jsxs("div",{className:"border-b px-4 py-3",style:{borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-end lg:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-black",style:{color:"var(--text-primary)"},children:"Log de atividades"}),e.jsx("div",{className:"text-[10px]",style:{color:"var(--text-muted)"},children:"Auditoria do workspace. Registros permanecem mesmo após a saída de um operador."})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-bold",style:{color:"var(--text-muted)"},children:[e.jsx(hr,{size:12})," Filtros"]}),e.jsxs("select",{"aria-label":"Filtrar atividades por ação",value:Z,onChange:a=>We(a.target.value),className:"min-w-0 rounded-lg border px-2.5 py-2 text-[11px] outline-none sm:w-48",style:{background:"var(--bg-elevated)",borderColor:"var(--border-subtle)",color:"var(--text-primary)"},children:[e.jsx("option",{value:"all",children:"Todas as ações"}),Wr.map(a=>e.jsx("option",{value:a,children:Ae(a)},a))]}),e.jsxs("select",{"aria-label":"Filtrar atividades por membro",value:ye,onChange:a=>Be(a.target.value),className:"min-w-0 rounded-lg border px-2.5 py-2 text-[11px] outline-none sm:w-56",style:{background:"var(--bg-elevated)",borderColor:"var(--border-subtle)",color:"var(--text-primary)"},children:[e.jsx("option",{value:"all",children:"Todos os membros"}),T.some(a=>!a.actor_email)&&e.jsx("option",{value:"system",children:"Sistema"}),Yr.map(a=>e.jsx("option",{value:a,children:a},a))]})]})]}),e.jsxs("div",{className:"mt-2 text-[10px]",style:{color:"var(--text-muted)"},children:[Ie.length===T.length?`${q.format(T.length)} ${T.length===1?"atividade":"atividades"}`:`${q.format(Ie.length)} de ${q.format(T.length)} atividades`,Ie.length>8?" · role dentro da lista para ver as demais":""]})]}),e.jsxs("div",{className:"divide-y overflow-y-auto overscroll-contain",style:{borderColor:"var(--border-subtle)",maxHeight:"416px",scrollbarGutter:"stable"},children:[Ie.map(a=>e.jsxs("div",{className:"flex min-h-[52px] gap-3 px-4 py-3",children:[e.jsx("div",{className:"mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-lg",style:{background:"var(--primary-muted)",color:"var(--primary)"},children:e.jsx(Sa,{size:13})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-xs font-bold",style:{color:"var(--text-primary)"},children:Ae(a.action)}),e.jsxs("div",{className:"mt-0.5 text-[10px]",style:{color:"var(--text-muted)"},children:[a.actor_email||"Sistema"," · ",na.format(new Date(a.created_at)),a.target_email?` · ${a.target_email}`:""]})]})]},a.id)),!Ie.length&&e.jsx("div",{className:"p-8 text-center text-xs",style:{color:"var(--text-muted)"},children:T.length?"Nenhuma atividade corresponde aos filtros selecionados.":"Nenhuma atividade registrada."})]})]}),C==="plan"&&r.role==="owner"&&e.jsxs("div",{className:"grid gap-4 lg:grid-cols-[1fr_360px]",children:[e.jsxs(E,{className:"overflow-hidden",children:[e.jsx("div",{className:"border-b px-5 py-4",style:{borderColor:"var(--border-subtle)"},children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-xl",style:{background:"var(--primary-muted)",color:"var(--primary)"},children:e.jsx(Da,{size:20})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-lg font-black",style:{color:"var(--text-primary)"},children:"DuckTips Equipe"}),e.jsx("div",{className:"text-xs",style:{color:"var(--text-muted)"},children:r.subscription_active?"Assinatura ativa e pronta para operar":"Aguardando ativação do plano equipe"})]})]})}),e.jsxs("div",{className:"grid gap-4 p-5 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx(de,{label:"Assentos",value:q.format(u?.seats?.total||oe),sub:"Capacidade atual"}),e.jsx(de,{label:"Utilizados",value:q.format(u?.seats?.used||1),sub:"Membros ativos"}),e.jsx(de,{label:"Pendentes",value:q.format(u?.seats?.pending||0),sub:"Convites aguardando",tone:Number(u?.seats?.pending||0)>0?"warning":"default"}),e.jsx(de,{label:"Disponíveis",value:q.format(u?.seats?.available||0),sub:"Prontos para uso",tone:Number(u?.seats?.available||0)>0?"good":"default"})]}),e.jsxs("div",{className:"grid gap-4 border-t p-5 lg:grid-cols-2",style:{borderColor:"var(--border-subtle)"},children:[e.jsxs("div",{className:"rounded-2xl border p-4",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[e.jsx("div",{className:"text-[10px] font-black uppercase tracking-[0.14em]",style:{color:"var(--text-muted)"},children:"Benefícios inclusos"}),e.jsxs("div",{className:"mt-3 space-y-2 text-xs",style:{color:"var(--text-primary)"},children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(De,{size:13,style:{color:"#22d3a6"}})," Painel consolidado da equipe"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(De,{size:13,style:{color:"#22d3a6"}})," Metas por operador e visão gerencial"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(De,{size:13,style:{color:"#22d3a6"}})," Histórico, atividades e auditoria"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(De,{size:13,style:{color:"#22d3a6"}})," Acesso Premium da equipe para membros"]})]})]}),e.jsxs("div",{className:"rounded-2xl border p-4",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[e.jsx("div",{className:"text-[10px] font-black uppercase tracking-[0.14em]",style:{color:"var(--text-muted)"},children:"Resumo operacional"}),e.jsxs("div",{className:"mt-3 space-y-2 text-[11px] leading-5",style:{color:"var(--text-muted)"},children:[e.jsx("div",{children:"O owner é responsável pelo pagamento e pela quantidade de assentos da equipe."}),e.jsx("div",{children:"Operadores, gestores e visualizadores usam o Premium da equipe sem contratar o plano individual."}),e.jsx("div",{children:"Assinaturas pessoais dos membros permanecem independentes."})]})]})]})]}),e.jsxs(E,{className:"p-5",children:[e.jsx("div",{className:"text-xs font-black uppercase tracking-widest",style:{color:"var(--primary)"},children:r.subscription_active?"Assentos e renovação":"Ativar equipe"}),U?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold",style:{color:"var(--text-primary)"},children:"Quantidade de assentos"}),e.jsxs("div",{className:"text-[10px]",style:{color:"var(--text-muted)"},children:["Owner incluso · +",b.format(U.extra_seat_price)," por membro adicional"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>Ze(a=>Math.max(U.included_seats,Number(u?.seats?.used||0)+Number(u?.seats?.pending||0),a-1)),className:"h-8 w-8 rounded-lg border",style:{borderColor:"var(--border-subtle)",color:"var(--text-primary)"},children:"-"}),e.jsx("div",{className:"w-7 text-center text-sm font-black",style:{color:"var(--text-primary)"},children:oe}),e.jsx("button",{onClick:()=>Ze(a=>Math.min(U.max_seats||100,a+1)),className:"h-8 w-8 rounded-lg border",style:{borderColor:"var(--border-subtle)",color:"var(--text-primary)"},children:"+"})]})]}),e.jsxs("div",{className:"mt-4 space-y-1.5 rounded-xl border p-3 text-[10px]",style:{borderColor:"var(--border-subtle)",background:"var(--bg-elevated)"},children:[e.jsxs("div",{className:"flex items-center justify-between",style:{color:"var(--text-muted)"},children:[e.jsx("span",{children:"Plano Equipe · Owner"}),e.jsx("span",{className:"font-bold",style:{color:"var(--text-primary)"},children:b.format(U.price)})]}),e.jsxs("div",{className:"flex items-center justify-between",style:{color:"var(--text-muted)"},children:[e.jsxs("span",{children:[ta," ",ta===1?"membro adicional":"membros adicionais"," × ",b.format(U.extra_seat_price)]}),e.jsx("span",{className:"font-bold",style:{color:"var(--text-primary)"},children:b.format(ta*U.extra_seat_price)})]}),ee?.action==="activate"&&ee.credit_amount>0&&e.jsxs("div",{className:"flex items-center justify-between text-emerald-400",children:[e.jsx("span",{children:"Crédito do Premium Individual restante"}),e.jsxs("span",{className:"font-black",children:["− ",b.format(ee.credit_amount)]})]}),ee?.action==="seat_upgrade"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between text-cyan-300",children:[e.jsxs("span",{children:["Pró-rata até o fim do ciclo (",Math.round(ee.proration_factor*100),"%)"]}),e.jsx("span",{className:"font-black",children:b.format(ee.payment_amount)})]}),e.jsxs("div",{style:{color:"var(--text-muted)"},children:["Na próxima renovação, os ",oe," assentos custarão ",b.format(sa),"."]})]}),ee?.action==="reduction"&&e.jsx("div",{className:"text-amber-300",children:"A redução não altera nem reembolsa o ciclo atual. Ela será salva para a próxima renovação."})]}),e.jsxs("div",{className:"mt-4 flex items-end justify-between border-t pt-4",style:{borderColor:"var(--border-subtle)"},children:[e.jsx("div",{className:"text-xs",style:{color:"var(--text-muted)"},children:ee?.action==="seat_upgrade"?"Cobrança agora":ee?.action==="reduction"?"Próxima renovação":`Total / ${U.interval_days} dias`}),e.jsx("div",{className:"text-2xl font-black",style:{color:"var(--primary)"},children:b.format(ee?.action==="reduction"?sa:nr)})]}),ee?.action==="reduction"?e.jsx("button",{onClick:at,disabled:ar,className:"mt-4 w-full rounded-xl px-4 py-3 text-sm font-black disabled:opacity-50",style:{background:"var(--primary)",color:"var(--primary-foreground)"},children:ar?"Salvando...":"Salvar para a próxima renovação"}):e.jsx("button",{onClick:()=>va(!0),className:"mt-4 w-full rounded-xl px-4 py-3 text-sm font-black",style:{background:"var(--primary)",color:"var(--primary-foreground)"},children:ee?.action==="seat_upgrade"?"Adicionar assentos com PIX":r.subscription_active?"Gerar PIX de renovação":"Ativar com PIX"}),e.jsx("div",{className:"mt-3 text-[10px] leading-4",style:{color:"var(--text-muted)"},children:"O Owner paga a equipe e todos os assentos. Operadores, gestores e visualizadores usam o Premium da equipe sem precisar pagar o plano Individual. Assinaturas pessoais dos membros continuam independentes."})]}):e.jsx("div",{className:"mt-5 flex justify-center",children:e.jsx(ce,{className:"animate-spin",style:{color:"var(--primary)"}})})]})]}),e.jsx(Wt,{open:Rr,onClose:()=>pa(!1),loading:Lr,data:$r,section:Tr,onSectionChange:Ya,operatorEmail:et}),e.jsx(wr,{open:Ja,onClose:()=>Qe(!1),loading:Ka,bet:Qa}),e.jsx(vt,{open:Vr,workspaceId:r.workspace_id,workspaceName:r.name,onClose:()=>tr(!1),onMigrated:async()=>{await xe(),await n()}}),e.jsx(Kt,{open:qr,onClose:()=>{ua(!1),ba(null)},workspace:r,members:w,editing:Ir,onSaved:()=>void xe()}),dr&&c&&e.jsx(ht,{isOpen:Gr,onClose:()=>va(!1),plan:dr,userId:c.id,userEmail:c.email||"",supabase:yt,isRenewal:ee?.action==="renew",paymentContext:{workspaceId:r.workspace_id,seatCount:oe},onSuccess:async()=>{va(!1),await n(),await xe(),window.dispatchEvent(new CustomEvent("subscriptionUpdated"))}})]})}const ks=ot.memo(Qt);export{ks 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.