<?php
/**
 * Fashion Outfits Trend functions and definitions
 *
 * @package Fashion Outfits Trend
 */

if ( ! function_exists( 'fashion_outfits_trend_setup' ) ) :
	function fashion_outfits_trend_setup() {
		
		// Add default posts and comments RSS feed links to head.
		add_theme_support( 'automatic-feed-links' );

		add_theme_support( 'woocommerce' );

		load_theme_textdomain( 'fashion-outfits-trend', get_template_directory() . '/languages' );

		/*
		 * Let WordPress manage the document title.
		 * By adding theme support, we declare that this theme does not use a
		 * hard-coded <title> tag in the document head, and expect WordPress to
		 * provide it for us.
		 */
		add_theme_support( 'title-tag' );

		/*
		 * Post thumbnail support should be enabled for pages and posts.
		 */
		add_theme_support( 'post-thumbnails' );

		// This theme uses wp_nav_menu() in one location.
		register_nav_menus( array(
			'menu-1' => esc_html__( 'Primary', 'fashion-outfits-trend' ),
			'menu-2' => esc_html__( 'Footer', 'fashion-outfits-trend' ),
		) );

		/*
		 * To produce valid HTML5, change the default core markup for the comments, search form, and search form.
		 */
		add_theme_support( 'html5', array(
			'search-form',
			'comment-form',
			'comment-list',
			'gallery',
			'caption',
		) );
		
		/**
		 * Add support for core custom logo.
		 *
		 * @link https://codex.wordpress.org/Theme_Logo
		 */
		add_theme_support( 'custom-logo', array(
			'width'       => 270,
			'height'      => 80,
			'flex-height' => true,
			'flex-width'  => true,
		) );

		// Add theme support for selective refresh for widgets.
		add_theme_support( 'customize-selective-refresh-widgets' );

		// Add custom image size.
		add_image_size( 'fashion-outfits-trend-1920-550', 1920, 550, true );
		add_image_size( 'fashion-outfits-trend-1370-550', 1370, 550, true );
		add_image_size( 'fashion-outfits-trend-590-310', 590, 310, true );
		add_image_size( 'fashion-outfits-trend-420-380', 420, 380, true );
		add_image_size( 'fashion-outfits-trend-420-300', 420, 300, true );
		add_image_size( 'fashion-outfits-trend-420-200', 420, 200, true );
		add_image_size( 'fashion-outfits-trend-290-150', 290, 150, true );
		add_image_size( 'fashion-outfits-trend-80-60', 80, 60, true );
		
		add_theme_support( 'align-wide' );
		add_theme_support( 'wp-block-styles' );

        add_theme_support( 'custom-background', apply_filters( 'fashion_outfits_trend_custom_background', array(
            'default-color' => 'ffffff',
            'default-image' => '',
        )));
        
        add_theme_support( 'responsive-embeds' );

		add_theme_support('custom-header', array(
			'default-image'      => '',
			'width'              => 1920,
			'height'             => 200,
			'flex-height'        => true,
			'flex-width'         => true,
			'uploads'            => true,
		));

		/*
		* Enable support for Post Formats.
		*
		* See: https://codex.wordpress.org/Post_Formats
		*/
		add_theme_support( 'post-formats', array('image','video','gallery','audio',) );

		define('FASHION_OUTFITS_TREND_BUY_NOW',__('https://www.themepixels.net/products/fashion-wordpress-theme/','fashion-outfits-trend'));
		define('FASHION_OUTFITS_TREND_LIVE_DEMO',__('https://themepixels.net/demo-site/fashion-outfits-trend/','fashion-outfits-trend'));
		define('FASHION_OUTFITS_TREND_FREE_DOC',__('https://www.themepixels.net/docs/fashion-outfits-trend-free/','fashion-outfits-trend'));
		define('FASHION_OUTFITS_TREND_BUNDLE',__('https://www.themepixels.net/products/wp-theme-bundle/','fashion-outfits-trend'));
		define('FASHION_OUTFITS_TREND_THEME_SUPPORT',__('https://wordpress.org/support/theme/fashion-outfits-trend','fashion-outfits-trend'));

		/**
		* FREE DEMO CONTENT.
		*/
		require get_template_directory() . '/inc/free-demo-content/fashion_outfits_trend_config_file.php';

	}
