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

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

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

    // Configuration for EntityAttachmentDetailPage
    const config = useMemo(
      () => ({
        entityType: "event-contract",
        entityIdParam: "ecid", // Event contract uses 'ecid' for event contract ID
        attachmentIdParam: "atid", // and 'atid' for attachment ID

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

        // Route configuration
        routes: {
          buildBreadcrumbs: (eventContractId, attachmentId) => [
            {
              label: "Dashboard",
              href: "/admin/dashboard",
              icon: ChartBarIcon,
            },
            {
              label: "Event Contracts",
              icon: DocumentTextIcon,
              href: "/admin/event-contracts",
            },
            {
              label: "Detail",
              href: `/admin/event-contract/${eventContractId}`,
            },
            {
              label: "Attachments",
              href: `/admin/event-contract/${eventContractId}/attachments`,
            },
            {
              label: "Attachment Detail",
              icon: DocumentTextIcon,
              current: true,
            },
          ],

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

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

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

function AdminEventContractDetailAttachmentDetailPage() {
  return (
    <UIXThemeProvider>
      <AdminEventContractDetailAttachmentDetailPageContent />
    </UIXThemeProvider>
  );
}

export default AdminEventContractDetailAttachmentDetailPage;
