<?php
/**
 * Technical theme functions.
 * DO NOT remove or override them unless you know what you're doing ;)
 *
 * @package Sunset
 */

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

/**
 * A wrapper function to get options.
 *
 * @param string $option The option name to look up.
 * @return string The option value.
 */
function sunset_get_option( $option, $defaults = null ) {
	if ($defaults === null) {
		$defaults = sunset_get_defaults();
	}

	if ( ! isset( $defaults[ $option ] ) ) {
		return;
	}

	// try to get option for a single post
	$option_meta = get_post_meta( get_queried_object_id(), '_'.$option, true );

	// return option for a single post if exists and not in Customizer mode
	if ( !is_customize_preview() && $option_meta !== '' && ($option_meta === 0 || $option_meta === '0' || !empty($option_meta)) ) {
		return $option_meta;
	}

	if ( strpos($option, 'sunset_settings' ) !== false ) { // if options is as an array
		$options = wp_parse_args(
			get_option( 'sunset_settings', array() ),
			$defaults
		);
		return $options[ $option ];
	} else { // if options is as an string
		$option_val = get_option( $option, $defaults[ $option ] );
		
		return ( $option_val === '' || $option_val === 0 || $option_val === '0' || !empty($option_val) ) ? $option_val : $defaults[ $option ];
	}

	return $options[ $option ];
}

/**
 * Generate string of classes for the specific part of content
 *
 * @param string $section The part of the content to generate classes for (topbar, header, content, footer, copyright etc.).
 * @param string $extra_class Extra class to be added for the list of classes.
 * 
 * @return string Space separated string of classes.
 */
