<?php

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


if ( $is_enable_swatches ) : ?>
	<div class="prodigy-custom-template">
		<div class="prodigy-logo-brand">
			<div class="prodigy-logo-tool__container">
				<div class="prodigy-logo-tool__form-container form-container prodigy-custom-template d-block">
					<div class="prodigy-product__attr-item--no-select prodigy-product__attr-item--logo-select">
						<div class="prodigy-product__attr-item--no-select-value prodigy-product__logo-item d-flex flex-column">
							<form class="w-100">
								<fieldset class="d-flex flex-wrap prodigy-radio__logo-btn-wrap position-relative">
									<legend class="prodigy-visually-hidden">
										<?php esc_html_e( 'Select a brand logo', 'prodigy-commerce' ); ?>
									</legend>
								<?php if ( isset( $data ) && ! empty( $data ) ) : ?>
									<?php foreach ( $data as $brand ) : ?>
										<?php $name = $brand['brand_name']; ?>
									<div class="flex-column prodigy-radio__btn-wrap position-md-relative prodigy-tooltip">
										<div class="prodigy-product__attr-item--no-select-value d-flex flex-wrap align-items-center">
											<div class="prodigy-radio__swatch-btn prodigy-radio__swatch-logo-btn">
												<input
														type="radio"
														id="<?php echo esc_attr( $brand['brand_slug'] ); ?>"
														name="radio.swatch.logo"
														data-link="<?php echo esc_url( $brand['brand_link'] ); ?>"
														class="prodigy-product__btn-no-select prodigy-product__swatch prodigy-product__logo-swatch brand-swatch-js"
												/>
												<?php foreach ( $brand['logos'] as $logo ) : ?>
													<?php if ( isset( $logo['logo-url'] ) ) : ?>
														<label for="<?php echo esc_attr( $brand['brand_slug'] ); ?>"
															class="d-flex flex-column justify-content-center align-items-center prodigy-logo-brand__label">
															<img
																	alt="<?php echo esc_attr( $name ); ?>"
																	class="prodigy-product__btn-no-select prodigy-product__swatch prodigy-product__logo-swatch position-relative"
																	data-slug="<?php echo esc_attr( $brand['brand_slug'] ); ?>"
																	src="<?php echo esc_url( $logo['logo-url'] ?? '' ); ?>"
															/>
														</label>
													<?php endif; ?>
												<?php endforeach; ?>

											</div>
										</div>
										<div class="prodigy-logo-brand__name">
											<span><?php echo esc_html( $brand['brand_name'] ); ?></span>
										</div>
									</div>
								<?php endforeach; ?>
								<?php endif; ?>
								</fieldset>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
<?php else : ?>
<div class="brands-container-js prodigy-custom-template"
	data-brands='<?php echo esc_attr( wp_json_encode( array_values( $data ?? array() ), JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE ) ); ?>'>
	<div class="prodigy-select__brands-widget">
		<div class="prodigy-select__brands">
			<label for="brand-select" class="prodigy-visually-hidden">
				<?php esc_html_e( 'Select a brand', 'prodigy-commerce' ); ?>
			</label>
			<select class="prodigy-main-select brands-js" id="brand-select" aria-label="<?php esc_attr_e( 'Select a brand', 'prodigy-commerce' ); ?>">
				<?php if ( isset( $data ) ) : ?>
					<?php foreach ( $data as $brand ) : ?>
						<option value="<?php echo esc_attr( $brand['brand_slug'] ); ?>">
							<?php echo esc_html( $brand['brand_name'] ); ?>
						</option>
					<?php endforeach; ?>
				<?php endif; ?>
			</select>
		</div>
	</div>
<?php endif; ?>
