<?php

if ( ! defined( 'ABSPATH' ) )
	exit; // Exit if accessed directly

use Elementor\Widget_Base;
use Elementor\Icons_Manager;

class Banae_Timeline extends Widget_Base {

	/**
	 * Get widget name.
	 *
	 * @return string Widget name.
	 */
	public function get_name() {
		return 'banae_timeline';
	}

	/**
	 * Get widget title.
	 *
	 * @return string Widget title.
	 */
	public function get_title() {
		return __( 'Timeline', 'banana-addons-for-elementor' );
	}

	/**
	 * Get widget icon.
	 *
	 * @return string Widget icon.
	 */
	public function get_icon() {
		return 'eicon-editor-list-ul';
	}

	/**
	 * Get widget categories.
	 *
	 * @return array Widget categories.
	 */
	public function get_categories() {
		return [ 'banana-addons-category' ];
	}

	/**
	 * Get widget keywords for search
	 * 
	 * @return string[]
	 */
	public function get_keywords() {
		return [ 'info', 'list', 'timeline' ];
	}

	/**
	 * Enqueue dependend styles
	 * 
	 * Retrieve the list of style dependencies the widget requires.
	 * 
	 * @return string[]
	 */
	public function get_style_depends() {
		return [ 'banae-timeline-style' ];
	}

	protected function is_dynamic_content(): bool {
		return false;
	}

	/**
	 * Register widget content controls
	 */
	protected function register_controls() {

		// Instantiate the control class
		require_once 'register-controls.php';

		// Call to the register controls method
		Banae_Timeline_Controls::add_register_controls( $this );

	}

	protected function render() {
		$settings = $this->get_settings_for_display();
		$style = sprintf( 'timeline-%s', $settings['timeline_style'] );

		?>

<div class="banae-timeline-wrap <?php echo esc_attr( $style ); ?>">

    <?php if ( $settings['list'] ) : ?>

    <?php foreach ( $settings['list'] as $item ) : ?>

    <?php $icon_class = $item['item_icon']['value']; ?>

    <div class="banae-timeline-block elementor-repeater-item-<?php echo esc_attr( $item['_id'] ); ?>">

        <?php if ( $item['item_icon'] && $style === 'timeline-style-3' ) : ?>
        <i class="banae-tl-icon <?php echo $icon_class; ?>"></i>
        <?php endif; ?>

        <div class="banae-tl-date">
            <?php echo esc_html( $item['list_time'] ); ?>
        </div>

        <div class="banae-tl-content">

            <div class="banae-tl-sm-date">
                <?php echo esc_html( $item['list_time'] ); ?>
            </div>

            <h2 class="banae-tl-heading"><?php echo esc_html( $item['list_title'] ); ?></h2>

            <?php echo $item['list_description']; ?>

            <?php if ( $item['list_button_text'] ) : ?>

            <?php
								if ( ! empty( $item['list_button_link']['url'] ) ) {
									$this->add_link_attributes( 'list_button_link', $item['list_button_link'] );
								}
								?>
            <a class="banae-timeline-button"
                <?php $this->print_render_attribute_string( 'list_button_link' ); ?>><?php echo esc_html( $item['list_button_text'] ); ?></a>

            <?php endif; ?>

        </div>
    </div>
    <?php endforeach; ?>

    <?php endif; ?>

</div>
<?php
	}

}