import React, { useEffect, useMemo, useRef, useState } from 'react' import { Head, Link, router, useForm } from '@inertiajs/react' import { createPortal } from 'react-dom' import AdminLayout from '../../../Layouts/AdminLayout' import DateTimePicker from '../../../components/ui/DateTimePicker' import NovaSelect from '../../../components/ui/NovaSelect' import ShareToast from '../../../components/ui/ShareToast' import CourseEditor from './CourseEditor' import LessonEditor from './LessonEditor' function normalizePayload(fields, data) { const payload = { ...data } fields.forEach((field) => { if (field.type === 'csv') { payload[field.name] = String(payload[field.name] || '') .split(/[,\n]/) .map((item) => item.trim()) .filter(Boolean) } if (field.type === 'json') { if (typeof payload[field.name] === 'string') { const trimmed = payload[field.name].trim() if (!trimmed) { payload[field.name] = null return } try { payload[field.name] = JSON.parse(trimmed) } catch { // Keep the original string so the caller can surface a field-specific validation error. } } } }) return payload } function serializeStructuredJson(value) { if (value == null || value === '') return '' if (typeof value === 'string') return value try { return JSON.stringify(value, null, 2) } catch { return '' } } function getField(fields, name) { return fields.find((field) => field.name === name) || null } function firstErrorMessage(errors, fallback = 'Please correct the highlighted fields and try again.') { const queue = [errors] while (queue.length > 0) { const current = queue.shift() if (typeof current === 'string') { const message = current.trim() if (message) { return message } continue } if (Array.isArray(current)) { queue.push(...current) continue } if (current && typeof current === 'object') { queue.push(...Object.values(current)) } } return fallback } function SectionCard({ eyebrow, title, description, children, className = '' }) { return (
{eyebrow ?

{eyebrow}

: null}

{title}

{description ?

{description}

: null}
{children}
) } function TextField({ label, value, onChange, error, ...rest }) { return ( ) } function TextAreaField({ label, value, onChange, error, rows = 6, hint }) { return (