endif;
add_action( 'after_setup_theme', 'fashion_outfits_trend_setup' );

/**
 * Enqueue scripts and styles.
 */
function fashion_outfits_trend_scripts() {

	wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/assets/bootstrap/css/bootstrap.min.css' );
	if ( is_rtl() ){
		wp_enqueue_style( 'bootstrap-rtl', get_template_directory_uri() . '/assets/bootstrap/css/rtl/bootstrap.min.css' );

		wp_enqueue_style( 'fashion-outfits-trend-rtl-style', get_template_directory_uri() . '/rtl.css' );
	}

	// Theme stylesheet.
	wp_enqueue_style( 'fashion-outfits-trend-style', get_stylesheet_uri() );
	require get_parent_theme_file_path( '/extra-pixel-customize.php' );
	wp_add_inline_style( 'fashion-outfits-trend-style',$fashion_outfits_trend_pix_theme_css );

	wp_enqueue_style( 'fashion-outfits-trend-style', get_stylesheet_uri() );
	
	wp_enqueue_style( 'fontawesome', get_template_directory_uri() . '/assets/font-awesome/css/all.min.css' );
	
	wp_enqueue_style( 'owl.carousel.css', get_template_directory_uri() . '/assets/css/owl.carousel.css' );
	wp_enqueue_style( 'inter-google-font', 'https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap', false );

	$scripts = array(
		array(
			'id'     => 'bootstrap',
			'url'    => get_template_directory_uri() . '/assets/bootstrap/js/bootstrap.min.js',
			'footer' => true
		),
	);
	fashion_outfits_trend_add_scripts( $scripts );

	wp_enqueue_script( 'owl.carousel.js' , get_template_directory_uri() . '/assets/js/owl.carousel.js' , array( 'jquery' ), 0.9, true );

    $fashion_outfits_trend_countdown_date = get_theme_mod('fashion_outfits_trend_countdown_target_date','December 31, 2025 23:59:59');

    wp_enqueue_script( 'fashion-outfits-trend-custom' , get_template_directory_uri() . '/assets/js/custom.js' , array( 'jquery', 'jquery-masonry', 'owl.carousel.js' ), 0.8, true );

    wp_localize_script('fashion-outfits-trend-custom', 'countdownData', array(
        'targetDate' => $fashion_outfits_trend_countdown_date
    ));

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
}
add_action( 'wp_enqueue_scripts', 'fashion_outfits_trend_scripts' );

// Change number or products per row to 6
	add_filter('loop_shop_columns', 'fashion_outfits_trend_loop_columns');
	if (!function_exists('fashion_outfits_trend_loop_columns')) {
		function fashion_outfits_trend_loop_columns() {
			$fashion_outfits_trend_columns = get_theme_mod( 'fashion_outfits_trend_per_columns', 3 );
			return $fashion_outfits_trend_columns;
		}
	}

	//Change number of products that are displayed per page (shop page)
	add_filter( 'loop_shop_per_page', 'fashion_outfits_trend_per_page', 10 );
	function fashion_outfits_trend_per_page( $fashion_outfits_trend_cols ) {
	  	$fashion_outfits_trend_cols = get_theme_mod( 'fashion_outfits_trend_product_per_page', 10 );
		return $fashion_outfits_trend_cols;
	}

	function fashion_outfits_trend_sanitize_number_absint( $number, $setting ) {
		// Ensure $number is an absolute integer (whole number, zero or greater).
		$number = absint( $number );

		// If the input is an absolute integer, return it; otherwise, return the default
		return ( $number ? $number : $setting->default );
	}


