<?php
namespace WpBookingEventAdmin\app\helpers;

use WpBookingEvent\Factory;
use WpBookingEvent\Mvc\Model\Model as ModelAlias;
use WpBookingEvent\Mvc\Table\Table;
use WpBookingEvent\Registry\Registry;
use WpBookingEvent\Utilities\Utility;

class ConfigHelper extends AdminHelper
{
    public static function set_page_tour($page_id,$type){
        $modelConfig = ModelAlias::getInstance('config');
        $table = $modelConfig->getTable();
        $table->load(1);
        $params = $table->params;
        $reg = new Registry();
        $reg->loadString($params);
        $reg->set($type,$page_id);
        $table->params = $reg->toString();
        $table->store();
    }
    public static function get_page_list_service(){
        $modelConfig = ModelAlias::getInstance('config');
        $item = $modelConfig->getItem(1);
        return $item->params->get('page_list_service',0);

    }
    public static function get_page_list_category(){
        $modelConfig = ModelAlias::getInstance('config');
        $item = $modelConfig->getItem(1);
        return $item->params->get('page_list_category',0);

    }
    public static function get_page_service_detail(){
        $modelConfig = ModelAlias::getInstance('config');
        $item = $modelConfig->getItem(1);
        return $item->params->get('page_service_detail',0);

    }
    public static function get_go_to_page_event_detail(){
        $modelConfig = ModelAlias::getInstance('config');
        $item = $modelConfig->getItem(1);
        return $item->params->get('onclick_event_detail','');

    }
    public static function get_style_block_top_event(){
        $modelConfig = ModelAlias::getInstance('config');
        $item = $modelConfig->getItem(1);
        return $item->params->get('select_style_top_event','');
    }
    public static function get_select_form_booking_style(){
        $modelConfig = ModelAlias::getInstance('config');
        $item = $modelConfig->getItem(1);
        return $item->params->get('select_form_booking_style','');
    }

    public static function create_create_page($view,$type)
    {
        $a_view=str_replace("-"," ",$view);
        $key_page=$a_view;
        $tour_detail = array(
            'post_name' => "$key_page",
            'post_title' => $key_page,
            'post_content' => '[wpbookingevent view="'.$view.'"]',
            'post_status' => "publish",
            'post_author' => get_current_user_id(),
            'post_type' => "page",
        );
        $post_id=wp_insert_post($tour_detail, '');
        self::set_page_tour($post_id,$type);
    }

}