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

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

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

    // Configuration for EntityAttachmentUpdatePage
    const config = useMemo(
      () => ({
        entityType: "virtual",
        entityIdParam: "vid", // Virtual uses 'vid' 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: HomeIcon,
            },
            {
              label: "Events",
              href: "/admin/events",
              icon: VideoCameraIcon,
            },
            {
              label: "Virtual",
              href: "/admin/event/virtuals",
              icon: VideoCameraIcon,
            },
            {
              label: "Detail",
              href: `/admin/event/virtual/${eventId}`,
            },
            {
              label: "Attachments",
              href: `/admin/event/virtual/${eventId}/attachments`,
            },
            {
              label: "Update Attachment",
              icon: PencilSquareIcon,
              current: true,
            },
          ],

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

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

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

function AdminVirtualDetailAttachmentUpdatePage() {
  return (
    <UIXThemeProvider>
      <AdminVirtualDetailAttachmentUpdatePageContent />
    </UIXThemeProvider>
  );
}

export default AdminVirtualDetailAttachmentUpdatePage;
