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

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

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

// Define available WooCommerce order fields for export
$wc_fields = array(
    'order_id'          => __( 'Order ID', 'primelink' ),
    'order_number'      => __( 'Order Number', 'primelink' ),
    'status'            => __( 'Order Status', 'primelink' ),
    'date_created'      => __( 'Date Created', 'primelink' ),
    'date_modified'     => __( 'Date Modified', 'primelink' ),
    'date_paid'         => __( 'Date Paid', 'primelink' ),
    'date_completed'    => __( 'Date Completed', 'primelink' ),
    'customer_id'       => __( 'Customer ID', 'primelink' ),
    'customer_email'    => __( 'Customer Email', 'primelink' ),
    'customer_name'     => __( 'Customer Name', 'primelink' ),
    'billing_first_name' => __( 'Billing First Name', 'primelink' ),
    'billing_last_name' => __( 'Billing Last Name', 'primelink' ),
    'billing_company'   => __( 'Billing Company', 'primelink' ),
    'billing_address_1' => __( 'Billing Address 1', 'primelink' ),
    'billing_address_2' => __( 'Billing Address 2', 'primelink' ),
    'billing_city'     => __( 'Billing City', 'primelink' ),
    'billing_state'    => __( 'Billing State', 'primelink' ),
    'billing_postcode' => __( 'Billing Postcode', 'primelink' ),
    'billing_country'  => __( 'Billing Country', 'primelink' ),
    'billing_email'    => __( 'Billing Email', 'primelink' ),
    'billing_phone'    => __( 'Billing Phone', 'primelink' ),
    'shipping_first_name' => __( 'Shipping First Name', 'primelink' ),
    'shipping_last_name' => __( 'Shipping Last Name', 'primelink' ),
    'shipping_company' => __( 'Shipping Company', 'primelink' ),
    'shipping_address_1' => __( 'Shipping Address 1', 'primelink' ),
    'shipping_address_2' => __( 'Shipping Address 2', 'primelink' ),
    'shipping_city'    => __( 'Shipping City', 'primelink' ),
    'shipping_state'   => __( 'Shipping State', 'primelink' ),
    'shipping_postcode' => __( 'Shipping Postcode', 'primelink' ),
    'shipping_country' => __( 'Shipping Country', 'primelink' ),
    'payment_method'   => __( 'Payment Method', 'primelink' ),
    'payment_method_title' => __( 'Payment Method Title', 'primelink' ),
    'transaction_id'   => __( 'Transaction ID', 'primelink' ),
    'order_total'      => __( 'Order Total', 'primelink' ),
    'order_subtotal'   => __( 'Order Subtotal', 'primelink' ),
    'order_tax'        => __( 'Order Tax', 'primelink' ),
    'order_shipping'   => __( 'Order Shipping', 'primelink' ),
    'order_discount'   => __( 'Order Discount', 'primelink' ),
    'currency'         => __( 'Currency', 'primelink' ),
    'line_items'       => __( 'Line Items', 'primelink' ),
    'customer_note'    => __( 'Customer Note', '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. Order Number: order_number, order_id, number).', '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';
            ?>

                    <!-- 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(
                                'order_id'      => __( 'Order ID', 'primelink' ),
                                'order_number'  => __( 'Order Number', 'primelink' ),
                                'status'        => __( 'Order Status', 'primelink' ),
                                'date_created'  => __( 'Date Created', 'primelink' ),
                                'order_total'   => __( 'Order Total', 'primelink' ),
                                'currency'      => __( 'Currency', 'primelink' ),
                            ) ); ?>
                        </div>
                    </details>

                    <!-- Customer Information -->
                    <details class="mt_primelink-accordion">
                        <summary class="mt_primelink-accordion-title"><?php esc_html_e( 'Customer Information', 'primelink' ); ?></summary>
                        <div class="mt_primelink-accordion-body">
                            <?php TemplateHelper::render_export_slots( array(
                                'customer_id'    => __( 'Customer ID', 'primelink' ),
                                'customer_email' => __( 'Customer Email', 'primelink' ),
                                'customer_name'  => __( 'Customer Name', 'primelink' ),
                            ) ); ?>
                        </div>
                    </details>

                    <!-- Billing Address -->
                    <details class="mt_primelink-accordion">
                        <summary class="mt_primelink-accordion-title"><?php esc_html_e( 'Billing Address', 'primelink' ); ?></summary>
                        <div class="mt_primelink-accordion-body">
                            <?php TemplateHelper::render_export_slots( array(
                                'billing_first_name' => __( 'Billing First Name', 'primelink' ),
                                'billing_last_name' => __( 'Billing Last Name', 'primelink' ),
                                'billing_company'   => __( 'Billing Company', 'primelink' ),
                                'billing_address_1' => __( 'Billing Address 1', 'primelink' ),
                                'billing_address_2' => __( 'Billing Address 2', 'primelink' ),
                                'billing_city'     => __( 'Billing City', 'primelink' ),
                                'billing_state'    => __( 'Billing State', 'primelink' ),
                                'billing_postcode' => __( 'Billing Postcode', 'primelink' ),
                                'billing_country'  => __( 'Billing Country', 'primelink' ),
                                'billing_email'    => __( 'Billing Email', 'primelink' ),
                                'billing_phone'    => __( 'Billing Phone', 'primelink' ),
                            ) ); ?>
                        </div>
                    </details>

                    <!-- Shipping Address -->
                    <details class="mt_primelink-accordion">
                        <summary class="mt_primelink-accordion-title"><?php esc_html_e( 'Shipping Address', 'primelink' ); ?></summary>
                        <div class="mt_primelink-accordion-body">
                            <?php TemplateHelper::render_export_slots( array(
                                'shipping_first_name' => __( 'Shipping First Name', 'primelink' ),
                                'shipping_last_name' => __( 'Shipping Last Name', 'primelink' ),
                                'shipping_company' => __( 'Shipping Company', 'primelink' ),
                                'shipping_address_1' => __( 'Shipping Address 1', 'primelink' ),
                                'shipping_address_2' => __( 'Shipping Address 2', 'primelink' ),
                                'shipping_city'    => __( 'Shipping City', 'primelink' ),
                                'shipping_state'   => __( 'Shipping State', 'primelink' ),
                                'shipping_postcode' => __( 'Shipping Postcode', 'primelink' ),
                                'shipping_country' => __( 'Shipping Country', 'primelink' ),
                            ) ); ?>
                        </div>
                    </details>

                    <!-- Payment Information -->
                    <details class="mt_primelink-accordion">
                        <summary class="mt_primelink-accordion-title"><?php esc_html_e( 'Payment Information', 'primelink' ); ?></summary>
                        <div class="mt_primelink-accordion-body">
                            <?php TemplateHelper::render_export_slots( array(
                                'payment_method'       => __( 'Payment Method', 'primelink' ),
                                'payment_method_title' => __( 'Payment Method Title', 'primelink' ),
                                'transaction_id'       => __( 'Transaction ID', 'primelink' ),
                            ) ); ?>
                        </div>
                    </details>

                    <!-- Order Totals -->
                    <details class="mt_primelink-accordion">
                        <summary class="mt_primelink-accordion-title"><?php esc_html_e( 'Order Totals', 'primelink' ); ?></summary>
                        <div class="mt_primelink-accordion-body">
                            <?php TemplateHelper::render_export_slots( array(
                                'order_subtotal' => __( 'Order Subtotal', 'primelink' ),
                                'order_tax'      => __( 'Order Tax', 'primelink' ),
                                'order_shipping' => __( 'Order Shipping', 'primelink' ),
                                'order_discount' => __( 'Order Discount', 'primelink' ),
                            ) ); ?>
                        </div>
                    </details>

                    <!-- Dates -->
                    <details class="mt_primelink-accordion">
                        <summary class="mt_primelink-accordion-title"><?php esc_html_e( 'Dates', 'primelink' ); ?></summary>
                        <div class="mt_primelink-accordion-body">
                            <?php TemplateHelper::render_export_slots( array(
                                'date_modified'  => __( 'Date Modified', 'primelink' ),
                                'date_paid'      => __( 'Date Paid', 'primelink' ),
                                'date_completed' => __( 'Date Completed', 'primelink' ),
                            ) ); ?>
                        </div>
                    </details>

                    <!-- Other -->
                    <details class="mt_primelink-accordion">
                        <summary class="mt_primelink-accordion-title"><?php esc_html_e( 'Other', 'primelink' ); ?></summary>
                        <div class="mt_primelink-accordion-body">
                            <?php TemplateHelper::render_export_slots( array(
                                'line_items'    => __( 'Line Items', 'primelink' ),
                                'customer_note'  => __( 'Customer Note', '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';
?>





