<?php

return _get_menu_list();

// helpers
function _get_menu_list() {
    $main_items = [
        'order',
        'product',
        'customer',
        'marketing',
        //'investor_relation',
        'article',
        'job',
        'pcbuilder',
        'payinstall',
        'distributor',
        'report',
        'system',
    ];

    $menu_list = [];
    foreach ($main_items as $item) {
        $item_menu = include_once __DIR__."/menu_item/".$item.".php";

        // skip not enabled
        if(!$item_menu['enable']) {
            continue;
        }

        // skip not enabled children
        $item_menu_children_enabled = array_filter($item_menu['menu'], function ($menu_child) { return $menu_child['enable'];});
        if(!sizeof($item_menu_children_enabled)) {
            continue;
        }

        $menu_list[] = [
            'id' => $item,
            'name' => $item_menu['name'],
            'icon_class' => $item_menu['icon_class'] ?? '',
            'url' => $item_menu['url'],
            'menu' => array_map(function ($menu_child) {
                return [
                    //'module' => $menu_child['module'],
                    //'view' => $menu_child['view'],
                    'id' => $menu_child['id'],
                    'name' => $menu_child['name'],
                    'icon_class' => $menu_child['icon_class'] ?? '',
                    'url' => $menu_child['url'],
                ];
            }, $item_menu_children_enabled),
        ];
    }

    //debug_var($menu_list);

    return $menu_list;
}
