<?php 

/**
 * Swipper Lib
*/
if(!function_exists('solarva_elements_scripts')){
    add_action( 'wp_enqueue_scripts', 'solarva_elements_scripts');
    function solarva_elements_scripts() {  
        $theme = wp_get_theme( get_template() );
        wp_register_script( 'gsap', get_template_directory_uri() . '/assets/js/libs/gsap.min.js', array( 'jquery' ), '3.5.0', true );
        wp_register_script( 'pxl-scroll-trigger', get_template_directory_uri() . '/assets/js/libs/scroll-trigger.js', array( 'jquery' ), '3.10.5', true );
        wp_register_script( 'pxl-splitText', get_template_directory_uri() . '/assets/js/libs/split-text.js', array( 'jquery' ), '3.6.1', true );
        wp_register_script( 'pxl-bundled-lenis', get_template_directory_uri() . '/assets/js/libs/bundled-lenis.min.js', array( 'jquery' ), '1.0.0', true );
        wp_register_script( 'pxl-nice-scroll', get_template_directory_uri() . '/assets/js/libs/nice-scroll.min.js', array( 'jquery' ), '3.7.6', true );

        wp_register_script('solarva-particle', get_template_directory_uri() . '/elements/assets/js/particle.js', [ 'jquery' ], $theme->get( 'Version' ), true);
        wp_register_script('solarva-parallax', get_template_directory_uri() . '/elements/assets/js/parallax.js', [ 'jquery' ], $theme->get( 'Version' ), true);
        wp_register_script('pxl-post-grid', get_template_directory_uri() . '/elements/assets/js/grid.js', [ 'isotope', 'jquery' ], $theme->get( 'Version' ), true);
        wp_localize_script('pxl-post-grid', 'main_data', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'wpnonce' => wp_create_nonce( '_ajax_nonce' ) ) );
        wp_register_script('pxl-swiper', get_template_directory_uri() . '/elements/assets/js/carousel.js', [ 'jquery' ], $theme->get( 'Version' ), true);
        wp_register_script('pxl-slick', get_template_directory_uri() . '/elements/assets/js/slick.js', [ 'jquery' ], $theme->get( 'Version' ), true);
        wp_register_script('solarva-counter', get_template_directory_uri() . '/elements/assets/js/counter.js', [ 'jquery' ], $theme->get( 'Version' ), true);
        wp_register_script('solarva-accordion', get_template_directory_uri() . '/elements/assets/js/accordion.js', [ 'jquery' ], $theme->get( 'Version' ), true);
        wp_register_script('solarva-tabs', get_template_directory_uri() . '/elements/assets/js/tabs.js', [ 'jquery' ], $theme->get( 'Version' ), true);
        wp_register_script('solarva-progressbar', get_template_directory_uri() . '/elements/assets/js/progressbar.js', [ 'jquery' ], $theme->get( 'Version' ), true);
        wp_register_script('solarva-countdown', get_template_directory_uri() . '/elements/assets/js/countdown.js', [ 'jquery' ], $theme->get( 'Version' ), true);
        wp_register_script('pxl-pie-chart', get_template_directory_uri() . '/assets/js/libs/pie-chart.min.js', [ 'jquery' ], $theme->get( 'Version' ), true);
        wp_register_script('solarva-pie-chart', get_template_directory_uri() . '/elements/assets/js/pie-chart.js', [ 'jquery' ], $theme->get( 'Version' ), true);
        wp_enqueue_script('solarva-elementor', get_template_directory_uri() . '/elements/assets/js/elementor.js', [ 'jquery' ], $theme->get( 'Version' ), true);

        wp_register_script('solarva-circular-text', get_template_directory_uri() . '/elements/assets/js/circular-text.js', [ 'jquery' ], $theme->get( 'Version' ), true);

    }
}

/**
 * Extra Elementor Icons
*/
if(!function_exists('solarva_register_custom_icon_library')){
    add_filter('elementor/icons_manager/native', 'solarva_register_custom_icon_library');
    function solarva_register_custom_icon_library($tabs){
        $custom_tabs = [
            'pxl_icon1' => [
                'name' => 'flaticon',
                'label' => esc_html__( 'Solarva', 'solarva' ),
                'url' => false,
                'enqueue' => false,
                'prefix' => 'flaticon-',
                'displayPrefix' => 'flaticon',
                'labelIcon' => 'flaticon-it',
                'ver' => '1.0.0',
                'fetchJson' => get_template_directory_uri() . '/assets/fonts/flaticon/flaticon-08.js',
                'native' => true,
            ],

        ];
        $tabs = array_merge($custom_tabs, $tabs);
        return $tabs;
    }
}
 
/**
 * Get class widget path
*/
if(!function_exists('solarva_get_class_widget_path')){
    function solarva_get_class_widget_path(){
        $upload_dir = wp_upload_dir();
        $cls_path = $upload_dir['basedir'].'/elementor-widget/';
        if(!is_dir($cls_path)) {
            wp_mkdir_p( $cls_path );
        }
        return $cls_path;
    }
}

/**
 * Get post type options
*/
function solarva_get_post_type_options($pt_supports=[]){
    $post_types = get_post_types([
        'public'   => true,
    ], 'objects');
    $excluded_post_type = [
        'page',
        'attachment',
        'revision',
        'nav_menu_item',
        'custom_css',
        'customize_changeset',
        'oembed_cache',
        'e-landing-page',
        'header',
        'footer',
        'mega-menu',
        'elementor_library'
    ];

    $result_some = [];
    $result_any = [];
    if (!is_array($post_types))
        return $result;
    foreach ($post_types as $post_type) {
        if (!$post_type instanceof WP_Post_Type)
            continue;
        if (in_array($post_type->name, $excluded_post_type))
            continue;

        if(!empty($pt_supports) && in_array($post_type->name, $pt_supports)){
            $result_some[$post_type->name] = $post_type->labels->singular_name;
        }else{
            $result_any[$post_type->name] = $post_type->labels->singular_name;
        }
    }

    if(!empty($pt_supports))
        return $result_some;
    else   
        return $result_any;
}

