<?php

namespace Linksy\SearchAndReplace\Plugli\Standard\Admin\Partials;

/**
 * The admin-specific functionality of the plugin.
 *
 * @since      1.0.0
 *
 * @package    Plugli\Admin
 * @subpackage Plugli\Admin\Partials
 */
use Linksy\SearchAndReplace\Plugli\Standard\Common\Traits\Hooker;
abstract class Partials
{
    use Hooker;
    public $page;
    protected $plugin_name;
    protected $plugin_version;
    protected $plugin_base_dir;
    protected $plugin_base_path;
    /**
     * The Constructor.
     */
    public function __construct($plugin_name, $version, $plugin_base_dir, $plugin_base_path)
    {
        $this->plugin_name = $plugin_name;
        $this->plugin_version = $version;
        $this->plugin_base_dir = $plugin_base_dir;
        $this->plugin_base_path = $plugin_base_path;
        $this->admin_init();
    }
    protected function get_module_dir_path()
    {
        $class = static::class;
        $reflection = new \ReflectionClass($class);
        return plugin_dir_path($reflection->getFileName());
    }
    public function render_view($module, $variables = array(), $print = \true)
    {
        $output = '';
        $filePath = $this->get_module_dir_path() . "/_build/index.php";
        if (file_exists($filePath)) {
            // Extract the variables to a local namespace
            extract($variables);
            // Start output buffering
            ob_start();
            // Include the template file
            include $filePath;
            // End buffering and return its contents
            $output = ob_get_clean();
        } else {
            $output = '<h1>Page not found</h1>';
        }
        if ($print) {
            print $output;
        }
        return $output;
    }
    /**
     * Check if current page.
     */
    public function is_current_page()
    {
        return isset($_GET['page']) && $this->page === $_GET['page'];
    }
    public function enqueue_files($strict = \true)
    {
        if ($strict && !$this->is_current_page()) {
            return;
        }
        wp_register_script($this->plugin_name, $this->plugin_base_dir . 'assets/js/plugli-admin.js', [], $this->plugin_version, \false);
        $this->action('admin_enqueue_scripts', 'enqueue_styles');
        $this->action('admin_enqueue_scripts', 'enqueue_scripts');
    }
    /**
     * styles.
     */
    public function enqueue_styles()
    {
    }
    /**
     * scripts.
     */
    public function enqueue_scripts()
    {
        wp_add_inline_script($this->plugin_name, "var LINKSY_SECURE_TOKEN = '" . wp_create_nonce($this->page) . "'");
    }
    /**
     * Admin initialize.
     */
    abstract public function admin_init();
    /**
     * Register admin page.
     */
    abstract public function register_admin_page();
    /**
     * Display admin page.
     */
    abstract public function display_page();
}
