PageSourceSearch

https://www.instagem.ai/assets/Afiliado-SXIW7yyt.js

js instagem.ai collected 2026-10-05 12:05:39 UTC 26,137 bytes, 1 lines download raw bytes

1import{r as d,W as N,b as k,U as se,j as e,C as E,l as A,O as te,c as w,H as ie,g as D,h as M,ao as W,aq as Q,ar as R,as as G,at as J,z as S,I as $,au as X,ah as _,u as Y,aa as re,ab as le,ac as ne,ad as oe,ae as F,aw as Z,ax as B,ay as ee,az as ae,a as ce,a6 as de,k as fe,ak as me}from"./main-DX7XzkoU.js";import{S as L}from"./skeleton-DN2cjZOe.js";import{T as ue,a as xe,b as U,c as H}from"./tabs-BuRg9jtd.js";import{f as b,d as q}from"./format-jANIzc1h.js";import{C as z}from"./circle-check-DRpR_UoF.js";import{B as pe}from"./banknote-4zCf3LdD.js";import{C as he}from"./clock-DZY59rpR.js";import{C as je}from"./copy-CZIwHXLK.js";import{S as _e}from"./share-2-DpYr0PID.js";import{T as O,a as K,b as T,c as v,d as P,e as y}from"./table-CyYSUJFs.js";import{U as be}from"./upload-CRdrqrw1.js";import{A as ge}from"./arrow-left-Cf41rOjY.js";import{C as ve}from"./coins-CxtjDjJM.js";import{W as ye}from"./wallet-Dgmvon6n.js";import{C as we}from"./chevron-right-D27HfhtL.js";import"./index-D6Z5KIMn.js";function Ne(){const[a,t]=d.useState(null),[s,o]=d.useState(!0),[x,l]=d.useState(null),i=d.useCallback(async()=>{try{o(!0),l(null);const{data:r,error:m}=await N.rpc("get_affiliate_dashboard");if(m){l(m.message);return}t(r)}catch(r){l(r instanceof Error?r.message:"Erro desconhecido")}finally{o(!1)}},[]);return d.useEffect(()=>{i()},[i]),{data:a,loading:s,error:x,refresh:i}}function ke(){const[a,t]=d.useState(null),[s,o]=d.useState(!0),[x,l]=d.useState(null),i=d.useCallback(async()=>{try{o(!0),l(null);const{data:r,error:m}=await N.from("affiliate_settings").select("conversion_rate_brl_per_post, minimum_payout_brl, carencia_days, referred_bonus_pct").eq("id",1).maybeSingle();if(m){l(m.message);return}r&&t(r)}catch(r){l(r instanceof Error?r.message:"Unknown error")}finally{o(!1)}},[]);return d.useEffect(()=>{i()},[i]),{settings:a,loading:s,error:x,refresh:i}}const Ce=({referralCode:a,totalReferrals:t,totalConversions:s,pendingBalance:o,availableBalance:x,lifetimeEarnings:l,referredBonusPct:i})=>{const{t:r}=k(),[m,f]=d.useState(!1),n=a?`${window.location.origin}/c/${a}`:"",u=o+x,j=async()=>{if(n)try{await navigator.clipboard.writeText(n),f(!0),setTimeout(()=>f(!1),2e3)}catch(h){console.warn("Clipboard copy failed:",h)}},p=async()=>{if(!n)return;const h=r("affiliate.share.message",{pct:i});if(navigator.share)try{await navigator.share({title:r("referral.share_title"),text:h,url:n});return}catch(c){if(c instanceof Error&&c.name==="AbortError")return}try{await navigator.clipboard.writeText(`${h} ${n}`),f(!0),setTimeout(()=>f(!1),2e3)}catch(c){console.warn("Clipboard copy failed:",c)}},g=[{icon:se,value:t,label:r("affiliate.stats.referrals"),tint:"text-violet-600 dark:text-violet-400 bg-violet-500/10"},{icon:z,value:s,label:r("affiliate.stats.conversions"),tint:"text-emerald-600 dark:text-emerald-400 bg-emerald-500/10"},{icon:pe,value:b(l),label:r("affiliate.stats.lifetime"),tint:"text-amber-600 dark:text-amber-400 bg-amber-500/10"}];return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"rounded-2xl bg-gradient-to-br from-violet-600 to-fuchsia-600 p-6 text-white shadow-lg shadow-violet-500/20",children:[u>0?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm font-medium text-white/80",children:r("affiliate.balance.title")}),e.jsx("p",{className:"text-4xl font-bold mt-1 tracking-tight",children:b(u)})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm font-medium text-white/80",children:r("affiliate.balance.empty_title")}),e.jsx("p",{className:"text-3xl font-bold mt-1 tracking-tight",children:r("affiliate.balance.empty_value")}),e.jsx("p",{className:"text-sm text-white/80 mt-1.5",children:r("affiliate.balance.empty_hint")})]}),(x>0||o>0)&&e.jsxs("div",{className:"flex flex-wrap gap-2 mt-4",children:[x>0&&e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full bg-white/15 px-3 py-1 text-xs font-medium",children:[e.jsx(z,{className:"w-3.5 h-3.5"}),b(x)," · ",r("affiliate.balance.released_short")]}),o>0&&e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full bg-white/15 px-3 py-1 text-xs font-medium",children:[e.jsx(he,{className:"w-3.5 h-3.5"}),b(o)," · ",r("affiliate.balance.waiting_short")]})]})]}),e.jsx(E,{children:e.jsxs(A,{className:"pt-6",children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:r("affiliate.link_label")}),e.jsx("div",{className:"rounded-xl bg-muted/60 border px-3 py-2.5 text-sm font-mono text-muted-foreground truncate",children:n||"—"}),e.jsxs("div",{className:"flex items-start gap-2 mt-2.5 rounded-lg bg-violet-500/5 border border-violet-500/15 px-3 py-2",children:[e.jsx(te,{className:"w-4 h-4 mt-0.5 shrink-0 text-violet-600 dar
1k:text-violet-400"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("affiliate.share.benefit",{pct:i})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 mt-2.5",children:[e.jsx(w,{variant:"outline",onClick:j,disabled:!n,children:m?e.jsxs(e.Fragment,{children:[e.jsx(ie,{className:"w-4 h-4 mr-2"})," ",r("referral.copied")]}):e.jsxs(e.Fragment,{children:[e.jsx(je,{className:"w-4 h-4 mr-2"})," ",r("referral.copy")]})}),e.jsxs(w,{onClick:p,disabled:!n,children:[e.jsx(_e,{className:"w-4 h-4 mr-2"}),r("referral.share")]})]})]})}),e.jsx("div",{className:"grid grid-cols-3 gap-3",children:g.map(h=>e.jsx(E,{children:e.jsxs(A,{className:"pt-5 pb-4 px-4",children:[e.jsx("div",{className:`w-9 h-9 rounded-lg flex items-center justify-center ${h.tint}`,children:e.jsx(h.icon,{className:"w-5 h-5"})}),e.jsx("p",{className:"text-xl font-bold mt-2.5 leading-tight",children:h.value}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:h.label})]})},h.label))})]})},Se=[{plan:"Pro",monthly:25,yearly:100},{plan:"Elite",monthly:40,yearly:180},{plan:"Scale",monthly:100,yearly:450}],Ee=()=>{const{t:a}=k(),t=[a("affiliate.how.step1"),a("affiliate.how.step2"),a("affiliate.how.step3")];return e.jsxs(E,{children:[e.jsx(D,{children:e.jsx(M,{className:"text-base",children:a("affiliate.how.title")})}),e.jsxs(A,{className:"space-y-5",children:[e.jsx("ol",{className:"space-y-3",children:t.map((s,o)=>e.jsxs("li",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"w-6 h-6 rounded-full bg-violet-500/10 text-violet-600 dark:text-violet-400 text-xs font-bold flex items-center justify-center shrink-0",children:o+1}),e.jsx("span",{className:"text-sm leading-relaxed",children:s})]},o))}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:a("affiliate.how.table_title")}),e.jsx("div",{className:"rounded-lg border overflow-hidden",children:e.jsxs(O,{children:[e.jsx(K,{children:e.jsxs(T,{children:[e.jsx(v,{children:a("affiliate.how.col_plan")}),e.jsx(v,{children:a("affiliate.how.col_monthly")}),e.jsx(v,{children:a("affiliate.how.col_yearly")})]})}),e.jsx(P,{children:Se.map(s=>e.jsxs(T,{children:[e.jsx(y,{className:"font-medium",children:s.plan}),e.jsx(y,{children:b(s.monthly)}),e.jsx(y,{className:"font-semibold text-violet-600 dark:text-violet-400",children:b(s.yearly)})]},s.plan))})]})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("affiliate.how.note")})]})]})};function Ae(){const[a,t]=d.useState(!1),[s,o]=d.useState(null);return{convert:d.useCallback(async l=>{t(!0),o(null);try{const{data:i,error:r}=await N.rpc("convert_balance_to_posts",{p_amount_brl:l});return r?(o(r.message),{success:!1,reason:r.message}):i??{success:!1}}catch(i){const r=i instanceof Error?i.message:"Unknown error";return o(r),{success:!1,reason:r}}finally{t(!1)}},[]),loading:a,error:s}}const Te=({open:a,onOpenChange:t,totalConvertibleBrl:s,conversionRateBrlPerPost:o,onConverted:x})=>{const{t:l}=k(),{convert:i,loading:r}=Ae(),[m,f]=d.useState(""),n=d.useMemo(()=>{const p=m.replace(/[^\d.,]/g,""),g=Math.max(p.lastIndexOf("."),p.lastIndexOf(",")),h=g===-1?p:`${p.slice(0,g).replace(/[.,]/g,"")}.${p.slice(g+1)}`,c=parseFloat(h);return Number.isFinite(c)&&c>0?c:0},[m]),u=d.useMemo(()=>o>0?Math.floor(n/o):0,[n,o]),j=async()=>{if(n<=0){_.error(l("affiliate.convert.invalid_amount"));return}if(n>s){_.error(l("affiliate.convert.insufficient"));return}const p=await i(n);if(p.success)_.success(l("affiliate.convert.success",{posts:p.posts_credited??u})),f(""),x==null||x(),t(!1);else{const g={invalid_amount:"affiliate.convert.invalid_amount",insufficient_balance:"affiliate.convert.insufficient",amount_below_rate:"affiliate.convert.amount_below_rate",settings_missing:"affiliate.convert.settings_missing"},h=p.reason&&g[p.reason];h?_.error(l(h,{rate:p.min_amount_brl??o})):_.error(p.reason||l("affiliate.convert.error"))}};return e.jsx(W,{open:a,onOpenChange:t,children:e.jsxs(Q,{className:"sm:max-w-md",children:[e.jsxs(R,{children:[e.jsx(G,{children:l("affiliate.convert.modal_title")}),e.jsx(J,{children:l("affiliate.convert.rate_info",{rate:o})})]}
1),e.jsxs("div",{className:"space-y-4 mt-2",children:[e.jsxs("div",{children:[e.jsx(S,{htmlFor:"amount",children:l("affiliate.convert.amount_label")}),e.jsx($,{id:"amount",inputMode:"decimal",placeholder:"0,00",value:m,onChange:p=>f(p.target.value),autoFocus:!0}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:l("affiliate.convert.balance_hint",{balance:b(s)})})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-muted/60 border text-sm",children:[e.jsx("p",{className:"text-muted-foreground",children:l("affiliate.convert.preview_label")}),e.jsxs("p",{className:"text-lg font-semibold mt-1",children:["+",u," ",l("affiliate.convert.posts_unit")]})]})]}),e.jsxs(X,{children:[e.jsx(w,{variant:"outline",onClick:()=>t(!1),disabled:r,children:l("common.cancel")}),e.jsx(w,{onClick:j,disabled:r||n<=0,children:l(r?"common.loading":"affiliate.convert.confirm")})]})]})})};function Fe(){const{user:a}=Y(),[t,s]=d.useState(!1),[o,x]=d.useState(null),l=d.useCallback(async m=>{var j;if(!a)throw new Error("not_authenticated");const f=((j=m.name.split(".").pop())==null?void 0:j.toLowerCase())||"pdf",n=`${a.id}/${Date.now()}.${f}`,{error:u}=await N.storage.from("affiliate-invoices").upload(n,m,{upsert:!1,cacheControl:"3600"});if(u)throw u;return n},[a]),i=d.useCallback(async m=>{const{data:f,error:n}=await N.from("affiliate_payouts").select("id").eq("invoice_storage_path",m).limit(1).maybeSingle();if(n){console.warn("[affiliate] orphan cleanup skipped: could not verify payout link",n.message,{path:m});return}if(f){console.warn("[affiliate] orphan cleanup skipped: path is referenced by a payout",{path:m,payoutId:f.id});return}const{error:u}=await N.storage.from("affiliate-invoices").remove([m]);u&&console.warn("[affiliate] orphan invoice cleanup failed:",u.message,{path:m})},[]);return{request:d.useCallback(async m=>{s(!0),x(null);let f=null;try{f=await l(m.invoice_file);const{data:n,error:u}=await N.rpc("request_payout",{p_invoice_number:m.invoice_number,p_invoice_storage_path:f}),j=n??{success:!1};return(u||!j.success)&&await i(f),u?(x(u.message),{success:!1,reason:u.message}):j}catch(n){f&&await i(f);const u=n instanceof Error?n.message:"Erro desconhecido";return x(u),{success:!1,reason:u}}finally{s(!1)}},[l,i]),loading:t,error:o}}const $e=10*1024*1024,V=["application/pdf","image/jpeg","image/png"],Ie=({open:a,onOpenChange:t,availableBrl:s,minimumBrl:o,hasFiscalData:x,onRequested:l})=>{const{t:i}=k(),{request:r,loading:m}
1=Fe(),[f,n]=d.useState(""),[u,j]=d.useState(null),p=d.useRef(null),g=c=>{if(!c){j(null);return}if(!V.includes(c.type)){_.error(i("affiliate.payout.invalid_file_type"));return}if(c.size>$e){_.error(i("affiliate.payout.file_too_large"));return}j(c)},h=async()=>{if(!x){_.error(i("affiliate.payout.missing_fiscal"));return}if(s<o){_.error(i("affiliate.payout.minimum_not_met",{available:b(s),minimum:b(o)}));return}if(!f.trim()){_.error(i("affiliate.payout.missing_invoice_number"));return}if(!u){_.error(i("affiliate.payout.missing_invoice_file"));return}const c=await r({invoice_number:f.trim(),invoice_file:u});if(c.success)_.success(i("affiliate.payout.success")),n(""),j(null),l==null||l(),t(!1);else{const C={missing_fiscal_data:"affiliate.payout.missing_fiscal",missing_invoice_number:"affiliate.payout.missing_invoice_number",missing_invoice_file:"affiliate.payout.missing_invoice_file",invalid_invoice_path:"affiliate.payout.invoice_invalid",invoice_not_found:"affiliate.payout.invoice_invalid",invoice_already_used:"affiliate.payout.invoice_already_used",no_available_balance:"affiliate.payout.no_balance",minimum_not_met:"affiliate.payout.minimum_not_met"},I=c.reason?C[c.reason]:void 0;I==="affiliate.payout.minimum_not_met"?_.error(i(I,{available:b(c.available_brl??s),minimum:b(c.minimum_brl??o)})):_.error(i(I||"affiliate.payout.error"))}};return e.jsx(W,{open:a,onOpenChange:t,children:e.jsxs(Q,{className:"sm:max-w-md",children:[e.jsxs(R,{children:[e.jsx(G,{children:i("affiliate.payout.modal_title")}),e.jsx(J,{children:i("affiliate.payout.modal_description",{available:b(s),minimum:b(o)})})]}),e.jsxs("div",{className:"space-y-4 mt-2",children:[!x&&e.jsx("div",{className:"p-3 rounded-lg bg-amber-500/10 border border-amber-500/30 text-sm text-amber-700 dark:text-amber-400",children:i("affiliate.payout.fiscal_required")}),e.jsxs("div",{children:[e.jsx(S,{htmlFor:"invoice_number",children:i("affiliate.payout.invoice_number_label")}),e.jsx($,{id:"invoice_number",value:f,onChange:c=>n(c.target.value),placeholder:i("affiliate.payout.invoice_number_placeholder"),disabled:!x})]}),e.jsxs("div",{children:[e.jsx(S,{children:i("affiliate.payout.invoice_file_label")}),e.jsx("input",{ref:p,type:"file",className:"hidden",accept:V.join(","),onChange:c=>{var C;return g(((C=c.target.files)==null?void 0:C[0])||null)}}),e.jsxs(w,{type:"button",variant:"outline",className:"w-full justify-start",onClick:()=>{var c;return(c=p.current)==null?void 0:c.click()},disabled:!x,children:[e.jsx(be,{className:"w-4 h-4 mr-2"}),u?u.name:i("affiliate.payout.invoice_file_pick")]})]})]}),e.jsxs(X,{children:[e.jsx(w,{variant:"outline",onClick:()=>t(!1),disabled:m,children:i("common.cancel")}),e.jsx(w,{onClick:h,disabled:m||!x,children:i(m?"common.loading":"affiliate.payout.confirm")})]})]})})};function qe(){const{user:a}=Y(),[t,s]=d.useState(null),[o,x]=d.useState(!0),[l,i]=d.useState(null),r=d.useCallback(async()=>{if(a)try{x(!0),i(null);const{data:f,error:n}=await N.from("affiliate_profiles").select("id, user_id, cnpj, business_name, pix_key_type, pix_key_value").eq("user_id",a.id).maybeSingle();if(n){i(n.message);return}s(f)}catch(f){i(f instanceof Error?f.message:"Unknown error")}finally{x(!1)}},[a]);d.useEffect(()=>{r()},[r]);const m=d.useCallback(async f=>{if(!a)throw new Error("not_authenticated");const{data:n,error:u}=await N.from("affiliate_profiles").upsert({user_id:a.id,cnpj:f.cnpj,business_name:f.business_name,pix_key_type:f.pix_key_type,pix_key_value:f.pix_key_value,updated_at:new Date().toISOString()},{onConflict:"user_id"}).select().single();if(u)throw u;return s(n),n},[a]);return{profile:t,loading:o,error:l,upsert:m,refresh:r}}const Le=({onSaved:a})=>{const{t}=k(),{profile:s,loading:o,upsert:x}=qe(),[l,i]=d.useState(""),[r,m]=d.useState(""),[f,n]=d.useState("cnpj"),[u,j]=d.use
1State(""),[p,g]=d.useState(!1);d.useEffect(()=>{s&&(i(s.cnpj||""),m(s.business_name||""),n(s.pix_key_type||"cnpj"),j(s.pix_key_value||""))},[s]);const h=async()=>{if(!l||!r||!u){_.error(t("affiliate.fiscal.required_fields"));return}g(!0);try{await x({cnpj:l,business_name:r,pix_key_type:f,pix_key_value:u}),_.success(t("affiliate.fiscal.saved")),a==null||a()}catch(c){_.error(c instanceof Error?c.message:t("affiliate.fiscal.save_error"))}finally{g(!1)}};return e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:t("affiliate.fiscal.description")}),e.jsxs("div",{children:[e.jsx(S,{htmlFor:"business_name",children:t("affiliate.fiscal.business_name")}),e.jsx($,{id:"business_name",value:r,onChange:c=>m(c.target.value),disabled:o,placeholder:t("affiliate.fiscal.business_name_placeholder")})]}),e.jsxs("div",{children:[e.jsx(S,{htmlFor:"cnpj",children:t("affiliate.fiscal.cnpj")}),e.jsx($,{id:"cnpj",value:l,onChange:c=>i(c.target.value),disabled:o,placeholder:"00.000.000/0000-00"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(S,{htmlFor:"pix_key_type",children:t("affiliate.fiscal.pix_key_type")}),e.jsxs(re,{value:f,onValueChange:c=>n(c),children:[e.jsx(le,{id:"pix_key_type",children:e.jsx(ne,{})}),e.jsxs(oe,{children:[e.jsx(F,{value:"cnpj",children:t("affiliate.fiscal.pix_type.cnpj")}),e.jsx(F,{value:"cpf",children:t("affiliate.fiscal.pix_type.cpf")}),e.jsx(F,{value:"email",children:t("affiliate.fiscal.pix_type.email")}),e.jsx(F,{value:"phone",children:t("affiliate.fiscal.pix_type.phone")}),e.jsx(F,{value:"random",children:t("affiliate.fiscal.pix_type.random")})]})]})]}),e.jsxs("div",{children:[e.jsx(S,{htmlFor:"pix_key_value",children:t("affiliate.fiscal.pix_key_value")}),e.jsx($,{id:"pix_key_value",value:u,onChange:c=>j(c.target.value),disabled:o})]})]}),e.jsx("div",{className:"pt-2",children:e.jsx(w,{onClick:h,disabled:p||o,children:t(p?"common.saving":"common.save")})})]})},De=a=>{switch(a){case"pending":return"bg-amber-500/10 text-amber-700 dark:text-amber-400";case"available":return"bg-emerald-500/10 text-emerald-700 dark:text-emerald-400";case"converted":return"bg-violet-500/10 text-violet-700 dark:text-violet-400";case"withdrawn":return"bg-sky-500/10 text-sky-700 dark:text-sky-400";case"reverted":return"bg-rose-500/10 text-rose-700 dark:text-rose-400"}},Me=({rows:a})=>{const{t}=k();return!a||a.length===0?e.jsx("div",{className:"text-sm text-muted-foreground py-8 text-center",children:t("affiliate.commissions.empty")}):e.jsx("div",{className:"rounded-lg border overflow-hidden",children:e.jsxs(O,{children:[e.jsx(K,{children:e.jsxs(T,{children:[e.jsx(v,{children:t("affiliate.commissions.col_date")}),e.jsx(v,{children:t("affiliate.commissions.col_amount")}),e.jsx(v,{children:t("affiliate.commissions.col_period")}),e.jsx(v,{children:t("affiliate.commissions.col_status")}),e.jsx(v,{children:t("affiliate.commissions.col_available_at")})]})}),e.jsx(P,{children:a.map(s=>e.jsxs(T,{children:[e.jsx(y,{className:"whitespace-nowrap",children:q(s.created_at)}),e.jsx(y,{className:"font-medium",children:b(s.amount_brl)}),e.jsx(y,{className:"text-sm text-muted-foreground",children:t(`affiliate.commissions.period.${s.billing_period}`)}),e.jsx(y,{children:e.jsx("span",{className:`text-xs px-2 py-1 rounded-md font-medium ${De(s.status)}`,children:t(`affiliate.status.${s.status}`)})}),e.jsx(y,{className:"whitespace-nowrap text-sm text-muted-foreground",children:q(s.available_at)})]},s.id))})]})})},Oe=["earn","amount","cost_limit","easy_sell","where_share","available","no_cnpj","cnpj_type","trust","refund"],Ke=()=>{const{t:a}=k();return e.jsxs(E,{children:[e.jsx(D,{children:e.jsx(M,{className:"text-base",children:a("affiliate.faq.title")})}),e.jsx(A,{children:e.jsx(Z,{type:"single",collapsible:!0,children:Oe.map(t=>e.jsxs(B,{value:t,children:[e.jsx(ee,{className:"text-sm text-left hover:no-underline",children:a(`affiliate.faq.${t}.q`)}),e.jsx(ae,{className:"text-sm text-muted-foreground leading-relaxed",children:a(`affiliate.faq.${t}.a`)})]},t))})})]})},Pe=a=>{switch(a){case"requested":return"bg-amber-500/10 text-amber-700 dark:text-amber-400";case"approved":return"bg-sky-500/10 text-sky-700 dark:text-sky-400";case"paid":return"bg-emerald-500/10 text-emerald-700 dark:text-emerald-400";case"rejected":return"bg-rose-500/10 text-rose-700 dark:text-rose-400";case"canceled":return"bg-muted text-muted-foreground"}},Ue=({rows:a})=>{const{t}=k();return!a||a.length===0?e.jsx("div",{className:"text-sm text-muted-foreground py-8 text-center",children:t("affiliate.payouts.empty")}):e.jsx("div",{className:"rounded-lg border overflow-hidden",children:e.jsxs(O,{children:[e.jsx(K,{children:e.jsxs(T,{children:[e.jsx(v,{children:t("affiliate.payouts.col_date")}),e.jsx(v,{children:t("affiliate.payouts.col_amount")}),e.jsx(v,{children:t("affiliate.payouts.col_invoice")}),e.jsx(v,{children:t("affiliate.payouts.col_status")}),e.jsx(v,{children:t("affiliate.payouts.col_paid_at")})]})}),e.jsx(P,{children:a.map(s=>e.jsxs(T,{children:[e.jsx(y,{className:"whitespace-nowrap",children:q(s.created_at)}),e.jsx(y,{className:"font-medium",children:b(s.amount_brl)}),e.jsx(y,{className:"text-sm text-muted-foreground font-mono",children:s.invoice_number||"—"}),e.jsxs(y,{children:[e.jsx("span",{className:`text-xs px-2 py-1 rounded-md font-medium ${Pe(s.status)}`,children:t(`affiliate.status.${s.status}`)}),s.status==="rejected"&&s.rejection_reason&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:s.rejection_reason})]}),e.jsx(y,{className:"whitespace-nowrap text-sm text-muted-foreground",children:q(s.paid_at)})]},s.id))})]})})},ia=()=>{const{t:a}=k(),t=ce(),{data:s,loading:o,error:x,refresh:l}=Ne(),{settings:i,loading:r,error:m,refresh:f}=ke(),[n,u]=d.useState(!1),[j,p]=d.useState(!1),g=()=>{l(),f()};if(o||r)return e.jsxs("div",{className:"container mx-auto max-w-3xl py-8 px-4 space-y-4",children:[e.jsx(L,{className:"h-10 w-1/3"}),e.jsx(L,{className:"h-32 w-full"}),e.jsx(L,{className:"h-40 w-full"})]});if(x||m||!s||!i)return e.jsx("div",{className:"container mx-auto max-w-3xl py-8 px-4",children:e.jsxs(E,{className:"border-destructive",children:[e.jsxs(D,{children:[e.jsxs(M,{className:"flex items-center gap-2 text-destructive",children:[e.jsx(de,{className:"h-5 w-5"}),a("affiliate.error.title")]}),e.jsx(fe,{children:x||m||a("affiliate.error.unknown")})]}),e.jsx(A,{children:e.jsxs(w,{onClick:g,variant:"outline",size:"sm",children:[e.jsx(me,{className:"h-4 w-4 mr-2"}),a("affiliate.error.retry")]})})]})});const h=s.pending_balance+s.available_balance,c=h>0,C=s.available_balance>=i.minimum_payout_brl;return e.jsxs("div",{className:"container mx-auto max-w-3xl py-8 px-4 space-y-6",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(w,{variant:"ghost",size:"icon",onClick:()=>
1t("/dashboard"),"aria-label":a("common.back"),className:"shrink-0 -ml-2",children:e.jsx(ge,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:a("affiliate.page_title")}),e.jsx("p",{className:"text-muted-foreground mt-1",children:a("affiliate.page_subtitle")})]})]}),e.jsx(Ce,{referralCode:s.referral_code,totalReferrals:s.total_referrals,totalConversions:s.total_conversions,pendingBalance:s.pending_balance,availableBalance:s.available_balance,lifetimeEarnings:s.lifetime_earnings,referredBonusPct:i.referred_bonus_pct}),e.jsx(Ee,{}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-semibold text-muted-foreground px-1 mb-2",children:a("affiliate.actions.section_title")}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("button",{type:"button",onClick:()=>u(!0),disabled:!c,className:"text-left rounded-xl border bg-card p-4 transition-all hover:border-violet-500/50 hover:shadow-sm disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:border-border disabled:hover:shadow-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"w-9 h-9 rounded-lg flex items-center justify-center bg-violet-500/10 text-violet-600 dark:text-violet-400",children:e.jsx(ve,{className:"w-5 h-5"})}),e.jsx("span",{className:"font-semibold",children:a("affiliate.actions.convert")})]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-2.5",children:a("affiliate.actions.convert_desc",{rate:i.conversion_rate_brl_per_post})})]}),e.jsxs("button",{type:"button",onClick:()=>p(!0),disabled:!C,className:"text-left rounded-xl border bg-card p-4 transition-all hover:border-emerald-500/50 hover:shadow-sm disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:border-border disabled:hover:shadow-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"w-9 h-9 rounded-lg flex items-center justify-center bg-emerald-500/10 text-emerald-600 dark:text-emerald-400",children:e.jsx(ye,{className:"w-5 h-5"})}),e.jsx("span",{className:"font-semibold",children:a("affiliate.actions.withdraw")})]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-2.5",children:a("affiliate.actions.withdraw_desc")}),!C&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1.5",children:a("affiliate.actions.withdraw_locked",{minimum:b(i.minimum_payout_brl)})})]})]})]}),e.jsx(E,{children:e.jsx(A,{className:"pt-6",children:e.jsxs(ue,{defaultValue:"commissions",children:[e.jsxs(xe,{children:[e.jsx(U,{value:"commissions",children:a("affiliate.commissions.title")}),e.jsx(U,{value:"payouts",children:a("affiliate.payouts.title")})]}),e.jsx(H,{value:"commissions",className:"mt-4",children:e.jsx(Me,{rows:s.recent_commissions})}),e.jsx(H,{value:"payouts",className:"mt-4",children:e.jsx(Ue,{rows:s.recent_payouts})})]})})}),e.jsx(Ke,{}),e.jsx(Z,{type:"single",collapsible:!0,children:e.jsxs(B,{value:"fiscal",className:"border rounded-lg px-4",children:[e.jsx(ee,{className:"text-base font-semibold hover:no-underline",children:e.jsxs("span",{className:"flex items-center gap-2",children:[a("affiliate.fiscal.section_title"),!s.has_fiscal_data&&e.jsxs("span",{className:"text-xs font-normal text-amber-600 dark:text-amber-400",children:[e.jsx(we,{className:"w-3 h-3 inline"}),a("affiliate.fiscal.pending_badge")]})]})}),e.jsx(ae,{className:"pb-4",children:e.jsx(Le,{onSaved:l})})]})}),e.jsx("p",{className:"text-center text-xs text-muted-foreground",children:e.jsx("button",{type:"button",onClick:()=>t("/afiliado/regulamento"),className:"underline underline-offset-2 hover:text-foreground transition-colors",children:a("affiliate.terms_link")})}),e.jsx(Te,{open:n,onOpenChange:u,totalConvertibleBrl:h,conversionRateBrlPerPost:i.conversion_rate_brl_per_post,onConverted:l}),e.jsx(Ie,{open:j,onOpenChange:p,availableBrl:s.available_balance,minimumBrl:i.minimum_payout_brl,hasFiscalData:s.has_fiscal_data,onRequested:l})]})};export{ia 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.