if (!function_exists('solarva_carousel_settings')) {
    function solarva_carousel_settings($condition = []) {
        $options = [
            array(
                'name' => 'carousel_options',
                'label' => esc_html__('NORMAL', 'solarva'),
                'type' => \Elementor\Controls_Manager::HEADING,
                'separator' => 'after', 
            ),
            array(
                'name' => 'pause_on_hover',
                'label' => esc_html__('Pause on Hover', 'solarva'),
                'type' => \Elementor\Controls_Manager::SWITCHER,
                'default' => '',
            ),
            array(
                'name' => 'autoplay',
                'label' => esc_html__('Autoplay', 'solarva'),
                'type' => \Elementor\Controls_Manager::SWITCHER,
                'default' => '',
            ),
            array(
                'name' => 'autoplay_speed',
                'label' => esc_html__('Autoplay Delay', 'solarva'),
                'type' => \Elementor\Controls_Manager::NUMBER,
                'condition' => [
                    'autoplay!' => ''
                ]
            ),
            array(
                'name' => 'slide_to_scroll',
                'label' => esc_html__('Slide To Scroll', 'solarva'),
                'type' => \Elementor\Controls_Manager::NUMBER,
            ),
            array(
                'name' => 'infinite',
                'label' => esc_html__('Infinite Loop', 'solarva'),
                'type' => \Elementor\Controls_Manager::SWITCHER,
                'default' => '',
            ),
            array(
                'name' => 'speed',
                'label' => esc_html__('Animation Speed', 'solarva'),
                'type' => \Elementor\Controls_Manager::NUMBER,
            ),
            array(
                'name' => 'divider2',
                'type' => \Elementor\Controls_Manager::DIVIDER,
            ),
            array(
                'name' => 'arrow_options',
                'label' => esc_html__('ARROW', 'solarva'),
                'type' => \Elementor\Controls_Manager::HEADING,
                'separator' => 'after', 
            ),
            array(
                'name' => 'arrows',
                'label' => esc_html__('Show Arrows', 'solarva'),
                'type' => \Elementor\Controls_Manager::SWITCHER,
                'default' => '',
            ),
            array(
                'name' => 'arrow_normal',
                'label' => esc_html__('Normal', 'solarva'),
                'type' => \Elementor\Controls_Manager::HEADING,
                'condition' => [
                    'arrows!' => '',
                ],
            ),
            array(
                'name' => 'arrow_color',
                'label' => esc_html__('Color', 'solarva' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pxl-swiper-slider .pxl-swiper-arrows .pxl-swiper-arrow' => 'color: {{VALUE}};',
                    '{{WRAPPER}} .pxl-swiper-slider .pxl-swiper-arrows .pxl-swiper-arrow svg path' => 'fill: {{VALUE}};',
                ],
                'condition' => [
                    'arrows!' => '',
                ],
            ),
            array(
                'name' => 'arrow_bg_color',
                'label' => esc_html__('Background Color', 'solarva' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pxl-swiper-slider .pxl-swiper-arrows .pxl-swiper-arrow' => 'background-color: {{VALUE}};',
                ],
                'condition' => [
                    'arrows!' => '',
                ],
            ),
            array(
                'name'         => 'arrow_border',
                'label' => esc_html__( 'Border', 'solarva' ),
                'type'         => \Elementor\Group_Control_Border::get_type(),
                'control_type' => 'group',
                'selector'     => '{{WRAPPER}} .pxl-swiper-slider .pxl-swiper-arrows .pxl-swiper-arrow',
                'condition' => [
                    'arrows!' => '',
                ],
            ),
            array(
                'name' => 'arrow_hover',
                'label' => esc_html__('Hover', 'solarva'),
                'type' => \Elementor\Controls_Manager::HEADING,
                'condition' => [
                    'arrows!' => '',
                ],
            ),
            array(
                'name' => 'arrow_hover_color',
                'label' => esc_html__('Color', 'solarva' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pxl-swiper-slider .pxl-swiper-arrows .pxl-swiper-arrow:hover' => 'color: {{VALUE}};',
                    '{{WRAPPER}} .pxl-swiper-slider .pxl-swiper-arrows .pxl-swiper-arrow:hover svg path' => 'fill: {{VALUE}};',
                ],
                'condition' => [
                    'arrows!' => '',
                ],
            ),
            array(
                'name' => 'arrow_hover_bg_color',
                'label' => esc_html__('Background Color', 'solarva' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pxl-swiper-slider .pxl-swiper-arrows .pxl-swiper-arrow:hover' => 'background-color: {{VALUE}};',
                ],
                'condition' => [
                    'arrows!' => '',
                ],
            ),
            array(
                'name'         => 'arrow_hover_border',
                'label'        => esc_html__( 'Border', 'solarva' ),
                'type'         => \Elementor\Group_Control_Border::get_type(),
                'control_type' => 'group',
                'selector'     => '{{WRAPPER}} .pxl-swiper-slider .pxl-swiper-arrows .pxl-swiper-arrow:hover',
                'condition' => [
                    'arrows!' => '',
                ],
            ),
            array(
                'name' => 'divider4',
                'type' => \Elementor\Controls_Manager::DIVIDER,
            ),
            array(
                'name' => 'pagination_carousel_options',
                'label' => esc_html__('PAGINATION', 'solarva'),
                'type' => \Elementor\Controls_Manager::HEADING,
                'separator' => 'after', 
            ),
            array(
                'name' => 'pagination',
                'label' => esc_html__('Show Pagination', 'solarva'),
                'type' => \Elementor\Controls_Manager::SWITCHER,
                'default' => '',
            ),
            array(
                'name' => 'pagination_carousel_type',
                'label' => esc_html__('Pagination Type', 'solarva' ),
                'type' => \Elementor\Controls_Manager::SELECT,
                'default' => 'bullets',
                'options' => [
                    'bullets' => 'Bullets',
                    'progressbar' => 'Progressbar',
                ],
                'condition' => [
                    'pagination!' => ''
                ]
            ),
        ];

        return [
            'name' => 'tab_carousel',
            'label' => esc_html__('Carousel', 'solarva'),
            'tab' => \Elementor\Controls_Manager::TAB_SETTINGS,
            'controls' => $options,
            'condition' => $condition,
        ];
    }
}

