<?php
/**
 * Documentation template.
 *
 * @package DoliTrainingManagement
 */

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

$doli_training_management_settings_url = admin_url('admin.php?page=doli-training-management');
?>

<div class="wrap">
    <h1><?php echo esc_html__('Doli Training Management — Documentation', 'doli-training-management'); ?></h1>

    <div class="doli-training-management-doc">
        <h2><?php esc_html_e('Overview', 'doli-training-management'); ?></h2>
        <p>
            <?php esc_html_e('This plugin embeds the Training Management module from Dolibarr into WordPress so visitors can browse trainings and interact with your catalog from the front end.', 'doli-training-management'); ?>
        </p>

        <h2><?php esc_html_e('Requirements', 'doli-training-management'); ?></h2>
        <div class="notice notice-info inline">
            <p>
                <strong><?php esc_html_e('Important:', 'doli-training-management'); ?></strong>
                <?php esc_html_e('You need a Dolibarr instance with the training management features you use in production, and a valid API key.', 'doli-training-management'); ?>
            </p>
        </div>
        <ul>
            <li><?php esc_html_e('A reachable Dolibarr base URL (HTTPS recommended).', 'doli-training-management'); ?></li>
            <li><?php esc_html_e('An API key with permissions suitable for the Training Management API endpoints you call.', 'doli-training-management'); ?></li>
            <li><?php esc_html_e('The Angular application build deployed under assets/doli-training-management/ (see project build instructions).', 'doli-training-management'); ?></li>
        </ul>

        <h2><?php esc_html_e('TrainingManagement account & API key', 'doli-training-management'); ?></h2>
        <ol>
            <li>
                <?php
                $doli_training_management_signup_url = 'https://aplose.ma-gestion-cloud.fr/custom/sellyoursaas/myaccount/register.php?origin=wordpress&plan=MGC0007&country=FR';
                ?>
                <?php esc_html_e('Create your TrainingManagement account (30-day free trial).', 'doli-training-management'); ?>
                <br />
                <a href="<?php echo esc_url($doli_training_management_signup_url); ?>" target="_blank" rel="noopener noreferrer">
                    <?php esc_html_e('Signup link', 'doli-training-management'); ?>
                </a>
            </li>
            <li>
                <?php esc_html_e('In your Dolibarr instance with the TrainingManagement module enabled, locate the dedicated Dolibarr user named `training-management` (already provided/used by TrainingManagement).', 'doli-training-management'); ?>
            </li>
            <li>
                <?php esc_html_e('Generate an API/Web key for the `training-management` user in Dolibarr (Administration → Setup → Security → API keys / Web keys, or Administration → Tools → API depending on your instance).', 'doli-training-management'); ?>
            </li>
            <li>
                <?php esc_html_e('Copy the API key into the WordPress setup screen, then save.', 'doli-training-management'); ?>
            </li>
        </ol>

        <h2><?php esc_html_e('Configuration', 'doli-training-management'); ?></h2>
        <ol>
            <li>
                <a href="<?php echo esc_url($doli_training_management_settings_url); ?>"><?php esc_html_e('Open Settings', 'doli-training-management'); ?></a>
                <?php esc_html_e('in the Doli Training menu.', 'doli-training-management'); ?>
            </li>
            <li><?php esc_html_e('Enter your Dolibarr URL and API key, then save.', 'doli-training-management'); ?></li>
            <li><?php esc_html_e('Add the shortcode to a page or post where you want the training UI to appear.', 'doli-training-management'); ?></li>
        </ol>

        <h2><?php esc_html_e('Shortcode', 'doli-training-management'); ?></h2>
        <p><?php esc_html_e('Use the following shortcode to render the training management widget:', 'doli-training-management'); ?></p>
        <pre><code>[doli-training-management]</code></pre>
        <p class="description">
            <?php esc_html_e('No attributes are required. The widget reads Dolibarr URL and API key from the plugin settings.', 'doli-training-management'); ?>
        </p>

        <h2><?php esc_html_e('Front-end behaviour', 'doli-training-management'); ?></h2>
        <p>
            <?php esc_html_e('If URL or API key is missing, visitors see a notice with a link to the settings screen (administrators only see actionable links depending on context).', 'doli-training-management'); ?>
        </p>

        <h2><?php esc_html_e('Troubleshooting', 'doli-training-management'); ?></h2>
        <ul>
            <li><?php esc_html_e('Blank area: open the browser developer console and verify that main.js and polyfills.js load without 404 errors.', 'doli-training-management'); ?></li>
            <li><?php esc_html_e('API errors: confirm the API key, user rights in Dolibarr, and CORS/network access from the browser to your Dolibarr host.', 'doli-training-management'); ?></li>
            <li><?php esc_html_e('Custom element not defined: rebuild the Angular app and ensure files are under assets/doli-training-management/browser/.', 'doli-training-management'); ?></li>
        </ul>
    </div>
</div>
