import React, { JSX } from 'react';

import { BffCatalogEntity } from '@redocly/theme/core/types';
import { GraphIcon } from '@redocly/theme/icons/GraphIcon/GraphIcon';
import { Tag } from '@redocly/theme/components/Tag/Tag';
import { CatalogEntityPropertyCard } from '@redocly/theme/components/Catalog/CatalogEntity/CatalogEntityProperties/CatalogEntityPropertyCard';
import { useThemeHooks } from '@redocly/theme/core/hooks';

export type DomainsPropertyProps = {
  entity: BffCatalogEntity;
};

export function DomainsProperty({ entity }: DomainsPropertyProps): JSX.Element {
  const { useTranslate } = useThemeHooks();
  const { translate } = useTranslate();

  const { domains = [] } = entity;

  return (
    <div data-component-name="Catalog/CatalogEntity/CatalogEntityProperties/DomainsProperty">
      <CatalogEntityPropertyCard
        header={
          <>
            <GraphIcon />
            {translate('catalog.domains.label', 'Domains')}
          </>
        }
        content={
          <>
            {domains?.map((domain) => (
              <Tag
                key={domain?.id}
                style={{ backgroundColor: 'var(--bg-color)' }}
                variant="outline"
              >
                <GraphIcon />
                {domain?.title}
              </Tag>
            ))}
          </>
        }
      />
    </div>
  );
}
