<?php
/**
 * Select field template.
 *
 * @param array $data {
 *     Radio buttons  arguments.
 *
 *     @type string $id              Field identifier.
 *     @type string $label           Field label.
 *     @type string $container_class Field container class.
 *     @type string $value           Field value.
 *     @type string $description     Field description.
 *     @type array $items            Exclusion list.
 *     @type array $items            Exclusion list.
 *     @type array $wp_science_scripts Script exclusion list.
 *     @type array $wp_science_themes Theme exclusion list.
 *     @type array $wp_science_plugins Plugin exclusion list.
 *     @type array $wp_science_textarea Textarea exclusion list.
 *     @type array $wp_science_select_exclusions Selected exclusion list values.
 *     @type array $wp_science_state Currently exclusion list.
 *     @type array  $options {
 *          Option options.
 *
 *          @type string $description Option value.
 *          @type string $label Option label.
 *          @type array  $sub_fields fields to show when option is selected.
 *     }
 * }
 * @since 3.10
 */

defined( 'ABSPATH' ) || exit;
?>

<div id='<?php echo esc_attr( $data['id'] ); ?>' class="wpr-field wpr-multiple-select wpr-field--categorizedmultiselect <?php echo esc_attr( $data['container_class'] ); ?>" data-default="<?php echo ( ! empty( $data['default'] ) ? 'wpr-radio-' . esc_attr( $data['default'] ) : '' ); ?>" <?php echo $data['parent']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $data['parent'] escaped with esc_attr. ?>>
	<div class="wpr-field-description-label"><?php echo esc_attr( $data['label'] ); ?></div>
	<div class="wpr-field-description">
		<p>
			<?php
			echo esc_html( $data['description'] );
			?>
		</p>
		<?php if ( ! empty( $data['sub_description'] ) ) { ?>
			<p>
				<?php
				echo esc_html( $data['sub_description'] );
				?>
			</p>
		<?php } ?>
	</div>

	<?php
	foreach ( $data['items'] as $science_item_key => $science_item ) {
		if ( empty( $science_item['items'] ) ) {
			continue;
		}
		?>
		<div class="wpr-list<?php echo 'scripts' === $science_item_key ? ' open' : ''; ?>">
			<div class="wpr-list-header">
				<div class="wpr-checkbox">
					<input class="wpr-main-checkbox" type="checkbox" />
					<label>
						<?php if ( ! empty( $science_item['dashicon-class'] ) ) { ?>
							<span class="dashicons dashicons-<?php echo esc_html( $science_item['dashicon-class'] ); ?>"></span>
						<?php } ?>
						<span class="wpr-multiple-select-title">
							<?php echo esc_html( $science_item['title'] ); ?>
						</span>
					</label>
				</div>
				<div class="wpr-list-header-arrow">
					<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" height="100%" width="100%"><path d="M233.4 105.4c12.5-12.5 32.8-12.5 45.3 0l192 192c12.5 12.5 12.5 32.8 0 45.3s-32.8 12.5-45.3 0L256 173.3 86.6 342.6c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3l192-192z"/></svg>
				</div>
			</div>
			<div class="wpr-list-body">
				<ul>
					<?php
					foreach ( $science_item['items'] as $science_oneitem ) {
						?>
						<li>
							<div class="wpr-checkbox">
								<input type="checkbox" name="wp_science_settings[<?php echo esc_attr( $data['id'] ); ?>][]"
									value='<?php echo esc_attr( $science_oneitem['id'] ); ?>'
									<?php echo checked( in_array( $science_oneitem['id'], $data['selected'], true ) ); ?> />
								<label>
									<?php if ( ! empty( $science_oneitem['icon'] ) ) { ?>
									<img src="<?php echo esc_url( $science_oneitem['icon'] ); ?>"/>
									<?php } ?>
									<?php echo esc_attr( $science_oneitem['title'] ); ?>
								</label>
							</div>
						</li>
						<?php
					}
					?>
				</ul>
			</div>
		</div>
		<?php
	}
	unset( $science_item_key, $science_item, $science_oneitem );
	?>
</div>
