<?php
namespace Atlasly\Admin;

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

use Atlasly\Admin\Pages\Dashboard;
use Atlasly\Admin\Pages\ContentTypes;
use Atlasly\Admin\Pages\Entries;
use Atlasly\Admin\Pages\SetupWizard;
use Atlasly\Admin\Pages\Webhooks;
use Atlasly\Core\Permissions;

class Menu
{
    public static function register()
    {
        $setup_completed = get_option('atlasly_setup_completed', false);
        $reconfigure = isset($_GET['reconfigure']) && '1' === sanitize_text_field(wp_unslash($_GET['reconfigure']));

        if (!$setup_completed || $reconfigure) {
            add_menu_page('Atlasly Setup', 'Atlasly Setup', 'manage_options', 'atlasly-setup', [SetupWizard::class, 'render'], 'dashicons-database', 80);
            return;
        }

        if (Permissions::can_view_dashboard()) {
            add_menu_page('Atlasly', 'Atlasly', 'atlasly_view_dashboard', 'atlasly', [Dashboard::class, 'render'], 'dashicons-database', 80);
        }

        if (Permissions::can_manage_types()) {
            add_submenu_page('atlasly', 'Content Types', 'Content Types', 'atlasly_manage_types', 'atlasly-content-types', [ContentTypes::class, 'render']);
        }

        if (Permissions::can_edit_entries()) {
            add_submenu_page('atlasly', 'Entries', 'Entries', 'atlasly_edit_entries', 'atlasly-entries', [Entries::class, 'render']);
        }

        if (Permissions::can_manage_types()) {
            add_submenu_page('atlasly', 'Settings', 'Settings', 'atlasly_manage_types', 'atlasly-webhooks', [\Atlasly\Admin\Pages\Webhooks::class, 'render']);
        }

        add_submenu_page('atlasly', 'Help', 'Help', 'read', 'atlasly-help', [\Atlasly\Admin\Pages\Help::class, 'render']);
    }
}
