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

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

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

    // Configuration for EntityAttachmentUpdatePage
    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,
          );
        },

        onAttachmentUpdate: async (
          attachmentId,
          updateData,
          onUnauthorized,
        ) => {
          return await attachmentManager.updateAttachment(
            attachmentId,
            updateData,
            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: "Update Attachment",
              icon: PencilSquareIcon,
              current: true,
            },
          ],

          backPath: `/admin/customer/{entityId}/attachment/{attachmentId}`,
          successRedirectPath: `/admin/customer/{entityId}/attachment/{attachmentId}`,
        },

        // Header configuration
        header: {
          pageTitle: "Customer - Update Attachment",
          pageIcon: PencilSquareIcon,
          entityIcon: UserGroupIcon,
          entityType: "Customer",
          backLabel: "Back to Detail",
          basePath: "/admin/customers",
        },
      }),
      [attachmentManager],
    );

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

function AdminCustomerDetailAttachmentUpdatePage() {
  return (
    <UIXThemeProvider>
      <AdminCustomerDetailAttachmentUpdatePageContent />
    </UIXThemeProvider>
  );
}

export default AdminCustomerDetailAttachmentUpdatePage;
