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

import React, { useMemo, useCallback } from "react";
import { useParams } from "react-router";
import {
  ChartBarIcon,
  CalendarIcon,
  PlusCircleIcon,
  ClipboardDocumentListIcon,
  DocumentArrowUpIcon,
} from "@heroicons/react/24/outline";
import {
  useAttachmentManager,
  useEventManager,
} from "../../../../../../../services/Services";
import { EntityAttachmentAddPage } from "../../../../../../../components/UIX";
import { ATTACHMENT_OWNERSHIP_TYPE } from "../../../../../../../constants/Attachment";

function AdminConferenceDetailAttachmentAddPage() {
  const { cid } = useParams();
  const attachmentManager = useAttachmentManager();
  const eventManager = useEventManager();

  // Fetch event details
  const fetchEntity = useCallback(async (eventId, onUnauthorized) => {
    return await eventManager.getEventDetail(eventId, onUnauthorized);
  }, []); // eslint-disable-line react-hooks/exhaustive-deps

  // Handle attachment upload
  const uploadAttachment = useCallback(async (file, metadata, onProgress, onUnauthorized) => {
    return await attachmentManager.uploadAttachment(
      file,
      metadata,
      onProgress,
      onUnauthorized,
    );
  }, []); // eslint-disable-line react-hooks/exhaustive-deps

  // Configuration object
  const config = useMemo(() => ({
    entityId: cid,
    entityType: "conference event",
    ownershipType: ATTACHMENT_OWNERSHIP_TYPE.CONFERENCE_EVENT,
    maxFileSize: 10 * 1024 * 1024, // 10MB

    fetchEntity,
    uploadAttachment,

    breadcrumbs: {
      items: [
        {
          label: "Dashboard",
          to: "/admin/dashboard",
          icon: ChartBarIcon,
        },
        {
          label: "Events",
          to: "/admin/events",
          icon: CalendarIcon,
        },
        {
          label: "Conference",
          to: "/admin/event/conference",
        },
        {
          label: "Detail (Attachments)",
          to: `/admin/event/conference/${cid}/attachments`,
          icon: ClipboardDocumentListIcon,
        },
        {
          label: "Add",
          icon: PlusCircleIcon,
          isActive: true,
        },
      ]
    },

    header: {
      title: "Conference Event - Add Attachment",
      icon: DocumentArrowUpIcon,
      loadingText: "Loading event details...",
    },

    routes: {
      backPath: `/admin/event/conference/${cid}/attachments`,
      backLabel: "Back to Attachments",
      successPath: `/admin/event/conference/${cid}/attachments`,
    },

    showEntityStatus: true,
    canUpload: (event) => {
      return event ? event.status !== 'archived' : false;
    },
  }), [cid, fetchEntity, uploadAttachment]);

  return <EntityAttachmentAddPage config={config} />;
}

export default AdminConferenceDetailAttachmentAddPage;
