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