<?php

$collectPermissionKeys = static function (array $items) use (&$collectPermissionKeys): array {
    $keys = [];

    foreach ($items as $item) {
        $permission = $item['permission_key'] ?? null;
        if (is_string($permission) && $permission !== '') {
            $keys[] = $permission;
        }

        $children = $item['children'] ?? [];
        if (is_array($children) && $children !== []) {
            $keys = [...$keys, ...$collectPermissionKeys($children)];
        }
    }

    return $keys;
};

$dashboardPermissions = $collectPermissionKeys(config('mtt_dashboard_menu', []));

$settingsPermissions = [
    'settings.dealers.view',
    'settings.dealers.manage',
    'settings.users.view',
    'settings.users.manage',
    'settings.users.security',
    'settings.departments.manage',
    'settings.branches.manage',
    'settings.branding.manage',
];

return array_values(array_unique(array_merge(
    ['dashboard.index.view'],
    $dashboardPermissions,
    $settingsPermissions
)));
