<?php
declare( strict_types=1 );

namespace FiboFilters\Widgets;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! class_exists( 'WC_Widget' ) ) {
	return;
}

/**
 * Class Filters
 */
class Filters extends \WC_Widget {

	/**
	 * Constructor
	 */
	public function __construct() {

		$this->widget_cssclass    = 'woocommerce fibofilters-filters-widget';
		$this->widget_description = _x( 'Display a product filters that make the process of finding products in your store simple and fast', '[admin]', 'fibofilters' );
		$this->widget_id          = 'fibofilters-filters-widget';
		$this->widget_name        = _x( 'FiboFilters - product filters', '[admin]', 'fibofilters' );
		$this->settings           = [
			'title' => [
				'type'  => 'text',
				'std'   => '',
				'label' => _x( 'Title', '[admin]', 'fibofilters' ),
			],
			// 'layout' => array(
			// 'type'    => 'select',
			// 'std'     => 'vertical',
			// 'options' => array(
			// 'vertical'   => _x( 'Vertical layout', '[admin]', 'fibofilters' ),
			// 'horizontal' => _x( 'Horizontal layout', '[admin]', 'fibofilters' ),
			// ),
			// 'label'   => _x( 'Layout', '[admin]', 'fibofilters' )
			// )
		];

		parent::__construct();
	}


	/**
	 * Outputs the content of the widget
	 *
	 * @param array $args Args.
	 * @param array $instance Instance.
	 */
	public function widget( $args, $instance ) {

		$this->widget_start( $args, $instance );
		$params = '';

		// Layout.
		if ( ! empty( $instance['layout'] ) && in_array(
			$instance['layout'],
			[
				'horizontal',
			],
			true
		) ) {
			$params .= ' layout="' . $instance['layout'] . '"';
		}

		echo do_shortcode( '[fibofilters' . $params . ']' );

		$this->widget_end( $args );
	}
}
