<?php
declare(strict_types=1);
/**
 * Hero Section.
 * @package WTE_Business_Card
 * @since   1.0.0
 */
if ( ! defined( 'ABSPATH' ) ) { exit; }

$wte_heading    = get_theme_mod( 'wte_hero_heading', '' );
$wte_subheading = get_theme_mod( 'wte_hero_subheading', '' );
$wte_bg_image   = get_theme_mod( 'wte_hero_image', '' );
$wte_height     = get_theme_mod( 'wte_hero_height', 'full' );
$wte_cta1_text  = get_theme_mod( 'wte_hero_cta_primary_text', __( '詳しく見る', 'wte_' ) );
$wte_cta1_url   = get_theme_mod( 'wte_hero_cta_primary_url', '' );
$wte_cta2_text  = get_theme_mod( 'wte_hero_cta_secondary_text', __( 'お問い合わせ', 'wte_' ) );
$wte_cta2_url   = get_theme_mod( 'wte_hero_cta_secondary_url', '' );

// 一次CTA: URL未設定の場合はサービスセクションへスクロール
if ( empty( $wte_cta1_url ) ) {
	$wte_cta1_url = '#wte-services';
}

// 二次CTA: URL未設定の場合はお問い合わせページへ
if ( empty( $wte_cta2_url ) ) {
	$wte_contact_pages = get_pages( [ 'meta_key' => '_wte_is_contact_page', 'meta_value' => '1', 'number' => 1 ] );
	$wte_cta2_url      = ! empty( $wte_contact_pages ) ? get_permalink( $wte_contact_pages[0] ) : '#wte-contact-cta';
}

$wte_style = '';
if ( $wte_bg_image ) {
	$wte_style = 'background-image: url(' . esc_url( $wte_bg_image ) . ');';
}
?>
<section id="wte-hero" class="wte-hero wte-hero--<?php echo esc_attr( $wte_height ); ?>"<?php echo $wte_style ? ' style="' . esc_attr( $wte_style ) . '"' : ''; ?>>
	<div class="wte-hero__overlay" aria-hidden="true"></div>
	<div class="wte-container wte-hero__inner">
		<div class="wte-hero__content">
			<?php if ( $wte_heading ) : ?>
				<h1 class="wte-hero__heading"><?php echo esc_html( $wte_heading ); ?></h1>
			<?php endif; ?>
			<?php if ( $wte_subheading ) : ?>
				<p class="wte-hero__subheading"><?php echo esc_html( $wte_subheading ); ?></p>
			<?php endif; ?>
			<div class="wte-hero__cta-group">
				<?php if ( $wte_cta1_text ) : ?>
					<a href="<?php echo esc_url( $wte_cta1_url ); ?>" class="wte-btn wte-btn--primary wte-hero__cta-primary"><?php echo esc_html( $wte_cta1_text ); ?></a>
				<?php endif; ?>
				<?php if ( $wte_cta2_text ) : ?>
					<a href="<?php echo esc_url( $wte_cta2_url ); ?>" class="wte-btn wte-btn--outline wte-hero__cta-secondary"><?php echo esc_html( $wte_cta2_text ); ?></a>
				<?php endif; ?>
			</div>
		</div>
	</div>
	<button class="wte-hero__scroll-btn" aria-label="<?php esc_attr_e( 'スクロールダウン', 'wte_' ); ?>">
		<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M7 13l5 5 5-5"/><path d="M7 6l5 5 5-5"/></svg>
	</button>
</section>
