<?php
/** Bricks element adapter. */

if ( ! defined( 'ABSPATH' ) || ! class_exists( '\Bricks\Element' ) ) {
	return;
}

class YATOON_Bricks_Element extends \Bricks\Element {
	public $category = 'yatoon';
	public $name     = 'yatoon-booking';
	public $icon     = 'ti-calendar';

	public function get_label() {
		return esc_html__( 'Yatoon Booking', 'yatoon-booking-system' );
	}

	public function set_controls() {
		$options = array();
		foreach ( YATOON_Builder_Integrations::surfaces() as $key => $surface ) {
			$options[ $key ] = $surface['label'];
		}
		$this->controls['surface'] = array( 'tab' => 'content', 'label' => esc_html__( 'Surface', 'yatoon-booking-system' ), 'type' => 'select', 'options' => $options, 'default' => 'booking' );
		foreach ( array( 'location_id' => __( 'Location ID', 'yatoon-booking-system' ), 'service_id' => __( 'Service ID', 'yatoon-booking-system' ), 'staff_id' => __( 'Staff ID', 'yatoon-booking-system' ) ) as $key => $label ) {
			$this->controls[ $key ] = array( 'tab' => 'content', 'label' => $label, 'type' => 'text' );
		}
	}

	public function render() {
		$settings = is_array( $this->settings ) ? $this->settings : array();
		$this->set_attribute( '_root', 'class', 'yatoon-builder-surface' );
		echo '<div ' . $this->render_attributes( '_root' ) . '>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Bricks renders and escapes its registered attribute collection.
		echo YATOON_Builder_Integrations::render_surface( $settings['surface'] ?? 'booking', $settings ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- trusted shortcode output.
		echo '</div>';
	}
}
