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

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

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

    // Configuration for EntityAttachmentUpdatePage
    const config = useMemo(
      () => ({
        entityType: "conference",
        entityIdParam: "cid", // Conference uses 'cid' for conference 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: CalendarIcon,
              href: "/admin/events",
            },
            {
              label: "Conference",
              href: "/admin/event/conference",
            },
            {
              label: "Detail",
              href: `/admin/event/conference/${eventId}`,
            },
            {
              label: "Attachments",
              href: `/admin/event/conference/${eventId}/attachments`,
            },
            {
              label: "Update Attachment",
              icon: PencilSquareIcon,
              current: true,
            },
          ],

          backPath: `/admin/event/conference/{entityId}/attachment/{attachmentId}`,
          successRedirectPath: `/admin/event/conference/{entityId}/attachment/{attachmentId}`,
        },

        // Header configuration
        header: {
          pageTitle: "Conference Event - Update Attachment",
          pageIcon: PencilSquareIcon,
          entityIcon: CalendarIcon,
          entityType: "Conference Event",
          backLabel: "Back to Detail",
          basePath: "/admin/event/conference",
        },
      }),
      [attachmentManager],
    );

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

function AdminConferenceDetailAttachmentUpdatePage() {
  return (
    <UIXThemeProvider>
      <AdminConferenceDetailAttachmentUpdatePageContent />
    </UIXThemeProvider>
  );
}

export default AdminConferenceDetailAttachmentUpdatePage;
