<?php

namespace Quicker\Base;

defined( 'ABSPATH' ) || exit;

use Quicker\Utils\Singleton;

/**
 * Enqueue all css and js file class
 */
class Enqueue {

	use Singleton;

	/**
	 * Main calling function
	 */
	public function init() {
		// backend asset
		add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_assets' ) );
		// frontend asset
		add_action( 'wp_enqueue_scripts', array( $this, 'frontend_enqueue_assets' ) );
		// Allow SVG uploads for qview_icon
		add_action( 'admin_init', array( $this, 'setup_svg_support' ) );
		// enqueue editor css.
		add_action( 'elementor/editor/before_enqueue_styles', array( $this, 'elementor_editor_css' ) );
		// enqueue editor js.
		add_action( 'elementor/frontend/before_enqueue_scripts', array( $this, 'elementor_js' ) );
	}


	/**
	 * all admin js files function
	 */
	public function admin_get_scripts() {
		$script_arr = array(
			'quicker-select2'  => array(
				'src'     => \Quicker::assets_url() . 'js/quicker-select2.js',
				'version' => \Quicker::get_version(),
				'deps'    => array( 'jquery' ),
			),
			'quicker-admin-js' => array(
				'src'     => \Quicker::assets_url() . 'js/admin.js',
				'version' => \Quicker::get_version(),
				'deps'    => array( 'jquery', 'quicker-select2' ),
			),
		);

		return $script_arr;
	}

	/**
	 * all admin css files function
	 *
	 * @param array
	 */
	public function admin_get_styles() {
		return array(
			'quicker-select2'   => array(
				'src'     => \Quicker::assets_url() . 'css/select2.css',
				'version' => \Quicker::get_version(),
			),
			'quicker-admin-css' => array(
				'src'     => \Quicker::assets_url() . 'css/admin.css',
				'version' => \Quicker::get_version(),
			),
		);
	}

	/**
	 * Enqueue admin js and css function
	 *
	 * @param  $var
	 */
	public function admin_enqueue_assets() {
		$screen = get_current_screen();
		$pages  = \Quicker\Utils\Helper::admin_pages_id();

		// load js in specific pages
		if ( is_admin() && ( in_array( $screen->id, $pages ) ) ) {
				wp_enqueue_style( 'wp-color-picker' );
				wp_enqueue_script( 'wp-color-picker' );
				wp_enqueue_script( 'jquery-ui-sortable' );
				wp_enqueue_media();
				wp_enqueue_script( 'wc-enhanced-select' );
				// Icon font used by the conditional-logic repeater + / - buttons.
				wp_enqueue_style( 'dashicons' );

			foreach ( $this->admin_get_scripts() as $key => $value ) {
				$deps    = ! empty( $value['deps'] ) ? $value['deps'] : false;
				$version = ! empty( $value['version'] ) ? $value['version'] : false;
				wp_enqueue_script( $key, $value['src'], $deps, $version, true );
			}

				// css

			foreach ( $this->admin_get_styles() as $key => $value ) {
				$deps    = isset( $value['deps'] ) ? $value['deps'] : false;
				$version = ! empty( $value['version'] ) ? $value['version'] : false;
				wp_enqueue_style( $key, $value['src'], $deps, $version, 'all' );
			}

				// localize for admin
				$settings                      = \Quicker\Utils\Helper::get_settings();
				$form_data                     = array();
				$form_data['ajax_url']              = admin_url( 'admin-ajax.php' );
				$form_data['nonce']                 = wp_create_nonce( 'quicker' );
				$form_data['up_sell_products']      = $settings['up_sell_products'];
				$form_data['search_products_nonce'] = wp_create_nonce( 'search-products' );

				// Option lists for checkout field conditional-logic value dropdowns.
				$form_data['product_categories'] = \Quicker\Utils\Helper::get_product_categories();
				$form_data['payment_methods']    = \Quicker\Utils\Helper::get_payment_methods();
				$form_data['shipping_methods']   = \Quicker\Utils\Helper::get_shipping_methods();
				$form_data['shipping_classes']   = \Quicker\Utils\Helper::get_shipping_classes();

				// Pre-resolve product/variation IDs referenced in saved field conditions so
				// the admin select2 shows product names (instead of raw IDs) when reopening.
				$form_data['selected_product_labels'] = \Quicker\Utils\Helper::get_condition_product_labels();

				wp_localize_script( 'quicker-admin-js', 'quicker_admin_data', $form_data );
		}
	}

