(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,17658,e=>{"use strict";var t=e.i(43476);function n(...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:n("be-card p-5",e),children:i})},"buttonClass",0,function(e="primary",t){return n("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)}])},50607,e=>{"use strict";var t=e.i(43476),n=e.i(71645),i=e.i(18566),r=e.i(11795),s=e.i(17658);function a({label:e,hint:n,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," ",n&&(0,t.jsxs)("span",{className:"font-normal text-be-muted",children:["— ",n]})]}),i]})}e.s(["default",0,function({events:e}){let l=(0,i.useRouter)(),o=(0,r.createClient)(),[u,d]=(0,n.useState)({code:"",eventId:"",kind:"percent",value:"",maxRedemptions:"",perCustomerLimit:"1",startsAt:"",endsAt:""}),[c,m]=(0,n.useState)(null),[p,b]=(0,n.useState)(!1);async function g(e){e.preventDefault(),b(!0),m(null);let{data:t}=await o.auth.getUser();if(!t.user){m("Not signed in"),b(!1);return}let n=Number(u.value);if(!n||n<=0){m("Enter a discount value greater than 0"),b(!1);return}if("percent"===u.kind&&n>100){m("A percentage discount can't exceed 100"),b(!1);return}let{error:i}=await o.from("coupons").insert({organizer_id:t.user.id,event_id:u.eventId||null,code:u.code.trim().toUpperCase(),kind:u.kind,percent_off:"percent"===u.kind?n:null,amount_off_cents:"fixed"===u.kind?Math.round(100*n):null,max_redemptions:u.maxRedemptions?Number(u.maxRedemptions):null,per_customer_limit:u.perCustomerLimit?Number(u.perCustomerLimit):null,starts_at:u.startsAt||null,ends_at:u.endsAt||null});if(i){m("23505"===i.code?"You already have a coupon with this code.":i.message),b(!1);return}l.push("/dashboard/coupons"),l.refresh()}return(0,t.jsxs)("form",{onSubmit:g,className:"space-y-4",children:[(0,t.jsx)(a,{label:"Code",children:(0,t.jsx)("input",{required:!0,value:u.code,onChange:e=>d({...u,code:e.target.value}),placeholder:"e.g. EARLYBIRD",className:"input font-mono uppercase"})}),(0,t.jsx)(a,{label:"Applies to",children:(0,t.jsxs)("select",{value:u.eventId,onChange:e=>d({...u,eventId:e.target.value}),className:"input",children:[(0,t.jsx)("option",{value:"",children:"All of your events"}),e.map(e=>(0,t.jsx)("option",{value:e.id,children:e.title},e.id))]})}),(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,t.jsx)(a,{label:"Discount type",children:(0,t.jsxs)("select",{value:u.kind,onChange:e=>d({...u,kind:e.target.value}),className:"input",children:[(0,t.jsx)("option",{value:"percent",children:"Percent off"}),(0,t.jsx)("option",{value:"fixed",children:"Fixed amount off (KES)"})]})}),(0,t.jsx)(a,{label:"percent"===u.kind?"Percent":"Amount (KES)",children:(0,t.jsx)("input",{required:!0,type:"number",min:"1",step:"percent"===u.kind?"1":"0.01",value:u.value,onChange:e=>d({...u,value:e.target.value}),className:"input"})})]}),(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,t.jsx)(a,{label:"Max redemptions",hint:"Blank = unlimited",children:(0,t.jsx)("input",{type:"number",min:"1",value:u.maxRedemptions,onChange:e=>d({...u,maxRedemptions:e.target.value}),className:"input"})}),(0,t.jsx)(a,{label:"Per-customer limit",hint:"Blank = unlimited",children:(0,t.jsx)("input",{type:"number",min:"1",value:u.perCustomerLimit,onChange:e=>d({...u,perCustomerLimit:e.target.value}),className:"input"})})]}),(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,t.jsx)(a,{label:"Starts",hint:"Optional",children:(0,t.jsx)("input",{type:"datetime-local",value:u.startsAt,onChange:e=>d({...u,startsAt:e.target.value}),className:"input"})}),(0,t.jsx)(a,{label:"Ends",hint:"Optional",children:(0,t.jsx)("input",{type:"datetime-local",value:u.endsAt,onChange:e=>d({...u,endsAt:e.target.value}),className:"input"})})]}),c&&(0,t.jsx)("p",{className:"text-sm text-red-600",children:c}),(0,t.jsx)("button",{type:"submit",disabled:p,className:(0,s.buttonClass)("primary"),children:p?"Creating…":"Create coupon"})]})}])}]);