<?php

namespace PPB_AdvancedGutenbergPro\Utils;

class Definitions
{
    public static function advgb_pro_get_blocks()
    {
        return array(
            'advgb/countdown',
            'advgb/pricing-table',
            'advgb/feature-list',
            'advgb/feature',
            'core/paragraph',
            'core/heading'
        );
    }

    // Enqueue main styles
    public static function advgb_pro_enqueue_main_styles()
    {
        wp_enqueue_style(
            'advgb_blocks_styles_pro',
            plugins_url('assets/css/blocks-pro.css', dirname(__FILE__)),
            array(),
            ADVANCED_GUTENBERG_PRO_VERSION
        );
    }

    // Load main styles as inline in Site Editor
    public static function advgb_pro_enqueue_main_styles_inline()
    {
        add_editor_style(plugins_url(
            'assets/css/blocks-pro.css',
            dirname(__FILE__) 
        )); // 'advgb_blocks_styles_pro'
    }

    // Register styles for frontend
    public static function advgb_pro_register_styles_frontend()
    {
    }

    // Enqueue styles for frontend
    public static function advgb_pro_enqueue_styles_frontend()
    {
    }

    // Register scripts for admin
    public static function advgb_pro_register_scripts_admin()
    {
    }

    // Enqueue scripts for admin
    public static function advgb_pro_enqueue_scripts_admin()
    {
    }

    // Register scripts for frontend
    public static function advgb_pro_register_scripts_frontend()
    {
        /*wp_register_script(
            'advgb_blocks_frontend_scripts_pro',
            plugins_url('assets/blocks/frontend-pro.js', dirname(__FILE__)),
            array(),
            ADVANCED_GUTENBERG_PRO_VERSION
        );*/
        wp_register_script(
            'advgb_countdown_scripts',
            plugins_url('assets/blocks/countdown/countdown.min.js', dirname(__FILE__)),
            array(),
            ADVANCED_GUTENBERG_PRO_VERSION
        );
    }

    // Enqueue scripts for frontend - Countdown block
    public static function advgb_pro_enqueue_scripts_frontend_countdown()
    {
        wp_enqueue_script('advgb_countdown_scripts');
    }

    // Register scripts for editor
    public static function advgb_pro_register_scripts_editor()
    {
    }

    // Get the editor dependency based on current screen

    public static function advgb_pro_enqueue_scripts_editor()
    {
        $wp_editor_dep = self::advgb_pro_get_editor_handle();

        wp_enqueue_script(
            'advgb_blocks_pro',
            plugins_url('assets/blocks/blocks-pro.js', dirname(__FILE__)),
            array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-data', $wp_editor_dep, 'wp-plugins', 'wp-compose' ),
            ADVANCED_GUTENBERG_PRO_VERSION,
            true
        );

        wp_enqueue_script(
            'advgb_countdown_scripts',
            plugins_url('assets/blocks/countdown/countdown.min.js', dirname(__FILE__)),
            array(),
            ADVANCED_GUTENBERG_PRO_VERSION
        );
    }

    // Enqueue scripts for editor

    public static function advgb_pro_get_editor_handle()
    {
        $currentScreen = get_current_screen();

        if ($currentScreen->id === 'customize') {
            // Customizer > Widgets
            $wp_editor_dep = 'wp-customize-widgets';
        } elseif ($currentScreen->id === 'widgets') {
            // Appearance > Widgets
            $wp_editor_dep = 'wp-edit-widgets';
        } else {
            // Post edit and Site Editor
            $wp_editor_dep = 'wp-editor';
        }

        return $wp_editor_dep;
    }

    // Enqueue scripts for editor which features can be disabled

    public static function advgb_pro_enqueue_scripts_editor_conditional()
    {
        if (self::advgb_pro_setting_is_enabled('enable_core_blocks_features')) {
            $wp_editor_dep = self::advgb_pro_get_editor_handle();

            wp_enqueue_script(
                'advgb_editor_utilities_pro',
                plugins_url('assets/js/editor-utilities.min.js', dirname(__FILE__)),
                array( 'advgb_blocks_pro' ),
                ADVANCED_GUTENBERG_PRO_VERSION,
                true
            );

            wp_enqueue_script(
                'advgb_core_blocks_pro',
                plugins_url('assets/blocks/core-blocks.js', dirname(__FILE__)),
                array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-data', $wp_editor_dep, 'wp-plugins', 'wp-compose' ),
                ADVANCED_GUTENBERG_PRO_VERSION,
                true
            );
        }
    }

