<?php

namespace Convertforce\Admin;

class Menu
{
    public static function register()
    {
        add_menu_page(
            'ConvertForce',
            'ConvertForce',
            'manage_options',
            'convertforce',
            [__CLASS__, 'render'],
            plugins_url('assets/images/logo-20.png', CONVERTFORCE_FILE),
            100
        );

        // First submenu with same slug as parent so the top-level link points here (not to CPT list).
        add_submenu_page(
            'convertforce',
            'ConvertForce',
            'Features',
            'manage_options',
            'convertforce',
            [__CLASS__, 'render']
        );
        add_submenu_page(
            'convertforce',
            'New Campaign',
            'New Campaign',
            'edit_posts',
            'post-new.php?post_type=convertforce-popup'
        );
    }

    public static function render()
    {
        if (!isset($_GET['page']) || $_GET['page'] !== 'convertforce') {
            return;
        }

        $version          = defined('CONVERTFORCE_VERSION') ? CONVERTFORCE_VERSION : '';
        $welcome_url      = admin_url('admin.php?page=convertforce');
        $campaigns_url    = admin_url('edit.php?post_type=convertforce-popup');
        $new_campaign_url = admin_url('post-new.php?post_type=convertforce-popup');
        $docs_url         = 'https://convertforce.com/docs/';
        $support_url      = 'https://convertforce.com/contact/';

        include __DIR__ . '/templates/react.php';
    }
}