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

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

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

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

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

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

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

function AdminStaffDetailAttachmentUpdatePage() {
  return (
    <UIXThemeProvider>
      <AdminStaffDetailAttachmentUpdatePageContent />
    </UIXThemeProvider>
  );
}

export default AdminStaffDetailAttachmentUpdatePage;
