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

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

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

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

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

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

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

function AdminSpeakerDetailAttachmentUpdatePage() {
  return (
    <UIXThemeProvider>
      <AdminSpeakerDetailAttachmentUpdatePageContent />
    </UIXThemeProvider>
  );
}

export default AdminSpeakerDetailAttachmentUpdatePage;