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

//# sourceMappingURL=src_0cj31yk._.js.map