1import{n as y,r as u,j as e}from"./vendor-react-5FA5AwQ7.js";import{u as I,aa as U,V as D,e as w,f as F,h as L,i as z,j as S,A as i,I as C,m,X as T,H as f,av as k,aw as R,ax as q,N as l,ay as H,k as A,az as B}from"./App-eW_BAJUB.js";import{u as E}from"./index-DXziZZwX.js";import"./vendor-editor-BrE3CBZg.js";import"./vendor-charts-YGw0RwdG.js";import"./vendor-radix-Cc97sJpJ.js";import"./vendor-i18n-VWbTNjcU.js";function V(t){return t.replace(/\s+/g,"").toUpperCase().slice(0,5)}function O(){const{t}=I(),p=y(),{tenant:c}=E(),{create:v,saving:d}=U(),[s,o]=u.useState({title:"",description:"",icon:"",imageUrl:""}),[x,h]=u.useState(!1),[b,g]=u.useState(null),j=u.useRef(null);D([{label:t("tutor.courses","Courses"),to:"/courses"},{label:t("tutor.createCourse","Create")}],[]);const N=async r=>{if(r.preventDefault(),!s.title.trim()){l.error(t("tutor.createCoursePage.toastTitleRequired"));return}if(!s.icon.trim()){l.error(t("tutor.createCoursePage.toastLabelRequired"));return}const a=await v({title:s.title.trim(),description:s.description.trim()||void 0,icon:s.icon.trim(),image_url:s.imageUrl||null,published:!1});a?(l.success(t("tutor.createCoursePage.toastCreated")),p(`/courses/${a.id}`)):l.error(t("tutor.createCoursePage.toastCreateFailed"))};return e.jsxs("div",{className:"max-w-3xl mx-auto px-4 sm:px-6 lg:px-8 py-8",children:[e.jsxs("div",{className:"mb-8",children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold text-gray-900 mb-2",children:t("tutor.createCoursePage.title")}),e.jsx("p",{className:"text-gray-600",children:t("tutor.createCoursePage.subtitle")})]}),e.jsxs("form",{onSubmit:N,children:[e.jsxs(w,{children:[e.jsxs(F,{children:[e.jsx(L,{children:t("tutor.createCoursePage.courseDetails")}),e.jsx(z,{children:t("tutor.createCoursePage.courseDetailsDescription")})]}),e.jsxs(S,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{htmlFor:"shortLabel",children:t("tutor.createCoursePage.shortLabel")}),e.jsx(C,{id:"shortLabel",placeholder:t("tutor.createCoursePage.shortLabelPlaceholder"),value:s.icon,maxLength:5,onChange:r=>o({...s,icon:V(r.target.value)}),required:!0}),e.jsx("p",{className:"text-sm text-gray-500",children:t("tutor.createCoursePage.shortLabelHint")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{children:t("tutor.courseImage.label","Course image")}),e.jsx("p",{className:"text-sm text-gray-500",children:t("tutor.courseImage.hint","Upload an image to represent this course. If no image is set, the short label above is shown instead.")}),s.imageUrl?e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-16 h-16 rounded-lg overflow-hidden flex-shrink-0",children:e.jsx("img",{src:s.imageUrl,alt:"",className:"w-full h-full object-cover"})}),e.jsxs(m,{type:"button",variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>o({...s,imageUrl:void 0}),children:[e.jsx(T,{className:"size-4 mr-1"})," ",t("tutor.courseImage.remove","Remove")]})]}):e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:j,type:"file",accept:"image/png,image/jpeg,image/jpg,image/gif,image/webp",className:"hidden",onChange:r=>{var n;const a=(n=r.target.files)==null?void 0:n[0];a&&g(a),r.target.value=""}}),e.jsx(m,{type:"button",variant:"outline",size:"sm",disabled:x,onClick:()=>{var r;return(r=j.current)==null?void 0:r.click()},children:x?e.jsxs(e.Fragment,{children:[e.jsx(f,{className:"size-4 animate-spin mr-2"})," ",t("tutor.courseImage.uploading","Uploadingâ¦")]}):e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"size-4 mr-2"})," ",t("tutor.courseImage.choose","Choose image")]})}),e.jsx(R,{file:b,title:t("tutor.courseImage.cropTitle","Crop course image"),description:t("tutor.courseImage.cropDescription","Drag to reposition. Scroll to zoom."),confirmLabel:t("tutor.courseImage.cropConfirm","Upload"),cancelLabel:t("common.cancel","Cancel"),onCancel:()=>g(null),onConfirm:async r=>{if(g(null),!!(c!=null&&c.id)){h(!0);try{const a=crypto.randomUUID(),n=await q(r,c.id,a);o(P=>({...P,imageUrl:n}))}catch{l.error(t("tutor.courseImage.uploadFailed","Image upload failed"))}finally{h(!1)}}}})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{htmlFor:"title",children:t("tutor.createCoursePage.courseTitle")}),e.jsx(C,{id:"title",placeholder:t("tutor.createCoursePage.courseTitlePlaceholder"),value:s.title,onChange:r=>o({...s,title:r.target.value}),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{htmlFor:"description",children:t("tutor.createCoursePage.description")}),e.jsx(H,{id:"description",placeholder:t("tutor.createCoursePage.descriptionPlaceholder"),value:s.description,onChange:r=>o({...s,description:r.target.value}),rows:4})]}),e.jsxs("div",{className:"border-t pt-6",children:[e.jsx(i,{className:"mb-4 block",children:t("tutor.createCoursePage.preview")}),e.jsxs("div",{className:"flex items-center gap-4 p-4 bg-slate-50 rounded-lg",children:[e.jsx(A,{icon:s.icon,imageUrl:s.imageUrl,size:"md",className:"w-16 h-16"}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-lg",children:s.title||t("tutor.createCoursePage.courseTitleDefault")}),e.jsx("p",{className:"text-sm text-gray-600",children:s.description||t("tutor.createCoursePage.courseDescriptionDefault")})]})]})]})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row justify-end gap-3 sm:gap-4 mt-6",children:[e.jsx(m,{type:"button",variant:"outline",onClick:()=>p("/courses"),disabled:d,children:t("tutor.createCoursePage.cancel")}),e.jsx(m,{type:"submit",disabled:d,children:d?e.jsxs(e.Fragment,{children:[e.jsx(f,{className:"mr-2 size-4 animate-spin"}),t("tutor.createCoursePage.creating")]}):e.jsxs(e.Fragment,{children:[e.jsx(B,{className:"mr-2 size-4"}),t("tutor.createCoursePage.createCourse")]})})]})]})]})}export{O as CreateCourse};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.