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

function wte_customizer_controls( \WP_Customize_Manager $wp_customize ): void {

	// Load custom control classes inside the callback
	// so that WP_Customize_Control is guaranteed to exist.
	require_once WTE_THEME_DIR . '/inc/customizer/controls/class-range-control.php';
	require_once WTE_THEME_DIR . '/inc/customizer/controls/class-email-control.php';
	require_once WTE_THEME_DIR . '/inc/customizer/controls/class-tel-control.php';
	require_once WTE_THEME_DIR . '/inc/customizer/controls/class-separator-control.php';
	require_once WTE_THEME_DIR . '/inc/customizer/controls/class-info-control.php';
	require_once WTE_THEME_DIR . '/inc/customizer/controls/class-toggle-control.php';
	require_once WTE_THEME_DIR . '/inc/customizer/controls/class-icon-select-control.php';

	// ── Panel 1: ロゴ ──
	$wp_customize->add_control( new \WP_Customize_Image_Control( $wp_customize, 'wte_site_logo', [
		'label'   => __( 'ロゴ画像（推奨 400×120px）', 'wte_' ),
		'section' => 'wte_section_logo', 'priority' => 10,
	] ) );
	$wp_customize->add_control( new WTE_Range_Control( $wp_customize, 'wte_site_logo_width', [
		'label' => __( 'ロゴ表示幅（px）', 'wte_' ), 'section' => 'wte_section_logo', 'priority' => 20,
		'input_attrs' => [ 'min' => 80, 'max' => 400, 'step' => 10 ],
	] ) );
	$wp_customize->add_control( new WTE_Toggle_Control( $wp_customize, 'wte_site_tagline_display', [
		'label' => __( 'キャッチフレーズを表示', 'wte_' ), 'section' => 'wte_section_logo', 'priority' => 30,
	] ) );
	$wp_customize->add_control( new \WP_Customize_Image_Control( $wp_customize, 'wte_favicon', [
		'label' => __( 'ファビコン（32×32推奨）', 'wte_' ), 'section' => 'wte_section_logo', 'priority' => 40,
	] ) );

	// ── Panel 1: 運営者情報 ──
	$wp_customize->add_control( 'wte_owner_name', [ 'label' => __( '氏名（フルネーム）', 'wte_' ), 'section' => 'wte_section_owner', 'type' => 'text', 'priority' => 10 ] );
	$wp_customize->add_control( 'wte_owner_name_kana', [ 'label' => __( '氏名（ふりがな）', 'wte_' ), 'section' => 'wte_section_owner', 'type' => 'text', 'priority' => 20 ] );
	$wp_customize->add_control( 'wte_owner_title', [ 'label' => __( '肩書き・職種', 'wte_' ), 'section' => 'wte_section_owner', 'type' => 'text', 'priority' => 30 ] );
	$wp_customize->add_control( new \WP_Customize_Image_Control( $wp_customize, 'wte_owner_photo', [
		'label' => __( 'プロフィール写真', 'wte_' ), 'section' => 'wte_section_owner', 'priority' => 40,
	] ) );
	$wp_customize->add_control( 'wte_owner_bio', [ 'label' => __( '自己紹介文（短文）', 'wte_' ), 'section' => 'wte_section_owner', 'type' => 'textarea', 'priority' => 50 ] );
	$wp_customize->add_control( 'wte_business_name', [ 'label' => __( '屋号・事務所名', 'wte_' ), 'section' => 'wte_section_owner', 'type' => 'text', 'priority' => 60 ] );
	$wp_customize->add_control( 'wte_business_address', [ 'label' => __( '住所（表示用）', 'wte_' ), 'section' => 'wte_section_owner', 'type' => 'textarea', 'priority' => 70 ] );
	$wp_customize->add_control( new WTE_Tel_Control( $wp_customize, 'wte_business_tel', [
		'label' => __( '電話番号', 'wte_' ), 'section' => 'wte_section_owner', 'priority' => 80,
	] ) );
	$wp_customize->add_control( 'wte_business_hours', [ 'label' => __( '営業時間', 'wte_' ), 'section' => 'wte_section_owner', 'type' => 'textarea', 'priority' => 90 ] );
	$wp_customize->add_control( 'wte_business_founded', [ 'label' => __( '創業年（例: 2018）', 'wte_' ), 'section' => 'wte_section_owner', 'type' => 'text', 'priority' => 100 ] );

	// ── Panel 1: 代表挨拶 ──
	$wp_customize->add_control( 'wte_greeting_heading', [ 'label' => __( '挨拶見出し', 'wte_' ), 'section' => 'wte_section_greeting', 'type' => 'text', 'priority' => 10 ] );
	$wp_customize->add_control( 'wte_greeting_body', [ 'label' => __( '挨拶本文（400字程度）', 'wte_' ), 'section' => 'wte_section_greeting', 'type' => 'textarea', 'priority' => 20 ] );
	$wp_customize->add_control( 'wte_greeting_signature', [ 'label' => __( '署名', 'wte_' ), 'section' => 'wte_section_greeting', 'type' => 'text', 'priority' => 30 ] );
	$wp_customize->add_control( new \WP_Customize_Image_Control( $wp_customize, 'wte_greeting_image', [
		'label' => __( '挨拶セクション添付画像', 'wte_' ), 'section' => 'wte_section_greeting', 'priority' => 40,
	] ) );

	// ── Panel 2: カラー ──
	$color_labels = [
		'wte_color_header_bg' => __( 'ヘッダー背景色', 'wte_' ), 'wte_color_header_text' => __( 'ヘッダーテキスト色', 'wte_' ),
		'wte_color_footer_bg' => __( 'フッター背景色', 'wte_' ), 'wte_color_footer_text' => __( 'フッターテキスト色', 'wte_' ),
		'wte_color_accent' => __( 'アクセントカラー', 'wte_' ), 'wte_color_link' => __( 'リンク色', 'wte_' ),
		'wte_color_body_bg' => __( 'ボディ背景色', 'wte_' ), 'wte_color_section_alt_bg' => __( '奇数セクション背景色', 'wte_' ),
	];
	$p = 10;
	foreach ( $color_labels as $id => $label ) {
		$wp_customize->add_control( new \WP_Customize_Color_Control( $wp_customize, $id, [
			'label' => $label, 'section' => 'wte_section_colors', 'priority' => $p,
		] ) );
		$p += 10;
	}

	// ── Panel 2: フォント ──
	$font_choices = [
		'noto_sans_jp' => 'Noto Sans JP', 'noto_serif_jp' => 'Noto Serif JP',
		'zen_kaku_gothic' => 'Zen Kaku Gothic New', 'shippori_mincho' => 'Shippori Mincho', 'm_plus_1p' => 'M PLUS 1p',
	];
	$wp_customize->add_control( 'wte_font_body', [ 'label' => __( '本文フォント', 'wte_' ), 'section' => 'wte_section_fonts', 'type' => 'select', 'choices' => $font_choices, 'priority' => 10 ] );
	$wp_customize->add_control( 'wte_font_heading', [ 'label' => __( '見出しフォント', 'wte_' ), 'section' => 'wte_section_fonts', 'type' => 'select', 'choices' => $font_choices, 'priority' => 20 ] );
	$wp_customize->add_control( new WTE_Range_Control( $wp_customize, 'wte_font_size_base', [
		'label' => __( '基本フォントサイズ（px）', 'wte_' ), 'section' => 'wte_section_fonts', 'priority' => 30,
		'input_attrs' => [ 'min' => 12, 'max' => 22, 'step' => 1 ],
	] ) );

	// ── Panel 2: ヘッダー設定 ──
	$wp_customize->add_control( new WTE_Toggle_Control( $wp_customize, 'wte_header_sticky', [ 'label' => __( 'ヘッダーを固定表示', 'wte_' ), 'section' => 'wte_section_header', 'priority' => 10 ] ) );
	$wp_customize->add_control( new WTE_Range_Control( $wp_customize, 'wte_header_height', [
		'label' => __( 'ヘッダー高さ（px）', 'wte_' ), 'section' => 'wte_section_header', 'priority' => 20,
		'input_attrs' => [ 'min' => 48, 'max' => 120, 'step' => 4 ],
	] ) );
	$wp_customize->add_control( new WTE_Toggle_Control( $wp_customize, 'wte_header_shadow', [ 'label' => __( 'ヘッダーにシャドウ', 'wte_' ), 'section' => 'wte_section_header', 'priority' => 30 ] ) );
	$wp_customize->add_control( new WTE_Toggle_Control( $wp_customize, 'wte_nav_display', [ 'label' => __( 'グローバルナビを表示', 'wte_' ), 'section' => 'wte_section_header', 'priority' => 40 ] ) );
	$wp_customize->add_control( 'wte_header_cta_text', [ 'label' => __( 'ヘッダー CTA テキスト', 'wte_' ), 'section' => 'wte_section_header', 'type' => 'text', 'priority' => 50 ] );
	$wp_customize->add_control( new WTE_Toggle_Control( $wp_customize, 'wte_header_cta_display', [ 'label' => __( 'ヘッダー CTA を表示', 'wte_' ), 'section' => 'wte_section_header', 'priority' => 60 ] ) );

	// ── Panel 3: ヒーロー ──
	$wp_customize->add_control( 'wte_hero_heading', [ 'label' => __( 'メインキャッチコピー', 'wte_' ), 'section' => 'wte_section_hero', 'type' => 'text', 'priority' => 10 ] );
	$wp_customize->add_control( 'wte_hero_subheading', [ 'label' => __( 'サブキャッチコピー', 'wte_' ), 'section' => 'wte_section_hero', 'type' => 'textarea', 'priority' => 20 ] );
	$wp_customize->add_control( new \WP_Customize_Image_Control( $wp_customize, 'wte_hero_image', [
		'label' => __( 'ヒーロー背景画像', 'wte_' ), 'section' => 'wte_section_hero', 'priority' => 30,
	] ) );
	$wp_customize->add_control( new WTE_Range_Control( $wp_customize, 'wte_hero_overlay_opacity', [
		'label' => __( 'オーバーレイ不透明度（%）', 'wte_' ), 'section' => 'wte_section_hero', 'priority' => 40,
		'input_attrs' => [ 'min' => 0, 'max' => 100, 'step' => 5 ],
	] ) );
	$wp_customize->add_control( new \WP_Customize_Color_Control( $wp_customize, 'wte_hero_overlay_color', [
		'label' => __( 'オーバーレイ色', 'wte_' ), 'section' => 'wte_section_hero', 'priority' => 50,
	] ) );
	$wp_customize->add_control( 'wte_hero_cta_primary_text', [ 'label' => __( '一次CTAテキスト', 'wte_' ), 'section' => 'wte_section_hero', 'type' => 'text', 'priority' => 60 ] );
	$wp_customize->add_control( 'wte_hero_cta_primary_url', [ 'label' => __( '一次CTAリンクURL（未入力でサービスへスクロール）', 'wte_' ), 'section' => 'wte_section_hero', 'type' => 'url', 'priority' => 61 ] );
	$wp_customize->add_control( 'wte_hero_cta_secondary_text', [ 'label' => __( '二次CTAテキスト', 'wte_' ), 'section' => 'wte_section_hero', 'type' => 'text', 'priority' => 70 ] );
	$wp_customize->add_control( 'wte_hero_cta_secondary_url', [ 'label' => __( '二次CTAリンクURL（未入力でお問い合わせページへ）', 'wte_' ), 'section' => 'wte_section_hero', 'type' => 'url', 'priority' => 71 ] );
	$wp_customize->add_control( 'wte_hero_height', [
		'label' => __( 'ヒーロー高さ', 'wte_' ), 'section' => 'wte_section_hero', 'type' => 'select', 'priority' => 80,
		'choices' => [ 'full' => '100vh', 'large' => '80vh', 'medium' => '60vh', 'small' => '40vh' ],
	] );

	// ── Panel 3: サービス ──
	$wp_customize->add_control( 'wte_service_section_heading', [ 'label' => __( 'セクション見出し', 'wte_' ), 'section' => 'wte_section_services', 'type' => 'text', 'priority' => 5 ] );
	$wp_customize->add_control( 'wte_service_section_subtext', [ 'label' => __( 'セクション説明文', 'wte_' ), 'section' => 'wte_section_services', 'type' => 'textarea', 'priority' => 6 ] );
	$icon_choices = [ 'star' => '★ Star', 'check' => '✓ Check', 'briefcase' => '💼 Briefcase', 'document' => '📄 Document', 'chat' => '💬 Chat', 'gear' => '⚙ Gear', 'lock' => '🔒 Lock', 'chart' => '📊 Chart', 'heart' => '❤ Heart', 'lightbulb' => '💡 Lightbulb', 'shield' => '🛡 Shield', 'users' => '👥 Users' ];
	for ( $n = 1; $n <= 6; $n++ ) {
		$base = $n * 10 + 10;
		$wp_customize->add_control( new WTE_Separator_Control( $wp_customize, "wte_service_{$n}_sep", [ 'section' => 'wte_section_services', 'priority' => $base ] ) );
		$wp_customize->add_control( "wte_service_{$n}_title", [ 'label' => sprintf( __( 'サービス%d：名称', 'wte_' ), $n ), 'section' => 'wte_section_services', 'type' => 'text', 'priority' => $base + 1 ] );
		$wp_customize->add_control( "wte_service_{$n}_desc", [ 'label' => sprintf( __( 'サービス%d：説明', 'wte_' ), $n ), 'section' => 'wte_section_services', 'type' => 'textarea', 'priority' => $base + 2 ] );
		$wp_customize->add_control( "wte_service_{$n}_icon", [ 'label' => sprintf( __( 'サービス%d：アイコン', 'wte_' ), $n ), 'section' => 'wte_section_services', 'type' => 'select', 'choices' => $icon_choices, 'priority' => $base + 3 ] );
		$wp_customize->add_control( new WTE_Toggle_Control( $wp_customize, "wte_service_{$n}_display", [ 'label' => sprintf( __( 'サービス%d：表示', 'wte_' ), $n ), 'section' => 'wte_section_services', 'priority' => $base + 4 ] ) );
	}

	// ── Panel 3: アピールポイント ──
	$wp_customize->add_control( 'wte_appeal_section_heading', [ 'label' => __( 'セクション見出し', 'wte_' ), 'section' => 'wte_section_appeal', 'type' => 'text', 'priority' => 5 ] );
	for ( $n = 1; $n <= 3; $n++ ) {
		$base = $n * 10 + 10;
		$wp_customize->add_control( new WTE_Separator_Control( $wp_customize, "wte_appeal_{$n}_sep", [ 'section' => 'wte_section_appeal', 'priority' => $base ] ) );
		$wp_customize->add_control( "wte_appeal_{$n}_heading", [ 'label' => sprintf( __( 'ポイント%d：見出し', 'wte_' ), $n ), 'section' => 'wte_section_appeal', 'type' => 'text', 'priority' => $base + 1 ] );
		$wp_customize->add_control( "wte_appeal_{$n}_body", [ 'label' => sprintf( __( 'ポイント%d：説明', 'wte_' ), $n ), 'section' => 'wte_section_appeal', 'type' => 'textarea', 'priority' => $base + 2 ] );
		$wp_customize->add_control( "wte_appeal_{$n}_number", [ 'label' => sprintf( __( 'ポイント%d：強調数字', 'wte_' ), $n ), 'section' => 'wte_section_appeal', 'type' => 'text', 'priority' => $base + 3 ] );
	}

	// ── Panel 4: SNS ──
	$sns_labels = [ 'wte_sns_x' => 'X（旧Twitter）', 'wte_sns_instagram' => 'Instagram', 'wte_sns_facebook' => 'Facebook', 'wte_sns_linkedin' => 'LinkedIn', 'wte_sns_youtube' => 'YouTube', 'wte_sns_note' => 'note', 'wte_sns_github' => 'GitHub' ];
	$p = 10;
	foreach ( $sns_labels as $id => $label ) {
		$wp_customize->add_control( $id, [ 'label' => $label . ' URL', 'section' => 'wte_section_sns', 'type' => 'url', 'priority' => $p ] );
		$p += 10;
	}
	$wp_customize->add_control( new WTE_Toggle_Control( $wp_customize, 'wte_sns_display_header', [ 'label' => __( 'ヘッダーにSNSアイコン表示', 'wte_' ), 'section' => 'wte_section_sns', 'priority' => 90 ] ) );
	$wp_customize->add_control( new WTE_Toggle_Control( $wp_customize, 'wte_sns_display_footer', [ 'label' => __( 'フッターにSNSアイコン表示', 'wte_' ), 'section' => 'wte_section_sns', 'priority' => 100 ] ) );

	// ── Panel 5: お問い合わせ ──
	$wp_customize->add_control( new WTE_Email_Control( $wp_customize, 'wte_contact_email', [ 'label' => __( 'メールアドレス（必須）', 'wte_' ), 'section' => 'wte_section_contact', 'priority' => 10 ] ) );
	$wp_customize->add_control( 'wte_contact_page_title', [ 'label' => __( 'ページタイトル', 'wte_' ), 'section' => 'wte_section_contact', 'type' => 'text', 'priority' => 20 ] );
	$wp_customize->add_control( 'wte_contact_page_intro', [ 'label' => __( 'ページ導入文', 'wte_' ), 'section' => 'wte_section_contact', 'type' => 'textarea', 'priority' => 30 ] );
	$wp_customize->add_control( 'wte_contact_cta_label', [ 'label' => __( 'メールリンクボタンテキスト', 'wte_' ), 'section' => 'wte_section_contact', 'type' => 'text', 'priority' => 40 ] );
	$wp_customize->add_control( new WTE_Toggle_Control( $wp_customize, 'wte_contact_display_in_lp', [ 'label' => __( 'LPにCTAセクション表示', 'wte_' ), 'section' => 'wte_section_contact', 'priority' => 50 ] ) );

	// ── Panel 6: SEO ──
	$wp_customize->add_control( 'wte_meta_description', [ 'label' => __( 'メタディスクリプション', 'wte_' ), 'section' => 'wte_section_seo', 'type' => 'textarea', 'priority' => 10, 'input_attrs' => [ 'maxlength' => 160 ] ] );
	$wp_customize->add_control( new \WP_Customize_Image_Control( $wp_customize, 'wte_og_image', [ 'label' => __( 'OGP画像（1200×630推奨）', 'wte_' ), 'section' => 'wte_section_seo', 'priority' => 20 ] ) );
	$biz_types = [ 'ProfessionalService' => __( '専門サービス', 'wte_' ), 'LegalService' => __( '法律サービス', 'wte_' ), 'Accountant' => __( '会計士', 'wte_' ), 'FinancialPlanningService' => __( 'ファイナンシャルプランナー', 'wte_' ), 'InsuranceAgency' => __( '保険代理店', 'wte_' ), 'Dentist' => __( '歯科医', 'wte_' ), 'Physician' => __( '医師', 'wte_' ), 'Architect' => __( '建築家', 'wte_' ), 'ITConsultant' => __( 'ITコンサルタント', 'wte_' ), 'MarketingConsultant' => __( 'マーケティングコンサルタント', 'wte_' ), 'PhotographStudio' => __( '写真スタジオ', 'wte_' ), 'TravelAgency' => __( '旅行代理店', 'wte_' ), 'LocalBusiness' => __( '地域ビジネス', 'wte_' ) ];
	$wp_customize->add_control( 'wte_schema_business_type', [ 'label' => __( 'ビジネスタイプ', 'wte_' ), 'section' => 'wte_section_seo', 'type' => 'select', 'choices' => $biz_types, 'priority' => 30 ] );
	$wp_customize->add_control( 'wte_schema_price_range', [ 'label' => __( '価格帯', 'wte_' ), 'section' => 'wte_section_seo', 'type' => 'select', 'choices' => [ '¥' => '¥', '¥¥' => '¥¥', '¥¥¥' => '¥¥¥', '¥¥¥¥' => '¥¥¥¥' ], 'priority' => 40 ] );
	$wp_customize->add_control( 'wte_google_analytics_id', [ 'label' => __( 'Google Analytics 4 計測ID', 'wte_' ), 'section' => 'wte_section_google', 'type' => 'text', 'priority' => 10 ] );
	$wp_customize->add_control( 'wte_recaptcha_site_key', [ 'label' => __( 'reCAPTCHA v3 サイトキー', 'wte_' ), 'section' => 'wte_section_google', 'type' => 'text', 'priority' => 20 ] );
	$wp_customize->add_control( 'wte_recaptcha_secret_key', [ 'label' => __( 'reCAPTCHA v3 シークレットキー', 'wte_' ), 'section' => 'wte_section_google', 'type' => 'text', 'priority' => 30 ] );
	$wp_customize->add_control( new WTE_Toggle_Control( $wp_customize, 'wte_noindex', [ 'label' => __( 'インデックスさせない', 'wte_' ), 'section' => 'wte_section_seo', 'priority' => 50 ] ) );
}
add_action( 'customize_register', 'wte_customizer_controls', 13 );