function fashion_outfits_trend_sanitize_number_range( $number, $setting ) {

	// Ensure input is an absolute integer.
	$number = absint( $number );

	// Get the input attributes associated with the setting.
	$atts = $setting->manager->get_control( $setting->id )->input_attrs;

	// Get minimum number in the range.
	$min = ( isset( $atts['min'] ) ? $atts['min'] : $number );

	// Get maximum number in the range.
	$max = ( isset( $atts['max'] ) ? $atts['max'] : $number );

	// Get step.
	$step = ( isset( $atts['step'] ) ? $atts['step'] : 1 );

	// If the number is within the valid range, return it; otherwise, return the default
	return ( $min <= $number && $number <= $max && is_int( $number / $step ) ? $number : $setting->default );
}

function fashion_outfits_trend_sanitize_checkbox( $input ) {
    // Boolean check
    return ( ( isset( $input ) && true == $input ) ? true : false );
}

/*radio button sanitization*/
function fashion_outfits_trend_sanitize_choices( $input, $setting ) {
    global $wp_customize;
    $control = $wp_customize->get_control( $setting->id );
    if ( array_key_exists( $input, $control->choices ) ) {
        return $input;
    } else {
        return $setting->default;
    }
}

/**
* Add script
* 
* @since Fashion Outfits Trend 1.0.0
*/
function fashion_outfits_trend_add_scripts( $scripts ){
	foreach ( $scripts as $key => $value ) {
		wp_enqueue_script( $value['id'] , $value['url'] , array( 'jquery', 'jquery-masonry' ), 0.8, $value['footer'] );
	}
}

/**
 * Sanitizes Image Upload.
 *
 * @param string $input potentially dangerous data.
 */
function fashion_outfits_trend_sanitize_image( $input ) {
	$filetype = wp_check_filetype( $input );
	if ( $filetype['ext'] && wp_ext2type( $filetype['ext'] ) === 'image' ) {
		return esc_url( $input );
	}
	return '';
}



// Add custom container before main content
add_action('woocommerce_before_main_content', 'fashion_outfits_trend_add_custom_container_start', 5);
function fashion_outfits_trend_add_custom_container_start() {
    echo '<div class="container custom-woo-css my-5">';
}

// Close custom container after main content
add_action('woocommerce_after_main_content', 'fashion_outfits_trend_add_custom_container_end', 15);
function fashion_outfits_trend_add_custom_container_end() {
    echo '</div>';
}

/**
 * Custom template tags for this theme.
 */
require get_template_directory() . '/inc/template-tags.php';

/**
 * Functions which enhance the theme by hooking into WordPress.
 */
require get_template_directory() . '/inc/template-functions.php';

/**
 * Customizer additions.
 */
require get_template_directory() . '/inc/customizer/customizer.php';

/**
 * Dynamic CSS.
 */
require get_template_directory() . '/inc/customizer/loader.php';

/**
* GET START.
*/
require get_template_directory() . '/themeinfo/fashion_outfits_trend_themeinfo_page.php';

/**
 * Typography Fonts
 */
require get_template_directory() . '/inc/typography-settings/typography-fonts.php';