    /**
     * Check if a setting is enabled
     *
     * @since 2.13.1
     *
     * return boolean
     */
    public static function advgb_pro_setting_is_enabled($setting)
    {
        $saved_settings = get_option('advgb_settings');
        if (! isset($saved_settings[ $setting ]) || $saved_settings[ $setting ]) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * Checkbox settings for Settings page to output inside <table>
     *
     * @param string $setting Field name
     * @param string $title Field title
     * @param string $label Field label
     *
     * @return string
     */
    public static function advgb_pro_setting($setting, $title, $label)
    {
        $saved_settings = get_option('advgb_settings');
        $checkbox       = isset($saved_settings[ $setting ]) && $saved_settings[ $setting ] ? ' checked' : '';
        if (! isset($saved_settings[ $setting ])) {
            $checkbox = ' checked';
        }

        return '<tr>
            <th scope="row">
                ' . esc_html($title) . '
            </th>
            <td>
                <label>
                    <input type="checkbox" name="' . esc_attr($setting) . '"
                           id="' . esc_attr($setting) . '"
                           value="1" ' . $checkbox . '
                    />
                    ' . esc_attr($label) . '
                </label>
            </td>
        </tr>';
    }

    // Set value for checkbox setting to save
    public static function advgb_pro_setting_set_value($setting)
    {
        if (isset($_POST[ $setting ])) {
            return 1;
        } else {
            return 0;
        }
    }

    // Default Block Settings page
    public static function advgb_pro_default_block_settings($option)
    {
        switch ($option) {
            case 'excluded_blocks':
                return array(
                    'advgb/countdown',
                    'advgb/pricing-table',
                    'advgb/feature-list',
                    'advgb/feature',
                );
                break;
        }
    }

    // Set styles for blocks in frontend
    public static function advgb_pro_set_styles_for_blocks($attributes, $block)
    {
        switch ($block) {
            case 'advgb/pricing-table':
                wp_enqueue_style('dashicons');

                $style_html              = '';
                $block_id                = esc_html($attributes['blockID']);
                $border_width            = isset($attributes['borderWidth']) ? esc_html(intval($attributes['borderWidth'])) : 2;
                $border_style            = isset($attributes['borderStyle']) ? esc_html($attributes['borderStyle']) : 'solid';
                $border_color            = isset($attributes['borderColor']) ? esc_html($attributes['borderColor']) : '#2196f3';
                $border_radius           = isset($attributes['borderRadius']) ? esc_html(intval($attributes['borderRadius'])) : 0;
                $heading_border          = isset($attributes['headingBorder']) ? esc_html($attributes['headingBorder']) : false;
                $heading_background      = isset($attributes['headingBackground']) ? esc_html($attributes['headingBackground']) : '#2196f3';
                $heading_padding_top     = isset($attributes['headingPaddingTop']) ? esc_html(intval($attributes['headingPaddingTop'])) : 20;
                $heading_padding_right   = isset($attributes['headingPaddingRight']) ? esc_html(intval($attributes['headingPaddingRight'])) : 20;
                $heading_padding_bottom  = isset($attributes['headingPaddingBottom']) ? esc_html(intval($attributes['headingPaddingBottom'])) : 20;
                $heading_padding_left    = isset($attributes['headingPaddingLeft']) ? esc_html(intval($attributes['headingPaddingLeft'])) : 20;
                $price_border            = isset($attributes['priceBorder']) ? esc_html($attributes['priceBorder']) : false;
                $price_background        = isset($attributes['priceBackground']) ? esc_html($attributes['priceBackground']) : '#82c2f7';
                $price_padding_top       = isset($attributes['pricePaddingTop']) ? esc_html(intval($attributes['pricePaddingTop'])) : 20;
                $price_padding_right     = isset($attributes['pricePaddingRight']) ? esc_html(intval($attributes['pricePaddingRight'])) : 20;
                $price_padding_bottom    = isset($attributes['pricePaddingBottom']) ? esc_html(intval($attributes['pricePaddingBottom'])) : 20;
                $price_padding_left      = isset($attributes['pricePaddingLeft']) ? esc_html(intval($attributes['pricePaddingLeft'])) : 20;
                $features_background     = isset($attributes['featuresBackground']) ? esc_html($attributes['featuresBackground']) : '#ffffff';
                $features_padding_top    = isset($attributes['featuresPaddingTop']) ? esc_html(intval($attributes['featuresPaddingTop'])) : 0;
                $features_padding_right  = isset($attributes['featuresPaddingRight']) ? esc_html(intval($attributes['featuresPaddingRight'])) : 0;
                $features_padding_bottom = isset($attributes['featuresPaddingBottom']) ? esc_html(intval($attributes['featuresPaddingBottom'])) : 0;
                $features_padding_left   = isset($attributes['featuresPaddingLeft']) ? esc_html(intval($attributes['featuresPaddingLeft'])) : 0;

                $style_html .= '.wp-block-advgb-pricing-table #' . $block_id . ' {';
                $style_html .= 'border: ' . $border_width . 'px ' . $border_style . ' ' . $border_color . ';';
                $style_html .= 'border-radius: ' . $border_radius . 'px;';
                $style_html .= '}';
                $style_html .= '.wp-block-advgb-pricing-table #' . $block_id . ' .advgb-pricing-table__heading {';
                $style_html .= 'border-bottom: ' . ( $heading_border && $border_width > 0 ? $border_width . 'px ' . $border_style . ' ' . $border_color : 'none' ) . ';';
                $style_html .= 'background: ' . $heading_background . ';';
                $style_html .= 'padding: ' . $heading_padding_top . 'px ' . $heading_padding_right . 'px ' . $heading_padding_bottom . 'px ' . $heading_padding_left . 'px;';
                $style_html .= '}';
                $style_html .= '.wp-block-advgb-pricing-table #' . $block_id . ' .advgb-pricing-table__price {';
                $style_html .= 'border-bottom: ' . ( $price_border && $border_width > 0 ? $border_width . 'px ' . $border_style . ' ' . $border_color : 'none' ) . ';';
                $style_html .= 'background: ' . $price_background . ';';
                $style_html .= 'padding: ' . $price_padding_top . 'px ' . $price_padding_right . 'px ' . $price_padding_bottom . 'px ' . $price_padding_left . 'px;';
                $style_html .= '}';
                $style_html .= '.wp-block-advgb-pricing-table #' . $block_id . ' .advgb-pricing-table__features {';
                $style_html .= 'background: ' . $features_background . ';';
                $style_html .= 'padding: ' . $features_padding_top . 'px ' . $features_padding_right . 'px ' . $features_padding_bottom . 'px ' . $features_padding_left . 'px;';
                $style_html .= '}';

                return $style_html;
                break;

            case 'advgb/feature-list':
                wp_enqueue_style('dashicons');

                $style_html        = '';
                $block_id          = esc_html($attributes['blockID']);
                $stripes           = isset($attributes['stripes']) ? esc_html($attributes['stripes']) : true;
                $font_size         = isset($attributes['fontSize']) ? esc_html(intval($attributes['fontSize'])) : 18;
                $icon_size         = isset($attributes['iconSize']) ? esc_html(intval($attributes['iconSize'])) : 22;
                $line_height       = isset($attributes['lineHeight']) ? esc_html(intval($attributes['lineHeight'])) : 30;
                $spacing_icon_text = isset($attributes['spacingIconText']) ? esc_html(intval($attributes['spacingIconText'])) : 5;
                $padding_top       = isset($attributes['paddingTop']) ? esc_html(intval($attributes['paddingTop'])) : 15;
                $padding_right     = isset($attributes['paddingRight']) ? esc_html(intval($attributes['paddingRight'])) : 20;
                $padding_bottom    = isset($attributes['paddingBottom']) ? esc_html(intval($attributes['paddingBottom'])) : 15;
                $padding_left      = isset($attributes['paddingLeft']) ? esc_html(intval($attributes['paddingLeft'])) : 20;

                if ($stripes) {
                    $stripes_background1 = isset($attributes['stripesBackground1']) ? esc_html($attributes['stripesBackground1']) : '#ffffff';
                    $stripes_background2 = isset($attributes['stripesBackground2']) ? esc_html($attributes['stripesBackground2']) : '#f2f2f2';

                    $style_html .= '.' . $block_id . '.wp-block-advgb-feature-list > div.wp-block-advgb-feature:nth-child(2n+1) {';
                    $style_html .= 'background: ' . $stripes_background1 . ';';
                    $style_html .= '}';
                    $style_html .= '.' . $block_id . '.wp-block-advgb-feature-list > div.wp-block-advgb-feature {';
                    $style_html .= 'background: ' . $stripes_background2 . ';';
                    $style_html .= '}';
                }

                $style_html .= '.' . $block_id . '.wp-block-advgb-feature-list > div.wp-block-advgb-feature {';
                $style_html .= 'font-size: ' . $font_size . 'px;';
                $style_html .= 'line-height: ' . $line_height . 'px;';
                $style_html .= 'padding: ' . $padding_top . 'px ' . $padding_right . 'px ' . $padding_bottom . 'px ' . $padding_left . 'px';
                $style_html .= '}';
                $style_html .= '.' . $block_id . '.wp-block-advgb-feature-list > div.wp-block-advgb-feature:before {';
                $style_html .= 'font-size: ' . $icon_size . 'px;';
                $style_html .= 'margin-right: ' . $spacing_icon_text . 'px;';
                $style_html .= '}';

                return $style_html;
                break;

            case 'advgb/feature':
                $style_html = '';
                $block_id   = esc_html($attributes['blockID']);
                $font_size  = isset($attributes['fontSize']) ? esc_html(intval($attributes['fontSize'])) : 18;
                $icon       = isset($attributes['icon']) && ! empty($attributes['icon']) ? esc_html($attributes['icon']) : 'saved';
                $icon_color = isset($attributes['iconColor']) ? esc_html($attributes['iconColor']) : '#08ba79';

                if (! empty($icon)) {
                    $style_html .= '.wp-block-advgb-feature.' . $block_id . ':before {';
                    $style_html .= 'color: ' . $icon_color . ';';
                    $style_html .= '}';
                }

                return $style_html;
                break;

            case 'advgb/button':
                $block_class    = esc_html($attributes['id']);
                $icon_display   = isset($attributes['iconDisplay']) ? esc_html($attributes['iconDisplay']) : false;
                $icon           = isset($attributes['icon']) ? esc_html($attributes['icon']) : 'insert_link';
                $icon_size      = isset($attributes['iconSize']) ? esc_html(intval($attributes['iconSize'])) : 30;
                $icon_color     = isset($attributes['iconColor']) ? esc_html($attributes['iconColor']) : 'inherit';
                $icon_position  = isset($attributes['iconPosition']) ? esc_html($attributes['iconPosition']) : 'left';
                $icon_spacing   = isset($attributes['iconSpacing']) ? esc_html(intval($attributes['iconSpacing'])) : 7;
                $font_family    = isset($attributes['fontFamily']) ? esc_html($attributes['fontFamily']) : '';
                $font_variation = isset($attributes['fontVariation']) ? esc_html($attributes['fontVariation']) : '';

                $style_html = '.' . $block_class . ' > i {';
                $style_html .= 'font-size:' . $icon_size . 'px;';
                $style_html .= 'color:' . $icon_color . ';';
                $style_html .= 'float:' . $icon_position . ';';

                if ($icon_position == 'left') {
                    $style_html .= 'margin-right:' . $icon_spacing . 'px;';
                } else {
                    $style_html .= 'margin-left:' . $icon_spacing . 'px;';
                }

                $style_html .= '}';

                if (! empty($font_family)) {
                    $style_html .= '.' . $block_class . ' span {';
                    $style_html .= self::advgb_pro_set_google_font_style($font_family, $font_variation);
                    $style_html .= '}';
                }

                return $style_html;
                break;

            case 'advgb/recent-posts':
                if (! isset($attributes['id'])) {
                    return;
                }

                $style_html = '';

                $block_class                 = esc_html($attributes['id']);
                $display_read_more           = isset($attributes['displayReadMore']) ? esc_html($attributes['displayReadMore']) : true;
                $read_more_text_decoration   = isset($attributes['readMoreTextDecoration']) ? esc_html($attributes['readMoreTextDecoration']) : '';
                $read_more_text_decoration_h = isset($attributes['readMoreTextDecorationH']) ? esc_html($attributes['readMoreTextDecorationH']) : '';
                $read_more_text_color        = isset($attributes['readMoreTextColor']) ? esc_html($attributes['readMoreTextColor']) : '';
                $read_more_text_color_h      = isset($attributes['readMoreTextColorH']) ? esc_html($attributes['readMoreTextColorH']) : '';
                $read_more_bg_color          = isset($attributes['readMoreBgColor']) ? esc_html($attributes['readMoreBgColor']) : '';
                $read_more_bg_color_h        = isset($attributes['readMoreBgColorH']) ? esc_html($attributes['readMoreBgColorH']) : '';
                $read_more_border_style      = isset($attributes['readMoreBorderStyle']) ? esc_html($attributes['readMoreBorderStyle']) : 'none';
                $read_more_border_color      = isset($attributes['readMoreBorderColor']) ? esc_html($attributes['readMoreBorderColor']) : '#000';
                $read_more_border_color_h    = isset($attributes['readMoreBorderColorH']) ? esc_html($attributes['readMoreBorderColorH']) : '#000';
                $read_more_border_width      = isset($attributes['readMoreBorderWidth']) ? esc_html($attributes['readMoreBorderWidth']) : 1;
                $read_more_border_radius     = isset($attributes['readMoreBorderRadius']) ? esc_html($attributes['readMoreBorderRadius']) : 0;
                $read_more_padding_enabled   = isset($attributes['readMorePaddingEnabled']) ? esc_html($attributes['readMorePaddingEnabled']) : false;
                $read_more_padding_top       = isset($attributes['readMorePaddingTop']) ? esc_html($attributes['readMorePaddingTop']) : 5;
                $read_more_padding_bottom    = isset($attributes['readMorePaddingBottom']) ? esc_html($attributes['readMorePaddingBottom']) : 5;
                $read_more_padding_left      = isset($attributes['readMorePaddingLeft']) ? esc_html($attributes['readMorePaddingLeft']) : 10;
                $read_more_padding_right     = isset($attributes['readMorePaddingRight']) ? esc_html($attributes['readMorePaddingRight']) : 10;
                $read_more_font_family       = isset($attributes['readMoreFontFamily']) ? esc_html($attributes['readMoreFontFamily']) : '';
                $read_more_font_variation    = isset($attributes['readMoreFontVariation']) ? esc_html($attributes['readMoreFontVariation']) : '';
                $read_more_text_transform    = isset($attributes['readMoreTextTransform']) ? esc_html($attributes['readMoreTextTransform']) : '';
                $image_size_enabled          = isset($attributes['imageSizeEnabled']) ? esc_html($attributes['imageSizeEnabled']) : false;
                $image_height                = isset($attributes['imageHeight']) ? esc_html($attributes['imageHeight']) : false;
                $image_width_unit            = isset($attributes['imageWidthUnit']) ? esc_html($attributes['imageWidthUnit']) : 'px';
                $image_width                 = isset($attributes['imageWidth']) ? esc_html($attributes['imageWidth']) : false;
                $image_width_auto            = isset($attributes['imageWidthAuto']) ? esc_html($attributes['imageWidthAuto']) : true;
                $image_height_auto           = isset($attributes['imageHeightAuto']) ? esc_html($attributes['imageHeightAuto']) : true;
                $image_size_force            = isset($attributes['imageSizeForce']) ? esc_html($attributes['imageSizeForce']) : false;
                $title_font_family           = isset($attributes['titleFontFamily']) ? esc_html($attributes['titleFontFamily']) : '';
                $title_font_variation        = isset($attributes['titleFontVariation']) ? esc_html($attributes['titleFontVariation']) : '';
                $title_text_transform        = isset($attributes['titleTextTransform']) ? esc_html($attributes['titleTextTransform']) : '';
                $title_line_height           = isset($attributes['titleLineHeight']) ? esc_html($attributes['titleLineHeight']) : false;
                $info_font_family            = isset($attributes['infoFontFamily']) ? esc_html($attributes['infoFontFamily']) : '';
                $info_font_variation         = isset($attributes['infoFontVariation']) ? esc_html($attributes['infoFontVariation']) : '';
                $info_text_transform         = isset($attributes['infoTextTransform']) ? esc_html($attributes['infoTextTransform']) : '';
                $info_color                  = isset($attributes['infoColor']) ? esc_html($attributes['infoColor']) : '';
                $info_link_color             = isset($attributes['infoLinkColor']) ? esc_html($attributes['infoLinkColor']) : '';
                $info_link_color_h           = isset($attributes['infoLinkColorH']) ? esc_html($attributes['infoLinkColorH']) : '';
                $taxonomy_font_family        = isset($attributes['taxonomyFontFamily']) ? esc_html($attributes['taxonomyFontFamily']) : '';
                $taxonomy_font_variation     = isset($attributes['taxonomyFontVariation']) ? esc_html($attributes['taxonomyFontVariation']) : '';
                $taxonomy_text_transform     = isset($attributes['taxonomyTextTransform']) ? esc_html($attributes['taxonomyTextTransform']) : '';
                $taxonomy_color              = isset($attributes['taxonomyColor']) ? esc_html($attributes['taxonomyColor']) : '';
                $taxonomy_color_h            = isset($attributes['taxonomyColorH']) ? esc_html($attributes['taxonomyColorH']) : '';
                $content_font_family         = isset($attributes['contentFontFamily']) ? esc_html($attributes['contentFontFamily']) : '';
                $content_font_variation      = isset($attributes['contentFontVariation']) ? esc_html($attributes['contentFontVariation']) : '';
                $content_text_transform      = isset($attributes['contentTextTransform']) ? esc_html($attributes['contentTextTransform']) : '';
                $title_hide_d                = isset($attributes['titleHideD']) ? esc_html($attributes['titleHideD']) : false;
                $title_size_d                = isset($attributes['titleSizeD']) ? esc_html($attributes['titleSizeD']) : false;
                $title_hide_t                = isset($attributes['titleHideT']) ? esc_html($attributes['titleHideT']) : false;
                $title_size_t                = isset($attributes['titleSizeT']) ? esc_html($attributes['titleSizeT']) : false;
                $title_hide_m                = isset($attributes['titleHideM']) ? esc_html($attributes['titleHideM']) : false;
                $title_size_m                = isset($attributes['titleSizeM']) ? esc_html($attributes['titleSizeM']) : false;
                $title_color                 = isset($attributes['titleColor']) ? esc_html($attributes['titleColor']) : '';
                $title_color_h               = isset($attributes['titleColorH']) ? esc_html($attributes['titleColorH']) : '';
                $content_color               = isset($attributes['contentColor']) ? esc_html($attributes['contentColor']) : '';

                // Title
                if (! empty($title_font_family) || ! empty($title_text_transform) || $title_line_height) {
                    $style_html .= '.' . $block_class . '.advgb-recent-posts-block .advgb-recent-posts .advgb-recent-post .advgb-post-title {';

                    if (! empty($title_font_family)) {
                        $style_html .= self::advgb_pro_set_google_font_style(
                            $title_font_family,
                            $title_font_variation 
                        );
                    }

                    if (! empty($title_text_transform)) {
                        $style_html .= 'text-transform:' . $title_text_transform . ';';
                    }

                    if ($title_line_height) {
                        $style_html .= 'line-height:' . $title_line_height . 'em;';
                    }

                    $style_html .= '}';
                }

                if (! empty($title_color) || ! empty($title_color_h)) {
                    if (! empty($title_color)) {
                        $style_html .= '.' . $block_class . '.advgb-recent-posts-block .advgb-recent-posts .advgb-recent-post .advgb-post-title > a {';
                        $style_html .= 'color:' . $title_color . ' !important;';
                        $style_html .= '}';
                    }

                    if (! empty($title_color_h)) {
                        $style_html .= '.' . $block_class . '.advgb-recent-posts-block .advgb-recent-posts .advgb-recent-post .advgb-post-title > a:hover,';
                        $style_html .= '.' . $block_class . '.advgb-recent-posts-block .advgb-recent-posts .advgb-recent-post .advgb-post-title > a:focus,';
                        $style_html .= '.' . $block_class . '.advgb-recent-posts-block .advgb-recent-posts .advgb-recent-post .advgb-post-title > a:active {';
                        $style_html .= 'color:' . $title_color_h . ' !important;';
                        $style_html .= '}';
                    }
                }

                if ($title_size_d || $title_hide_d) {
                    $style_html .= '@media (min-width:992px) {';
                    $style_html .= '.' . $block_class . '.advgb-recent-posts-block .advgb-recent-posts .advgb-recent-post .advgb-post-title {';
                    $style_html .= $title_size_d ? 'font-size:' . $title_size_d . 'px;' : '';
                    $style_html .= $title_hide_d ? 'display:none;' : '';
                    $style_html .= '}';
                    $style_html .= '}';
                }

                if ($title_size_t || $title_hide_t) {
                    $style_html .= '@media (min-width:768px) and (max-width:991px) {';
                    $style_html .= '.' . $block_class . '.advgb-recent-posts-block .advgb-recent-posts .advgb-recent-post .advgb-post-title {';
                    $style_html .= $title_size_t ? 'font-size:' . $title_size_t . 'px;' : '';
                    $style_html .= $title_hide_t ? 'display:none;' : '';
                    $style_html .= '}';
                    $style_html .= '}';
                }

                if ($title_size_m || $title_hide_m) {
                    $style_html .= '@media (max-width:767px) {';
                    $style_html .= '.' . $block_class . '.advgb-recent-posts-block .advgb-recent-posts .advgb-recent-post .advgb-post-title {';
                    $style_html .= $title_size_m ? 'font-size:' . $title_size_m . 'px;' : '';
                    $style_html .= $title_hide_m ? 'display:none;' : '';
                    $style_html .= '}';
                    $style_html .= '}';
                }

                // Info
                if (! empty($info_font_family) || ! empty($info_text_transform) || ! empty($info_color)) {
                    $style_html .= '.' . $block_class . '.advgb-recent-posts-block .advgb-recent-posts .advgb-recent-post .advgb-post-info * {';

                    if (! empty($info_font_family)) {
                        $style_html .= self::advgb_pro_set_google_font_style($info_font_family, $info_font_variation);
                    }

                    if (! empty($info_text_transform)) {
                        $style_html .= 'text-transform:' . $info_text_transform . ';';
                    }

                    if (! empty($info_color)) {
                        $style_html .= 'color:' . $info_color . ' !important;';
                    }

                    $style_html .= '}';
                }

                if (! empty($info_link_color)) {
                    $style_html .= '.' . $block_class . '.advgb-recent-posts-block .advgb-recent-posts .advgb-recent-post .advgb-post-info > a {';
                    $style_html .= 'color:' . $info_link_color . ' !important;';
                    $style_html .= '}';
                }

                if (! empty($info_link_color_h)) {
                    $style_html .= '.' . $block_class . '.advgb-recent-posts-block .advgb-recent-posts .advgb-recent-post .advgb-post-info > a:hover,';
                    $style_html .= '.' . $block_class . '.advgb-recent-posts-block .advgb-recent-posts .advgb-recent-post .advgb-post-info > a:focus,';
                    $style_html .= '.' . $block_class . '.advgb-recent-posts-block .advgb-recent-posts .advgb-recent-post .advgb-post-info > a:active {';
                    $style_html .= 'color:' . $info_link_color_h . ' !important;';
                    $style_html .= '}';
                }

                // Taxonomy
                if (! empty($taxonomy_font_family) || ! empty($taxonomy_text_transform) || ! empty($taxonomy_color)) {
                    $style_html .= '.' . $block_class . '.advgb-recent-posts-block .advgb-recent-posts .advgb-recent-post .advgb-post-tax-info a,';
                    $style_html .= '.' . $block_class . '.advgb-recent-posts-block .advgb-recent-posts .advgb-recent-post .advgb-post-tax-info span {';

                    if (! empty($taxonomy_font_family)) {
                        $style_html .= self::advgb_pro_set_google_font_style(
                            $taxonomy_font_family,
                            $taxonomy_font_variation 
                        );
                    }

                    if (! empty($taxonomy_text_transform)) {
                        $style_html .= 'text-transform:' . $taxonomy_text_transform . ';';
                    }

                    if (! empty($taxonomy_color)) {
                        $style_html .= 'color:' . $taxonomy_color . ' !important;';
                    }

                    $style_html .= '}';
                }

                if (! empty($taxonomy_color_h)) {
                    $style_html .= '.' . $block_class . '.advgb-recent-posts-block .advgb-recent-posts .advgb-recent-post .advgb-post-tax-info a:hover,';
                    $style_html .= '.' . $block_class . '.advgb-recent-posts-block .advgb-recent-posts .advgb-recent-post .advgb-post-tax-info a:focus,';
                    $style_html .= '.' . $block_class . '.advgb-recent-posts-block .advgb-recent-posts .advgb-recent-post .advgb-post-tax-info a:active {';
                    $style_html .= 'color:' . $taxonomy_color_h . ' !important;';
                    $style_html .= '}';
                }

                // Content
                if (! empty($content_font_family) || ! empty($content_text_transform) || ! empty($content_color)) {
                    $style_html .= '.' . $block_class . '.advgb-recent-posts-block .advgb-recent-posts .advgb-recent-post .advgb-post-content .advgb-post-excerpt {';

                    if (! empty($content_font_family)) {
                        $style_html .= self::advgb_pro_set_google_font_style(
                            $content_font_family,
                            $content_font_variation 
                        );
                    }

                    if (! empty($content_text_transform)) {
                        $style_html .= 'text-transform:' . $content_text_transform . ';';
                    }

                    if (! empty($content_color)) {
                        $style_html .= 'color:' . $content_color . ' !important;';
                    }

                    $style_html .= '}';
                }

                // Read more
                if ($display_read_more) {
                    // Read more default
                    if (
                        ! empty($read_more_font_family)
                        || ! empty($read_more_text_transform)
                        || ! empty($read_more_text_color)
                        || ! empty($read_more_bg_color)
                        || $read_more_border_style !== 'none'
                        || $read_more_padding_enabled
                        || $read_more_border_radius > 0
                        || ! empty($read_more_text_decoration)
                    ) {
                        $style_html .= '.' . $block_class . '.advgb-recent-posts-block .advgb-recent-posts .advgb-recent-post .advgb-post-readmore a {';

                        if (! empty($read_more_font_family)) {
                            $style_html .= self::advgb_pro_set_google_font_style(
                                $read_more_font_family,
                                $read_more_font_variation 
                            );
                        }

                        if (! empty($read_more_text_transform)) {
                            $style_html .= 'text-transform:' . $read_more_text_transform . ';';
                        }

                        if (! empty($read_more_text_color)) {
                            $style_html .= 'color:' . $read_more_text_color . ' !important;';
                        }

                        if (! empty($read_more_bg_color)) {
                            $style_html .= 'background:' . $read_more_bg_color . ';';
                        }

                        if ($read_more_border_radius > 0) {
                            $style_html .= 'border-radius:' . $read_more_border_radius . 'px;';
                        }

                        if ($read_more_border_style !== 'none') {
                            $style_html .= 'border-style:' . $read_more_border_style . ';';
                            $style_html .= 'border-color:' . $read_more_border_color . ';';
                            $style_html .= 'border-width:' . $read_more_border_width . 'px;';
                        }

                        if (! empty($read_more_text_decoration)) {
                            $style_html .= 'text-decoration:' . $read_more_text_decoration . ';';
                        }

                        if ($read_more_padding_enabled) {
                            $style_html .= 'padding-top:' . $read_more_padding_top . 'px;';
                            $style_html .= 'padding-bottom:' . $read_more_padding_bottom . 'px;';
                            $style_html .= 'padding-right:' . $read_more_padding_right . 'px;';
                            $style_html .= 'padding-left:' . $read_more_padding_left . 'px;';
                        }

                        $style_html .= '}';
                    }

                    // Read more hover
                    if (
                        ! empty($read_more_text_color_h)
                        || ! empty($read_more_bg_color_h)
                        || $read_more_border_style !== 'none'
                        || ! empty($read_more_text_decoration_h)
                    ) {
                        $style_html .= '.' . $block_class . '.advgb-recent-posts-block .advgb-recent-posts .advgb-recent-post .advgb-post-readmore a:hover,';
                        $style_html .= '.' . $block_class . '.advgb-recent-posts-block .advgb-recent-posts .advgb-recent-post .advgb-post-readmore a:focus,';
                        $style_html .= '.' . $block_class . '.advgb-recent-posts-block .advgb-recent-posts .advgb-recent-post .advgb-post-readmore a:active {';

                        if (! empty($read_more_text_color_h)) {
                            $style_html .= 'color:' . $read_more_text_color_h . ' !important;';
                        }

                        if (! empty($read_more_bg_color_h)) {
                            $style_html .= 'background:' . $read_more_bg_color_h . ';';
                        }

                        if (! empty($read_more_text_decoration_h)) {
                            $style_html .= 'text-decoration:' . $read_more_text_decoration_h . ';';
                        }

                        if ($read_more_border_style !== 'none') {
                            $style_html .= 'border-color:' . $read_more_border_color_h . ';';
                        }

                        $style_html .= '}';
                    }
                }

                // Featured image
                if ($image_size_enabled) {
                    $image_size_force = $image_size_force == true ? ' !important' : '';
                    $style_html       .= '.' . $block_class . '.advgb-recent-posts-block .advgb-recent-posts .advgb-recent-post .advgb-post-thumbnail img {';
                    $style_html       .= 'height:' . ( ! $image_height || $image_height_auto ? 'auto' . $image_size_force : $image_height . 'px' . $image_size_force ) . ';';
                    $style_html       .= 'width:' . ( ! $image_width || $image_width_auto ? 'auto' . $image_size_force : $image_width . $image_width_unit . $image_size_force ) . ';';
                    $style_html       .= '}';
                }

                return $style_html;
                break;

            case 'advgb/list':
                $block_class = esc_html($attributes['id']);
                $text_color  = isset($attributes['textColor']) ? esc_html($attributes['textColor']) : '';

                $style_html = '';

                if (! empty($text_color)) {
                    $style_html .= '.' . $block_class . ' > li {';
                    $style_html .= 'color:' . $text_color . ';';
                    $style_html .= '}';
                }

                return $style_html;
                break;

            case 'advgb/count-up':
                if (! isset($attributes['id'])) {
                    return;
                }

                $block_class      = esc_html($attributes['id']);
                $header_size      = isset($attributes['headerSize']) ? esc_html(intval($attributes['headerSize'])) : '';
                $description_size = isset($attributes['descriptionSize']) ? esc_html(intval($attributes['descriptionSize'])) : '';
                $align            = isset($attributes['align']) ? esc_html($attributes['align']) : '';

                $style_html = '';

                if (! empty($header_size)) {
                    $style_html .= '.' . $block_class . ' .advgb-count-up-header {';
                    $style_html .= 'font-size:' . $header_size . 'px;';
                    $style_html .= '}';
                }

                if (! empty($description_size)) {
                    $style_html .= '.' . $block_class . ' .advgb-count-up-desc {';
                    $style_html .= 'font-size:' . $description_size . 'px;';
                    $style_html .= '}';
                }

                if (! empty($align)) {
                    $style_html .= '.' . $block_class . '.advgb-count-up > div {';
                    $style_html .= 'text-align:' . $align . ';';
                    $style_html .= '}';
                }

                return $style_html;
                break;

            case 'advgb/testimonial':
                $block_id         = esc_html($attributes['pid']);
                $name_size        = isset($attributes['nameSize']) ? esc_html(intval($attributes['nameSize'])) : '';
                $position_size    = isset($attributes['positionSize']) ? esc_html(intval($attributes['positionSize'])) : '';
                $description_size = isset($attributes['descriptionSize']) ? esc_html(intval($attributes['descriptionSize'])) : '';
                $align            = isset($attributes['align']) ? esc_html($attributes['align']) : '';

                $style_html = '';

                if (! empty($name_size)) {
                    $style_html .= '#' . $block_id . ' .advgb-testimonial .advgb-testimonial-name {';
                    $style_html .= 'font-size:' . $name_size . 'px;';
                    $style_html .= '}';
                }

                if (! empty($position_size)) {
                    $style_html .= '#' . $block_id . ' .advgb-testimonial .advgb-testimonial-position {';
                    $style_html .= 'font-size:' . $position_size . 'px;';
                    $style_html .= '}';
                }

                if (! empty($description_size)) {
                    $style_html .= '#' . $block_id . ' .advgb-testimonial .advgb-testimonial-desc {';
                    $style_html .= 'font-size:' . $description_size . 'px;';
                    $style_html .= '}';
                }

                if (! empty($align)) {
                    $style_html .= '#' . $block_id . ' .advgb-testimonial .advgb-testimonial-item {';
                    $style_html .= 'text-align:' . $align . ';';
                    $style_html .= '}';
                }

                return $style_html;
                break;

            case 'advgb/images-slider':
                if (! isset($attributes['id'])) {
                    return;
                }

                $style_html = '';

                $block_class          = esc_html($attributes['id']);
                $title_font_family    = isset($attributes['titleFontFamily']) ? esc_html($attributes['titleFontFamily']) : '';
                $title_font_variation = isset($attributes['titleFontVariation']) ? esc_html($attributes['titleFontVariation']) : '';
                $text_font_family     = isset($attributes['textFontFamily']) ? esc_html($attributes['textFontFamily']) : '';
                $text_font_variation  = isset($attributes['textFontVariation']) ? esc_html($attributes['textFontVariation']) : '';
                $title_show           = isset($attributes['titleShow']) ? esc_html($attributes['titleShow']) : true;

                // Title
                if (! empty($title_font_family) && $title_show) {
                    $style_html .= '.' . $block_class . ' .advgb-image-slider-item .advgb-image-slider-item-info .advgb-image-slider-title {';
                    $style_html .= self::advgb_pro_set_google_font_style($title_font_family, $title_font_variation);
                    $style_html .= '}';
                }

                // Text
                if (! empty($text_font_family)) {
                    $style_html .= '.' . $block_class . ' .advgb-image-slider-item .advgb-image-slider-item-info .advgb-image-slider-text {';
                    $style_html .= self::advgb_pro_set_google_font_style($text_font_family, $text_font_variation);
                    $style_html .= '}';
                }

                return $style_html;
                break;

            case 'advgb/adv-tabs':
                $block_class         = esc_html($attributes['pid']);
                $font_size           = isset($attributes['fontSize']) ? intval($attributes['fontSize']) : '';
                $font_family         = isset($attributes['fontFamily']) ? esc_html($attributes['fontFamily']) : '';
                $font_variation      = isset($attributes['fontVariation']) ? esc_html($attributes['fontVariation']) : '';
                $text_transform      = isset($attributes['textTransform']) ? esc_html($attributes['textTransform']) : '';
                $spacing_below       = isset($attributes['spacingBelow']) ? intval($attributes['spacingBelow']) : 8;
                $spacing_right       = isset($attributes['spacingRight']) ? intval($attributes['spacingRight']) : 8;
                $tabs_style_d        = isset($attributes['tabsStyleD']) ? esc_html($attributes['tabsStyleD']) : 'horz';
                $tabs_style_t        = isset($attributes['tabsStyleT']) ? esc_html($attributes['tabsStyleT']) : 'vert';
                $tabs_style_m        = isset($attributes['tabsStyleM']) ? esc_html($attributes['tabsStyleM']) : 'stack';
                $active_tab_bg_color = isset($attributes['activeTabBgColor']) ? esc_html($attributes['activeTabBgColor']) : '#5954d6';
                $border_color        = isset($attributes['borderColor']) ? esc_html($attributes['borderColor']) : '#e0e0e0';
                $border_width        = isset($attributes['borderWidth']) ? intval($attributes['borderWidth']) : 1;

                // Fixes empty "triangle" when making a border from right or bottom "invisible"
                $triangle_fix_global = 'content:"";display:block;position:absolute;';

                $triangle_fix = [];

                // Vertical
                $triangle_fix['vert'] = '.' . $block_class . ' ul.advgb-tabs-panel li.advgb-tab.advgb-tab-active:before{';
                $triangle_fix['vert'] .= $triangle_fix_global . 'width:' . $border_width . 'px;height:' . $border_width . 'px;background:' . $border_color . ';right:-' . $border_width . 'px;top:-' . $border_width . 'px;left:unset;bottom:unset;';
                $triangle_fix['vert'] .= '}';
                $triangle_fix['vert'] .= '.' . $block_class . ' ul.advgb-tabs-panel li.advgb-tab.advgb-tab-active:after{';
                $triangle_fix['vert'] .= $triangle_fix_global . 'width:' . $border_width . 'px;height:' . $border_width . 'px;background:' . $border_color . ';right:-' . $border_width . 'px;bottom:-' . $border_width . 'px;left:unset;top:unset;';
                $triangle_fix['vert'] .= '}';

                // Horizontal
                $triangle_fix['horz'] = '.' . $block_class . ' ul.advgb-tabs-panel li.advgb-tab.advgb-tab-active:before{';
                $triangle_fix['horz'] .= $triangle_fix_global . 'width:' . $border_width . 'px;height:' . $border_width . 'px;background:' . $border_color . ';left:-' . $border_width . 'px;bottom:-' . $border_width . 'px;right:unset;top:unset;';
                $triangle_fix['horz'] .= '}';
                $triangle_fix['horz'] .= '.' . $block_class . ' ul.advgb-tabs-panel li.advgb-tab.advgb-tab-active:after{';
                $triangle_fix['horz'] .= $triangle_fix_global . 'width:' . $border_width . 'px;height:' . $border_width . 'px;background:' . $border_color . ';right:-' . $border_width . 'px;bottom:-' . $border_width . 'px;left:unset;top:unset;';
                $triangle_fix['horz'] .= '}';

                $style_html = '';

                if (
                    ! empty($font_size)
                     || ! empty($text_transform)
                     || ! empty($font_family)
                     || $spacing_below !== 8
                     || $spacing_right !== 8
                ) {
                    $style_html .= '.' . $block_class . ' ul.advgb-tabs-panel li.advgb-tab {';

                    if (! empty($font_size)) {
                        $style_html .= 'font-size:' . $font_size . 'px;';
                    }

                    if (! empty($text_transform)) {
                        $style_html .= 'text-transform:' . $text_transform . ';';
                    }

                    if (! empty($font_family)) {
                        $style_html .= self::advgb_pro_set_google_font_style($font_family, $font_variation);
                        // Enqueue Google Font - @TODO - Move this to advgb_pro_set_google_font_style for all blocks
                        self::advgb_pro_get_google_font_stylesheet($font_family, $font_variation);
                    }

                    if ($spacing_below !== 8) {
                        $style_html .= 'margin-bottom:' . $spacing_below . 'px;';
                    }

                    if ($spacing_right !== 8) {
                        $style_html .= 'margin-right:' . $spacing_right . 'px;';
                    }

                    $style_html .= '}';
                }

                /* Desktop
                 * If margin-bottom or margin-right are negative,
                 * make the border-bottom-color or border-right-color same as bg
                 */
                if (
                    ( $spacing_below < 0
                       && $spacing_right >= 0
                       && $tabs_style_d === 'horz'
                     ) || ( $spacing_right < 0
                            && $spacing_below >= 0
                            && $tabs_style_d === 'vert'
                     )
                ) {
                    $style_html .= '.' . $block_class . ' ul.advgb-tabs-panel li.advgb-tab.advgb-tab-active {';

                    if ($spacing_below < 0 && $tabs_style_d === 'horz') {
                        $style_html .= 'border-bottom-color:' . $active_tab_bg_color . ' !important;';
                    }

                    // If  is negative, make the border-right-color same as bg
                    if ($spacing_right < 0 && $tabs_style_d === 'vert') {
                        $style_html .= 'border-right-color:' . $active_tab_bg_color . ' !important;';
                    }

                    $style_html .= '}';

                    // Fix empty "triangle" in border
                    if (array_key_exists($tabs_style_d, $triangle_fix)) {
                        $style_html .= $triangle_fix[ $tabs_style_d ];
                    }
                }

                /* Tablet
                 * If layout is vertical, we switch the margin-bottom and margin-right,
                 * and also switch the border-bottom-color and border-right-color
                 */
                if ($spacing_below < 0 || $spacing_right < 0) {
                    $style_html .= '@media screen and (max-width: 1023px) {';

                    if (
                        $tabs_style_d === 'horz' // Desktop
                         && $tabs_style_t === 'vert' // Tablet
                         && $spacing_below < 0
                         && $spacing_right >= 0
                    ) {
                        $style_html .= '.' . $block_class . ' ul.advgb-tabs-panel li.advgb-tab {';
                        $style_html .= 'margin-bottom:' . $spacing_right . 'px;';
                        $style_html .= 'margin-right:' . $spacing_below . 'px;';
                        $style_html .= '}';

                        $style_html .= '.' . $block_class . ' ul.advgb-tabs-panel li.advgb-tab.advgb-tab-active {';
                        $style_html .= 'border-right-color:' . $active_tab_bg_color . ' !important;';
                        $style_html .= 'border-bottom-color:' . $border_color . ' !important;';
                        $style_html .= '}';

                        // Fix empty "triangle" in border
                        $style_html .= $triangle_fix[ $tabs_style_t ];
                    } elseif (
                        $tabs_style_d === 'vert' // Desktop
                               && $tabs_style_t === 'horz' // Tablet
                               && $spacing_right < 0
                               && $spacing_below >= 0
                    ) {
                        $style_html .= '.' . $block_class . ' ul.advgb-tabs-panel li.advgb-tab {';
                        $style_html .= 'margin-bottom:' . $spacing_right . 'px;';
                        $style_html .= 'margin-right:' . $spacing_below . 'px;';
                        $style_html .= '}';

                        $style_html .= '.' . $block_class . ' ul.advgb-tabs-panel li.advgb-tab.advgb-tab-active {';
                        $style_html .= 'border-right-color:' . $border_color . ' !important;';
                        $style_html .= 'border-bottom-color:' . $active_tab_bg_color . ' !important;';
                        $style_html .= '}';

                        // Fix empty "triangle" in border
                        $style_html .= $triangle_fix[ $tabs_style_t ];
                    } else {
                        // Nothing to do here
                    }

                    $style_html .= '}';
                }

                /* Mobile
                 * If layout is vertical, we switch the margin-bottom and margin-right,
                 * and also switch the border-bottom-color and border-right-color
                 */
                if ($spacing_below < 0 || $spacing_right < 0) {
                    $style_html .= '@media screen and (max-width: 767px) {';

                    if (
                        $tabs_style_d === 'horz' // Desktop
                         && $tabs_style_m === 'vert' // Mobile
                         && $spacing_below < 0
                         && $spacing_right >= 0
                    ) {
                        $style_html .= '.' . $block_class . ' ul.advgb-tabs-panel li.advgb-tab {';
                        $style_html .= 'margin-bottom:' . $spacing_right . 'px;';
                        $style_html .= 'margin-right:' . $spacing_below . 'px;';
                        $style_html .= '}';

                        $style_html .= '.' . $block_class . ' ul.advgb-tabs-panel li.advgb-tab.advgb-tab-active {';
                        $style_html .= 'border-right-color:' . $active_tab_bg_color . ' !important;';
                        $style_html .= 'border-bottom-color:' . $border_color . ' !important;';
                        $style_html .= '}';

                        // Fix empty "triangle" in border
                        $style_html .= $triangle_fix['vert'];
                    } elseif (
                        $tabs_style_d === 'horz' // Desktop
                               && $tabs_style_m === 'horz' // Mobile
                               && $spacing_below < 0
                               && $spacing_right >= 0
                    ) {
                        $style_html .= '.' . $block_class . ' ul.advgb-tabs-panel li.advgb-tab {';
                        $style_html .= 'margin-bottom:' . $spacing_below . 'px;';
                        $style_html .= 'margin-right:' . $spacing_right . 'px;';
                        $style_html .= '}';

                        $style_html .= '.' . $block_class . ' ul.advgb-tabs-panel li.advgb-tab.advgb-tab-active {';
                        $style_html .= 'border-right-color:' . $border_color . ' !important;';
                        $style_html .= 'border-bottom-color:' . $active_tab_bg_color . ' !important;';
                        $style_html .= '}';

                        // Fix empty "triangle" in border
                        $style_html .= $triangle_fix['horz'];
                    } elseif (
                        $tabs_style_d === 'vert' // Desktop
                               && $tabs_style_m === 'vert' // Mobile
                               && $spacing_below >= 0
                               && $spacing_right < 0
                    ) {
                        $style_html .= '.' . $block_class . ' ul.advgb-tabs-panel li.advgb-tab {';
                        $style_html .= 'margin-bottom:' . $spacing_below . 'px;';
                        $style_html .= 'margin-right:' . $spacing_right . 'px;';
                        $style_html .= '}';

                        $style_html .= '.' . $block_class . ' ul.advgb-tabs-panel li.advgb-tab.advgb-tab-active {';
                        $style_html .= 'border-right-color:' . $active_tab_bg_color . ' !important;';
                        $style_html .= 'border-bottom-color:' . $border_color . ' !important;';
                        $style_html .= '}';

                        // Fix empty "triangle" in border
                        $style_html .= $triangle_fix['vert'];
                    } elseif (
                        $tabs_style_d === 'vert' // Desktop
                               && $tabs_style_m === 'horz' // Mobile
                               && $spacing_right < 0
                               && $spacing_below >= 0
                    ) {
                        $style_html .= '.' . $block_class . ' ul.advgb-tabs-panel li.advgb-tab {';
                        $style_html .= 'margin-bottom:' . $spacing_right . 'px;';
                        $style_html .= 'margin-right:' . $spacing_below . 'px;';
                        $style_html .= '}';

                        $style_html .= '.' . $block_class . ' ul.advgb-tabs-panel li.advgb-tab.advgb-tab-active {';
                        $style_html .= 'border-right-color:' . $border_color . ' !important;';
                        $style_html .= 'border-bottom-color:' . $active_tab_bg_color . ' !important;';
                        $style_html .= '}';

                        // Fix empty "triangle" in border
                        $style_html .= $triangle_fix['horz'];
                    } elseif (
                        $tabs_style_m === 'stack' // Mobile
                               && ( ( $spacing_below < 0 && $spacing_right >= 0 )
                                    || ( $spacing_right < 0 && $spacing_below >= 0 )
                               )
                    ) {
                        $style_html .= '.' . $block_class . ' ul.advgb-tabs-panel li.advgb-tab {';
                        $style_html .= 'margin-bottom:0px;';
                        $style_html .= 'margin-right:0px;';
                        $style_html .= '}';

                        $style_html .= '.' . $block_class . ' ul.advgb-tabs-panel li.advgb-tab.advgb-tab-active {';
                        $style_html .= 'border-right-color:' . $border_color . ' !important;';
                        $style_html .= 'border-bottom-color:' . $border_color . ' !important;';
                        $style_html .= '}';
                    } else {
                        // Nothing to do here
                    }

                    $style_html .= '}';
                }

                return $style_html;
                break;

            case 'advgb/accordions':
                $block_class    = esc_html($attributes['id']);
                $header_size    = isset($attributes['headerSize']) ? esc_html(intval($attributes['headerSize'])) : '';
                $font_family    = isset($attributes['fontFamily']) ? esc_html($attributes['fontFamily']) : '';
                $font_variation = isset($attributes['fontVariation']) ? esc_html($attributes['fontVariation']) : '';
                $text_transform = isset($attributes['textTransform']) ? esc_html($attributes['textTransform']) : '';

                $style_html = '';

                if (
                    ! empty($header_size)
                     || ! empty($text_transform)
                     || ! empty($font_family)
                ) {
                    $style_html .= '.' . $block_class . ' .advgb-accordion-header-title {';

                    if (! empty($header_size)) {
                        $style_html .= 'font-size:' . $header_size . 'px !important;';
                    }

                    if (! empty($text_transform)) {
                        $style_html .= 'text-transform:' . $text_transform . ';';
                    }

                    if (! empty($font_family)) {
                        $style_html .= self::advgb_pro_set_google_font_style($font_family, $font_variation);
                        // Enqueue Google Font - @TODO - Move this to advgb_pro_set_google_font_style for all blocks
                        self::advgb_pro_get_google_font_stylesheet($font_family, $font_variation);
                    }

                    $style_html .= '}';
                }

                return $style_html;
                break;

            case 'core/paragraph':
            case 'core/heading':
                if (! isset($attributes['advgbClass']) || self::advgb_pro_setting_is_enabled('enable_core_blocks_features') == false) {
                    return;
                }

                $style_html = '';

                $block_class    = esc_html($attributes['advgbClass']);
                $font_family    = isset($attributes['fontFamily']) ? esc_html($attributes['fontFamily']) : '';
                $font_variation = isset($attributes['fontVariation']) ? esc_html($attributes['fontVariation']) : '';
                $style_force    = isset($attributes['styleForce']) ? esc_html($attributes['styleForce']) : false;

                if (! empty($font_family)) {
                    $style_html .= '.' . $block_class . ' {';
                    $style_html .= self::advgb_pro_set_google_font_style($font_family, $font_variation, $style_force);
                    $style_html .= '}';
                    self::advgb_pro_enqueue_font_styles_frontend(
                        'core-blocks',
                        $attributes 
                    ); // core-blocks means: core/paragraph and core/heading
                }

                return $style_html;
                break;

            default:
                // Nothing to do here
                break;
        }
    }

    /**
     * Define font-family, font-weight and font-style properties - Content Display block
     *
     * @since 2.13.0
     *
     * return void
     */
    public static function advgb_pro_set_google_font_style($font_family, $font_variation, $style_force = false)
    {
        $style       = '';
        $style_force = $style_force == true ? ' !important' : '';

        // Split fontVariation value to adapt to font-style and font-weight CSS properties
        if (! empty($font_variation)) {
            if (strpos($font_variation, 'italic') !== false && strlen($font_variation) > 6) {
                $v     = explode('italic', $font_variation);
                $style = 'font-weight:' . $v[0] . $style_force . '; font-style: italic' . $style_force . ';';
            } elseif (strlen($font_variation) > 0) {
                $style = 'font-weight:' . $font_variation . $style_force . ';';
            } else {
                $style = '';
            }
        }

        if (! empty($font_family) && strlen($font_family) > 0) {
            return 'font-family:"' . $font_family . '"' . $style_force . ';' . $style;
        }
    }

    /**
     * Enqueue Google Font styles
     *
     * @since 2.13.0
     *
     * return void
     */
    public static function advgb_pro_get_google_font_stylesheet($font_family, $font_variation)
    {
        if (! empty($font_family)) {
            $google_font_variation = '';
            // Extract font-weight and font-style from variation. e.g. 400italic -> 400
            if (! empty($font_variation)) {
                if (strpos($font_variation, 'italic') !== false) {
                    $v = explode('italic', $font_variation);
                    if (strlen($v[0]) > 0) {
                        $google_font_variation = ':ital,wght@1,' . $v[0];
                    } else {
                        $google_font_variation = ':ital@1';
                    }
                } else {
                    $google_font_variation = ':wght@' . $font_variation;
                }
            }

            $google_font_url = 'https://fonts.googleapis.com/css2?family=' . str_replace(
                ' ',
                '+',
                $font_family 
            ) . $google_font_variation;
            $google_font_id  = 'advgb_google_font_' . str_replace(' ', '_', strtolower($font_family))
                               . ( strlen($font_variation) > 0 ? '_' . $font_variation : '' );
            wp_enqueue_style(
                $google_font_id,
                $google_font_url,
                array(),
                null
            );
        }
    }

    /**
     * Enqueue all Google Font styles
     *
     * @since 2.13.0
     *
     * return void
     */
    public static function advgb_pro_enqueue_font_styles_frontend($blockType, $blockAttrs)
    {
        switch ($blockType) {
            case 'advgb/recent-posts':
                // Title Google Font
                $titleFontFamily    = isset($blockAttrs['titleFontFamily']) ? esc_html($blockAttrs['titleFontFamily']) : '';
                $titleFontVariation = isset($blockAttrs['titleFontVariation']) ? esc_html($blockAttrs['titleFontVariation']) : '';
                self::advgb_pro_get_google_font_stylesheet($titleFontFamily, $titleFontVariation);
                // Info Google Font
                $infoFontFamily    = isset($blockAttrs['infoFontFamily']) ? esc_html($blockAttrs['infoFontFamily']) : '';
                $infoFontVariation = isset($blockAttrs['infoFontVariation']) ? esc_html($blockAttrs['infoFontVariation']) : '';
                self::advgb_pro_get_google_font_stylesheet($infoFontFamily, $infoFontVariation);
                // Taxonomy Google Font
                $taxonomyFontFamily    = isset($blockAttrs['taxonomyFontFamily']) ? esc_html($blockAttrs['taxonomyFontFamily']) : '';
                $taxonomyFontVariation = isset($blockAttrs['taxonomyFontVariation']) ? esc_html($blockAttrs['taxonomyFontVariation']) : '';
                self::advgb_pro_get_google_font_stylesheet($taxonomyFontFamily, $taxonomyFontVariation);
                // Content Google Font
                $contentFontFamily    = isset($blockAttrs['contentFontFamily']) ? esc_html($blockAttrs['contentFontFamily']) : '';
                $contentFontVariation = isset($blockAttrs['contentFontVariation']) ? esc_html($blockAttrs['contentFontVariation']) : '';
                self::advgb_pro_get_google_font_stylesheet($contentFontFamily, $contentFontVariation);
                // Read More Google Font
                $readMoreFontFamily    = isset($blockAttrs['readMoreFontFamily']) ? esc_html($blockAttrs['readMoreFontFamily']) : '';
                $readMoreFontVariation = isset($blockAttrs['readMoreFontVariation']) ? esc_html($blockAttrs['readMoreFontVariation']) : '';
                self::advgb_pro_get_google_font_stylesheet($readMoreFontFamily, $readMoreFontVariation);
                break;

            case 'advgb/images-slider':
                // Title Google Font
                $titleShow = isset($blockAttrs['titleShow']) ? esc_html($blockAttrs['titleShow']) : true;
                if ($titleShow) {
                    $titleFontFamily    = isset($blockAttrs['titleFontFamily']) ? esc_html($blockAttrs['titleFontFamily']) : '';
                    $titleFontVariation = isset($blockAttrs['titleFontVariation']) ? esc_html($blockAttrs['titleFontVariation']) : '';
                    self::advgb_pro_get_google_font_stylesheet($titleFontFamily, $titleFontVariation);
                }
                // Text Google Font
                $textFontFamily    = isset($blockAttrs['textFontFamily']) ? esc_html($blockAttrs['textFontFamily']) : '';
                $textFontVariation = isset($blockAttrs['textFontVariation']) ? esc_html($blockAttrs['textFontVariation']) : '';
                self::advgb_pro_get_google_font_stylesheet($textFontFamily, $textFontVariation);
                break;

            case 'advgb/button':
                $fontFamily    = isset($blockAttrs['fontFamily']) ? esc_html($blockAttrs['fontFamily']) : '';
                $fontVariation = isset($blockAttrs['fontVariation']) ? esc_html($blockAttrs['fontVariation']) : '';
                self::advgb_pro_get_google_font_stylesheet($fontFamily, $fontVariation);
                break;

            case 'advgb/adv-tabs':
                $fontFamily    = isset($blockAttrs['fontFamily']) ? esc_html($blockAttrs['fontFamily']) : '';
                $fontVariation = isset($blockAttrs['fontVariation']) ? esc_html($blockAttrs['fontVariation']) : '';
                self::advgb_pro_get_google_font_stylesheet($fontFamily, $fontVariation);
                break;

            case 'core-blocks': // core-blocks means: core/paragraph and core/heading
                $font = self::advgb_pro_get_google_font_attrs($blockAttrs);
                self::advgb_pro_get_google_font_stylesheet($font['family'], $font['variation']);
                break;

            default:
                // Nothing to do here
                break;
        }
    }

    /**
     * Return Google Font attributes for core blocks
     *
     * @since 2.13.1
     *
     * return array
     */
    public static function advgb_pro_get_google_font_attrs($blockAttrs)
    {
        $font              = array();
        $font['family']    = isset($blockAttrs['fontFamily']) ? esc_html($blockAttrs['fontFamily']) : '';
        $font['variation'] = isset($blockAttrs['fontVariation']) ? esc_html($blockAttrs['fontVariation']) : '';

        return $font;
    }

    /**
     * Enqueue styles for frontend - Advanced Button block
     *
     * @since 2.11.6
     *
     * return void
     */
    public static function advgb_pro_enqueue_styles_frontend_advbutton()
    {
        wp_enqueue_style('material_icon_font');
    }

    /**
     * Load scripts for Customizer > Widgets
     *
     * @since 2.9.0
     *
     * return void
     */
    public static function advgb_pro_widgets_customizer_frontend()
    {
        wp_enqueue_script(
            'advgb_widgets_customizer_pro_js',
            plugins_url('assets/js/widgets-customizer.js', dirname(__FILE__)),
            array( 'advgb_countdown_scripts' ),
            ADVANCED_GUTENBERG_PRO_VERSION
        );
    }

    /**
     * Set javascript for blocks in frontend
     *
     * @since 2.11.5
     *
     * return void
     */
    public static function advgb_pro_inline_scripts_frontend($block, $attributes = false)
    {
        switch ($block) {
            case 'advgb/accordion-item':
                wp_enqueue_script(
                    'adv_accordion_extra_js',
                    plugins_url('assets/blocks/advaccordion/script.min.js', dirname(__FILE__)),
                    array( 'adv_accordion_js' ),
                    ADVANCED_GUTENBERG_PRO_VERSION
                );
                break;

            case 'advgb/adv-tabs':
                wp_enqueue_script(
                    'adv_tabs_extra_js',
                    plugins_url('assets/blocks/advtabs/script.min.js', dirname(__FILE__)),
                    array( 'advgb_tabs_js' ),
                    ADVANCED_GUTENBERG_PRO_VERSION
                );
                break;

            case 'advgb/images-slider':
                if (! isset($attributes['id'])) {
                    return;
                }

                $id            = esc_html($attributes['id']);
                $autoplay      = isset($attributes['autoplay']) ? esc_html($attributes['autoplay']) : false;
                $autoplaySpeed = isset($attributes['autoplaySpeed']) ? esc_html(intval($attributes['autoplaySpeed'])) : 3000;

                $script = '';

                if ($autoplay) {
                    $script .= 'jQuery(document).ready(function ( $ ) {';
                    $script .= '$(".' . $id . ' .advgb-images-slider.slick-initialized").slick("slickSetOption", "autoplay", true, true);';
                    $script .= '$(".' . $id . ' .advgb-images-slider.slick-initialized").slick("slickSetOption", "autoplaySpeed", ' . $autoplaySpeed . ', true);';
                    $script .= '});';
                }

                return $script;
                break;

            case 'advgb/recent-posts':
                if (! isset($attributes['id'])) {
                    return;
                }

                $id                  = esc_html($attributes['id']);
                $postView            = isset($attributes['postView']) ? esc_html($attributes['postView']) : 'grid';
                $sliderAutoplay      = isset($attributes['sliderAutoplay']) ? esc_html($attributes['sliderAutoplay']) : false;
                $sliderAutoplaySpeed = isset($attributes['sliderAutoplaySpeed']) ? esc_html(intval($attributes['sliderAutoplaySpeed'])) : 3000;

                $script = '';

                if ($postView === 'slider' && $sliderAutoplay) {
                    $script .= 'jQuery(document).ready(function ( $ ) {';
                    $script .= '$(".' . $id . '.advgb-recent-posts-block.slider-view .advgb-recent-posts.slick-initialized").slick("slickSetOption", "autoplaySpeed", ' . $sliderAutoplaySpeed . ', true);';
                    $script .= '});';
                }

                return $script;
                break;

            default:
                // Nothing to do here
                break;
        }
    }

    /**
     * Load fonts in admin
     *
     * @since 2.13.0
     *
     * return void
     */
    public static function advgb_pro_fonts_list()
    {
        $google_fonts       = __DIR__ . '/../assets/blocks/0-adv-components/google_fonts.php';
        $google_fonts_names = __DIR__ . '/../assets/blocks/0-adv-components/google_fonts_names.php';
        wp_localize_script(
            'wp-blocks',
            'advgbFonts',
            array(
                'google_fonts'       => file_exists($google_fonts) ? include $google_fonts : array(),
                'google_fonts_names' => file_exists($google_fonts_names) ? include $google_fonts_names : array(),
            )
        );
    }

    /**
     * Receives a valid timezone string and returns a timezone object
     *
     * @param string $timezone e.g. 'America/Mexico_City'
     *
     * return object
     *
     * @since 3.1.4
     *
     */
    public static function advgb_pro_set_timezone($timezone = '')
    {
        if (! empty($timezone) && in_array($timezone, self::advgb_pro_timezones_list())) {
            return new \DateTimeZone($timezone);
        } else {
            return wp_timezone();
        }
    }

    /**
     * Receives a list of timezones
     *
     * @since 3.1.4
     *
     * return object
     */
    public static function advgb_pro_timezones_list()
    {
        $timezones      = timezone_identifiers_list();
        $manual_offsets = [
            '-12:00',
            '-11:30',
            '-11:00',
            '-10:30',
            '-10:00',
            '-09:30',
            '-09:00',
            '-08:30',
            '-08:00',
            '-07:30',
            '-07:00',
            '-06:30',
            '-06:00',
            '-05:30',
            '-05:00',
            '-04:30',
            '-04:00',
            '-03:30',
            '-03:00',
            '-02:30',
            '-02:00',
            '-01:30',
            '-01:00',
            '-00:30',
            '+00:00',
            '+00:30',
            '+01:00',
            '+01:30',
            '+02:00',
            '+02:30',
            '+03:00',
            '+03:30',
            '+04:00',
            '+04:30',
            '+05:00',
            '+05:30',
            '+05:45',
            '+06:00',
            '+06:30',
            '+07:00',
            '+07:30',
            '+08:00',
            '+08:30',
            '+08:45',
            '+09:00',
            '+09:30',
            '+10:00',
            '+10:30',
            '+11:00',
            '+11:30',
            '+12:00',
            '+12:45',
            '+13:00',
            '+13:45',
            '+14:00'
        ];

        return array_merge($timezones, $manual_offsets);
    }
}