// Custom Ceatran
if(!function_exists('solarva_grid_settings')) {
    function solarva_grid_settings($pagination = true, $condition = []) {
        $pagination = filter_var($pagination, FILTER_VALIDATE_BOOLEAN);
        $options = [
            array(
                'name' => 'grid_options',
                'label' => esc_html__('GRID', 'solarva' ),
                'type' => \Elementor\Controls_Manager::HEADING,
                'separator' => 'after',
            ),
            array(
                'name' => 'col_xs',
                'label' => esc_html__('Columns: Screen < 576px', 'solarva' ),
                'type' => \Elementor\Controls_Manager::SELECT,
                'default' => '1',
                'options' => [
                    '1' => '1',
                    '2' => '2',
                    '3' => '3',
                    '4' => '4',
                    '6' => '6',
                ],
            ),
            array(
                'name' => 'col_sm',
                'label' => esc_html__('Columns: Screen ≥ 576px', 'solarva' ),
                'type' => \Elementor\Controls_Manager::SELECT,
                'default' => '2',
                'options' => [
                    '1' => '1',
                    '2' => '2',
                    '3' => '3',
                    '4' => '4',
                    '6' => '6',
                ],
            ),
            array(
                'name' => 'col_md',
                'label' => esc_html__('Columns: Screen ≥ 768px', 'solarva' ),
                'type' => \Elementor\Controls_Manager::SELECT,
                'default' => '2',
                'options' => [
                    '1' => '1',
                    '2' => '2',
                    '3' => '3',
                    '4' => '4',
                    '6' => '6',
                ],
            ),
            array(
                'name' => 'col_lg',
                'label' => esc_html__('Columns: Screen ≥ 992px', 'solarva' ),
                'type' => \Elementor\Controls_Manager::SELECT,
                'default' => '3',
                'options' => [
                    '1' => '1',
                    '2' => '2',
                    '3' => '3',
                    '4' => '4',
                    '6' => '6',
                ],
            ),
            array(
                'name' => 'col_xl',
                'label' => esc_html__('Columns: Screen ≥ 1200px', 'solarva' ),
                'type' => \Elementor\Controls_Manager::SELECT,
                'default' => '3',
                'options' => [
                    '1' => '1',
                    '2' => '2',
                    '3' => '3',
                    '4' => '4',
                    '5' => '5',
                    '6' => '6',
                ],
            ),
            array(
                'name' => 'col_xxl',
                'label' => esc_html__('Columns: Screen ≥ 1400px', 'solarva' ),
                'type' => \Elementor\Controls_Manager::SELECT,
                'default' => '3',
                'options' => [
                    '1' => '1',
                    '2' => '2',
                    '3' => '3',
                    '4' => '4',
                    '5' => '5',
                    '6' => '6',
                ],
            ),
        ];
    
        if ($pagination) {
            $pagination_options = [
                array(
                    'name' => 'divider1',
                    'type' => \Elementor\Controls_Manager::DIVIDER,
                ),
                array(
                    'name' => 'pagination_grid_options',
                    'label' => esc_html__('PAGINATION', 'solarva' ),
                    'type' => \Elementor\Controls_Manager::HEADING,
                    'separator' => 'after',
                ),
                array(
                    'name' => 'pagination_type',
                    'label' => esc_html__('Pagination Type', 'solarva' ),
                    'type' => \Elementor\Controls_Manager::SELECT,
                    'default' => 'false',
                    'options' => [
                        'pagination' => esc_html__('Pagination', 'solarva' ),
                        'loadmore' => esc_html__('Loadmore', 'solarva' ),
                        'false' => esc_html__('Disable', 'solarva' ),
                    ],
                ),
            ];    
            $options = array_merge($options, $pagination_options);
        }

        return [
            'name' => 'tab_grid',
            'label' => esc_html__('Grid', 'solarva' ),
            'tab' => \Elementor\Controls_Manager::TAB_SETTINGS,
            'controls' => $options,
            'condition' => $condition,
        ];
    }
}

function solarva_swiper_controls($pagination = false, $arrows = false) {
    if(!$pagination && !$arrows) return;
    if ($pagination): ?>
        <div class="pxl-swiper-dots-wrap">
            <div class="pxl-swiper-dots pxl-swiper-dots1"></div>
        </div>
    <?php endif; ?>
    <?php if ($arrows): ?>
        <div class="pxl-swiper-arrow-wrap">
            <div class="pxl-swiper-arrows pxl-swiper-arrows1">
                <div class="pxl-swiper-arrow pxl-swiper-arrow-prev">
                    <svg xmlns="http://www.w3.org/2000/svg" width="10" height="18" viewBox="0 0 10 18" fill="none">
                        <path d="M1.61719 7.96875L0.585938 9L8.83594 17.25L9.86719 16.2187L2.64844 9L9.86719 1.78125L8.83594 0.749998L4.71094 4.875L1.61719 7.96875Z" fill="#003973"/>
                    </svg>
                </div>
                <div class="pxl-swiper-arrow pxl-swiper-arrow-next">
                    <svg xmlns="http://www.w3.org/2000/svg" width="10" height="18" viewBox="0 0 10 18" fill="none">
                        <path d="M8.38281 10.0312L9.41406 9L1.07812 0.749998L0.046875 1.78125L7.26562 9L0.046875 16.2187L1.07812 17.25L5.28906 13.125L8.38281 10.0312Z" fill="#003973"/>
                    </svg>
                </div>
            </div>
        </div>
    <?php endif; 
}

function solarva_get_sidebar() {
    global $wp_registered_sidebars;
    $options = [];
    $args = [];
    if ( !$wp_registered_sidebars ) {
        $options[''] = esc_html__( 'No sidebars were found', 'solarva' );
    } else {
        $options[''] = esc_html__( 'Choose Sidebar', 'solarva' );
        foreach ( $wp_registered_sidebars as $sidebar_id => $sidebar ) {
            $options[ $sidebar_id ] = $sidebar['name'];
        }
    }
    $default_key = array_keys( $options );
    $default_key = array_shift( $default_key );
    $args = [
        'default' => $default_key,
        'options' => $options,
    ];
    return $args;
}

function solarva_get_thumbnail($image_id, $image_size = 'full' , $url = false, $class = '') {
    $url = filter_var($url, FILTER_VALIDATE_BOOLEAN);
    $image_size = empty($image_size) ? 'full' : (string)$image_size;
    $thumbnail = '';
    $thumbnail_url = '';
    if (!empty($image_id) && is_numeric($image_id) && wp_attachment_is_image($image_id)) {
        $image = pxl_get_image_by_size( array(
            'attach_id'  => $image_id,
            'thumb_size' => $image_size,
            'class' => (string)$class,
        ));
        $thumbnail    = $image['thumbnail'];
        $thumbnail_url = $image['url'];
    }
    if($url) {
        return $thumbnail_url;
    }
    return $thumbnail;
}


function solarva_get_link($link){
    $attrs = '';
    if(!empty($link['url'])) {
        $attrs = 'href="'.$link['url'].'"';
        if ($link['is_external']) {
            $attrs .= ' '.'target="_blank"';
        }
        if ($link['nofollow'] ) {
            $attrs .= ' '.'rel="nofollow"';
        }
        if($link['custom_attributes']) {
            $custom_attributes = explode(',', $link["custom_attributes"]);
            foreach($custom_attributes as $attr) {
                list($key, $value) = explode('|', $attr);
                $attrs .= ' '.$key.'="'.$value.'"';
            }
        }
    }
    return $attrs;
}

function solarva_render_icon($icon, $is_wrap = true, $tag = 'span', $class = "pxl-item--icon") {
    $is_wrap = filter_var($is_wrap, FILTER_VALIDATE_BOOLEAN);
    $tag = (string)$tag;
    $class = (string)$class;
    $openingTag = '<' . $tag . ' class="' . $class . '">';
    $closingTag = '</' . $tag . '>';

    if (empty($icon['value'])) {
        return '';
    }
    if ($is_wrap) {
        return pxl_print_html($openingTag) . \Elementor\Icons_Manager::render_icon($icon, ['aria-hidden' => 'true', 'class' => ''], 'i') . pxl_print_html($closingTag);
    } 
    return \Elementor\Icons_Manager::render_icon($icon, ['aria-hidden' => 'true', 'class' => ''], 'i');
}

