import React from 'react';

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

interface CreatePageModalProps {
  onModalClose: () => void;
  onPageCreationSuccess?: () => void;
  parentPageTreeOptions?: PageMenuTreeNode[];
  allAvailableResources?: ResourceDefinition[];
  allPagesData?: any[];
  defaultParentId?: number | null;
  defaultPathPrefix?: string;
}

export const CreatePageModal: React.FC<CreatePageModalProps> = ({
  onModalClose,
  onPageCreationSuccess,
  parentPageTreeOptions,
  allAvailableResources,
  allPagesData,
  defaultParentId,
  defaultPathPrefix,
}) => {
  const handlePageCreationMutationSuccess = () => {
    onPageCreationSuccess?.();
    onModalClose?.();
  };

  return (
    <PageFormModal
      formActionType="create"
      onModalCancel={onModalClose}
      onFormSubmitSuccess={handlePageCreationMutationSuccess}
      parentPageTreeOptions={parentPageTreeOptions}
      allAvailableResources={allAvailableResources}
      allPagesData={allPagesData}
      defaultParentId={defaultParentId}
      defaultPathPrefix={defaultPathPrefix}
    />
  );
};
