lms/public/build/assets/section-Bz0LxI_C.js
2025-12-15 12:26:23 +01:00

2 lines
23 KiB
JavaScript

import{r as b,j as e,aj as ie,bm as me,c0 as C,u as $,aq as de,e as K,bV as U,bZ as z,b_ as V,b$ as B,bY as H,w as ue,b as ge,c1 as pe}from"./vendor-BKmmeuxg.js";import{D as he,a as xe,b as be,c as je,d as fe}from"./dialog-B2gN9MvT.js";import{u as q}from"./use-lang-YfV87_zl.js";import{C as ve}from"./chunked-uploader-input-D0XPVOTS.js";import{L as ye}from"./loading-button-BnTVAMJ7.js";import{I as S}from"./input-DM0goJrn.js";import{L as _}from"./label-HmIcv5Yx.js";import{T as G}from"./textarea-CyndvowL.js";import{o as P}from"./inertia-SZXqLvQm.js";import{C as te,b as se}from"./card-D9_SJYq6.js";import{I as Ne}from"./icon-picker-dialog-AqyWbPod.js";import{B as v}from"./button-BpNwv2aE.js";import{c as I}from"./utils-DxSsnXxD.js";import{T as Q}from"./table-header-DVkEnG6Y.js";import{T as W,a as X,b as k,c as R}from"./table-DWOXv4Pu.js";import{T as _e}from"./table-page-size-OCfjNXER.js";import{d as Se}from"./debounce-CWHP_ANh.js";import{g as O}from"./route-B4ZMN77y.js";import{D as we,a as Ce,b as Ie,c as Pe}from"./dropdown-menu-DO-po5c1.js";import{S as ke}from"./scroll-area-C8HGru-R.js";import{A as Re,a as $e,b as Ee}from"./avatar-j28afJTV.js";const ht=(t,s)=>t.sections.find(n=>n.slug===s),w=t=>t.replace(/_/g," ").replace(/\b\w/g,s=>s.toUpperCase()),M=(t,s)=>typeof s=="string"?t==="image"||t.includes("image")||t==="avatar"||typeof s=="string"&&s.match(/\.(jpeg|jpg|gif|png)$/i)?{type:"file",label:w(t),name:t,value:null}:t==="description"||t.includes("description")||t==="bio"||t==="content"?{type:"textarea",label:w(t),name:t,value:s||""}:t==="url"||t.includes("_url")||t.includes("link")?{type:"url",label:w(t),name:t,value:s||""}:t==="icon"?{type:"icon",label:w(t),name:t,value:s||""}:{type:"text",label:w(t),name:t,value:s||""}:typeof s=="number"?{type:"number",label:w(t),name:t,value:s||0}:typeof s=="boolean"?{type:"boolean",label:w(t),name:t,value:s||!1}:{type:"text",label:w(t),name:t,value:(s==null?void 0:s.toString())||""},F=t=>{if("contents"in t){const s=[{type:"contents",label:"Contents",name:"contents",value:t.contents||[]}];return Object.entries(t).forEach(([n,a])=>{if(n==="array"||n==="contents")return;const o=M(n,a);s.unshift(o)}),s}if("array"in t){const s=Array.isArray(t.array)&&t.array.length>0?t.array[0]:{};let n=[];Object.keys(s).length>0?Object.keys(s).forEach(o=>{(typeof s[o]=="string"||typeof s[o]=="number"||typeof s[o]=="boolean")&&n.push(M(o,s[o]))}):n=[{type:"text",label:"Title",name:"title",value:""},{type:"text",label:"Value",name:"value",value:""}];const a=[{type:"array",label:"Items",name:"array",value:(t.array||[]).map(o=>{const i={...o};return Object.keys(i).forEach(u=>{(u==="image"||u.includes("image"))&&(i.new_image=null)}),i}),fields:n}];return Object.entries(t).forEach(([o,i])=>{if(o==="array"||o==="contents")return;const u=M(o,i);a.unshift(u)}),a}return Object.entries(t).map(([s,n])=>typeof n=="object"&&n!==null&&!Array.isArray(n)?{type:"object",label:w(s),name:s,value:n,fields:F(n)}:M(s,n))},Ae=t=>{let s=!0;return Object.entries(t).forEach(([n,a])=>{switch(typeof a){case"string":a.length>0&&(s=!1);break;case"number":a>0&&(s=!1);break}}),s},Te=t=>t.filter(s=>{let n=!1;return Object.entries(s).forEach(([a,o])=>{switch(typeof o){case"string":o.trim().length>0&&(n=!0);break;case"number":o>0&&(n=!0);break;case"boolean":o&&(n=!0);break}}),n}),xt=t=>{var n;const s=(n=t==null?void 0:t.properties)==null?void 0:n.array;return s?Te(s):[]},ae=b.createContext(void 0),Me=({children:t,section:s,onSuccess:n,onError:a})=>{const[o,i]=b.useState(!1),[u,g]=b.useState(!1),c={section:s,open:o,setOpen:i,isSubmit:u,setIsSubmit:g};return e.jsx(ae.Provider,{value:c,children:t})},D=()=>{const t=b.useContext(ae);if(t===void 0)throw new Error("useSectionEditor must be used within a SectionEditorProvider");return t},De=({field:t,onChange:s})=>{const{button:n}=q(),[a,o]=b.useState({}),[i,u]=b.useState(Array.isArray(t.value)?t.value:[]);b.useEffect(()=>{Array.isArray(t.value)&&u(t.value)},[t.value,t.type]);const g=(d,m,x)=>{c(d,"new_image",x);const h=`${d}-${m}`;if(x&&x.type.startsWith("image/")){a[h]&&URL.revokeObjectURL(a[h]);const r=URL.createObjectURL(x);o(f=>({...f,[h]:r}))}else o(r=>{const f={...r};return f[h]&&(URL.revokeObjectURL(f[h]),delete f[h]),f}),x===null&&c(d,"new_image",null)},c=(d,m,x)=>{const h=[...i];h[d]||(h[d]={}),h[d][m]=x,u(h),s(h)},l=()=>{var x;const d=(x=t.fields)==null?void 0:x.reduce((h,r)=>(h[r.name]=r.value,h),{}),m=[...i,d];u(m),s(m)},p=d=>{const m=i.filter((x,h)=>h!==d);u(m),s(m)};return e.jsxs("div",{children:[e.jsx("div",{className:"space-y-4",children:i.map((d,m)=>{var h;const x=m===0&&Ae(d);return e.jsx(te,{className:I("relative",x&&"hidden"),children:e.jsxs(se,{className:"p-4 pt-6",children:[e.jsx(v,{size:"icon",type:"button",variant:"ghost",onClick:()=>p(m),className:"absolute top-2 right-2 text-red-600 hover:text-red-800",children:e.jsx(ie,{className:"h-5 w-5"})}),(h=t.fields)==null?void 0:h.map((r,f)=>{const A=r.type==="file"?d.image:null;return e.jsxs("div",{className:"mb-4",children:[e.jsx(_,{htmlFor:`${t.name}-${m}-${r.name}`,className:"mb-2 block",children:r.label}),e.jsx("div",{className:"mt-1",children:r.type==="textarea"?e.jsx(G,{id:`${t.name}-${m}-${r.name}`,value:d[r.name]||"",onChange:N=>c(m,r.name,N.target.value),rows:3}):r.type==="file"?e.jsxs("div",{className:"space-y-3",children:[e.jsx(S,{type:"file",id:`${t.name}-${m}-${r.name}`,accept:"image/*",onChange:N=>{var E;return g(m,r.name,((E=N.target.files)==null?void 0:E[0])||null)},className:"cursor-pointer"}),(a[`${m}-${r.name}`]||A)&&e.jsx("div",{className:"relative inline-block",children:e.jsx("img",{alt:"Preview",src:a[`${m}-${r.name}`]||A,className:"h-20 w-auto rounded-lg border object-cover shadow-sm"})})]}):r.type==="icon"?e.jsx(Ne,{name:r.name,value:d[r.name]||"",placeholder:"Pick your category icon",onSelect:N=>c(m,r.name,N)}):e.jsx(S,{type:r.type==="number"?"number":"text",id:`${t.name}-${m}-${r.name}`,value:d[r.name]||"",onChange:N=>c(m,r.name,N.target.value)})})]},f)})]})},m)})}),e.jsx("div",{className:"mt-4",children:e.jsxs(v,{type:"button",onClick:l,variant:"outline",size:"sm",className:"flex items-center",children:[e.jsx(me,{className:"mr-1 h-4 w-4"}),n.add_item]})})]})},Le=t=>[{accessorKey:"title",header:({column:s})=>e.jsxs(v,{type:"button",variant:"ghost",onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),children:[t.table.category_name,e.jsx(C,{className:"ml-2 h-4 w-4"})]}),cell:({row:s})=>e.jsx("div",{className:"capitalize",children:s.getValue("title")})},{accessorKey:"courses_count",header:({column:s})=>e.jsx("div",{className:"flex items-center justify-center",children:e.jsxs(v,{type:"button",variant:"ghost",onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),children:[t.table.courses,e.jsx(C,{className:"ml-2 h-4 w-4"})]})}),cell:({row:s})=>e.jsx("div",{className:"text-center",children:e.jsx("p",{children:s.original.courses_count})})}],Y=t=>{const{Icon:s,data:n,title:a,component:o,globalSearch:i,tablePageSizes:u,routeName:g,className:c,searchKey:l="search"}=t,p=$(),d=O(p.url),m=b.useRef(null),x=Se(async h=>{const r=h.target.value;K.get(route(g||"",{...d,[l]:r}),{},{preserveState:!0})},300);return b.useEffect(()=>{d[l]&&m.current&&m.current.focus()},[t]),e.jsxs("div",{className:I("items-center justify-between p-6 md:flex",c),children:[e.jsxs("div",{className:"flex items-center gap-5",children:[s&&e.jsx("div",{className:"bg-primary-25 flex h-10 w-10 items-center justify-center rounded-md",children:s}),a&&e.jsx("p",{className:"mb-4 text-lg font-semibold md:mb-0",children:a})]}),e.jsxs("div",{className:"flex items-center justify-end",children:[i&&e.jsxs("div",{className:"relative w-full md:max-w-[260px]",children:[e.jsx("input",{type:"text",ref:m,placeholder:"Search",onChange:x,className:"focus:border-primary border-border h-10 w-full rounded-md border py-[15px] pr-4 pl-12 text-sm font-normal focus:ring-0 focus:outline-0",defaultValue:d[l]??""}),e.jsx(de,{className:"absolute top-3 left-4 z-10 h-4 w-4"})]}),g&&e.jsx(_e,{routeName:g,pageData:n,dropdownList:u,pageSizeKey:`${l}_per_page`,className:"ml-3"}),o&&o]})]})},Z=t=>{const{paginationInfo:s,paginationKey:n="page"}=t,{current_page:a,last_page:o,first_page_url:i,last_page_url:u,next_page_url:g,prev_page_url:c}=s,l=$(),p=O(l.url),d=[];if(o>0)for(let r=1;r<=o;r++)d.push({key:`${r}`,value:r});else d.push({key:"1",value:1});const m=r=>{K.get(route(t.routeName,{...t.routeParams||{},...p,[n]:r}),{},{preserveState:!0})},x=r=>{const f=O(r);K.get(route(t.routeName,{...t.routeParams||{},...p,[n]:f.page}),{},{preserveState:!0})},h=r=>`text-center py-1 ${a===r&&"bg-primary-50"}`;return e.jsxs("div",{className:`space-y-4 ${t.className}`,children:[e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx("span",{className:"mr-1",children:e.jsxs("strong",{children:[a," of ",o]})}),e.jsx("span",{className:"mr-3",children:"| Go to page:"}),e.jsxs(we,{children:[e.jsx(Ce,{children:e.jsx(v,{type:"button",variant:"outline",className:"h-8 w-[60px] rounded-md border",children:a})}),e.jsx(Ie,{align:"end",className:"min-w-[60px]",children:e.jsx(ke,{className:"",children:d.map(r=>e.jsx(Pe,{onClick:()=>m(r.value),className:h(r.value),children:r.value},r.key))})})]})]}),e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(v,{type:"button",variant:"ghost",disabled:!c,onClick:()=>x(i),className:"bg-muted border-border h-8 border px-2 text-xs sm:px-3",children:"<<First"}),e.jsx(v,{type:"button",variant:"ghost",disabled:!c,onClick:()=>x(c),className:"bg-muted border-border mx-3 h-8 border px-2 text-xs sm:px-3",children:"Prev"}),e.jsx(v,{type:"button",variant:"ghost",disabled:!g,onClick:()=>x(g),className:"bg-muted border-border mx-3 h-8 border px-2 text-xs sm:px-3",children:"Next"}),e.jsx(v,{type:"button",variant:"ghost",disabled:!g,onClick:()=>x(u),className:"bg-muted border-border h-8 border px-2 text-xs sm:px-3",children:"Last>>"})]})]})},Ke=({categories:t,selectedIds:s=[],onCourseSelect:n})=>{var c;const a=$(),o=a.props.type==="demo"?"home.demo":"home",[i,u]=b.useState([]),g=U({data:t.data,columns:Le(a.props.translate),onSortingChange:u,getCoreRowModel:B(),getSortedRowModel:V(),getFilteredRowModel:z(),state:{sorting:i}});return e.jsxs("div",{children:[e.jsx(Y,{data:t,title:"Categories",globalSearch:!0,searchKey:"category",tablePageSizes:[10,15,20,25],routeName:o}),e.jsxs(W,{className:"border-border border-y",children:[e.jsx(Q,{table:g}),e.jsx(X,{children:(c=g.getRowModel().rows)!=null&&c.length?g.getRowModel().rows.map(l=>e.jsx(k,{"data-state":l.getIsSelected()&&"selected",className:I("hover:bg-muted cursor-pointer",(s==null?void 0:s.includes(Number(l.original.id)))&&"bg-secondary-light"),onClick:()=>n&&n(Number(l.original.id)),children:l.getVisibleCells().map(p=>e.jsx(R,{children:H(p.column.columnDef.cell,p.getContext())},p.id))},l.id)):e.jsx(k,{children:e.jsx(R,{className:"h-24 text-center",children:a.props.translate.common.no_results_found})})})]}),e.jsx(Z,{className:"p-4",routeName:o,paginationInfo:t,paginationKey:"category"})]})},Oe=t=>[{accessorKey:"title",header:"Title",cell:({row:s})=>e.jsx("div",{className:"capitalize",children:s.getValue("title")})},{accessorKey:"enrollments_count",header:({column:s})=>e.jsx("div",{className:"flex items-center justify-center",children:e.jsxs(v,{type:"button",variant:"ghost",onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),children:[t.table.enrollments,e.jsx(C,{})]})}),cell:({row:s})=>e.jsx("div",{className:"text-center",children:e.jsx("p",{children:s.original.enrollments_count})})},{accessorKey:"average_rating",header:({column:s})=>e.jsx("div",{className:"flex items-center justify-center",children:e.jsxs(v,{type:"button",variant:"ghost",onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),children:["Rating",e.jsx(C,{})]})}),cell:({row:s})=>e.jsxs("div",{className:"flex items-center justify-center gap-1 text-center",children:[e.jsx("p",{children:Number(s.original.average_rating).toFixed(1)}),e.jsx("span",{className:"text-yellow-500",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",stroke:"currentColor",children:e.jsx("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})})}),e.jsxs("span",{className:"text-muted-foreground text-sm",children:["(",s.original.reviews_count,")"]})]})}],Fe=({courses:t,selectedIds:s=[],onCourseSelect:n})=>{var c;const a=$(),o=a.props.type==="demo"?"home.demo":"home",[i,u]=b.useState([]),g=U({data:t.data,columns:Oe(a.props.translate),onSortingChange:u,getCoreRowModel:B(),getSortedRowModel:V(),getFilteredRowModel:z(),state:{sorting:i}});return e.jsxs("div",{children:[e.jsx(Y,{data:t,title:"Courses",globalSearch:!0,searchKey:"course",tablePageSizes:[10,15,20,25],routeName:o}),e.jsxs(W,{className:"border-border border-y",children:[e.jsx(Q,{table:g}),e.jsx(X,{children:(c=g.getRowModel().rows)!=null&&c.length?g.getRowModel().rows.map(l=>e.jsx(k,{"data-state":l.getIsSelected()&&"selected",className:I("hover:bg-muted cursor-pointer",(s==null?void 0:s.includes(Number(l.original.id)))&&"bg-secondary-light"),onClick:()=>n&&n(Number(l.original.id)),children:l.getVisibleCells().map(p=>e.jsx(R,{children:H(p.column.columnDef.cell,p.getContext())},p.id))},l.id)):e.jsx(k,{children:e.jsx(R,{className:"h-24 text-center",children:a.props.translate.common.no_results_found})})})]}),e.jsx(Z,{className:"p-4",routeName:o,paginationInfo:t})]})},Ue=t=>[{accessorKey:"user.name",header:({column:s})=>e.jsxs(v,{type:"button",variant:"ghost",onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),children:[t.table.instructor,e.jsx(C,{className:"ml-2 h-4 w-4"})]}),cell:({row:s})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(Re,{className:"h-8 w-8",children:[e.jsx($e,{src:s.original.user.photo||"",alt:s.original.user.name,className:"object-cover"}),e.jsx(Ee,{children:s.original.user.name.charAt(0)})]}),e.jsx("span",{className:"capitalize",children:s.original.user.name})]})},{accessorKey:"total_enrollments",header:({column:s})=>e.jsx("div",{className:"flex items-center justify-center",children:e.jsxs(v,{type:"button",variant:"ghost",onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),children:[t.table.enrollments,e.jsx(C,{className:"ml-2 h-4 w-4"})]})}),cell:({row:s})=>e.jsx("div",{className:"text-center",children:e.jsx("p",{children:s.original.total_enrollments_count})})},{accessorKey:"average_rating",header:({column:s})=>e.jsx("div",{className:"flex items-center justify-center",children:e.jsxs(v,{type:"button",variant:"ghost",onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),children:[t.table.rating,e.jsx(C,{className:"ml-2 h-4 w-4"})]})}),cell:({row:s})=>e.jsxs("div",{className:"flex items-center justify-center gap-1 text-center",children:[e.jsx("p",{children:Number(s.original.total_average_rating).toFixed(1)}),e.jsx(ue,{className:"h-4 w-4 fill-yellow-400 text-yellow-400"}),e.jsxs("span",{className:"text-muted-foreground text-sm",children:["(",s.original.total_reviews_count,")"]})]})}],ze=({instructors:t,selectedIds:s=[],onCourseSelect:n})=>{var c;const a=$(),o=a.props.type==="demo"?"home.demo":"home",[i,u]=b.useState([]),g=U({data:t.data,columns:Ue(a.props.translate),onSortingChange:u,getCoreRowModel:B(),getSortedRowModel:V(),getFilteredRowModel:z(),state:{sorting:i}});return e.jsxs("div",{children:[e.jsx(Y,{data:t,title:"Instructors",globalSearch:!0,searchKey:"instructor",tablePageSizes:[10,15,20,25],routeName:o}),e.jsxs(W,{className:"border-border border-y",children:[e.jsx(Q,{table:g}),e.jsx(X,{children:(c=g.getRowModel().rows)!=null&&c.length?g.getRowModel().rows.map(l=>e.jsx(k,{"data-state":l.getIsSelected()&&"selected",className:I("hover:bg-muted cursor-pointer",(s==null?void 0:s.includes(Number(l.original.id)))&&"bg-secondary-light"),onClick:()=>n&&n(Number(l.original.id)),children:l.getVisibleCells().map(p=>e.jsx(R,{children:H(p.column.columnDef.cell,p.getContext())},p.id))},l.id)):e.jsx(k,{children:e.jsx(R,{className:"h-24 text-center",children:a.props.translate.common.no_results_found})})})]}),e.jsx(Z,{className:"p-4",routeName:o,paginationInfo:t,paginationKey:"instructor"})]})},Ve=({field:t,section_slug:s,onChange:n})=>{var m,x;const{props:a}=$(),{courses:o,categories:i,instructors:u}=a,{section:g}=D(),[c,l]=b.useState((m=g.properties)!=null&&m.contents?(x=g.properties)==null?void 0:x.contents:[]);b.useEffect(()=>{t.type==="contents"&&Array.isArray(t.value)&&l(t.value)},[t.value,t.type]);const p=h=>{let r;c.includes(h)?r=c.filter(f=>f!==h):r=[...c,h],l(r),n==null||n(r)},d=()=>{switch(s){case"hero":case"top_course":case"top_courses":case"new_courses":return e.jsx(Fe,{courses:o,selectedIds:c,onCourseSelect:p});case"top_categories":case"category_courses":return e.jsx(Ke,{categories:i,selectedIds:c,onCourseSelect:p});case"top_instructors":return e.jsx(ze,{instructors:u,selectedIds:c,onCourseSelect:p});case"blogs":return e.jsx("h1",{children:"Blogs"});default:return null}};return e.jsx("div",{className:"rounded-md border",children:d()})},re=({field:t,onChange:s})=>{const{section:n}=D(),[a,o]=b.useState(t.value||"");b.useEffect(()=>{o(t.value||"")},[t.value,t.type]);const i=c=>{const{value:l,type:p}=c.target;if(p==="checkbox"){const d=c.target.checked;o(d),s(d);return}o(l),s(l)},u=c=>{var p;const l=((p=c.target.files)==null?void 0:p[0])||null;o(l),s(l)},g=()=>{var c;switch(t.type){case"contents":return e.jsx(Ve,{field:t,section_slug:n.slug,onChange:s});case"text":case"url":return e.jsx(S,{type:"text",id:t.name,name:t.name,value:a,onChange:i});case"textarea":return e.jsx(G,{id:t.name,name:t.name,rows:3,value:a,onChange:i});case"number":return e.jsx(S,{type:"number",id:t.name,name:t.name,value:a,onChange:i});case"image":case"file":return e.jsx(S,{type:"file",id:t.name,name:t.name,onChange:u});case"boolean":return e.jsx(S,{type:"checkbox",id:t.name,name:t.name,checked:a||!1,onChange:i,className:"h-4 w-4"});case"array":return e.jsx(De,{field:t,onChange:s});case"object":return e.jsx(te,{children:e.jsx(se,{className:"p-4",children:(c=t.fields)==null?void 0:c.map((l,p)=>e.jsxs("div",{className:"mb-4",children:[e.jsx(_,{htmlFor:`${t.name}-${l.name}`,className:"mb-2 block",children:l.label}),e.jsx("div",{className:"mt-1",children:e.jsx(re,{field:{...l,name:`${t.name}-${l.name}`,value:t.value&&t.value[l.name]!==void 0?t.value[l.name]:l.value},onChange:d=>{const m={...t.value||{},[l.name]:d};s(m)}})})]},p))})});default:return null}};return e.jsxs("div",{className:"mb-4",children:[t.type!=="boolean"&&t.type!=="contents"&&e.jsx(_,{htmlFor:t.name,className:"mb-2 block",children:t.label}),g(),t.type==="boolean"&&e.jsx(_,{htmlFor:t.name,className:"ml-2 inline-block",children:t.label})]})},Be=()=>{const{input:t,button:s,frontend:n}=q(),{section:a,setOpen:o,isSubmit:i,setIsSubmit:u}=D(),[g,c]=b.useState(!1),[l,p]=b.useState(!1),[d,m]=b.useState(a.thumbnail||null),[x,h]=b.useState(a.background_image||null),{data:r,setData:f,post:A,reset:N,processing:E,errors:y}=ge({title:a.title,sub_title:a.sub_title,description:a.description||"",thumbnail:null,video_url:a.video_url,background_image:null,background_color:a.background_color,properties:a.properties,active:a.active,sort:a.sort}),ne=F(r.properties),[J,oe]=b.useState(ne);b.useEffect(()=>{oe(F(a.properties))},[a]);const le=j=>{if(j.preventDefault(),g){u(!0);return}ee()},ee=()=>{A(route("page.section.update",a.id),{onSuccess:()=>{N(),o(!1),u(!1)}})};b.useEffect(()=>{r.video_url&&l&&(ee(),N("video_url"),p(!1))},[r.video_url]);const ce=(j,L)=>{f(T=>({...T,properties:{...T.properties,[j]:L}}))};return b.useEffect(()=>{open||N()},[open]),e.jsxs("form",{onSubmit:le,children:[e.jsxs("div",{className:"space-y-6",children:[a.flags.title&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(_,{htmlFor:"title",children:t.title}),e.jsx(S,{type:"text",id:"title",name:"title",value:r.title,onChange:j=>P(j,f),placeholder:t.title_placeholder}),y.title&&e.jsx("p",{className:"mt-1 text-sm text-red-600",children:y.title})]}),a.flags.sub_title&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(_,{htmlFor:"sub_title",children:t.sub_title}),e.jsx(S,{type:"text",id:"sub_title",name:"sub_title",value:r.sub_title,onChange:j=>P(j,f),placeholder:t.title_placeholder}),y.sub_title&&e.jsx("p",{className:"mt-1 text-sm text-red-600",children:y.sub_title})]}),a.flags.description&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(_,{htmlFor:"description",children:t.description}),e.jsx(G,{id:"description",name:"description",value:r.description||"",onChange:j=>P(j,f),placeholder:t.description_placeholder,rows:3}),y.description&&e.jsx("p",{className:"mt-1 text-sm text-red-600",children:y.description})]}),a.flags.thumbnail&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(_,{htmlFor:"thumbnail",children:t.thumbnail}),e.jsx(S,{type:"file",id:"thumbnail",name:"thumbnail",accept:"image/*",onChange:j=>P(j,f,m),className:"cursor-pointer"}),y.thumbnail&&e.jsx("p",{className:"mt-1 text-sm text-red-600",children:y.thumbnail}),d&&e.jsx("img",{src:d,alt:"Thumbnail Preview",className:"h-32 w-auto rounded-lg border object-cover shadow-sm"})]}),a.flags.video_url&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(_,{htmlFor:"video_url",children:t.preview_video}),e.jsx(ve,{isSubmit:i,filetype:"video",delayUpload:!1,onFileSelected:j=>{c(!0)},onFileUploaded:j=>{p(!0),f("video_url",j.file_url)},onError:j=>{u(!1)},onCancelUpload:()=>{u(!1)}}),y.video_url&&e.jsx("p",{className:"mt-1 text-sm text-red-600",children:y.video_url})]}),a.flags.background_image&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(_,{htmlFor:"background_image",children:t.background_image}),e.jsx(S,{type:"file",id:"background_image",name:"background_image",onChange:j=>P(j,f,h)}),y.background_image&&e.jsx("p",{className:"mt-1 text-sm text-red-600",children:y.background_image}),x&&e.jsx("img",{src:x,alt:"Background Image Preview",className:"h-32 w-auto rounded-lg border object-cover shadow-sm"})]}),a.flags.background_color&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(_,{htmlFor:"background_color",children:t.background_color}),e.jsx(S,{type:"color",id:"background_color",name:"background_color",value:r.background_color,onChange:j=>P(j,f)}),y.background_color&&e.jsx("p",{className:"mt-1 text-sm text-red-600",children:y.background_color})]}),J.length>0&&e.jsxs("div",{className:"",children:[e.jsx("h3",{className:"text-lg font-medium",children:n.section_properties}),e.jsx("div",{className:"mt-4 space-y-6",children:J.map((j,L)=>e.jsx(re,{field:j,onChange:T=>ce(j.name,T)},`${j.name}-${L}`))})]})]}),e.jsx("div",{className:"mt-8 flex justify-end",children:e.jsx(ye,{loading:E||i,disabled:E||i,children:s.save})})]})},He=({section:t,actionComponent:s})=>e.jsx(Me,{section:t,children:e.jsx(qe,{actionComponent:s})}),qe=({actionComponent:t})=>{const{button:s,frontend:n}=q(),{open:a,setOpen:o,isSubmit:i,section:u}=D();return e.jsxs(he,{open:a,onOpenChange:g=>!i&&o(g),children:[e.jsx(xe,{asChild:!0,children:t}),e.jsxs(be,{className:"max-h-[90vh] overflow-y-auto",children:[e.jsx(je,{children:e.jsxs(fe,{className:"text-lg font-medium",children:[s.update," ",u.name," ",n.section]})}),e.jsx(Be,{})]})]})},Ge=({containerClass:t,contentClass:s,children:n,pageSection:a,customize:o,containerStyle:i,contentStyle:u,...g})=>e.jsx("section",{className:I("container",t),...g,style:i,children:e.jsxs("div",{className:I(s,o&&"section-edit"),style:u,children:[o&&a&&e.jsx(He,{section:a,actionComponent:e.jsx(v,{size:"icon",variant:"secondary",className:"absolute top-3 right-3 z-20",children:e.jsx(pe,{className:"h-7 w-7"})})}),n]})}),bt=Object.freeze(Object.defineProperty({__proto__:null,default:Ge},Symbol.toStringTag,{value:"Module"}));export{Ge as S,xt as a,ht as g,bt as s};