import React from 'react';

import { CatalogEntityRelationsRootNode } from '@redocly/theme/components/Catalog/CatalogEntity/CatalogEntityGraph/CatalogEntityRelationsRootNode';
import { CatalogEntityRelationsLinkedNode } from '@redocly/theme/components/Catalog/CatalogEntity/CatalogEntityGraph/CatalogEntityRelationsLinkedNode';

export type CatalogEntityNodeData = {
  label: string;
  entityType: string;
  entityKey: string;
  isRoot?: boolean;
};

export type CatalogEntityRelationsNodeProps = { data: CatalogEntityNodeData; className?: string };

export enum HandleType {
  Target = 'target',
  Source = 'source',
}

export function CatalogEntityRelationsNode({
  data,
  className,
}: CatalogEntityRelationsNodeProps): React.ReactElement {
  const { label, entityType, isRoot, entityKey } = data;
  const mergedClassName = `nopan${className ? ` ${className}` : ''}`;

  if (isRoot) {
    return (
      <CatalogEntityRelationsRootNode
        className={mergedClassName}
        label={label}
        entityType={entityType}
      />
    );
  }

  return (
    <CatalogEntityRelationsLinkedNode
      className={mergedClassName}
      label={label}
      entityType={entityType}
      to={`/catalogs/all/entities/${entityKey}`}
    />
  );
}
