<?php
/**
 * 主题自定义函数
 * 包含所有主题自定义器设置
 */

// 防止直接访问
if (!defined('ABSPATH')) {
    exit;
}
/**
 * 浮点数验证函数
 */
function nenghui_sanitize_float($value) {
    return (float) $value;
}

/**
 * 添加自定义器设置
 */
function nenghui_customize_register($wp_customize) {
    // 定义自定义画廊控制器类
    if (class_exists('WP_Customize_Control')) {
        class Nenghui_Gallery_Control extends WP_Customize_Control {
            public $type = 'gallery';

            public function render_content() {
                ?>
                <label>
                    <span class="customize-control-title"><?php echo esc_html($this->label); ?></span>
                    <?php if (!empty($this->description)) : ?>
                        <span class="description customize-control-description"><?php echo $this->description; ?></span>
                    <?php endif; ?>
                    <div class="gallery-control-wrapper">
                        <input type="hidden" <?php $this->link(); ?> value="<?php echo esc_attr($this->value()); ?>" />
                        <button type="button" class="button gallery-select-button">选择图片</button>
                        <button type="button" class="button gallery-clear-button" style="margin-left: 10px;">清空</button>
                        <div class="gallery-preview" style="margin-top: 10px;"></div>
                    </div>
                </label>
                <?php
            }

            public function enqueue() {
                wp_enqueue_media();
            }
        }
    }

    // 添加Banner设置面板
    $wp_customize->add_panel('nenghui_banner_panel', array(
        'title' => '首页Banner设置',
        'description' => '配置首页Banner轮播图片和内容',
        'priority' => 30,
    ));

    // 为每个Banner添加设置区域
    for ($i = 1; $i <= 5; $i++) {
        // 添加Banner区域
        $wp_customize->add_section('nenghui_banner_section_' . $i, array(
            'title' => 'Banner ' . $i,
            'panel' => 'nenghui_banner_panel',
            'priority' => $i * 10,
        ));

        // Banner图片设置
        $wp_customize->add_setting('banner_image_' . $i, array(
            'default' => '',
            'sanitize_callback' => 'esc_url_raw',
        ));
        $wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'banner_image_' . $i, array(
            'label' => 'Banner图片',
            'description' => '上传Banner背景图片（如果同时设置了视频，图片将作为视频加载失败时的备用显示）',
            'section' => 'nenghui_banner_section_' . $i,
            'settings' => 'banner_image_' . $i,
        )));

        // Banner视频设置
        $wp_customize->add_setting('banner_video_' . $i, array(
            'default' => '',
            'sanitize_callback' => 'esc_url_raw',
        ));
        $wp_customize->add_control('banner_video_' . $i, array(
            'label' => 'Banner视频URL',
            'description' => '输入视频文件的完整URL地址（支持MP4格式）。视频将自动循环播放且静音，用户无法控制播放。',
            'section' => 'nenghui_banner_section_' . $i,
            'type' => 'url',
            'input_attrs' => array(
                'placeholder' => 'https://example.com/video.mp4',
            ),
        ));

        // Banner内容设置（富文本编辑器）
        $wp_customize->add_setting('banner_content_' . $i, array(
            'default' => '<h2>Banner标题 ' . $i . '</h2><p>这里是Banner描述文字，可以介绍您的产品或服务。</p>',
            'sanitize_callback' => 'wp_kses_post',
        ));
        $wp_customize->add_control('banner_content_' . $i, array(
            'label' => 'Banner内容',
            'description' => '支持HTML标签的富文本内容，可以使用完整的HTML标签来自定义样式和布局',
            'section' => 'nenghui_banner_section_' . $i,
            'type' => 'textarea',
            'input_attrs' => array(
                'placeholder' => '输入HTML内容，例如：<h2>标题</h2><p>描述文字</p>',
                'rows' => 8,
            ),
        ));

        // Banner按钮文字设置
        $wp_customize->add_setting('banner_button_text_' . $i, array(
            'default' => '了解更多',
            'sanitize_callback' => 'sanitize_text_field',
        ));
        $wp_customize->add_control('banner_button_text_' . $i, array(
            'label' => '按钮文字',
            'section' => 'nenghui_banner_section_' . $i,
            'type' => 'text',
        ));

        // Banner按钮链接设置
        $wp_customize->add_setting('banner_button_url_' . $i, array(
            'default' => '#',
            'sanitize_callback' => 'esc_url_raw',
        ));
        $wp_customize->add_control('banner_button_url_' . $i, array(
            'label' => '按钮链接',
            'section' => 'nenghui_banner_section_' . $i,
            'type' => 'url',
        ));
    }

    // 添加Banner全局设置区域
    $wp_customize->add_section('nenghui_banner_global_settings', array(
        'title' => 'Banner全局设置',
        'panel' => 'nenghui_banner_panel',
        'priority' => 100,
    ));

    // Banner数量设置
    $wp_customize->add_setting('banner_count', array(
        'default' => 3,
        'sanitize_callback' => 'absint',
        'transport' => 'postMessage'
    ));
    $wp_customize->add_control('banner_count', array(
        'label' => 'Banner数量',
        'description' => '设置要显示的Banner数量（1-5个）。只有上传了图片的Banner才会显示。',
        'section' => 'nenghui_banner_global_settings',
        'type' => 'range',
        'input_attrs' => array(
            'min' => 1,
            'max' => 5,
            'step' => 1
        )
    ));
    // Banner高度设置
    $wp_customize->add_setting('banner_height', array(
        'default' => '500px',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('banner_height', array(
        'label' => 'Banner高度',
        'description' => '支持px和vh单位，例如：500px 或 50vh',
        'section' => 'nenghui_banner_global_settings',
        'type' => 'text',
        'input_attrs' => array(
            'placeholder' => '500px 或 50vh',
        ),
    ));

    // 自动播放设置
    $wp_customize->add_setting('banner_autoplay', array(
        'default' => true,
        'sanitize_callback' => 'wp_validate_boolean',
    ));
    $wp_customize->add_control('banner_autoplay', array(
        'label' => '启用自动播放',
        'section' => 'nenghui_banner_global_settings',
        'type' => 'checkbox',
    ));

    // 播放间隔设置
    $wp_customize->add_setting('banner_autoplay_delay', array(
        'default' => '5000',
        'sanitize_callback' => 'absint',
    ));
    $wp_customize->add_control('banner_autoplay_delay', array(
        'label' => '自动播放间隔 (毫秒)',
        'section' => 'nenghui_banner_global_settings',
        'type' => 'number',
        'input_attrs' => array(
            'min' => 1000,
            'max' => 10000,
            'step' => 500,
        ),
    ));

    // Banner遮罩开关设置
    $wp_customize->add_setting('banner_overlay_enabled', array(
        'default' => true,
        'sanitize_callback' => 'wp_validate_boolean',
    ));
    $wp_customize->add_control('banner_overlay_enabled', array(
        'label' => '启用Banner遮罩',
        'description' => '开启后会在Banner图片上添加半透明黑色遮罩，提高文字可读性',
        'section' => 'nenghui_banner_global_settings',
        'type' => 'checkbox',
    ));

    // Banner纯图模式开关设置
    $wp_customize->add_setting('banner_image_only_mode', array(
        'default' => false,
        'sanitize_callback' => 'wp_validate_boolean',
    ));
    $wp_customize->add_control('banner_image_only_mode', array(
        'label' => '启用纯图模式',
        'description' => '开启后只显示背景图片，隐藏标题、描述和按钮',
        'section' => 'nenghui_banner_global_settings',
        'type' => 'checkbox',
    ));

    // Banner移动端显示控制设置
    $wp_customize->add_setting('banner_show_on_mobile', array(
        'default' => true,
        'sanitize_callback' => 'wp_validate_boolean',
        'transport' => 'postMessage',
    ));
    $wp_customize->add_control('banner_show_on_mobile', array(
        'label' => '在移动端显示Banner',
        'description' => '关闭此开关后，Banner区块将在移动设备（屏幕宽度小于768px）上隐藏',
        'section' => 'nenghui_banner_global_settings',
        'type' => 'checkbox',
    ));

    // 添加Banner Title设置面板
    $wp_customize->add_panel('nenghui_banner_title_panel', array(
        'title' => '页面标题横幅设置',
        'description' => '配置页面标题横幅区块的内容和样式',
        'priority' => 34,
    ));

    // 添加Banner Title基本设置区域
    $wp_customize->add_section('nenghui_banner_title_basic_settings', array(
        'title' => '页面标题横幅基本设置',
        'panel' => 'nenghui_banner_title_panel',
        'priority' => 10,
    ));

    // Banner Title标题设置
    $wp_customize->add_setting('banner_title_main_title', array(
        'default' => 'ABOUT US',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('banner_title_main_title', array(
        'label' => '主标题',
        'section' => 'nenghui_banner_title_basic_settings',
        'type' => 'text',
    ));

    // Banner Title描述设置
    $wp_customize->add_setting('banner_title_description', array(
        'default' => 'Powering Sustainable Futures with Advanced Energy Storage Solutions',
        'sanitize_callback' => 'sanitize_textarea_field',
    ));
    $wp_customize->add_control('banner_title_description', array(
        'label' => '描述文字',
        'section' => 'nenghui_banner_title_basic_settings',
        'type' => 'textarea',
        'input_attrs' => array(
            'rows' => 3,
        ),
    ));

    // Banner Title背景图片设置
    $wp_customize->add_setting('banner_title_bg_image', array(
        'default' => get_template_directory_uri() . '/assets/images/about-bg.webp',
        'sanitize_callback' => 'esc_url_raw',
    ));
    $wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'banner_title_bg_image', array(
        'label' => '背景图片',
        'section' => 'nenghui_banner_title_basic_settings',
        'settings' => 'banner_title_bg_image',
    )));

    // Banner Title遮罩透明度设置
    $wp_customize->add_setting('banner_title_overlay_opacity', array(
        'default' => '0.4',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('banner_title_overlay_opacity', array(
        'label' => '遮罩透明度',
        'description' => '设置背景遮罩的透明度（0-1之间的数值）',
        'section' => 'nenghui_banner_title_basic_settings',
        'type' => 'range',
        'input_attrs' => array(
            'min' => 0,
            'max' => 1,
            'step' => 0.1,
        ),
    ));

    // Banner Title高度设置
    $wp_customize->add_setting('banner_title_height', array(
        'default' => '60vh',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('banner_title_height', array(
        'label' => 'Banner高度',
        'description' => '支持px、vh、%单位，例如：60vh、500px、100%',
        'section' => 'nenghui_banner_title_basic_settings',
        'type' => 'text',
        'input_attrs' => array(
            'placeholder' => '60vh',
        ),
    ));

    // 添加选项卡设置面板
    $wp_customize->add_panel('nenghui_tabs_panel', array(
        'title' => '选项卡设置',
        'description' => '配置首页选项卡内容和样式',
        'priority' => 35,
    ));

    // 选项卡数量设置
    $wp_customize->add_section('nenghui_tabs_global_settings', array(
        'title' => '选项卡全局设置',
        'panel' => 'nenghui_tabs_panel',
        'priority' => 10,
    ));

    $wp_customize->add_setting('tabs_count', array(
        'default' => 3,
        'sanitize_callback' => 'absint',
        'transport' => 'postMessage'
    ));
    $wp_customize->add_control('tabs_count', array(
        'label' => '选项卡数量',
        'description' => '设置要显示的选项卡数量（1-5个）。只有设置了标题的选项卡才会显示。',
        'section' => 'nenghui_tabs_global_settings',
        'type' => 'range',
        'input_attrs' => array(
            'min' => 1,
            'max' => 5,
            'step' => 1
        )
    ));
    // 为每个选项卡添加设置（最多5个）
    for ($i = 1; $i <= 5; $i++) {
        // 添加选项卡区域
        $wp_customize->add_section('nenghui_tab_section_' . $i, array(
            'title' => '选项卡 ' . $i,
            'panel' => 'nenghui_tabs_panel',
            'priority' => $i * 10 + 10,
        ));

        // 选项卡标题设置
        $wp_customize->add_setting('tab_title_' . $i, array(
            'default' => "选项卡 {$i}",
            'sanitize_callback' => 'sanitize_text_field',
        ));
        $wp_customize->add_control('tab_title_' . $i, array(
            'label' => '选项卡标题',
            'section' => 'nenghui_tab_section_' . $i,
            'type' => 'text',
        ));

        // 选项卡标识符设置
        $wp_customize->add_setting('tab_id_' . $i, array(
            'default' => "tab-{$i}",
            'sanitize_callback' => 'sanitize_key',
        ));
        $wp_customize->add_control('tab_id_' . $i, array(
            'label' => '选项卡标识符',
            'description' => '用于内部识别，只能包含字母、数字和下划线',
            'section' => 'nenghui_tab_section_' . $i,
            'type' => 'text',
        ));

        // 主标题设置
        $wp_customize->add_setting('tab_main_title_' . $i, array(
            'default' => "这是选项卡 {$i} 的主要内容标题",
            'sanitize_callback' => 'wp_kses_post',
        ));
        $wp_customize->add_control('tab_main_title_' . $i, array(
            'label' => '主标题',
            'description' => '支持HTML标签，可以使用<span class="highlight">文字</span>来高亮显示',
            'section' => 'nenghui_tab_section_' . $i,
            'type' => 'textarea',
            'input_attrs' => array(
                'rows' => 3,
            ),
        ));

        // 按钮文字设置
        $wp_customize->add_setting('tab_button_text_' . $i, array(
            'default' => "了解更多",
            'sanitize_callback' => 'sanitize_text_field',
        ));
        $wp_customize->add_control('tab_button_text_' . $i, array(
            'label' => '按钮文字',
            'section' => 'nenghui_tab_section_' . $i,
            'type' => 'text',
        ));

        // 按钮链接设置
        $wp_customize->add_setting('tab_button_url_' . $i, array(
            'default' => '#',
            'sanitize_callback' => 'esc_url_raw',
        ));
        $wp_customize->add_control('tab_button_url_' . $i, array(
            'label' => '按钮链接',
            'section' => 'nenghui_tab_section_' . $i,
            'type' => 'url',
        ));

        // 图片设置
        $wp_customize->add_setting('tab_image_' . $i, array(
            'default' => get_template_directory_uri() . '/assets/images/NaN-img.png',
            'sanitize_callback' => 'esc_url_raw',
        ));
        $wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'tab_image_' . $i, array(
            'label' => '选项卡图片',
            'section' => 'nenghui_tab_section_' . $i,
            'settings' => 'tab_image_' . $i,
        )));

        // 图片替代文字设置
        $wp_customize->add_setting('tab_image_alt_' . $i, array(
            'default' => "选项卡 {$i} 图片",
            'sanitize_callback' => 'sanitize_text_field',
        ));
        $wp_customize->add_control('tab_image_alt_' . $i, array(
            'label' => '图片替代文字',
            'description' => '用于SEO和无障碍访问',
            'section' => 'nenghui_tab_section_' . $i,
            'type' => 'text',
        ));
    }
    $wp_customize->add_control('banner_image_only_mode', array(
        'label' => '启用纯图模式',
        'description' => '开启后将隐藏所有文字和按钮，只显示Banner图片',
        'section' => 'nenghui_banner_global_settings',
        'type' => 'checkbox',
    ));

    // Banner左右切换按钮开关设置
    $wp_customize->add_setting('banner_navigation_enabled', array(
        'default' => true,
        'sanitize_callback' => 'wp_validate_boolean',
    ));
    $wp_customize->add_control('banner_navigation_enabled', array(
        'label' => '显示左右切换按钮',
        'description' => '开启后将显示Banner的左右切换箭头按钮',
        'section' => 'nenghui_banner_global_settings',
        'type' => 'checkbox',
    ));

    // Banner背景图片缩放动画开关设置
    $wp_customize->add_setting('banner_zoom_animation_enabled', array(
        'default' => true,
        'sanitize_callback' => 'wp_validate_boolean',
    ));
    $wp_customize->add_control('banner_zoom_animation_enabled', array(
        'label' => '启用背景图片缩放动画',
        'description' => '开启后Banner背景图片会缓慢平滑放大，营造动态视觉效果',
        'section' => 'nenghui_banner_global_settings',
        'type' => 'checkbox',
    ));

    // Banner背景图片缩放动画速度设置
    $wp_customize->add_setting('banner_zoom_animation_duration', array(
        'default' => 20,
        'sanitize_callback' => 'absint',
    ));
    $wp_customize->add_control('banner_zoom_animation_duration', array(
        'label' => '缩放动画持续时间（秒）',
        'description' => '设置背景图片从原始大小放大到最终大小所需的时间',
        'section' => 'nenghui_banner_global_settings',
        'type' => 'range',
        'input_attrs' => array(
            'min' => 5,
            'max' => 60,
            'step' => 1,
        ),
    ));

    // Banner背景图片缩放比例设置
    $wp_customize->add_setting('banner_zoom_animation_scale', array(
        'default' => 1.08,
        'sanitize_callback' => 'nenghui_sanitize_float',
    ));
    $wp_customize->add_control('banner_zoom_animation_scale', array(
        'label' => '缩放比例',
        'description' => '设置背景图片最终放大的倍数（1.0-1.5倍）',
        'section' => 'nenghui_banner_global_settings',
        'type' => 'range',
        'input_attrs' => array(
            'min' => 1.0,
            'max' => 1.5,
            'step' => 0.01,
        ),
    ));

    // Banner显示顺序设置
    $wp_customize->add_setting('banner_display_order', array(
        'default' => '1,2,3,4,5',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('banner_display_order', array(
        'label' => 'Banner显示顺序',
        'description' => '设置Banner的显示顺序，用逗号分隔，例如：3,1,4,2,5 表示先显示Banner3，再显示Banner1，以此类推',
        'section' => 'nenghui_banner_global_settings',
        'type' => 'text',
        'input_attrs' => array(
            'placeholder' => '1,2,3,4,5',
        ),
    ));

    // 添加Futures设置面板
    $wp_customize->add_panel('nenghui_futures_panel', array(
        'title' => '特色功能设置',
        'description' => '配置特色功能区块的内容和样式',
        'priority' => 35,
    ));

    // 添加About导航设置面板
    $wp_customize->add_panel('nenghui_about_nav_panel', array(
        'title' => '关于我们导航设置',
        'description' => '配置关于我们页面导航菜单的显示和样式',
        'priority' => 36,
    ));

    // 添加About导航基本设置区域
    $wp_customize->add_section('nenghui_about_nav_settings', array(
        'title' => '关于我们导航基本设置',
        'panel' => 'nenghui_about_nav_panel',
        'priority' => 10,
    ));

    // About导航菜单选择设置
    $wp_customize->add_setting('about_nav_menu_id', array(
        'default' => '',
        'sanitize_callback' => 'nenghui_sanitize_menu_id',
    ));
    $wp_customize->add_control('about_nav_menu_id', array(
         'label' => '选择导航菜单',
         'description' => '选择要在About页面显示的导航菜单',
         'section' => 'nenghui_about_nav_settings',
         'type' => 'select',
         'choices' => nenghui_get_nav_menu_choices(),
     ));

    // About导航显示位置设置
    $wp_customize->add_setting('about_nav_position', array(
        'default' => 'top',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('about_nav_position', array(
        'label' => '导航显示位置',
        'section' => 'nenghui_about_nav_settings',
        'type' => 'select',
        'choices' => array(
            'top' => '页面顶部',
            'sidebar' => '侧边栏',
            'bottom' => '页面底部',
        ),
    ));

    // About导航样式设置
    $wp_customize->add_setting('about_nav_style', array(
        'default' => 'horizontal',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('about_nav_style', array(
        'label' => '导航样式',
        'section' => 'nenghui_about_nav_settings',
        'type' => 'select',
        'choices' => array(
            'horizontal' => '水平排列',
            'vertical' => '垂直排列',
            'dropdown' => '下拉菜单',
        ),
    ));

    // About导航背景色设置
    $wp_customize->add_setting('about_nav_bg_color', array(
        'default' => '#ffffff',
        'sanitize_callback' => 'sanitize_hex_color',
    ));
    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'about_nav_bg_color', array(
        'label' => '导航背景色',
        'section' => 'nenghui_about_nav_settings',
        'settings' => 'about_nav_bg_color',
    )));

    // About导航文字颜色设置
    $wp_customize->add_setting('about_nav_text_color', array(
        'default' => '#333333',
        'sanitize_callback' => 'sanitize_hex_color',
    ));
    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'about_nav_text_color', array(
        'label' => '导航文字颜色',
        'section' => 'nenghui_about_nav_settings',
        'settings' => 'about_nav_text_color',
    )));

    // About导航激活状态颜色设置
    $wp_customize->add_setting('about_nav_active_color', array(
        'default' => '#007cba',
        'sanitize_callback' => 'sanitize_hex_color',
    ));
    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'about_nav_active_color', array(
        'label' => '激活状态颜色',
        'section' => 'nenghui_about_nav_settings',
        'settings' => 'about_nav_active_color',
    )));

    // 添加新闻区块设置面板
    $wp_customize->add_panel('nenghui_news_panel', array(
        'title' => '首页新闻设置',
        'description' => '配置首页新闻区块的显示内容和样式',
        'priority' => 40,
    ));

    // 添加新闻基本设置区域
    $wp_customize->add_section('nenghui_news_basic_settings', array(
        'title' => '新闻基本设置',
        'panel' => 'nenghui_news_panel',
        'priority' => 10,
    ));

    // 新闻区块标题设置
    $wp_customize->add_setting('news_title', array(
        'default' => 'NEWS',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('news_title', array(
        'label' => '新闻区块标题',
        'section' => 'nenghui_news_basic_settings',
        'type' => 'text',
    ));



    // 文章分类ID设置
    $wp_customize->add_setting('news_category_id', array(
        'default' => '',
        'sanitize_callback' => 'absint',
    ));
    $wp_customize->add_control('news_category_id', array(
        'label' => '文章分类ID',
        'description' => '指定要显示的文章分类ID，留空则显示所有分类的文章。注意：在分类页面使用短代码时会自动使用当前分类，短代码参数优先级最高。',
        'section' => 'nenghui_news_basic_settings',
        'type' => 'number',
        'input_attrs' => array(
            'min' => 0,
            'step' => 1,
        ),
    ));

    // 文章排序方式设置
    $wp_customize->add_setting('news_order_by', array(
        'default' => 'date',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('news_order_by', array(
        'label' => '文章排序方式',
        'section' => 'nenghui_news_basic_settings',
        'type' => 'select',
        'choices' => array(
            'date' => '按发布日期',
            'modified' => '按修改日期',
            'title' => '按标题',
            'menu_order' => '按菜单顺序',
            'rand' => '随机排序',
        ),
    ));

    // 文章排序顺序设置
    $wp_customize->add_setting('news_order', array(
        'default' => 'DESC',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('news_order', array(
        'label' => '排序顺序',
        'section' => 'nenghui_news_basic_settings',
        'type' => 'select',
        'choices' => array(
            'DESC' => '降序（新到旧）',
            'ASC' => '升序（旧到新）',
        ),
    ));

    // 显示文章数量设置
    $wp_customize->add_setting('news_posts_count', array(
        'default' => 3,
        'sanitize_callback' => 'absint',
    ));
    $wp_customize->add_control('news_posts_count', array(
        'label' => '显示文章数量',
        'description' => '设置在没有分页时显示的文章数量',
        'section' => 'nenghui_news_basic_settings',
        'type' => 'number',
        'input_attrs' => array(
            'min' => 1,
            'max' => 10,
            'step' => 1,
        ),
    ));

    // 每页显示文章数量设置（用于分页）
    $wp_customize->add_setting('news_posts_per_page', array(
        'default' => 6,
        'sanitize_callback' => 'absint',
    ));
    $wp_customize->add_control('news_posts_per_page', array(
        'label' => '每页显示文章数量',
        'description' => '设置启用分页时每页显示的文章数量',
        'section' => 'nenghui_news_basic_settings',
        'type' => 'number',
        'input_attrs' => array(
            'min' => 1,
            'max' => 20,
            'step' => 1,
        ),
    ));

    // 是否启用分页设置
    $wp_customize->add_setting('news_enable_pagination', array(
        'default' => false,
        'sanitize_callback' => 'wp_validate_boolean',
    ));
    $wp_customize->add_control('news_enable_pagination', array(
        'label' => '启用分页',
        'description' => '启用后将显示数字分页组件，否则只显示指定数量的文章',
        'section' => 'nenghui_news_basic_settings',
        'type' => 'checkbox',
    ));

    // 添加Futures基本设置区域
    $wp_customize->add_section('nenghui_futures_basic_settings', array(
        'title' => '特色功能基本设置',
        'panel' => 'nenghui_futures_panel',
        'priority' => 10,
    ));

    // Futures标题设置
    $wp_customize->add_setting('futures_title', array(
        'default' => 'Powering Sustainble Futures',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('futures_title', array(
        'label' => '特色功能主标题',
        'section' => 'nenghui_futures_basic_settings',
        'type' => 'text',
    ));

    // Futures背景图片设置
    $wp_customize->add_setting('futures_bg_image', array(
        'default' => get_template_directory_uri() . '/assets/images/futures-bg.webp',
        'sanitize_callback' => 'esc_url_raw',
    ));
    $wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'futures_bg_image', array(
        'label' => '特色功能背景图片',
        'section' => 'nenghui_futures_basic_settings',
        'settings' => 'futures_bg_image',
    )));

    // Futures按钮文字设置
    $wp_customize->add_setting('futures_button_text', array(
        'default' => 'About us',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('futures_button_text', array(
        'label' => '按钮文字',
        'section' => 'nenghui_futures_basic_settings',
        'type' => 'text',
    ));

    // Futures按钮链接设置
    $wp_customize->add_setting('futures_button_link', array(
        'default' => 'about.html',
        'sanitize_callback' => 'esc_url_raw',
    ));
    $wp_customize->add_control('futures_button_link', array(
        'label' => '按钮链接',
        'section' => 'nenghui_futures_basic_settings',
        'type' => 'url',
    ));

    // 为每个Futures项目添加设置区域
    $default_items = array(
        1 => array('title' => 'High-Performance', 'icon' => './images/2_03.png'),
        2 => array('title' => 'Advanced Safety', 'icon' => './images/2_05.png'),
        3 => array('title' => 'Smart Energy', 'icon' => './images/4_05.png'),
        4 => array('title' => 'Fast Deployment', 'icon' => './images/5_05.png'),
        5 => array('title' => 'Global Compliance', 'icon' => './images/7_05.png'),
    );

    for ($i = 1; $i <= 5; $i++) {
        // 添加Futures项目区域
        $wp_customize->add_section('nenghui_futures_item_' . $i, array(
            'title' => '特色功能项目 ' . $i,
            'panel' => 'nenghui_futures_panel',
            'priority' => 10 + $i * 10,
        ));

        // 项目图标设置
        $wp_customize->add_setting('futures_item_' . $i . '_icon', array(
            'default' => get_template_directory_uri() . '/assets/images/NaN-img.png',
            'sanitize_callback' => 'esc_url_raw',
        ));
        $wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'futures_item_' . $i . '_icon', array(
            'label' => '项目图标',
            'section' => 'nenghui_futures_item_' . $i,
            'settings' => 'futures_item_' . $i . '_icon',
        )));

        // 项目标题设置
        $wp_customize->add_setting('futures_item_' . $i . '_title', array(
            'default' => $default_items[$i]['title'],
            'sanitize_callback' => 'sanitize_text_field',
        ));
        $wp_customize->add_control('futures_item_' . $i . '_title', array(
            'label' => '项目标题',
            'section' => 'nenghui_futures_item_' . $i,
            'type' => 'text',
        ));


    }

    // 添加About Company设置面板
    $wp_customize->add_panel('nenghui_about_company_panel', array(
        'title' => '关于公司设置',
        'description' => '配置关于公司区块的内容和样式',
        'priority' => 37,
    ));

    // 添加About Company基本设置区域
    $wp_customize->add_section('nenghui_about_company_basic_settings', array(
        'title' => '关于公司基本设置',
        'panel' => 'nenghui_about_company_panel',
        'priority' => 10,
    ));

    // About Company主标题设置
    $wp_customize->add_setting('about_company_title', array(
        'default' => 'ABOUT NENGHUI',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('about_company_title', array(
        'label' => '主标题',
        'section' => 'nenghui_about_company_basic_settings',
        'type' => 'text',
    ));

    // About Company描述设置
    $wp_customize->add_setting('about_company_description', array(
        'default' => 'Nenghui Technology (Shanghai Nenghui Technology Co., Ltd., SZ stock: 301046), established in 2018, is a listed public company with business ranging from solar power plant EPC, operation and maintenance, renewable energy services, microgrid solutions, energy storage and refuse pyrolysis, etc. With years of continuous innovation in the renewable energy industry, Nenghui has formed a comprehensive technology system and industrial layout in smart energy development and applications.',
        'sanitize_callback' => 'wp_kses_post',
    ));
    $wp_customize->add_control('about_company_description', array(
        'label' => '公司描述',
        'section' => 'nenghui_about_company_basic_settings',
        'type' => 'textarea',
        'input_attrs' => array(
            'rows' => 6,
        ),
    ));

    // About Company右侧图片设置
    $wp_customize->add_setting('about_company_image', array(
        'default' => get_template_directory_uri() . '/assets/images/about-img.webp',
        'sanitize_callback' => 'esc_url_raw',
    ));
    $wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'about_company_image', array(
        'label' => '右侧图片',
        'section' => 'nenghui_about_company_basic_settings',
        'settings' => 'about_company_image',
    )));

    // About Company第二段描述设置
    $wp_customize->add_setting('about_company_description_2', array(
        'default' => 'Nenghui Energy, established in 2018, is a subsidiary entity of Nenghui Technology that focuses on lithium battery storage. Since 2018, Nenghui Energy has developed advanced and highly safe LFP battery storage systems (BESS) for homes and businesses. Ranging from low to high voltage and from single to multiple operations, as well as from cabinets to containers, with continuous technological innovations, Nenghui has been awarded excellent recognition in the industry and is committed to providing prompt service for all of our current and potential customers.',
        'sanitize_callback' => 'wp_kses_post',
    ));
    $wp_customize->add_control('about_company_description_2', array(
        'label' => '第二段描述',
        'section' => 'nenghui_about_company_basic_settings',
        'type' => 'textarea',
        'input_attrs' => array(
            'rows' => 6,
        ),
    ));

    // 为每个统计项目添加设置区域
    $default_stats = array(
        1 => array('number' => '130+', 'label' => 'Patents', 'icon' => get_template_directory_uri() . '/assets/images/about-icon-1.svg'),
        2 => array('number' => '70%', 'label' => 'R&D employees', 'icon' => get_template_directory_uri() . '/assets/images/about-icon-2.svg'),
        3 => array('number' => '100+', 'label' => 'Solar power stations', 'icon' => get_template_directory_uri() . '/assets/images/about-icon-3.svg'),
        4 => array('number' => '200+', 'label' => 'Grid engineering projects', 'icon' => get_template_directory_uri() . '/assets/images/about-icon-4.svg'),
    );

    for ($i = 1; $i <= 4; $i++) {
        // 添加统计项目区域
        $wp_customize->add_section('nenghui_about_company_stat_' . $i, array(
            'title' => '统计项目 ' . $i,
            'panel' => 'nenghui_about_company_panel',
            'priority' => 10 + $i * 10,
        ));

        // 统计数字设置
        $wp_customize->add_setting('about_company_stat_' . $i . '_number', array(
            'default' => $default_stats[$i]['number'],
            'sanitize_callback' => 'sanitize_text_field',
        ));
        $wp_customize->add_control('about_company_stat_' . $i . '_number', array(
            'label' => '统计数字',
            'section' => 'nenghui_about_company_stat_' . $i,
            'type' => 'text',
        ));

        // 统计标签设置
        $wp_customize->add_setting('about_company_stat_' . $i . '_label', array(
            'default' => $default_stats[$i]['label'],
            'sanitize_callback' => 'sanitize_text_field',
        ));
        $wp_customize->add_control('about_company_stat_' . $i . '_label', array(
            'label' => '统计标签',
            'section' => 'nenghui_about_company_stat_' . $i,
            'type' => 'text',
        ));

        // 统计图标设置
        $wp_customize->add_setting('about_company_stat_' . $i . '_icon', array(
            'default' => $default_stats[$i]['icon'],
            'sanitize_callback' => 'esc_url_raw',
        ));
        $wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'about_company_stat_' . $i . '_icon', array(
            'label' => '统计图标',
            'section' => 'nenghui_about_company_stat_' . $i,
            'settings' => 'about_company_stat_' . $i . '_icon',
        )));
    }

    // 添加Development History设置面板
    $wp_customize->add_panel('nenghui_development_history_panel', array(
        'title' => '发展历程设置',
        'description' => '配置发展历程区块的内容和样式',
        'priority' => 38,
    ));

    // 添加Development History基本设置区域
    $wp_customize->add_section('nenghui_development_history_basic_settings', array(
        'title' => '发展历程基本设置',
        'panel' => 'nenghui_development_history_panel',
        'priority' => 10,
    ));

    // Development History主标题设置
    $wp_customize->add_setting('development_history_title', array(
        'default' => 'DEVELOPMENT HISTORY',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('development_history_title', array(
        'label' => '主标题',
        'section' => 'nenghui_development_history_basic_settings',
        'type' => 'text',
    ));

    // Development History背景图片设置
    $wp_customize->add_setting('development_history_bg_image', array(
        'default' => get_template_directory_uri() . '/assets/images/Development History.webp',
        'sanitize_callback' => 'esc_url_raw',
    ));
    $wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'development_history_bg_image', array(
        'label' => '背景图片',
        'section' => 'nenghui_development_history_basic_settings',
        'settings' => 'development_history_bg_image',
    )));

    // Development History年份数量设置
    $wp_customize->add_setting('development_history_items_count', array(
        'default' => 5,
        'sanitize_callback' => 'absint',
    ));
    $wp_customize->add_control('development_history_items_count', array(
        'label' => '年份项目数量',
        'description' => '设置要显示的历史年份数量（1-20）',
        'section' => 'nenghui_development_history_basic_settings',
        'type' => 'number',
        'input_attrs' => array(
            'min' => 1,
            'max' => 20,
            'step' => 1,
        ),
    ));

    // 为每个历史年份添加设置区域
    $default_history = array(
        1 => array('year' => '2009', 'description' => '', 'active' => false),
        2 => array('year' => '2012', 'description' => '', 'active' => false),
        3 => array('year' => '2015', 'description' => 'Over 800 MW solar power plants on hand in operation.', 'active' => true),
        4 => array('year' => '2021', 'description' => '', 'active' => false),
        5 => array('year' => '2022', 'description' => '', 'active' => false),
    );

    // 获取年份数量设置，默认为5，最大为20
    $items_count = get_theme_mod('development_history_items_count', 5);
    $items_count = min(max(1, intval($items_count)), 20); // 限制在1-20之间

    for ($i = 1; $i <= $items_count; $i++) {
        // 添加历史年份区域
        $wp_customize->add_section('nenghui_development_history_item_' . $i, array(
            'title' => '历史年份 ' . $i,
            'panel' => 'nenghui_development_history_panel',
            'priority' => 10 + $i * 10,
        ));

        // 年份设置
        $wp_customize->add_setting('development_history_item_' . $i . '_year', array(
            'default' => $default_history[$i]['year'],
            'sanitize_callback' => 'sanitize_text_field',
        ));
        $wp_customize->add_control('development_history_item_' . $i . '_year', array(
            'label' => '年份',
            'section' => 'nenghui_development_history_item_' . $i,
            'type' => 'text',
        ));

        // 描述设置
        $wp_customize->add_setting('development_history_item_' . $i . '_description', array(
            'default' => $default_history[$i]['description'],
            'sanitize_callback' => 'wp_kses_post',
        ));
        $wp_customize->add_control('development_history_item_' . $i . '_description', array(
            'label' => '描述',
            'section' => 'nenghui_development_history_item_' . $i,
            'type' => 'textarea',
            'input_attrs' => array(
                'rows' => 3,
            ),
        ));

        // 是否为默认激活状态
        $wp_customize->add_setting('development_history_item_' . $i . '_active', array(
            'default' => $default_history[$i]['active'],
            'sanitize_callback' => 'wp_validate_boolean',
        ));
        $wp_customize->add_control('development_history_item_' . $i . '_active', array(
            'label' => '默认激活状态',
            'section' => 'nenghui_development_history_item_' . $i,
            'type' => 'checkbox',
        ));
    }

    // 添加证书画廊设置面板
    $wp_customize->add_panel('nenghui_certification_gallery_panel', array(
        'title' => '资质证书设置',
        'description' => '配置资质证书区块的内容和样式',
        'priority' => 39,
    ));

    // 添加证书画廊基本设置区域
    $wp_customize->add_section('nenghui_certification_gallery_basic_settings', array(
        'title' => '资质证书基本设置',
        'panel' => 'nenghui_certification_gallery_panel',
        'priority' => 10,
    ));

    // 证书画廊图片设置
    $wp_customize->add_setting('certification_gallery_images', array(
        'default' => '',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control(new Nenghui_Gallery_Control($wp_customize, 'certification_gallery_images', array(
        'label' => '资质证书图片',
        'description' => '点击按钮选择多张资质证书图片',
        'section' => 'nenghui_certification_gallery_basic_settings',
        'settings' => 'certification_gallery_images',
    )));

    // 证书画廊列数设置
    $wp_customize->add_setting('certification_gallery_columns', array(
        'default' => 5,
        'sanitize_callback' => 'absint',
    ));
    $wp_customize->add_control('certification_gallery_columns', array(
        'label' => '每行显示列数',
        'description' => '设置每行显示的资质证书数量（1-6）',
        'section' => 'nenghui_certification_gallery_basic_settings',
        'type' => 'number',
        'input_attrs' => array(
            'min' => 1,
            'max' => 6,
            'step' => 1,
        ),
    ));

    // 是否启用灯箱效果
    $wp_customize->add_setting('certification_gallery_lightbox', array(
        'default' => true,
        'sanitize_callback' => 'wp_validate_boolean',
    ));
    $wp_customize->add_control('certification_gallery_lightbox', array(
        'label' => '启用灯箱效果',
        'description' => '点击证书图片时显示大图',
        'section' => 'nenghui_certification_gallery_basic_settings',
        'type' => 'checkbox',
    ));

    // 是否启用动画效果
    $wp_customize->add_setting('certification_gallery_animation', array(
        'default' => true,
        'sanitize_callback' => 'wp_validate_boolean',
    ));
    $wp_customize->add_control('certification_gallery_animation', array(
        'label' => '启用动画效果',
        'description' => '滚动时显示动画',
        'section' => 'nenghui_certification_gallery_basic_settings',
        'type' => 'checkbox',
    ));



    // 添加联系地图设置面板
    $wp_customize->add_panel('nenghui_contact_map_panel', array(
        'title' => '联系地图设置',
        'description' => '配置联系方式和地图显示',
        'priority' => 45,
    ));

    // 添加联系方式基本设置区域
    $wp_customize->add_section('nenghui_contact_basic_settings', array(
        'title' => '联系方式基本设置',
        'panel' => 'nenghui_contact_map_panel',
        'priority' => 10,
    ));

    // 联系地图区块标题设置
    $wp_customize->add_setting('contact_map_title', array(
        'default' => '联系我们',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('contact_map_title', array(
        'label' => '区块标题',
        'section' => 'nenghui_contact_basic_settings',
        'type' => 'text',
    ));

    // 办公地址设置
    $wp_customize->add_setting('contact_office_address', array(
        'default' => 'i288 Tongxie Road Shanghai China 200335',
        'sanitize_callback' => 'sanitize_textarea_field',
    ));
    $wp_customize->add_control('contact_office_address', array(
        'label' => '办公地址',
        'section' => 'nenghui_contact_basic_settings',
        'type' => 'textarea',
        'input_attrs' => array(
            'rows' => 3,
        ),
    ));

    // 电话/手机设置
    $wp_customize->add_setting('contact_phone', array(
        'default' => '+86-21-50896255',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('contact_phone', array(
        'label' => '电话/手机',
        'section' => 'nenghui_contact_basic_settings',
        'type' => 'text',
    ));

    // 邮箱设置
    $wp_customize->add_setting('contact_email', array(
        'default' => 'info@nhet.energy',
        'sanitize_callback' => 'sanitize_email',
    ));
    $wp_customize->add_control('contact_email', array(
        'label' => '邮箱地址',
        'section' => 'nenghui_contact_basic_settings',
        'type' => 'email',
    ));

    // 添加地图设置区域
    $wp_customize->add_section('nenghui_contact_map_settings', array(
        'title' => '地图设置',
        'panel' => 'nenghui_contact_map_panel',
        'priority' => 20,
    ));

    // 地图嵌入代码设置
    $default_map_file = get_template_directory() . '/docs/Google-maps.txt';
    $default_map_code = '';
    if (file_exists($default_map_file)) {
        $default_map_code = file_get_contents($default_map_file);
    }
    
    $wp_customize->add_setting('contact_map_embed_code', array(
        'default' => $default_map_code,
        'sanitize_callback' => 'wp_unslash',
    ));
    $wp_customize->add_control('contact_map_embed_code', array(
        'label' => '地图嵌入代码',
        'description' => '粘贴Google地图或其他地图服务的嵌入代码',
        'section' => 'nenghui_contact_map_settings',
        'type' => 'textarea',
        'input_attrs' => array(
            'rows' => 8,
            'placeholder' => '粘贴地图嵌入代码...',
        ),
    ));

    // 地图高度设置
    $wp_customize->add_setting('contact_map_height', array(
        'default' => '400px',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('contact_map_height', array(
        'label' => '地图高度',
        'description' => '支持px、vh单位，例如：400px 或 50vh',
        'section' => 'nenghui_contact_map_settings',
        'type' => 'text',
        'input_attrs' => array(
            'placeholder' => '400px',
        ),
    ));

    // 添加样式设置区域
    $wp_customize->add_section('nenghui_contact_style_settings', array(
        'title' => '样式设置',
        'panel' => 'nenghui_contact_map_panel',
        'priority' => 30,
    ));

    // 背景颜色设置
    $wp_customize->add_setting('contact_bg_color', array(
        'default' => '#f8f9fa',
        'sanitize_callback' => 'sanitize_hex_color',
    ));
    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'contact_bg_color', array(
        'label' => '背景颜色',
        'section' => 'nenghui_contact_style_settings',
        'settings' => 'contact_bg_color',
    )));

    // 文字颜色设置
    $wp_customize->add_setting('contact_text_color', array(
        'default' => '#333333',
        'sanitize_callback' => 'sanitize_hex_color',
    ));
    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'contact_text_color', array(
        'label' => '文字颜色',
        'section' => 'nenghui_contact_style_settings',
        'settings' => 'contact_text_color',
    )));

    // 图标颜色设置
    $wp_customize->add_setting('contact_icon_color', array(
        'default' => '#007cba',
        'sanitize_callback' => 'sanitize_hex_color',
    ));
    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'contact_icon_color', array(
        'label' => '图标颜色',
        'section' => 'nenghui_contact_style_settings',
        'settings' => 'contact_icon_color',
    )));

    // 添加案例展示设置面板
    $wp_customize->add_panel('nenghui_cases_panel', array(
        'title' => '案例展示设置',
        'description' => '配置案例展示区块的背景和样式',
        'priority' => 46,
    ));

    // 添加案例展示基本设置区域
    $wp_customize->add_section('nenghui_cases_basic_settings', array(
        'title' => '案例展示基本设置',
        'panel' => 'nenghui_cases_panel',
        'priority' => 10,
    ));

    // 案例展示区块标题设置
    $wp_customize->add_setting('cases_section_title', array(
        'default' => 'Cases',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('cases_section_title', array(
        'label' => '区块标题',
        'section' => 'nenghui_cases_basic_settings',
        'type' => 'text',
    ));

    // 添加案例展示背景设置区域
    $wp_customize->add_section('nenghui_cases_background_settings', array(
        'title' => '背景设置',
        'panel' => 'nenghui_cases_panel',
        'priority' => 20,
    ));

    // 背景类型选择
    $wp_customize->add_setting('cases_background_type', array(
        'default' => 'color',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('cases_background_type', array(
        'label' => '背景类型',
        'section' => 'nenghui_cases_background_settings',
        'type' => 'select',
        'choices' => array(
            'color' => '纯色背景',
            'image' => '图片背景',
            'video' => '视频背景',
        ),
    ));

    // 背景颜色设置
    $wp_customize->add_setting('cases_background_color', array(
        'default' => '#f8f9fa',
        'sanitize_callback' => 'sanitize_hex_color',
    ));
    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'cases_background_color', array(
        'label' => '背景颜色',
        'section' => 'nenghui_cases_background_settings',
        'settings' => 'cases_background_color',
    )));

    // 背景图片设置
    $wp_customize->add_setting('cases_background_image', array(
        'default' => '',
        'sanitize_callback' => 'esc_url_raw',
    ));
    $wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'cases_background_image', array(
        'label' => '背景图片',
        'description' => '选择作为背景的图片文件',
        'section' => 'nenghui_cases_background_settings',
        'settings' => 'cases_background_image',
    )));

    // 背景视频URL设置
    $wp_customize->add_setting('cases_background_video', array(
        'default' => '',
        'sanitize_callback' => 'esc_url_raw',
    ));
    $wp_customize->add_control('cases_background_video', array(
        'label' => '背景视频URL',
        'description' => '输入MP4格式视频文件的完整URL地址',
        'section' => 'nenghui_cases_background_settings',
        'type' => 'url',
        'input_attrs' => array(
            'placeholder' => 'https://example.com/video.mp4',
        ),
    ));

    // 背景图片位置设置
    $wp_customize->add_setting('cases_background_position', array(
        'default' => 'center center',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('cases_background_position', array(
        'label' => '背景图片位置',
        'section' => 'nenghui_cases_background_settings',
        'type' => 'select',
        'choices' => array(
            'left top' => '左上',
            'center top' => '居中上',
            'right top' => '右上',
            'left center' => '左中',
            'center center' => '居中',
            'right center' => '右中',
            'left bottom' => '左下',
            'center bottom' => '居中下',
            'right bottom' => '右下',
        ),
    ));

    // 背景图片尺寸设置
    $wp_customize->add_setting('cases_background_size', array(
        'default' => 'cover',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('cases_background_size', array(
        'label' => '背景图片尺寸',
        'section' => 'nenghui_cases_background_settings',
        'type' => 'select',
        'choices' => array(
            'auto' => '原始尺寸',
            'cover' => '覆盖容器',
            'contain' => '完整显示',
        ),
    ));

    // 背景重复设置
    $wp_customize->add_setting('cases_background_repeat', array(
        'default' => 'no-repeat',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('cases_background_repeat', array(
        'label' => '背景重复',
        'section' => 'nenghui_cases_background_settings',
        'type' => 'select',
        'choices' => array(
            'no-repeat' => '不重复',
            'repeat' => '重复',
            'repeat-x' => '水平重复',
            'repeat-y' => '垂直重复',
        ),
    ));

    // 背景遮罩设置
    $wp_customize->add_setting('cases_background_overlay', array(
        'default' => true,
        'sanitize_callback' => 'wp_validate_boolean',
    ));
    $wp_customize->add_control('cases_background_overlay', array(
        'label' => '启用背景遮罩',
        'description' => '在背景上添加半透明遮罩以提高文字可读性',
        'section' => 'nenghui_cases_background_settings',
        'type' => 'checkbox',
    ));

    // 背景遮罩颜色设置
    $wp_customize->add_setting('cases_background_overlay_color', array(
        'default' => '#000000',
        'sanitize_callback' => 'sanitize_hex_color',
    ));
    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'cases_background_overlay_color', array(
        'label' => '遮罩颜色',
        'section' => 'nenghui_cases_background_settings',
        'settings' => 'cases_background_overlay_color',
    )));

    // 背景遮罩透明度设置
    $wp_customize->add_setting('cases_background_overlay_opacity', array(
        'default' => '0.4',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('cases_background_overlay_opacity', array(
        'label' => '遮罩透明度',
        'description' => '设置背景遮罩的透明度（0-1之间的数值）',
        'section' => 'nenghui_cases_background_settings',
        'type' => 'range',
        'input_attrs' => array(
            'min' => 0,
            'max' => 1,
            'step' => 0.1,
        ),
    ));

    // 添加产品Banner设置面板
    $wp_customize->add_panel('nenghui_products_banner_panel', array(
        'title' => '产品Banner轮播设置',
        'description' => '配置产品Banner卡片轮播的图片、标题、描述和链接',
        'priority' => 35,
    ));

    // 产品Banner基本设置
    $wp_customize->add_section('nenghui_products_banner_basic_settings', array(
        'title' => '基本设置',
        'panel' => 'nenghui_products_banner_panel',
        'priority' => 10,
    ));

    // 产品数量设置
    $wp_customize->add_setting('products_banner_count', array(
        'default' => 3,
        'sanitize_callback' => 'absint',
        'transport' => 'postMessage',
    ));
    $wp_customize->add_control('products_banner_count', array(
        'label' => '显示产品数量',
        'description' => '设置要显示的产品数量（最多7个）',
        'section' => 'nenghui_products_banner_basic_settings',
        'type' => 'number',
        'input_attrs' => array(
            'min' => 1,
            'max' => 7,
            'step' => 1,
        ),
    ));

    // 自动播放设置
    $wp_customize->add_setting('products_banner_autoplay', array(
        'default' => true,
        'sanitize_callback' => 'wp_validate_boolean',
        'transport' => 'postMessage',
    ));
    $wp_customize->add_control('products_banner_autoplay', array(
        'label' => '启用自动播放',
        'description' => '是否自动切换产品卡片',
        'section' => 'nenghui_products_banner_basic_settings',
        'type' => 'checkbox',
    ));

    // 自动播放延迟设置
    $wp_customize->add_setting('products_banner_autoplay_delay', array(
        'default' => 5000,
        'sanitize_callback' => 'absint',
        'transport' => 'postMessage',
    ));
    $wp_customize->add_control('products_banner_autoplay_delay', array(
        'label' => '自动播放延迟（毫秒）',
        'description' => '设置自动切换的时间间隔',
        'section' => 'nenghui_products_banner_basic_settings',
        'type' => 'number',
        'input_attrs' => array(
            'min' => 1000,
            'max' => 10000,
            'step' => 500,
        ),
    ));

    // 为每个产品添加设置区域
    for ($i = 1; $i <= 7; $i++) {
        // 产品设置区域
        $wp_customize->add_section('nenghui_products_banner_product_' . $i, array(
            'title' => '产品 ' . $i,
            'panel' => 'nenghui_products_banner_panel',
            'priority' => 10 + $i,
        ));

        // 产品图片
        $wp_customize->add_setting('products_banner_image_' . $i, array(
            'default' => '',
            'sanitize_callback' => 'esc_url_raw',
            'transport' => 'postMessage',
        ));
        $wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'products_banner_image_' . $i, array(
            'label' => '产品图片',
            'description' => '上传产品图片（建议尺寸：600x400px）',
            'section' => 'nenghui_products_banner_product_' . $i,
        )));

        // 产品标题
        $wp_customize->add_setting('products_banner_title_' . $i, array(
            'default' => '',
            'sanitize_callback' => 'sanitize_text_field',
            'transport' => 'postMessage',
        ));
        $wp_customize->add_control('products_banner_title_' . $i, array(
            'label' => '产品标题',
            'description' => '输入产品标题',
            'section' => 'nenghui_products_banner_product_' . $i,
            'type' => 'text',
        ));

        // 产品描述
        $wp_customize->add_setting('products_banner_description_' . $i, array(
            'default' => '',
            'sanitize_callback' => 'sanitize_textarea_field',
            'transport' => 'postMessage',
        ));
        $wp_customize->add_control('products_banner_description_' . $i, array(
            'label' => '产品描述',
            'description' => '输入产品描述信息',
            'section' => 'nenghui_products_banner_product_' . $i,
            'type' => 'textarea',
        ));

        // 产品链接
        $wp_customize->add_setting('products_banner_link_' . $i, array(
            'default' => '#',
            'sanitize_callback' => 'esc_url_raw',
            'transport' => 'postMessage',
        ));
        $wp_customize->add_control('products_banner_link_' . $i, array(
            'label' => '产品链接',
            'description' => '输入产品详情页链接',
            'section' => 'nenghui_products_banner_product_' . $i,
            'type' => 'url',
        ));
    }

    // 添加流程图Tab设置面板
    $wp_customize->add_panel('nenghui_flowchart_tabs_panel', array(
        'title' => '流程图Tab设置',
        'description' => '配置流程图Tab切换组件的标题、图片和说明文字',
        'priority' => 36,
    ));

    // 为每个流程图Tab添加设置区域
    $flowchart_tab_names = array(
        1 => 'PACK Process Flowchart',
        2 => 'Enclosure Manufacturing Process Flow Diagram', 
        3 => 'Module Manufacturing Process Flow Diagram'
    );

    foreach ($flowchart_tab_names as $i => $default_name) {
        // 添加Tab设置区域
        $wp_customize->add_section('nenghui_flowchart_tab_section_' . $i, array(
            'title' => '流程图Tab ' . $i,
            'panel' => 'nenghui_flowchart_tabs_panel',
            'priority' => $i * 10,
        ));

        // Tab标题设置
        $wp_customize->add_setting('flowchart_tab_' . $i . '_title', array(
            'default' => $default_name,
            'sanitize_callback' => 'sanitize_text_field',
            'transport' => 'postMessage',
        ));
        $wp_customize->add_control('flowchart_tab_' . $i . '_title', array(
            'label' => 'Tab标题',
            'description' => '设置Tab按钮显示的标题',
            'section' => 'nenghui_flowchart_tab_section_' . $i,
            'type' => 'text',
        ));

        // Tab图片设置
        $default_images = array(
            1 => get_template_directory_uri() . '/assets/images/pack-process flow-chart.png',
            2 => get_template_directory_uri() . '/assets/images/cabinet-process flow-chart.png',
            3 => get_template_directory_uri() . '/assets/images/module-process flow.png'
        );
        
        $wp_customize->add_setting('flowchart_tab_' . $i . '_image', array(
            'default' => $default_images[$i],
            'sanitize_callback' => 'esc_url_raw',
            'transport' => 'postMessage',
        ));
        $wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'flowchart_tab_' . $i . '_image', array(
            'label' => '流程图图片',
            'description' => '上传或选择流程图图片',
            'section' => 'nenghui_flowchart_tab_section_' . $i,
        )));

        // Tab说明文字设置
        $default_notes = array(
            1 => 'Note 1: Blue procedures denote liquid-cooled project operations; Turquoise procedures indicate universal processes (Air-cooled PACK units require turquoise procedures only). 2.Operations marked with [★] denote critical processes; those marked with [▲] indicate inspection operations.',
            2 => '', // 第二个tab没有说明文字
            3 => 'Note: [★] denotes Critical Processes; [▲] denotes Inspection Processes.'
        );
        
        $wp_customize->add_setting('flowchart_tab_' . $i . '_note', array(
            'default' => $default_notes[$i],
            'sanitize_callback' => 'wp_kses_post',
            'transport' => 'postMessage',
        ));
        $wp_customize->add_control('flowchart_tab_' . $i . '_note', array(
            'label' => '说明文字',
            'description' => '设置图片下方的说明文字（支持HTML标签，留空则不显示）',
            'section' => 'nenghui_flowchart_tab_section_' . $i,
            'type' => 'textarea',
        ));
    }



}
add_action('customize_register', 'nenghui_customize_register');

/**
 * 验证国家JSON数据
 */
function nenghui_sanitize_countries_json($input) {
    if (empty($input)) {
        return '';
    }
    
    $decoded = json_decode($input, true);
    if (json_last_error() !== JSON_ERROR_NONE) {
        return '';
    }
    
    // 验证数据结构
    if (!is_array($decoded)) {
        return '';
    }
    
    $sanitized = array();
    foreach ($decoded as $country) {
        if (is_array($country) && 
            isset($country['code']) && 
            isset($country['lat']) && 
            isset($country['lng'])) {
            
            $sanitized[] = array(
                'code' => sanitize_text_field($country['code']),
                'name' => isset($country['name']) ? sanitize_text_field($country['name']) : '',
                'lat' => floatval($country['lat']),
                'lng' => floatval($country['lng']),
                'value' => isset($country['value']) ? intval($country['value']) : 30,
            );
        }
    }
    
    return json_encode($sanitized);
}



/**
 * 自定义菜单ID验证函数
 */
function nenghui_sanitize_menu_id($input) {
    // 如果输入为空，返回空字符串
    if (empty($input)) {
        return '';
    }
    
    // 转换为整数
    $menu_id = intval($input);
    
    // 如果菜单ID无效，返回空字符串
    if ($menu_id <= 0) {
        return '';
    }
    
    // 检查菜单是否存在
    $menu = wp_get_nav_menu_object($menu_id);
    if (!$menu || is_wp_error($menu)) {
        return '';
    }
    
    // 返回有效的菜单ID
    return strval($menu_id);
}

/**
 * 获取导航菜单选项
 */
function nenghui_get_nav_menu_choices() {
    $menus = wp_get_nav_menus();
    $choices = array('' => '请选择菜单');
    
    if (is_array($menus) && !empty($menus)) {
        foreach ($menus as $menu) {
            // 确保菜单对象有效且有term_id
            if (isset($menu->term_id) && isset($menu->name)) {
                $choices[strval($menu->term_id)] = $menu->name . ' (ID: ' . $menu->term_id . ')';
            }
        }
    }
    
    return $choices;
}

/**
 * 添加自定义器预览脚本
 */
function nenghui_customize_preview_js() {
    wp_enqueue_script('nenghui-customizer-preview', get_template_directory_uri() . '/assets/js/customizer-preview.js', array('customize-preview'), '1.0.0', true);
}
add_action('customize_preview_init', 'nenghui_customize_preview_js');

/**
 * 添加地图设置到自定义器
 */
function nenghui_add_black_maps_customizer($wp_customize) {
    // 添加地图设置面板
    $wp_customize->add_panel('black_maps_panel', array(
        'title' => '全球地图设置',
        'description' => '配置全球地图的显示样式和国家数据',
        'priority' => 35,
    ));

    // 基础设置区域
    $wp_customize->add_section('black_maps_basic_section', array(
        'title' => '基础设置',
        'panel' => 'black_maps_panel',
        'priority' => 10,
    ));

    // 地图标题
    $wp_customize->add_setting('black_maps_title', array(
        'default' => 'Global Layout',
        'sanitize_callback' => 'sanitize_text_field',
        'transport' => 'postMessage'
    ));
    $wp_customize->add_control('black_maps_title', array(
        'label' => '地图标题',
        'section' => 'black_maps_basic_section',
        'type' => 'text',
    ));

    // 地图副标题
    $wp_customize->add_setting('black_maps_subtitle', array(
        'default' => 'Global Service Operations: Remote diagnostics with 2-hour onsite response in key markets',
        'sanitize_callback' => 'sanitize_textarea_field',
        'transport' => 'postMessage'
    ));
    $wp_customize->add_control('black_maps_subtitle', array(
        'label' => '地图副标题',
        'section' => 'black_maps_basic_section',
        'type' => 'textarea',
    ));

    // 地图高度
    $wp_customize->add_setting('black_maps_height', array(
        'default' => '100vh',
        'sanitize_callback' => 'sanitize_text_field',
        'transport' => 'postMessage'
    ));
    $wp_customize->add_control('black_maps_height', array(
        'label' => '地图高度',
        'description' => '支持px、vh、%等单位，例如：100vh、600px',
        'section' => 'black_maps_basic_section',
        'type' => 'text',
    ));

    // 样式设置区域
    $wp_customize->add_section('black_maps_style_section', array(
        'title' => '样式设置',
        'panel' => 'black_maps_panel',
        'priority' => 20,
    ));

    // 背景颜色
    $wp_customize->add_setting('black_maps_bg_color', array(
        'default' => '#f5f5f5',
        'sanitize_callback' => 'sanitize_hex_color',
        'transport' => 'postMessage'
    ));
    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'black_maps_bg_color', array(
        'label' => '背景颜色',
        'section' => 'black_maps_style_section',
    )));

    // 图表背景颜色
    $wp_customize->add_setting('black_maps_chart_bg', array(
        'default' => '#f8f9fa',
        'sanitize_callback' => 'sanitize_hex_color',
        'transport' => 'postMessage'
    ));
    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'black_maps_chart_bg', array(
        'label' => '图表背景颜色',
        'section' => 'black_maps_style_section',
    )));

    // 标题颜色
    $wp_customize->add_setting('black_maps_title_color', array(
        'default' => '#333333',
        'sanitize_callback' => 'sanitize_hex_color',
        'transport' => 'postMessage'
    ));
    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'black_maps_title_color', array(
        'label' => '标题颜色',
        'section' => 'black_maps_style_section',
    )));

    // 标题字体大小
    $wp_customize->add_setting('black_maps_title_size', array(
        'default' => 20,
        'sanitize_callback' => 'absint',
        'transport' => 'postMessage'
    ));
    $wp_customize->add_control('black_maps_title_size', array(
        'label' => '标题字体大小 (px)',
        'section' => 'black_maps_style_section',
        'type' => 'range',
        'input_attrs' => array(
            'min' => 12,
            'max' => 36,
            'step' => 1
        )
    ));

    // 中国颜色
    $wp_customize->add_setting('black_maps_china_color', array(
        'default' => '#e74c3c',
        'sanitize_callback' => 'sanitize_hex_color',
        'transport' => 'postMessage'
    ));
    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'black_maps_china_color', array(
        'label' => '中国区域颜色',
        'section' => 'black_maps_style_section',
    )));

    // 目标国家颜色
    $wp_customize->add_setting('black_maps_target_color', array(
        'default' => '#2eb6aa',
        'sanitize_callback' => 'sanitize_hex_color',
        'transport' => 'postMessage'
    ));
    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'black_maps_target_color', array(
        'label' => '目标国家颜色',
        'section' => 'black_maps_style_section',
    )));

    // 连线颜色
    $wp_customize->add_setting('black_maps_line_color', array(
        'default' => '#FFFFFF',
        'sanitize_callback' => 'sanitize_hex_color',
        'transport' => 'postMessage'
    ));
    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'black_maps_line_color', array(
        'label' => '连线颜色',
        'section' => 'black_maps_style_section',
    )));

    // 特效颜色
    $wp_customize->add_setting('black_maps_effect_color', array(
        'default' => '#0080ff',
        'sanitize_callback' => 'sanitize_hex_color',
        'transport' => 'postMessage'
    ));
    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'black_maps_effect_color', array(
        'label' => '特效颜色',
        'section' => 'black_maps_style_section',
    )));

    // 国家管理区域
    $wp_customize->add_section('black_maps_countries_section', array(
        'title' => '国家管理',
        'panel' => 'black_maps_panel',
        'priority' => 30,
    ));

    // 自定义国家数据（JSON格式）
    $wp_customize->add_setting('black_maps_countries_json', array(
        'default' => '',
        'sanitize_callback' => 'nenghui_sanitize_json',
        'transport' => 'postMessage'
    ));
    $wp_customize->add_control('black_maps_countries_json', array(
        'label' => '自定义国家数据 (JSON)',
        'description' => '格式：[{"name":"国家名","code":"国家代码","lat":纬度,"lng":经度,"value":数值}]',
        'section' => 'black_maps_countries_section',
        'type' => 'textarea',
        'input_attrs' => array(
            'rows' => 8,
            'placeholder' => '[{"name":"Japan","code":"JP","lat":36.2048,"lng":138.2529,"value":25}]'
        )
    ));

    // 显示参数区域
    $wp_customize->add_section('black_maps_display_section', array(
        'title' => '显示参数',
        'panel' => 'black_maps_panel',
        'priority' => 40,
    ));

    // 启用缩放
    $wp_customize->add_setting('black_maps_enable_zoom', array(
        'default' => false,
        'sanitize_callback' => 'wp_validate_boolean',
        'transport' => 'postMessage'
    ));
    $wp_customize->add_control('black_maps_enable_zoom', array(
        'label' => '启用地图缩放',
        'section' => 'black_maps_display_section',
        'type' => 'checkbox',
    ));

    // 启用拖拽
    $wp_customize->add_setting('black_maps_enable_drag', array(
        'default' => false,
        'sanitize_callback' => 'wp_validate_boolean',
        'transport' => 'postMessage'
    ));
    $wp_customize->add_control('black_maps_enable_drag', array(
        'label' => '启用地图拖拽',
        'section' => 'black_maps_display_section',
        'type' => 'checkbox',
    ));

    // 动画速度
    $wp_customize->add_setting('black_maps_animation_speed', array(
        'default' => 6,
        'sanitize_callback' => 'absint',
        'transport' => 'postMessage'
    ));
    $wp_customize->add_control('black_maps_animation_speed', array(
        'label' => '动画速度 (秒)',
        'section' => 'black_maps_display_section',
        'type' => 'range',
        'input_attrs' => array(
            'min' => 1,
            'max' => 10,
            'step' => 1
        )
    ));
}
add_action('customize_register', 'nenghui_add_black_maps_customizer');

