import {
  buildComposerMediaMenuOptions,
  resolveComposerTextareaPaddingClass,
  shouldMergeComposerMediaActions
} from './composer-media-menu.rules';

describe('composer-media-menu.rules', () => {
  describe('shouldMergeComposerMediaActions', () => {
    it('merges attachment, gif, and emoji triggers on mobile viewports', () => {
      expect(shouldMergeComposerMediaActions(true)).toBe(true);
    });

    it('keeps separate triggers on desktop viewports', () => {
      expect(shouldMergeComposerMediaActions(false)).toBe(false);
    });
  });

  describe('buildComposerMediaMenuOptions', () => {
    it('includes attachment, gif, and emoji when all are available', () => {
      expect(buildComposerMediaMenuOptions(true, true)).toEqual([
        { action: 'attachment', labelKey: 'chat.mediaMenu.attachFiles' },
        { action: 'gif', labelKey: 'chat.mediaMenu.gif' },
        { action: 'emoji', labelKey: 'chat.mediaMenu.emoji' }
      ]);
    });

    it('omits attachment when the picker is unavailable', () => {
      const gifOption = { action: 'gif' as const, labelKey: 'chat.mediaMenu.gif' };
      const emojiOption = { action: 'emoji' as const, labelKey: 'chat.mediaMenu.emoji' };

      expect(buildComposerMediaMenuOptions(false, true)).toEqual([gifOption, emojiOption]);
    });

    it('omits gif when klipy is disabled', () => {
      const options = buildComposerMediaMenuOptions(true, false);

      expect(options.map((option) => option.action)).toEqual(['attachment', 'emoji']);
    });

    it('always includes emoji even when attachment and gif are unavailable', () => {
      expect(buildComposerMediaMenuOptions(false, false)).toEqual([{ action: 'emoji', labelKey: 'chat.mediaMenu.emoji' }]);
    });
  });

  describe('resolveComposerTextareaPaddingClass', () => {
    it('uses compact padding when mobile actions are merged', () => {
      expect(
        resolveComposerTextareaPaddingClass({
          isMobileViewport: true,
          showAttachment: true,
          klipyEnabled: true
        })
      ).toBe('pr-28');
    });

    it('preserves desktop padding combinations', () => {
      expect(
        resolveComposerTextareaPaddingClass({
          isMobileViewport: false,
          showAttachment: true,
          klipyEnabled: false
        })
      ).toBe('pr-36');

      expect(
        resolveComposerTextareaPaddingClass({
          isMobileViewport: false,
          showAttachment: true,
          klipyEnabled: true
        })
      ).toBe('pr-52');

      expect(
        resolveComposerTextareaPaddingClass({
          isMobileViewport: false,
          showAttachment: false,
          klipyEnabled: false
        })
      ).toBe('pr-28');

      expect(
        resolveComposerTextareaPaddingClass({
          isMobileViewport: false,
          showAttachment: false,
          klipyEnabled: true
        })
      ).toBe('pr-44');
    });
  });
});
