// File Path: monorepo/web/frontend/src/pages/Admin/Event/InSchool/Detail/Attachment/Update/Page.jsx

import React, { useMemo, memo } from "react";
import {
  AcademicCapIcon,
  PencilSquareIcon,
  ChartBarIcon,
} from "@heroicons/react/24/outline";
import { useAttachmentManager } from "../../../../../../../services/Services";
import {
  UIXThemeProvider,
  EntityAttachmentUpdatePage,
} from "../../../../../../../components/UIX";

const AdminInSchoolDetailAttachmentUpdatePageContent = memo(
  function AdminInSchoolDetailAttachmentUpdatePageContent() {
    const attachmentManager = useAttachmentManager();

    // Configuration for EntityAttachmentUpdatePage
    const config = useMemo(
      () => ({
        entityType: "in-school",
        entityIdParam: "isid", // InSchool uses 'isid' for event ID
        attachmentIdParam: "atid", // and 'atid' for attachment ID

        // Data operations
        onAttachmentFetch: async (attachmentId, onUnauthorized) => {
          return await attachmentManager.getAttachmentDetail(
            attachmentId,
            onUnauthorized,
          );
        },

        onAttachmentUpdate: async (
          attachmentId,
          updateData,
          onUnauthorized,
        ) => {
          return await attachmentManager.updateAttachment(
            attachmentId,
            updateData,
            onUnauthorized,
          );
        },

        // Route configuration
        routes: {
          buildBreadcrumbs: (eventId, attachmentId) => [
            {
              label: "Dashboard",
              href: "/admin/dashboard",
              icon: ChartBarIcon,
            },
            {
              label: "Events",
              icon: AcademicCapIcon,
              href: "/admin/events",
            },
            {
              label: "In-School",
              icon: AcademicCapIcon,
              href: "/admin/event/in-school",
            },
            {
              label: "Detail",
              href: `/admin/event/in-school/${eventId}`,
            },
            {
              label: "Attachments",
              href: `/admin/event/in-school/${eventId}/attachments`,
            },
            {
              label: "Update Attachment",
              icon: PencilSquareIcon,
              current: true,
            },
          ],

          backPath: `/admin/event/in-school/{entityId}/attachment/{attachmentId}`,
          successRedirectPath: `/admin/event/in-school/{entityId}/attachment/{attachmentId}`,
        },

        // Header configuration
        header: {
          pageTitle: "In-School Event - Update Attachment",
          pageIcon: PencilSquareIcon,
          entityIcon: AcademicCapIcon,
          entityType: "In-School Event",
          backLabel: "Back to Detail",
          basePath: "/admin/event/in-school",
        },
      }),
      [attachmentManager],
    );

    return <EntityAttachmentUpdatePage config={config} />;
  },
);

function AdminInSchoolDetailAttachmentUpdatePage() {
  return (
    <UIXThemeProvider>
      <AdminInSchoolDetailAttachmentUpdatePageContent />
    </UIXThemeProvider>
  );
}

export default AdminInSchoolDetailAttachmentUpdatePage;
