<?php

/**
 * The admin-specific functionality of the plugin.
 *
 * @link       http://example.com
 * @since      1.0.0
 *
 * @package    agile_tix
 * @subpackage agile_tix/admin
 */

/**
 * The admin-specific functionality of the plugin.
 *
 * Defines the plugin name, version, and two examples hooks for how to
 * enqueue the admin-specific stylesheet and JavaScript.
 *
 * @package    agile_tix
 * @subpackage agile_tix/admin
 * @author     AgileTix
 */
class agile_tix_Admin
{

    /**
     * The ID of this plugin.
     *
     * @since    1.0.0
     * @access   private
     * @var      string    $agile_tix    The ID of this plugin.
     */
    private $agile_tix;

    /**
     * The version of this plugin.
     *
     * @since    1.0.0
     * @access   private
     * @var      string    $version    The current version of this plugin.
     */
    private $version;

    /**
     * Initialize the class and set its properties.
     *
     * @since    1.0.0
     * @param      string    $agile_tix       The name of this plugin.
     * @param      string    $version    The version of this plugin.
     */
    public function __construct($agile_tix, $version)
    {
        $this->agile_tix = $agile_tix;
        $this->version = $version;
    }

    /**
     * Register the stylesheets for the admin area.
     *
     * @since    1.0.0
     */
    public function enqueue_styles()
    {
        wp_enqueue_style($this->agile_tix, plugin_dir_url(__FILE__) . 'css/agile-ticketing-admin.css', array(), $this->version, 'all');
        $custom_css_file_path = plugin_dir_path(__FILE__) . '../public/css/agile-ticketing-user-defined-admin.css';
        if (file_exists($custom_css_file_path)) {
            wp_enqueue_style($this->agile_tix, $custom_css_file_path, array(), $this->version, 'all');
        }
    }

    /**
     * Register the JavaScript for the admin area.
     *
     * @since    1.0.0
     */
    public function enqueue_scripts()
    {
        wp_enqueue_script($this->agile_tix, plugin_dir_url(__FILE__) . 'js/agile-ticketing-admin.js', array('jquery') );
        wp_localize_script($this->agile_tix, 'agileAjax', array(
            'ajaxurl' => admin_url('admin-ajax.php'),
            'utility_metrics_nonce' => wp_create_nonce('agile_utility_metrics_nonce')
        ));
        wp_enqueue_script('jquery-ui-sortable');
    }


    static function agile_cache_api_transient($api_response){
        /* Predefined experation intervals are:
         *   MINUTE_IN_SECONDS
         *   HOUR_IN_SECONDS
         *   DAY_IN_SECONDS
         *   WEEK_IN_SECONDS
         *   MONTH_IN_SECONDS
         *   YEAR_IN_SECONDS
         * 
         * Otherwise use an exact number of seconds
         * */
        
        //clear the old transient 
        delete_transient('agile_api_response');

        set_transient('agile_api_response', $api_response, HOUR_IN_SECONDS); 
    }

    static function agile_custom_cron_interval($schedules)
    {
        $schedules['every_fifteen_minutes'] = array(
            'interval' => 15 * 60, // 15 minutes in seconds
            'display' => __('Every 15 Minutes'),
        );
        return $schedules;
    }
}
