<?php
    /**
     * Animation / Hover effects Section
     * 
     * @package Blog Bee
     * @since 1.0.0
     */
    namespace BBE\Customizer\Section;

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

    use function esc_html__;

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

            /**
             * Register controls
             * 
             * @since 1.0.0
             */
            public function register_controls() {
                $this->add_section( 'hover_effects_section' );
                $this->add_control( 'hover_effects_post_title_hover' );
                $this->add_control( 'hover_effects_image_hover' );
                $this->add_control( 'hover_effects_cursor_animation' );
            }

            /**
             * Settings
             * 
             * @since 1.0.0
             */
            public function get_settings( $id = '' ) {
                $settings = [
                    'hover_effects_post_title_hover' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_select' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'hover_effects_image_hover' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_select' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'hover_effects_cursor_animation' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_select' ],
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                ];
                return $id ? $settings[ $id ] : $settings;
            }

            /**
             * Controls
             * 
             * @since 1.0.0
             */
            public function get_controls( $id = '' ) {
                $controls = [
                    'hover_effects_section' =>  [
                        'title' =>  esc_html__( 'Animation / Hover Effects', 'blog-bee' ),
                        'panel' =>  'global_panel',
                        'priority'  =>  40
                    ],
                    'hover_effects_post_title_hover' =>  [
                        'label' =>  esc_html__( 'Post Title Hover Effects', 'blog-bee' ),
                        'description' => esc_html__( 'Applied to post titles listed in archive pages.', 'blog-bee' ),
                        'type'  =>  'bbe-select',
                        'choices'    =>  [
                            'none' => esc_html__( 'None', 'blog-bee' ),
                            'one'  => esc_html__( 'Text color', 'blog-bee' ),
                            'two'  => esc_html__( 'Underline', 'blog-bee' ),  
                        ]
                    ],
                    'hover_effects_image_hover' =>  [
                        'label' =>  esc_html__( 'Image Hover Effects', 'blog-bee' ),
                        'description' => esc_html__( 'Applied to post thumbanails listed in archive pages.', 'blog-bee' ),
                        'type'  =>  'bbe-select',
                        'choices'    =>  [
                            'none' => esc_html__( 'None', 'blog-bee' ),
                            'one'  => esc_html__( 'Rise', 'blog-bee' ),
                            'two'  => esc_html__( 'Zoom', 'blog-bee' ),
                        ]
                    ],
                    'hover_effects_cursor_animation' =>  [
                        'label' =>  esc_html__( 'Cursor Animation', 'blog-bee' ),
                        'description' => esc_html__( 'Applied to mouse pointer.', 'blog-bee' ),
                        'type'  =>  'bbe-select',
                        'choices'    =>  [
                            'none' => esc_html__( 'None', 'blog-bee' ),
                            'two'  => esc_html__( 'Animation 1', 'blog-bee' ),
                        ]
                    ],
                ];
                return $id ? $controls[ $id ] : $controls;
            }

            /**
             * Defaults
             * 
             * @since 1.0.0
             */
            public function set_defaults() {
                Theme_Defaults::update_theme_defaults( [
                    'hover_effects_post_title_hover'    =>  'one',
                    'hover_effects_image_hover' =>  'one',
                    'hover_effects_cursor_animation'    =>  'none',
                ] );
            }

            /**
             * Get dynamic css args
             * 
             * @since 1.0.0
             */
            public function get_dynamic_css_args(): array {
                $dynamic_args = [
                    'hover_effects_post_title_hover'    =>  [
                        'selector'  =>  'body',
                        'prefix'    =>  'post-title--'
                    ],
                    'hover_effects_image_hover' =>  [
                        'selector'  =>  'body',
                        'prefix'    =>  'image-hover--'
                    ],
                ];
                return $dynamic_args;
            }

            /**
             * Render HTML
             * 
             * @since 1.0.0
             */
            public function render_html() {
                $cursor = Theme_Defaults::get_theme_option( 'hover_effects_cursor_animation' );
                if( $cursor !== 'none' ) :
                    $block_class[] = 'cursor-animation';
                    $block_class[] = 'layout--' . $cursor;
                    echo '<div class="' . esc_attr( implode( ' ', $block_class ) ) . '"></div>';
                    if( $cursor === 'two' ) echo '<div class="cursor-dot"></div>';
                endif;
            }

            /**
             * Data attributes for aos animation
             * 
             * @since 1.0.0
             */
            public function get_aos_data_attributes() {
                return '';
            }
        }
        Hover_Effects::get_instance();
    }