<?php

namespace Elementor_Pay_Addons\Traits;

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

// Exit if accessed directly

use Elementor_Pay_Addons\Shared\Utils;

trait Admin
{
    /**
     * Create an admin menu.
     *
     * @since 1.0.0
     */
    public function admin_menu()
    {
        $svg_img = 'data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMjQiIGhlaWdodD0iMTAyNCIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCI+CjxnIGlkPSJpY29tb29uLWlnbm9yZSI+CjwvZz4KPHBhdGggZmlsbD0iI2EyYWFiMiIgZD0iTTgyNC44ODcgODUuMzMzYzYyLjgzOSAwIDExMy43NzkgNTAuOTQgMTEzLjc3OSAxMTMuNzc4djYyNS43NzZjMCA2Mi44MzktNTAuOTQgMTEzLjc3OS0xMTMuNzc5IDExMy43NzloLTYyNS43NzZjLTYyLjgzOCAwLTExMy43NzgtNTAuOTQtMTEzLjc3OC0xMTMuNzc5di02MjUuNzc2YzAtNjIuODM4IDUwLjk0LTExMy43NzggMTEzLjc3OC0xMTMuNzc4aDYyNS43NzZ6TTQxMS43NzkgNzg2Ljk2MXYtMjExLjIwOWgxMTcuMjdjMzcuMTUgMCA3MC40MTctNy4yNzkgOTkuODA2LTIxLjg1IDI5Ljk0My0xNC41NjYgNTMuNTA4LTM1LjA2MyA3MC42OTQtNjEuNSAxNy4xOS0yNi45NzQgMjUuNzgzLTU4LjgwMyAyNS43ODMtOTUuNDg5IDAtMzYuNjg1LTguNTkzLTY4LjI0NS0yNS43ODMtOTQuNjgtMTcuMTg2LTI2Ljk3NC00MC43NTEtNDcuNzQ0LTcwLjY5NC02Mi4zMTEtMjkuMzg5LTE0LjU2Ni02Mi42NTYtMjEuODQ5LTk5LjgwNi0yMS44NDloLTIzMC4zODN2NTY4Ljg4N2gxMTMuMTEzek01MTcuNDA2IDQ4NS45MzFoLTEwNS42MjZ2LTE3OC4wMzJoMTA1LjYyNmMxNy43NDUgMCAzMy44MjIgMy41MDcgNDguMjM5IDEwLjUyczI1Ljc4MyAxNy4yNjQgMzQuMTAzIDMwLjc1MWM4LjMxMSAxMy40ODcgMTIuNDcxIDI5LjQwMiAxMi40NzEgNDcuNzQ0IDAgMTguODgzLTQuMTYgMzUuMDY1LTEyLjQ3MSA0OC41NTYtOC4zMiAxMi45NDUtMTkuNjg2IDIyLjkyNS0zNC4xMDMgMjkuOTM5cy0zMC40OTQgMTAuNTIyLTQ4LjIzOSAxMC41MjJ6TTYwNy4yNDkgNzgxLjMwOGMxMi45MzIgMTMuMjQ4IDI5LjUyMSAxOS44NzggNDkuNzY2IDE5Ljg3OCAxOS42NzggMCAzNS45ODUtNi42MyA0OC45MTctMTkuODc4IDEyLjkzMi0xMy4yNTIgMTkuNDAxLTI5LjU0MiAxOS40MDEtNDguODYyIDAtMTkuMzI0LTYuNDY4LTM1LjYxNC0xOS40MDEtNDguODY2LTEyLjkzMi0xMy4yNDgtMjkuMjM5LTE5Ljg3OC00OC45MTctMTkuODc4LTIwLjI0NSAwLTM2LjgzNCA2LjYzLTQ5Ljc2NiAxOS44NzgtMTIuOTMyIDEzLjI1Mi0xOS4zOTYgMjkuNTQyLTE5LjM5NiA0OC44NjYgMCAxOS4zMTkgNi40NjQgMzUuNjEgMTkuMzk2IDQ4Ljg2MnoiPjwvcGF0aD4KPC9zdmc+Cg==';
        add_menu_page(
            'Elementor Payment',
            'Elementor Pay',
            'manage_options',
            'elementor-pay-addons',
            array($this, 'admin_settings_page'),
            $svg_img,
            58
        );

        // Add Transactions as a sub-menu page under Elementor Pay
        add_submenu_page(
            'elementor-pay-addons',
            'Transactions',
            'Transactions',
            'manage_options',
            'elementor-pay-addons-transactions',
            array($this, 'epa_transactions_page')
        );
    }
    /**
     * Render the transactions page as a full-width admin page
     */
    public function epa_transactions_page() {
        require EPA_ADDONS_PATH . '/includes/admin/pages/transactions.php';
    }

    /**
     * Loading all scripts
     *
     * @since 1.0.0
     */
    public function admin_enqueue_scripts($hook)
    {
        if (isset($hook) && ($hook == 'toplevel_page_elementor-pay-addons' || $hook == 'elementor-pay_page_elementor-pay-addons-transactions')) {
            wp_enqueue_script('wp-color-picker');
            wp_enqueue_style('wp-color-picker');
            wp_enqueue_script('epa-tiptip', EPA_ADDONS_ASSET_URL . 'lib/js/jquery-tiptip/jquery.tipTip.js', array('jquery'), EPA_PLUGIN_VERSION);

            wp_enqueue_script('flowbite-js', 'https://cdnjs.cloudflare.com/ajax/libs/flowbite/1.8.0/flowbite.min.js', false, null, true);
            wp_enqueue_style('elementor-pay-addons-admin-css', EPA_ADDONS_ASSET_URL . 'admin/css/admin.css', false, EPA_PLUGIN_VERSION);
            wp_enqueue_script('elementor-pay-addons-admin-js', EPA_ADDONS_ASSET_URL . 'admin/js/admin.js', ['wp-color-picker'], EPA_PLUGIN_VERSION, true);
            wp_localize_script('elementor-pay-addons-admin-js', 'epaSettings', array(
                'root' => esc_url_raw(rest_url() . EPA_ADDONS_REST_API),
                'nonce' => wp_create_nonce('wp_rest'),
                'locale' => get_locale(),
            ));
        }
    }

    /**
     * Create settings page.
     *
     * @since 1.0.0
     */
    public function admin_settings_page()
    {
        require_once EPA_ADDONS_PATH . '/includes/admin/pages/home.php';
    }
}
