PageSourceSearch

https://mostreams-com.lovable.app/assets/royalty-splits-B1Lq7FLy.js

js mostreams-com.lovable.app collected 2026-10-03 03:36:07 UTC 6,412 bytes, 3 lines download raw bytes

1import{bz as G,r as a,j as t,bA as H,B as h,a$ as J,s as c,v as n}from"./index-BNrdOJig.js";import{I as g}from"./input-CwAqzCK4.js";import{P as K}from"./plus-BewcIKll.js";import{T as Q}from"./trash-2-DqSHrMYS.js";const V=["producer","featured","writer","engineer","label"];function ee(){const i=G(),[b,E]=a.useState([]),[o,P]=a.useState([]),[p,$]=a.useState(0),[L,v]=a.useState(!0),[O,f]=a.useState(!1),[m,A]=a.useState(""),[u,j]=a.useState(""),[N,w]=a.useState(""),[y,q]=a.useState("producer"),[S,k]=a.useState("10"),[_,C]=a.useState(!1),x=async()=>{if(!i?.id)return;v(!0);const[e,r,d]=await Promise.all([c.from("tracks").select("id, title").eq("owner_id",i.id).order("created_at",{ascending:!1}),c.from("revenue_splits").select("*").eq("owner_id",i.id).order("created_at",{ascending:!1}),c.from("artist_earnings_ledger").select("net_cents").eq("artist_id",i.id)]);E(e.data??[]),P(r.data??[]),$((d.data??[]).reduce((s,l)=>s+(l.net_cents??0),0)),v(!1)};a.useEffect(()=>{x()},[i?.id]);const T=async()=>{const e=Number(S);if(!m){n.error("Pick a track");return}if(!u.trim()){n.error("Collaborator name is required");return}if(!Number.isFinite(e)||e<=0||e>100){n.error("Share must be between 1 and 100");return}const r=o.filter(s=>s.track_id===m).reduce((s,l)=>s+Number(l.percentage),0);if(r+e>100){n.error(`That track already has ${r}% allocated`);return}C(!0);const{error:d}=await c.from("revenue_splits").insert({owner_id:i.id,track_id:m,collaborator_name:u.trim(),collaborator_email:N.trim()||null,role:y,percentage:e});if(C(!1),d){n.error(d.message);return}n.success(`${u} gets ${e}% of that track`),j(""),w(""),k("10"),f(!1),x()},I=async e=>{await c.from("revenue_splits").delete().eq("id",e.id),n.success("Split removed"),x()},R=e=>b.find(r=>r.id===e)?.title??"—",U=()=>{const e=`Release,Collaborator,Share %,Role,Status
2`,r=o.map(l=>[R(l.track_id),l.collaborator_name??"",l.percentage,l.role??"",l.accepted_at?"accepted":"pending"].map(M=>`"${String(M).replace(/"/g,'""')}"`).join(",")).join(`
3`),d=URL.createObjectURL(new Blob([e+r],{type:"text/csv"})),s=document.createElement("a");s.href=d,s.download="royalty-splits.csv",s.click(),URL.revokeObjectURL(d)},z=new Set(o.map(e=>e.collaborator_email??e.collaborator_name)).size,B=o.reduce((e,r)=>e+Number(r.percentage),0),F=p/100*0,D=p/100*(Math.min(B,100)/100);return t.jsx(H,{profile:i,title:"Royalty Splits",subtitle:"Auto-split earnings with collaborators",children:t.jsxs("div",{className:"space-y-6",children:[t.jsx("p",{className:"text-sm text-muted-foreground max-w-3xl",children:"Set who gets paid what when a release earns money. Splits are applied automatically at payout, and each collaborator's share is deducted from your net earnings for that track."}),t.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[{label:"Active splits",value:o.length},{label:"Collaborators",value:z},{label:"Lifetime net",value:`$${(p/100).toFixed(2)}`},{label:"Owed to collaborators",value:`$${D.toFixed(2)}`}].map(e=>t.jsxs("div",{className:"rounded-2xl border border-white/5 p-5",style:{background:"var(--backoffice-card)"},children:[t.jsx("div",{className:"text-[10px] font-bold uppercase tracking-[0.18em] text-muted-foreground",children:e.label}),t.jsx("div",{className:"font-display text-3xl mt-2",children:e.value})]},e.label))}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs(h,{onClick:()=>f(e=>!e),className:"bg-primary text-primary-foreground hover:opacity-90",children:[t.jsx(K,{className:"w-4 h-4 mr-1.5"})," New split"]}),t.jsxs(h,{variant:"outline",onClick:U,disabled:o.length===0,children:[t.jsx(J,{className:"w-4 h-4 mr-1.5"})," Export"]}),t.jsx("span",{className:"text-xs text-muted-foreground",children:(F>0,"")})]}),O&&t.jsxs("div",{className:"rounded-2xl border border-white/5 p-5 grid md:grid-cols-5 gap-3",style:{background:"var(--backoffice-card)"},children:[t.jsxs("select",{value:m,onChange:e=>A(e.target.value),className:"h-10 rounded-md border border-input bg-[var(--dropdown,#000)] px-3 text-sm",children:[t.jsx("option",{value:"",children:"Select track…"}),b.map(e=>t.jsx("option",{value:e.id,children:e.title},e.id))]}),t.jsx(g,{placeholder:"Collaborator",value:u,onChange:e=>j(e.target.value)}),t.jsx(g,{placeholder:"Email (optional)",value:N,onChange:e=>w(e.target.value)}),t.jsx("select",{value:y,onChange:e=>q(e.target.value),className:"h-10 rounded-md border border-input bg-[var(--dropdown,#000)] px-3 text-sm",children:V.map(e=>t.jsx("option",{value:e,children:e},e))}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(g,{type:"number",min:1,max:100,value:S,onChange:e=>k(e.target.value)}),t.jsx(h,{onClick:T,disabled:_,children:_?"…":"Add"})]})]}),t.jsxs("div",{className:"rounded-2xl border border-white/5 overflow-hidden",style:{background:"var(--backoffice-card)"},children:[t.jsxs("div",{className:"grid grid-cols-5 px-5 py-3 border-b border-white/5 text-[10px] font-bold uppercase tracking-[0.18em] text-muted-foreground",children:[t.jsx("div",{children:"Release"}),t.jsx("div",{children:"Collaborator"}),t.jsx("div",{children:"Share %"}),t.jsx("div",{children:"Role"}),t.jsx("div",{className:"text-right",children:"Status"})]}),L?t.jsx("div",{className:"p-10 text-center text-sm text-muted-foreground",children:"Loading…"}):o.length===0?t.jsxs("div",{className:"p-10 text-center",children:[t.jsx("div",{className:"font-display text-lg mb-1",children:"No splits configured"}),t.jsx("p",{className:"text-sm text-muted-foreground",children:"Add a split to any release and earnings will be divided automatically on payout."})]}):o.map(e=>t.jsxs("div",{className:"grid grid-cols-5 px-5 py-4 border-b border-white/5 text-sm items-center",children:[t.jsx("div",{className:"font-semibold truncate",children:R(e.track_id)}),t.jsxs("div",{className:"truncate",children:[e.collaborator_name,e.collaborator_email&&t.jsx("div",{className:"text-xs text-muted-foreground truncate",children:e.collaborator_email})]}),t.jsxs("div",{children:[Number(e.percentage),"%"]}),t.jsx("div",{className:"capitalize text-muted-foreground",children:e.role??"—"}),t.jsxs("div",{className:"text-right text-muted-foreground flex items-center justify-end gap-3",children:[e.accepted_at?"Accepted":"Pending",t.jsx("button",{onClick:()=>I(e),"aria-label":"Remove split",className:"hover:text-destructive",children:t.jsx(Q,{className:"w-4 h-4"})})]})]},e.id))]})]})})}export{ee as component};

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.