<?php
namespace Tiamr\Admin;

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

final class More_Plugins_Page {
    public function render(): void {
        if (!current_user_can('edit_theme_options')) {
            return;
        }

        $plugins = $this->get_plugins();
        ?>
        <div class="amr-more-plugins-page">
            <section class="amr-more-plugins-hero">
                <div>
                    <span class="amr-more-plugins-kicker"><?php esc_html_e('More Plugins', 'titanium-advanced-menu-rules'); ?></span>
                    <h2><?php esc_html_e('Free WordPress tools from AdminPlugins.', 'titanium-advanced-menu-rules'); ?></h2>
                    <p><?php esc_html_e('Build a cleaner WordPress admin setup with focused tools for roles, permissions, menus, navigation and content access. Each plugin is designed to solve one admin problem properly instead of adding another heavy all-in-one suite.', 'titanium-advanced-menu-rules'); ?></p>
                </div>
                <div class="amr-more-plugins-hero-badge" aria-hidden="true">
                    <span class="dashicons dashicons-admin-plugins"></span>
                    <strong><?php esc_html_e('AdminPlugins', 'titanium-advanced-menu-rules'); ?></strong>
                </div>
            </section>

            <div class="amr-more-plugins-grid">
                <?php foreach ($plugins as $plugin) : ?>
                    <?php $this->render_plugin_card($plugin); ?>
                <?php endforeach; ?>
            </div>
        </div>
        <?php
    }

    private function get_plugins(): array {
        return [
            [
                'category'    => __('Roles, permissions & access control', 'titanium-advanced-menu-rules'),
                'title'       => __('Titanium User Role Manager, Capabilities & Access Control', 'titanium-advanced-menu-rules'),
                'description' => __('A complete role and capability manager for WordPress. Create, clone, rename and compare roles, edit capabilities visually, allow multiple roles per user, control admin toolbar and dashboard access, hide admin menu items by role, block direct access to hidden admin pages, and manage frontend content visibility with role/login rules and shortcodes.', 'titanium-advanced-menu-rules'),
                'image'       => TIAMR_PLUGIN_URL . 'assets/more-plugins/advanced-user-roles.webp',
                'url'         => 'https://wordpress.org/plugins/titanium-advanced-user-roles/',
                'highlights'  => [
                    __('Clean dashboard for roles, users, capabilities, access rules and settings.', 'titanium-advanced-menu-rules'),
                    __('Useful for membership sites, client portals, editorial teams and custom workflows.', 'titanium-advanced-menu-rules'),
                ],
                'badges'      => [
                    __('Visual capability editor', 'titanium-advanced-menu-rules'),
                    __('Create, clone & compare roles', 'titanium-advanced-menu-rules'),
                    __('Multiple roles per user', 'titanium-advanced-menu-rules'),
                    __('Admin menu restrictions', 'titanium-advanced-menu-rules'),
                    __('Frontend content control', 'titanium-advanced-menu-rules'),
                ],
            ],
        ];
    }

    private function render_plugin_card(array $plugin): void {
        $highlights = isset($plugin['highlights']) && is_array($plugin['highlights']) ? $plugin['highlights'] : [];
        $badges     = isset($plugin['badges']) && is_array($plugin['badges']) ? $plugin['badges'] : [];
        ?>
        <article class="amr-more-plugin-card">
            <div class="amr-more-plugin-visual" aria-hidden="true">
                <span class="amr-more-plugin-glow amr-more-plugin-glow-one"></span>
                <span class="amr-more-plugin-glow amr-more-plugin-glow-two"></span>
                <?php if (!empty($plugin['image'])) : ?>
                    <img src="<?php echo esc_url((string) $plugin['image']); ?>" alt="" loading="lazy" decoding="async" />
                <?php endif; ?>
            </div>

            <div class="amr-more-plugin-content">
                <span class="amr-more-plugins-kicker"><?php echo esc_html((string) ($plugin['category'] ?? '')); ?></span>
                <h3><?php echo esc_html((string) ($plugin['title'] ?? '')); ?></h3>
                <p><?php echo esc_html((string) ($plugin['description'] ?? '')); ?></p>

                <?php if (!empty($highlights)) : ?>
                    <ul class="amr-more-plugin-highlights">
                        <?php foreach ($highlights as $highlight) : ?>
                            <li><?php echo esc_html((string) $highlight); ?></li>
                        <?php endforeach; ?>
                    </ul>
                <?php endif; ?>

                <?php if (!empty($badges)) : ?>
                    <div class="amr-more-plugin-badges" aria-label="<?php esc_attr_e('Plugin highlights', 'titanium-advanced-menu-rules'); ?>">
                        <?php foreach ($badges as $badge) : ?>
                            <span><?php echo esc_html((string) $badge); ?></span>
                        <?php endforeach; ?>
                    </div>
                <?php endif; ?>

                <div class="amr-more-plugin-actions">
                    <a class="button button-primary" href="<?php echo esc_url((string) ($plugin['url'] ?? '')); ?>" target="_blank" rel="noopener noreferrer">
                        <?php esc_html_e('View on WordPress.org', 'titanium-advanced-menu-rules'); ?>
                    </a>
                </div>
            </div>
        </article>
        <?php
    }
}
