1import{u as Ht,c as Yt,b as Zt,bb as qt,r as s,j as e,S as ot,C as w,d as A,e as F,f as J,g as U,B as g,L as _e,h as Gt,aY as Jt,G as Ce}from"./index-Cbruulzy.js";import{B as Ne}from"./badge-DDrBl-nU.js";import{C as Qt}from"./checkbox-CS2SwTR7.js";import{I as m}from"./input-NDk1Z9Qt.js";import{L as u}from"./label-CNkV1J_C.js";import{S as Se,a as ke,b as we,c as Ae,d as Fe}from"./select-MWxKtGSP.js";import{A as De}from"./AppShell-Cm3arvdk.js";import{n as Ee,T as Kt,C as ea,b as ta}from"./legal-company-name-CG-HivfF.js";import{e as Te,v as aa,t as sa}from"./deliverables-TRPafTWp.js";import{u as na}from"./deliverable-vocabulary-DQ73ajYV.js";import"./index-CN8Upzs-.js";import"./index-8xqJYClv.js";import"./popover-DGNiKMx7.js";import"./Combobox-BqS_DH9P.js";const ut="ABCDEFGHJKLMNPQRSTUVWXYZ23456789";function ra(c=4){let p="";for(let f=0;f<c;f++)p+=ut[Math.floor(Math.random()*ut.length)];return p}function ia(c){return(c??"").toUpperCase().replace(/[^A-Z]+/g,"").slice(0,4)||"CRTR"}function la(c,p){return`INFL-${ia(c)}-${p}`}const ca=/^[A-Z0-9]+(-[A-Z0-9]+)*$/;function da(c){const p=c.trim();return p.length>0&&p.length<=60&&ca.test(p)}const oa="https://jxgrmfdufarwmiaiugqu.supabase.co/functions/v1/admin-crm",le=/^[^@\s]+@[^@\s]+\.[^@\s]+$/;function ua(c,p){const f=new Set,_=[];for(const E of c.split(",")){const r=E.trim();if(!r)continue;if(r.length>255||!le.test(r))return{error:`"${r.slice(0,40)}" doesn't look like a valid email â check the CC list.`};const T=r.toLowerCase();if(T===p.trim().toLowerCase())return{error:`"${r}" is already the recipient â remove it from the CC list.`};f.has(T)||(f.add(T),_.push(r))}return _.length>5?{error:"List at most 5 CC addresses."}:{emails:_}}function D(c){return c.toLocaleString("en-US",{style:"currency",currency:"USD",maximumFractionDigits:2})}const ma=10*1024*1024;function Pe(c){return c?c.type==="application/pdf"||c.name.toLowerCase().endsWith(".pdf")?c.size>ma?"The PDF must be 10 MB or smaller.":null:"Attach a PDF file.":"Attach the signed contract PDF."}function ha(c){return new Promise(p=>{const f=new FileReader;f.onload=()=>{const _=f.result;p(_.slice(_.indexOf(",")+1))},f.onerror=()=>p(null),f.readAsDataURL(c)})}const pa={invalid_pdf:"That file isn't a valid PDF.",pdf_too_large:"The PDF must be 10 MB or smaller.",signed_at_in_future:"Signed date can't be in the future.",invalid_signed_at:"Enter a valid signed date.",missing_signatory:"Add a signatory name and a valid email.",pdf_upload_failed:"Couldn't upload the signed PDF â try again.",installments_require_fee:"Enter a total fee before saving a payment schedule.",invalid_flat_fee:"Enter a valid flat fee.",invalid_per_deliverable_amount:"Enter a valid amount per deliverable, greater than 0.",per_line_amount_missing:"Every deliverable needs a fee greater than 0 before this contract can save.",...ta};async function O(c){const{data:{session:p}}=await Gt.auth.getSession();if(!p)return null;const f=await fetch(oa,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${p.access_token}`,apikey:"sb_publishable_pa3Q_IQij0VmW-foLMM-wA_vhXc_6av"},body:JSON.stringify(c)});return f.ok&&!/^(list|get)/.test(String(c.action??""))&&Jt(),f}function Fa(){const{user:c,loading:p}=Ht(),{canMutate:f}=Yt(),_=Zt(),{creator:E}=qt({from:"/platform_/admin/deals/new"}),[r,T]=s.useState("individual"),[ce,mt]=s.useState([]),[C,ht]=s.useState(""),[de,pt]=s.useState(""),[Re,xt]=s.useState([]),[Le,Ie]=s.useState(!1),[h,N]=s.useState([]),[z,gt]=s.useState(""),[$e,ft]=s.useState(""),[Me,vt]=s.useState(null),[Ue]=s.useState(()=>ra()),[Q,yt]=s.useState(""),[v,Oe]=s.useState("send"),[oe,jt]=s.useState(null),[ze,bt]=s.useState(null),[I,_t]=s.useState(""),[K,Ct]=s.useState(""),[ee,Nt]=s.useState(""),[ue,St]=s.useState(!1),[x,me]=s.useState("lump_sum"),[te,B]=s.useState("agency"),[he,Be]=s.useState(!1),[Ve,We]=s.useState(null),[V,kt]=s.useState(""),[W,pe]=s.useState([]),[X,wt]=s.useState(""),[Xe,At]=s.useState("2 weeks before and after each post goes live"),[xe,ge]=s.useState(""),[He,Ft]=s.useState(!1),[Ye,Ze]=s.useState(""),[qe,Dt]=s.useState(!1),[fe,Ge]=s.useState(""),[Je,Et]=s.useState(""),[ae,S]=s.useState(!1),[ve,d]=s.useState(null),[Tt,se]=s.useState(!1),Pt=r==="individual"?h[0]?.creator.id??null:null;s.useEffect(()=>{Ge("")},[Pt]);const{activeContentTypes:H,activeCampaignTags:ne,loading:Qe,error:Ke}=na(),P=s.useCallback(()=>({...Te(),content_type:H.find(t=>t.value!=="other")?.value??H[0]?.value??Te().content_type,campaign_tag:ne[0]?.value??Te().campaign_tag}),[H,ne]);s.useEffect(()=>{(async()=>{const t=await O({action:"list_agencies"});if(t?.ok){const a=await t.json().catch(()=>({}));mt((a.agencies??[]).map(n=>({id:n.id,name:n.name})))}})()},[]);const et=s.useCallback(t=>{N(a=>a.some(n=>n.creator.id===t.id)?a:r==="individual"?[{creator:t,deliverables:[P()]}]:[...a,{creator:t,deliverables:[P()]}])},[r,P]),Rt=s.useCallback(t=>{N(a=>a.some(n=>n.creator.id===t.id)?a.filter(n=>n.creator.id!==t.id):r==="individual"?[{creator:t,deliverables:[P()]}]:[...a,{creator:t,deliverables:[P()]}])},[r,P]),tt=s.useRef(null);s.useEffect(()=>{!E||!c||tt.current!==E&&(async()=>{const t=await O({action:"get_creator",creator_id:E});if(!t?.ok)return;const n=(await t.json().catch(()=>({})))?.creator;n?.id&&(tt.current=E,et({id:n.id,full_name:n.full_name,primary_handle:n.primary_handle,primary_platform:n.primary_platform,email:n.email??null}))})()},[E,c,et]);const at=s.useCallback(async()=>{Ie(!0);const t=await O({action:"list",page:1,page_size:20,search:de.trim()||void 0});if(t?.ok){const a=await t.json().catch(()=>({}));xt(a.rows??[])}Ie(!1)},[de]);s.useEffect(()=>{if(!c)return;const t=setTimeout(()=>{at()},250);return()=>clearTimeout(t)},[c,at]),s.useEffect(()=>{const t=h[0]?.creator;yt(t?la(t.full_name,Ue):"")},[h,Ue]),s.useEffect(()=>{if(r!=="agency"||!C){We(null);return}(async()=>{const t=await O({action:"get_agency",agency_id:C});if(!t?.ok)return;const a=await t.json().catch(()=>({}));We(a?.agency?.payout_recipient==="creators"?"creators":"agency")})()},[r,C]),s.useEffect(()=>{he||B(Ve??"agency")},[Ve,he]);const re=s.useRef(null);s.useEffect(()=>{x==="lump_sum"?(he&&(re.current=te),B("agency")):re.current&&(B(re.current),re.current=null)},[x]),s.useEffect(()=>{He||ge(r==="agency"?ce.find(t=>
1t.id===C)?.name??"":h[0]?.creator.full_name??"")},[r,C,ce,h,He]),s.useEffect(()=>{qe||Ze(r==="individual"?h[0]?.creator.email??"":"")},[r,h,qe]);const R=(t,a,n)=>{N(o=>o.map((i,y)=>y!==t?i:{...i,deliverables:i.deliverables.map((k,M)=>M===a?{...k,...n}:k)}))},Lt=()=>pe(t=>[...t,{label:"",amount_usd:""}]),st=(t,a)=>pe(n=>n.map((o,i)=>i===t?{...o,...a}:o)),It=t=>pe(a=>a.filter((n,o)=>o!==t)),$t=async t=>{t.preventDefault(),d(null);const a=r==="individual"&&v==="send"?Ee(fe):null;if(a&&a.length>200){d({kind:"error",text:"Legal company name must be 200 characters or fewer."});return}if(Qe){d({kind:"error",text:"Still loading content types and campaign tags â try again in a moment."});return}if(Ke){d({kind:"error",text:"Couldn't load content types and campaign tags â reload the page and try again."});return}if(!z.trim()){d({kind:"error",text:"Give the deal a title."});return}if(r==="agency"&&!C){d({kind:"error",text:"Pick an agency."});return}if(h.length===0){d({kind:"error",text:"Add at least one creator."});return}const n=new Set(H.map(l=>l.value)),o=new Set(ne.map(l=>l.value));for(const l of h){if(l.deliverables.length===0){d({kind:"error",text:`Add a deliverable for ${l.creator.full_name}.`});return}for(const j of l.deliverables){const b=aa(j,n,o);if(b){d({kind:"error",text:`${l.creator.full_name}: ${b}`});return}}}if(r==="individual"&&Q.trim()&&!da(Q)){d({kind:"error",text:"Use uppercase letters, digits and hyphens in the discount code."});return}let i="",y={emails:[]},k=null;if(v==="send"){if(!xe.trim()){d({kind:"error",text:"Add a signatory name."});return}if(i=Ye.trim(),!i||!le.test(i)){d({kind:"error",text:"Enter a valid recipient email."});return}if(y=ua(Je,i),"error"in y){d({kind:"error",text:y.error});return}}else{const l=Pe(oe);
1if(l){d({kind:"error",text:l});return}const j=new Date().toISOString().slice(0,10);if(!I||I>j){d({kind:"error",text:"Enter a valid signed date, not in the future."});return}if(!K.trim()||!le.test(ee.trim())){d({kind:"error",text:r==="agency"?"Add the agency contact's name and a valid email.":"Add a signatory name and a valid email."});return}if(!ue){d({kind:"error",text:"Confirm this is the fully executed agreement before saving."});return}S(!0);const b=await ha(oe);if(!b){S(!1),d({kind:"error",text:"Couldn't read the file â try again."});return}k={pdf_base64:b,signed_at:I,signatory_name:K.trim(),recipient_email:ee.trim()}}let M,Y,lt;if(x==="lump_sum"){const l=Number(V);if(!V.trim()||!Number.isFinite(l)||l<=0||l>1e7){d({kind:"error",text:"Enter a total fee greater than 0."});return}if(M=l,W.length>0){const j=[];for(const q of W){const G=q.label.trim();if(!G){d({kind:"error",text:"Every payment schedule row needs a label."});return}const be=Number(q.amount_usd);if(!q.amount_usd.trim()||!Number.isFinite(be)||be<=0){d({kind:"error",text:`${G}: enter a schedule amount greater than 0.`});return}j.push({label:G,amount_cents:Math.round(be*100)})}const b=j.reduce((q,G)=>q+G.amount_cents,0),dt=Math.round(l*100);if(b!==dt){d({kind:"error",text:`The payment schedule totals ${D(b/100)}, but the total fee is ${D(dt/100)} â they must match exactly.`});return}lt=j}}else if(x==="per_deliverable"){const l=Number(X);if(!X.trim()||!Number.isFinite(l)||l<=0||l>1e7){d({kind:"error",text:"Enter an amount per deliverable greater than 0."});return}Y=l}else for(const l of h)for(const j of l.deliverables){const b=Number(j.amount_usd);if(!j.amount_usd.trim()||!Number.isFinite(b)||b<=0){d({kind:"error",text:`${l.creator.full_name}: set a fee greater than 0 for every deliverable.`});return}}S(!0);const ie=await O({action:"create_deal",deal_type:r,agency_id:r==="agency"?C:void 0,payout_recipient:r==="agency"?te:void 0,deal_title:z.trim(),notion_url:$e.trim()||void 0,creative_os_request_id:Me??void 0,legal_company_name:r==="individual"&&v==="send"?a:void 0,discount_code:r==="individual"?Q.trim().toUpperCase():void 0,participants:h.map(l=>({creator_id:l.creator.id,deliverables:l.deliverables.map(j=>sa(j,x==="per_line"))})),payment_structure:x,installments:lt,attach_signed:k??void 0,...k?{contract_title:z.trim(),...x==="lump_sum"?{flat_fee_usd:M}:x==="per_deliverable"?{per_deliverable_amount_usd:Y}:{}}:{}}).catch(()=>null);if(!ie){S(!1),d({kind:"error",text:"Your session expired. Sign in again."});return}const je=await ie.json().catch(()=>({}));if(!ie.ok){S(!1);const l=je.error;d({kind:"error",text:l&&pa[l]||`Could not create the deal (${l??ie.status}).`});return}const Z=je.campaign_id;if(!Z){S(!1),d({kind:"error",text:"Deal created, but no id came back â check the board."});return}if(je.attached){S(!1),Ce.success("Deal created â the contract was attached and the deal is live."),_({to:"/platform/admin/campaigns",search:{deal:Z}});return}const ct=await O({action:"send_contract",campaign_id:Z,contract_title:z.trim(),signatory_name:xe.trim(),recipient_email:i,...r==="individual"?{expected_legal_company_name:a}:{},cc_emails:"emails"in y&&y.emails.length?y.emails:void 0,payment_structure:x,exclusivity_period:Xe.trim()||void 0,...x==="lump_sum"?{flat_fee_usd:M}:x==="per_deliverable"?{per_deliverable_amount_usd:Y}:{}}).catch(()=>null);if(S(!1),!ct||!ct.ok){Ce.error("Deal created, but contract delivery could not be confirmed. Check its status before trying again."),_({to:"/platform/admin/campaigns",search:{deal:Z}});return}Ce.success("Deal created and contract sent for signature."),_({to:"/platform/admin/campaigns",search:{deal:Z}})};if(p)return e.jsx("div",{className:"min-h-screen flex items-center justify-center",children:e.jsx(ot,{})});if(!c)return e.jsx(De,{children:e.jsx("main",{className:"p-6 max-w-2xl mx-auto",children:e.jsx(w,{children:e.jsx(A,{children:e.jsx(F,{children:"Sign in required"})})})})});if(!f)return e.jsx(De,{children:e.jsx("main",{className:"p-6 max-w-2xl mx-auto",children:e.jsx(w,{children:e.jsxs(A,{children:[e.jsx(F,{children:"View only"}),e.jsx(J,{children:"You have view-only access â deals are created by admins."})]})})})});const Mt=v!=="attach"||!Pe(oe)&&!!I&&I<=new Date().toISOString().slice(0,10)&&K.trim()!==""&&le.test(ee.trim())&&ue,L=h.reduce((t,a)=>t+a.deliverables.length,0),Ut=new Set(h.map(t=>t.creator.id)),ye=Number(X),Ot=X.trim()!==""&&Number.isFinite(ye)&&L>0?`${D(ye)} Ã ${L} = ${D(ye*L)}`:`Applies to every deliverable in this deal (${L} so far).`,zt=h.reduce((t,a)=>t+a.deliverables.reduce((n,o)=>{const i=Number(o.amount_usd);return n+(o.amount_usd.trim()!==""&&Number.isFinite(i)?i:0)},0),0),Bt=`${D(zt)} across ${L} deliverable${L===1?"":"s"}.`,Vt=Ee(fe),Wt=r==="individual"?Ee(h[0]?.creator.full_name??""):null,Xt=Vt??Wt,nt=Number(V),rt=V.trim()!==""&&Number.isFinite(nt)?Math.round(nt*100):null,it=W.reduce((t,a)=>{const n=Number(a.amount_usd);return t+(a.amount_usd.trim()!==""&&Number.isFinite(n)?Math.round(n*100):0)},0),$=rt!=null?rt-it:null;return e.jsx(De,{children:e.jsxs("main",{className:"p-6 max-w-5xl mx-auto
1space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-semibold",children:"Create deal & send contract"}),e.jsx("p",{className:"text-muted-foreground",children:"Creates the deal and its deliverables, then sends the contract for signature â all in one step. Nothing creator-facing fires until it's signed."})]}),Ke&&e.jsx("p",{className:"text-sm text-destructive-primary",children:"Couldn't load content types and campaign tags â reload the page and try again."}),e.jsxs("form",{onSubmit:$t,className:"space-y-6",children:[e.jsxs("fieldset",{disabled:ae||Qe,className:"space-y-6 disabled:opacity-60",children:[e.jsxs(w,{children:[e.jsxs(A,{children:[e.jsx(F,{children:"Payment"}),e.jsx(J,{children:"How this deal pays out. Per-line fees are entered on each deliverable below."})]}),e.jsxs(U,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(u,{children:"Contract"}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsx(g,{type:"button",variant:v==="send"?"default":"outline",onClick:()=>Oe("send"),children:"Send for signature"}),e.jsx(g,{type:"button",variant:v==="attach"?"default":"outline",onClick:()=>Oe("attach"),children:"Attach signed contract"})]})]}),v==="attach"&&e.jsxs("div",{className:"space-y-4 rounded-md border border-border p-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(u,{htmlFor:"deal-attach-file",children:"Signed contract (PDF)"}),e.jsx(m,{id:"deal-attach-file",type:"file",accept:"application/pdf",onChange:t=>{const a=t.target.files?.[0]??null;jt(a),bt(a?Pe(a):null)}}),ze&&e.jsx("p",{className:"text-xs text-destructive-primary",children:ze})]}),e.jsxs("div",{className:"space-y-1.5 max-w-xs",children:[e.jsx(u,{htmlFor:"deal-attach-signed-on",children:"Signed on"}),e.jsx(m,{id:"deal-attach-signed-on",type:"date",max:new Date().toISOString().slice(0,10),value:I,onChange:t=>_t(t.target.value)})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(u,{htmlFor:"deal-attach-signatory-name",children:r==="agency"?"Agency contact name":"Signatory name"}),e.jsx(m,{id:"deal-attach-signatory-name",value:K,onChange:t=>Ct(t.target.value),placeholder:r==="agency"?"Who signed for the agency":"Who signed the contract"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(u,{htmlFor:"deal-attach-signatory-email",children:r==="agency"?"Agency contact email":"Signatory email"}),e.jsx(m,{id:"deal-attach-signatory-email",type:"email",value:ee,onChange:t=>Nt(t.target.value),placeholder:"[email protected]"})]})]}),e.jsxs("label",{className:"flex items-start gap-2 text-xs text-muted-foreground",children:[e.jsx(Qt,{className:"mt-0.5",checked:ue,onCheckedChange:t=>St(t===!0)}),"I confirm this is the fully executed agreement and the deliverables, fees and dates entered match it."]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(u,{children:"Payment structure"}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsx(g,{type:"button",variant:x==="lump_sum"?"default":"outline",onClick:()=>me("lump_sum"),children:"Lump sum"}),e.jsx(g,{type:"button",variant:x==="per_deliverable"?"default":"outline",onClick:()=>me("per_deliverable"),children:"Per deliverable"}),e.jsx(g,{type:"button",variant:x==="per_line"?"default":"outline",onClick:()=>me("per_line"),children:"Per line (itemized)"})]})]}),x==="lump_sum"?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5 max-w-xs",children:[e.jsx(u,{htmlFor:"deal-flat-fee",children:"Total fee (USD)"}),e.jsx(m,{id:"deal-flat-fee",type:"number",min:"0",step:"0.01",inputMode:"decimal",value:V,onChange:t=>kt(t.target.value),placeholder:"e.g. 5000"})]}),e.jsxs("div",{className:"space-y-2 border-t border-border pt-4",children:[e.jsx(u,{children:"Payment schedule (optional)"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Split the total fee into installments, each approved and paid individually. Internal only â never appears on the contract."}),W.map((t,a)=>e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(m,{value:t.label,onChange:n=>st(a,{label:n.target.value}),placeholder:"e.g. Deposit",maxLength:200,className:"flex-1"}),e.jsx(m,{type:"number",min:"0",step:"0.01",inputMode:"decimal",value:t.amount_usd,onChange:n=>st(a,{amount_usd:n.target.value}),placeholder:"e.g. 2500",className:"w-32"}),e.jsx(g,{type:"button",variant:"ghost",size:"sm",onClick:()=>It(a),children:"Remove"})]},a)),e.jsx(g,{type:"button",variant:"outline",size:"sm",onClick:Lt,children:"Add installment"}),W.length>0&&e.jsx("p",{className:`text-xs ${$===0?"text-muted-foreground":"text-destructive-primary"}`,children:$==null?"Enter a total fee to check the schedule against it.":$===0?`Schedule matches the total fee (${D(it/100)}).`:$>0?`${D($/100)} left to schedule.`:`${D(Math.abs($)/100)} over the total fee.`})]})]}):x==="per_deliverable"?e.jsxs("div",{className:"space-y-1.5 max-w-xs",children:[e.jsx(u,{htmlFor:"deal-per-deliverable-fee",children:"Amount per deliverable (USD)"}),e.jsx(m,{id:"deal-per-deliverable-fee",type:"number",min:"0",step:"0.01",inputMode:"decimal",value:X,onChange:t=>wt(t.target.value),placeholder:"e.g. 500"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:Ot})]}):e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Set each deliverable's fee below. ",Bt]}),r==="agency"&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(u,{children:"Pay to"}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsx(g,{type:"button",variant:te==="agency"?"default":"outline",onClick:()=>{Be(!0),B("agency")},children:"Agency"}),e.jsx(g,{type:"button",variant:te==="creators"?"default":"outline",disabled:x==="lump_sum",onClick:()=>{Be(!0),B("creators")},children:"Creators directly"})]}),x==="lump_sum"&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"A lump sum can only be paid to the agency â use per-line to pay creators individually."})]})]})]}),e.jsxs(w,{children:[e.jsxs(A,{children:[e.jsx(F,{children:"Who is this deal with?"}),e.jsx(J,{children:"An individual creator, or several creators under one agency contract."})]}),e.jsxs(U,{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{type:"button",variant:r==="individual"?"default":"outline",onClick:()=>
1{if(r==="agency"&&h.length>1){se(!0);return}se(!1),T("individual"),N(t=>t.slice(0,1))},children:"Individual"}),e.jsx(g,{type:"button",variant:r==="agency"?"default":"outline",onClick:()=>T("agency"),children:"Agency"})]}),Tt&&e.jsxs("div",{className:"rounded-md border border-border bg-muted p-3 space-y-2 text-sm",children:[e.jsxs("p",{children:["Switching to Individual keeps only ",h[0]?.creator.full_name??"the first creator"," and removes ",h.length-1," other creator",h.length-1===1?"":"s","."]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{type:"button",size:"sm",variant:"destructive",onClick:()=>{T("individual"),N(t=>t.slice(0,1)),se(!1)},children:"Confirm"}),e.jsx(g,{type:"button",size:"sm",variant:"outline",onClick:()=>se(!1),children:"Cancel"})]})]}),r==="agency"&&e.jsxs("div",{className:"space-y-1.5 max-w-sm",children:[e.jsx(u,{htmlFor:"deal-agency",children:"Agency"}),e.jsxs(Se,{value:C,onValueChange:ht,children:[e.jsx(ke,{id:"deal-agency",children:e.jsx(we,{placeholder:"Select an agency"})}),e.jsx(Ae,{children:ce.map(t=>e.jsx(Fe,{value:t.id,children:t.name},t.id))})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Agency not in the CRM yet?"," ",e.jsx(_e,{to:"/platform/admin/agencies",className:"underline underline-offset-2",children:"Add it first"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(u,{htmlFor:"deal-search",children:"Find creators"}),e.jsx(m,{id:"deal-search",value:de,onChange:t=>pt(t.target.value),placeholder:"Search by name or handle"})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto rounded-md border border-border divide-y",children:[Le&&e.jsx("p",{className:"p-3 text-sm text-muted-foreground",children:"Searchingâ¦"}),!Le&&Re.length===0&&e.jsxs("div",{className:"p-3 space-y-1",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"No creators match that search."}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Creator not in the CRM yet?"," ",e.jsx(_e,{to:"/platform/admin/creators",className:"underline underline-offset-2",children:"Add them first"})]})]}),Re.map(t=>{const a=Ut.has(t.id);return e.jsxs("button",{type:"button",onClick:()=>Rt(t),"aria-pressed":a,title:a?`Remove ${t.full_name} from this deal`:`Add ${t.full_name} to this deal`,className:`group flex w-full items-center justify-between gap-3 p-3 text-left transition-colors ${a?"bg-muted":"hover:bg-muted"}`,children:[e.jsxs("span",{className:"flex items-center gap-2 text-sm",children:[a&&e.jsx("span",{"aria-hidden":!0,className:"text-primary",children:"â"}),e.jsxs("span",{className:a?"font-medium":void 0,children:[t.full_name,e.jsxs("span",{className:"text-muted-foreground",children:[" · ",t.primary_handle]})]})]}),a?e.jsxs(e.Fragment,{children:[e.jsx(Ne,{className:"group-hover:hidden group-focus-visible:hidden",children:"Selected"}),e.jsx(Ne,{variant:"outline",className:"hidden group-hover:inline-flex group-focus-visible:inline-flex",children:"Remove"})]}):e.jsx("span",{className:"text-xs text-muted-foreground",children:r==="individual"?"Select":"Add"})]},t.id)})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r==="individual"?"Individual deals have one creator â picking a new one replaces the current selection.":"Pick one or more creators for this agency deal."}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Creator not in the CRM yet?"," ",e.jsx(_e,{to:"/platform/admin/creators",className:"underline underline-offset-2",children:"Add them first"})]})]})]}),h.map((t,a)=>e.jsxs(w,{children:[e.jsx(A,{children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(F,{children:t.creator.full_name}),e.jsxs(J,{children:[t.creator.primary_handle," · deliverables for this creator"]})]}),e.jsx(g,{type:"button",variant:"outline",size:"sm",onClick:()=>N(n=>n.filter((o,i)=>i!==a)),children:"Remove"})]})}),e.jsxs(U,{className:"space-y-4",children:[t.deliverables.map((n,o)=>e.jsxs("div",{className:"rounded-md border border-border p-4 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs(Ne,{variant:"outline",children:["Deliverable ",o+1]}),t.deliverables.length>1&&e.jsx(g,{type:"button",variant:"ghost",size:"sm",onClick:()=>N(i=>i.map((y,k)=>k!==a?y:{...y,deliverables:y.deliverables.filter((M,Y)=>Y!==o)})),children:"Remove"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(u,{children:"Content type"}),e.jsxs(Se,{value:n.content_type,onValueChange:i=>R(a,o,{content_type:i}),children:[e.jsx(ke,{children:e.jsx(we,{})}),e.jsx(Ae,{children:H.map(i=>e.jsx(Fe,{value:i.value,children:i.label},i.value))})]}),n.content_type==="other"&&e.jsxs(e.Fragment,{children:[e.jsx(m,{value:n.description,onChange:i=>R(a,o,{description:i.target.value}),placeholder:"e.g. Podcast mention",maxLength:200}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Appears in the contract as the deliverable description."})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(u,{children:"Campaign tag"}),e.jsxs(Se,{value:n.campaign_tag,onValueChange:i=>R(a,o,{campaign_tag:i}),children:[e.jsx(ke,{children:e.jsx(we,{})}),e.jsx(Ae,{children:ne.map(i=>e.jsx(Fe,{value:i.value,children:i.label},i.value))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(u,{children:"Due date"}),e.jsx(m,{type:"date",value:n.due_at,onChange:i=>R(a,o,{due_at:i.target.value})})]}),e.jsxs("div",{className:"space-y-1.5 md:col-span-2",children:[e.jsx(u,{children:"Product tags"}),e.jsx(Kt,{tags:n.product_tags,onChange:i=>R(a,o,{product_tags:i}),placeholder:"Type a tag and press comma or Enter, e.g. agent mode"})]}),x==="per_line"&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(u,{children:"Fee ($)"}),e.jsx(m,{type:"number",min:"0",step:"0.01",inputMode:"decimal",value:n.amount_usd,onChange:i=>R(a,o,{amount_usd:i.target.value}),placeholder:"e.g. 500"})]}),e.jsxs("div",{className:"space-y-1.5 md:col-span-2",children:[e.jsx(u,{children:"Usage rights"}),e.jsx(m,{value:n.usage_rights,onChange:i=>R(a,o,{usage_rights:i.target.value}),placeholder:"e.g. 90 days paid usage"})]})]})]},o)),e.jsx(g,{type:"button",variant:"outline",size:"sm",onClick:()=>N(n=>n.map((o,i)=>i!==a?o:{...o,deliverables:[...o.deliverables,P()]})),children:"Add deliverable"})]})]},t.creator.id)),e.jsxs(w,{children:[e.jsx(A,{children:e.jsx(F,{children:"Deal details"})}),e.jsxs(U,{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5 md:col-span-2",children:[e.jsx(u,{htmlFor:"deal-title",children:"Deal title"}),e.jsx(m,{id:"deal-title",maxLength:200,value:z,onChange:t=>gt(t.target.value),placeholder:"e.g. Summer launch"})]}),e.jsxs("div",{className:"space-y-1.5 md:col-span-2",children:[e.jsx(u,{htmlFor:"deal-notion-url",children:"Brief link"}),e.jsx(m,{id:"deal-notion-url",maxLength:500,value:$e,onChange:t=>ft(t.target.value),placeholder:"https://notion.so/â¦"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Shown to the creator once the deal is theirs."})]}),e.jsx("div",{className:"md:col-span-2",children:e.jsx(ea,{value:Me,onChange:vt,disabled:ae})}),r==="individual"&&e.jsxs("div",{className:"space-y-1.5 md:col-span-2",children:[e.jsx(u,{htmlFor:"deal-code",children:"Discount code"}),e.jsx(m,{id:"deal-code",className:"font-mono bg-muted",value:Q,readOnly:!0,"aria-readonly":"true",placeholder:"INFL-NAME-XXXX"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Auto-generated from the creator's name. Created in Stripe once the contract is signed â new customers only, no expiry."})]}),r==="agency"&&e.jsx("p",{className:"md:col-span-2 text-xs text-muted-foreground",children:"Agency deals get their tracking link and discount code once the contract is signed."})]})]}),v==="send"&&e.jsxs(w,{children:[e.jsxs(A,{children:[e.jsx(F,{children:"Signature & terms"}),e.jsx(J,{children:"Sent for signature as soon as you save. Nothing creator-facing fires until it's signed."})]}),e.jsxs(U,{className:"space-y-4",children:[r==="individual"&&e.jsxs("div",{className:"space-y-1.5 max-w-md",children:[e.jsx(u,{htmlFor:"deal-legal-company-name",children:"Legal company name (optional)"}),e.jsx(m,{id:"deal-legal-company-name",value:fe,maxLength:200,onChange:t=>Ge(t.target.value),placeholder:"e.g. Acme Studio LLC"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Leave blank to contract in the creator's own name."}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Contracting as: ",Xt??"Add a company name or creator full name."]})]}),e.jsxs("div",{className:"space-y-1.5 max-w-md",children:[e.jsx(u,{htmlFor:"deal-exclusivity",children:"Exclusivity period"}),e.jsx(m,{id:"deal-exclusivity",value:Xe,onChange:t=>At(t.target.value),placeholder:"e.g. 2 weeks before and after each post goes live"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(u,{htmlFor:"deal-signatory",children:"Signatory name"}),e.jsx(m,{id:"deal-signatory",value:xe,onChange:t=>{Ft(!0),ge(t.target.value)},placeholder:"Who signs the contract"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(u,{htmlFor:"deal-recipient-email",children:"Recipient email"}),e.jsx(m,{id:"deal-recipient-email",type:"email",value:Ye,onChange:t=>{Dt(!0),Ze(t.target.value)},placeholder:"[email protected]"})]})]}),e.jsxs("div",{className:"space-y-1.5 max-w-md",children:[e.jsx(u,{htmlFor:"deal-cc-email",children:"CC emails (optional)"}),e.jsx(m,{id:"deal-cc-email",type:"text",value:Je,onChange:t=>Et(t.target.value),placeholder:"[email protected], [email protected]"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Comma-separated. They get a copy from DocuSign and don't sign it."})]})]})]}),e.jsxs(w,{children:[e.jsx(A,{children:e.jsx(F,{children:"What happens when you save"})}),e.jsx(U,{children:e.jsxs("ul",{className:"text-sm text-muted-foreground space-y-1 list-disc pl-4",children:[e.jsx("li",{children:v==="attach"?"The deal is created and the attached contract lands it straight in Signed â no DocuSign envelope goes out.":"The deal is created, then the contract is sent for signature right away."}),e.jsx("li",{children:v==="attach"?"The tracking link, discount code, personal code and creator email are all created and sent as soon as it's attached.":"The tracking link, discount code, personal code and creator email are all created and sent once it's signed."}),e.jsxs("li",{className:"text-foreground",children:["Deliverables entered here: ",L]})]})})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(g,{type:"submit",disabled:ae||!Mt,children:ae?e.jsxs(e.Fragment,{children:[e.jsx(ot,{size:"small"}),v==="attach"?"Savingâ¦":"Sendingâ¦"]}):v==="attach"?e.jsx(e.Fragment,{children:"Create deal & attach contract"}):e.jsx(e.Fragment,{children:"Create deal & send contract"})}),ve&&e.jsx("p",{className:ve.kind==="error"?"text-sm text-destructive-primary":"text-sm text-muted-foreground",children:ve.text})]})]})]})})}export{Fa 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.