var F=(n,t,l)=>new Promise((p,u)=>{var h=o=>{try{c(l.next(o))}catch(i){u(i)}},d=o=>{try{c(l.throw(o))}catch(i){u(i)}},c=o=>o.done?p(o.value):Promise.resolve(o.value).then(h,d);c((l=l.apply(n,t)).next())});import{jsxs as s,jsx as r}from"react/jsx-runtime";import{C as q}from"./chunked-uploader-input-WemAY1Qi.js";import{I as C}from"./input-error-BbsDx4-P.js";import{L as D}from"./loading-button-B_LaGOAp.js";import{L as f,I as b,as as T,at as V,au as j,av as w,aw as N}from"./ui-components-B24mpb8o.js";import{g as z}from"./file-metadata-CAFSN-Sn.js";import{o as S}from"./inertia-FIn3q7f1.js";import{usePage as A,useForm as B}from"@inertiajs/react";import{useState as H,useEffect as M}from"react";import"axios";import"lucide-react";import"sonner";import"next-themes";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";const Le=({lesson:n,resource:t,isSubmit:l,setIsSubmit:p,setIsOpen:u})=>{const[h,d]=H(!1),{props:c}=A(),{translate:o}=c,{input:i,button:U}=o,{data:a,setData:m,post:k,put:E,reset:v,processing:g,errors:y,clearErrors:I}=B({title:t?t.title:"",type:t?t.type:"document",resource:t?t.resource:"",resource_url:null,section_lesson_id:n.id}),L=e=>F(null,null,function*(){if(e.preventDefault(),a.type==="link"){_();return}p(!0)}),_=()=>{I(),t?E(route("resources.update",t.id),{preserveScroll:!0,onSuccess:()=>{v(),p(!1),u(!0)}}):k(route("resources.store"),{preserveScroll:!0,onSuccess:()=>{v(),p(!1),u(!0)}})};M(()=>{a.resource_url&&h&&(_(),v("resource_url"),d(!1))},[a.resource_url]);const x=[{label:"Document",value:"document"},{label:"Image File",value:"image"},{label:"Video File",value:"video"},{label:"Zip/Archive",value:"zip"},{label:"External Link",value:"link"}];return s("form",{onSubmit:L,className:"space-y-4",children:[s("div",{children:[r(f,{children:i.title}),r(b,{required:!0,name:"title",value:a.title,placeholder:i.title,onChange:e=>S(e,m)}),r(C,{message:y.title})]}),s("div",{children:[r(f,{children:"Resource Type"}),s(T,{required:!0,name:"type",value:a.type,onValueChange:e=>m("type",e),children:[r(V,{className:"w-full",children:r(j,{placeholder:i.select})}),r(w,{children:x.map(e=>r(N,{value:e.value,children:e.label},e.value))})]})]}),a.type==="link"?s("div",{children:[r(f,{children:"Resource"}),r(b,{required:!0,type:"url",name:"resource",value:a.resource,placeholder:i.url,onChange:e=>S(e,m)}),r(C,{message:y.resource})]}):s("div",{children:[r(f,{children:"Resource"}),r(q,{isSubmit:l,courseId:n.course_id,sectionId:n.course_section_id,filetype:a.type,delayUpload:!0,onFileSelected:e=>{z(e).then(R=>{m("title",R.name)})},onFileUploaded:e=>{d(!0),m("resource_url",e.file_url)},onError:e=>{p(!1)},onCancelUpload:()=>{p(!1)}})]}),r(D,{loading:g||l,disabled:g||l,children:t?"Update":U.submit})]})};export{Le as default};
