<?php

/**
 * The admin-specific functionality of the plugin.
 *
 * @link       https://tillpaid.com/
 * @since      4.0.1
 *
 * @package    cash_to_cash_payments_for_woocommerce
 * @subpackage cash_to_cash_payments_for_woocommerce/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    cash_to_cash_payments_for_woocommerce
 * @subpackage cash_to_cash_payments_for_woocommerce/admin
 * @author     Tillpaid <contact@tillpaid.com>
 */
class cash_to_cash_payments_for_woocommerce_admin {


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

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

	/**
	 * Initialize the class and set its properties.
	 *
	 * @since    4.0.1
	 * @param string $plugin_name The name of this plugin.
	 * @param string $version The version of this plugin.
	 */
	public function __construct( $plugin_name, $version ) {

		$this->plugin_name = $plugin_name;
		$this->version     = $version;
	}

	/**
	 * Register the stylesheets for the admin area.
	 *
	 * @since    4.0.1
	 */
	public function enqueue_styles() {

		/**
		 * This function is provided for demonstration purposes only.
		 *
		 * An instance of this class should be passed to the run() function
		 * defined in cash_to_cash_payments_for_woocommerce_loader as all of the hooks are defined
		 * in that particular class.
		 *
		 * The cash_to_cash_payments_for_woocommerce_loader will then create the relationship
		 * between the defined hooks and the functions defined in this
		 * class.
		 */
		wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/cash-to-cash-payments-for-woocommerce-admin.css', array(), $this->version, 'all' );
	}

	/**
	 * Register the JavaScript for the admin area.
	 *
	 * @since    4.0.1
	 */
	public function enqueue_scripts() {

		/**
		 * This function is provided for demonstration purposes only.
		 *
		 * An instance of this class should be passed to the run() function
		 * defined in cash_to_cash_payments_for_woocommerce_loader as all of the hooks are defined
		 * in that particular class.
		 *
		 * The cash_to_cash_payments_for_woocommerce_loader will then create the relationship
		 * between the defined hooks and the functions defined in this
		 * class.
		 */
		wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/cash-to-cash-payments-for-woocommerce-admin.js', array( 'jquery' ), $this->version, false );
	}

	/**
	 * Function for check if woocommerce is activated
	 */
	public function check_if_woocommerce_is_active() {

    if ( ! class_exists( 'WooCommerce' ) ) {
        ?>
        <div class="notice notice-error">
            <p>
                <?php
                esc_html_e(
                    'Cash to Cash requiert l’activation de WooCommerce.',
                    'cash-to-cash-payments-for-woocommerce'
                );
                ?>
            </p>
        </div>
        <?php
    }
}

	/**
	 * Add settings link
	 */
	public function link_to_settings( $links, $file ) {
		if ( 'cash-to-cash-payments-for-woocommerce/cash-to-cash-payments-for-woocommerce.php' === $file && current_user_can( 'manage_options' ) ) {
			$settings = array( 'settings' => '<a href="admin.php?page=wc-settings&tab=checkout&section=cash-to-cash-payments-for-woocommerce">' . __( 'Réglages', 'cash-to-cash-payments-for-woocommerce' ) . '</a>' );
			$links    = array_merge( $settings, $links );
		}
		return $links;
	}


}

