<?php get_header(); ?>

<?php
while (have_posts()) : the_post();

$subtitle = function_exists('pls_field') ? pls_field('product_subtitle') : '';
$tagline = function_exists('pls_field') ? pls_field('product_tagline') : '';
$moq = function_exists('pls_field') ? pls_field('product_moq') : '';
$stock_status = function_exists('pls_field') ? pls_field('product_stock_status') : '';
$label_ready = function_exists('pls_field') ? pls_field('product_label_ready') : '';
$formula_type = function_exists('pls_field') ? pls_field('product_formula_type') : '';
$packaging_type = function_exists('pls_field') ? pls_field('product_packaging_type') : '';
$capacity = function_exists('pls_field') ? pls_field('product_capacity') : '';

$hero_image = function_exists('pls_field') ? pls_normalize_image(pls_field('hero_image')) : null;
$gallery_views = function_exists('pls_field') ? pls_field('product_gallery_views') : array();
$label_previews = function_exists('pls_field') ? pls_field('label_preview_items') : array();
$highlights = function_exists('pls_field') ? pls_field('product_highlights') : array();
$marketing_assets = function_exists('pls_field') ? pls_field('marketing_assets') : array();
$product_specs = function_exists('pls_field') ? pls_field('product_specs') : array();

$cta_title = function_exists('pls_field') ? pls_field('cta_title') : '';
$cta_desc = function_exists('pls_field') ? pls_field('cta_desc') : '';
$cta_button_text = function_exists('pls_field') ? pls_field('cta_button_text') : '';
$cta_button_link = function_exists('pls_field') ? pls_field('cta_button_link') : '';
?>

<section class="pd-hero">
    <div class="pl-container pd-hero__wrap">
        <div class="pd-hero__content">
            <p class="pl-eyebrow"><?php echo esc_html(function_exists('pls_t') ? pls_t('现货 / 支持贴牌', 'Ready Stock / Private Label Ready') : 'Ready Stock / Private Label Ready'); ?></p>
            <h1><?php the_title(); ?></h1>

            <?php if ($subtitle) : ?>
                <h2 class="pd-subtitle"><?php echo esc_html($subtitle); ?></h2>
            <?php endif; ?>

            <?php if ($tagline) : ?>
                <p class="pd-tagline"><?php echo esc_html($tagline); ?></p>
            <?php endif; ?>

            <div class="pd-meta">
                <?php if ($stock_status) : ?><span class="pl-chip"><?php echo esc_html(function_exists('pls_t') ? pls_t('现货可出', 'Ready to Ship') : '现货可出'); ?></span><?php endif; ?>
                <?php if ($label_ready) : ?><span class="pl-chip"><?php echo esc_html(function_exists('pls_t') ? pls_t('支持换标', 'Private Label Ready') : '支持换标'); ?></span><?php endif; ?>
                <?php if ($moq) : ?><span class="pl-chip">MOQ <?php echo esc_html($moq); ?></span><?php endif; ?>
                <?php if ($capacity) : ?><span class="pl-chip"><?php echo esc_html($capacity); ?></span><?php endif; ?>
            </div>

            <div class="pd-specs-inline">
                <?php if ($formula_type) : ?><p><strong><?php echo esc_html(function_exists('pls_t') ? pls_t('配方类型：', 'Formula Type: ') : '配方类型：'); ?></strong><?php echo esc_html($formula_type); ?></p><?php endif; ?>
                <?php if ($packaging_type) : ?><p><strong><?php echo esc_html(function_exists('pls_t') ? pls_t('包材形式：', 'Packaging Type: ') : '包材形式：'); ?></strong><?php echo esc_html($packaging_type); ?></p><?php endif; ?>
            </div>
        </div>

        <div class="pd-hero__media">
            <?php if (! empty($hero_image)) : ?>
                <img id="main-product-image" src="<?php echo esc_url($hero_image['url']); ?>" alt="<?php echo esc_attr($hero_image['alt']); ?>">
            <?php elseif (has_post_thumbnail()) : ?>
                <?php the_post_thumbnail('large', array('id' => 'main-product-image')); ?>
            <?php endif; ?>

            <?php if (! empty($gallery_views)) : ?>
                <div class="pd-thumbs">
                    <?php foreach ($gallery_views as $image_row) : ?>
                        <?php $image = function_exists('pls_normalize_image') ? pls_normalize_image(isset($image_row['image_url']) ? $image_row['image_url'] : '') : null; ?>
                        <?php if (! empty($image)) : ?>
                            <button class="pd-thumb" type="button" data-image="<?php echo esc_url($image['url']); ?>">
                                <img src="<?php echo esc_url($image['thumb']); ?>" alt="<?php echo esc_attr($image['alt']); ?>">
                            </button>
                        <?php endif; ?>
                    <?php endforeach; ?>
                </div>
            <?php endif; ?>
        </div>
    </div>
</section>

