const { SystemTray } = ags.Service;
const { Widget } = ags;

export const Systray = () => Widget.Box({
    className: 'systray',
    connections: [[SystemTray, box => {
        box.children = SystemTray.items.map(item =>{ 
            const iconW = Widget.Icon({
                size: 24
            });
            iconW.set_margin_left(6);
            iconW.icon = item.icon;
            const btn = Widget.Button({
                onPrimaryClick: (_, event) => item.activate(event),
                onSecondaryClick: (_, event) => item.openMenu(event),
                child: iconW,
                className: 'systray-icon',
                connections: [[item, button => {
                     button.child.icon = item.icon;
                     button.tooltipMarkup = item.tooltipMarkup;
                }]],
            }); 
            return btn;
      });
    }]],
});
