<?php
namespace WebshoptigerCatalogSync\Admin;

defined( 'ABSPATH' ) || exit;

use WebshoptigerCatalogSync\Settings;

class AdminPage {

    public static function init(): void {
        add_action( 'admin_menu',            [ __CLASS__, 'register_menu' ] );
        add_action( 'admin_enqueue_scripts', [ __CLASS__, 'enqueue_assets' ] );
    }

    public static function register_menu(): void {
        $title = WEBSHOPTIGERCATALOGSYNC_PLUGIN_NAME . ( Settings::is_pro() ? ' Pro' : ' Lite' );
        add_menu_page(
            $title,
            'Webshoptiger Catalog Sync',
            'manage_woocommerce',
            'webshoptigercatalogsync-sync',
            [ __CLASS__, 'render_page' ],
            'dashicons-update',
            56
        );
    }

    public static function enqueue_assets( string $hook ): void {
        $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only routing param
        if ( $page !== 'webshoptigercatalogsync-sync' ) return;
        wp_enqueue_style( 'webshoptigercatalogsync-sync-admin', WEBSHOPTIGERCATALOGSYNC_URL . 'assets/css/admin.css', [], WEBSHOPTIGERCATALOGSYNC_VERSION );
        wp_enqueue_script( 'chartjs', WEBSHOPTIGERCATALOGSYNC_URL . 'assets/js/chart.min.js', [], '4.4.1', true );
        wp_enqueue_script( 'webshoptigercatalogsync-sync-admin', WEBSHOPTIGERCATALOGSYNC_URL . 'assets/js/admin.js', [ 'jquery', 'chartjs' ], WEBSHOPTIGERCATALOGSYNC_VERSION, true );
        wp_localize_script( 'webshoptigercatalogsync-sync-admin', 'webshoptigerCatalogSync', [
            'nonce'   => wp_create_nonce( 'webshoptigercatalogsync_nonce' ),
            'ajaxUrl' => admin_url( 'admin-ajax.php' ),
        ] );
    }

