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

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 = __('Pro is active', 'nexdirectory');
    $nexdirectory_hero_description = __('Your Pro add-on is connected. This page shows what is included today and what Pro adds on top.', 'nexdirectory');
} elseif ($nexdirectory_pro_addon_active) {
    $nexdirectory_plan_label = __('Finish Pro setup', 'nexdirectory');
    $nexdirectory_hero_kicker = __('Complete your setup', 'nexdirectory');
    $nexdirectory_hero_title = __('Pro is installed but not active yet', 'nexdirectory');
    $nexdirectory_hero_description = __('Connect your Pro license or trial to turn on the extra tools. You can still keep publishing listings without it.', 'nexdirectory');
} else {
    $nexdirectory_plan_label = __('Included plan', 'nexdirectory');
    $nexdirectory_hero_kicker = __('Upgrade when you need more', 'nexdirectory');
    $nexdirectory_hero_title = __('Start with the essentials. Add Pro when it saves time.', 'nexdirectory');
    $nexdirectory_hero_description = __('Nex Directory already lets you publish unlimited listings and events. Pro adds automation, paid workflows, AI tools, deeper 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 optional. This page does not limit the features already included with Nex Directory.', '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('Your listings stay on your site', '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 admin time', 'nexdirectory'); ?></h2>
                <p><?php esc_html_e('Send reminders, surface items that need review, and automate repeat tasks.', 'nexdirectory'); ?></p>
            </div>
        </article>
        <article>
            <span class="dashicons dashicons-chart-line" aria-hidden="true"></span>
            <div>
                <h2><?php esc_html_e('Sell and promote listings', 'nexdirectory'); ?></h2>
                <p><?php esc_html_e('Add ticket sales, paid boosts, payment providers, check-in tools, and stronger reports.', 'nexdirectory'); ?></p>
            </div>
        </article>
        <article>
            <span class="dashicons dashicons-smartphone" aria-hidden="true"></span>
            <div>
                <h2><?php esc_html_e('Give users more to work with', 'nexdirectory'); ?></h2>
                <p><?php esc_html_e('Add an AI assistant, private calendars, team tools, and an installable event 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('Nex Directory covers the everyday directory tools. Pro is a separate add-on for teams that need automation, payments, AI, or deeper reporting.', '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 and 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', 'nexdirectory'); ?></span>
                            <span><?php esc_html_e('Unlimited listings', 'nexdirectory'); ?></span>
                        </th>
                        <th scope="col">
                            <span class="nexdirectory-comparison-plan-name"><?php esc_html_e('Nex Directory 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', 'nexdirectory')
                                : sanitize_text_field((string) ($nexdirectory_feature['free_status'] ?? __('Pro add-on', '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', '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('Nex Directory Pro', 'nexdirectory'); ?>">
                                    <span class="nexdirectory-comparison-status is-pro">
                                        <span class="dashicons dashicons-star-filled" aria-hidden="true"></span>
                                        <?php esc_html_e('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('When Pro makes sense', 'nexdirectory'); ?></span>
            <h2><?php esc_html_e('Stay with Nex Directory until Pro clearly saves time or opens revenue.', 'nexdirectory'); ?></h2>
            <p><?php esc_html_e('Consider Pro when manual admin is taking too much time, listings need to earn 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 review summaries.', '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 rebuilding your directory.', 'nexdirectory'); ?></h2>
                <p><?php esc_html_e('Pro builds on the same listings, users, settings, and workflows. If Pro is paused later, your included Nex Directory features keep working.', '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>
