<?php
use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Repeater;

class Custom_Author_Big_Box extends Widget_Base {

    public function get_name() {
        return 'author_big_box';
    }

    public function get_title() {
        return 'Author Big Box';
    }

    public function get_icon() {
        return 'eicon-code';
    }

    public function get_categories() {
        return [ 'general' ];
    }

    public function get_script_depends() {
        return [ 'author' ];
    }

    protected function _register_controls() {

        $this->start_controls_section(
            'Box',
            [
                'label' => esc_html__( 'Box', 'elementor-addon' ),
            ]
        );

        $this->add_control(
            'author_image',
            [
                'label' => esc_html__( 'Image', 'elementor-addon' ),
                'type' => \Elementor\Controls_Manager::MEDIA,
                'default' => [
                    'url' => \Elementor\Utils::get_placeholder_image_src(),
                ],
            ]
        );

        $this->add_control(
            'author_name',
            [
                'label' => esc_html__( 'Name', 'elementor-addon' ),
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => esc_html__( 'Lorem ipsum', 'elementor-addon' ),
                'label_block' => true,
            ]
        );

        $this->add_control(
            'author_position',
            [
                'label' => esc_html__( 'Position', 'elementor-addon' ),
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => esc_html__( 'Lorem ipsum', 'elementor-addon' ),
                'label_block' => true,
            ]
        );

        $this->add_control(
            'author_content',
            [
                'label' => esc_html__( 'Text', 'elementor-addon' ),
                'type' => \Elementor\Controls_Manager::WYSIWYG,
                'default' => esc_html__( 'Lorem ipsum ...', 'elementor-addon' ),
            ]
        );

        $this->end_controls_section();
    }

    protected function render() {
        $settings = $this->get_settings_for_display();
        ?>
        <div class="box-row">
            <div class="box-col-1">
                <div class="box-img">
                    <?php if ( !empty( $settings['author_image']['url'] ) ) : ?>
                        <img src="<?php echo esc_url( $settings['author_image']['url'] ); ?>" alt="<?php echo esc_attr( $settings['author_name'] ); ?>">
                    <?php endif; ?>
                </div>
            </div>
            <div class="box-col-2">
                <div class="author-head">
                    <h2><?php echo esc_html( $settings['author_name'] ); ?></h2>
                    <h3><?php echo esc_html( $settings['author_position'] ); ?></h3>
                </div>
                <div class="author-content">
                    <?php echo wp_kses_post( $settings['author_content'] ); ?>
                </div>
            </div>
        </div>
        <?php
    }

}