/**
 * JSON数据验证函数
 */
function nenghui_sanitize_json($input) {
    if (empty($input)) {
        return '';
    }
    
    $decoded = json_decode($input, true);
    if (json_last_error() !== JSON_ERROR_NONE) {
        return '';
    }
    
    return $input;
}

/**
 * 添加自定义器控制脚本
 */
function nenghui_customize_controls_js() {
    // 确保媒体库已加载
    wp_enqueue_media();
    wp_enqueue_script('nenghui-customizer-controls', get_template_directory_uri() . '/assets/js/customizer-controls.js', array('customize-controls'), '1.0.0', true);
}
add_action('customize_controls_enqueue_scripts', 'nenghui_customize_controls_js');

// 添加业务流程设计区块自定义选项
function nenghui_business_process_customizer($wp_customize) {
    // 添加业务流程面板
    $wp_customize->add_panel('business_process_panel', array(
        'title' => '业务流程设计',
        'description' => '配置业务流程设计区块的显示选项和内容',
        'priority' => 70,
    ));

    // 添加基础设置部分
    $wp_customize->add_section('business_process_basic_section', array(
        'title' => '基础设置',
        'panel' => 'business_process_panel',
        'priority' => 10,
    ));

    // 是否显示业务流程区块
    $wp_customize->add_setting('business_process_show', array(
        'default' => true,
        'sanitize_callback' => 'wp_validate_boolean',
        'transport' => 'postMessage',
    ));

    $wp_customize->add_control('business_process_show', array(
        'label' => '显示业务流程区块',
        'section' => 'business_process_basic_section',
        'type' => 'checkbox',
        'description' => '是否在页面中显示业务流程设计区块',
    ));

    // 区块标题设置
    $wp_customize->add_setting('business_process_title', array(
        'default' => '设计业务流程',
        'sanitize_callback' => 'sanitize_text_field',
        'transport' => 'postMessage',
    ));

    $wp_customize->add_control('business_process_title', array(
        'label' => '区块标题',
        'section' => 'business_process_basic_section',
        'type' => 'text',
        'description' => '业务流程设计区块的主标题',
    ));

    // 区块副标题设置
    $wp_customize->add_setting('business_process_subtitle', array(
        'default' => '专业的设计流程，确保项目高质量完成',
        'sanitize_callback' => 'sanitize_text_field',
        'transport' => 'postMessage',
    ));

    $wp_customize->add_control('business_process_subtitle', array(
        'label' => '区块副标题',
        'section' => 'business_process_basic_section',
        'type' => 'text',
        'description' => '业务流程设计区块的副标题',
    ));

    // Tab 01 设置部分
    $wp_customize->add_section('business_process_tab1_section', array(
        'title' => 'Tab 01 - 可行性研究',
        'panel' => 'business_process_panel',
        'priority' => 20,
    ));

    // Tab 01 标题
    $wp_customize->add_setting('business_process_tab1_title', array(
        'default' => '可行性研究',
        'sanitize_callback' => 'sanitize_text_field',
        'transport' => 'postMessage',
    ));

    $wp_customize->add_control('business_process_tab1_title', array(
        'label' => 'Tab 01 标题',
        'section' => 'business_process_tab1_section',
        'type' => 'text',
    ));

    // Tab 01 描述
    $wp_customize->add_setting('business_process_tab1_description', array(
        'default' => '前期调研并综合考虑"可行性、经济性、安全性"三个方面，多方案比较，确定最优设计方案和实施策略。',
        'sanitize_callback' => 'sanitize_textarea_field',
        'transport' => 'postMessage',
    ));

    $wp_customize->add_control('business_process_tab1_description', array(
        'label' => 'Tab 01 描述',
        'section' => 'business_process_tab1_section',
        'type' => 'textarea',
    ));

    // Tab 01 图片
    $wp_customize->add_setting('business_process_tab1_image', array(
        'default' => get_template_directory_uri() . '/assets/images/FWas.jpg',
        'sanitize_callback' => 'esc_url_raw',
        'transport' => 'postMessage',
    ));

    $wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'business_process_tab1_image', array(
        'label' => 'Tab 01 图片',
        'section' => 'business_process_tab1_section',
        'settings' => 'business_process_tab1_image',
        'description' => '选择Tab 01对应的图片',
    )));

    // Tab 02 设置部分
    $wp_customize->add_section('business_process_tab2_section', array(
        'title' => 'Tab 02 - 初步设计',
        'panel' => 'business_process_panel',
        'priority' => 30,
    ));

    // Tab 02 标题
    $wp_customize->add_setting('business_process_tab2_title', array(
        'default' => '初步设计',
        'sanitize_callback' => 'sanitize_text_field',
        'transport' => 'postMessage',
    ));

    $wp_customize->add_control('business_process_tab2_title', array(
        'label' => 'Tab 02 标题',
        'section' => 'business_process_tab2_section',
        'type' => 'text',
    ));

    // Tab 02 描述
    $wp_customize->add_setting('business_process_tab2_description', array(
        'default' => '在基本方案确定的基础上，进行"精细设计"，确定主要设备的选型和布置，形成初步设计方案。',
        'sanitize_callback' => 'sanitize_textarea_field',
        'transport' => 'postMessage',
    ));

    $wp_customize->add_control('business_process_tab2_description', array(
        'label' => 'Tab 02 描述',
        'section' => 'business_process_tab2_section',
        'type' => 'textarea',
    ));

    // Tab 02 图片
    $wp_customize->add_setting('business_process_tab2_image', array(
        'default' => get_template_directory_uri() . '/assets/images/FWas.jpg',
        'sanitize_callback' => 'esc_url_raw',
        'transport' => 'postMessage',
    ));

    $wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'business_process_tab2_image', array(
        'label' => 'Tab 02 图片',
        'section' => 'business_process_tab2_section',
        'settings' => 'business_process_tab2_image',
        'description' => '选择Tab 02对应的图片',
    )));

    // Tab 03 设置部分
    $wp_customize->add_section('business_process_tab3_section', array(
        'title' => 'Tab 03 - 施工图设计',
        'panel' => 'business_process_panel',
        'priority' => 40,
    ));

    // Tab 03 标题
    $wp_customize->add_setting('business_process_tab3_title', array(
        'default' => '施工图设计',
        'sanitize_callback' => 'sanitize_text_field',
        'transport' => 'postMessage',
    ));

    $wp_customize->add_control('business_process_tab3_title', array(
        'label' => 'Tab 03 标题',
        'section' => 'business_process_tab3_section',
        'type' => 'text',
    ));

    // Tab 03 描述
    $wp_customize->add_setting('business_process_tab3_description', array(
        'default' => '基于初步设计方案，进行详细的施工图设计，确保设计方案的可实施性和工程质量。',
        'sanitize_callback' => 'sanitize_textarea_field',
        'transport' => 'postMessage',
    ));

    $wp_customize->add_control('business_process_tab3_description', array(
        'label' => 'Tab 03 描述',
        'section' => 'business_process_tab3_section',
        'type' => 'textarea',
    ));

    // Tab 03 图片
    $wp_customize->add_setting('business_process_tab3_image', array(
        'default' => get_template_directory_uri() . '/assets/images/FWas.jpg',
        'sanitize_callback' => 'esc_url_raw',
        'transport' => 'postMessage',
    ));

    $wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'business_process_tab3_image', array(
        'label' => 'Tab 03 图片',
        'section' => 'business_process_tab3_section',
        'settings' => 'business_process_tab3_image',
        'description' => '选择Tab 03对应的图片',
    )));

    // Tab 04 设置部分
    $wp_customize->add_section('business_process_tab4_section', array(
        'title' => 'Tab 04 - 竣工图设计',
        'panel' => 'business_process_panel',
        'priority' => 50,
    ));

    // Tab 04 标题
    $wp_customize->add_setting('business_process_tab4_title', array(
        'default' => '竣工图设计',
        'sanitize_callback' => 'sanitize_text_field',
        'transport' => 'postMessage',
    ));

    $wp_customize->add_control('business_process_tab4_title', array(
        'label' => 'Tab 04 标题',
        'section' => 'business_process_tab4_section',
        'type' => 'text',
    ));

    // Tab 04 描述
    $wp_customize->add_setting('business_process_tab4_description', array(
        'default' => '项目完工后的竣工图设计，真实反映工程实际建设情况，为后续运维提供准确的技术资料。',
        'sanitize_callback' => 'sanitize_textarea_field',
        'transport' => 'postMessage',
    ));

    $wp_customize->add_control('business_process_tab4_description', array(
        'label' => 'Tab 04 描述',
        'section' => 'business_process_tab4_section',
        'type' => 'textarea',
    ));

    // Tab 04 图片
    $wp_customize->add_setting('business_process_tab4_image', array(
        'default' => get_template_directory_uri() . '/assets/images/FWas.jpg',
        'sanitize_callback' => 'esc_url_raw',
        'transport' => 'postMessage',
    ));

    $wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'business_process_tab4_image', array(
        'label' => 'Tab 04 图片',
        'section' => 'business_process_tab4_section',
        'settings' => 'business_process_tab4_image',
        'description' => '选择Tab 04对应的图片',
    )));
}

