                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                			],
			false
		);
		$fld = $this->field_element(
			'select',
			$field,
			[
				'slug'    => 'icon_size',
				'value'   => ! empty( $field['icon_size'] ) ? esc_attr( $field['icon_size'] ) : 'medium',
				'options' => [
					'small'  => esc_html__( 'Small', 'wpforms-lite' ),
					'medium' => esc_html__( 'Medium', 'wpforms-lite' ),
					'large'  => esc_html__( 'Large', 'wpforms-lite' ),
				],
			],
			false
		);

		$this->field_element(
			'row',
			$field,
			[
				'slug'    => 'icon_size',
				'content' => $lbl . $fld,
			]
		);

		$this->score_labels( $field );

		// Icon color picker.
		$lbl = $this->field_element(
			'label',
			$field,
			[
				'slug'    => 'icon_color',
				'value'   => esc_html__( 'Icon Color', 'wpforms-lite' ),
				'tooltip' => esc_html__( 'Select the color for the rating icon', 'wpforms-lite' ),
			],
			false
		);

		$icon_color = isset( $field['icon_color'] ) ? wpforms_sanitize_hex_color( $field['icon_color'] ) : '';
		$icon_color = empty( $icon_color ) ? $this->get_default_icon_color() : $icon_color;

		$fld = $this->field_element(
			'color',
			$field,
			[
				'slug'  => 'icon_color',
				'value' => $icon_color,
				'data'  => [
					'fallback-color' => $icon_color,
				],
			],
			false
		);

		$this->field_element(
			'row',
			$field,
			[
				'slug'    => 'icon_color',
				'content' => $lbl . $fld,
				'class'   => 'color-picker-row',
			]
		);

		// Custom CSS classes.
		$this->field_option( 'css', $field );

		// Hide label.
		$this->field_option( 'label_hide', $field );

		// Options close markup.
		$this->field_option(
			'advanced-options',
			$field,
			[
				'markup' => 'close',
			]
		);
	}

	/**
	 * Score labels.
	 *
	 * @since 1.9.8
	 *
	 * @param array $field Field settings.
	 */
	private function score_labels( array $field ): void {

		// Lowest score label.
		$lowest_label = $this->field_element(
			'label',
			$field,
			[
				'slug'    => 'lowest_label',
				'value'   => esc_html__( 'Lowest Score Label', 'wpforms-lite' ),
				'tooltip' => esc_html__( 'This label indicates the lowest score on the scale.', 'wpforms-lite' ),
			],
			false
		);

		$lowest_field = $this->field_element(
			'text',
			$field,
			[
				'slug'  => 'lowest_label',
				'value' => $field['lowest_label'] ?? '',
			],
			false
		);

		$this->field_element(
			'row',
			$field,
			[
				'slug'    => 'lowest_label',
				'content' => $lowest_label . $lowest_field,
			]
		);

		// Highest score label.
		$highest_label = $this->field_element(
			'label',
			$field,
			[
				'slug'    => 'highest_label',
				'value'   => esc_html__( 'Highest Score Label', 'wpforms-lite' ),
				'tooltip' => esc_html__( 'This label indicates the highest score on the scale.', 'wpforms-lite' ),
			],
			false
		);

		$highest_field = $this->field_element(
			'text',
			$field,
			[
				'slug'  => 'highest_label',
				'value' => $field['highest_label'] ?? '',
			],
			false
		);

		$this->field_element(
			'row',
			$field,
			[
				'slug'    => 'highest_label',
				'content' => $highest_label . $highest_field,
			]
		);

		// Label position.
		$label_position = $this->field_element(
			'label',
			$field,
			[
				'slug'    => 'label_position',
				'value'   => esc_html__( 'Label Position', 'wpforms-lite' ),
				'tooltip' => esc_html__( 'Select the position of the label', 'wpforms-lite' ),
			],
			false
		);

		$select_position = $this->field_element(
			'select',
			$field,
			[
				'slug'    => 'label_position',
				'value'   => ! empty( $field['label_position'] ) ? esc_attr( $field['label_position'] ) : 'below',
				'options' => [
					'above' => esc_html__( 'Above', 'wpforms-lite' ),
					'below' => esc_html__( 'Below', 'wpforms-lite' ),
				],
			],
			false
		);

		$this->field_element(
			'row',
			$field,
			[
				'slug'    => 'label_position',
				'content' => $label_position . $select_position,
			]
		);
	}

	/**
	 * Field preview inside the builder.
	 *
	 * @since 1.9.4
	 *
	 * @param array $field Field settings.
	 */
	public function field_preview( $field ): void {

		// Label.
		$this->field_preview_option(
			'label',
			$field,
			[
				'label_badge' => $this->get_field_preview_badge(),
			]
		);

		echo '<div class="wpforms-rating-field">';

		$this->get_field_preview_icons( $field );

		$this->get_field_preview_labels( $field );

		echo '</div>';

		// Description.
		$this->field_preview_option( 'description', $field );
	}

	/**
	 * Get field preview icons.
	 *
	 * @since 1.9.8
	 *
	 * @param array $field Field settings.
	 */
	private function get_field_preview_icons( array $field ): void {

		// Define data.
		$scale      = ! empty( $field['scale'] ) ? esc_attr( $field['scale'] ) : 5;
		$icon       = ! empty( $field['icon'] ) ? esc_attr( $field['icon'] ) : 'star';
		$icon_size  = ! empty( $field['icon_size'] ) ? esc_attr( $field['icon_size'] ) : 'medium';
		$icon_color = ! empty( $field['icon_color'] ) ? esc_attr( $field['icon_color'] ) : $this->get_default_icon_color();
		$icon_class = $this->get_preview_icon_class( $icon );

		// Set icon size.
		$icon_size_css = $this->get_icon_size_css( $icon_size );

		echo '<div class="wpforms-rating-field-icons">';

		// Primary input.
		for ( $i = 1; $i <= 10; $i++ ) {
			printf(
				'<i class="fa %s %s rating-icon" aria-hidden="true" style="color:%s; display:%s; font-size:%dpx;"></i>',
				esc_attr( $icon_class ),
				esc_attr( $icon_size ),
				esc_attr( $icon_color ),
				$i <= $scale ? 'inline-block' : 'none',
				esc_attr( $icon_size_css )
			);
		}

		echo '</div>';
	}

	/**
	 * Get preview icon class based on the selected icon.
	 *
	 * @since 1.9.8
	 *
	 * @param string $icon Selected icon.
	 *
	 * @return string Icon class.
	 */
	private function get_preview_icon_class( string $icon ): string {

		$icon_class = '';

		// Set icon class.
		switch ( $icon ) {
			case 'star':
				$icon_class = 'fa-star';
				break;

			case 'heart':
				$icon_class = 'fa-heart';
				break;

			case 'thumb':
				$icon_class = 'fa-thumbs-up';
				break;

			case 'smiley':
				$icon_class = 'fa-smile-o';
				break;
		}

		return $icon_class;
	}

	/**
	 * Get field preview labels.
	 *
	 * @since 1.9.8
	 *
	 * @param array $field Field settings.
	 */
	private function get_field_preview_labels( array $field ): void {

		// Lowest score label.
		$lowest_label = ! empty( $field['lowest_label'] ) ? esc_html( $field['lowest_label'] ) : '';

		// Highest score label.
		$highest_label = ! empty( $field['highest_label'] ) ? esc_html( $field['highest_label'] ) : '';

		$class = [ 'wpforms-rating-field-labels' ];

		if ( ! empty( $field['label_position'] ) && $field['label_position'] === 'above' ) {
			$class[] = 'wpforms-rating-field-labels-position-above';
		}

		if ( empty( $lowest_label ) && empty( $highest_label ) ) {
			$class[] = 'wpforms-hidden';
		}

		echo '<div class=" ' . wpforms_sanitize_classes( $class, true ) . ' ">';

		printf(
			'<span class="wpforms-rating-field-lowest-label wpforms-sub-label">%s</span>',
			esc_html( $lowest_label )
		);

		printf(
			'<span class="wpforms-rating-field-highest-label wpforms-sub-label">%s</span>',
			esc_html( $highest_label )
		);

		echo '</div>';
	}

	/**
	 * Field display on the form front-end.
	 *
	 * @since 1.9.4
	 *
	 * @param array $field      Field settings.
	 * @param array $deprecated Deprecated, don't use.
	 * @param array $form_data  Form data and settings.
	 */
	public function field_display( $field, $deprecated, $form_data ) {
	}

	/**
	 * Get icon size CSS value in pixels.
	 *
	 * @since 1.9.4
	 *
	 * @param string $icon_size Icon size value.
	 */
	protected function get_icon_size_css( $icon_size ): string {

		$render_engine = wpforms_get_render_engine();

		$icon_sizes = [
			'classic' => [
				'small'  => '18',
				'medium' => '28',
				'large'  => '38',
			],
			'modern'  => [
				'small'  => '16',
				'medium' => '24',
				'large'  => '38',
			],
		];

		$default = $render_engine === 'modern' ? '24' : '28';

		return ! empty( $icon_sizes[ $render_engine ][ $icon_size ] )
			? $icon_sizes[ $render_engine ][ $icon_size ]
			: $default;
	}

	/**
	 * Get default icon color.
	 *
	 * @since 1.9.4
	 *
	 * @return string
	 */
	public function get_default_icon_color(): string {

		$render_engine = wpforms_get_render_engine();

		return array_key_exists( $render_engine, self::DEFAULT_ICON_COLOR ) ? self::DEFAULT_ICON_COLOR[ $render_engine ] : self::DEFAULT_ICON_COLOR['modern'];
	}
}
<?xml version="1.0"?>
<oembed><version>1.0</version><provider_name>prague@nestdomi.com</provider_name><provider_url>https://nestdomi.com/zh</provider_url><author_name>bara.prosek@seznam.cz</author_name><author_url>https://nestdomi.com/zh/author/bara-prosekseznam-cz/</author_url><title>Nestdomi Prague</title><type>rich</type><width>600</width><height>338</height><html>&lt;blockquote class="wp-embedded-content" data-secret="q2r4UjcsLX"&gt;&lt;a href="https://nestdomi.com/zh/accommodation/nestdomi-prague/"&gt;Nestdomi Prague&lt;/a&gt;&lt;/blockquote&gt;&lt;iframe sandbox="allow-scripts" security="restricted" src="https://nestdomi.com/zh/accommodation/nestdomi-prague/embed/#?secret=q2r4UjcsLX" width="600" height="338" title="&#x300A; Nestdomi Prague &#x300B;&#x2014;prague@nestdomi.com" data-secret="q2r4UjcsLX" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" class="wp-embedded-content"&gt;&lt;/iframe&gt;&lt;script&gt;
/*! This file is auto-generated */
!function(d,l){"use strict";l.querySelector&amp;&amp;d.addEventListener&amp;&amp;"undefined"!=typeof URL&amp;&amp;(d.wp=d.wp||{},d.wp.receiveEmbedMessage||(d.wp.receiveEmbedMessage=function(e){var t=e.data;if((t||t.secret||t.message||t.value)&amp;&amp;!/[^a-zA-Z0-9]/.test(t.secret)){for(var s,r,n,a=l.querySelectorAll('iframe[data-secret="'+t.secret+'"]'),o=l.querySelectorAll('blockquote[data-secret="'+t.secret+'"]'),c=new RegExp("^https?:$","i"),i=0;i&lt;o.length;i++)o[i].style.display="none";for(i=0;i&lt;a.length;i++)s=a[i],e.source===s.contentWindow&amp;&amp;(s.removeAttribute("style"),"height"===t.message?(1e3&lt;(r=parseInt(t.value,10))?r=1e3:~~r&lt;200&amp;&amp;(r=200),s.height=r):"link"===t.message&amp;&amp;(r=new URL(s.getAttribute("src")),n=new URL(t.value),c.test(n.protocol))&amp;&amp;n.host===r.host&amp;&amp;l.activeElement===s&amp;&amp;(d.top.location.href=t.value))}},d.addEventListener("message",d.wp.receiveEmbedMessage,!1),l.addEventListener("DOMContentLoaded",function(){for(var e,t,s=l.querySelectorAll("iframe.wp-embedded-content"),r=0;r&lt;s.length;r++)(t=(e=s[r]).getAttribute("data-secret"))||(t=Math.random().toString(36).substring(2,12),e.src+="#?secret="+t,e.setAttribute("data-secret",t)),e.contentWindow.postMessage({message:"ready",secret:t},"*")},!1)))}(window,document);
//# sourceURL=https://nestdomi.com/wp-includes/js/wp-embed.min.js
&lt;/script&gt;</html></oembed>