function solarva_get_icon_service($post_id) {
    global $wp_filesystem;

    $icon_content = '';
    $icon_type = get_post_meta($post_id, 'service_icon_type', true);
    $icon_normal = get_post_meta($post_id, 'service_icon_font', '');
    $icon_image = get_post_meta($post_id, 'service_icon_img', true); 

    if (!empty($icon_normal) && $icon_type === 'icon') {
        $icon_normal = implode(' ', $icon_normal);
        $icon_content = '<i class="' . $icon_normal . '"></i>';
        return $icon_content;
    }

    if (!empty($icon_image) && $icon_type === 'image') {

        if((pathinfo($icon_image['url'], PATHINFO_EXTENSION) === 'svg')) {
            $icon_urls = explode('uploads', $icon_image['url']);
            $upload_dir = wp_upload_dir();
            $icon_path = $upload_dir['basedir']. $icon_urls[1] ;
            $icon_content = $wp_filesystem->get_contents( $icon_path );
        }else {
            $icon_content = solarva_get_thumbnail($icon_image['id']);
        }
    }
    return $icon_content;
}

function get_team_socials($post_id) {
    $social_names = ['pinterest', 'youtube', 'linkedin', 'instagram', 'twitter', 'facebook'];
    $socials = [];
    
    foreach($social_names as $social_name) {
        $social = 'social_' . $social_name;
        $social_link = 'link_social_' . $social_name;
        
        $socials[$social]['is_active'] = get_post_meta($post_id, $social, true);
        
        $socials[$social]['url'] = get_post_meta($post_id, $social_link, true);
        
        $socials[$social]['icon'] = 'caseicon-' . $social_name;
    }
    
    return $socials;
}


/**
 * Start Post Grid Functions
*/
function solarva_get_post_grid_layout($pt_supports = []){
    $post_types  = solarva_get_post_type_options($pt_supports); 
    $result = [];
    if (!is_array($post_types))
        return $result;
    foreach ($post_types as $name => $label) {
        $result[] = array(
            'name'     => 'layout_'.$name,
            'label'    => sprintf(esc_html__( 'Select Template of %s', 'solarva' ), $label),
            'type'     => 'layoutcontrol',
            'default' => 'post-1',
            'options'  => solarva_get_grid_layout_options($name),
            'prefix_class' => 'pxl-post-layout-',
            'condition' => [
                'post_type' => [$name]
            ]
        );
    }
    return $result;   
}

function solarva_get_grid_layout_options($post_type_name){
    $option_layouts = [];
    switch ($post_type_name) {
        case 'portfolio':
            $option_layouts = [
                'portfolio-1' => [
                    'label' => esc_html__( 'Layout 1', 'solarva' ),
                    'image' => get_template_directory_uri() . '/elements/assets/img/pxl_post_grid/portfolio1.jpg'
                ],
                'portfolio-2' => [
                    'label' => esc_html__( 'Layout 2', 'solarva' ),
                    'image' => get_template_directory_uri() . '/elements/assets/img/pxl_post_grid/portfolio2.jpg'
                ],
                'portfolio-3' => [
                    'label' => esc_html__( 'Layout 3', 'solarva' ),
                    'image' => get_template_directory_uri() . '/elements/assets/img/pxl_post_grid/portfolio3.jpg'
                ],
            ];
            break;

        case 'post':  
            $option_layouts = [
                'post-1' => [
                    'label' => esc_html__( 'Layout 1', 'solarva' ),
                    'image' => get_template_directory_uri() . '/elements/assets/img/pxl_post_grid/post1.jpg'
                ],
                'post-2' => [
                    'label' => esc_html__( 'Layout 2', 'solarva' ),
                    'image' => get_template_directory_uri() . '/elements/assets/img/pxl_post_grid/post2.jpg'
                ],
            ];
            break;

        case 'service':  
            $option_layouts = [
                'service-1' => [
                    'label' => esc_html__( 'Layout 1', 'solarva' ),
                    'image' => get_template_directory_uri() . '/elements/assets/img/pxl_post_grid/service1.jpg'
                ],
                'service-2' => [
                    'label' => esc_html__( 'Layout 2', 'solarva' ),
                    'image' => get_template_directory_uri() . '/elements/assets/img/pxl_post_grid/service2.jpg'
                ],
                'service-3' => [
                    'label' => esc_html__( 'Layout 3', 'solarva' ),
                    'image' => get_template_directory_uri() . '/elements/assets/img/pxl_post_grid/service3.jpg'
                ],
                'service-4' => [
                    'label' => esc_html__( 'Layout 4', 'solarva' ),
                    'image' => get_template_directory_uri() . '/elements/assets/img/pxl_post_grid/service6.jpg'
                ],
                'service-5' => [
                    'label' => esc_html__( 'Layout 5', 'solarva' ),
                    'image' => get_template_directory_uri() . '/elements/assets/img/pxl_post_grid/service4.jpg'
                ],
            ];
            break;

        case 'team':  
            $option_layouts = [
                'team-1' => [
                    'label' => esc_html__( 'Layout 1', 'solarva' ),
                    'image' => get_template_directory_uri() . '/elements/assets/img/pxl_post_grid/team1.jpg'
                ],
                'team-2' => [
                    'label' => esc_html__( 'Layout 2', 'solarva' ),
                    'image' => get_template_directory_uri() . '/elements/assets/img/pxl_post_grid/team2.jpg'
                ],
            ];
            break;

    }
    return $option_layouts;
}

function solarva_get_grid_term_by_post_type($pt_supports = [], $args=[]){
    $args = wp_parse_args($args, ['condition' => 'post_type', 'custom_condition' => []]); 
    $post_types  = solarva_get_post_type_options($pt_supports); 
    $result = [];
    if (!is_array($post_types))
        return $result;
    foreach ($post_types as $name => $label) {
         
        $taxonomy = get_object_taxonomies($name, 'names');
        
        if($name == 'post') $taxonomy = ['category'];

        $result[] = array(
            'name'     => 'source_'.$name,
            'label'    => sprintf(esc_html__( 'Select Term of %s', 'solarva' ), $label),
            'type'     => \Elementor\Controls_Manager::SELECT2,
            'multiple' => true,
            'options'  => pxl_get_grid_term_options($name,$taxonomy),
            'condition' => array_merge(
                [
                    $args['condition'] => [$name]
                ],
                $args['custom_condition']
            )
        );
    }

    return $result;
}

