<?php
/**
 * Step 2 - Field Mapping for Variation Export.
 *
 * @package PrimeLink
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

$export_id = isset( $_GET['export_id'] ) ? absint( $_GET['export_id'] ) : 0;

// Define available WooCommerce variation fields for export
$wc_fields = array(
    'variation_id'      => __( 'Variation ID', 'primelink' ),
    'parent_id'         => __( 'Parent Product ID', 'primelink' ),
    'parent_sku'        => __( 'Parent Product SKU', 'primelink' ),
    'parent_title'      => __( 'Parent Product Title', 'primelink' ),
    'sku'               => __( 'SKU', 'primelink' ),
    'regular_price'     => __( 'Regular Price', 'primelink' ),
    'sale_price'        => __( 'Sale Price', 'primelink' ),
    'stock_quantity'    => __( 'Stock Quantity', 'primelink' ),
    'stock_status'      => __( 'Stock Status', 'primelink' ),
    'manage_stock'      => __( 'Manage Stock', 'primelink' ),
    'backorders'        => __( 'Backorders', 'primelink' ),
    'weight'            => __( 'Weight', 'primelink' ),
    'length'            => __( 'Length', 'primelink' ),
    'width'             => __( 'Width', 'primelink' ),
    'height'            => __( 'Height', 'primelink' ),
    'image'             => __( 'Image URL', 'primelink' ),
    'image_id'          => __( 'Image ID', 'primelink' ),
    'gallery'           => __( 'Gallery URLs (comma-separated)', 'primelink' ),
    'gallery_ids'       => __( 'Gallery IDs (comma-separated)', 'primelink' ),
    'description'       => __( 'Description', 'primelink' ),
    'short_description' => __( 'Short Description', 'primelink' ),
    'attributes'        => __( 'Attributes (JSON)', 'primelink' ),
    'tax_class'         => __( 'Tax Class', 'primelink' ),
    'status'            => __( 'Status', 'primelink' ),
    'date_created'      => __( 'Date Created', 'primelink' ),
    'date_modified'     => __( 'Date Modified', 'primelink' ),
);

use PrimeLink\Helpers\TemplateHelper;
?>
<div class="mt_primelink-summary-eyebrow"><?php esc_html_e( 'Step 2 · Mapping', 'primelink' ); ?></div>
<h2><?php esc_html_e( 'Field Mapping Studio', 'primelink' ); ?></h2>
<input type="hidden" id="mt-primelink-step" value="2">

<?php
// Include reusable templates section
include MT_PRIMELINK_PATH . 'templates/admin/exports/partials/templates-section.php';

// Include mapping shell (with alias card)
$alias_hint = __( 'Add custom synonyms for export columns (e.g. Variation ID: variation_id, var_id, id).', 'primelink' );
include MT_PRIMELINK_PATH . 'templates/admin/exports/partials/mapping-shell.php';
?>

            <?php
            // Include export columns header (with helper row)
            include MT_PRIMELINK_PATH . 'templates/admin/exports/partials/export-columns-header.php';
            ?>

                    <!-- Parent Product -->
                    <details class="mt_primelink-accordion">
                        <summary class="mt_primelink-accordion-title"><?php esc_html_e( 'Parent Product', 'primelink' ); ?></summary>
                        <div class="mt_primelink-accordion-body">
                            <?php TemplateHelper::render_export_slots( array(
                                'parent_id'      => __( 'Parent Product ID', 'primelink' ),
                                'parent_sku'     => __( 'Parent Product SKU', 'primelink' ),
                                'parent_title'   => __( 'Parent Product Title', 'primelink' ),
                            ) ); ?>
                        </div>
                    </details>

                    <!-- Basic Fields -->
                    <details class="mt_primelink-accordion">
                        <summary class="mt_primelink-accordion-title"><?php esc_html_e( 'Basic Fields', 'primelink' ); ?></summary>
                        <div class="mt_primelink-accordion-body">
                            <?php TemplateHelper::render_export_slots( array(
                                'variation_id'   => __( 'Variation ID', 'primelink' ),
                                'sku'            => __( 'SKU', 'primelink' ),
                                'status'         => __( 'Status', 'primelink' ),
                            ) ); ?>
                        </div>
                    </details>

                    <!-- Pricing -->
                    <details class="mt_primelink-accordion">
                        <summary class="mt_primelink-accordion-title"><?php esc_html_e( 'Pricing', 'primelink' ); ?></summary>
                        <div class="mt_primelink-accordion-body">
                            <?php TemplateHelper::render_export_slots( array(
                                'regular_price'  => __( 'Regular Price', 'primelink' ),
                                'sale_price'     => __( 'Sale Price', 'primelink' ),
                            ) ); ?>
                        </div>
                    </details>

                    <!-- Stock Management -->
                    <details class="mt_primelink-accordion">
                        <summary class="mt_primelink-accordion-title"><?php esc_html_e( 'Stock Management', 'primelink' ); ?></summary>
                        <div class="mt_primelink-accordion-body">
                            <?php TemplateHelper::render_export_slots( array(
                                'stock_quantity' => __( 'Stock Quantity', 'primelink' ),
                                'stock_status'   => __( 'Stock Status', 'primelink' ),
                                'manage_stock'   => __( 'Manage Stock', 'primelink' ),
                                'backorders'     => __( 'Backorders', 'primelink' ),
                            ) ); ?>
                        </div>
                    </details>

                    <!-- Dimensions -->
                    <details class="mt_primelink-accordion">
                        <summary class="mt_primelink-accordion-title"><?php esc_html_e( 'Dimensions', 'primelink' ); ?></summary>
                        <div class="mt_primelink-accordion-body">
                            <?php TemplateHelper::render_export_slots( array(
                                'weight'         => __( 'Weight', 'primelink' ),
                                'length'          => __( 'Length', 'primelink' ),
                                'width'           => __( 'Width', 'primelink' ),
                                'height'          => __( 'Height', 'primelink' ),
                            ) ); ?>
                        </div>
                    </details>

                    <!-- Images -->
                    <details class="mt_primelink-accordion">
                        <summary class="mt_primelink-accordion-title"><?php esc_html_e( 'Images', 'primelink' ); ?></summary>
                        <div class="mt_primelink-accordion-body">
                            <?php TemplateHelper::render_export_slots( array(
                                'image'          => __( 'Image URL', 'primelink' ),
                                'image_id'       => __( 'Image ID', 'primelink' ),
                                'gallery'        => __( 'Gallery URLs (comma-separated)', 'primelink' ),
                                'gallery_ids'    => __( 'Gallery IDs (comma-separated)', 'primelink' ),
                            ) ); ?>
                        </div>
                    </details>

                    <!-- Attributes -->
                    <details class="mt_primelink-accordion">
                        <summary class="mt_primelink-accordion-title"><?php esc_html_e( 'Variation Attributes', 'primelink' ); ?></summary>
                        <div class="mt_primelink-accordion-body">
                            <?php TemplateHelper::render_export_slots( array(
                                'attributes'     => __( 'Attributes (JSON)', 'primelink' ),
                            ) ); ?>
                            <p class="description"><?php esc_html_e( 'Attributes will be exported as JSON object with attribute names as keys and values as values.', 'primelink' ); ?></p>
                        </div>
                    </details>

                    <!-- Description -->
                    <details class="mt_primelink-accordion">
                        <summary class="mt_primelink-accordion-title"><?php esc_html_e( 'Description', 'primelink' ); ?></summary>
                        <div class="mt_primelink-accordion-body">
                            <?php TemplateHelper::render_export_slots( array(
                                'description'    => __( 'Description', 'primelink' ),
                                'short_description' => __( 'Short Description', 'primelink' ),
                            ) ); ?>
                        </div>
                    </details>

                    <!-- Tax & Dates -->
                    <details class="mt_primelink-accordion">
                        <summary class="mt_primelink-accordion-title"><?php esc_html_e( 'Tax & Dates', 'primelink' ); ?></summary>
                        <div class="mt_primelink-accordion-body">
                            <?php TemplateHelper::render_export_slots( array(
                                'tax_class'      => __( 'Tax Class', 'primelink' ),
                                'date_created'   => __( 'Date Created', 'primelink' ),
                                'date_modified'  => __( 'Date Modified', 'primelink' ),
                            ) ); ?>
                        </div>
                    </details>

                    <!-- Custom Export Columns -->
                    <details class="mt_primelink-accordion">
                        <summary class="mt_primelink-accordion-title"><?php esc_html_e( 'Custom Columns', 'primelink' ); ?></summary>
                        <div class="mt_primelink-accordion-body">
                            <div id="mt_primelink-custom-export-columns-wrap"></div>
                            <button type="button" class="button" id="mt_primelink-add-custom-export-column"><?php esc_html_e( 'Add Custom Column', 'primelink' ); ?></button>
                            <p class="description"><?php esc_html_e( 'Create custom export columns with custom headers.', 'primelink' ); ?></p>
                        </div>
                    </details>

                    <?php
                    // Shared integrations mapping (Yoast, ACF, WPML, Polylang).
                    include MT_PRIMELINK_PATH . 'templates/admin/exports/partials/integrations-mapping.php';
                    ?>
                </div>
            </section>

            <!-- Preview -->
            <div id="mt-primelink-export-preview"
                 class="mt_primelink-preview-card"
                 data-export-id="<?php echo esc_attr( $export_id ); ?>">
            </div>
        </main>
    </div>
</div>

<?php
// Include reusable row filters
include MT_PRIMELINK_PATH . 'templates/admin/exports/partials/row-filters.php';
?>

<?php
// Include reusable map editor partial
include MT_PRIMELINK_PATH . 'templates/admin/exports/partials/map-editor.php';
?>


