<?php
defined('ABSPATH') || exit;

// Template files are required from Renderer methods; these variables are scoped to that renderer invocation.
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$asuka_product_designer_template_debug = is_array($config['context']['apdTemplateLayoutDebug'] ?? null) ? $config['context']['apdTemplateLayoutDebug'] : [];
$asuka_product_designer_template_id = (int) ($asuka_product_designer_template_debug['templateId'] ?? 0);
$asuka_product_designer_template_title = (string) ($asuka_product_designer_template_debug['templateTitle'] ?? '');
$asuka_product_designer_config_title = (string) ($asuka_product_designer_template_debug['configTitle'] ?? '');
?>
<div class="apd-shell" data-apd-shell data-config-id="<?php echo esc_attr((string) $configId); ?>" data-product-id="<?php echo esc_attr((string) $productId); ?>" data-variation-id="<?php echo esc_attr((string) ($config['context']['variationId'] ?? 0)); ?>" data-template-id="<?php echo esc_attr((string) $asuka_product_designer_template_id); ?>" data-template-title="<?php echo esc_attr($asuka_product_designer_template_title); ?>" data-config-title="<?php echo esc_attr($asuka_product_designer_config_title); ?>" data-apd-shell-key="<?php echo esc_attr((string) ($config['context']['variationId'] ? ('variation:' . (int) $config['context']['variationId']) : "parent")); ?>" data-apd-cart-edit="<?php echo ! empty($config['context']['isCartEdit']) ? '1' : '0'; ?>" data-apd-cart-submit-label="<?php echo esc_attr((string) ($config['context']['cartSubmitLabel'] ?? '')); ?>">
    <div class="apd-shell__stage">
        <div
            id="<?php echo esc_attr($mountId); ?>"
            class="apd-mount"
            data-apd-mount="1"
            style="height: <?php echo esc_attr($config['layout']['height'] ?? '720px'); ?>;"
        ></div>
        <script type="application/json" class="apd-config">
            <?php echo wp_json_encode($config, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT); ?>
        </script>
    </div>

    <input type="hidden" name="apd_design_json" value="" data-apd-design-json>
    <input type="hidden" name="apd_state_json" value="" data-apd-state-json>
    <input type="hidden" name="apd_preview_data" value="" data-apd-preview-data>
    <input type="hidden" name="apd_preview_url" value="" data-apd-preview-url>
    <input type="hidden" name="apd_preview_attachment_id" value="" data-apd-preview-attachment-id>
    <input type="hidden" name="apd_price_adjustment" value="0" data-apd-price-adjustment>
    <input type="hidden" name="apd_price_total" value="0" data-apd-price-total>
    <input type="hidden" name="apd_price_breakdown" value="" data-apd-price-breakdown>
    <input type="hidden" name="apd_pricing_payload" value="" data-apd-pricing-payload>
    <input type="hidden" name="apd_payload_version" value="<?php echo esc_attr((string) \APD\Support\PricingSnapshot::VERSION); ?>" data-apd-payload-version>
    <input type="hidden" name="apd_config_id" value="<?php echo esc_attr((string) $configId); ?>">
    <input type="hidden" name="apd_product_id" value="<?php echo esc_attr((string) $productId); ?>">
    <input type="hidden" name="apd_variation_id" value="" data-apd-variation-id>
    <input type="hidden" name="apd_variation_attributes" value="" data-apd-variation-attributes>
    <input type="hidden" name="apd_add_to_cart_nonce" value="<?php echo esc_attr(\APD\Support\Nonces::cartSubmission()); ?>" data-apd-add-to-cart-nonce>
    <input type="hidden" name="apd_user_design_id" value="<?php echo esc_attr((string) ($config['context']['userDesignId'] ?? '')); ?>" data-apd-user-design-id>
    <input type="hidden" name="apd_cart_line_token" value="<?php echo esc_attr((string) ($config['context']['cartLineToken'] ?? '')); ?>" data-apd-cart-line-token>
    <input type="hidden" name="apd_replace_cart_item_key" value="<?php echo esc_attr((string) ($config['context']['replaceCartItemKey'] ?? '')); ?>" data-apd-replace-cart-item-key>
</div>
<?php // phpcs:enable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound ?>
