<?php
/**
 * Integrations Mapping - shared section for external plugins.
 *
 * Currently supports (conditionally, only when plugins are active):
 * - Yoast SEO
 * - ACF / ACF Pro
 * - WPML
 * - Polylang
 *
 * This partial is included in Step 5 (Field Mapping) for all import types.
 *
 * @package PrimeLink
 */

use PrimeLink\Helpers\TemplateHelper;

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

<?php if ( class_exists( 'WPSEO_Meta' ) || defined( 'WPSEO_VERSION' ) ) : ?>
    <!-- Yoast SEO -->
    <details class="mt_primelink-accordion">
        <summary class="mt_primelink-accordion-title"><?php esc_html_e( 'Yoast SEO', 'primelink' ); ?></summary>
        <div class="mt_primelink-accordion-body">
            <?php
            // Common Yoast fields - mapped via Yoast meta keys.
            TemplateHelper::render_import_slots(
                array(
                    'yoast_title'       => __( 'SEO Title', 'primelink' ),
                    'yoast_description' => __( 'Meta Description', 'primelink' ),
                    'yoast_focuskw'     => __( 'Focus Keyword', 'primelink' ),
                )
            );
            ?>
        </div>
    </details>
<?php endif; ?>

<?php if ( class_exists( 'ACF' ) || function_exists( 'acf_get_field' ) ) : ?>
    <!-- ACF / ACF Pro -->
    <details class="mt_primelink-accordion">
        <summary class="mt_primelink-accordion-title"><?php esc_html_e( 'ACF / ACF Pro', 'primelink' ); ?></summary>
        <div class="mt_primelink-accordion-body">
            <p class="description">
                <?php esc_html_e( 'Define any number of ACF fields. Set the meta key for each (e.g. field_XXXX or the ACF meta key) and drag a source field into the slot.', 'primelink' ); ?>
            </p>
            <div id="mt_primelink-acf-fields-wrap" class="mt_primelink-acf-fields-wrap">
                <!-- ACF rows are added dynamically via JS -->
            </div>
            <button type="button" class="button" id="mt_primelink-add-acf-field">
                <?php esc_html_e( 'Add ACF Field', 'primelink' ); ?>
            </button>
        </div>
    </details>
<?php endif; ?>

<?php if ( defined( 'ICL_SITEPRESS_VERSION' ) || class_exists( 'SitePress' ) ) : ?>
    <!-- WPML -->
    <details class="mt_primelink-accordion">
        <summary class="mt_primelink-accordion-title"><?php esc_html_e( 'WPML', 'primelink' ); ?></summary>
        <div class="mt_primelink-accordion-body">
            <p class="description">
                <?php esc_html_e( 'Map language and translation data for WPML-enabled sites.', 'primelink' ); ?>
            </p>
            <?php
            TemplateHelper::render_import_slots(
                array(
                    'wpml_lang'          => __( 'Language Code (e.g. en, de)', 'primelink' ),
                    'wpml_trid'          => __( 'Translation Group ID (TRID)', 'primelink' ),
                    'wpml_source_lang'   => __( 'Source Language Code', 'primelink' ),
                ),
                'mapping[wpml]'
            );
            ?>
        </div>
    </details>
<?php endif; ?>

<?php if ( function_exists( 'pll_current_language' ) ) : ?>
    <!-- Polylang -->
    <details class="mt_primelink-accordion">
        <summary class="mt_primelink-accordion-title"><?php esc_html_e( 'Polylang', 'primelink' ); ?></summary>
        <div class="mt_primelink-accordion-body">
            <p class="description">
                <?php esc_html_e( 'Assign imported items to Polylang languages or link translations.', 'primelink' ); ?>
            </p>
            <?php
            TemplateHelper::render_import_slots(
                array(
                    'pll_lang'        => __( 'Language Code (e.g. en, de)', 'primelink' ),
                    'pll_translation' => __( 'Translation Group / Reference', 'primelink' ),
                ),
                'mapping[polylang]'
            );
            ?>
        </div>
    </details>
<?php endif; ?>

