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

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

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

    // Configuration for EntityAttachmentUpdatePage
    const config = useMemo(
      () => ({
        entityType: "field-trip",
        entityIdParam: "ftid", // Field trip uses 'ftid' for event 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: (eventId, attachmentId) => [
            {
              label: "Dashboard",
              href: "/admin/dashboard",
              icon: ChartBarIcon,
            },
            {
              label: "Events",
              href: "/admin/events",
            },
            {
              label: "Field Trip",
              icon: MapIcon,
              href: "/admin/event/field-trip",
            },
            {
              label: "Detail",
              href: `/admin/event/field-trip/${eventId}`,
            },
            {
              label: "Attachments",
              href: `/admin/event/field-trip/${eventId}/attachments`,
            },
            {
              label: "Update Attachment",
              icon: PencilSquareIcon,
              current: true,
            },
          ],

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

        // Header configuration
        header: {
          pageTitle: "Field Trip Event - Update Attachment",
          pageIcon: PencilSquareIcon,
          entityIcon: MapIcon,
          entityType: "Field Trip Event",
          backLabel: "Back to Detail",
          basePath: "/admin/event/field-trip",
        },
      }),
      [attachmentManager],
    );

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

function AdminFieldTripDetailAttachmentUpdatePage() {
  return (
    <UIXThemeProvider>
      <AdminFieldTripDetailAttachmentUpdatePageContent />
    </UIXThemeProvider>
  );
}

export default AdminFieldTripDetailAttachmentUpdatePage;
