import { useEffect, useRef, useState } from 'react' import { DndContext, closestCenter, PointerSensor, useSensor, useSensors } from '@dnd-kit/core' import { arrayMove, SortableContext, verticalListSortingStrategy, useSortable } from '@dnd-kit/sortable' import { CSS } from '@dnd-kit/utilities' import type { ChangeEvent } from 'react' import { Link } from 'react-router-dom' import type { SiteContent, CustomLink, CustomBlock, ArchivedSeries, ArchivedSeriesResourceLink, ArchivedSeriesNote, ColossiansStudySection, StudyProgram, RedirectRule, PodcastFeaturedLink, SeoSettings, LegalSettings } from './content' import { DEFAULTS } from './content' import { AnalyticsPanel } from './components/AnalyticsPanel' import { AdminCollapsibleCard } from './components/AdminCollapsibleCard' import { useAutosave } from './hooks/useAutosave' interface SortableLessonSectionProps { section: ColossiansStudySection study: StudyProgram updateStudySection: (studyId: string, sectionId: string, field: keyof ColossiansStudySection, value: string | string[] | number) => void removeStudySection: (studyId: string, sectionId: string) => void } function SortableLessonSection({ section, study, updateStudySection, removeStudySection }: SortableLessonSectionProps) { const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id: section.id }) const style = { transform: CSS.Transform.toString(transform), transition, opacity: isDragging ? 0.5 : 1, background: isDragging ? '#f8f7f2' : undefined, border: isDragging ? '2px solid #e0c070' : undefined, marginBottom: '0.5rem', } return (
Lesson {section.reference || section.id}

{section.title || 'Untitled section'}

e.stopPropagation()}>Preview Expand to edit lesson
updateStudySection(study.id, section.id, 'reference', e.target.value)} />
updateStudySection(study.id, section.id, 'title', e.target.value)} />
updateStudySection(study.id, section.id, 'audioEmbedUrl', e.target.value)} />
{ const val = e.target.value; if (val) { const date = new Date(val + ':00Z'); updateStudySection(study.id, section.id, 'releasedAt', date.toISOString()); } else { updateStudySection(study.id, section.id, 'releasedAt', ''); } }} />