<section class="pd-highlights">
    <div class="pl-container">
        <div class="pl-section-head">
            <p class="pl-section-kicker"><?php echo esc_html(function_exists('pls_t') ? pls_t('核心卖点', 'Core Selling Points') : 'Core Selling Points'); ?></p>
            <h2><?php echo esc_html(function_exists('pls_t') ? pls_t('成熟现货，不止出货快，也更容易被市场接受', 'Ready-stock products that launch faster and resonate better with the market') : ''); ?></h2>
        </div>

        <?php if (! empty($highlights)) : ?>
            <div class="pd-highlight-grid">
                <?php foreach ($highlights as $item) : ?>
                    <div class="pd-highlight-card">
                        <h3><?php echo esc_html(function_exists('pls_is_en') && pls_is_en() ? (! empty($item['highlight_title_en']) ? $item['highlight_title_en'] : $item['highlight_title']) : $item['highlight_title']); ?></h3>
                        <p><?php echo esc_html(function_exists('pls_is_en') && pls_is_en() ? (! empty($item['highlight_desc_en']) ? $item['highlight_desc_en'] : $item['highlight_desc']) : $item['highlight_desc']); ?></p>
                    </div>
                <?php endforeach; ?>
            </div>
        <?php endif; ?>
    </div>
</section>

<section class="pd-label-preview">
    <div class="pl-container">
        <div class="pl-section-head">
            <p class="pl-section-kicker"><?php echo esc_html(function_exists('pls_t') ? pls_t('贴标预览', 'Label Preview') : 'Label Preview'); ?></p>
            <h2><?php echo esc_html(function_exists('pls_t') ? pls_t('线上查看贴标效果', 'Preview label concepts online') : ''); ?></h2>
            <p><?php echo esc_html(function_exists('pls_t') ? pls_t('客户可以先看到不同品牌标签风格贴到同一产品上的视觉效果，更方便判断是否适合快速上市。', 'Let customers compare different brand label concepts on the same packaging before moving into launch.') : ''); ?></p>
        </div>

        <?php if (! empty($label_previews)) : ?>
            <?php $first_preview = $label_previews[0]; ?>
            <?php $first_preview_title = function_exists('pls_is_en') && pls_is_en() ? (! empty($first_preview['label_preview_name_en']) ? $first_preview['label_preview_name_en'] : $first_preview['label_preview_name']) : $first_preview['label_preview_name']; ?>
            <?php $first_preview_desc = function_exists('pls_is_en') && pls_is_en() ? (! empty($first_preview['label_preview_desc_en']) ? $first_preview['label_preview_desc_en'] : $first_preview['label_preview_desc']) : $first_preview['label_preview_desc']; ?>
            <?php $first_preview_image = function_exists('pls_normalize_image') ? pls_normalize_image(isset($first_preview['label_preview_image']) ? $first_preview['label_preview_image'] : '') : null; ?>
            <?php if (! empty($first_preview_image)) : ?>
                <div class="pd-label-wrap">
                    <div class="pd-label-stage">
                        <img id="label-preview-main" src="<?php echo esc_url($first_preview_image['url']); ?>" alt="<?php echo esc_attr($first_preview_title); ?>">
                        <div class="pd-label-caption" id="label-preview-caption">
                            <strong><?php echo esc_html($first_preview_title); ?></strong>
                            <p><?php echo esc_html($first_preview_desc); ?></p>
                        </div>
                    </div>

                    <div class="pd-label-options">
                        <?php foreach ($label_previews as $index => $preview) : ?>
                            <?php $preview_title = function_exists('pls_is_en') && pls_is_en() ? (! empty($preview['label_preview_name_en']) ? $preview['label_preview_name_en'] : $preview['label_preview_name']) : $preview['label_preview_name']; ?>
                            <?php $preview_desc = function_exists('pls_is_en') && pls_is_en() ? (! empty($preview['label_preview_desc_en']) ? $preview['label_preview_desc_en'] : $preview['label_preview_desc']) : $preview['label_preview_desc']; ?>
                            <?php $preview_image = function_exists('pls_normalize_image') ? pls_normalize_image(isset($preview['label_preview_image']) ? $preview['label_preview_image'] : '') : null; ?>
                            <?php if (! empty($preview_image)) : ?>
                                <button
                                    type="button"
                                    class="pd-label-option <?php echo 0 === $index ? 'is-active' : ''; ?>"
                                    data-image="<?php echo esc_url($preview_image['url']); ?>"
                                    data-title="<?php echo esc_attr($preview_title); ?>"
                                    data-desc="<?php echo esc_attr($preview_desc); ?>"
                                >
                                    <?php echo esc_html($preview_title); ?>
                                </button>
                            <?php endif; ?>
                        <?php endforeach; ?>
                    </div>
                </div>
            <?php endif; ?>
        <?php endif; ?>
    </div>
</section>