function sunset_get_classes( $section, $extra_class = null ) {
	$classes = [];

	if ($section === 'topbar') { // classes for the topbar
		$sidebars_widgets = wp_get_sidebars_widgets();
		$is_topbar_enable = sunset_get_option( 'sunset_topbar_enable' );
		$header_container_class = sunset_get_option( 'sunset_header_full_width' ) ? 'container-fluid' : 'container';		
		$is_header_fixed = sunset_get_option( 'sunset_header_fixed' );
		$is_topbar_sticky = sunset_get_option( 'sunset_topbar_sticky' );
		$is_topbar_runline_enable = sunset_get_option( 'sunset_topbar_runline' );
		$topbar_cols = ( is_active_sidebar( 'topbar' ) ) ? count ($sidebars_widgets['topbar']) : 0;
		$topbar_align = sunset_get_option( 'sunset_topbar_align' );
		$is_topbar_hide_on_mobile = sunset_get_option( 'sunset_topbar_mobile_hide' );

		$classes = ['topbar'];
		$classes[] = 'topbar--align-'.$topbar_align;

		if ($topbar_cols === 1) {
			$classes[] = 'topbar--single';
		}
		if ($is_topbar_sticky && $is_header_fixed) {
			$classes[] = 'topbar--fixed';
		}
		if ($is_topbar_runline_enable) {
			$classes[] = 'topbar--runline';
		}
		if ($is_topbar_hide_on_mobile) {
			$classes[] = 'topbar--hide-on-mobile';
		}
	}

	if ($section === 'header') { // classes for the header
		$sunset_header_type = sunset_get_option( 'sunset_header_type' ) ;
		$header_menu_hover_type = sunset_get_option( 'sunset_header_menu_hover_type' );	
		$is_header_fixed = sunset_get_option( 'sunset_header_fixed' );
		$is_header_mobile_sticky_disable = sunset_get_option( 'sunset_header_mobile_sticky_disable' );
		$is_header_full_width = sunset_get_option( 'sunset_header_full_width' );
		$is_header_add_search = sunset_get_option( 'sunset_header_add_search' );
		$is_header_add_social = sunset_get_option( 'sunset_header_add_social' );
		$is_header_add_shadow = sunset_get_option( 'sunset_header_add_shadow' );
		$is_header_auto_responsive = sunset_get_option( 'sunset_header_auto_responsive' );
		$is_topbar_enable = sunset_get_option( 'sunset_topbar_enable' );
		$is_topbar_sticky = sunset_get_option( 'sunset_topbar_sticky' );
		$is_header_dynamic_font_size = sunset_get_option( 'sunset_header_dynamic_font_size' );

		$classes = ['site-header'];

		if ($is_header_fixed) {
			$classes[] = 'site-header--fixed';
			$classes[] = 'site-header--fixed-'.sunset_get_option( 'sunset_header_fixed_type' );
		}
		if ($is_header_full_width) {
			$classes[] = 'site-header--full-width';
		}
		if ($is_header_mobile_sticky_disable) {
			$classes[] = 'site-header--mobile-sticky-disable';
		}
		if ($is_header_add_search) {
			$classes[] = 'site-header--has-search';
		}
		if ($is_header_add_social) {
			$classes[] = 'site-header--has-social';
		}
		if ($is_header_add_shadow) {
			$classes[] = 'site-header--with-shadow';
		}
		if ($is_header_auto_responsive) {
			$classes[] = 'site-header--auto-responsive';
		} else {
			$classes[] = 'site-header--no-auto-responsive';
		}
		if ($is_topbar_enable && $is_topbar_sticky) {
			$classes[] = 'site-header--with-sticky-topbar';
		}
		if ($is_topbar_enable && !$is_topbar_sticky) {
			$classes[] = 'site-header--without-sticky-topbar';
		}
		if ( $sunset_header_type === 'header_1' ) {
			$classes[] = 'site-header--left';
		}
		if ( $sunset_header_type === 'header_2' ) {
			$classes[] = 'site-header--centered';
		}
		if ( $sunset_header_type === 'header_3' ) {
			$classes[] = 'site-header--left';
			$classes[] = 'site-header--left-with-menu';
		}
		if ( $sunset_header_type === 'header_4' ) {
			$classes[] = 'site-header--burger-always';
		}
		if ($is_header_dynamic_font_size) {
			$classes[] = 'site-header--dynamic-font-size';
		} else {
			$classes[] = 'site-header--no-dynamic-font-size';
		}

		if (is_single()) {
			$post_header_type = sunset_get_option('sunset_post_header_type');
			$classes[] = 'site-header--heading-'.$post_header_type;
		}
		if (is_page()) {
			$page_header_type = sunset_get_option('sunset_page_header_type');
			$classes[] = 'site-header--heading-'.$page_header_type;
		}

	}
	if ($section === 'mobile_menu') { // classes for the mobile menu
		$header_menu_mobile_align_x = sunset_get_option('sunset_header_menu_mobile_align_x');
		$header_menu_mobile_hover_type = sunset_get_option( 'sunset_header_menu_mobile_hover_type' ) ;
		
		$classes = ['fullscreen-menu-block'];
		$classes[] = 'fullscreen-menu-block--align-x-'.$header_menu_mobile_align_x;
		$classes[] = 'fullscreen-menu-block--'.$header_menu_mobile_hover_type;
	}
	if ($section === 'footer') { // classes for the footer
		$is_footer_dynamic_font_size = sunset_get_option( 'sunset_footer_dynamic_font_size' );
		$footer_type = sunset_get_option( 'sunset_footer_type' );

		$classes = ['site-footer'];

		if ($is_footer_dynamic_font_size) {
			$classes[] = 'site-footer--dynamic-font-size';
		} else {
			$classes[] = 'site-footer--no-dynamic-font-size';
		}
		if ($footer_type  === 'footer_1') { // columns
			$footer_columns = sunset_get_option( 'sunset_footer_columns' );
		}
		if ($footer_type  === 'footer_2') { // cross
			$footer_columns = 4;
			$classes[] = 'site-footer--cross-style';
		}
		$classes[] = 'cols-'.$footer_columns;
		
	}
	if ($section === 'copyright') { // classes for the copyright
		$sidebars_widgets = wp_get_sidebars_widgets();
		$sunset_copyright_cols = ( is_active_sidebar( 'copyright' ) ) ? count ($sidebars_widgets['copyright']) : 0;
		$is_copyright_runline_enable = sunset_get_option( 'sunset_copyright_runline' );		
		$copyright_align = sunset_get_option( 'sunset_copyright_align' );

		$classes = ['site-copyright'];
		$classes[] = 'site-copyright--align-'.$copyright_align;

		if ($is_copyright_runline_enable) {
			$classes[] = 'site-copyright--runline';
		}
		if ($sunset_copyright_cols === 1) {
			$classes[] = 'site-copyright--single';
		}
	}
	if ($section === 'body') { // classes for the <body> tag
		$layout_type = sunset_get_option( 'sunset_layout_type' );

		$blog_sidebar_position = sunset_get_option( 'sunset_blog_sidebar_position' );
		$post_sidebar_position = sunset_get_option( 'sunset_post_sidebar_position' );

		$blog_layout_type = sunset_get_option( 'sunset_blog_layout_type' );
		$post_layout_type = sunset_get_option( 'sunset_post_layout_type' );

		$is_blog_sidebar_sticky = sunset_get_option( 'sunset_blog_sidebar_sticky' );
		$is_post_sidebar_sticky = sunset_get_option( 'sunset_post_sidebar_sticky' );

		$blog_sidebar_sticky_position = sunset_get_option( 'sunset_blog_sidebar_sticky_position' );
		$post_sidebar_sticky_position = sunset_get_option( 'sunset_post_sidebar_sticky_position' );

		$is_header_fixed = sunset_get_option( 'sunset_header_fixed' );
		$header_fixed_type = sunset_get_option( 'sunset_header_fixed_type' );

		$is_content_dynamic_font_size = sunset_get_option( 'sunset_content_dynamic_font_size' );
		$is_bg_noise_enable = sunset_get_option( 'sunset_style_bg_noise_enable' );
		$is_custom_checkbox_enable = sunset_get_option( 'sunset_style_custom_checkbox_enable' );
		$input_style = sunset_get_option( 'sunset_style_input_style' );

		$classes = [];

		if (is_single() && has_post_thumbnail()) {
			$classes[] = 'has-post-thumbnail';
		}
		if (is_home() || is_archive() || is_search()) {
			if (is_active_sidebar( 'sidebar-blog' )) {
				$classes[] = 'has-sidebar';
				$classes[] = 'blog-sidebar--'.$blog_sidebar_position;
			}
			
			$classes[] = 'blog-layout--'.$blog_layout_type;

			if ($is_blog_sidebar_sticky) {
				if (is_active_sidebar( 'sidebar-blog' )) {
					$classes[] = 'has-sidebar-sticky';
					$classes[] = 'blog-sidebar-sticky--'.$blog_sidebar_position;
				}
				
			}
		}
		if (is_singular('post')) {
			if (is_active_sidebar( 'sidebar-post' )) {
				$classes[] = 'has-sidebar';
				$classes[] = 'post-sidebar--'.$post_sidebar_position;
			}

			if ($is_post_sidebar_sticky) {
				if (is_active_sidebar( 'sidebar-post' )) {
					$classes[] = 'has-sidebar-sticky';
					$classes[] = 'post-sidebar-sticky--'.$post_sidebar_position;
				}
			}
		}
		if (is_page()) {
			$classes[] = 'page-layout-'.$layout_type;
			$is_page_hide_paddings = sunset_get_option('sunset_page_hide_paddings');

			if ($is_page_hide_paddings) {
				$classes[] = 'page-no-paddings';
			}
		}
		if ($is_content_dynamic_font_size) {
			$classes[] = 'has-dynamic-font-size';
		} else {
			$classes[] = 'has-no-dynamic-font-size';
		}

		if ($is_bg_noise_enable) {
			$classes[] = 'has-bg-noise';
		}

		if ($is_header_fixed) {			
			$classes[] = 'header-'.$header_fixed_type;
		}

		if ($is_custom_checkbox_enable) {
			$classes[] = 'has-custom-checkbox';
		}
		$classes[] = 'input-style-'.$input_style;
	}

	if ($section === 'sidebar_blog_left') { // left sidebar for the archive <aside>
		$classes[] = 'sidebar';
		$classes[] = 'sidebar-blog';
		$classes[] = 'sidebar-blog--left';
		$classes[] = 'with-border';
	}

	if ($section === 'sidebar_blog_right') { // right sidebar for the archive <aside>
		$classes[] = 'sidebar';
		$classes[] = 'sidebar-blog';
		$classes[] = 'sidebar-blog--right';
		$classes[] = 'with-border';
	}

	if ($section === 'sidebar_post_left') { // left sidebar for the single post <aside>
		$classes[] = 'sidebar';
		$classes[] = 'sidebar-post';
		$classes[] = 'sidebar-post--left';
		$classes[] = 'with-border';
	}

	if ($section === 'sidebar_post_right') { // right sidebar for the single post <aside>
		$classes[] = 'sidebar';
		$classes[] = 'sidebar-post';
		$classes[] = 'sidebar-post--right';
		$classes[] = 'with-border';
	}

	if ($section === 'loop_post') { // classes for the post in loop (<article> tag)
		global $wp_query;
		$blog_grid_type = sunset_get_option( 'sunset_blog_grid_type' );

		$classes[] = 'loop-post';
		$counter = $wp_query->current_post + 1;
		$classes[] = ($counter % 2 === 0) ? 'even' : 'odd';

		if ($blog_grid_type === 'sticky' && $counter === 1) {
			$classes[] = 'loop-post-primary';
		}
		if ($blog_grid_type === 'full') {
			$classes[] = 'loop-post--full-width';
		}
	}

	if ($section === 'blog') { // classes for the <section> tag with posts for the archive
		$blog_grid_type = sunset_get_option( 'sunset_blog_grid_type' );
		$is_blog_add_border = sunset_get_option( 'sunset_blog_add_border' );
		$is_blog_add_shadow = sunset_get_option( 'sunset_blog_add_shadow' );

		$classes[] = 'content-section';
		$classes[] = 'content-section--blog';
		
		if ($blog_grid_type === 'sticky') {
			$classes[] = 'content-section--with-primary-post'; 
		} elseif($blog_grid_type === 'full') {
			$classes[] = 'content-section--full-width';
		} elseif($blog_grid_type === 'grid-fluid') {
			$classes[] = 'content-section--grid';
			$classes[] = 'content-section--grid-fluid';
		} else { 
			$classes[] = 'content-section--grid';
		}
		if ($is_blog_add_border && $blog_grid_type !== 'grid-fluid') {
			$classes[] = 'content-section--with-border'; 
		}
		if ($is_blog_add_shadow) {
			$classes[] = 'content-section--with-shadow'; 
		}
	}

	if ($section === 'blog_title') { // classes for the title of the archive
		$classes[] = 'title';
		$classes[] = 'title--primary';
	}

	if ($section === 'post_title') { // classes for the title of the single post
		if (is_page()) {
			$page_header_animation_type = sunset_get_option('sunset_page_header_animation_type');
			$is_page_stroke_title = sunset_get_option('sunset_page_stroke_title');

			if ($page_header_animation_type !== 'none') {
				$classes[] = 'sunset-animation';
				$classes[] = 'animate-'.$page_header_animation_type;
			}			

			if ($is_page_stroke_title) {
				$classes[] = 'title--stroked';
			}
		}
		if (is_singular('post')) {
			$post_header_animation_type = sunset_get_option('sunset_post_header_animation_type');
			$is_post_stroke_title = sunset_get_option('sunset_post_stroke_title');

			if ($post_header_animation_type !== 'none') {
				$classes[] = 'sunset-animation';
				$classes[] = 'animate-'.$post_header_animation_type;
			}	

			if ($is_post_stroke_title) {
				$classes[] = 'title--stroked';
			}
		}
		
		$classes[] = 'title';
		$classes[] = 'title--primary';
	}

	if ($section === 'heading_section') { // classes for the heading section (with title, breadcrumbs etc.)
		$classes[] = 'heading-section';
		if (is_singular('post')) {
			$post_header_type = sunset_get_option('sunset_post_header_type');			
			$classes[] = 'heading-section--'.$post_header_type;

			if (has_post_thumbnail() && $post_header_type !== 'default') {
				$classes[] = 'with-image';
			} elseif(!has_post_thumbnail() && $post_header_type === 'split') {
				$classes[] = 'with-image';
			}
			
		}
		if (is_page()) {
			$page_header_type = sunset_get_option('sunset_page_header_type');			
			$classes[] = 'heading-section--'.$page_header_type;

			if (has_post_thumbnail() && $page_header_type !== 'default') {
				$classes[] = 'with-image';
			} elseif(!has_post_thumbnail() && $page_header_type === 'split') {
				$classes[] = 'with-image';
			}
			
		}
		if (is_archive() || is_home()) {
			$blog_title_type = sunset_get_option( 'sunset_blog_title_type' );
			if ($blog_title_type === 'siblings') {
				$classes[] = 'with-siblings';
			}
		}
	}

	if ($section === 'page') { // classes for the single page content <section>
		$classes[] = 'content-section';
		$classes[] = 'content-section--page';
	}

	if ($section === 'post') { // classes for the single post content <section>
		$classes[] = 'content-section';
		$classes[] = 'content-section--post';
	}

	if ($section === 'related_posts') { // classes for the related posts block
		$is_blog_add_shadow = sunset_get_option( 'sunset_blog_add_shadow' );
		$classes[] = 'related-posts';
		
		$post_related_type = sunset_get_option('sunset_post_related_type');
		$related_posts_columns = sunset_get_option( 'sunset_post_related_columns' );
		$classes[] = 'related-posts--'.$post_related_type;
		$classes[] = 'related-posts--columns-'.$related_posts_columns;

		if ($is_blog_add_shadow) {
			$classes[] = 'related-posts--with-shadow'; 
		}
	}
	
	$classes[] = is_array($extra_class) ? esc_attr( implode( ' ', $classes ) ) : $extra_class;

	array_unique( $classes );
	$classes = esc_attr( implode( ' ', $classes ) );		
	$classes = apply_filters( 'sunset_'.$section.'_classes', $classes, $extra_class );

	return $classes;
}