function solarva_get_grid_ids_by_post_type($pt_supports = [], $args = []){
    $args = wp_parse_args($args, ['condition' => 'post_type', 'custom_condition' => []]);
    $post_types = solarva_get_post_type_options($pt_supports);
    $result = [];
    if (!is_array($post_types))
        return $result;
    foreach ($post_types as $name => $label) {

        $posts = solarva_list_post($name, false);
 
        $result[] = array(
            'name' => 'source_' . $name . '_post_ids',
            'label' => sprintf(esc_html__('Select posts', 'solarva'), $label),
            'type'     => \Elementor\Controls_Manager::SELECT2,
            'multiple' => true,
            'options' => $posts,
            'condition' => array_merge(
                [
                    $args['condition'] => [$name]
                ],
                $args['custom_condition']
            )
        );
    }

    return $result;
}

/**
 * End Post Grid Functions
*/


/**
 * Start Post Carousel Functions
*/
function solarva_get_post_carousel_layout($pt_supports = []){
    $post_types  = solarva_get_post_type_options($pt_supports); 
    $result = [];
    if (!is_array($post_types))
        return $result;
    foreach ($post_types as $name => $label) {
        $result[] = array(
            'name'     => 'layout_'.$name,
            'label'    => sprintf(esc_html__( 'Select Template of %s', 'solarva' ), $label),
            'type'     => 'layoutcontrol',
            'default' => 'post-1',
            'options'  => solarva_get_carousel_layout_options($name),
            'prefix_class' => 'post-layout-',
            'condition' => [
                'post_type' => [$name]
            ]
        );
    }
    return $result;   
}

function solarva_get_carousel_layout_options($post_type_name){
    $option_layouts = [];
    switch ($post_type_name) {

        case 'service':
            $option_layouts = [
                'service-1' => [
                    'label' => esc_html__( 'Layout 1', 'solarva' ),
                    'image' => get_template_directory_uri() . '/elements/assets/img/pxl_post_grid/service1.jpg'
                ],
                'service-2' => [
                    'label' => esc_html__( 'Layout 2', 'solarva' ),
                    'image' => get_template_directory_uri() . '/elements/assets/img/pxl_post_grid/service2.jpg'
                ],
                'service-3' => [
                    'label' => esc_html__( 'Layout 3', 'solarva' ),
                    'image' => get_template_directory_uri() . '/elements/assets/img/pxl_post_grid/service3.jpg'
                ],
                'service-5' => [
                    'label' => esc_html__( 'Layout 4', 'solarva' ),
                    'image' => get_template_directory_uri() . '/elements/assets/img/pxl_post_grid/service4.jpg'
                ],
                'service-6' => [
                    'label' => esc_html__( 'Layout 5', 'solarva' ),
                    'image' => get_template_directory_uri() . '/elements/assets/img/pxl_post_grid/service5.jpg'
                ],
            ];
            break;

        case 'portfolio':
            $option_layouts = [
                'portfolio-1' => [
                    'label' => esc_html__( 'Layout 1', 'solarva' ),
                    'image' => get_template_directory_uri() . '/elements/assets/img/pxl_post_grid/portfolio4.jpg'
                ],
                'portfolio-3' => [
                    'label' => esc_html__( 'Layout 3', 'solarva' ),
                    'image' => get_template_directory_uri() . '/elements/assets/img/pxl_post_grid/portfolio3.jpg'
                ],
            ];
            break;

        case 'post':  
            $option_layouts = [
                'post-1' => [
                    'label' => esc_html__( 'Layout 1', 'solarva' ),
                    'image' => get_template_directory_uri() . '/elements/assets/img/pxl_post_grid/post1.jpg'
                ],
            ];
            break;
    }
    return $option_layouts;
}

function solarva_get_carousel_term_by_post_type($pt_supports = [], $args=[]){
    $args = wp_parse_args($args, ['condition' => 'post_type', 'custom_condition' => []]);
    $post_types  = solarva_get_post_type_options($pt_supports); 
    $result = [];
    if (!is_array($post_types))
        return $result;
    foreach ($post_types as $name => $label) {
         
        $taxonomy = get_object_taxonomies($name, 'names');
        
        if($name == 'post') $taxonomy = ['category'];

        $result[] = array(
            'name'     => 'source_'.$name,
            'label'    => sprintf(esc_html__( 'Select Term of %s', 'solarva' ), $label),
            'type'     => \Elementor\Controls_Manager::SELECT2,
            'multiple' => true,
            'options'  => pxl_get_grid_term_options($name,$taxonomy),
            'condition' => array_merge(
                [
                    $args['condition'] => [$name]
                ],
                $args['custom_condition']
            )
        );
    }

    return $result;
}

function solarva_render_post_grid($filter_grid_args = []) {
    extract($filter_grid_args);
    if ($select_post_by == 'term_selected' && $filter == "true"): ?>
        <div class="pxl-grid-filter <?php echo esc_attr($filter_type) ?>">
            <div class="pxl-filter-inner">
                <span class="filter-item active" data-filter="*"><?php echo esc_html($filter_default_title); ?></span>
                <?php foreach ($categories as $category): ?>
                    <?php 
                        $category_arr = explode('|', $category); 
                        $term = get_term_by('slug',$category_arr[0], $category_arr[1]); 
                    ?>
                    <span class="filter-item" data-filter="<?php echo esc_attr('.'.$term->slug); ?>">
                        <?php echo esc_html($term->name); ?>
                    </span>
                <?php endforeach; ?>
            </div>
        </div>
    <?php endif; ?>

    <div class="<?php echo esc_attr($grid_class); ?>" data-gutter="15">
        <?php solarva_get_post_grid($posts, $load_more); ?>
        <div class="grid-sizer <?php echo esc_attr($grid_sizer); ?>"></div>
    </div>
    <?php if ($pagination_type == 'pagination') : ?>
        <div class="pxl-grid-pagination">
            <?php solarva()->page->get_pagination($query, true); ?>
        </div>
    <?php endif; ?>
    <?php if (!empty($next_link) && $pagination_type == 'loadmore') : ?>
        <div class="pxl-load-more">
            <span class="btn btn-grid-loadmore">
                <span class="pxl-loadmore-text"><?php echo esc_html__('Load More', 'solarva') ?></span>
                <span class="pxl-load-icon"></span>
            </span>
        </div>
    <?php endif;
}


/**
 * End Post Carousel Functions
*/

