<?php
    /**
     * Web stories Section
     * 
     * @package Blog Bee
     * @since 1.0.0
     */
    namespace BBE\Customizer\Section;

    use BBE\Helpers as Helpers;
    use BBE\Query_Manager as Query_Manager;
    use BBE\Customizer\Section\Section as Section;
    use BBE\Customizer\Theme_Defaults as Theme_Defaults;

    use function esc_html__;
    use function get_posts;

    if( ! class_exists( __NAMESPACE__ . '\\Web_Stories' ) ) {
        /**
         * Web_Stories class
         */
        class Web_Stories extends Section {
            /**
             * Section Id
             * 
             * @since 1.0.0
             * @var string
             */
            public static $id = 'bbe-web-stories';

            /**
             * Ambient
             * 
             * @since 1.0.0
             */
            private $ambient = null;

            /**
             * Get ambient
             * 
             * @since 1.0.0
             */
            public function get_ambient() {
                if( $this->ambient === null ) {
                    $content_toggles = Theme_Defaults::get_theme_option( 'web_stories_slider_settings_toggles' );
                    $default_content_toggles = Theme_Defaults::get_defaults( 'web_stories_slider_settings_toggles' );
                    $this->ambient = isset( $content_toggles[ 'ambient' ] ) ? $content_toggles[ 'ambient' ] : $default_content_toggles[ 'ambient' ];
                }
                return $this->ambient;
            }

            /**
             * Section Id
             * 
             * @since 1.0.0
             * @var string
             */
            public function register_controls() {
                $this->add_section( 'web_stories_section' );
                $this->add_control( 'web_stories_section_tab' );
                $this->add_control( 'web_stories_type' );
                $this->add_control( 'web_stories_google_redirect' );
                $this->add_control( 'web_stories_notice' );
                $this->add_control( 'web_stories_section_label' );
                $this->add_control( 'web_stories_view_all_label' );
                $this->add_control( 'web_stories_container' );
                $this->add_control( 'web_stories_post_query_settings' );
                $this->add_control( 'web_stories_collection_categories_include' );
                $this->add_control( 'web_stories_number_of_posts' );
                $this->add_control( 'web_stories_max_inner_stories' );
                $this->add_control( 'web_stories_orderby' );
                $this->add_control( 'web_stories_hide_no_featured' );
                $this->add_control( 'web_stories_post_elements_settings' );
                $this->add_control( 'web_stories_post_elements_settings_in_slider' );
                $this->add_control( 'web_stories_content_toggles_in_slider' );
                $this->add_control( 'web_stories_image_settings' );
                $this->add_control( 'web_stories_image_sizes' );
                $this->tab = 'design';
                $this->add_control( 'web_stories_preview_count_typography' );
                $this->add_control( 'web_stories_preview_title_typography' );
                $this->add_control( 'web_stories_title_typography' );
            }

            /**
             * Settings
             * 
             * @since 1.0.0
             */
            public function get_settings( $id = '' ) {
                $settings = [
                    'web_stories_section_tab' =>  [
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'web_stories_type' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_select' ],
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'web_stories_google_redirect' =>  [
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'web_stories_notice' =>  [
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'web_stories_section_label' =>  [
                        'sanitize_callback' =>  'sanitize_text_field',
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'web_stories_view_all_label' =>  [
                        'sanitize_callback' =>  'sanitize_text_field',
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'web_stories_container' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_select' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'web_stories_post_query_settings' =>  [
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'web_stories_collection_categories_include' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_async_multiselect' ],
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'web_stories_number_of_posts' =>  [
                        'sanitize_callback' =>  'absint',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'web_stories_max_inner_stories' =>  [
                        'sanitize_callback' =>  'absint',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'web_stories_orderby' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_select' ],
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'web_stories_hide_no_featured' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_toggle' ],
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'web_stories_post_elements_settings' =>  [
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'web_stories_post_elements_settings_in_slider' =>  [
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'web_stories_content_toggles_in_slider' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_toggle_group' ],
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'web_stories_image_settings' =>  [
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'web_stories_image_sizes' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_select' ],
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'web_stories_preview_count_typography' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_typography' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'web_stories_preview_title_typography' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_typography' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'web_stories_title_typography' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_typography' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                ];
                return $id ? $settings[ $id ] : $settings;
            }

            /**
             * Controls
             * 
             * @since 1.0.0
             */
            public function get_controls( $id = '' ) {
                $type_condition = [
                    'relation'  =>  'AND',
                    'rules' =>  [
                        [
                            'setting' => 'web_stories_type',
                            'operator' => '==',
                            'value' => 'default'
                        ]
                    ]
                ];
                $controls = [
                    'web_stories_section' =>  [
                        'title' =>  esc_html__( 'Web Stories', 'blog-bee' ),
                        'active_callback'   =>  function() {
                            return Helpers::get_reorder_value( 'section_reorder_fields', 'web-stories' );
                        },
                        'section_to_open' =>  'section_reorder_section'
                    ],
                    'web_stories_section_tab' =>  [
                        'type'  =>  'section-tab',
                        'fields'  =>  Helpers::get_customizer_section_tabs()
                    ],
                    'web_stories_type' =>  [
                        'label' =>  esc_html__( 'Type', 'blog-bee' ),
                        'type'  =>  'bbe-select',
                        'choices'   =>  [
                            'default'   =>  esc_html__( 'Default', 'blog-bee' ),
                            'google'    =>  esc_html__( 'Google Web Stories', 'blog-bee' )
                        ]
                    ],
                    'web_stories_google_redirect'    =>  [
                        'label' =>  esc_html__( 'Edit plugin web stories.', 'blog-bee' ),
                        'type'  =>  'redirect',
                        'section_to_expand' =>  'web_story_options',
                        'conditions' =>  [
                            'relation'  =>  'AND',
                            'rules' =>  [
                                [
                                    'setting' => 'web_stories_type',
                                    'operator' => '==',
                                    'value' => 'google'
                                ]
                            ]
                        ]
                    ],
                    'web_stories_notice' =>  [
                        'label' =>  esc_html__( 'Please activate Google Web Stories plugin and refresh this page.', 'blog-bee' ),
                        'type'  =>  'notice',
                        'conditions' =>  [
                            'relation'  =>  'AND',
                            'rules' =>  [
                                [
                                    'setting' => 'web_stories_type',
                                    'operator' => '==',
                                    'value' => 'google'
                                ]
                            ]
                        ]
                    ],
                    'web_stories_section_label' =>  [
                        'label' =>  esc_html__( 'Section Label', 'blog-bee' ),
                        'type'  =>  'bbe-text',
                        'conditions'    =>  $type_condition,
                        'priority'  =>  20
                    ],
                    'web_stories_view_all_label' =>  [
                        'label' =>  esc_html__( 'View All', 'blog-bee' ),
                        'type'  =>  'bbe-text',
                        'conditions'    =>  $type_condition,
                        'priority'  =>  20
                    ],
                    'web_stories_container' =>  [
                        'label' =>  esc_html__( 'Container', 'blog-bee' ),
                        'type'  =>  'bbe-select',
                        'choices'    =>  Helpers::get_card_options(),
                        'conditions'    =>  $type_condition,
                        'priority'  =>  20
                    ],
                    'web_stories_post_query_settings' =>  [
                        'label' =>  esc_html__( 'Post Query Settings', 'blog-bee' ),
                        'type'  =>  'heading-toggle',
                        'conditions'    =>  $type_condition,
                        'priority'  =>  20
                    ],
                    'web_stories_collection_categories_include' =>  [
                        'label' =>  esc_html__( 'Categories to Include', 'blog-bee' ),
                        'type'  =>  'async-multiselect',
                        'endpoint'  =>  'get_taxonomy',
                        'purpose'   =>  'category',
                        'conditions'    =>  $type_condition,
                        'priority'  =>  20
                    ],
                    'web_stories_number_of_posts' =>  [
                        'label' =>  esc_html__( 'No of Categories To Show', 'blog-bee' ),
                        'type'  =>  'bbe-number',
                        'show_unit' =>  false,
                        'input_attrs'   =>  [
                            'min'   =>  1,
                            'max'   =>  15,
                            'step'  =>  1
                        ],
                        'conditions'    =>  $type_condition,
                        'priority'  =>  20
                    ],
                    'web_stories_max_inner_stories' =>  [
                        'label' =>  esc_html__( 'Max No of Inner Stories', 'blog-bee' ),
                        'type'  =>  'bbe-number',
                        'show_unit' =>  false,
                        'input_attrs'   =>  [
                            'min'   =>  0,
                            'max'   =>  20,
                            'step'  =>  1
                        ],
                        'conditions'    =>  $type_condition,
                        'priority'  =>  20
                    ],
                    'web_stories_orderby' =>  [
                        'label' =>  esc_html__( 'Order By', 'blog-bee' ),
                        'type'  =>  'bbe-select',
                        'choices'   =>  Helpers::get_order_by(),
                        'conditions'    =>  $type_condition,
                        'priority'  =>  20
                    ],
                    'web_stories_hide_no_featured' =>  [
                        'label' =>  esc_html__( 'Hide Stories With No Featured Image', 'blog-bee' ),
                        'type'  =>  'toggle-button',
                        'conditions'    =>  $type_condition,
                        'priority'  =>  20
                    ],
                    'web_stories_post_elements_settings' =>  [
                        'label' =>  esc_html__( 'Post Elements Settings', 'blog-bee' ),
                        'type'  =>  'heading-toggle',
                        'conditions'    =>  $type_condition,
                        'priority'  =>  20
                    ],
                    'web_stories_post_elements_settings_in_slider' =>  [
                        'label' =>  esc_html__( 'Slider Settings', 'blog-bee' ),
                        'type'  =>  'separator',
                        'conditions'    =>  $type_condition,
                        'priority'  =>  20
                    ],
                    'web_stories_content_toggles_in_slider' =>  [
                        'type'  =>  'toggle-button-group',
                        'fields'    =>  [
                            [
                                'label' =>  esc_html__( 'Title', 'blog-bee' ),
                                'id' =>  'title'
                            ],
                            [
                                'label' =>  esc_html__( 'Category', 'blog-bee' ),
                                'id' =>  'category'
                            ],
                            [
                                'label' =>  esc_html__( 'Date', 'blog-bee' ),
                                'id' =>  'date'
                            ],
                            [
                                'label' =>  esc_html__( 'Author', 'blog-bee' ),
                                'id' =>  'author'
                            ],
                        ],
                        'conditions'    =>  $type_condition,
                        'priority'  =>  20
                    ],
                    'web_stories_image_settings' =>  [
                        'label' =>  esc_html__( 'Image Settings', 'blog-bee' ),
                        'type'  =>  'heading-toggle',
                        'conditions'    =>  $type_condition,
                        'priority'  =>  20
                    ],
                    'web_stories_image_sizes' =>  [
                        'label' =>  esc_html__( 'Image Sizes', 'blog-bee' ),
                        'type'  =>  'bbe-select',
                        'choices'   =>  Helpers::get_customizer_image_sizes(),
                        'conditions'    =>  $type_condition,
                        'priority'  =>  20
                    ],
                    'web_stories_preview_count_typography' =>  [
                        'label' =>  esc_html__( 'Preview Count', 'blog-bee' ),
                        'type'  =>  'typography',
                    ],
                    'web_stories_preview_title_typography' =>  [
                        'label' =>  esc_html__( 'Preview Title', 'blog-bee' ),
                        'type'  =>  'typography',
                    ],
                    'web_stories_title_typography' =>  [
                        'label' =>  esc_html__( 'Title', 'blog-bee' ),
                        'type'  =>  'typography',
                    ],
                ];
                return $id ? $controls[ $id ] : $controls;
            }

            /**
             * Defaults
             * 
             * @since 1.0.0
             */
            public function set_defaults() {
                Theme_Defaults::update_theme_defaults( [
                    'web_stories_section_tab' =>  'general',
                    'web_stories_type' =>  'default',
                    'web_stories_google_redirect' =>  '',
                    'web_stories_notice' =>  '',
                    'web_stories_section_label' =>  'Web Stories',
                    'web_stories_view_option' =>  true,
                    'web_stories_view_all_label' =>  'View All',
                    'web_stories_close_modal_on_esc' =>  false,
                    'web_stories_container' =>  'default',
                    'web_stories_post_query_settings' =>  false,
                    'web_stories_collection_categories_include'    =>  [],
                    'web_stories_collection_categories_exclude'    =>  [],
                    'web_stories_number_of_posts' =>  5,
                    'web_stories_max_inner_stories' =>  5,
                    'web_stories_orderby' =>  'date-desc',
                    'web_stories_hide_no_featured' =>  true,
                    'web_stories_post_elements_settings' =>  false,
                    'web_stories_post_elements_settings_in_slider' =>  false,
                    'web_stories_content_toggles_in_slider'  =>  [
                        'title' =>  true,
                        'category'  =>  true,
                        'author'  =>  false,
                        'date'  =>  false,
                    ],
                    'web_stories_slider_settings' =>  false,
                    'web_stories_slider_settings_toggles'  =>  [
                        'arrows' =>  true,
                        'fade'  =>  true,
                        'autoplay'  =>  true,
                        'ambient'  =>  true,
                    ],
                    'web_stories_speed' =>  300,
                    'web_stories_image_settings' =>  '',
                    'web_stories_image_sizes' =>  'bbe_content_width',
                    'web_stories_image_ratio' =>  'wide',
                    'web_stories_width_layout' =>  'boxed',
                    'web_stories_preview_count_typography'    =>  $this->get_typography( [
                        'font_weight'   =>  '600',
                        'font_size' =>  $this->get_responsive( '11px', '11px', '11px' )
                    ] ),
                    'web_stories_preview_title_typography'    =>  $this->get_typography( [
                        'font_weight'   =>  '500',
                        'font_size' =>  $this->get_responsive( '18px', '18px', '18px' ),
                        'line_height'   =>  $this->get_responsive( 1.5, 1.5, 1.5 ),
                    ] ),
                    'web_stories_title_typography'    =>  $this->get_typography( [
                        'font_weight'   =>  '600',
                        'font_size' =>  $this->get_responsive( '24px', '24px', '24px' ),
                        'line_height'   =>  $this->get_responsive( 1.4, 1.4, 1.4 ),
                    ] ),
                ] );
            }

            /**
             * Get dynamic css args
             * 
             * @since 1.0.0
             */
            public function get_dynamic_css_args() {
                $dynamic_css = [
                    'web_stories_section_label'  =>  [
                        'selector'  =>  '.bbe-web-stories .section-head .label',
                        'parent'  =>  '.bbe-web-stories .section-head',
                    ],
                    'web_stories_view_all_label'  =>  [
                        'selector'  =>  '.bbe-web-stories .web-stories-view-all .label',
                        'parent'  =>  '.bbe-web-stories .web-stories-view-all',
                    ],
                    'web_stories_container'    =>  [
                        'selector'  =>  '.bbe-web-stories',
                        'prefix'    =>  'card--'
                    ],
                    'web_stories_preview_count_typography'  =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'web_stories_preview_count_typography' ),
                        'default'   =>  Theme_Defaults::get_defaults( 'web_stories_preview_count_typography' ),
                        'selector'  =>  '.bbe-web-stories .stories-wrap .preview .story-count',
                    ],
                    'web_stories_preview_title_typography'  =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'web_stories_preview_title_typography' ),
                        'default'   =>  Theme_Defaults::get_defaults( 'web_stories_preview_title_typography' ),
                        'selector'  =>  '.bbe-web-stories .stories-wrap .story-title',
                    ],
                    'web_stories_title_typography'  =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'web_stories_title_typography' ),
                        'default'   =>  Theme_Defaults::get_defaults( 'web_stories_title_typography' ),
                        'selector'  =>  '.bbe-web-stories .inner-stories-wrap .entry-inner .entry-title',
                    ],
                ];
                return $dynamic_css;
            }

            /**
             * Query instance
             * 
             * @since 1.0.0
             */
            private function get_query_instance() {
                $orderby = Theme_Defaults::get_theme_option( 'web_stories_orderby' );
                $include = Theme_Defaults::get_theme_option( 'web_stories_collection_categories_include' );
                $exclude = Theme_Defaults::get_theme_option( 'web_stories_collection_categories_exclude' );
                $exploded_orderby = explode( '-', $orderby );

                $category_args = [
                    'number'    =>  absint( Theme_Defaults::get_theme_option( 'web_stories_number_of_posts' ) ),
                    'max_no_of_inner_stories'    =>  absint( Theme_Defaults::get_theme_option( 'web_stories_max_inner_stories' ) ),
                    'hide_empty'    =>  Theme_Defaults::get_theme_option( 'web_stories_hide_no_featured' ),
                    'orderby'   =>  $exploded_orderby[ 1 ],
                    'order' =>  $exploded_orderby[ 0 ]
                ];

                if( ! empty( $include ) ) {
                    $category_args[ 'include' ] = array_map( 'absint', array_column( $include, 'value' ) );
                }

                $categories = get_categories( $category_args );

                if( ! empty( $exclude ) && is_array( $categories ) ) {
                    $exclude_ids = array_map( 'absint', array_column( $exclude, 'value' ) );
                    $categories = array_values( array_filter( $categories, function( $category ) use ( $exclude_ids ) {
                        return ! in_array( (int) $category->term_id, $exclude_ids, true );
                    } ) );
                }

                return $categories;
            }

            /**
             * Render HTML
             * 
             * @since 1.0.0
             */
            public function render_html() {
                $type = Theme_Defaults::get_theme_option( 'web_stories_type' );
                $is_google_type = apply_filters( 'blog_bee_web_stories_is_google_type_filter', ( $type === 'google' ) );
                
                $block_class[] = self::$id;
                $block_class[] = 'type--' . $type;
                if( ! $is_google_type ) {
                    if( empty( $this->get_query_instance() ) || ! is_array( $this->get_query_instance() ) ) return;   // guard

                    $block_class[] = 'card--' . Theme_Defaults::get_theme_option( 'web_stories_container' );
                    $block_class[] = 'ratio--' . Theme_Defaults::get_theme_option( 'web_stories_image_ratio' );
                    if( $this->get_ambient() ) $block_class[] = 'ambient';
                } else {
                    if( ! function_exists( '\Google\Web_Stories\render_theme_stories' ) ) return;   // guard
                }
                ?>
                    <section class="<?php echo esc_attr( implode( ' ', $block_class ) ); ?>" <?php Helpers::the_aos_data_attr(); ?>>
                        <div class="bbe-container">
                            <div class="row">
                                <?php
                                    if( $is_google_type ) :
                                        $this->get_google_web_stories();
                                    else :
                                        $this->get_web_stories();
                                    endif;
                                ?>
                            </div>
                        </div>
                    </section><!-- .bbe-web-stories -->
                <?php
            }

            /**
             * Get google web stories
             * 
             * @since 1.0.0
             */
            private function get_google_web_stories() {
                if( ! function_exists( '\Google\Web_Stories\render_theme_stories' ) ) return;
                \Google\Web_Stories\render_theme_stories();
            }

            /**
             * Get web stories
             * 
             * @since 1.0.0
             */
            private function get_web_stories() {
                $this->get_section_head();
                $categories = $this->get_query_instance();
                $web_stories_layout = 'two';
                $show_preview_count = true;
                $show_preview_title = true;

                $image_size = Theme_Defaults::get_theme_option( 'web_stories_image_sizes' );
                ?>
                <div class="full-stories-wrapper">
                    <div class="stories-wrap">
                        <?php
                            foreach( $categories as $cat_key => $cat_value ) :
                                
                                $category_query_args = [
                                    'cat'   =>  absint( $cat_value->term_id ),
                                    'post_type'   =>  'post',
                                    'post_status'   =>  'publish',
                                    'ignore_sticky_posts'   =>  true,
                                    'fields'    =>  'ids',
                                    'no_found_rows' =>  true,
                                    'update_post_meta_cache'    =>  false,
                                    'update_post_term_cache'    =>  false,
                                ];
                                $category_query = get_posts( $category_query_args, true );
                                $preview_title = '';
                                if( ! empty( $category_query ) && is_array( $category_query ) ) :
                                    $first_post = $category_query[ 0 ];
                                    $thumbnail_id = ( $first_post != null ) ? $first_post : '';
                                    $preview_title = get_the_title( $first_post );
                                else:
                                    continue;
                                    $thumbnail_id = '';
                                endif;
                                $category_count = $cat_value->count;

                                $template_part_args = [
                                    'cat_value' =>  $cat_value,
                                    'thumbnail_id'  =>  $thumbnail_id,
                                    'image_size'  =>  $image_size,
                                    'show_preview_count'    =>  $show_preview_count,
                                    'preview_title'    =>  $preview_title,
                                    'show_preview_title'    =>  $show_preview_title,
                                    'layout'    =>  $web_stories_layout
                                ];
                                get_template_part( 'template-parts/content', 'web-stories', $template_part_args );
                            endforeach;
                        ?>
                    </div>
                    <?php
                        if( $web_stories_layout !== 'two' ) :
                            echo '<button class="scroll-button left"></button>';
                            echo '<button class="scroll-button right"></button>';
                        endif;
                    ?>
                </div>
                <div class="inner-stories-wrap">
                    <div class="inner-stories"></div>
                    <?php if( $this->get_ambient() ) echo '<div class="ambient-wrapper"></div>'; ?>
                    <div class="action-buttons">
                        <button class="action-btn close"><i class="fa-solid fa-xmark"></i></button>
                        <button class="action-btn pause"><i class="fa-solid fa-pause"></i></button>
                    </div>
                    <div class="story-arrows">
                        <?php Helpers::get_slick_arrows( true, true ); ?>
                    </div>
                </div>
                <?php
            }

            /**
             * Get section head
             * 
             * @since 1.0.0
             */
            private function get_section_head() {
                $page = get_pages( [
                    'meta_key'  =>  '_wp_page_template',
                    'meta_value'    =>  'web-stories.php',
                    'number'    =>  1
                ] );
                $archive_link = '#';
                if( ! empty( $page ) ) $archive_link = get_permalink( $page[ 0 ]->ID );

                $view_all_option = apply_filters( 'blog_bee_web_stories_view_all_button_filter', Theme_Defaults::get_theme_option( 'web_stories_view_option' ) );
                $view_all_label = Theme_Defaults::get_theme_option( 'web_stories_view_all_label' );

                echo '<div class="section-head-wrap">';
                
                    Helpers::get_section_head( Theme_Defaults::get_theme_option( 'web_stories_section_label' ) );

                    if( $view_all_option ) : ?>
                        <a href="<?php echo esc_url( $archive_link ); ?>" class="view-all">
                            <?php
                                echo '<span class="label">' . esc_html( $view_all_label ) . '</span>';
                                $view_all_icon = [
                                    'type'  =>  'icon',
                                    'value'  =>  'fa-solid fa-chevron-right',
                                    'tag'  =>  'span',
                                    'aria_label'    =>  esc_html__( 'View all web stories', 'blog-bee' )
                                ];
                                echo Helpers::get_icon_html( $view_all_icon );
                            ?>
                        </a>
                    <?php endif;
                echo '</div>';
            }

            /**
             * is google filter
             * 
             * @since 1.0.0
             */
            public function is_google_filter( $value ) {
                return false;
            }

            /**
             * show / hide view all button filter
             * 
             * @since 1.0.0
             */
            public function view_all_button_filter( $value ) {
                return false;
            }
        }
        Web_Stories::get_instance();
    }