<?php

namespace Discountify;

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

use Discountify;

class Bootstrap {

	private static $instance;

	/**
	 * __construct function
	 *
	 * @since 1.0.0
	 */
	public function __construct() {
		// Load autoload method.
		Autoloader::run();
		// Register custom post type
		add_action( 'init', array( $this, 'register_post_types' ) );
		// pro & others menu
		add_filter( 'plugin_action_links_' . \Discountify::plugins_basename(), array( $this, 'add_action_links' ) );
		// Core files
		\Discountify\Core\Core::instance()->init();
		// Import/Export
		\Discountify\Core\Admin\ImportExport::instance()->init();
		// Enqueue Assets
		\Discountify\Base\Enqueue::instance()->init();
		// Deactivation Feedback
		\Discountify\Core\Admin\DeactivationFeedback::instance()->init();
	}

	/**
	 * Register custom post types
	 */
	public function register_post_types() {
		if ( post_type_exists( 'discountify_rules' ) ) {
			return;
		}

		register_post_type(
			'discountify_rules',
			array(
				'labels'       => array(
					'name'          => __( 'Discount Rules', 'discountify' ),
					'singular_name' => __( 'Discount Rule', 'discountify' ),
				),
				'public'       => false,
				'show_ui'      => false,
				'show_in_menu' => false,
				'supports'     => array( 'title' ),
				'rewrite'      => false,
				'query_var'    => false,
			)
		);
	}

	/**
	 * Add required links
	 *
	 * @param [type] $actions
	 * @return void
	 */
	public function add_action_links( $actions ) {
		$actions[] = '<a href="' . esc_url( get_admin_url( null, 'admin.php?page=discountify' ) ) . '">' .
		esc_html__( 'Settings', 'discountify' ) . '</a>';
		if ( ! class_exists( 'DiscountifyPro' ) ) {
			$actions[] = '<a href="https://wpbens.com/" target="_blank">' . esc_html__( 'Go To Premium', 'discountify' ) . '</a>';
		}

		return $actions;
	}

	/**
	 * Singleton Instance
	 *
	 * @return Bootstrap
	 */
	public static function instance() {

		if ( ! self::$instance ) {
			self::$instance = new self();
		}

		return self::$instance;
	}
}