/* Icon render */ 
function solarva_elementor_icon_render( $settings, $args = []){
    $args = wp_parse_args($args, [
        'prefix'     => '',   
        'id'         => 'selected_icon',
        'loop'       => false,
        'tag'        => 'div',   
        'wrap_class' => '',
        'class'      => '',
        'style'      => '',
        'before'     => '',
        'after'      => '',
        'atts'       => [],
        'animate_data' => '',
        'default_icon'    => [
            'value'   => '',
            'library' => ''
        ],
        'echo' => true
    ]);
    if($args['loop']) {
        $icon = $args['id'];
    } else {
        $icon = $settings[$args['id']];
    }
    if(empty($icon['value'])) $icon = $args['default_icon'];
    if (empty($icon['value'])) return;

    if ( 'svg' === $icon['library'] ){
        $args['before'] = '<span class="'.$args['wrap_class'].' '.$args['class'].'" data-settings="'. esc_attr($args['animate_data']).'">';
        $args['after']  = '</span>';
    }
    ob_start();
    printf('%s', $args['before']);
    ?>
    <?php \Elementor\Icons_Manager::render_icon( $icon, array_merge(
            [ 
                'aria-hidden' => 'true', 
                'class'       => trim(implode(' ', ['pxl-icon', $args['class'], $args['wrap_class']])),
                'style'       => $args['style']  
            ],
            $args['atts']
        ), $args['tag']); ?>
    <?php
    printf('%s', $args['after']);

    if($args['echo']){
        echo ob_get_clean();
    } else {
        return ob_get_clean();
    }
}

/**
 * Animation List
*/

function solarva_widget_animate() {
    $solarva_animate = array(
        '' => 'None',
        'wow bounce' => 'bounce',
        'wow flash' => 'flash',
        'wow pulse' => 'pulse',
        'wow rubberBand' => 'rubberBand',
        'wow shake' => 'shake',
        'wow swing' => 'swing',
        'wow tada' => 'tada',
        'wow wobble' => 'wobble',
        'wow bounceIn' => 'bounceIn',
        'wow bounceInDown' => 'bounceInDown',
        'wow bounceInLeft' => 'bounceInLeft',
        'wow bounceInRight' => 'bounceInRight',
        'wow bounceInUp' => 'bounceInUp',
        'wow bounceOut' => 'bounceOut',
        'wow bounceOutDown' => 'bounceOutDown',
        'wow bounceOutLeft' => 'bounceOutLeft',
        'wow bounceOutRight' => 'bounceOutRight',
        'wow bounceOutUp' => 'bounceOutUp',
        'wow fadeIn' => 'fadeIn',
        'wow fadeInDown' => 'fadeInDown',
        'wow fadeInDownBig' => 'fadeInDownBig',
        'wow fadeInLeft' => 'fadeInLeft',
        'wow fadeInLeftBig' => 'fadeInLeftBig',
        'wow fadeInRight' => 'fadeInRight',
        'wow fadeInRightBig' => 'fadeInRightBig',
        'wow fadeInUp' => 'fadeInUp',
        'wow fadeInUpBig' => 'fadeInUpBig',
        'wow fadeOut' => 'fadeOut',
        'wow fadeOutDown' => 'fadeOutDown',
        'wow fadeOutDownBig' => 'fadeOutDownBig',
        'wow fadeOutLeft' => 'fadeOutLeft',
        'wow fadeOutLeftBig' => 'fadeOutLeftBig',
        'wow fadeOutRight' => 'fadeOutRight',
        'wow fadeOutRightBig' => 'fadeOutRightBig',
        'wow fadeOutUp' => 'fadeOutUp',
        'wow fadeOutUpBig' => 'fadeOutUpBig',
        'wow flip' => 'flip',
        'wow flipCase' => 'flipCase',
        'wow flipInX' => 'flipInX',
        'wow flipInY' => 'flipInY',
        'wow flipOutX' => 'flipOutX',
        'wow flipOutY' => 'flipOutY',
        'wow lightSpeedIn' => 'lightSpeedIn',
        'wow lightSpeedOut' => 'lightSpeedOut',
        'wow rotateIn' => 'rotateIn',
        'wow rotateInDownLeft' => 'rotateInDownLeft',
        'wow rotateInDownRight' => 'rotateInDownRight',
        'wow rotateInUpLeft' => 'rotateInUpLeft',
        'wow rotateInUpRight' => 'rotateInUpRight',
        'wow rotateOut' => 'rotateOut',
        'wow rotateOutDownLeft' => 'rotateOutDownLeft',
        'wow rotateOutDownRight' => 'rotateOutDownRight',
        'wow rotateOutUpLeft' => 'rotateOutUpLeft',
        'wow rotateOutUpRight' => 'rotateOutUpRight',
        'wow hinge' => 'hinge',
        'wow rollIn' => 'rollIn',
        'wow rollOut' => 'rollOut',
        'wow zoomInSmall' => 'zoomInSmall',
        'wow zoomIn' => 'zoomInBig',
        'wow zoomOut' => 'zoomOut',
        'wow skewIn' => 'skewInLeft',
        'wow skewInRight' => 'skewInRight',
        'wow skewInBottom' => 'skewInBottom',
        'wow RotatingY' => 'RotatingY',
        'wow PXLfadeInUp' => 'PXLfadeInUp',
        'fadeInPopup' => 'fadeInPopup',
    );
    return $solarva_animate;
}

