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

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

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

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

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

        // Route configuration
        routes: {
          buildBreadcrumbs: (customerId) => [
            {
              label: "Dashboard",
              href: "/admin/dashboard",
              icon: ChartBarIcon,
            },
            {
              label: "Customers",
              icon: UserGroupIcon,
              href: "/admin/customers",
            },
            {
              label: "Detail",
              href: `/admin/customer/${customerId}`,
            },
            {
              label: "Attachments",
              href: `/admin/customer/${customerId}/attachments`,
            },
            {
              label: "Attachment Detail",
              icon: DocumentTextIcon,
              current: true,
            },
          ],

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

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

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

function AdminCustomerDetailAttachmentDetailPage() {
  return (
    <UIXThemeProvider>
      <AdminCustomerDetailAttachmentDetailPageContent />
    </UIXThemeProvider>
  );
}

export default AdminCustomerDetailAttachmentDetailPage;
