<?php
namespace Elementor; // Custom widgets must be defined in the Elementor namespace
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
 * Widget Name: Panolens 360 Viewer
 */
class PBMIT_PanolensElement extends Widget_Base {
	/**
	 * Get widget name.
	 *
	 * Retrieve tabs widget name.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget name.
	 */
	public function get_name() {
		return 'pbmit_panolens_element';
	}
	/**
	 * Get widget title.
	 *
	 * Retrieve tabs widget title.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget title.
	 */
	public function get_title() {
		return esc_html__( 'Xinterio Panolens Image', 'xinterio' );
	}
	/**
	 * Get widget icon.
	 *
	 * Retrieve tabs widget icon.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget icon.
	 */
	public function get_icon() {
		return 'fas fa-biohazard';
	}
	// The get_categories method, lets you set the category of the widget, return the category name as a string.
	public function get_categories() {
		return [ 'xinterio_category' ];
	}
	/**
	 * Get widget keywords.
	 *
	 * Retrieve the list of keywords the widget belongs to.
	 *
	 * @since 2.1.0
	 * @access public
	 *
	 * @return array Widget keywords.
	 */
	public function get_keywords() {
		return [ 'panolens', '360', 'panorama', 'vr' ];
	}
	// Register widget controls
	protected function register_controls() {
		// Start content section
		$this->start_controls_section(
			'content_section',
			[
				'label'	=> esc_attr__( 'Panorama Image', 'xinterio' ),
				'tab'	=> Controls_Manager::TAB_CONTENT,
			]
		);
		// Panorama image control
		$this->add_control(
			'pano_image',
			[
				'label'		=> esc_attr__( 'Panorama 360 Image', 'xinterio' ),
				'type'		=> Controls_Manager::MEDIA,
				'dynamic' => ['active' => true],
				'default'	=> [
					'url'		=> get_template_directory_uri() . '/images/panorama.jpg',
				],
			]
		);
		// Panorama container height
		$this->add_control(
			'height',
			[
				'label'		=> esc_attr__( 'Set Height in (px)', 'xinterio' ),
				'type'		=> Controls_Manager::NUMBER,
				'default'	=> 600,
			]
		);
		$this->add_control(
			'image',
			[
				'label'		=> esc_attr__( 'Choose Image', 'xinterio' ),
				'type'		=> Controls_Manager::MEDIA,
				'dynamic'	=> [
					'active'	=> true,
				],
				'default'	=> [
					'url'		=> get_template_directory_uri() . '/images/icon-img.png',
				],
			]
		);
		$this->add_control(
			'title',
			[
				'label'			=> esc_attr__( 'Heading', 'xinterio' ),
				'type'			=> Controls_Manager::TEXTAREA,
				'dynamic'		=> [
					'active' => true,
				],
				'default'		=> esc_attr__( '360 Interior View', 'xinterio' ),
				'placeholder'	=> esc_attr__( 'Enter your heading', 'xinterio' ),
				'label_block'	=> true,
			]
		);
		// End content section
		$this->end_controls_section();
	}
	// Render widget output on frontend
	protected function render() {
		$settings = $this->get_settings_for_display();
		if ( empty( $settings['pano_image']['url'] ) ) {
			return;
		}
		$image_html = ( ! empty( $settings['image']['url'] ) )
			? '<div class="pbmit-panolens-image">
					<img src="' . esc_url( $settings['image']['url'] ) . '" alt="' . esc_attr( $settings['title'] ) . '" />
			</div>'
			: '';
		?>
		<div class="pbmit-panolens-wrapper">
			<div class="pbmit-image-title-wrap">
				<?php echo pbmit_esc_kses( $image_html ); ?>
				<?php if ( ! empty( $settings['title'] ) ) : ?>
					<h3 class="pbmit-panolens-title">
						<?php echo esc_html( $settings['title'] ); ?>
					</h3>
				<?php endif; ?>
			</div>
			<div class="pbmit-panolens-container"
				data-pano="<?php echo esc_url( $settings['pano_image']['url'] ); ?>"
				style="width:100%; height:<?php echo esc_attr( $settings['height'] ); ?>px;">
			</div>
		</div>
		<?php
	}
	// Render widget output in editor
	protected function content_template() {}
}
// After the Schedule class is defined, I must register the new widget class with Elementor:
Plugin::instance()->widgets_manager->register( new PBMIT_PanolensElement() );
