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

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

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

  // Configuration for EntityAttachmentUpdatePage
  const config = useMemo(() => ({
    entityType: "division",
    entityIdParam: "did", // Division uses 'did' for division 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: (divisionId, attachmentId) => [
        {
          label: "Dashboard",
          href: "/admin/dashboard",
          icon: ChartBarIcon
        },
        {
          label: "Divisions",
          icon: BuildingOfficeIcon,
          href: "/admin/divisions"
        },
        {
          label: "Detail",
          href: `/admin/division/${divisionId}`
        },
        {
          label: "Attachments",
          href: `/admin/division/${divisionId}/attachments`
        },
        {
          label: "Update Attachment",
          icon: PencilSquareIcon,
          current: true
        }
      ],

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

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

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

function AdminDivisionDetailAttachmentUpdatePage() {
  return (
    <UIXThemeProvider>
      <AdminDivisionDetailAttachmentUpdatePageContent />
    </UIXThemeProvider>
  );
}

export default AdminDivisionDetailAttachmentUpdatePage;
