<?php
/**
 * Page callback class for building the VicTheme Core
 * configuration page
 *
 * @author jason.xie@victheme.com
 *
 */
class VTCore_Wordpress_Pages_Config
extends VTCore_Wordpress_Models_Page {



  protected function register() {
    $this->headerText = __('VicTheme Core - Configuration', VTCORE_LANGUAGE);
    $this->headerIcon = 'dashboard';
    $this->saveKey = 'vtcore-save';
    $this->resetKey = 'vtcore-reset';
    $this->actionHeaderKey = 'vtcore-configuration-header-alter';
    $this->actionFormKey = 'vtcore-configuration-form-alter';
  }

  protected function loadAssets() {
    wp_deregister_script('heartbeat');
    VTCore_Wordpress_Utility::loadAsset('wp-bootstrap');
    VTCore_Wordpress_Utility::loadAsset('wp-page');
    VTCore_Wordpress_Utility::loadAsset('bootstrap-confirmation');
  }

  public function renderAjax($post) {
    return false;
  }

  protected function save() {
    $this->messages->setNotice(__('All Core related cached deleted', VTCORE_LANGUAGE));

    // Just promise to delete on next page load
    update_option('vtcore_clear_cache', true);
  }

  protected function reset() {
    return $this;
  }


  protected function buildForm() {

    $this->form = new VTCore_Bootstrap_Form_BsInstance(array(
      'attributes' => array(
        'id' => 'vtcore-configuration-form',
        'method' => 'post',
        'action' => $_SERVER['REQUEST_URI'],
        'class' => array('container-fluid', 'vtcore-configuration-form-skins'),
        'autocomplete' => 'off',
      ),
    ));

    $this->form
      ->addChildren(new VTCore_Bootstrap_Element_BsPanel(array(
        'text' => __('Performance', VTCORE_LANGUAGE),
      )))
      ->lastChild()
      ->addContent(new VTCore_Bootstrap_Form_BsDescription(array(
        'text' => __('Caching core will be performed automatically, you can force to clear the cache by clicking the clear cache button', VTCORE_LANGUAGE),
      )))
      ->addContent(new VTCore_Bootstrap_Form_BsSubmit(array(
        'attributes' => array(
          'name' => $this->saveKey,
          'value' => __('Clear Cache', VTCORE_LANGUAGE),
        ),
        'mode' => 'danger',
        'confirmation' => true,
        'title' => __('Are you sure?', VTCORE_LANGUAGE),
        'ok' => __('Yes', VTCORE_LANGUAGE),
        'cancel' => __('No', VTCORE_LANGUAGE),
      )));

  }

}