import React, { JSX } from 'react';

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

export type ContactPropertyProps = {
  entity: BffCatalogEntity;
};

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

  const channels = entity.contact?.slack?.channels;

  return (
    <div data-component-name="Catalog/CatalogEntity/CatalogEntityProperties/ContactProperty">
      <CatalogEntityPropertyCard
        header={
          <>
            <SlackIcon />
            {translate('catalog.contact.label', 'Slack channels')}
          </>
        }
        content={
          <>
            {channels?.map((channel) => (
              <Button
                key={channel.name}
                variant="outlined"
                size="small"
                style={{ backgroundColor: 'var(--bg-color)' }}
                to={channel.url}
                external={true}
              >
                {channel.name}
              </Button>
            ))}
          </>
        }
      />
    </div>
  );
}
