export type ComposerMediaMenuAction = 'attachment' | 'gif' | 'emoji';

export interface ComposerMediaMenuOption {
  action: ComposerMediaMenuAction;
  labelKey: string;
}

export interface ComposerTextareaPaddingInput {
  isMobileViewport: boolean;
  showAttachment: boolean;
  klipyEnabled: boolean;
}

/** Whether the composer should expose one media menu trigger instead of separate buttons. */
export function shouldMergeComposerMediaActions(isMobileViewport: boolean): boolean {
  return isMobileViewport;
}

/** Build the actions shown in the merged mobile composer media menu. */
export function buildComposerMediaMenuOptions(showAttachment: boolean, klipyEnabled: boolean): ComposerMediaMenuOption[] {
  const options: ComposerMediaMenuOption[] = [];

  if (showAttachment) {
    options.push({ action: 'attachment', labelKey: 'chat.mediaMenu.attachFiles' });
  }

  if (klipyEnabled) {
    options.push({ action: 'gif', labelKey: 'chat.mediaMenu.gif' });
  }

  options.push({ action: 'emoji', labelKey: 'chat.mediaMenu.emoji' });

  return options;
}

/** Resolve textarea right padding based on how many composer action buttons are visible. */
export function resolveComposerTextareaPaddingClass(input: ComposerTextareaPaddingInput): string {
  if (input.isMobileViewport) {
    return 'pr-28';
  }

  if (input.showAttachment && !input.klipyEnabled) {
    return 'pr-36';
  }

  if (input.showAttachment && input.klipyEnabled) {
    return 'pr-52';
  }

  if (!input.showAttachment && !input.klipyEnabled) {
    return 'pr-28';
  }

  return 'pr-44';
}
