import type { PresentationId } from './types';

export type BubbleRadiusInput = {
  isOut: boolean;
  groupedTop: boolean;
  groupedBottom: boolean;
  /** У Telegram влияет на «острый» нижний угол под хвост; у WhatsApp не используется. */
  showTail: boolean;
};

/**
 * Классы скругления пузыря: Telegram (хвост), WhatsApp (~7.5px), Instagram (отдельная геометрия).
 */
export function getBubbleRadiusClasses(
  id: PresentationId,
  {
    isOut,
    groupedTop,
    groupedBottom,
    showTail,
  }: BubbleRadiusInput
): string {
  if (id === 'whatsapp') {
    const base = 'rounded-[7.5px]';
    if (groupedTop && groupedBottom) {
      return `${base} rounded-t-[5px] rounded-b-[5px]`;
    }
    if (groupedTop) {
      return `${base} rounded-tl-[5px] rounded-tr-[5px]`;
    }
    if (groupedBottom) {
      return `${base} rounded-bl-[5px] rounded-br-[5px]`;
    }
    return base;
  }

  if (id === 'instagram') {
    const base = 'rounded-[22px]';
    if (groupedTop && groupedBottom) {
      return `${base} rounded-t-[11px] rounded-b-[11px]`;
    }
    if (groupedTop) {
      return `${base} rounded-tl-[11px] rounded-tr-[11px]`;
    }
    if (groupedBottom) {
      return `${base} rounded-bl-[11px] rounded-br-[11px]`;
    }
    return base;
  }

  const base = 'rounded-2xl';
  if (isOut) {
    const top = groupedTop ? 'rounded-tr-md' : '';
    const bottom = groupedBottom
      ? 'rounded-br-md'
      : showTail
        ? 'rounded-br-none'
        : '';
    return [base, top, bottom].filter(Boolean).join(' ');
  }
  const top = groupedTop ? 'rounded-tl-md' : '';
  const bottom = groupedBottom
    ? 'rounded-bl-md'
    : showTail
      ? 'rounded-bl-none'
      : '';
  return [base, top, bottom].filter(Boolean).join(' ');
}
