<?php
namespace Elementor;

/**
 * Elementor Widget
 * @package Geroz
 * @since 1.0.0
 */ 
 
class Service_Sidebar extends Widget_Base {

	/**
	 * Get widget name.
	 * Retrieve button widget name.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return string Widget name.
	 */
	public function get_name() {
		return 'geroz-service-sidebar-widget';
	}

	/**
	 * Get widget title.
	 * Retrieve button widget title.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return string Widget title.
	 */
	public function get_title() {
		return esc_html__( 'Service Sidebar', 'geroz-core' );
	}

	/**
	 * Get widget icon.
	 * Retrieve button widget icon.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return string Widget icon.
	 */
	public function get_icon() {
		return 'eicon-flash';
	}

	/**
	 * Get widget categories.
	 * Retrieve the list of categories the button widget belongs to.
	 * Used to determine where to display the widget in the editor.
	 *
	 * @since  2.0.0
	 * @access public
	 * @return array Widget categories.
	 */
	public function get_categories()
    {
        return ['geroz_widgets'];
    }
	
	/**
	 * Register button widget controls.
	 * Adds different input fields to allow the user to change and customize the widget settings.
	 *
	 * @since  1.0.0
	 * @access protected
	 */
	protected function register_controls() {

		$this->start_controls_section(
			'service_sidebar_content',
			[
				'label' => __( 'Sidebar Content', 'geroz-core' ),
				'tab'   => Controls_Manager::TAB_CONTENT,
			]
		);

		$this->add_control(
			'sidebar_title',
			[
				'label'   => __( 'Sidebar Title', 'geroz-core' ),
				'type'    => Controls_Manager::TEXT,
				'default' => esc_html__( 'Our Services', 'geroz-core' ),
			]
		);

		$repeater = new \Elementor\Repeater();

		$repeater->add_control(
			'section_title',
			[
				'label'   => __( 'Service Title', 'geroz-core' ),
				'type'    => Controls_Manager::TEXT,
				'default' => esc_html__( 'Design Planning', 'geroz-core' ),
			]
		);

		$repeater->add_control(
			'section_link',
			[
				'label'   => __( 'Service Link', 'geroz-core' ),
				'type'    => Controls_Manager::URL,
				'default' => [
					'url' => '#',
				],
			]
		);

		$this->add_control(
			'services_list',
			[
				'label'  => __( 'Services List', 'geroz-core' ),
				'type'   => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'default' => [
					[ 'section_title' => 'Design Planning' ],
					[ 'section_title' => 'Branding Identity' ],
					[ 'section_title' => 'Digital Services' ],
				],
				'title_field' => '{{section_title}}',
			]
		);

		$this->add_control(
			'sidebar_image',
			[
				'label'   => __( 'Sidebar Image', 'geroz-core' ),
				'type'    => Controls_Manager::MEDIA,
				'default' => [ 'url' => Utils::get_placeholder_image_src() ],
			]
		);

		$this->add_control(
			'image_title',
			[
				'label'   => __( 'Image Section Title', 'geroz-core' ),
				'type'    => Controls_Manager::TEXT,
				'default' => esc_html__( 'Need Your Services', 'geroz-core' ),
			]
		);

		$this->add_control(
			'image_button_text',
			[
				'label'   => __( 'Button Text', 'geroz-core' ),
				'type'    => Controls_Manager::TEXT,
				'default' => esc_html__( 'Hire For Projects', 'geroz-core' ),
			]
		);

		$this->add_control(
			'image_button_link',
			[
				'label'   => __( 'Button Link', 'geroz-core' ),
				'type'    => Controls_Manager::URL,
				'default' => [
					'url' => '#',
				],
			]
		);

		$this->end_controls_section();
	}

	protected function render() {
		$settings = $this->get_settings_for_display();
		$allowed_tags = wp_kses_allowed_html('post');
		?>

		<div class="service-details-section p-0">
			<div class="sidebar">
				<?php if ($settings['sidebar_title']) : ?>
					<h4 class="sidebar-title"><?php echo esc_html($settings['sidebar_title']); ?></h4>
				<?php endif; ?>

				<ul class="pt-4">
					<?php foreach ($settings['services_list'] as $item) : ?>
						<li>
							<a href="<?php echo esc_url($item['section_link']['url']); ?>">
								<div class="icon">
									<i class="far fa-long-arrow-right"></i>
								</div>
								<?php echo esc_html($item['section_title']); ?>
								<div class="hover-icon">
									<i class="far fa-long-arrow-right"></i>
								</div>
							</a>
						</li>
					<?php endforeach; ?>
				</ul>

				<?php if (!empty($settings['sidebar_image']['url'])) : ?>
					<div class="image-4 mt-5">
						<img src="<?php echo esc_url($settings['sidebar_image']['url']); ?>" alt="">
						<div class="infu">
							<?php if ($settings['image_title']) : ?>
								<h5><?php echo esc_html($settings['image_title']); ?></h5>
							<?php endif; ?>
							<?php if ($settings['image_button_text']) : ?>
								<a href="<?php echo esc_url($settings['image_button_link']['url']); ?>" class="theme-btn">
									<?php echo esc_html($settings['image_button_text']); ?>
								</a>
							<?php endif; ?>
						</div>
					</div>
				<?php endif; ?>
			</div>
		</div>


		<?php
	}


}

Plugin::instance()->widgets_manager->register_widget_type(new Service_Sidebar());