<?php
/**
 * Контакты + Яндекс.Карта
 * .bento .pksh-section #pksh-contact
 *
 * @package Dekart
 */

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

$data             = Pksh_Data::instance();
$opt_phone        = $data->get_phone();
$opt_email        = $data->get_email();
$opt_address      = $data->get_address();
$opt_social       = $data->get_social_links();
$opt_coords       = $data->get_coords();
$opt_name         = $data->get_name();
$opt_logistics_walk   = $data->get_logistics_walk();
$opt_logistics_parking = $data->get_logistics_parking();
$opt_logistics_nearby  = $data->get_logistics_nearby();
?>
<section class="bento pksh-section" id="pksh-contact" aria-label="Контакты">
	<div class="bento__full section-header--centered">
		<span class="bento-label">Контакты</span>
		<h2 class="bento-h2">Наш адрес</h2>
		<p class="bento-p">Ждём вас в гости — удобно добираться из любого района города</p>
	</div>
	<div class="bento__full pksh-contact">
		<div class="pksh-contact__wrapper">
			<div class="pksh-contact__info">
				<?php if ( ! empty( $opt_phone ) ) : ?>
				<div class="pksh-contact__subtitle">Телефон:</div>
				<a class="pksh-contact__value" href="tel:+<?php echo preg_replace( '/[^0-9]/', '', $opt_phone ); ?>"><?php echo esc_html( $opt_phone ); ?></a>
				<?php endif; ?>

				<?php if ( ! empty( $opt_email ) ) : ?>
				<div class="pksh-contact__subtitle">Почта:</div>
				<a class="pksh-contact__value" href="mailto:<?php echo esc_attr( $opt_email ); ?>"><?php echo esc_html( $opt_email ); ?></a>
				<?php endif; ?>

			<?php if ( ! empty( $opt_address ) ) : ?>
				<div class="pksh-contact__subtitle">Адрес:</div>
				<div class="pksh-contact__value"><?php echo esc_html( $opt_address ); ?></div>
			<?php endif; ?>

			<div class="pksh-contact__logistics">
				<?php if ( ! empty( $opt_logistics_walk ) ) : ?>
				<span class="pksh-contact__logistics-item">
					<span class="pksh-contact__logistics-icon">📍</span>
					<span class="pksh-contact__logistics-text"><?php echo esc_html( $opt_logistics_walk ); ?></span>
				</span>
				<?php endif; ?>
				<?php if ( ! empty( $opt_logistics_parking ) ) : ?>
				<span class="pksh-contact__logistics-item">
					<span class="pksh-contact__logistics-icon">🅿️</span>
					<span class="pksh-contact__logistics-text"><?php echo esc_html( $opt_logistics_parking ); ?></span>
				</span>
				<?php endif; ?>
				<?php if ( ! empty( $opt_logistics_nearby ) ) : ?>
				<span class="pksh-contact__logistics-item">
					<span class="pksh-contact__logistics-icon">🚸</span>
					<span class="pksh-contact__logistics-text"><?php echo esc_html( $opt_logistics_nearby ); ?></span>
				</span>
				<?php endif; ?>
			</div>

			<?php if ( ! empty( $opt_social ) && is_array( $opt_social ) ) : ?>
				<div class="pksh-contact__subtitle">Наши соцсети:</div>
				<div class="pksh-contact__social">
					<?php foreach ( $opt_social as $item ) :
						$link = $item['url'] ?? '';
						$name = $item['name'] ?? '';
						if ( $link ) : ?>
						<a class="pksh-contact__social-link" href="<?php echo esc_url( $link ); ?>" target="_blank" rel="noopener noreferrer" title="<?php echo esc_attr( $name ); ?>">
							<?php echo esc_html( $name ?: $link ); ?>
						</a>
						<?php endif; ?>
					<?php endforeach; ?>
				</div>
				<?php endif; ?>
			</div>
			<div class="pksh-contact__map">
				<div id="ya-map" style="width: 100%; height: 100%; min-height: 400px;"
					data-coords="<?php echo esc_attr( $opt_coords ?: '55.7558,37.6173' ); ?>"
					data-label="<?php echo esc_attr( $opt_name ?: 'Детский центр «Декарт»' ); ?>"></div>
			</div>
		</div>
	</div>
</section>

