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

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

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

    // Configuration for EntityAttachmentUpdatePage
    const config = useMemo(
      () => ({
        entityType: "organization",
        entityIdParam: "oid", // Organization uses 'oid' for organization 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: (organizationId, attachmentId) => [
            {
              label: "Dashboard",
              href: "/admin/dashboard",
              icon: ChartBarIcon,
            },
            {
              label: "Organizations",
              icon: BuildingOffice2Icon,
              href: "/admin/organizations",
            },
            {
              label: "Detail",
              href: `/admin/organization/${organizationId}`,
            },
            {
              label: "Attachments",
              href: `/admin/organization/${organizationId}/attachments`,
            },
            {
              label: "Update Attachment",
              icon: PencilSquareIcon,
              current: true,
            },
          ],

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

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

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

function AdminOrganizationDetailAttachmentUpdatePage() {
  return (
    <UIXThemeProvider>
      <AdminOrganizationDetailAttachmentUpdatePageContent />
    </UIXThemeProvider>
  );
}

export default AdminOrganizationDetailAttachmentUpdatePage;
