<?php
/**
 * Free versus Pro comparison page.
 *
 * @package NexDirectoryFree
 */

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

$nexdirectory_comparison_catalog = $this->get_free_pro_comparison_catalog();
$nexdirectory_pro_addon_active = function_exists('nexdirectory_is_pro_addon_active')
    && nexdirectory_is_pro_addon_active();
$nexdirectory_pro_license_active = function_exists('nexdirectory_is_pro_license_active')
    && nexdirectory_is_pro_license_active();
$nexdirectory_upgrade_url = function_exists('nexdirectory_get_pro_upgrade_url')
    ? nexdirectory_get_pro_upgrade_url()
    : 'https://nexdirectory.com/pricing';
$nexdirectory_manage_pro_url = admin_url('admin.php?page=nexdirectory-pro');
$nexdirectory_dashboard_url = admin_url('admin.php?page=nexdirectory-dashboard');

if ($nexdirectory_pro_license_active) {
    $nexdirectory_plan_label = __('Pro active', 'nexdirectory');
    $nexdirectory_hero_kicker = __('Your plan', 'nexdirectory');
    $nexdirectory_hero_title = __('You have the complete NexDirectory toolkit.', 'nexdirectory');
    $nexdirectory_hero_description = __('Use this page as a quick capability guide. Your compatible Pro add-on is licensed and the advanced modules can load.', 'nexdirectory');
} elseif ($nexdirectory_pro_addon_active) {
    $nexdirectory_plan_label = __('Pro setup required', 'nexdirectory');
    $nexdirectory_hero_kicker = __('Complete your setup', 'nexdirectory');
    $nexdirectory_hero_title = __('Your Pro add-on is installed and waiting.', 'nexdirectory');
    $nexdirectory_hero_description = __('Connect an eligible license or trial in the existing Pro add-on to enable its advanced modules. Free publishing stays unlimited.', 'nexdirectory');
} else {
    $nexdirectory_plan_label = __('Free — unlimited publishing', 'nexdirectory');
    $nexdirectory_hero_kicker = __('A clear upgrade path', 'nexdirectory');
    $nexdirectory_hero_title = __('Keep the essentials free. Add Pro when the work gets more complex.', 'nexdirectory');
    $nexdirectory_hero_description = __('Nex Directory Free is built for real sites with unlimited core publishing. Pro adds automation, monetization, AI, richer analytics, and app-style experiences.', 'nexdirectory');
}
?>
<div class="wrap nexdirectory-admin-premium nexdirectory-upgrade-page">
    <?php $this->render_admin_premium_shell_styles(); ?>

    <section class="nexdirectory-admin-hero nexdirectory-upgrade-hero">
        <div class="nexdirectory-upgrade-hero__copy">
            <span class="nexdirectory-admin-hero-kicker"><?php echo esc_html($nexdirectory_hero_kicker); ?></span>
            <h1><?php echo esc_html($nexdirectory_hero_title); ?></h1>
            <p><?php echo esc_html($nexdirectory_hero_description); ?></p>
            <div class="nexdirectory-upgrade-hero__actions">
                <?php if ($nexdirectory_pro_addon_active) : ?>
                    <a class="button button-primary" href="<?php echo esc_url($nexdirectory_manage_pro_url); ?>">
                        <span class="dashicons dashicons-admin-plugins" aria-hidden="true"></span>
                        <?php echo esc_html($nexdirectory_pro_license_active ? __('Manage Pro', 'nexdirectory') : __('Finish Pro setup', 'nexdirectory')); ?>
                    </a>
                <?php else : ?>
                    <a class="button button-primary" href="<?php echo esc_url($nexdirectory_upgrade_url); ?>" target="_blank" rel="noopener noreferrer external">
                        <span class="dashicons dashicons-external" aria-hidden="true"></span>
                        <?php esc_html_e('View Pro plans', 'nexdirectory'); ?>
                    </a>
                <?php endif; ?>
                <a class="button" href="<?php echo esc_url($nexdirectory_dashboard_url); ?>">
                    <?php esc_html_e('Back to overview', 'nexdirectory'); ?>
                </a>
            </div>
            <?php if (!$nexdirectory_pro_addon_active) : ?>
                <p class="nexdirectory-upgrade-hero__note">
                    <?php esc_html_e('Pro is a separate add-on. Nothing on this page limits or disables the Free plugin.', 'nexdirectory'); ?>
                </p>
            <?php endif; ?>
        </div>
        <div class="nexdirectory-upgrade-status-card" aria-label="<?php esc_attr_e('Current plan status', 'nexdirectory'); ?>">
            <span class="nexdirectory-upgrade-status-card__eyebrow"><?php esc_html_e('Current plan', 'nexdirectory'); ?></span>
            <strong><?php echo esc_html($nexdirectory_plan_label); ?></strong>
            <span class="nexdirectory-upgrade-status-card__line">
                <span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
                <?php esc_html_e('Unlimited listings and events', 'nexdirectory'); ?>
            </span>
            <span class="nexdirectory-upgrade-status-card__line">
                <span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
                <?php esc_html_e('Core data remains yours', 'nexdirectory'); ?>
            </span>
            <span class="nexdirectory-upgrade-status-card__line">
                <span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
                <?php esc_html_e('Upgrade only when it adds value', 'nexdirectory'); ?>
            </span>
        </div>
    </section>

    <section class="nexdirectory-upgrade-value-grid" aria-label="<?php esc_attr_e('Reasons to consider Pro', 'nexdirectory'); ?>">
        <article>
            <span class="dashicons dashicons-clock" aria-hidden="true"></span>
            <div>
                <h2><?php esc_html_e('Save operational time', 'nexdirectory'); ?></h2>
                <p><?php esc_html_e('Automate reminders, attention digests, indexing, and repeatable setup work.', 'nexdirectory'); ?></p>
            </div>
        </article>
        <article>
            <span class="dashicons dashicons-chart-line" aria-hidden="true"></span>
            <div>
                <h2><?php esc_html_e('Build commercial workflows', 'nexdirectory'); ?></h2>
                <p><?php esc_html_e('Add paid tickets, boost packages, payment providers, QR check-in, and deeper reporting.', 'nexdirectory'); ?></p>
            </div>
        </article>
        <article>
            <span class="dashicons dashicons-smartphone" aria-hidden="true"></span>
            <div>
                <h2><?php esc_html_e('Create richer experiences', 'nexdirectory'); ?></h2>
                <p><?php esc_html_e('Offer an AI assistant, private calendars, advanced teams, and an installable Event Web App.', 'nexdirectory'); ?></p>
            </div>
        </article>
    </section>

    <section class="nexdirectory-admin-panel nexdirectory-comparison-panel">
        <div class="nexdirectory-comparison-heading">
            <div>
                <span class="nexdirectory-comparison-eyebrow"><?php esc_html_e('Feature comparison', 'nexdirectory'); ?></span>
                <h2><?php esc_html_e('Choose the version that fits the work you do today.', 'nexdirectory'); ?></h2>
                <p><?php esc_html_e('Free remains a complete directory foundation. Pro extends it through the separate existing NexDirectory Pro add-on.', 'nexdirectory'); ?></p>
            </div>
            <span class="nexdirectory-comparison-current"><?php echo esc_html($nexdirectory_plan_label); ?></span>
        </div>

        <div class="nexdirectory-comparison-table-wrap" tabindex="0" aria-label="<?php esc_attr_e('Scrollable Free and Pro feature comparison', 'nexdirectory'); ?>">
            <table class="widefat nexdirectory-comparison-table">
                <caption class="screen-reader-text"><?php esc_html_e('Nex Directory Free and NexDirectory Pro feature comparison', 'nexdirectory'); ?></caption>
                <thead>
                    <tr>
                        <th scope="col"><?php esc_html_e('Capability', 'nexdirectory'); ?></th>
                        <th scope="col">
                            <span class="nexdirectory-comparison-plan-name"><?php esc_html_e('Nex Directory Free', 'nexdirectory'); ?></span>
                            <span><?php esc_html_e('Unlimited core', 'nexdirectory'); ?></span>
                        </th>
                        <th scope="col">
                            <span class="nexdirectory-comparison-plan-name"><?php esc_html_e('NexDirectory Pro', 'nexdirectory'); ?></span>
                            <span><?php esc_html_e('Separate add-on', 'nexdirectory'); ?></span>
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($nexdirectory_comparison_catalog as $nexdirectory_group) : ?>
                        <?php
                        $nexdirectory_group_key = sanitize_key((string) ($nexdirectory_group['key'] ?? 'features'));
                        $nexdirectory_group_label = (string) ($nexdirectory_group['label'] ?? '');
                        $nexdirectory_group_description = (string) ($nexdirectory_group['description'] ?? '');
                        $nexdirectory_features = isset($nexdirectory_group['features']) && is_array($nexdirectory_group['features']) ? $nexdirectory_group['features'] : [];
                        ?>
                        <tr class="nexdirectory-comparison-group" id="nexdirectory-compare-<?php echo esc_attr($nexdirectory_group_key); ?>">
                            <th colspan="3" scope="rowgroup">
                                <strong><?php echo esc_html($nexdirectory_group_label); ?></strong>
                                <span><?php echo esc_html($nexdirectory_group_description); ?></span>
                            </th>
                        </tr>
                        <?php foreach ($nexdirectory_features as $nexdirectory_feature) : ?>
                            <?php
                            $nexdirectory_feature_key = sanitize_key((string) ($nexdirectory_feature['key'] ?? 'feature'));
                            $nexdirectory_free_included = !empty($nexdirectory_feature['free_included']);
                            $nexdirectory_free_status = $nexdirectory_free_included
                                ? __('Included in Free', 'nexdirectory')
                                : sanitize_text_field((string) ($nexdirectory_feature['free_status'] ?? __('Pro enhancement', 'nexdirectory')));
                            ?>
                            <tr class="nexdirectory-comparison-feature" id="nexdirectory-compare-<?php echo esc_attr($nexdirectory_feature_key); ?>">
                                <th scope="row">
                                    <span><?php echo esc_html((string) ($nexdirectory_feature['label'] ?? '')); ?></span>
                                </th>
                                <td data-label="<?php esc_attr_e('Nex Directory Free', 'nexdirectory'); ?>">
                                    <span class="nexdirectory-comparison-status <?php echo $nexdirectory_free_included ? 'is-included' : 'is-core'; ?>">
                                        <span class="dashicons <?php echo $nexdirectory_free_included ? 'dashicons-yes-alt' : 'dashicons-marker'; ?>" aria-hidden="true"></span>
                                        <?php echo esc_html($nexdirectory_free_status); ?>
                                    </span>
                                    <p><?php echo esc_html((string) ($nexdirectory_feature['free'] ?? '')); ?></p>
                                </td>
                                <td data-label="<?php esc_attr_e('NexDirectory Pro', 'nexdirectory'); ?>">
                                    <span class="nexdirectory-comparison-status is-pro">
                                        <span class="dashicons dashicons-star-filled" aria-hidden="true"></span>
                                        <?php esc_html_e('Available with Pro', 'nexdirectory'); ?>
                                    </span>
                                    <p><?php echo esc_html((string) ($nexdirectory_feature['pro'] ?? '')); ?></p>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    </section>

    <section class="nexdirectory-admin-panel nexdirectory-upgrade-fit-panel">
        <div>
            <span class="nexdirectory-comparison-eyebrow"><?php esc_html_e('A useful rule of thumb', 'nexdirectory'); ?></span>
            <h2><?php esc_html_e('Free is enough until you need leverage.', 'nexdirectory'); ?></h2>
            <p><?php esc_html_e('Consider Pro when manual operations are taking time, listings need to generate revenue, organizers need deeper collaboration, or attendees need an app-style experience.', 'nexdirectory'); ?></p>
        </div>
        <ul>
            <li><span class="dashicons dashicons-yes" aria-hidden="true"></span><?php esc_html_e('You send repeated reminders or operational digests.', 'nexdirectory'); ?></li>
            <li><span class="dashicons dashicons-yes" aria-hidden="true"></span><?php esc_html_e('You want to sell tickets or premium listing visibility.', 'nexdirectory'); ?></li>
            <li><span class="dashicons dashicons-yes" aria-hidden="true"></span><?php esc_html_e('You need advanced teams, private feeds, or richer reporting.', 'nexdirectory'); ?></li>
            <li><span class="dashicons dashicons-yes" aria-hidden="true"></span><?php esc_html_e('You want AI discovery or a dedicated Event Web App.', 'nexdirectory'); ?></li>
        </ul>
    </section>

    <?php if (!$nexdirectory_pro_addon_active) : ?>
        <section class="nexdirectory-upgrade-final-cta">
            <div>
                <span class="nexdirectory-comparison-eyebrow"><?php esc_html_e('Ready when you are', 'nexdirectory'); ?></span>
                <h2><?php esc_html_e('Add Pro without changing your Free content.', 'nexdirectory'); ?></h2>
                <p><?php esc_html_e('The existing Pro add-on extends the same listings, users, settings, and workflows. Free continues to operate if Pro is later paused.', 'nexdirectory'); ?></p>
            </div>
            <a class="button button-primary" href="<?php echo esc_url($nexdirectory_upgrade_url); ?>" target="_blank" rel="noopener noreferrer external">
                <?php esc_html_e('View Pro plans', 'nexdirectory'); ?>
                <span class="dashicons dashicons-arrow-right-alt" aria-hidden="true"></span>
            </a>
        </section>
    <?php endif; ?>
</div>