// 获取业务流程配置的辅助函数
function get_business_process_show() {
    return get_theme_mod('business_process_show', true);
}

function get_business_process_title() {
    return get_theme_mod('business_process_title', '设计业务流程');
}

function get_business_process_subtitle() {
    return get_theme_mod('business_process_subtitle', '专业的设计流程，确保项目高质量完成');
}

function get_business_process_tab_data($tab_number) {
    $defaults = array(
        1 => array(
            'title' => '可行性研究',
            'description' => '前期调研并综合考虑"可行性、经济性、安全性"三个方面，多方案比较，确定最优设计方案和实施策略。',
            'image' => get_template_directory_uri() . '/assets/images/FWas.jpg'
        ),
        2 => array(
            'title' => '初步设计',
            'description' => '在基本方案确定的基础上，进行"精细设计"，确定主要设备的选型和布置，形成初步设计方案。',
            'image' => get_template_directory_uri() . '/assets/images/FWas.jpg'
        ),
        3 => array(
            'title' => '施工图设计',
            'description' => '基于初步设计方案，进行详细的施工图设计，确保设计方案的可实施性和工程质量。',
            'image' => get_template_directory_uri() . '/assets/images/FWas.jpg'
        ),
        4 => array(
            'title' => '竣工图设计',
            'description' => '项目完工后的竣工图设计，真实反映工程实际建设情况，为后续运维提供准确的技术资料。',
            'image' => get_template_directory_uri() . '/assets/images/FWas.jpg'
        )
    );

    if (!isset($defaults[$tab_number])) {
        return null;
    }

    return array(
        'title' => get_theme_mod("business_process_tab{$tab_number}_title", $defaults[$tab_number]['title']),
        'description' => get_theme_mod("business_process_tab{$tab_number}_description", $defaults[$tab_number]['description']),
        'image' => get_theme_mod("business_process_tab{$tab_number}_image", $defaults[$tab_number]['image'])
    );
}
add_action('customize_register', 'nenghui_business_process_customizer');