<?php

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Hook module functions if plugin is active
 */
if ( class_exists( 'WCAPF' ) ) {
	add_action( 'wp_enqueue_scripts', 'shrk_wcapf_scripts', 20 );
	add_filter( 'option_wcapf_settings', 'shrk_wcapf_filter_settings', 10, 2);
}

/**
 * Enqueue module scripts and styles
 */





function shrk_wcapf_scripts() {
	global $shrk_theme_info;
	$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';

	wp_deregister_style( 'wcapf-style' );
	wp_deregister_style( 'wcapf-select2' );
	wp_deregister_script( 'wcapf-select2' );

	wp_register_style( 'wcapf-style', SHRK_THEME_MODULES_URI . 'wc-ajax-product-filter/css/wc-ajax-product-filter' . $suffix . '.css' , array(), $shrk_theme_info['Version']  );
}

/**
 * Modify plugin's settings
 */
function shrk_wcapf_filter_settings( $settings, $option_name ) {
	if ( !is_admin() && !empty( $settings ) && is_array( $settings ) ) {
		// Add select2 & swipers initialization on after products updated
		$settings['custom_scripts'] = $settings['custom_scripts'] . ' shrk.woo.select2_init(); shrk.woo.swipersLoopInit();';
	}

	return $settings;
}
