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

import React, { useMemo, memo } from "react";
import {
  MapIcon,
  PaperClipIcon,
  DocumentTextIcon,
  ChartBarIcon,
} from "@heroicons/react/24/outline";
import { useAttachmentManager } from "../../../../../../../services/Services";
import {
  UIXThemeProvider,
  EntityAttachmentDetailPage,
} from "../../../../../../../components/UIX";

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

    // Configuration for EntityAttachmentDetailPage
    const config = useMemo(
      () => ({
        entityType: "field-trip",
        entityIdParam: "ftid", // Field trip uses 'ftid' for event ID
        attachmentIdParam: "atid", // and 'atid' for attachment ID

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

        // Route configuration
        routes: {
          buildBreadcrumbs: (eventId, attachmentId) => [
            {
              label: "Dashboard",
              href: "/admin/dashboard",
              icon: ChartBarIcon,
            },
            {
              label: "Events",
              href: "/admin/events",
            },
            {
              label: "Field Trip",
              icon: MapIcon,
              href: "/admin/event/field-trip",
            },
            {
              label: "Detail",
              href: `/admin/event/field-trip/${eventId}`,
            },
            {
              label: "Attachments",
              href: `/admin/event/field-trip/${eventId}/attachments`,
            },
            {
              label: "Attachment Detail",
              icon: DocumentTextIcon,
              current: true,
            },
          ],

          backPath: `/admin/event/field-trip/{entityId}/attachments`,
          editPath: `/admin/event/field-trip/{entityId}/attachment/{attachmentId}/update`,
          deletePath: `/admin/event/field-trip/{entityId}/attachment/{attachmentId}/delete`,
        },

        // Header configuration
        header: {
          pageTitle: "Field Trip Event - Attachment Detail",
          pageIcon: PaperClipIcon,
          itemIcon: MapIcon,
          itemType: "Field Trip Event",
          backLabel: "Back to Attachments",
        },
      }),
      [attachmentManager],
    );

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

function AdminFieldTripDetailAttachmentDetailPage() {
  return (
    <UIXThemeProvider>
      <AdminFieldTripDetailAttachmentDetailPageContent />
    </UIXThemeProvider>
  );
}

export default AdminFieldTripDetailAttachmentDetailPage;
