<?php
namespace Dreamfox\DeliveryDate\Premium\Admin;

use Dreamfox\DeliveryDate\Abstracts\AbstractAjax;
use Dreamfox\DeliveryDate\Premium\Facades\SystemFacade;

class AdminAjax extends AbstractAjax
{

  public function getAjaxEvents()
  {
    return [
      'load_categories',
      'save_common_settings',
      'load_common_settings',
      'save_category_settings',
      'load_category_settings',
      'save_other_settings',
      'load_other_settings',
      'save_holiday_settings',
      'load_holiday_settings',
      'send_support',
      'activate_license',
    ];
  }

  public function load_categories()
  {
    $categories = SystemFacade::getInstance()->loadCategories();
    $response = array(
			'message' => 'Updated successfully!',
      'categories' => $categories,
		);
		wp_send_json( $response );
  }

  #begin_region common settings
    public function save_common_settings()
    {
      $data = $this->_getRequestData();
      SystemFacade::getInstance()->saveCommonSettings($data);
      $response = array(
        'message' => 'Updated successfully!',
      );
      wp_send_json( $response );
    }

    public function load_common_settings()
    {
      $settings = SystemFacade::getInstance()->loadCommonSettings();
      $response = $settings->toArray();
      wp_send_json( $response );
    }
  #end_region

  #begin_region category settings
    public function save_category_settings()
    {
      $data = $this->_getRequestData();
      SystemFacade::getInstance()->saveCategorySettings($data);
      $response = array(
        'message' => 'Updated successfully!',
      );
      wp_send_json( $response );
    }

    public function load_category_settings()
    {
      $settings = SystemFacade::getInstance()->loadCategorySettings();
      $response = $settings->toArray();
      wp_send_json( $response );
    }
  #end_region

  #begin_region common settings
    public function save_holiday_settings()
    {
      $data = $this->_getRequestData();
      SystemFacade::getInstance()->saveHolidaySettings($data);
      $response = array(
        'message' => 'Updated successfully!',
      );
      wp_send_json( $response );
    }

    public function load_holiday_settings()
    {
      $settings = SystemFacade::getInstance()->loadHolidaySettings();
      $response = $settings->toArray();
      wp_send_json( $response );
    }
  #end_region

  #begin_region common settings
    public function save_other_settings()
    {
      $data = $this->_getRequestData();
      SystemFacade::getInstance()->saveOtherSettings($data);
      $response = array(
        'message' => 'Updated successfully!',
      );
      wp_send_json( $response );
    }

    public function load_other_settings()
    {
      $settings = SystemFacade::getInstance()->loadOtherSettings();
      $response = $settings->toArray();
      wp_send_json( $response );
    }
  #end_region

  public function send_support()
  {
    $data = $this->_getRequestData();
    SystemFacade::getInstance()->sendSupport($data);
    $response = array(
      'message' => 'Updated successfully!',
    );
    wp_send_json( $response );
  }

  public function activate_license()
  {
    $data = $this->_getRequestData();
    SystemFacade::getInstance()->activateLicense($data);
    $response = array(
      'message' => 'Updated successfully!',
    );
    wp_send_json( $response );
  }


}