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

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

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

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

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

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

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

function AdminEventContractDetailAttachmentUpdatePage() {
  return (
    <UIXThemeProvider>
      <AdminEventContractDetailAttachmentUpdatePageContent />
    </UIXThemeProvider>
  );
}

export default AdminEventContractDetailAttachmentUpdatePage;
