// File Path: monorepo/web/frontend/src/pages/Admin/Facilitator/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 AdminFacilitatorDetailAttachmentUpdatePageContent = memo(
  function AdminFacilitatorDetailAttachmentUpdatePageContent() {
    const attachmentManager = useAttachmentManager();

    // Configuration for EntityAttachmentUpdatePage
    const config = useMemo(
      () => ({
        entityType: "facilitator",
        entityIdParam: "aid", // Facilitator uses 'aid' for facilitator 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: (facilitatorId, attachmentId) => [
            {
              label: "Dashboard",
              href: "/admin/dashboard",
              icon: ChartBarIcon,
            },
            {
              label: "Facilitators",
              icon: UserGroupIcon,
              href: "/admin/facilitators",
            },
            {
              label: "Detail",
              href: `/admin/facilitator/${facilitatorId}`,
            },
            {
              label: "Attachments",
              href: `/admin/facilitator/${facilitatorId}/attachments`,
            },
            {
              label: "Update Attachment",
              icon: PencilSquareIcon,
              current: true,
            },
          ],

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

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

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

function AdminFacilitatorDetailAttachmentUpdatePage() {
  return (
    <UIXThemeProvider>
      <AdminFacilitatorDetailAttachmentUpdatePageContent />
    </UIXThemeProvider>
  );
}

export default AdminFacilitatorDetailAttachmentUpdatePage;
