1import{c as q,k as P,a as C,r as y,b as j,s as l,d as D,j as e,at as E,B as w,N,E as A,t as v}from"./index-DH6psoju.js";import{C as b}from"./card-2dFQ2rB4.js";import{T as R,a as $,b as f,c as B}from"./tabs-BRzHnEwv.js";import{R as F}from"./refresh-cw-hVLaZu7_.js";import{A as I}from"./arrow-up-right-BbItHs-r.js";import"./index-DVsHZCFw.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const O=q("ArrowDownToLine",[["path",{d:"M12 17V3",key:"1cwfxf"}],["path",{d:"m6 11 6 6 6-6",key:"12ii2o"}],["path",{d:"M19 21H5",key:"150jfl"}]]),d=n=>(n/100).toLocaleString("en-US",{style:"currency",currency:"USD"}),W=()=>{P();const{user:n}=C(),[x,p]=y.useState(!1),u=j({queryKey:["stripe-balance",n==null?void 0:n.id],queryFn:async()=>{const{data:s,error:r}=await l.functions.invoke("stripe-payouts",{body:{action:"balance"}});if(r)throw r;return s},enabled:!!n,staleTime:3e4}),i=j({queryKey:["earnings-transactions",n==null?void 0:n.id],enabled:!!n,queryFn:async()=>{const s=n.id,[r,L,M,T]=await Promise.all([l.from("booking_requests").select("id, status, rate_cents, platform_fee_cents, paid_at, details").eq("target_id",s).in("status",["paid","delivered","checked_in","completed"]).order("paid_at",{ascending:!1}).limit(100),l.from("studio_bookings").select("id, status, amount_cents, platform_fee_cents, paid_at, completed_at").eq("studio_owner_id",s).in("status",["paid","completed"]).order("paid_at",{ascending:!1}).limit(100),l.from("shoot_plan_talent").select("id, invoice_status, rate_cents, platform_fee_cents, paid_at, completed_at").eq("user_id",s).in("invoice_status",["pending_payout","paid"]).order("paid_at",{ascending:!1}).limit(100),l.from("referral_commission_payouts").select("id, source, source_ref, referral_share_cents, status, created_at").eq("referrer_id",s).order("created_at",{ascending:!1}).limit(100)]),c=[];return(r.data??[]).forEach(t=>{var g;const o=t.platform_fee_cents??Math.round((t.rate_cents??0)*.2);c.push({id:`b-${t.id}`,source:"booking",label:((g=t.details)==null?void 0:g.title)||"Booking",gross_cents:t.rate_cents??0,net_cents:(t.rate_cents??0)-o,status:t.status,created_at:t.paid_at??new Date().toISOString()})}),(L.data??[]).forEach(t=>{const o=t.platform_fee_cents??Math.round((t.amount_cents??0)*.2);c.push({id:`s-${t.id}`,source:"studio_booking",label:"Studio booking",gross_cents:t.amount_cents??0,net_cents:(t.amount_cents??0)-o,status:t.status,created_at:t.paid_at??t.completed_at??new Date().toISOString()})}),(M.data??[]).forEach(t=>{const o=t.platform_fee_cents??Math.round((t.rate_cents??0)*.2);c.push({id:`sh-${t.id}`,source:"shoot_invoice",label:"Shoot invoice",gross_cents:t.rate_cents??0,net_cents:(t.rate_cents??0)-o,status:t.invoice_status,created_at:t.paid_at??t.completed_at??new Date().toISOString()})}),(T.data??[]).forEach(t=>{c.push({id:`r-${t.id}`,source:"premium_referral",label:`Premium referral (${t.source})`,gross_cents:t.referral_share_cents??0,net_cents:t.referral_share_cents??0,status:t.status,created_at:t.created_at})}),c.sort((t,o)=>+new Date(o.created_at)-+new Date(t.created_at)),c},staleTime:3e4}),k=y.useMemo(()=>(i.data??[]).reduce((s,r)=>(["paid","completed"].includes(r.status)&&(s.earned+=r.net_cents),s),{earned:0}),[i.data]),m=D({mutationFn:async()=>{const{data:s,error:r}=await l.functions.invoke("stripe-payouts",{body:{action:"payout"}});if(r)throw r;if(s.error)throw new Error(s.error);return s},onSuccess:s=>{v({title:"Payout requested",description:`${d(s.amount_cents)} sent to your bank.`}),u.refetch()},onError:s=>v({title:"Payout failed",description:(s==null?void 0:s.message)??"Try again later",variant:"destructive"})}),S=async()=>{p(!0),await Promise.all([u.refetch(),i.refetch()]),p(!1)},a=u.data,_=(a==null?void 0:a.available_cents)??0,h=(a==null?void 0:a.pending_cents)??0;return e.jsx("div",{className:"flex flex-col h-full min-h-0 overflow-hidden",children:e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[e.jsx("div",{className:"p-4 pb-2",children:e.jsx(b,{className:"p-4 bg-muted/30 border-none shadow-none",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"h-12 w-12 rounded-full bg-primary/20 flex items-center justify-center",children:e.jsx(E,{className:"h-6 w-6 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Available Balance"}),e.jsx("p",{className:"text-3xl font-bold text-foreground",children:u.isLoading?"â¦":d(_)}),h>0&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:[d(h)," pending"]})]})]}),e.jsx(w,{variant:"ghost",size:"icon",onClick:S,disabled:x,"aria-label":"Refresh balance",children:e.jsx(F,{className:`h-4 w-4 ${x?"animate-spin":""}`})})]})})}),e.jsxs("div",{className:"px-4 pb-3 space-y-2",children:[e.jsx(w,{className:"w-full",disabled:!(a!=null&&a.connected)||!(a!=null&&a.payouts_enabled)||_<=0||m.isPending,onClick:()=>m.mutate(),children:m.isPending?e.jsxs(e.Fragment,{children:[e.jsx(N,{className:"h-4 w-4 mr-2 animate-spin"})," Processingâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(O,{className:"h-4 w-4 mr-2"})," Pay out to bank"]})}),a&&!a.connected&&e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:"Connect Stripe in your profile to receive payouts."}),(a==null?void 0:a.connected)&&!(a!=null&&a.payouts_enabled)&&e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:"Finish your Str
6ipe onboarding to enable payouts."})]}),e.jsxs(R,{defaultValue:"all",className:"px-4",children:[e.jsxs($,{className:"w-full",children:[e.jsx(f,{value:"all",className:"flex-1 text-xs",children:"All"}),e.jsx(f,{value:"bookings",className:"flex-1 text-xs",children:"Bookings"}),e.jsx(f,{value:"referrals",className:"flex-1 text-xs",children:"Referrals"})]}),["all","bookings","referrals"].map(s=>e.jsxs(B,{value:s,className:"mt-3 space-y-2",children:[i.isLoading&&e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(N,{className:"h-5 w-5 animate-spin text-muted-foreground"})}),!i.isLoading&&(i.data??[]).filter(r=>s==="all"?!0:s==="referrals"?r.source==="premium_referral":r.source!=="premium_referral").map(r=>e.jsx(b,{className:"p-3 bg-muted/20 border-none shadow-none",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("div",{className:"h-8 w-8 rounded-full bg-primary/10 flex items-center justify-center flex-shrink-0",children:e.jsx(I,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-foreground truncate",children:r.label}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[A(new Date(r.created_at),"MMM d, yyyy")," · ",r.status]})]})]}),e.jsxs("p",{className:"text-sm font-semibold text-foreground flex-shrink-0 ml-2",children:["+",d(r.net_cents)]})]})},r.id)),!i.isLoading&&(i.data??[]).length===0&&e.jsx("p",{className:"text-center text-sm text-muted-foreground py-8",children:"No earnings yet."})]},s))]}),e.jsxs("div",{className:"px-4 py-4 text-xs text-muted-foreground text-center",children:["Lifetime earnings: ",e.jsx("span",{className:"text-foreground font-semibold",children:d(k.earned)})]})]})})};export{W 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.