/**
 * Dynamic font size clamp() builder
 * Scales $font_size from $min_width_px to $max_width_px 
 * @see https://css-tricks.com/linearly-scale-font-size-with-css-clamp-based-on-the-viewport/
 * 
 * @param integer $font_size - default font size at $max_width_px
 * @param integer $min_width_px - minimum width of the viewport when $font_size should be resized (mobile breakpoint)
 * @param integer $max_width_px - maximum width of the viewport when $font_size should be resized (content breakpoint)
 * @param integer $pixels_per_rem - default size of 1rem
 * @return string clamp()
 * 
 */
function sunset_clamp_builder( $font_size, $min_width_px, $max_width_px, $min_size = 10, $pixels_per_rem = 16 ) {
	$min_font_size = sunset_clamp_min_font_size($font_size, $min_size) / $pixels_per_rem;
	$max_font_size = $font_size / $pixels_per_rem; //sunset_clamp_max_font_size($font_size) / $pixels_per_rem; // if you need to scale font after $max_width_px 

	$min_width = $min_width_px / $pixels_per_rem;
	$maxWidth = $max_width_px / $pixels_per_rem;

	$slope = ( $max_font_size - $min_font_size ) / ( $maxWidth - $min_width );			
	$y_axis_intersection = -$min_width * $slope + $min_font_size;
	$slope = $slope * 100;

	return "clamp( {$min_font_size}rem, {$y_axis_intersection}rem + {$slope}vw, {$max_font_size}rem )";
}

