Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

1.5 KB
Raw Blame
'use client';

import { Alert, createStaticStyles, cx } from '@lobehub/ui';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';

import { useProviderName } from '@/hooks/useProviderName';

import { type GenerationModelNotice as GenerationModelNoticeType } from './useGenerationModelNotice';

const styles = createStaticStyles(({ css, cssVar }) => ({
  alert: css`
    flex: 0 1 auto;

    /* Keep the icon centered against the single-line title. */
    align-items: center !important;

    min-width: 0;
    max-width: min(560px, 52vw);
    padding-block: 4px !important;
    padding-inline: 8px 10px !important;
    border-radius: ${cssVar.borderRadius};

    @media (width <= 768px) {
      max-width: 100%;
    }
  `,
}));

interface GenerationModelNoticeProps {
  notice: GenerationModelNoticeType | undefined;
  /** i18n namespace the notice key resolves against. */
  ns: 'image' | 'music' | 'video';
}

const GenerationModelNotice = memo<GenerationModelNoticeProps>(({ notice, ns }) => {
  const { t } = useTranslation(ns);
  // Hooks must run unconditionally; `useProviderName('')` falls back to the raw id.
  const providerName = useProviderName(notice?.provider ?? '');

  if (!notice) return null;

  return (
    <Alert
      classNames={{ alert: cx(styles.alert) }}
      style={{ fontSize: 12 }}
      title={t(notice.key, { name: providerName })}
      type={notice.type}
      variant={'borderless'}
    />
  );
});

GenerationModelNotice.displayName = 'GenerationModelNotice';

export default GenerationModelNotice;