<?php
    /**
     * Author Box Section
     * 
     * @package Blog Bee Pro
     * @since 1.0.0
     */
    namespace BBE\Customizer\Section;

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

    use function esc_html__;
    use function esc_attr;

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

            /**
             * Register controls
             * 
             * @since 1.0.0
             */
            public function register_controls() {
            }

            /**
             * Settings
             * 
             * @since 1.0.0
             */
            public function get_settings( $id = '' ) {
                $settings = [
                ];
                return $id ? $settings[ $id ] : $settings;
            }

            /**
             * Controls
             * 
             * @since 1.0.0
             */
            public function get_controls( $id = '' ) {
                $controls = [];
                return $id ? $controls[ $id ] : $controls;
            }

            /**
             * Defaults
             * 
             * @since 1.0.0
             */
            public function set_defaults() {
                Theme_Defaults::update_theme_defaults( [
                    'author_box_layouts' =>  'default',
                    'author_box_content_toggles' =>  [
                        'image' =>  true,
                        'name'  =>  true,
                        'description'   =>  true,
                        'socials'   =>  true,
                    ],
                    'author_box_border_radius' =>  $this->get_dimension( [
                        'top'       =>  100,
                        'right'     =>  100,
                        'bottom'    =>  100,
                        'left'      =>  100,
                    ] ),
                ] );
            }

            /**
             * Get dynamic css args
             * 
             * @since 1.0.0
             */
            public function get_dynamic_css_args(): array {
                $dynamic_args = [
                ];
                return $dynamic_args;
            }

            /**
             * Render HTML
             * 
             * @since 1.0.0
             */
            public function render_html() {
                $content_toggles = Theme_Defaults::get_theme_option( 'author_box_content_toggles' );
                $default_content_toggles = Theme_Defaults::get_defaults( 'author_box_content_toggles' );
                $image = isset( $content_toggles[ 'image' ] ) ? $content_toggles[ 'image' ] : $default_content_toggles[ 'image' ];
                $name = isset( $content_toggles[ 'name' ] ) ? $content_toggles[ 'name' ] : $default_content_toggles[ 'name' ];
                $description = isset( $content_toggles[ 'description' ] ) ? $content_toggles[ 'description' ] : $default_content_toggles[ 'description' ];
                $socials = isset( $content_toggles[ 'socials' ] ) ? $content_toggles[ 'socials' ] : $default_content_toggles[ 'socials' ];

                $block_class[] = self::$id;
                $block_class[] = 'layout--' . Theme_Defaults::get_theme_option( 'author_box_layouts' );

                $author_id = get_the_author_meta( 'ID' );
                ?>

                    <div class="<?php echo esc_attr( implode( ' ', $block_class ) ); ?>" <?php Helpers::the_aos_data_attr(); ?>>

                        <?php

                            if( $image ) echo '<figure class="author-thumb">' . get_avatar( $author_id ) . '</figure>';

                            if( $name || $description ) :

                                echo '<div class="author-elements">';

                                    if( $name ) echo '<h2 class="author-name"><a href="' . esc_url( get_author_posts_url( $author_id ) ) . '">' . get_the_author() . '</a></h2>';

                                    if( $description && ! empty( get_the_author_meta( 'description' ) ) ) echo '<div class="author-desc">' . get_the_author_meta( 'description' ) . '</div>';

                                    if( $socials ) :

                                        echo '<div class="author-socials">';

                                            Helpers::get_author_socials( $author_id );

                                        echo '</div>';

                                    endif;

                                echo '</div>';

                            endif;
                            
                        ?>

                    </div>

                <?php 
            }
        }
        Author_Box::get_instance();
    }