function solarva_widget_animate_v2() {
    $solarva_animate_v2 = array(
        '' => 'None',
        'wow bounce' => 'bounce',
        'wow flash' => 'flash',
        'wow pulse' => 'pulse',
        'wow rubberBand' => 'rubberBand',
        'wow shake' => 'shake',
        'wow swing' => 'swing',
        'wow tada' => 'tada',
        'wow wobble' => 'wobble',
        'wow bounceIn' => 'bounceIn',
        'wow bounceInDown' => 'bounceInDown',
        'wow bounceInLeft' => 'bounceInLeft',
        'wow bounceInRight' => 'bounceInRight',
        'wow bounceInUp' => 'bounceInUp',
        'wow bounceOut' => 'bounceOut',
        'wow bounceOutDown' => 'bounceOutDown',
        'wow bounceOutLeft' => 'bounceOutLeft',
        'wow bounceOutRight' => 'bounceOutRight',
        'wow bounceOutUp' => 'bounceOutUp',
        'wow fadeIn' => 'fadeIn',
        'wow fadeInDown' => 'fadeInDown',
        'wow fadeInDownBig' => 'fadeInDownBig',
        'wow fadeInLeft' => 'fadeInLeft',
        'wow fadeInLeftBig' => 'fadeInLeftBig',
        'wow fadeInRight' => 'fadeInRight',
        'wow fadeInRightBig' => 'fadeInRightBig',
        'wow fadeInUp' => 'fadeInUp',
        'wow fadeInUpBig' => 'fadeInUpBig',
        'wow fadeOut' => 'fadeOut',
        'wow fadeOutDown' => 'fadeOutDown',
        'wow fadeOutDownBig' => 'fadeOutDownBig',
        'wow fadeOutLeft' => 'fadeOutLeft',
        'wow fadeOutLeftBig' => 'fadeOutLeftBig',
        'wow fadeOutRight' => 'fadeOutRight',
        'wow fadeOutRightBig' => 'fadeOutRightBig',
        'wow fadeOutUp' => 'fadeOutUp',
        'wow fadeOutUpBig' => 'fadeOutUpBig',
        'wow flip' => 'flip',
        'wow flipCase' => 'flipCase',
        'wow flipInX' => 'flipInX',
        'wow flipInY' => 'flipInY',
        'wow flipOutX' => 'flipOutX',
        'wow flipOutY' => 'flipOutY',
        'wow lightSpeedIn' => 'lightSpeedIn',
        'wow lightSpeedOut' => 'lightSpeedOut',
        'wow rotateIn' => 'rotateIn',
        'wow rotateInDownLeft' => 'rotateInDownLeft',
        'wow rotateInDownRight' => 'rotateInDownRight',
        'wow rotateInUpLeft' => 'rotateInUpLeft',
        'wow rotateInUpRight' => 'rotateInUpRight',
        'wow rotateOut' => 'rotateOut',
        'wow rotateOutDownLeft' => 'rotateOutDownLeft',
        'wow rotateOutDownRight' => 'rotateOutDownRight',
        'wow rotateOutUpLeft' => 'rotateOutUpLeft',
        'wow rotateOutUpRight' => 'rotateOutUpRight',
        'wow hinge' => 'hinge',
        'wow rollIn' => 'rollIn',
        'wow rollOut' => 'rollOut',
        'wow zoomInSmall' => 'zoomInSmall',
        'wow zoomIn' => 'zoomInBig',
        'wow zoomOut' => 'zoomOut',
        'wow skewIn' => 'skewInLeft',
        'wow skewInRight' => 'skewInRight',
        'wow RotatingY' => 'RotatingY',
        'wow PXLfadeInUp' => 'PXLfadeInUp',
        'wow TextOutlineAnimation' => 'Text Outline Animation',
        'pxl-split-text split-in-fade' => 'Slip Text In Fade',
        'pxl-split-text split-in-right' => 'Slip Text In Right',
        'pxl-split-text split-in-left'  => 'Slip Text In Left',
        'pxl-split-text split-in-up'    => 'Slip Text In Up',
        'pxl-split-text split-in-down'  => 'Slip Text In Down',
        'pxl-split-text split-in-rotate'  => 'Slip Text In Rotate',
        'pxl-split-text split-in-scale'  => 'Slip Text In Scale',

    );
    return $solarva_animate_v2;
}

/**
 * Pagram Animation
*/
if(!function_exists('solarva_widget_animation_settings')){
    function solarva_widget_animation_settings($args = []){
        $args = wp_parse_args($args, [
            'tab'       => \Elementor\Controls_Manager::TAB_STYLE,
            'condition' => []
        ]);
        return array(
            'name'      => 'section_animation',
            'label'     => esc_html__('Animation', 'solarva'),
            'tab'       => $args['tab'],
            'condition' => $args['condition'],
            'controls'  => array_merge(
                array(
                    array(
                        'name' => 'pxl_animate',
                        'label' => esc_html__('Animate', 'solarva' ),
                        'type' => \Elementor\Controls_Manager::SELECT,
                        'options' => solarva_widget_animate(),
                        'default' => '',
                    ),
                    array(
                        'name' => 'pxl_animate_delay',
                        'label' => esc_html__('Delay', 'solarva' ),
                        'type' => \Elementor\Controls_Manager::TEXT,
                        'palceholder' => 'Ex: 1s or 1000ms',
                    ),
                )
            )
        );
    }
}

if(!function_exists('solarva_widget_color_type')){
    function solarva_widget_color_type($args = []){
        $gradient_prefix_class = 'pxl-';
        $gradient_return_value = 'gradient';
        $args = wp_parse_args($args, [
            'label' => '',
            'prefix' => '',
            'selectors_class' => '',
            'condition' => []
        ]);
        $options = array(
            array(
                'name' => $args['prefix'] .'_color_type',
                'label' => $args['label'] .' '.esc_html__('Color Type', 'solarva' ),
                'type' => \Elementor\Controls_Manager::SELECT,
                'options' => [
                    'normal' => 'Normal',
                    'gradient' => 'Gradient',
                ],
                'default' => 'normal',
            ),

            array(
                'name' => $args['prefix'] .'_normal_color',
                'label' => $args['label'] .' '.esc_html__('Normal Color', 'solarva' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} '.$args['selectors_class'] => 'color: {{VALUE}};',
                ],
                'condition' => [
                    $args['prefix'].'_color_type' => ['normal'],
                ],
            ),

            array(
                'name'        => $args['prefix'].'_gradient_color',
                'label' => $args['label'] .' '.esc_html__('Gradient Color', 'solarva' ),
                'type' => \Elementor\Controls_Manager::POPOVER_TOGGLE,
                'prefix_class' => $gradient_prefix_class,
                'return_value' => $gradient_return_value,
                'condition' => [
                    $args['prefix'].'_color_type' => ['gradient'],
                ],
            ),
            array(
                'name'        => $args['prefix'].'pxl_start_popover',
                'label'       => ucfirst( str_replace('_', '', $args['prefix']) ).' '. esc_html__( 'Start Popover', 'solarva' ),
                'type'        => 'pxl_start_popover',
                'condition'   => $args['condition'],
            ),
            array(
                'name' => $args['prefix'].'_gradient_color_from',
                'label' => esc_html__('From', 'solarva' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} '.$args['selectors_class'] => '--gradient-color-from: {{VALUE}};',
                ],
                'condition' => [
                    $args['prefix'] .'_gradient_color!' => '',
                ],
            ),
            array(
                'name' => $args['prefix'].'_gradient_color_to',
                'label' => esc_html__('To', 'solarva' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} '.$args['selectors_class'] => '--gradient-color-to: {{VALUE}};',
                ],
                'condition' => [
                    $args['prefix'] .'_gradient_color!' => '',
                ],
            ),
            array(
                'name'        => $args['prefix'].'pxl_end_popover',
                'label'       => ucfirst( str_replace('_', '', $args['prefix']) ).' '. esc_html__( 'End Popover', 'solarva' ),
                'type'        => 'pxl_end_popover',
                'condition'   => $args['condition'],
            ),
        );
        return $options;
    }
}