/**
 * Min. font size based on desktop size
 *
 * @param integer $font_size - base font size
 * @param integer $min_size - minimal value of the font size in px.
 * @param float $scale - scaled value of the font size
 * @return integer - scaled (minimal) font size
 */
function sunset_clamp_min_font_size($font_size, $min_size = 10, $scale = 0.6) {
	$font_size = floatval($font_size * $scale);
	$font_size = $font_size >= $min_size ? $font_size : $min_size;
	return $font_size;
}

/**
 * Max. font size based on desktop size
 *
 * @param integer $font_size - base font size
 * @param float $scale - scaled value of the font size
 * @return integer - scaled (max) font size
 */
function sunset_clamp_max_font_size($font_size, $scale = 1.3) {
	$font_size = floatval($font_size * $scale);
	return $font_size;
}


add_filter('nav_menu_link_attributes', 'sunset_add_data_content_attr', 10, 3);
/**
 * Add data-content and tabindex attributes to menu items links (for shadowed hover)
 */
function sunset_add_data_content_attr($atts, $item, $args) {
	$atts['data-content'] = $item->title;

	if( strrpos($args->menu_class, 'main-nav-menu--mobile') !== false ) {
		$atts['tabindex'] = "-1";
	}

    return $atts;
}

add_action('wp_head', 'sunset_add_noscript', 10);
/**
 * Add a noscript notice to <head> for admins
 */