<section class="pd-marketing-assets">
    <div class="pl-container">
        <div class="pl-section-head">
            <p class="pl-section-kicker"><?php echo esc_html(function_exists('pls_t') ? pls_t('营销素材', 'Marketing Assets') : 'Marketing Assets'); ?></p>
            <h2><?php echo esc_html(function_exists('pls_t') ? pls_t('配套营销素材，帮助客户先预热再上市', 'Built-in marketing assets to support pre-launch warm-up') : ''); ?></h2>
        </div>

        <?php if (! empty($marketing_assets)) : ?>
            <div class="pd-assets-grid">
                <?php foreach ($marketing_assets as $asset) : ?>
                    <?php $asset_type = function_exists('pls_is_en') && pls_is_en() ? (! empty($asset['asset_type_en']) ? $asset['asset_type_en'] : $asset['asset_type']) : $asset['asset_type']; ?>
                    <?php $asset_title = function_exists('pls_is_en') && pls_is_en() ? (! empty($asset['asset_title_en']) ? $asset['asset_title_en'] : $asset['asset_title']) : $asset['asset_title']; ?>
                    <?php $asset_desc = function_exists('pls_is_en') && pls_is_en() ? (! empty($asset['asset_desc_en']) ? $asset['asset_desc_en'] : $asset['asset_desc']) : $asset['asset_desc']; ?>
                    <?php $asset_image = function_exists('pls_normalize_image') ? pls_normalize_image(isset($asset['asset_image']) ? $asset['asset_image'] : '') : null; ?>
                    <div class="pd-asset-card">
                        <?php if (! empty($asset_image)) : ?>
                            <div class="pd-asset-card__image">
                                <img src="<?php echo esc_url($asset_image['url']); ?>" alt="<?php echo esc_attr($asset_title); ?>">
                            </div>
                        <?php endif; ?>

                        <div class="pd-asset-card__body">
                            <p class="pd-asset-type"><?php echo esc_html($asset_type); ?></p>
                            <h3><?php echo esc_html($asset_title); ?></h3>
                            <p><?php echo esc_html($asset_desc); ?></p>
                        </div>
                    </div>
                <?php endforeach; ?>
            </div>
        <?php endif; ?>
    </div>
</section>

<section class="pd-specs">
    <div class="pl-container">
        <div class="pl-section-head">
            <p class="pl-section-kicker"><?php echo esc_html(function_exists('pls_t') ? pls_t('产品参数', 'Product Specs') : 'Product Specs'); ?></p>
            <h2><?php echo esc_html(function_exists('pls_t') ? pls_t('产品参数', 'Product Specifications') : ''); ?></h2>
        </div>

        <?php if (! empty($product_specs)) : ?>
            <div class="pd-spec-table">
                <?php foreach ($product_specs as $spec) : ?>
                    <?php $spec_label = function_exists('pls_is_en') && pls_is_en() ? (! empty($spec['spec_label_en']) ? $spec['spec_label_en'] : $spec['spec_label']) : $spec['spec_label']; ?>
                    <?php $spec_value = function_exists('pls_is_en') && pls_is_en() ? (! empty($spec['spec_value_en']) ? $spec['spec_value_en'] : $spec['spec_value']) : $spec['spec_value']; ?>
                    <div class="pd-spec-row">
                        <div class="pd-spec-label"><?php echo esc_html($spec_label); ?></div>
                        <div class="pd-spec-value"><?php echo esc_html($spec_value); ?></div>
                    </div>
                <?php endforeach; ?>
            </div>
        <?php endif; ?>
    </div>
</section>

<section class="pd-cta">
    <div class="pl-container">
        <div class="pd-cta__box">
            <div class="pd-cta__content">
                <p class="pl-section-kicker"><?php echo esc_html(function_exists('pls_t') ? pls_t('更快上市', 'Launch Faster') : 'Launch Faster'); ?></p>
                <h2><?php echo esc_html($cta_title ? $cta_title : (function_exists('pls_t') ? pls_t('确认产品后，即可进入贴标与上市准备', 'After product confirmation, move directly into branding and launch preparation') : '')); ?></h2>
                <p><?php echo esc_html($cta_desc ? $cta_desc : (function_exists('pls_t') ? pls_t('选择成熟产品、确认标签方案、获取营销素材，帮助品牌更快开启市场预热。', 'Select a proven product, confirm your label direction, and receive launch-ready materials.') : '')); ?></p>
            </div>

            <div class="pd-cta__action">
                <a class="pd-cta__button" href="<?php echo esc_url($cta_button_link ? $cta_button_link : '#'); ?>">
                    <?php echo esc_html($cta_button_text ? $cta_button_text : (function_exists('pls_t') ? pls_t('立即咨询产品方案', 'Discuss This Product Line') : '立即咨询产品方案')); ?>
                </a>
            </div>
        </div>
    </div>
</section>

<?php endwhile; ?>

<?php get_footer(); ?>