	/**
	 * all js files function
	 */
	public function frontend_get_scripts() {
		$script_arr = array(
			'quicker-frontend'    => array(
				'src'     => \Quicker::assets_url() . 'js/frontend.js',
				'version' => \Quicker::get_version(),
				'deps'    => array( 'jquery', 'quicker-swiper' ),
			),
			'quicker-swiper' => array(
				'src'     => \Quicker::assets_url() . 'js/quicker-swiper-element-bundle.min.js',
				'version' => \Quicker::get_version(),
				'deps'    => array( 'jquery' ),
			),
		);

		return $script_arr;
	}

	/**
	 * all css files function
	 */
	public function frontend_get_styles() {
		$enequeue = array(
			'quicker-public' => array(
				'src'     => \Quicker::assets_url() . 'css/public.css',
				'version' => \Quicker::get_version(),
			),
			'quicker-swiper' => array(
				'src'     => \Quicker::assets_url() . 'css/quicker-swiper-bundle.min.css',
				'version' => \Quicker::get_version(),
			),
		);

		return $enequeue;
	}

	/**
	 * Enqueue admin js and css function
	 */
	public function frontend_enqueue_assets() {
		// js
		$scripts = $this->frontend_get_scripts();
		if ( class_exists( 'Woocommerce' ) ) {
			wp_enqueue_script( 'wc-add-to-cart-variation' );
			wp_enqueue_script( 'wc-single-product' );
			wp_enqueue_script( 'zoom' );
			wp_enqueue_script( 'flexslider' );
			wp_enqueue_script( 'photoswipe-ui-default' );
			wp_enqueue_style( 'photoswipe-default-skin' );
		}
		if ( function_exists('WC') ) {
			// Enqueue WooCommerce cart fragments
			wp_enqueue_script('wc-cart-fragments');
		}
		foreach ( $scripts as $key => $value ) {
			$deps    = isset( $value['deps'] ) ? $value['deps'] : false;
			$version = ! empty( $value['version'] ) ? $value['version'] : false;
			wp_enqueue_script( $key, $value['src'], $deps, $version, true );
		}

		// css
		$styles = $this->frontend_get_styles();

		foreach ( $styles as $key => $value ) {
			$deps    = isset( $value['deps'] ) ? $value['deps'] : false;
			$version = ! empty( $value['version'] ) ? $value['version'] : false;
			wp_enqueue_style( $key, $value['src'], $deps, $version, 'all' );
		}

		// Dynamic side cart styles from settings
		$settings       = \Quicker\Utils\Helper::get_settings();
		$sidecart_css   = '';
		$sc_bg          = ! empty( $settings['sc_bg_color'] ) ? $settings['sc_bg_color'] : '';
		$sc_title       = ! empty( $settings['sc_title_color'] ) ? $settings['sc_title_color'] : '';
		$sc_name        = ! empty( $settings['sc_product_name_color'] ) ? $settings['sc_product_name_color'] : '';
		$sc_price       = ''; // Deprecated: now split into subtotal/fees/total individual colors
		$sc_checkout_bg = ! empty( $settings['sc_checkout_bg_color'] ) ? $settings['sc_checkout_bg_color'] : '';
		$sc_checkout_tx = ! empty( $settings['sc_checkout_text_color'] ) ? $settings['sc_checkout_text_color'] : '';

		if ( $sc_bg ) {
			$sidecart_css .= '.side-cart-wrapper{background:' . esc_attr( $sc_bg ) . ';}';
		}
		if ( $sc_title ) {
			$sidecart_css .= '.side-cart-title{color:' . esc_attr( $sc_title ) . ';}';
		}
		if ( $sc_name ) {
			$sidecart_css .= '.cart-row .product-name{color:' . esc_attr( $sc_name ) . ';}';
		}
		// Subtotal styles
		$sc_subtotal_label_fs    = isset( $settings['sc_subtotal_label_font_size'] ) && '' !== $settings['sc_subtotal_label_font_size'] ? $settings['sc_subtotal_label_font_size'] : '';
		$sc_subtotal_label_color = ! empty( $settings['sc_subtotal_label_color'] ) ? $settings['sc_subtotal_label_color'] : '';
		$sc_subtotal_price_fs    = isset( $settings['sc_subtotal_price_font_size'] ) && '' !== $settings['sc_subtotal_price_font_size'] ? $settings['sc_subtotal_price_font_size'] : '';
		$sc_subtotal_price_color = ! empty( $settings['sc_subtotal_price_color'] ) ? $settings['sc_subtotal_price_color'] : '';
		if ( '' !== $sc_subtotal_label_fs ) { $sidecart_css .= '.sub-total strong{font-size:' . intval( $sc_subtotal_label_fs ) . 'px;}'; }
		if ( $sc_subtotal_label_color ) { $sidecart_css .= '.sub-total strong{color:' . esc_attr( $sc_subtotal_label_color ) . ';}'; }
		if ( '' !== $sc_subtotal_price_fs ) { $sidecart_css .= '.sub-total span{font-size:' . intval( $sc_subtotal_price_fs ) . 'px;}'; }
		if ( $sc_subtotal_price_color ) { $sidecart_css .= '.sub-total span{color:' . esc_attr( $sc_subtotal_price_color ) . ';}'; }

		// Cart Fees styles
		$sc_fees_label_fs    = isset( $settings['sc_fees_label_font_size'] ) && '' !== $settings['sc_fees_label_font_size'] ? $settings['sc_fees_label_font_size'] : '';
		$sc_fees_label_color = ! empty( $settings['sc_fees_label_color'] ) ? $settings['sc_fees_label_color'] : '';
		$sc_fees_price_fs    = isset( $settings['sc_fees_price_font_size'] ) && '' !== $settings['sc_fees_price_font_size'] ? $settings['sc_fees_price_font_size'] : '';
		$sc_fees_price_color = ! empty( $settings['sc_fees_price_color'] ) ? $settings['sc_fees_price_color'] : '';
		if ( '' !== $sc_fees_label_fs ) { $sidecart_css .= '.mini-cart-fees .fee-label,.mini-cart-shipping .quicker-shipping span:first-child,.mini-cart-taxes .quicker-tax span:first-child{font-size:' . intval( $sc_fees_label_fs ) . 'px;}'; }
		if ( $sc_fees_label_color ) { $sidecart_css .= '.mini-cart-fees .fee-label,.mini-cart-shipping .quicker-shipping span:first-child,.mini-cart-taxes .quicker-tax span:first-child{color:' . esc_attr( $sc_fees_label_color ) . ';}'; }
		if ( '' !== $sc_fees_price_fs ) { $sidecart_css .= '.mini-cart-fees .fee-amount,.mini-cart-shipping .quicker-shipping span:last-child,.mini-cart-taxes .quicker-tax span:last-child{font-size:' . intval( $sc_fees_price_fs ) . 'px;}'; }
		if ( $sc_fees_price_color ) { $sidecart_css .= '.mini-cart-fees .fee-amount,.mini-cart-shipping .quicker-shipping span:last-child,.mini-cart-taxes .quicker-tax span:last-child{color:' . esc_attr( $sc_fees_price_color ) . ';}'; }

		// Total styles
		$sc_total_label_fs    = isset( $settings['sc_total_label_font_size'] ) && '' !== $settings['sc_total_label_font_size'] ? $settings['sc_total_label_font_size'] : '';
		$sc_total_label_color = ! empty( $settings['sc_total_label_color'] ) ? $settings['sc_total_label_color'] : '';
		$sc_total_price_fs    = isset( $settings['sc_total_price_font_size'] ) && '' !== $settings['sc_total_price_font_size'] ? $settings['sc_total_price_font_size'] : '';
		$sc_total_price_color = ! empty( $settings['sc_total_price_color'] ) ? $settings['sc_total_price_color'] : '';
		if ( '' !== $sc_total_label_fs ) { $sidecart_css .= '.side-cart-extra-total strong{font-size:' . intval( $sc_total_label_fs ) . 'px;}'; }
		if ( $sc_total_label_color ) { $sidecart_css .= '.side-cart-extra-total strong{color:' . esc_attr( $sc_total_label_color ) . ';}'; }
		if ( '' !== $sc_total_price_fs ) { $sidecart_css .= '.side-cart-extra-total b,.cart-total{font-size:' . intval( $sc_total_price_fs ) . 'px;}'; }
		if ( $sc_total_price_color ) { $sidecart_css .= '.side-cart-extra-total b,.cart-total{color:' . esc_attr( $sc_total_price_color ) . ';}'; }

		// Total extra text styles
		$sc_extra_text_fs    = isset( $settings['sc_total_extra_text_font_size'] ) && '' !== $settings['sc_total_extra_text_font_size'] ? $settings['sc_total_extra_text_font_size'] : '';
		$sc_extra_text_color = ! empty( $settings['sc_total_extra_text_color'] ) ? $settings['sc_total_extra_text_color'] : '';
		if ( '' !== $sc_extra_text_fs ) { $sidecart_css .= '.side-cart-extra-total .extra-text{font-size:' . intval( $sc_extra_text_fs ) . 'px;}'; }
		if ( $sc_extra_text_color ) { $sidecart_css .= '.side-cart-extra-total .extra-text{color:' . esc_attr( $sc_extra_text_color ) . ';}'; }

		if ( $sc_checkout_bg ) {
			$sidecart_css .= '.quicker-checkout{background:' . esc_attr( $sc_checkout_bg ) . ';border-color:' . esc_attr( $sc_checkout_bg ) . ';}';
			$sidecart_css .= '.continue-shopping,.continue-shopping:hover{color:' . esc_attr( $sc_checkout_bg ) . ' !important;border-color:' . esc_attr( $sc_checkout_bg ) . ' !important;}';
		}
		if ( $sc_checkout_tx ) {
			$sidecart_css .= '.quicker-checkout{color:' . esc_attr( $sc_checkout_tx ) . ';}';
		}

		$sc_checkout_hover = ! empty( $settings['sc_checkout_hover_color'] ) ? $settings['sc_checkout_hover_color'] : '';
		if ( $sc_checkout_hover && '#ffffff' !== strtolower( $sc_checkout_hover ) ) {
			$sidecart_css .= '.quicker-checkout:hover{background:' . esc_attr( $sc_checkout_hover ) . ' !important;border-color:' . esc_attr( $sc_checkout_hover ) . ' !important;opacity:1;}';
		}

		$sc_remove_color = ! empty( $settings['sc_remove_icon_color'] ) ? $settings['sc_remove_icon_color'] : '';
		$sc_remove_size  = isset( $settings['sc_remove_icon_size'] ) && '' !== $settings['sc_remove_icon_size'] && '15' !== $settings['sc_remove_icon_size'] ? $settings['sc_remove_icon_size'] : '22';
		$sc_calc_color   = ! empty( $settings['sc_price_calc_color'] ) ? $settings['sc_price_calc_color'] : '';
		$sc_calc_fs      = isset( $settings['sc_price_calc_font_size'] ) && '' !== $settings['sc_price_calc_font_size'] ? $settings['sc_price_calc_font_size'] : '14';

		if ( $sc_remove_color ) {
			$sidecart_css .= '.quicker_remove_item svg circle,.quicker_remove_item svg path{stroke:' . esc_attr( $sc_remove_color ) . ';}';
		}
		if ( '' !== $sc_remove_size && '22' !== $sc_remove_size ) {
			$sidecart_css .= '.quicker_remove_item svg.cart-remove{width:' . intval( $sc_remove_size ) . 'px;height:' . intval( $sc_remove_size ) . 'px;}';
		}
		if ( $sc_calc_color ) {
			$sidecart_css .= '.cart-row .product-price div:first-child{color:' . esc_attr( $sc_calc_color ) . ';}';
		}
		if ( '' !== $sc_calc_fs && '14' !== $sc_calc_fs ) {
			$sidecart_css .= '.cart-row .product-price div:first-child{font-size:' . intval( $sc_calc_fs ) . 'px;}';
		}

		// Quantity styles
		$sc_qty_color      = ! empty( $settings['sc_qty_color'] ) ? $settings['sc_qty_color'] : '';
		$sc_qty_border     = ! empty( $settings['sc_qty_border_color'] ) ? $settings['sc_qty_border_color'] : '';
		$sc_qty_btn_bg     = ! empty( $settings['sc_qty_btn_bg'] ) ? $settings['sc_qty_btn_bg'] : '';
		if ( $sc_qty_color ) {
			$sidecart_css .= '.mini-qty .qty-handle,.mini-qty .qty{color:' . esc_attr( $sc_qty_color ) . ';}';
		}
		if ( $sc_qty_border ) {
			$sidecart_css .= '.mini-qty{border-color:' . esc_attr( $sc_qty_border ) . ';}';
			$sidecart_css .= '.mini-qty .qty{border-left-color:' . esc_attr( $sc_qty_border ) . ';border-right-color:' . esc_attr( $sc_qty_border ) . ';}';
		}
		if ( $sc_qty_btn_bg ) {
			$sidecart_css .= '.mini-qty .qty-handle{background-color:' . esc_attr( $sc_qty_btn_bg ) . ';}';
		}

		// Quantity border widths
		$sc_qb_top    = isset( $settings['sc_qty_border_top'] ) && '' !== $settings['sc_qty_border_top'] ? $settings['sc_qty_border_top'] : '';
		$sc_qb_bottom = isset( $settings['sc_qty_border_bottom'] ) && '' !== $settings['sc_qty_border_bottom'] ? $settings['sc_qty_border_bottom'] : '';
		$sc_qb_left   = isset( $settings['sc_qty_border_left'] ) && '' !== $settings['sc_qty_border_left'] ? $settings['sc_qty_border_left'] : '';
		$sc_qb_right  = isset( $settings['sc_qty_border_right'] ) && '' !== $settings['sc_qty_border_right'] ? $settings['sc_qty_border_right'] : '';
		$qty_border_css = '';
		if ( '' !== $sc_qb_top ) { $qty_border_css .= 'border-top-width:' . intval( $sc_qb_top ) . 'px;'; }
		if ( '' !== $sc_qb_bottom ) { $qty_border_css .= 'border-bottom-width:' . intval( $sc_qb_bottom ) . 'px;'; }
		if ( '' !== $sc_qb_left ) { $qty_border_css .= 'border-left-width:' . intval( $sc_qb_left ) . 'px;'; }
		if ( '' !== $sc_qb_right ) { $qty_border_css .= 'border-right-width:' . intval( $sc_qb_right ) . 'px;'; }
		if ( $qty_border_css ) {
			$sidecart_css .= '.mini-qty{border-style:solid;' . $qty_border_css . '}';
		}

		$sc_border_top    = isset( $settings['sc_item_border_top'] ) && '' !== $settings['sc_item_border_top'] ? $settings['sc_item_border_top'] : '';
		$sc_border_bottom = isset( $settings['sc_item_border_bottom'] ) && '' !== $settings['sc_item_border_bottom'] ? $settings['sc_item_border_bottom'] : '';
		$sc_border_left   = isset( $settings['sc_item_border_left'] ) && '' !== $settings['sc_item_border_left'] ? $settings['sc_item_border_left'] : '';
		$sc_border_right  = isset( $settings['sc_item_border_right'] ) && '' !== $settings['sc_item_border_right'] ? $settings['sc_item_border_right'] : '';
		$sc_border_type   = ! empty( $settings['sc_item_border_type'] ) ? $settings['sc_item_border_type'] : '';
		$sc_border_color  = ! empty( $settings['sc_item_border_color'] ) ? $settings['sc_item_border_color'] : '';
		$border_css = '';
		if ( '' !== $sc_border_top ) { $border_css .= 'border-top-width:' . intval( $sc_border_top ) . 'px;'; }
		if ( '' !== $sc_border_bottom ) { $border_css .= 'border-bottom-width:' . intval( $sc_border_bottom ) . 'px;'; }
		if ( '' !== $sc_border_left ) { $border_css .= 'border-left-width:' . intval( $sc_border_left ) . 'px;'; }
		if ( '' !== $sc_border_right ) { $border_css .= 'border-right-width:' . intval( $sc_border_right ) . 'px;'; }
		if ( '' !== $sc_border_type ) { $border_css .= 'border-style:' . esc_attr( $sc_border_type ) . ';'; }
		if ( '' !== $sc_border_color ) { $border_css .= 'border-color:' . esc_attr( $sc_border_color ) . ';'; }
		if ( $border_css ) {
			$sidecart_css .= '.cart-row{' . $border_css . '}';
		}

		$sc_coupon_bg = ! empty( $settings['sc_coupon_bg_color'] ) ? $settings['sc_coupon_bg_color'] : '';
		$sc_coupon_tx = ! empty( $settings['sc_coupon_text_color'] ) ? $settings['sc_coupon_text_color'] : '';

		if ( $sc_coupon_bg ) {
			$sidecart_css .= '.cupon-btn,.coupon-wrapper .cupon-btn{background-color:' . esc_attr( $sc_coupon_bg ) . ' !important;border-color:' . esc_attr( $sc_coupon_bg ) . ' !important;}';
		}
		if ( $sc_coupon_tx ) {
			$sidecart_css .= '.cupon-btn,.coupon-wrapper .cupon-btn{color:' . esc_attr( $sc_coupon_tx ) . ' !important;}';
		}

		$sc_coupon_field_bg = ! empty( $settings['sc_coupon_field_bg_color'] ) ? $settings['sc_coupon_field_bg_color'] : '';
		if ( $sc_coupon_field_bg ) {
			$sidecart_css .= '.quicker-minicart-coupon-field,.minicart-coupon-field,.coupon_from .quicker-minicart-coupon-field{background-color:' . esc_attr( $sc_coupon_field_bg ) . ' !important;}';
		}

		// Coupon title styles
		$sc_coupon_title_fs    = isset( $settings['sc_coupon_title_font_size'] ) && '' !== $settings['sc_coupon_title_font_size'] ? $settings['sc_coupon_title_font_size'] : '';
		$sc_coupon_title_color = ! empty( $settings['sc_coupon_title_color'] ) ? $settings['sc_coupon_title_color'] : '';
		if ( '' !== $sc_coupon_title_fs ) { $sidecart_css .= '.coupon-wrapper .coupon-title{font-size:' . intval( $sc_coupon_title_fs ) . 'px;}'; }
		if ( $sc_coupon_title_color ) { $sidecart_css .= '.coupon-wrapper .coupon-title{color:' . esc_attr( $sc_coupon_title_color ) . ';}'; }

		// Coupon border styles
		$sc_cb_top    = isset( $settings['sc_coupon_border_top'] ) && '' !== $settings['sc_coupon_border_top'] ? $settings['sc_coupon_border_top'] : '';
		$sc_cb_bottom = isset( $settings['sc_coupon_border_bottom'] ) && '' !== $settings['sc_coupon_border_bottom'] ? $settings['sc_coupon_border_bottom'] : '';
		$sc_cb_left   = isset( $settings['sc_coupon_border_left'] ) && '' !== $settings['sc_coupon_border_left'] ? $settings['sc_coupon_border_left'] : '';
		$sc_cb_right  = isset( $settings['sc_coupon_border_right'] ) && '' !== $settings['sc_coupon_border_right'] ? $settings['sc_coupon_border_right'] : '';
		$sc_cb_type   = ! empty( $settings['sc_coupon_border_type'] ) ? $settings['sc_coupon_border_type'] : '';
		$sc_cb_color  = ! empty( $settings['sc_coupon_border_color'] ) ? $settings['sc_coupon_border_color'] : '';
		$coupon_border_css = '';
		if ( '' !== $sc_cb_top ) { $coupon_border_css .= 'border-top-width:' . intval( $sc_cb_top ) . 'px;'; }
		if ( '' !== $sc_cb_bottom ) { $coupon_border_css .= 'border-bottom-width:' . intval( $sc_cb_bottom ) . 'px;'; }
		if ( '' !== $sc_cb_left ) { $coupon_border_css .= 'border-left-width:' . intval( $sc_cb_left ) . 'px;'; }
		if ( '' !== $sc_cb_right ) { $coupon_border_css .= 'border-right-width:' . intval( $sc_cb_right ) . 'px;'; }
		if ( '' !== $sc_cb_type ) { $coupon_border_css .= 'border-style:' . esc_attr( $sc_cb_type ) . ';'; }
		if ( '' !== $sc_cb_color ) { $coupon_border_css .= 'border-color:' . esc_attr( $sc_cb_color ) . ';'; }
		if ( $coupon_border_css ) {
			$sidecart_css .= '.coupon-wrapper{' . $coupon_border_css . '}';
		}

		$sc_pt = isset( $settings['sc_padding_top'] ) && '' !== $settings['sc_padding_top'] ? $settings['sc_padding_top'] : '';
		$sc_pb = isset( $settings['sc_padding_bottom'] ) && '' !== $settings['sc_padding_bottom'] ? $settings['sc_padding_bottom'] : '';
		$sc_pl = isset( $settings['sc_padding_left'] ) && '' !== $settings['sc_padding_left'] ? $settings['sc_padding_left'] : '';
		$sc_pr = isset( $settings['sc_padding_right'] ) && '' !== $settings['sc_padding_right'] ? $settings['sc_padding_right'] : '';
		$padding_css = '';
		if ( '' !== $sc_pt ) { $padding_css .= 'padding-top:' . intval( $sc_pt ) . 'px;'; }
		if ( '' !== $sc_pb ) { $padding_css .= 'padding-bottom:' . intval( $sc_pb ) . 'px;'; }
		if ( '' !== $sc_pl ) { $padding_css .= 'padding-left:' . intval( $sc_pl ) . 'px;'; }
		if ( '' !== $sc_pr ) { $padding_css .= 'padding-right:' . intval( $sc_pr ) . 'px;'; }
		if ( $padding_css ) {
			$sidecart_css .= '.cart-row{' . $padding_css . '}';
		}
		// Mini-cart icon styles
		$sc_icon_pos    = isset( $settings['sc_icon_position'] ) ? $settings['sc_icon_position'] : 'bottom';
		$sc_icon_bottom = isset( $settings['sc_icon_bottom'] ) && '' !== $settings['sc_icon_bottom'] ? $settings['sc_icon_bottom'] : '20';
		$sc_icon_bg     = ! empty( $settings['sc_icon_bg_color'] ) ? $settings['sc_icon_bg_color'] : '';
		$sc_icon_radius = isset( $settings['sc_icon_border_radius'] ) && strlen( $settings['sc_icon_border_radius'] ) ? $settings['sc_icon_border_radius'] : '50';
		$sc_count_bg    = ! empty( $settings['sc_count_bg_color'] ) ? $settings['sc_count_bg_color'] : '';
		$sc_count_color = ! empty( $settings['sc_count_text_color'] ) ? $settings['sc_count_text_color'] : '';

		if ( 'middle' === $sc_icon_pos ) {
			$sidecart_css .= '.side-cart-icon{bottom:auto;top:50%;transform:translateY(-50%);}';
		} elseif ( '20' !== $sc_icon_bottom ) {
			$sidecart_css .= '.side-cart-icon{bottom:' . intval( $sc_icon_bottom ) . 'px;}';
		}
		if ( $sc_icon_bg ) {
			$sidecart_css .= '.side-cart-icon{background:' . esc_attr( $sc_icon_bg ) . ';}';
		}
		if ( '50' !== $sc_icon_radius ) {
			$sidecart_css .= '.side-cart-icon{border-radius:' . intval( $sc_icon_radius ) . '%;}';
		}
		if ( $sc_count_bg ) {
			$sidecart_css .= '.quicker-cart-count{background:' . esc_attr( $sc_count_bg ) . ';}';
		}
		if ( $sc_count_color ) {
			$sidecart_css .= '.quicker-cart-count{color:' . esc_attr( $sc_count_color ) . ';}';
		}

		$sc_icon_color = ! empty( $settings['sc_icon_color'] ) ? $settings['sc_icon_color'] : '';
		if ( $sc_icon_color ) {
			$sidecart_css .= '.side-cart-icon svg{fill:' . esc_attr( $sc_icon_color ) . ';color:' . esc_attr( $sc_icon_color ) . ';}';
		}

		$sidecart_css .= '.side-cart-content .cart-row a.quicker_remove_item{z-index:2;}';

		// Order Bump styles.
		$ob_bg = ! empty( $settings['ob_bg_color'] ) ? $settings['ob_bg_color'] : '';
		if ( $ob_bg ) {
			$sidecart_css .= '.quicker-bump,.bump-template-single-1 .bump-content{background:' . esc_attr( $ob_bg ) . ';}';
		}

		$ob_header_color = ! empty( $settings['ob_header_color'] ) ? $settings['ob_header_color'] : '';
		if ( $ob_header_color ) {
			$sidecart_css .= '.order-bump-title{color:' . esc_attr( $ob_header_color ) . ';}';
		}

		$ob_font_size = isset( $settings['ob_font_size'] ) && '' !== $settings['ob_font_size'] ? $settings['ob_font_size'] : '';
		if ( '' !== $ob_font_size && '15' !== $ob_font_size ) {
			$sidecart_css .= '.order-bump-title{font-size:' . intval( $ob_font_size ) . 'px;}';
		}

		// Order Bump padding.
		$ob_pt = isset( $settings['ob_padding_top'] ) && '' !== $settings['ob_padding_top'] ? $settings['ob_padding_top'] : '';
		$ob_pb = isset( $settings['ob_padding_bottom'] ) && '' !== $settings['ob_padding_bottom'] ? $settings['ob_padding_bottom'] : '';
		$ob_pl = isset( $settings['ob_padding_left'] ) && '' !== $settings['ob_padding_left'] ? $settings['ob_padding_left'] : '';
		$ob_pr = isset( $settings['ob_padding_right'] ) && '' !== $settings['ob_padding_right'] ? $settings['ob_padding_right'] : '';
		$ob_padding_css = '';
		if ( '' !== $ob_pt ) {
			$ob_padding_css .= 'padding-top:' . intval( $ob_pt ) . 'px;';
		}
		if ( '' !== $ob_pb ) {
			$ob_padding_css .= 'padding-bottom:' . intval( $ob_pb ) . 'px;';
		}
		if ( '' !== $ob_pl ) {
			$ob_padding_css .= 'padding-left:' . intval( $ob_pl ) . 'px;';
		}
		if ( '' !== $ob_pr ) {
			$ob_padding_css .= 'padding-right:' . intval( $ob_pr ) . 'px;';
		}
		if ( $ob_padding_css ) {
			$sidecart_css .= '.quicker-bump,.bump-template-single-1 .bump-content{' . $ob_padding_css . '}';
		}

		// Order Bump Item: Product Name styles.
		$ob_name_color = ! empty( $settings['ob_name_color'] ) ? $settings['ob_name_color'] : '';
		if ( $ob_name_color ) {
			$sidecart_css .= '.bump-item .title{color:' . esc_attr( $ob_name_color ) . ';}';
		}

		$ob_name_fs = isset( $settings['ob_name_font_size'] ) && '' !== $settings['ob_name_font_size'] ? $settings['ob_name_font_size'] : '';
		if ( '' !== $ob_name_fs ) {
			$sidecart_css .= '.bump-item .title{font-size:' . intval( $ob_name_fs ) . 'px;}';
		}

		$ob_name_mt = isset( $settings['ob_name_margin_top'] ) && '' !== $settings['ob_name_margin_top'] ? $settings['ob_name_margin_top'] : '';
		$ob_name_mb = isset( $settings['ob_name_margin_bottom'] ) && '' !== $settings['ob_name_margin_bottom'] ? $settings['ob_name_margin_bottom'] : '';
		$ob_name_margin = '';
		if ( '' !== $ob_name_mt ) {
			$ob_name_margin .= 'margin-top:' . intval( $ob_name_mt ) . 'px;';
		}
		if ( '' !== $ob_name_mb ) {
			$ob_name_margin .= 'margin-bottom:' . intval( $ob_name_mb ) . 'px;';
		}
		if ( $ob_name_margin ) {
			$sidecart_css .= '.bump-item .title{' . $ob_name_margin . '}';
		}

		// Order Bump Item: Product Price styles.
		$ob_price_color = ! empty( $settings['ob_price_color'] ) ? $settings['ob_price_color'] : '';
		if ( $ob_price_color ) {
			$sidecart_css .= '.bump-item .price{color:' . esc_attr( $ob_price_color ) . ';}';
		}

		$ob_price_fs = isset( $settings['ob_price_font_size'] ) && '' !== $settings['ob_price_font_size'] ? $settings['ob_price_font_size'] : '';
		if ( '' !== $ob_price_fs ) {
			$sidecart_css .= '.bump-item .price{font-size:' . intval( $ob_price_fs ) . 'px;}';
		}

		$ob_price_mt = isset( $settings['ob_price_margin_top'] ) && '' !== $settings['ob_price_margin_top'] ? $settings['ob_price_margin_top'] : '';
		$ob_price_mb = isset( $settings['ob_price_margin_bottom'] ) && '' !== $settings['ob_price_margin_bottom'] ? $settings['ob_price_margin_bottom'] : '';
		$ob_price_margin = '';
		if ( '' !== $ob_price_mt ) {
			$ob_price_margin .= 'margin-top:' . intval( $ob_price_mt ) . 'px;';
		}
		if ( '' !== $ob_price_mb ) {
			$ob_price_margin .= 'margin-bottom:' . intval( $ob_price_mb ) . 'px;';
		}
		if ( $ob_price_margin ) {
			$sidecart_css .= '.bump-item .price{' . $ob_price_margin . '}';
		}

		// Order Bump Item: Cart Icon styles.
		$ob_icon_size = isset( $settings['ob_icon_size'] ) && '' !== $settings['ob_icon_size'] ? $settings['ob_icon_size'] : '';
		if ( '' !== $ob_icon_size ) {
			$sidecart_css .= '.bump-item .cart-icon,.bump-item .quicker-cart-icon,.bump-item a.add_to_cart_button svg{width:' . intval( $ob_icon_size ) . 'px;height:' . intval( $ob_icon_size ) . 'px;}';
		}

		$ob_icon_color = ! empty( $settings['ob_icon_color'] ) ? $settings['ob_icon_color'] : '';
		if ( $ob_icon_color ) {
			$sidecart_css .= '.bump-item .cart-icon,.bump-item .quicker-cart-icon,.bump-item a.add_to_cart_button svg{fill:' . esc_attr( $ob_icon_color ) . ' !important;}';
		}

		// Order Bump Arrow styles (Swiper navigation).
		$ob_arrow_color = ! empty( $settings['ob_arrow_color'] ) ? $settings['ob_arrow_color'] : '';
		if ( $ob_arrow_color ) {
			$sidecart_css .= '.quicker-bump{--swiper-navigation-color:' . esc_attr( $ob_arrow_color ) . ';}';
		}

		$ob_arrow_size = isset( $settings['ob_arrow_size'] ) && '' !== $settings['ob_arrow_size'] ? $settings['ob_arrow_size'] : '';
		if ( '' !== $ob_arrow_size ) {
			$sidecart_css .= '.quicker-bump{--swiper-navigation-size:' . intval( $ob_arrow_size ) . 'px;}';
		}

		if ( $sidecart_css ) {
			wp_add_inline_style( 'quicker-public', $sidecart_css );
		}

		// localize for frontend
		$form_data                     = array();
		$form_data['quicker_ajax_url'] = admin_url( 'admin-ajax.php' );
		$form_data['nonce']            = wp_create_nonce( 'quicker' );

		wp_localize_script( 'quicker-frontend', 'quicker_client_data', $form_data );
	}

	/**
	 * Elementor editor css loaded
	 */
	public function elementor_editor_css() {
	}

	/**
	 * Elementor js loaded
	 */
	public function elementor_js() {
	}

	/**
	 * Setup SVG upload support globally with security measures
	 */
	public function setup_svg_support() {
		// Add SVG to allowed mime types
		add_filter(
			'upload_mimes',
			function ( $mimes ) {
				$mimes['svg'] = 'image/svg+xml';
				return $mimes;
			}
		);
	}
}