// NOTICE FUNCTION
function fashion_outfits_trend_activation_notice() {
    if (get_option('fashion_outfits_trend_notice_dismissed')) {
        return;
    }

    if (isset($_GET['page']) && $_GET['page'] === 'fashion-outfits-trend-themeinfo-page') {
        return;
    }
    ?>
    <div class="updated notice notice-theme-info-class is-dismissible" data-notice="theme_info">
        <div class="fashion-outfits-trend-theme-info-notice clearfix">
            <div class="fashion-outfits-trend-theme-notice-content">
				<div class="notice-content">
					<div class="inner-notice-contetn">
						<h2 class="fashion-outfits-trend-notice-h2">
							<?php
							printf(
								/* translators: 1: Theme name */
								esc_html__('Hello! Thank you for choosing our %1$s!', 'fashion-outfits-trend'), '<strong>' . esc_html(wp_get_theme()->get('Name')) . '</strong>'
							);
							?>
						</h2>

						<p class="fashion-outfits-trend-notice-p">
							<?php
							printf(
								/* translators: 1: Theme name */
								esc_html__('%1$s has been successfully installed and is ready for use. The links below will help you get started.', 'fashion-outfits-trend'), '<strong>' . esc_html(wp_get_theme()->get('Name')) . '</strong>'
							);
							?>
						</p>
					</div>
					<div class="inner-notice-buttons">
						<a class="fashion-outfits-trend-btn-theme-info button button-primary" target="_blank" href="<?php echo esc_url(admin_url('themes.php?page=fashion-outfits-trend-themeinfo-page')); ?>" id="fashion-outfits-trend-themeinfo-button"> <?php esc_html_e('Fashion Outfits Trend Theme Information', 'fashion-outfits-trend') ?></a>
						
						<a class="fashion-outfits-trend-btn-theme-info button button-primary buy-noww" target="_blank" href="<?php echo esc_url(FASHION_OUTFITS_TREND_BUY_NOW); ?>" id="fashion-outfits-trend-bundle-button"> <?php esc_html_e('Buy Now', 'fashion-outfits-trend') ?></a>
						<a class="fashion-outfits-trend-btn-theme-info button button-primary bundlee" target="_blank" href="<?php echo esc_url(FASHION_OUTFITS_TREND_BUNDLE); ?>" id="fashion-outfits-trend-bundle-button"> <?php esc_html_e('Get All Themes', 'fashion-outfits-trend') ?></a>
						<a class="fashion-outfits-trend-btn-theme-info button button-primary live-demoo" target="_blank" href="<?php echo esc_url(FASHION_OUTFITS_TREND_LIVE_DEMO); ?>" id="fashion-outfits-trend-bundle-button"> <?php esc_html_e('Live Demo', 'fashion-outfits-trend') ?></a>
					</div>
				</div>
				<div class="notice-image">
					<img src="<?php echo esc_url( get_stylesheet_directory_uri() . '/assets/images/bundle-img.png' ); ?>" alt="<?php esc_attr_e( 'Theme Screenshot', 'fashion-outfits-trend' ); ?>">
				</div>
            </div>
        </div>
    </div>
    <?php
}

add_action('admin_notices', 'fashion_outfits_trend_activation_notice');

add_action('wp_ajax_fashion_outfits_trend_dismiss_notice', 'fashion_outfits_trend_dismiss_notice');

function fashion_outfits_trend_notice_status() {
    delete_option('fashion_outfits_trend_notice_dismissed');
}
add_action('after_switch_theme', 'fashion_outfits_trend_notice_status');

function fashion_outfits_trend_dismiss_notice() {
    update_option('fashion_outfits_trend_notice_dismissed', true);
    wp_send_json_success();
}

function fashion_outfits_trend_admin_enqueue_scripts(){
	wp_enqueue_style('fashion-outfits-trend-admin-style', esc_url( get_template_directory_uri() ) . '/assets/css/fashion-outfits-trend-notice.css');
	wp_enqueue_script('fashion-outfits-trend-dismiss-notice-script', get_stylesheet_directory_uri() . '/assets/js/fashion-outfits-trend-notice.js', array('jquery'), null, true);
}
add_action( 'admin_enqueue_scripts', 'fashion_outfits_trend_admin_enqueue_scripts' );

function fashion_outfits_trend_remove_customize_register() {
    global $wp_customize;

    $wp_customize->remove_setting( 'display_header_text' );
    $wp_customize->remove_control( 'display_header_text' );

}

add_action( 'customize_register', 'fashion_outfits_trend_remove_customize_register', 11 );

add_filter( 'woocommerce_enable_setup_wizard', '__return_false' );