(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,17658,e=>{"use strict";var t=e.i(43476);function r(...e){return e.filter(Boolean).join(" ")}e.i(22016);let i={primary:"bg-brand-green text-white hover:bg-brand-green-deep focus-visible:ring-brand-green",secondary:"border border-be-border bg-be-surface text-be-text hover:bg-be-surface-2 focus-visible:ring-brand-green",ghost:"text-be-muted hover:text-be-text hover:bg-be-surface-2 focus-visible:ring-brand-green",danger:"bg-[color:var(--pill-danger-fg)] text-white hover:opacity-90 focus-visible:ring-[color:var(--pill-danger-fg)]"};e.s(["Card",0,function({className:e,children:i}){return(0,t.jsx)("div",{className:r("be-card p-5",e),children:i})},"buttonClass",0,function(e="primary",t){return r("inline-flex items-center justify-center gap-1.5 rounded-lg px-4 py-2 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-be-bg disabled:opacity-50 disabled:pointer-events-none",i[e],t)}])},29728,e=>{"use strict";var t=e.i(43476),r=e.i(71645),i=e.i(18566),n=e.i(11795),a=e.i(17658);function s({label:e,hint:r,children:i}){return(0,t.jsxs)("div",{children:[(0,t.jsxs)("label",{className:"block text-sm font-medium mb-1 text-be-text",children:[e," ",r&&(0,t.jsxs)("span",{className:"font-normal text-be-muted",children:["— ",r]})]}),i]})}e.s(["default",0,function(){let e=(0,i.useRouter)(),o=(0,n.createClient)(),[l,c]=(0,r.useState)({code:"",name:"",commissionPercent:"10"}),[u,d]=(0,r.useState)(null),[m,b]=(0,r.useState)(!1);async function f(t){t.preventDefault(),b(!0),d(null);let{data:r}=await o.auth.getUser();if(!r.user){d("Not signed in"),b(!1);return}let i=Number(l.commissionPercent);if(!i||i<=0||i>100){d("Enter a commission between 1 and 100"),b(!1);return}let{error:n}=await o.from("affiliates").insert({organizer_id:r.user.id,code:l.code.trim().toUpperCase(),name:l.name.trim()||null,commission_percent:i});if(n){d("23505"===n.code?"You already have an affiliate with this code.":n.message),b(!1);return}e.push("/dashboard/affiliates"),e.refresh()}return(0,t.jsxs)("form",{onSubmit:f,className:"space-y-4",children:[(0,t.jsx)(s,{label:"Code",children:(0,t.jsx)("input",{required:!0,value:l.code,onChange:e=>c({...l,code:e.target.value}),placeholder:"e.g. JOHN10",className:"input font-mono uppercase"})}),(0,t.jsx)(s,{label:"Promoter name",hint:"Optional",children:(0,t.jsx)("input",{value:l.name,onChange:e=>c({...l,name:e.target.value}),placeholder:"e.g. John Doe",className:"input"})}),(0,t.jsx)(s,{label:"Commission (%)",hint:"Share of the order total credited on each attributed sale",children:(0,t.jsx)("input",{required:!0,type:"number",min:"1",max:"100",value:l.commissionPercent,onChange:e=>c({...l,commissionPercent:e.target.value}),className:"input"})}),u&&(0,t.jsx)("p",{className:"text-sm text-red-600",children:u}),(0,t.jsx)("button",{type:"submit",disabled:m,className:(0,a.buttonClass)("primary"),children:m?"Creating…":"Create affiliate"})]})}])}]);