<?php
/**
 * apCampaign license and update client wrapper.
 *
 * @package apCampaign
 */

declare(strict_types=1);

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

final class APCampaign_License
{
    public static function init(): void
    {
        self::client()->hooks();
        add_action('admin_menu', [__CLASS__, 'admin_menu']);
    }

    public static function client(): ArtistProWP_License_Client
    {
        static $client = null;
        if (!$client) {
            $client = new ArtistProWP_License_Client([
                'product_key' => 'apcampaign',
                'product_name' => 'apCampaign',
                'plugin_file' => plugin_basename(APCAMPAIGN_PLUGIN_FILE),
                'version' => APCAMPAIGN_VERSION,
                'option_prefix' => 'apcampaign',
                'purchase_url' => 'https://artistprowp.com/apcampaign/',
                'account_url' => 'https://artistprowp.com/my-account/',
                'support_url' => 'mailto:support@artistprowp.com',
                'admin_page' => 'apcampaign-license',
                'admin_screen_contains' => 'apcampaign-license',
                'nonce_action' => 'apcampaign_license',
                'ajax_prefix' => 'apcampaign',
            ]);
        }
        return $client;
    }

    public static function admin_menu(): void
    {
        add_submenu_page('apcampaign', 'apCampaign License', 'License', 'manage_options', 'apcampaign-license', [__CLASS__, 'render_page']);
    }

    public static function render_page(): void
    {
        self::client()->render_panel();
    }
}
