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

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

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

    // Configuration for EntityAttachmentUpdatePage
    const config = useMemo(
      () => ({
        entityType: "event-order",
        entityIdParam: "eoid", // Event Order uses 'eoid' for event order 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: (eoid, attachmentId) => [
            {
              label: "Dashboard",
              href: "/admin/dashboard",
              icon: ChartBarIcon,
            },
            {
              label: "Event Orders",
              icon: TicketIcon,
              href: "/admin/event-orders",
            },
            {
              label: "Detail",
              href: `/admin/event-order/${eoid}`,
            },
            {
              label: "Attachments",
              href: `/admin/event-order/${eoid}/attachments`,
            },
            {
              label: "Update Attachment",
              icon: PencilSquareIcon,
              current: true,
            },
          ],

          backPath: `/admin/event-order/{entityId}/attachment/{attachmentId}`,
          successRedirectPath: `/admin/event-order/{entityId}/attachment/{attachmentId}`,
        },

        // Header configuration
        header: {
          pageTitle: "Event Order - Update Attachment",
          pageIcon: PencilSquareIcon,
          entityIcon: TicketIcon,
          entityType: "Event Order",
          backLabel: "Back to Detail",
          basePath: "/admin/event-orders",
        },
      }),
      [attachmentManager],
    );

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

function AdminEventOrderDetailAttachmentUpdatePage() {
  return (
    <UIXThemeProvider>
      <AdminEventOrderDetailAttachmentUpdatePageContent />
    </UIXThemeProvider>
  );
}

export default AdminEventOrderDetailAttachmentUpdatePage;
