"use client";

import type { AnnouncementCatalogs, AnnouncementFieldErrors, AnnouncementInput } from "@/domain/entities/announcement";

/** What every editor section receives. */
export interface SectionProps {
  input: AnnouncementInput;
  update: (patch: Partial<AnnouncementInput>) => void;
  errors: AnnouncementFieldErrors;
  catalogs: AnnouncementCatalogs;
  /** Published at least once: key, format, step count/order are locked (spec §6.2). */
  locked: boolean;
  disabled: boolean;
}

export function EditorSection({
  id,
  index,
  title,
  help,
  children,
  aside,
}: {
  id: string;
  index: number;
  title: string;
  help?: string;
  children: React.ReactNode;
  aside?: React.ReactNode;
}) {
  return (
    <section id={id} aria-labelledby={`${id}-title`} className="scroll-mt-24 rounded-xl border bg-card p-5 shadow-xs">
      <header className="mb-4 flex flex-wrap items-start justify-between gap-3">
        <div className="flex items-start gap-3">
          <span className="flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-blue-600 text-xs font-bold text-white" aria-hidden="true">
            {index}
          </span>
          <div>
            <h2 id={`${id}-title`} className="text-base font-semibold leading-6">{title}</h2>
            {help && <p className="text-xs text-muted-foreground">{help}</p>}
          </div>
        </div>
        {aside}
      </header>
      <div className="space-y-5">{children}</div>
    </section>
  );
}
