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

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

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

    // Configuration for EntityAttachmentDetailPage
    const config = useMemo(
      () => ({
        entityType: "division",
        entityIdParam: "did", // Division uses 'did' for division ID
        attachmentIdParam: "atid", // and 'atid' for attachment ID

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

        // Route configuration
        routes: {
          buildBreadcrumbs: (divisionId, attachmentId) => [
            {
              label: "Dashboard",
              href: "/admin/dashboard",
              icon: ChartBarIcon,
            },
            {
              label: "Divisions",
              icon: BuildingOfficeIcon,
              href: "/admin/divisions",
            },
            {
              label: "Detail",
              href: `/admin/division/${divisionId}`,
            },
            {
              label: "Attachments",
              href: `/admin/division/${divisionId}/attachments`,
            },
            {
              label: "Attachment Detail",
              icon: DocumentTextIcon,
              current: true,
            },
          ],

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

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

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

function AdminDivisionDetailAttachmentDetailPage() {
  return (
    <UIXThemeProvider>
      <AdminDivisionDetailAttachmentDetailPageContent />
    </UIXThemeProvider>
  );
}

export default AdminDivisionDetailAttachmentDetailPage;
