import React, { JSX } from 'react';

import { BffCatalogEntity } from '@redocly/theme/core/types';
import { PeopleIcon } from '@redocly/theme/icons/PeopleIcon/PeopleIcon';
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 OwnersPropertyProps = {
  entity: BffCatalogEntity;
};

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

  const { owners = [] } = entity;

  return (
    <div data-component-name="Catalog/CatalogEntity/CatalogEntityProperties/OwnersProperty">
      <CatalogEntityPropertyCard
        header={
          <>
            <PeopleIcon />
            {translate('catalog.owners.label', 'Owners')}
          </>
        }
        content={
          <>
            {owners.map((owner) => (
              <Tag
                key={owner?.id}
                style={{
                  backgroundColor: 'var(--bg-color)',
                  borderRadius: 'var(--border-radius-xl)',
                }}
                variant="outline"
              >
                {owner?.title}
              </Tag>
            ))}
          </>
        }
      />
    </div>
  );
}