function sunset_add_noscript(){
	$noscript = '<noscript>';
	$noscript .= '<p style="margin: 0;padding: 1em;text-align: center;">'.__("Please enable Javascript or this site will look kinda broken.", 'my-sunset').'&nbsp;😅</p>';
	$noscript .= '</noscript>';
	$noscript .= '<script>document.documentElement.className = "js";
	var supportsCssVars = function() { var e, t = document.createElement("style"); return t.innerHTML = "root: { --tmp-var: bold; }", document.head.appendChild(t), e = !!(window.CSS && window.CSS.supports && window.CSS.supports("font-weight", "var(--tmp-var)")), t.parentNode.removeChild(t), e };
	supportsCssVars() || alert("Please view this in a modern browser that supports CSS Variables.");</script>';
	echo $noscript;
}

/**
 * Convert string to anchor
 * 
 * @param string - string to be converted
 * @return string snake_cased string
 */
function sunset_str_to_anchor($str) {
	$snake_case_str = str_replace( " ", "_", trim($str));
	return preg_replace('/[^A-Za-z0-9-._\/]/', '', $snake_case_str);
}

add_filter( 'pre_http_request', 'sunset_pre_http_request_block_editor_customizer_styles', 10, 3 );
/**
 * Hack for using inline CSS for Gutenberg editor styles
 * @see https://github.com/WordPress/gutenberg/issues/18571#issuecomment-618932161
 */
function sunset_pre_http_request_block_editor_customizer_styles( $response, $parsed_args, $url ) {
	if ( strpos($url, 'admin-inline.css') !== false ) {

		$response = array(
			'body'     => sunset_inline_styles(), // E.g. 'body { background-color: #fbca04; }'
			'headers'  => new Requests_Utility_CaseInsensitiveDictionary(),
			'response' => array(
				'code'    => 200,
				'message' => 'OK',
			),
			'cookies'  => array(),
			'filename' => null,
		);
	}

	return $response;
}

/**
 * Get SVG code for specific $icon
 * 
 * @param string $icon
 * @return string
 */