    public static function render_page(): void {
        $is_source = Settings::is_source_site();
        $tab = sanitize_key( $_GET['tab'] ?? 'sites' ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only routing param
        $edition   = Settings::is_pro() ? 'Pro' : 'Lite';
        ?>
        <div class="wrap webshoptigercatalogsync-sync-wrap">
            <h1>
                <span class="dashicons dashicons-update"></span>
                <?php echo esc_html( WEBSHOPTIGERCATALOGSYNC_PLUGIN_NAME ); ?>
                <span class="sc-edition-badge sc-edition-<?php echo sanitize_html_class( strtolower( $edition ) ); ?>"><?php echo esc_html( $edition ); ?></span>
                <span class="webshoptigercatalogsync-sync-badge <?php echo sanitize_html_class( $is_source ? 'badge-source' : 'badge-dest' ); ?>">
                    <?php echo $is_source ? 'Source site' : 'Destination site'; /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- hardcoded strings */ ?>
                </span>
            </h1>

            <!-- Site role setting -->
            <div class="sc-sitetype-bar">
                <strong>Role of this installation:</strong>
                <select id="sc-sitetype-select">
                    <option value="1" <?php echo $is_source ? 'selected' : ''; ?>>&#127968; Source site (sends products to other sites)</option>
                    <option value="0" <?php echo ! $is_source ? 'selected' : ''; ?>>&#8594; Destination site (receives products from a source site)</option>
                </select>
                <button class="button" id="sc-sitetype-save">Save</button>
                <span class="sc-feedback" id="sc-sitetype-feedback"></span>
                <span class="sc-sitetype-hint">Set whether this is the source site or a destination site. The page will reload automatically.</span>
            </div>

            <?php if ( get_option( 'webshoptigercatalogsync_is_source', '' ) === '' ): ?>
            <div class="sc-setup-notice">
                <strong>&#9888; Role not set yet.</strong>
                Select above whether this is the <em>Source site</em> (where you manage products) or a <em>Destination site</em>
                (which receives products) and click Save. On the destination site, create a WooCommerce REST API key
                and enter it in the website settings on the source site.
            </div>
            <?php endif; ?>

            <?php if ( $is_source ): ?>
            <nav class="webshoptigercatalogsync-sync-tabs">
                <a href="?page=webshoptigercatalogsync-sync&tab=sites"        class="<?php echo esc_attr( $tab === 'sites' ? 'active' : '' ); ?>">Websites</a>
                <a href="?page=webshoptigercatalogsync-sync&tab=settings"     class="<?php echo esc_attr( $tab === 'settings' ? 'active' : '' ); ?>">Settings</a>
                <a href="?page=webshoptigercatalogsync-sync&tab=log"          class="<?php echo esc_attr( $tab === 'log' ? 'active' : '' ); ?>">Sync log</a>
                <a href="?page=webshoptigercatalogsync-sync&tab=status"       class="<?php echo esc_attr( $tab === 'status' ? 'active' : '' ); ?>">Status</a>
                <?php if ( Settings::is_pro() ): ?>
                <a href="?page=webshoptigercatalogsync-sync&tab=stats"        class="<?php echo esc_attr( $tab === 'stats' ? 'active' : '' ); ?>">Statistics</a>
                <a href="?page=webshoptigercatalogsync-sync&tab=descriptions" class="<?php echo esc_attr( $tab === 'descriptions' ? 'active' : '' ); ?>">Descriptions</a>
                <?php endif; ?>
            </nav>

            <div class="webshoptigercatalogsync-sync-content">
                <?php
                switch ( $tab ) {
                    case 'settings':     self::render_settings();     break;
                    case 'log':          self::render_log();          break;
                    case 'status':       self::render_status();       break;
                    case 'stats':        self::render_stats();        break;
                    case 'descriptions': self::render_descriptions(); break;
                    default:             self::render_sites();        break;
                }
                ?>
            </div>

            <?php else: ?>
            <div class="webshoptigercatalogsync-sync-content">
                <?php self::render_destination_info(); ?>
            </div>
            <?php endif; ?>
        </div>
        <?php
    }

    // -------------------------------------------------------------------------
    // Tab: Websites
    // -------------------------------------------------------------------------

    private static function render_sites(): void {
        $sites      = class_exists( 'WebshoptigerCatalogSync\\SiteManager' ) ? \WebshoptigerCatalogSync\SiteManager::get_all() : [];
        $categories = get_terms( [ 'taxonomy' => 'product_cat', 'hide_empty' => false ] );
        ?>
        <div class="webshoptigercatalogsync-sync-card">
            <h2>Manage destination websites</h2>
            <p>Add the websites you want to sync products to here. Install the plugin on the destination website too.</p>

            <button type="button" class="button button-primary" id="sc-add-site">+ Add website</button>

            <div id="sc-site-form" style="display:none;" class="sc-form">
                <h3 id="sc-form-title">New website</h3>
                <input type="hidden" id="sc-site-id" value="0">
                <table class="form-table">
                    <tr>
                        <th><label for="sc-label">Name</label></th>
                        <td><input type="text" id="sc-label" class="regular-text" placeholder="E.g. My Webshop"></td>
                    </tr>
                    <tr>
                        <th><label for="sc-site-url">Website URL</label></th>
                        <td><input type="url" id="sc-site-url" class="regular-text" placeholder="https://mywebshop.com"></td>
                    </tr>
                    <tr>
                        <th><label for="sc-api-key">WooCommerce Consumer Key</label></th>
                        <td>
                            <input type="text" id="sc-api-key" class="regular-text" placeholder="ck_...">
                            <p class="description">Create this via WooCommerce → Settings → Advanced → REST API on the destination site.</p>
                        </td>
                    </tr>
                    <tr>
                        <th><label for="sc-api-secret">WooCommerce Consumer Secret</label></th>
                        <td><input type="password" id="sc-api-secret" class="regular-text" placeholder="cs_..."></td>
                    </tr>
                    <tr>
                        <th><label>Categories</label></th>
                        <td>
                            <div class="sc-categories">
                                <?php foreach ( (array) $categories as $cat ): ?>
                                <label class="sc-cat-label">
                                    <input type="checkbox" class="sc-cat-cb" value="<?php echo esc_attr( $cat->term_id ); ?>">
                                    <?php echo esc_html( $cat->name ); ?> (<?php echo (int) $cat->count; ?>)
                                </label>
                                <?php endforeach; ?>
                            </div>
                            <p class="description">Select which categories will be synced to this website.</p>
                        </td>
                    </tr>
                    <tr>
                        <th><label for="webshoptigercatalogsync-sync-desc">Sync descriptions</label></th>
                        <td>
                            <label>
                                <input type="checkbox" id="webshoptigercatalogsync-sync-desc" checked>
                                Overwrite product descriptions during synchronization
                            </label>
                            <p class="description">Turn this off if you edit descriptions manually on the destination site and want to keep them.</p>
                        </td>
                    </tr>
                    <tr>
                        <th><label for="sc-enabled">Active</label></th>
                        <td><input type="checkbox" id="sc-enabled" checked></td>
                    </tr>
                </table>
                <div class="sc-form-actions">
                    <button type="button" class="button button-primary" id="sc-save-site">Save</button>
                    <button type="button" class="button" id="sc-test-site">Test connection</button>
                    <button type="button" class="button" id="sc-cancel-site">Cancel</button>
                    <span class="sc-feedback" id="sc-site-feedback"></span>
                </div>
            </div>

            <?php if ( $sites ): ?>
            <table class="wp-list-table widefat fixed striped sc-sites-table" style="margin-top:20px;">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>URL</th>
                        <th>Categories</th>
                        <th>Status</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ( $sites as $site ):
                        $cat_names = array_map( function ( $id ) {
                            $t = get_term( (int) $id, 'product_cat' );
                            return ( $t && ! is_wp_error( $t ) ) ? esc_html( $t->name ) : '#' . $id;
                        }, (array) $site['categories'] );
                    ?>
                    <tr data-site="<?php echo esc_attr( wp_json_encode( $site ) ); ?>">
                        <td><strong><?php echo esc_html( $site['label'] ); ?></strong></td>
                        <td><a href="<?php echo esc_url( $site['site_url'] ); ?>" target="_blank"><?php echo esc_html( $site['site_url'] ); ?></a></td>
                        <td><?php echo $cat_names ? esc_html( implode( ', ', $cat_names ) ) : '<em>None</em>'; /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- hardcoded HTML tag */ ?></td>
                        <td>
                            <?php echo (int) $site['enabled']
                                ? '<span class="sc-badge-ok">Active</span>'
                                : '<span class="sc-badge-off">Inactive</span>'; ?>
                            <?php if ( ! (int) ( $site['sync_description'] ?? 1 ) ): ?>
                                <span class="sc-badge-off" title="Descriptions are not overwritten">Desc. kept</span>
                            <?php endif; ?>
                        </td>
                        <td>
                            <button type="button" class="button button-small sc-edit-site" data-id="<?php echo (int) $site['id']; ?>">Edit</button>
                            <button type="button" class="button button-small webshoptigercatalogsync-sync-one" data-id="<?php echo (int) $site['id']; ?>">Sync now</button>
                            <button type="button" class="button button-small sc-reset-remote-ids" data-id="<?php echo (int) $site['id']; ?>" title="Clears the plugin&apos;s memory of which products exist on this destination site. Use this after manually deleting products there.">Reset sync state</button>
                            <button type="button" class="button button-small button-link-delete sc-delete-site" data-id="<?php echo (int) $site['id']; ?>">Delete</button>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
            <?php else: ?>
            <p class="sc-empty">No websites configured yet.</p>
            <?php endif; ?>
        </div>
        <?php
    }

    // -------------------------------------------------------------------------
    // Tab: Settings
    // -------------------------------------------------------------------------

    private static function render_settings(): void {
        $openai_key           = Settings::get( 'openai_key' );
        $openai_prompt        = Settings::get( 'openai_prompt' );
        $interval             = Settings::get( 'interval', 'hourly' );
        $rewrite_descriptions = (int) Settings::get( 'rewrite_descriptions' );
        $intervals            = Settings::allowed_intervals();
        $is_lite              = Settings::is_lite();
        ?>
        <div class="webshoptigercatalogsync-sync-card">
            <h2>General settings</h2>

            <h3>Sync interval</h3>
            <table class="form-table">
                <tr>
                    <th><label for="sc-interval">How often should syncing run?</label></th>
                    <td>
                        <select id="sc-interval">
                            <?php foreach ( $intervals as $key => $label ): ?>
                            <option value="<?php echo esc_attr( $key ); ?>" <?php echo selected( $interval, $key, false ); ?>>
                                <?php echo esc_html( $label ); ?>
                            </option>
                            <?php endforeach; ?>
                        </select>
                        <p class="description">How often products are automatically synchronised to all destination sites.</p>
                    </td>
                </tr>
            </table>

            <?php if ( Settings::is_pro() ): ?>
            <h3>OpenAI – Rewrite descriptions</h3>
            <table class="form-table">
                <tr>
                    <th><label for="sc-rewrite">Rewrite descriptions</label></th>
                    <td>
                        <label>
                            <input type="checkbox" id="sc-rewrite" value="1" <?php echo checked( $rewrite_descriptions, 1, false ); ?>>
                            Use OpenAI to rewrite product descriptions for destination sites
                        </label>
                    </td>
                </tr>
                <tr>
                    <th><label for="sc-openai-key">OpenAI API Key</label></th>
                    <td>
                        <input type="password" id="sc-openai-key" class="regular-text" value="<?php echo esc_attr( $openai_key ); ?>" placeholder="sk-...">
                        <button type="button" class="button" id="sc-test-openai">Test API key</button>
                        <span class="sc-feedback" id="sc-openai-feedback"></span>
                    </td>
                </tr>
                <tr>
                    <th><label for="sc-openai-prompt">Rewrite prompt</label></th>
                    <td>
                        <textarea id="sc-openai-prompt" class="large-text" rows="5"><?php echo esc_textarea( $openai_prompt ); ?></textarea>
                        <p class="description">Instructions for the AI. The product description is sent as the user message.</p>
                    </td>
                </tr>
            </table>
            <?php endif; ?>

            <button type="button" class="button button-primary" id="sc-save-settings">Save settings</button>
            <span class="sc-feedback" id="sc-settings-feedback"></span>
        </div>
        <?php
    }

    // -------------------------------------------------------------------------
    // Tab: Statistics
    // -------------------------------------------------------------------------



    private static function render_log(): void {
        $log = class_exists( 'WebshoptigerCatalogSync\\Sync' ) ? \WebshoptigerCatalogSync\Sync::get_log( 200 ) : [];
        ?>
        <div class="webshoptigercatalogsync-sync-card">
            <h2>Sync log</h2>
            <button type="button" class="button" id="sc-clear-log">Clear log</button>
            <span class="sc-feedback" id="sc-log-feedback"></span>

            <?php if ( $log ): ?>
            <table class="wp-list-table widefat fixed striped sc-log-table" style="margin-top:16px;">
                <thead>
                    <tr>
                        <th>Date/time</th>
                        <th>Website</th>
                        <th>Product</th>
                        <th>Action</th>
                        <th>Status</th>
                        <th>Message</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ( $log as $row ): ?>
                    <tr class="<?php echo esc_attr( $row['status'] === 'error' ? 'sc-log-error' : '' ); ?>">
                        <td><?php echo esc_html( $row['synced_at'] ); ?></td>
                        <td><?php echo esc_html( $row['site_label'] ?? '#' . $row['site_id'] ); ?></td>
                        <td><?php echo esc_html( $row['product_name'] ?? '#' . $row['product_id'] ); ?></td>
                        <td><?php echo esc_html( $row['action'] ); ?></td>
                        <td><span class="sc-badge-<?php echo esc_attr( $row['status'] ); ?>"><?php echo esc_html( $row['status'] ); ?></span></td>
                        <td>
                            <?php
                            $msg = $row['message'];
                            // Format pipe-separated details as separate lines
                            if ( strpos( $msg, ' | ' ) !== false ) {
                                $parts = explode( ' | ', $msg );
                                echo '<span class="sc-log-main">' . esc_html( $parts[0] ) . '</span>';
                                echo '<span class="sc-log-details">';
                                foreach ( array_slice( $parts, 1 ) as $part ) {
                                    echo '<span>' . esc_html( $part ) . '</span>';
                                }
                                echo '</span>';
                            } else {
                                echo esc_html( $msg );
                            }
                            ?>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
            <?php else: ?>
            <p class="sc-empty">No synchronizations logged yet.</p>
            <?php endif; ?>
        </div>
        <?php
    }

    // -------------------------------------------------------------------------
    // Tab: Status
    // -------------------------------------------------------------------------

    private static function render_status(): void {
        $sites     = class_exists( '\\WebshoptigerCatalogSync\\SiteManager' ) ? \WebshoptigerCatalogSync\SiteManager::get_all() : [];
        $enabled   = array_filter( $sites, fn( $s ) => (int) $s['enabled'] );
        $batch     = (int) Settings::get( 'batch_size', 10 );
        ?>
        <div class="webshoptigercatalogsync-sync-card">
            <h2>Status &amp; synchronization</h2>

            <table class="form-table">
                <tr>
                    <th>Next automatic sync</th>
                    <td>
                        <code><?php echo esc_html( class_exists( 'WebshoptigerCatalogSync\\Scheduler' ) ? \WebshoptigerCatalogSync\Scheduler::get_next_run() : 'N/A' ); ?></code>
                    </td>
                </tr>
                <tr>
                    <th>Interval</th>
                    <td><?php echo esc_html( Settings::allowed_intervals()[ Settings::get( 'interval', 'hourly' ) ] ?? Settings::get( 'interval', 'hourly' ) ); ?></td>
                </tr>
                <tr>
                    <th>Configured websites</th>
                    <td><?php echo (int) count( $sites ); ?> (<?php echo (int) count( $enabled ); ?> active)</td>
                </tr>
                <tr>
                    <th>OpenAI rewriting</th>
                    <td><?php echo (int) Settings::get( 'rewrite_descriptions' ) ? 'Active' : 'Inactive (Pro feature)'; /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */ ?></td>
                </tr>
                <tr>
                    <th><label for="sc-batch-size">Batch size</label></th>
                    <td>
                        <input type="number" id="sc-batch-size" value="<?php echo (int) $batch; ?>" min="1" max="50" style="width:70px">
                        products per background task
                        <button type="button" class="button" id="sc-save-batch" style="margin-left:8px">Save</button>
                        <span class="sc-feedback" id="sc-batch-feedback"></span>
                        <p class="description">Lower = less chance of timeout. Recommended: 5–10.</p>
                    </td>
                </tr>
            </table>

            <div class="sc-runner-info">
                <strong>Queue Runner:</strong>
                <code><?php echo esc_url( \WebshoptigerCatalogSync\Queue::get_runner_url() ); ?></code>
                <p class="description">
                    Add this URL as a server cron job for maximum reliability:<br>
                    <code>* * * * * curl -s "<?php echo esc_url( \WebshoptigerCatalogSync\Queue::get_runner_url() ); ?>" &gt;/dev/null 2&gt;&amp;1</code>
                </p>
            </div>

            <div class="webshoptigercatalogsync-sync-actions">
                <button type="button" class="button button-primary" id="sc-manual-sync">Sync all sites now</button>
                <button type="button" class="button" id="sc-clear-cat-cache">&#128465; Clear category cache</button>
                <span class="sc-feedback" id="sc-cat-cache-feedback"></span>
                <button type="button" class="button" id="sc-clear-brand-cache">&#128465; Clear brand cache</button>
                <span class="sc-feedback" id="sc-brand-cache-feedback"></span>
                <?php foreach ( $enabled as $site ): ?>
                <button type="button" class="button webshoptigercatalogsync-sync-one" data-id="<?php echo (int) $site['id']; ?>">
                    Sync: <?php echo esc_html( $site['label'] ); ?>
                </button>
                <?php endforeach; ?>
                <span class="sc-feedback" id="webshoptigercatalogsync-sync-feedback"></span>
            </div>
        </div>

        <div class="webshoptigercatalogsync-sync-card" style="margin-top:16px;">
            <h2>Select a product to sync</h2>
            <p class="description">Search for a specific product by name, SKU, or ID and sync it separately from regular category-based synchronization. Handy for quickly testing whether a single product comes across correctly.</p>

            <div class="sc-product-picker">
                <input type="text" id="sc-product-search" class="regular-text" placeholder="Search by product name, SKU, or ID…" autocomplete="off">
                <select id="sc-product-target-site">
                    <option value="">All active destination sites</option>
                    <?php foreach ( $enabled as $site ): ?>
                    <option value="<?php echo (int) $site['id']; ?>"><?php echo esc_html( $site['label'] ); ?></option>
                    <?php endforeach; ?>
                </select>
                <span class="sc-feedback" id="sc-product-sync-feedback"></span>
            </div>

            <div id="sc-product-search-results"></div>
        </div>

        <!-- Live job progress -->
        <div class="webshoptigercatalogsync-sync-card" style="margin-top:16px;" id="sc-jobs-card">
            <div class="sc-jobs-header">
                <h2 style="margin:0">Running &amp; completed synchronizations</h2>
                <button type="button" class="button" id="sc-clear-jobs">Remove completed</button>
            </div>
            <div id="sc-jobs-list">
                <p class="sc-empty">No active synchronizations.</p>
            </div>
        </div>
        <?php
    }

    // -------------------------------------------------------------------------
    // Tab: Descriptions
    // -------------------------------------------------------------------------



    // -------------------------------------------------------------------------
    // Destination site info
    // -------------------------------------------------------------------------

    private static function render_destination_info(): void {
        ?>
        <div class="webshoptigercatalogsync-sync-card">
            <h2>Destination site – <?php echo esc_html( WEBSHOPTIGERCATALOGSYNC_PLUGIN_NAME ); ?></h2>
            <p>This installation is configured as a <strong>destination site</strong>. Products, categories, and brands will be synced automatically once a source site connects.</p>

            <div class="sc-info-box" style="margin-bottom:20px;">
                <strong>&#10003; Brand synchronization active</strong> — brands are linked directly via the built-in <code>webshoptigercatalogsync-sync/v1/assign-brands</code> endpoint.
            </div>

            <h3>Step 1 – Create a WooCommerce REST API key</h3>
            <ol>
                <li>Go to <strong>WooCommerce → Settings → Advanced → REST API</strong></li>
                <li>Click <strong>Add key</strong></li>
                <li>Enter a description, e.g. <em><?php echo esc_html( WEBSHOPTIGERCATALOGSYNC_PLUGIN_NAME ); ?></em></li>
                <li>Set <strong>Permissions</strong> to <strong>Read/Write</strong></li>
                <li>Click <strong>Generate API key</strong></li>
                <li>Copy the <strong>Consumer Key</strong> and <strong>Consumer Secret</strong></li>
            </ol>

            <p>
                <a href="<?php echo esc_url( admin_url( 'admin.php?page=wc-settings&tab=advanced&section=keys' ) ); ?>" class="button button-primary" target="_blank">
                    Manage WooCommerce API keys
                </a>
            </p>

            <h3>Step 2 – Enter keys on the source site</h3>
            <p>Enter the Consumer Key and Consumer Secret on the source site under <strong>Webshoptiger Catalog Sync → Websites → Add website</strong>.</p>

            <table class="form-table" style="margin-top:16px;">
                <tr>
                    <th>Website URL</th>
                    <td><code><?php echo esc_url( get_site_url() ); ?></code></td>
                </tr>
                <tr>
                    <th>Status endpoint</th>
                    <td><code><?php echo esc_url( get_rest_url( null, 'webshoptigercatalogsync-sync/v1/status' ) ); ?></code></td>
                </tr>
                <tr>
                    <th>Brands endpoint</th>
                    <td><code><?php echo esc_url( get_rest_url( null, 'webshoptigercatalogsync-sync/v1/assign-brands' ) ); ?></code></td>
                </tr>
            </table>

            <div class="sc-info-box" style="margin-top:20px;">
                <strong>Protection active:</strong> products not created by <?php echo esc_html( WEBSHOPTIGERCATALOGSYNC_PLUGIN_NAME ); ?> are never changed or deleted by synchronization.
            </div>
        </div>
        <?php
    }
}
