import{jsxs as r,jsx as e}from"react/jsx-runtime";import{I as o}from"./input-error-BbsDx4-P.js";import{L as T}from"./loading-button-B_LaGOAp.js";import{H as M,J as U,K as j,M as k,N as A,L as d,I as c,B as C,as as S,at as y,au as D,av as F,aw as v,aJ as B,O as E,Q as H}from"./ui-components-B24mpb8o.js";import{a as n}from"./date-BZvGgr5q.js";import{o as p}from"./inertia-FIn3q7f1.js";import{useForm as O}from"@inertiajs/react";import{Shuffle as q}from"lucide-react";import{useState as J,useEffect as K}from"react";import"next-themes";import"sonner";import"@radix-ui/react-label";import"class-variance-authority";import"@radix-ui/react-checkbox";import"@radix-ui/react-avatar";import"@radix-ui/react-dropdown-menu";import"@radix-ui/react-scroll-area";import"@radix-ui/react-popover";import"@radix-ui/react-radio-group";import"@radix-ui/react-dialog";import"@radix-ui/react-slot";import"clsx";import"@radix-ui/react-separator";import"@radix-ui/react-tooltip";import"@radix-ui/react-tabs";import"@radix-ui/react-accordion";import"@radix-ui/react-progress";import"@radix-ui/react-select";import"cmdk";import"@radix-ui/react-switch";import"react-day-picker";import"@radix-ui/react-slider";import"embla-carousel-react";import"@radix-ui/react-toggle-group";import"vaul";import"tailwind-merge";import"date-fns";const Ie=({title:b,handler:N,coupon:i,courses:x})=>{var u,f;const[m,h]=J(!1),{data:l,setData:a,post:I,put:V,reset:g,processing:_,errors:s}=O({code:(i==null?void 0:i.code)||"",course_id:(i==null?void 0:i.course_id)||"",discount_type:(i==null?void 0:i.discount_type)||"percentage",discount:(i==null?void 0:i.discount)||0,valid_from:n(i==null?void 0:i.valid_from),valid_to:n(i==null?void 0:i.valid_to),is_active:(u=i==null?void 0:i.is_active)!=null?u:!0}),w=t=>{t.preventDefault(),i?V(route("course-coupons.update",i.id),{preserveScroll:!0,onSuccess:()=>{h(!1)}}):I(route("course-coupons.store"),{preserveScroll:!0,onSuccess:()=>{g(),h(!1)}})},L=()=>{const t=Math.random().toString(36).substring(2,10).toUpperCase();a("code",t)};return K(()=>{var t;m&&i?a({course_id:i.course_id||"",code:i.code||"",discount_type:i.discount_type||"percentage",discount:i.discount||0,valid_from:n(i.valid_from),valid_to:n(i.valid_to),is_active:(t=i.is_active)!=null?t:!0}):m||g()},[m,i]),r(M,{open:m,onOpenChange:h,children:[e(U,{asChild:!0,children:N}),r(j,{className:"max-w-2xl",children:[e(k,{children:e(A,{children:b})}),r("form",{onSubmit:w,children:[e("div",{className:"space-y-4 py-4",children:r("div",{className:"grid grid-cols-2 gap-4",children:[r("div",{className:"col-span-2",children:[e(d,{htmlFor:"code",children:"Coupon Code *"}),r("div",{className:"flex gap-2",children:[e(c,{id:"code",name:"code",value:l.code,onChange:t=>a("code",t.target.value.toUpperCase()),placeholder:"SUMMER2024",required:!0}),e(C,{type:"button",variant:"outline",onClick:L,children:e(q,{className:"h-4 w-4"})})]}),e(o,{message:s.code})]}),r("div",{children:[e(d,{htmlFor:"discount_type",children:"Discount Type *"}),r(S,{name:"discount_type",value:l.discount_type,onValueChange:t=>a("discount_type",t),children:[e(y,{children:e(D,{placeholder:"Select type"})}),r(F,{children:[e(v,{value:"percentage",children:"Percentage (%)"}),e(v,{value:"fixed",children:"Fixed Amount ($)"})]})]}),e(o,{message:s.discount_type})]}),r("div",{children:[e(d,{htmlFor:"discount",children:"Discount Value *"}),e(c,{id:"discount",name:"discount",type:"number",value:l.discount,onChange:t=>p(t,a),min:"0",step:"0.01",required:!0}),e(o,{message:s.discount})]}),r("div",{className:"col-span-2",children:[e(d,{htmlFor:"course_id",children:"Select Course"}),r(S,{name:"course_id",value:(f=l.course_id)==null?void 0:f.toString(),onValueChange:t=>a("course_id",t?parseInt(t):""),children:[e(y,{children:e(D,{placeholder:"All Courses (global coupon)"})}),e(F,{children:x.map(t=>e(v,{value:t.id.toString(),children:t.title},t.id))})]}),e(o,{message:s.course_id})]}),r("div",{children:[e(d,{htmlFor:"valid_from",children:"Valid From"}),e(c,{id:"valid_from",name:"valid_from",type:"datetime-local",value:l.valid_from,onChange:t=>p(t,a)}),e(o,{message:s.valid_from})]}),r("div",{children:[e(d,{htmlFor:"valid_to",children:"Valid To"}),e(c,{id:"valid_to",name:"valid_to",type:"datetime-local",value:l.valid_to,onChange:t=>p(t,a)}),e(o,{message:s.valid_to})]}),r("div",{className:"flex items-center justify-between",children:[e(d,{htmlFor:"is_active",children:"Active"}),e(B,{id:"is_active",checked:l.is_active,onCheckedChange:t=>a("is_active",t)})]})]})}),r(E,{className:"gap-2",children:[e(H,{asChild:!0,children:e(C,{type:"button",variant:"outline",children:"Cancel"})}),e(T,{loading:_,disabled:_,children:i?"Update":"Create"})]})]})]})]})};export{Ie as default};