function sunset_get_svg_icon($icon) {
	$svg = '';

	switch ($icon) {
		case 'search':
			$svg = '<svg data-icon="search" xmlns="http://www.w3.org/2000/svg" width="512.000000pt" height="512.000000pt" viewBox="0 0 512.000000 512.000000" preserveAspectRatio="xMidYMid meet"> <g transform="translate(0.000000,512.000000) scale(0.100000,-0.100000)" fill="#000000" stroke="none"> <path d="M1780 5104 c-917 -110 -1657 -855 -1764 -1775 -109 -932 438 -1816 1323 -2139 667 -244 1442 -108 1977 347 28 23 55 43 60 43 5 0 362 -353 794 -784 684 -684 790 -785 821 -791 74 -14 138 50 124 124 -6 31 -107 137 -791 821 -431 432 -784 789 -784 794 0 5 20 32 43 60 150 176 280 407 359 636 249 729 63 1534 -481 2079 -448 448 -1057 660 -1681 585z m515 -220 c656 -97 1203 -545 1436 -1177 71 -193 103 -381 103 -612 1 -233 -30 -414 -108 -628 -176 -487 -586 -897 -1073 -1073 -214 -78 -395 -109 -628 -108 -290 0 -511 49 -775 171 -296 137 -588 398 -759 676 -185 303 -272 608 -272 957 -1 357 86 663 273 964 138 223 352 436 575 575 372 231 797 319 1228 255z"/> </g> </svg>';
			break;
		case 'close':
			$svg = '<svg data-icon="times" xmlns="http://www.w3.org/2000/svg" width="56" height="55" viewBox="0 0 56 55" fill="none"> <line x1="3.76777" y1="2.23223" x2="53.2652" y2="51.7297" stroke="black" stroke-width="3"></line> <line x1="1.98223" y1="52.4784" x2="51.4797" y2="2.98098" stroke="black" stroke-width="3"></line> </svg>';
			break;
		default:
			$svg = '';
	}

	return apply_filters('sunset_svg_'.$icon.'_icon', $svg, $icon);
}

/**
 * Remove <br> from WPCF7
 */
add_filter( 'wpcf7_autop_or_not', '__return_false' );

add_filter( 'ocdi/register_plugins', 'sunset_ocdi_register_plugins' );
/**
 * List of plugins for Demo Import Plugin
 * @see https://ocdi.com/quick-integration-guide/
 */
function sunset_ocdi_register_plugins( $plugins ) {
	$theme_plugins = [
		[
			'name'     => 'Sunset Core',
			'slug'     => 'sunset-core', // The slug has to match the extracted folder from the zip.
			'source'   => get_template_directory_uri() . '/plugins/sunset-core.zip',
			'required' => false,
		],
		[ // A WordPress.org plugin repository example.
			'name'     => 'Contact Form 7', // Name of the plugin.
			'slug'     => 'contact-form-7', // Plugin slug - the same as on WordPress.org plugin repository.
			'required' => false, // If the plugin is required or not.
		],
		[
			'name'     => 'Yoast SEO',
			'slug'     => 'wordpress-seo',
			'required' => false,
		],
		[
			'name'     => 'WPZOOM Social Feed Widget & Block',
			'slug'     => 'instagram-widget-by-wpzoom',
			'required' => false,
		],
		
	];
   
	return array_merge( $plugins, $theme_plugins );
}

add_filter( 'ocdi/import_files', 'sunset_ocdi_import_files' );
/**
 * List of files with demo content for Demo Import Plugin
 * @see https://ocdi.com/quick-integration-guide/
 */
function sunset_ocdi_import_files() {
	return [
		[
			'import_file_name'           => 'Demo Minimal',
			'import_file_url'            => 'https://sunset.bogdan.kyiv.ua/minimal/wp-content/uploads/demo_data/sunset-content-minimal.xml',
			'import_widget_file_url'     => 'https://sunset.bogdan.kyiv.ua/minimal/wp-content/uploads/demo_data/sunset-widgets-minimal.wie',
			'import_customizer_file_url' => 'https://sunset.bogdan.kyiv.ua/minimal/wp-content/uploads/demo_data/sunset-customizer-minimal.dat',
			'import_preview_image_url'   => 'https://sunset.bogdan.kyiv.ua/minimal/wp-content/uploads/demo_data/demo-minimal.jpg',
			'preview_url'                => 'https://sunset.bogdan.kyiv.ua/minimal/',
		],
		[
			'import_file_name'           => 'Demo Bold',
			'import_file_url'            => 'https://sunset.bogdan.kyiv.ua/minimal/wp-content/uploads/demo_data/sunset-content-bold.xml',
			'import_widget_file_url'     => 'https://sunset.bogdan.kyiv.ua/minimal/wp-content/uploads/demo_data/sunset-widgets-bold.wie',
			'import_customizer_file_url' => 'https://sunset.bogdan.kyiv.ua/minimal/wp-content/uploads/demo_data/sunset-customizer-bold.dat',
			'import_preview_image_url'   => 'https://sunset.bogdan.kyiv.ua/minimal/wp-content/uploads/demo_data/demo-bold.jpg',
			'preview_url'                => 'https://sunset.bogdan.kyiv.ua/bold/',
		]
	];
}

add_filter( 'cei_export_option_keys', 'sunset_export_option_keys' );
/**
 * Add custom customizer options for import/export
 */
