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

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

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

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

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

        // Route configuration
        routes: {
          buildBreadcrumbs: (organizationId, attachmentId) => [
            {
              label: "Dashboard",
              href: "/admin/dashboard",
              icon: ChartBarIcon,
            },
            {
              label: "Organizations",
              icon: BuildingOffice2Icon,
              href: "/admin/organizations",
            },
            {
              label: "Detail",
              href: `/admin/organization/${organizationId}`,
            },
            {
              label: "Attachments",
              href: `/admin/organization/${organizationId}/attachments`,
            },
            {
              label: "Attachment Detail",
              icon: DocumentTextIcon,
              current: true,
            },
          ],

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

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

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

function AdminOrganizationDetailAttachmentDetailPage() {
  return (
    <UIXThemeProvider>
      <AdminOrganizationDetailAttachmentDetailPageContent />
    </UIXThemeProvider>
  );
}

export default AdminOrganizationDetailAttachmentDetailPage;
