/* Essentials YOOtheme Pro 2.2.16 build 0813.1608; ZOOlanders https://www.zoolanders.com; Copyright (C) Joolanders, SL; http://www.gnu.org/licenses/gpl.html GNU/GPL */

import Vue from 'vue';
import AccessIcon from './AccessIcon.vue';

Vue.events.on('statusIconsNode', ({ origin: Node, result = [] }) => {
    if (hasAccessIcon(Node)) {
        result.push({ component: AccessIcon });
    }

    return result;
});

function hasAccessIcon(Node) {
    const nodes = [Node.node];

    if ((Node.type.element && Node.type.container) || Node.type.name === 'row') {
        nodes.push(...Node.children);
    }

    return nodes.some((node) => (node?.props?.yooessentials_access_conditions ?? []).length);
}
