<?php

defined('DOLPHY_PLUGIN') or die('Access Denied!');

add_action('wp_enqueue_scripts', function () {
  do_action('dolphy_enqueue_core_scripts');

  wp_enqueue_style('dolphy-front', DOLPHY_ASSETS.'/css/front.min.css', array(), DOLPHY_SCRIPT_VERSION);
  wp_enqueue_script('dolphy-front', DOLPHY_ASSETS.'/js/front.min.js', array(), DOLPHY_SCRIPT_VERSION, true);

  do_action('dolphy_enqueue_scripts');
});


/**
 * Enqueue admin scripts and styles
 */
add_action('admin_enqueue_scripts', function ($hook) {
  do_action('dolphy_enqueue_core_scripts');

  if (strpos($hook, 'dolphy') === false) return;

  wp_enqueue_media();

  wp_enqueue_script('jquery-ui-dialog');
  wp_enqueue_style('wp-jquery-ui-dialog');

  $deps = array('quill');
  wp_enqueue_style('dolphy-admin', DOLPHY_ASSETS.'/css/admin.min.css', $deps, DOLPHY_SCRIPT_VERSION);

  $deps[] = 'dolphy-color-picker';
  wp_enqueue_script('dolphy-admin', DOLPHY_ASSETS.'/js/admin.min.js', $deps, DOLPHY_SCRIPT_VERSION, true);

  do_action('dolphy_admin_enqueue_scripts');
});


/**
 * Enqueue Access scripts and styles
 */
add_action('dolphy_access_enqueue_scripts', function () {
  do_action('dolphy_enqueue_core_scripts');

  wp_enqueue_style('dolphy-access', DOLPHY_ASSETS.'/css/access.min.css', array(), DOLPHY_SCRIPT_VERSION);
  wp_enqueue_script('dolphy-access', DOLPHY_ASSETS.'/js/access.min.js', array(), DOLPHY_SCRIPT_VERSION, true);
});


/**
 * Enqueue Account scripts and styles
 */
add_action('dolphy_account_enqueue_scripts', function () {
  do_action('dolphy_enqueue_core_scripts');

  wp_enqueue_style('dolphy-account', DOLPHY_ASSETS.'/css/account.min.css', array(), DOLPHY_SCRIPT_VERSION);

  $deps = array('vue-router');
  wp_enqueue_script('dolphy-account', DOLPHY_ASSETS.'/js/account.min.js', $deps, DOLPHY_SCRIPT_VERSION, true);
});


/**
 * Enqueue Maintenance scripts and styles
 */
add_action('dolphy_maintenance_enqueue_scripts', function () {
  do_action('dolphy_enqueue_core_scripts');

  wp_enqueue_style('dolphy-maintenance', DOLPHY_ASSETS.'/css/maintenance.min.css', array(), DOLPHY_SCRIPT_VERSION);
  wp_enqueue_script('dolphy-maintenance', DOLPHY_ASSETS.'/js/maintenance.min.js', array(), DOLPHY_SCRIPT_VERSION, true);
});


/**
 * Enqueue Error scripts and styles
 */
add_action('dolphy_error_enqueue_scripts', function () {
  do_action('dolphy_enqueue_core_scripts');

  wp_enqueue_style('dolphy-error', DOLPHY_ASSETS.'/css/error.min.css', array(), DOLPHY_SCRIPT_VERSION);
  wp_enqueue_script('dolphy-error', DOLPHY_ASSETS.'/js/error.min.js', array(), DOLPHY_SCRIPT_VERSION, true);
});

/**
 * Enqueue Core scripts and styles
 */
add_action('dolphy_enqueue_core_scripts', function () {
  $libs = DOLPHY_ASSETS.'/libs';

  // BEGIN: Register Styles
  wp_register_style('quill', "{$libs}/quill/quill.snow.css", array(), true);
  wp_register_style('fontawesome', "{$libs}/fontawesome/css/all.min.css", array(), true);
  // END: Register Styles

  // BEGIN: Register Scripts
  wp_register_script('quill', "{$libs}/quill/quill.min.js", array(), false, true);
  wp_register_script('dolphy-color-picker', "{$libs}/jscolor/jscolor.min.js", array(), '2.4.5', true);
  wp_register_script('es6-promise', "{$libs}/es6-promise.auto.min.js", array(), false, true);
  wp_register_script('vue', "{$libs}/vue/vue.min.js", array(), '3.0.5', true);
  wp_register_script('vue-router', "{$libs}/vue/vue-router.min.js", array('vue'), '3.5.1', true);
  wp_register_script('vuex', "{$libs}/vue/vuex.min.js", array('es6-promise'), '3.6.2', true);
  wp_register_script('vuelidate', "{$libs}/vue/vuelidate.min.js", array('vue'), '0.7.6', true);
  wp_register_script('validators', "{$libs}/vue/validators.min.js", array('vue'), '0.7.6', true);
  // END: Register Scripts

  $deps = array('fontawesome');
  wp_enqueue_style('dolphy-core', DOLPHY_ASSETS.'/css/core.min.css', $deps, DOLPHY_SCRIPT_VERSION);

  wp_enqueue_script('jquery');
  wp_enqueue_script('sweetalert', "{$libs}/sweetalert/sweetalert.js", array(), false, true);
  wp_enqueue_script('axios', "{$libs}/axios/axios.min.js", array(), '0.19.2', true);

  $deps = array('moment', 'vue', 'vuex'/*, 'vuelidate', 'validators'*/);
  wp_enqueue_script('dolphy-core', DOLPHY_ASSETS.'/js/core.min.js', $deps, DOLPHY_SCRIPT_VERSION, true);

  wp_localize_script('dolphy-core', 'Dolphy', array(
    'ajax' => DOLPHY_AJAX_URL
  ));
});
