<?php
/**
 * Template Helper for rendering common UI components.
 *
 * @package PrimeLink
 */

namespace PrimeLink\Helpers;

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

/**
 * Template Helper class for rendering reusable UI components.
 */
final class TemplateHelper {

    /**
     * Render export mapping slots.
     *
     * @param array  $fields     Array of field keys and labels.
     * @param string $name_prefix Name prefix for form inputs.
     * @return void
     */
    public static function render_export_slots( $fields, $name_prefix = 'mapping' ) {
        foreach ( $fields as $key => $label ) : ?>
            <div class="mt_primelink-map-slot" data-target="<?php echo esc_attr( $key ); ?>">
                <div class="mt_primelink-map-label">
                    <span class="mt_primelink-map-label__text"><?php echo esc_html( $label ); ?></span>
                    <button type="button"
                            class="button button-small mt_primelink-map-edit mt_primelink-map-edit--inline"
                            disabled>
                        <?php esc_html_e( 'Edit', 'primelink' ); ?>
                    </button>
                </div>
                <div class="mt_primelink-map-drop mt-map-slot__drop">
                    <span class="mt_primelink-muted"><?php esc_html_e( 'Drop field here', 'primelink' ); ?></span>
                </div>
                <input type="hidden"
                       class="mt_primelink-map-input"
                       name="<?php echo esc_attr( $name_prefix ); ?>[<?php echo esc_attr( $key ); ?>][source]"
                       value="" />
                <input type="hidden"
                       class="mt_primelink-map-config"
                       name="<?php echo esc_attr( $name_prefix ); ?>[<?php echo esc_attr( $key ); ?>][config]"
                       value="" />
            </div>
        <?php endforeach;
    }

    /**
     * Render import mapping slots.
     *
     * @param array  $fields     Array of field keys and labels.
     * @param string $name_prefix Name prefix for form inputs.
     * @return void
     */
    public static function render_import_slots( $fields, $name_prefix = 'mapping' ) {
        foreach ( $fields as $key => $label ) : ?>
            <div class="mt_primelink-map-slot" data-target="<?php echo esc_attr( $key ); ?>">
                <div class="mt_primelink-map-label">
                    <span class="mt_primelink-map-label__text"><?php echo esc_html( $label ); ?></span>
                    <button type="button"
                            class="button button-small mt_primelink-map-edit mt_primelink-map-edit--inline"
                            disabled>
                        <?php esc_html_e( 'Edit', 'primelink' ); ?>
                    </button>
                </div>
                <div class="mt_primelink-map-drop mt-map-slot__drop">
                    <span class="mt_primelink-muted"><?php esc_html_e( 'Drop field here', 'primelink' ); ?></span>
                </div>
                <input type="hidden"
                       class="mt_primelink-map-input"
                       name="<?php echo esc_attr( $name_prefix ); ?>[<?php echo esc_attr( $key ); ?>][source]"
                       value="" />
                <input type="hidden"
                       class="mt_primelink-map-config"
                       name="<?php echo esc_attr( $name_prefix ); ?>[<?php echo esc_attr( $key ); ?>][config]"
                       value="" />
            </div>
        <?php endforeach;
    }
}