if(!function_exists('solarva_widget_bgcolor_type')){
    function solarva_widget_bgcolor_type($args = []){
        $gradient_prefix_class = 'pxl-';
        $gradient_return_value = 'gradient';
        $args = wp_parse_args($args, [
            'label' => '',
            'prefix' => '',
            'selectors_class' => '',
            'condition' => []
        ]);
        $options = array(
            array(
                'name' => $args['prefix'] .'_color_type',
                'label' => esc_html__('BG Color Type', 'solarva' ),
                'type' => \Elementor\Controls_Manager::SELECT,
                'options' => [
                    'normal' => 'Normal',
                    'gradient' => 'Gradient 1',
                    'gradient2' => 'Gradient 2',
                ],
                'default' => 'normal',
            ),

            array(
                'name' => $args['prefix'] .'_normal_color',
                'label' => esc_html__('Box Normal Color', 'solarva' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} '.$args['selectors_class'] => 'background-color: {{VALUE}};',
                ],
                'condition' => [
                    $args['prefix'].'_color_type' => ['normal'],
                ],
            ),

            array(
                'name'        => $args['prefix'].'_gradient_color',
                'label' => $args['label'] .' '.esc_html__('BG Gradient Color', 'solarva' ),
                'type' => \Elementor\Controls_Manager::POPOVER_TOGGLE,
                'prefix_class' => $gradient_prefix_class,
                'return_value' => $gradient_return_value,
                'condition' => [
                    $args['prefix'].'_color_type' => ['gradient'],
                ],
            ),
            array(
                'name'        => $args['prefix'].'pxl_start_popover',
                'label'       => ucfirst( str_replace('_', '', $args['prefix']) ).' '. esc_html__( 'Start Popover', 'solarva' ),
                'type'        => 'pxl_start_popover',
                'condition'   => $args['condition'],
            ),
            array(
                'name' => $args['prefix'].'_gradient_color_from',
                'label' => esc_html__('From', 'solarva' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} '.$args['selectors_class'] => '--gradient-color-from: {{VALUE}};',
                ],
                'condition' => [
                    $args['prefix'] .'_gradient_color!' => '',
                ],
            ),
            array(
                'name' => $args['prefix'].'_gradient_color_to',
                'label' => esc_html__('To', 'solarva' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} '.$args['selectors_class'] => '--gradient-color-to: {{VALUE}};',
                ],
                'condition' => [
                    $args['prefix'] .'_gradient_color!' => '',
                ],
            ),
            array(
                'name'        => $args['prefix'].'pxl_end_popover',
                'label'       => ucfirst( str_replace('_', '', $args['prefix']) ).' '. esc_html__( 'End Popover', 'solarva' ),
                'type'        => 'pxl_end_popover',
                'condition'   => $args['condition'],
            ),
        );
        return $options;
    }
}

if(!function_exists('solarva_widget_gradient_color')){
    function solarva_widget_gradient_color($args = []){
        $gradient_prefix_class = 'pxl-';
        $gradient_return_value = 'gradient';
        $args = wp_parse_args($args, [
            'label' => '',
            'prefix' => '',
            'selectors_class' => '',
            'condition' => []
        ]);
        $options = array(
            array(
                'name'        => $args['prefix'] .'_gradient_color',
                'label' => $args['label'] .' '.esc_html__('Gradient Color', 'solarva' ),
                'type' => \Elementor\Controls_Manager::POPOVER_TOGGLE,
                'prefix_class' => $gradient_prefix_class,
                'return_value' => $gradient_return_value,
                'condition'   => $args['condition'],
            ),
            array(
                'name'        => $args['prefix'] .'pxl_start_popover',
                'label'       => ucfirst( str_replace('_', '', $args['prefix']) ).' '. esc_html__( 'Start Popover', 'solarva' ),
                'type'        => 'pxl_start_popover',
                'condition'   => $args['condition'],
            ),
            array(
                'name' => $args['prefix'] .'_gradient_color_from',
                'label' => esc_html__('From', 'solarva' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} '.$args['selectors_class'] => '--gradient-color-from: {{VALUE}};',
                ],
                'condition' => [
                    $args['prefix'] .'_gradient_color!' => '',
                ],
            ),
            array(
                'name' => $args['prefix'] .'_gradient_color_to',
                'label' => esc_html__('To', 'solarva' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} '.$args['selectors_class'] => '--gradient-color-to: {{VALUE}};',
                ],
                'condition' => [
                    $args['prefix'] .'_gradient_color!' => '',
                ],
            ),
            array(
                'name'        => $args['prefix'] .'pxl_end_popover',
                'label'       => ucfirst( str_replace('_', '', $args['prefix']) ).' '. esc_html__( 'End Popover', 'solarva' ),
                'type'        => 'pxl_end_popover',
                'condition'   => $args['condition'],
            ),
        );
        return $options;
    }
}

if(!function_exists('solarva_widget_gradient_color_rotate')){
    function solarva_widget_gradient_color_rotate($args = []){
        $gradient_prefix_class = 'pxl-';
        $gradient_return_value = 'gradient';
        $args = wp_parse_args($args, [
            'label' => '',
            'prefix' => '',
            'selectors_class' => '',
            'condition' => []
        ]);
        $options = array(
            array(
                'name'        => $args['prefix'] .'_gradient_color',
                'label' => $args['label'] .' '.esc_html__('Gradient Color', 'solarva' ),
                'type' => \Elementor\Controls_Manager::POPOVER_TOGGLE,
                'prefix_class' => $gradient_prefix_class,
                'return_value' => $gradient_return_value,
                'condition'   => $args['condition'],
            ),
            array(
                'name'        => $args['prefix'] .'pxl_start_popover',
                'label'       => ucfirst( str_replace('_', '', $args['prefix']) ).' '. esc_html__( 'Start Popover', 'solarva' ),
                'type'        => 'pxl_start_popover',
                'condition'   => $args['condition'],
            ),
            array(
                'name' => $args['prefix'] .'_gradient_color_from',
                'label' => esc_html__('From', 'solarva' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} '.$args['selectors_class'] => '--gradient-color-from: {{VALUE}};',
                ],
                'condition' => [
                    $args['prefix'] .'_gradient_color!' => '',
                ],
            ),
            array(
                'name' => $args['prefix'] .'_gradient_color_to',
                'label' => esc_html__('To', 'solarva' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} '.$args['selectors_class'] => '--gradient-color-to: {{VALUE}};',
                ],
                'condition' => [
                    $args['prefix'] .'_gradient_color!' => '',
                ],
            ),
            array(
                'name' => $args['prefix'] .'_gradient_angle',
                'label' => esc_html__('Angle', 'solarva' ),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => [ 'px' ],
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 360,
                        'step' => 10,
                    ],
                ],
            ),
            array(
                'name'        => $args['prefix'] .'pxl_end_popover',
                'label'       => ucfirst( str_replace('_', '', $args['prefix']) ).' '. esc_html__( 'End Popover', 'solarva' ),
                'type'        => 'pxl_end_popover',
                'condition'   => $args['condition'],
            ),
        );
        return $options;
    }
}