<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

require_once "generate-less-to-css.php";
if ( is_multisite() ) {
	if ( ! file_exists( trailingslashit( WP_CONTENT_DIR ) . 'uploads/sites/' . get_current_blog_id() . '/tc_stylesheets' ) ) {
		wp_mkdir_p( trailingslashit( WP_CONTENT_DIR ) . 'uploads/sites/' . get_current_blog_id() . '/tc_stylesheets', 0777, true );
	};
	define( 'CAKEART_UPLOADS_FOLDER', trailingslashit( WP_CONTENT_DIR ) . 'uploads/sites/' . get_current_blog_id() . '/tc_stylesheets/' );
	define( 'CAKEART_UPLOADS_URL', trailingslashit( WP_CONTENT_URL ) . 'uploads/sites/' . get_current_blog_id() . '/tc_stylesheets/' );
} else {
	if ( ! file_exists( trailingslashit( WP_CONTENT_DIR ) . 'uploads/tc_stylesheets' ) ) {
		wp_mkdir_p( trailingslashit( WP_CONTENT_DIR ) . 'uploads/tc_stylesheets', 0777, true );
	}
	if ( ! defined( 'CAKEART_UPLOADS_FOLDER' ) ) {
		define( 'CAKEART_UPLOADS_FOLDER', trailingslashit( WP_CONTENT_DIR ) . 'uploads/tc_stylesheets/' );
	}

	if ( ! defined( 'CAKEART_UPLOADS_URL' ) ) {
		define( 'CAKEART_UPLOADS_URL', trailingslashit( WP_CONTENT_URL ) . 'uploads/tc_stylesheets/' );
	}
}

if ( ! defined( 'CAKEART_FILE_NAME' ) ) {
	define( 'CAKEART_FILE_NAME', 'cakeart-options.css' );
}

class Customize_Options {

	function __construct() {
		add_action( 'tf_create_options', array( $this, 'create_customizer_options' ) );
		add_action( 'customize_save_after', array( $this, 'generate_to_css' ) );

		/* Unregister Default Customizer Section */
		add_action( 'customize_register', array( $this, 'unregister' ) );
	}

	function unregister( $wp_customize ) {

		$wp_customize->remove_section( 'colors' );
		$wp_customize->remove_section( 'background_image' );

	}

	function create_customizer_options() {
		$titan = TitanFramework::getInstance( 'thim' );

		include_once( ABSPATH . 'wp-admin/includes/plugin.php' );

		/* Register Customizer Sections */
		// include heading
		include THIM_DIR . "/inc/admin/customizer-sections/logo.php";
		include THIM_DIR . "/inc/admin/customizer-sections/header.php";
		include THIM_DIR . "/inc/admin/customizer-sections/header-mainmenu.php";
		include THIM_DIR . "/inc/admin/customizer-sections/header-mobile.php";
		include THIM_DIR . "/inc/admin/customizer-sections/header-submenu.php";
		include THIM_DIR . "/inc/admin/customizer-sections/header-stickymenu.php";
		include THIM_DIR . "/inc/admin/customizer-sections/header-toolbar.php";
		include THIM_DIR . "/inc/admin/customizer-sections/header-layout.php";

		// include styling
		include THIM_DIR . "/inc/admin/customizer-sections/styling.php";
		include THIM_DIR . "/inc/admin/customizer-sections/styling-color.php";
		include THIM_DIR . "/inc/admin/customizer-sections/styling-pattern.php";


		// include typography
		include THIM_DIR . "/inc/admin/customizer-sections/typography.php";

		// include footer
		include THIM_DIR . "/inc/admin/customizer-sections/footer.php";
		include THIM_DIR . "/inc/admin/customizer-sections/footer-copyright.php";
		include THIM_DIR . "/inc/admin/customizer-sections/footer-options.php";

		// include Support
//		include THIM_DIR . "/inc/admin/customizer-sections/support.php";

		// include Custom CSS
		//include THIM_DIR . "/inc/admin/customizer-sections/custom-css.php";

		// include display setting
		include THIM_DIR . "/inc/admin/customizer-sections/display.php";
		include THIM_DIR . "/inc/admin/customizer-sections/display-frontpage.php";
		include THIM_DIR . "/inc/admin/customizer-sections/display-archive.php";
		include THIM_DIR . "/inc/admin/customizer-sections/display-postpage.php";
		include THIM_DIR . "/inc/admin/customizer-sections/display-404.php";

		if ( is_plugin_active( 'thim-recipe/recipe.php' ) ) {
			// include Recipe setting
			include THIM_DIR . "/inc/admin/customizer-sections/recipe.php";
			include THIM_DIR . "/inc/admin/customizer-sections/recipe-archive.php";
			include THIM_DIR . "/inc/admin/customizer-sections/recipe-single.php";
		}

		if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
			// include WooCommerce setting
			include THIM_DIR . "/inc/admin/customizer-sections/woocommerce.php";
			include THIM_DIR . "/inc/admin/customizer-sections/woocommerce-archive.php";
			include THIM_DIR . "/inc/admin/customizer-sections/woocommerce-single.php";
			include THIM_DIR . "/inc/admin/customizer-sections/woocommerce-setting.php";
			include THIM_DIR . "/inc/admin/customizer-sections/woocommerce-sharing.php";
		}

		// include post sharing
		include THIM_DIR . "/inc/admin/customizer-sections/social-sharing.php";

		// include import export feature
//		include THIM_DIR . "/inc/admin/customizer-sections/import-export.php";

		//Add meta boxes for event shortcode

		$event = $titan->createMetaBox( array(
			'name'      => esc_html__( 'Event Options', 'cakeart' ),
			'id'        => 'event-options',
			'post_type' => array( 'post' ),
		) );

		$event->createOption( array(
			'name' => esc_html__( 'Use Event Post', 'cakeart' ),
			'id'   => 'use_event',
			'type' => 'checkbox',
			'desc' => ' ',
		) );

		$event->createOption( array(
			'name'    => esc_html__( 'Opening Time', 'cakeart' ),
			'id'      => 'time_opening',
			'type'    => 'text',
			'desc'    => esc_html__( 'Fill the opening time', 'cakeart' ),
			'default' => ''

		) );

		$event->createOption( array(
			'name'    => esc_html__( 'Closing Time', 'cakeart' ),
			'id'      => 'time_closing',
			'type'    => 'text',
			'desc'    => esc_html__( 'Fill the closing time', 'cakeart' ),
			'default' => '',
		) );
	}

	function generate_to_css() {
 		generate( CAKEART_UPLOADS_FOLDER . CAKEART_FILE_NAME );
	}

}

new customize_options();