import React from 'react';

import { PageFormModal } from './PageFormModal';
import type {
  PageMenuTreeNode,
  PageResourceAssignment,
  ResourceDefinition,
} from '../types';

interface EditPageModalProps {
  pageIdToEdit?: number;
  onModalClose: () => void;
  onPageEditSuccess?: () => void;
  parentPageTreeOptions?: PageMenuTreeNode[];
  allAvailableResources?: ResourceDefinition[];
  currentPageResourceAssignments?: PageResourceAssignment[];
  allPagesData?: any[];
}

export const EditPageModal: React.FC<EditPageModalProps> = ({
  pageIdToEdit,
  onModalClose,
  onPageEditSuccess,
  parentPageTreeOptions,
  allAvailableResources,
  currentPageResourceAssignments,
  allPagesData,
}) => {
  const handlePageEditMutationSuccess = () => {
    onPageEditSuccess?.();
    onModalClose();
  };

  return (
    <PageFormModal
      formActionType="edit"
      editingPageId={pageIdToEdit}
      onModalCancel={onModalClose}
      onFormSubmitSuccess={handlePageEditMutationSuccess}
      parentPageTreeOptions={parentPageTreeOptions}
      allAvailableResources={allAvailableResources}
      currentResourceAssignments={currentPageResourceAssignments}
      allPagesData={allPagesData}
    />
  );
};
