/**
 * Applies attributes to guild folders on the guilds sidebar.
 * @module Folder
 * @memberof Builtin.Attributes.Guilds
 */

import { patch, unpatch } from '@vizality/patcher';
import { getModule } from '@vizality/webpack';

export const labels = [ 'Guilds', 'Folder' ];

export default builtin => {
  const GuildFolder = getModule(m => m.GuildFolderComponent);
  patch('vz-attributes-guild-folders', GuildFolder?.default, 'render', (_args, res) => {
    try {
      const { unread, selected, expanded, audio, video, screenshare, badge: mentions } = res.props;
      res.props['vz-unread'] = Boolean(unread) && '';
      res.props['vz-selected'] = Boolean(selected) && '';
      res.props['vz-expanded'] = Boolean(expanded) && '';
      res.props['vz-collapsed'] = Boolean(!expanded) && '';
      res.props['vz-audio'] = Boolean(audio) && '';
      res.props['vz-video'] = Boolean(video) && '';
      res.props['vz-screenshare'] = Boolean(screenshare) && '';
      res.props['vz-mentioned'] = Boolean(mentions > 0) && '';
      return res;
    } catch (err) {
      return builtin.error(builtin._labels.concat(labels), err);
    }
  });
  return () => unpatch('vz-attributes-guild-folders');
};