function sunset_export_option_keys( $keys ) {
    $keys[] = 'sunset_layout_width';
	$keys[] = 'sunset_preloader_enable';
	$keys[] = 'sunset_topbar_enable';
	$keys[] = 'sunset_topbar_full_width';
	$keys[] = 'sunset_topbar_runline';
	$keys[] = 'sunset_topbar_runline_duration';
	$keys[] = 'sunset_topbar_sticky';
	$keys[] = 'sunset_topbar_align';
	$keys[] = 'sunset_topbar_add_border';
	$keys[] = 'sunset_topbar_border_height';
	$keys[] = 'sunset_topbar_content';
	$keys[] = 'sunset_topbar_background_color';
	$keys[] = 'sunset_topbar_color';
	$keys[] = 'sunset_topbar_border_color';
	$keys[] = 'sunset_topbar_font';
	$keys[] = 'sunset_topbar_mobile_hide';
	$keys[] = 'sunset_header_type';
	$keys[] = 'sunset_header_add_search';
	$keys[] = 'sunset_header_fixed';
	$keys[] = 'sunset_header_fixed_type';
	$keys[] = 'sunset_header_full_width';
	$keys[] = 'sunset_header_add_social';
	$keys[] = 'sunset_header_add_shadow';
	$keys[] = 'sunset_header_add_border';
	$keys[] = 'sunset_header_border_height';
	$keys[] = 'sunset_header_menu_hover_type';
	$keys[] = 'sunset_header_background_color';
	$keys[] = 'sunset_header_border_color';
	$keys[] = 'sunset_header_menu_color';
	$keys[] = 'sunset_header_menu_hover_color';
	$keys[] = 'sunset_header_menu_hover_bg_color';
	$keys[] = 'sunset_header_menu_hover_border_color';
	$keys[] = 'sunset_header_mobile_menu_background';
	$keys[] = 'sunset_header_mobile_menu_color';
	$keys[] = 'sunset_header_mobile_menu_hover_color';
	$keys[] = 'sunset_header_dynamic_font_size';
	$keys[] = 'sunset_menu_font';
	$keys[] = 'sunset_menu_mobile_font';
	$keys[] = 'sunset_header_auto_responsive';
	$keys[] = 'sunset_header_mobile_breakpoint';
	$keys[] = 'sunset_header_mobile_sticky_disable';
	$keys[] = 'sunset_header_burger_icon_type';
	$keys[] = 'sunset_header_burger_icon_text';
	$keys[] = 'sunset_header_menu_mobile_hover_type';
	$keys[] = 'sunset_header_menu_mobile_align_x';
	$keys[] = 'sunset_logo_dark_mode';
	$keys[] = 'sunset_logo_width';
	$keys[] = 'sunset_footer_type';
	$keys[] = 'sunset_footer_columns';
	$keys[] = 'sunset_footer_full_width';
	$keys[] = 'sunset_footer_add_border';
	$keys[] = 'sunset_footer_border_height';
	$keys[] = 'sunset_footer_color';
	$keys[] = 'sunset_footer_widget_title_color';
	$keys[] = 'sunset_footer_background_color';
	$keys[] = 'sunset_footer_border_color';
	$keys[] = 'sunset_footer_dynamic_font_size';
	$keys[] = 'sunset_footer_font';
	$keys[] = 'sunset_footer_widget_title_font';
	$keys[] = 'sunset_footer_mobile_font_size';
	$keys[] = 'sunset_footer_widget_mobile_font_size';
	$keys[] = 'sunset_copyright_enable';
	$keys[] = 'sunset_copyright_full_width';
	$keys[] = 'sunset_copyright_align';
	$keys[] = 'sunset_copyright_runline';
	$keys[] = 'sunset_copyright_runline_duration';
	$keys[] = 'sunset_copyright_add_border';
	$keys[] = 'sunset_copyright_border_height';
	$keys[] = 'sunset_copyright_color';
	$keys[] = 'sunset_copyright_background_color';
	$keys[] = 'sunset_copyright_border_color';
	$keys[] = 'sunset_copyright_font';
	$keys[] = 'sunset_copyright_mobile_align';
	$keys[] = 'sunset_social_links';
	$keys[] = 'sunset_layout_type';
	$keys[] = 'sunset_page_header_type';
	$keys[] = 'sunset_page_stroke_title';
	$keys[] = 'sunset_page_hide_title';
	$keys[] = 'sunset_page_hide_paddings';
	$keys[] = 'sunset_page_show_breadcrumbs';
	$keys[] = 'sunset_page_header_animation_type';
	$keys[] = 'sunset_blog_layout_type';
	$keys[] = 'sunset_blog_grid_type';
	$keys[] = 'sunset_blog_grid_columns';
	$keys[] = 'sunset_blog_add_border';
	$keys[] = 'sunset_blog_add_shadow';
	$keys[] = 'sunset_blog_show_tags';
	$keys[] = 'sunset_blog_show_categories';
	$keys[] = 'sunset_blog_show_default_category';
	$keys[] = 'sunset_blog_show_excerpt';
	$keys[] = 'sunset_blog_show_date';
	$keys[] = 'sunset_blog_show_read_time';
	$keys[] = 'sunset_layout_default_image';
	$keys[] = 'sunset_blog_title_type';
	$keys[] = 'sunset_blog_title_show_posts_count';
	$keys[] = 'sunset_blog_title_show_breadcrumbs';
	$keys[] = 'sunset_blog_sidebar_position';
	$keys[] = 'sunset_blog_sidebar_sticky';
	$keys[] = 'sunset_blog_sidebar_sticky_position';
	$keys[] = 'sunset_blog_pagination';
	$keys[] = 'sunset_blog_image_ratio';
	$keys[] = 'sunset_post_layout_type';
	$keys[] = 'sunset_post_content_width';
	$keys[] = 'sunset_post_sidebar_position';
	$keys[] = 'sunset_post_sidebar_sticky';
	$keys[] = 'sunset_post_sidebar_sticky_position';
	$keys[] = 'sunset_post_show_breadcrumbs';
	$keys[] = 'sunset_post_toc_enable';
	$keys[] = 'sunset_post_toc_tags';
	$keys[] = 'sunset_post_show_date';
	$keys[] = 'sunset_post_show_read_time';
	$keys[] = 'sunset_post_meta_show';
	$keys[] = 'sunset_post_meta_position';
	$keys[] = 'sunset_post_show_default_category';
	$keys[] = 'sunset_post_header_type';
	$keys[] = 'sunset_post_header_animation_type';
	$keys[] = 'sunset_post_stroke_title';
	$keys[] = 'sunset_post_related_show';
	$keys[] = 'sunset_post_related_type';
	$keys[] = 'sunset_post_related_number';
	$keys[] = 'sunset_post_related_columns';
	$keys[] = 'sunset_post_related_title_show';
	$keys[] = 'sunset_post_related_title_text';
	$keys[] = 'sunset_style_select2_enable';
	$keys[] = 'sunset_style_custom_checkbox_enable';
	$keys[] = 'sunset_style_lightbox_enable';
	$keys[] = 'sunset_style_bg_noise_enable';
	$keys[] = 'sunset_style_custom_cursor_enable';
	$keys[] = 'sunset_style_custom_cursor_style';
	$keys[] = 'sunset_style_input_style';
	$keys[] = 'sunset_content_bg_color';
	$keys[] = 'sunset_content_sidebars_bg_color';
	$keys[] = 'sunset_content_primary_color';
	$keys[] = 'sunset_content_secondary_color';
	$keys[] = 'sunset_content_link_color';
	$keys[] = 'sunset_content_link_hover_color';
	$keys[] = 'sunset_content_h1_color';
	$keys[] = 'sunset_content_h2_color';
	$keys[] = 'sunset_content_h3_color';
	$keys[] = 'sunset_content_h4_color';
	$keys[] = 'sunset_content_h5_color';
	$keys[] = 'sunset_content_h6_color';
	$keys[] = 'sunset_content_widget_title_color';
	$keys[] = 'sunset_buttons_color';
	$keys[] = 'sunset_buttons_hover_color';
	$keys[] = 'sunset_buttons_text_color';
	$keys[] = 'sunset_buttons_hover_text_color';
	$keys[] = 'sunset_buttons_border_color';
	$keys[] = 'sunset_inputs_color';
	$keys[] = 'sunset_inputs_text_color';
	$keys[] = 'sunset_inputs_border_color';
	$keys[] = 'sunset_content_dynamic_font_size';
	$keys[] = 'sunset_primary_font';
	$keys[] = 'sunset_h1_font';
	$keys[] = 'sunset_h2_font';
	$keys[] = 'sunset_h3_font';
	$keys[] = 'sunset_h4_font';
	$keys[] = 'sunset_h5_font';
	$keys[] = 'sunset_h6_font';
	$keys[] = 'sunset_widget_title_font';
	$keys[] = 'sunset_content_mobile_font_size';
	$keys[] = 'sunset_h1_mobile_font_size';
	$keys[] = 'sunset_h2_mobile_font_size';
	$keys[] = 'sunset_h3_mobile_font_size';
	$keys[] = 'sunset_h4_mobile_font_size';
	$keys[] = 'sunset_h5_mobile_font_size';
	$keys[] = 'sunset_h6_mobile_font_size';
	$keys[] = 'sunset_widget_title_mobile_font_size';
	
    return $keys;
}