<?php
/**
 * Advanced Mapping Editor - Reusable partial for all export types.
 *
 * @package PrimeLink
 */

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

<!-- Advanced Mapping Editor -->
<div id="mt_primelink-map-editor" class="mt_primelink-map-editor" style="display:none;">
    <div class="mt_primelink-map-editor__backdrop"></div>
    <div class="mt_primelink-map-editor__panel">
        <div class="mt_primelink-map-editor__header">
            <div class="mt_primelink-editor-title-wrap">
                <h3><?php esc_html_e( 'Column Options', 'primelink' ); ?></h3>
            </div>
            <button type="button" class="button mt_primelink-map-editor-close"><?php esc_html_e( 'Close', 'primelink' ); ?></button>
        </div>

        <div class="mt_primelink-map-editor__body">
            <input type="hidden" id="mt_primelink-editor-target" value="" />

            <div class="mt_primelink-form-row">
                <label><?php esc_html_e( 'Column Header', 'primelink' ); ?></label>
                <input type="text" id="mt_primelink-editor-column-header" placeholder="<?php esc_attr_e( 'Custom column name', 'primelink' ); ?>" />
                <small class="description"><?php esc_html_e( 'Custom header name for this export column.', 'primelink' ); ?></small>
            </div>

            <div class="mt_primelink-form-row">
                <label><?php esc_html_e( 'Source Field', 'primelink' ); ?></label>
                <input type="text" id="mt_primelink-editor-source" placeholder="<?php esc_attr_e( 'e.g. title or sku', 'primelink' ); ?>" />
            </div>

            <div class="mt_primelink-form-row">
                <label><?php esc_html_e( 'Prefix / Suffix', 'primelink' ); ?></label>
                <div style="display:grid;grid-template-columns:1fr 1fr;gap:8px;">
                    <input type="text" id="mt_primelink-editor-prefix" placeholder="<?php esc_attr_e( 'Prefix (optional)', 'primelink' ); ?>" />
                    <input type="text" id="mt_primelink-editor-suffix" placeholder="<?php esc_attr_e( 'Suffix (optional)', 'primelink' ); ?>" />
                </div>
                <small class="description"><?php esc_html_e( 'Useful to add fixed text before/after field values.', 'primelink' ); ?></small>
            </div>

            <div class="mt_primelink-form-row">
                <label><?php esc_html_e( 'Separator (for multi-values)', 'primelink' ); ?></label>
                <input type="text" id="mt_primelink-editor-separator" placeholder="<?php esc_attr_e( 'e.g. | , ; >', 'primelink' ); ?>" />
                <small class="description"><?php esc_html_e( 'Example: "img1.jpg,img2.jpg" use ","', 'primelink' ); ?></small>
            </div>

            <div class="mt_primelink-form-row">
                <label><?php esc_html_e( 'Default value (if empty)', 'primelink' ); ?></label>
                <input type="text" id="mt_primelink-editor-default" placeholder="<?php esc_attr_e( 'Fallback value', 'primelink' ); ?>" />
            </div>

            <div class="mt_primelink-form-row">
                <label><?php esc_html_e( 'Basic Transforms', 'primelink' ); ?></label>
                <div style="display:grid;grid-template-columns:repeat(3, 1fr);gap:8px;">
                    <label><input type="checkbox" id="mt_primelink-editor-trim" checked /> <?php esc_html_e( 'Trim spaces', 'primelink' ); ?></label>
                    <label><input type="checkbox" id="mt_primelink-editor-lowercase" /> <?php esc_html_e( 'Lowercase', 'primelink' ); ?></label>
                    <label><input type="checkbox" id="mt_primelink-editor-uppercase" /> <?php esc_html_e( 'Uppercase', 'primelink' ); ?></label>
                    <label><input type="checkbox" id="mt_primelink-editor-capitalize" /> <?php esc_html_e( 'Capitalize first', 'primelink' ); ?></label>
                    <label><input type="checkbox" id="mt_primelink-editor-title-case" /> <?php esc_html_e( 'Title Case', 'primelink' ); ?></label>
                    <label><input type="checkbox" id="mt_primelink-editor-normalize-html" /> <?php esc_html_e( 'Normalize HTML', 'primelink' ); ?></label>
                </div>
            </div>

            <div class="mt_primelink-form-row">
                <label><?php esc_html_e( 'Advanced Transforms', 'primelink' ); ?></label>
                <div style="display:grid;grid-template-columns:repeat(2, 1fr);gap:8px;">
                    <label><input type="checkbox" id="mt_primelink-editor-remove-accents" /> <?php esc_html_e( 'Remove accents/diacritics', 'primelink' ); ?></label>
                    <label><input type="checkbox" id="mt_primelink-editor-slugify" /> <?php esc_html_e( 'Slugify (URL-friendly)', 'primelink' ); ?></label>
                    <label><input type="checkbox" id="mt_primelink-editor-extract-numbers" /> <?php esc_html_e( 'Extract numbers only', 'primelink' ); ?></label>
                    <label><input type="checkbox" id="mt_primelink-editor-extract-text" /> <?php esc_html_e( 'Extract text only (remove numbers)', 'primelink' ); ?></label>
                    <label><input type="checkbox" id="mt_primelink-editor-url-encode" /> <?php esc_html_e( 'URL encode', 'primelink' ); ?></label>
                    <label><input type="checkbox" id="mt_primelink-editor-url-decode" /> <?php esc_html_e( 'URL decode', 'primelink' ); ?></label>
                </div>
            </div>

            <div class="mt_primelink-form-row">
                <label><?php esc_html_e( 'Number Transforms', 'primelink' ); ?></label>
                <div style="display:grid;grid-template-columns:repeat(2, 1fr);gap:8px;">
                    <label>
                        <input type="checkbox" id="mt_primelink-editor-round" />
                        <?php esc_html_e( 'Round number', 'primelink' ); ?>
                        <input type="number" id="mt_primelink-editor-round-decimals" min="0" max="10" value="2" style="width:60px;margin-left:4px;" placeholder="<?php esc_attr_e( 'decimals', 'primelink' ); ?>" />
                    </label>
                    <label><input type="checkbox" id="mt_primelink-editor-ceil" /> <?php esc_html_e( 'Ceil (round up)', 'primelink' ); ?></label>
                    <label><input type="checkbox" id="mt_primelink-editor-floor" /> <?php esc_html_e( 'Floor (round down)', 'primelink' ); ?></label>
                    <label>
                        <?php esc_html_e( 'Format number', 'primelink' ); ?>
                        <select id="mt_primelink-editor-number-format" style="width:120px;margin-left:4px;">
                            <option value=""><?php esc_html_e( 'None', 'primelink' ); ?></option>
                            <option value="comma">1,234.56</option>
                            <option value="dot">1.234,56</option>
                            <option value="space">1 234.56</option>
                        </select>
                    </label>
                </div>
            </div>

            <div class="mt_primelink-form-row">
                <label><?php esc_html_e( 'String Operations', 'primelink' ); ?></label>
                <div style="display:grid;grid-template-columns:repeat(2, 1fr);gap:8px;">
                    <label>
                        <?php esc_html_e( 'Substring', 'primelink' ); ?>
                        <input type="number" id="mt_primelink-editor-substring-start" placeholder="<?php esc_attr_e( 'Start', 'primelink' ); ?>" style="width:80px;margin-left:4px;" />
                        <input type="number" id="mt_primelink-editor-substring-length" placeholder="<?php esc_attr_e( 'Length', 'primelink' ); ?>" style="width:80px;margin-left:4px;" />
                    </label>
                    <label>
                        <?php esc_html_e( 'Pad', 'primelink' ); ?>
                        <select id="mt_primelink-editor-pad-side" style="width:80px;margin-left:4px;">
                            <option value=""><?php esc_html_e( 'None', 'primelink' ); ?></option>
                            <option value="left"><?php esc_html_e( 'Left', 'primelink' ); ?></option>
                            <option value="right"><?php esc_html_e( 'Right', 'primelink' ); ?></option>
                        </select>
                        <input type="number" id="mt_primelink-editor-pad-length" placeholder="<?php esc_attr_e( 'Length', 'primelink' ); ?>" style="width:60px;margin-left:4px;" />
                        <input type="text" id="mt_primelink-editor-pad-char" placeholder="<?php esc_attr_e( 'Char', 'primelink' ); ?>" style="width:40px;margin-left:4px;" maxlength="1" />
                    </label>
                </div>
            </div>

            <div class="mt_primelink-form-row">
                <label><?php esc_html_e( 'Date/Time Transforms', 'primelink' ); ?></label>
                <div style="display:grid;grid-template-columns:repeat(2, 1fr);gap:8px;">
                    <label>
                        <?php esc_html_e( 'Format date', 'primelink' ); ?>
                        <input type="text" id="mt_primelink-editor-date-format" placeholder="Y-m-d" style="width:120px;margin-left:4px;" />
                        <small class="description" style="display:block;margin-top:4px;"><?php esc_html_e( 'Input format (e.g. d/m/Y, Y-m-d)', 'primelink' ); ?></small>
                    </label>
                    <label>
                        <?php esc_html_e( 'Output format', 'primelink' ); ?>
                        <input type="text" id="mt_primelink-editor-date-output" placeholder="Y-m-d" style="width:120px;margin-left:4px;" />
                        <small class="description" style="display:block;margin-top:4px;"><?php esc_html_e( 'Output format (e.g. Y-m-d, d/m/Y)', 'primelink' ); ?></small>
                    </label>
                </div>
            </div>

            <div class="mt_primelink-form-row">
                <label><?php esc_html_e( 'Regex Replace', 'primelink' ); ?></label>
                <div style="display:grid;grid-template-columns:1fr 1fr;gap:8px;">
                    <input type="text" id="mt_primelink-editor-regex-pattern" placeholder="<?php esc_attr_e( 'Pattern (e.g. /[0-9]+/)', 'primelink' ); ?>" />
                    <input type="text" id="mt_primelink-editor-regex-replacement" placeholder="<?php esc_attr_e( 'Replacement', 'primelink' ); ?>" />
                </div>
                <small class="description"><?php esc_html_e( 'Use regex pattern to find and replace. Example: /[0-9]+/ to replace all numbers.', 'primelink' ); ?></small>
            </div>

            <div class="mt_primelink-form-row">
                <label><?php esc_html_e( 'Replace rules', 'primelink' ); ?></label>
                <div id="mt_primelink-editor-replace-wrap"></div>
                <button type="button" class="button" id="mt_primelink-editor-add-replace"><?php esc_html_e( 'Add Replace Rule', 'primelink' ); ?></button>
            </div>
        </div>

        <div class="mt_primelink-map-editor__footer">
            <button type="button" class="button button-primary" id="mt_primelink-editor-save"><?php esc_html_e( 'Save Options', 'primelink' ); ?></button>
        </div>
    </div>
</div>
