<?php

namespace Macymed\MacymedLinkTracker\Admin;

if (! defined('ABSPATH')) {
    exit; // Sécurité
}
class Hooks
{
    public static function init()
    {
        add_action('macymed_link_tracker_pro_list_url_render_actions', [Hooks::class, 'proMessage'], 10, 2);
        add_action('macymed_link_tracker_pro_list_referer_render_actions', [Hooks::class, 'proMessage'], 10, 2);
        add_action('macymed_link_tracker_pro_list_history_render_actions', [Hooks::class, 'proMessage'], 10, 2);
        add_action('macymed_link_tracker_stats_report_tab_pro_before', [Hooks::class, 'proMessage'], 10, 2);
        add_action('macymed_link_tracker_stats_report_tab_pro_after', [Hooks::class, 'proMessage'], 10, 2);
        add_action('macymed_link_tracker_pro_details_url_graph_network', [Hooks::class, 'proMessage'], 10, 2);

        self::addActionSettings();
    }
    public static function addActionSettings()
    {
        add_action('macymed_link_tracker_list_type_tracking_message', [Hooks::class, 'proMessage'], 10, 2);
        add_action('macymed_link_tracker_list_personal_data_message', [Hooks::class, 'proMessage'], 10, 2);
        add_action('macymed_link_tracker_list_personal_data_message_rgpd', [Hooks::class, 'rgpdMessage'], 10);
        //
        add_action('macymed_tracker_tracking_use_external_redirect_page_message', [Hooks::class, 'proMessage'], 10, 2);
    }
    public static function rgpdMessage($message)
    {
        if (is_callable($message)) {
            // Si c'est un callable, on l'exécute et on utilise son résultat
            $message = call_user_func($message);
        } else {
            ?>
            <div class="macymed_link_tracker-pro-message">

                <h3 class="macymed_link_tracker-pro-message-text dashicons-before dashicons-editor-help">
                    <?php
                                echo wp_kses(
                                    sprintf(
                                        /* translators: %s: URL vers la réglementation RGPD */
                                        __('Veuillez consulter la <a href="%s" target="_blank">réglementation RGPD</a> avant d\'utiliser ces options', 'macymed-link-tracker'),
                                        "https://www.economie.gouv.fr/entreprises/reglement-general-protection-donnees-rgpd"
                                    ),
                                    [
                                                                                                                                            'a' => [
                                                                                                                                                'href'         => [],
                                                                                                                                                'target'        => [],
                                                                                                                                                'class'        => [],

                                                                                                                                            ],
                                                                                                                                        ]
                                );

            ?>

                </h3>
            </div>
        <?php
        }
    }
    public static function helpMessage($message )
    {
        if (is_callable($message)) {
            // Si c'est un callable, on l'exécute et on utilise son résultat
            $message = call_user_func($message);
        } else {
            ?>
            <div class="macymed_link_tracker-pro-message">

                <h3 class="macymed_link_tracker-pro-message-text dashicons-before dashicons-editor-help">
                    <?php
                        echo esc_html($message);
            ?>


                </h3>
            </div>
        <?php
        }
    }
    public static function proMessage($message, $helpUrl = null)
    {
        if($helpUrl == null) {
            $helpUrl = 'https://extensions.macymed.fr/documentation/';
        }
        else {
            $helpUrl = 'https://extensions.macymed.fr/docs/' . esc_html($helpUrl);
        }
        if (is_callable($message)) {
            // Si c'est un callable, on l'exécute et on utilise son résultat
            $message = call_user_func($message);
        } else {
            ?>
            <div class="macymed_link_tracker-pro-message">

                <h3 class="macymed_link_tracker-pro-message-text dashicons-before dashicons-star-filled">
                    <?php
                        echo wp_kses(
                            sprintf(
                                /* translators: 1: URL vers la documentation, 2: message spécial, 3: URL vers la version Pro */
                                __('Bénéficiez de <a href="%1$s" target="_blank">"%2$s"</a> avec la <a href="%3$s" target="_blank">version Pro</a>', 'macymed-link-tracker'),
                                $helpUrl,
                                esc_html($message),
                                "https://extensions.macymed.fr"
                            ),
                            [
                                                                                            'a' => [
                                                                                                'href'         => [],
                                                                                                'target'        => [],
                                                                                                'class'        => [],

                                                                                            ],
                                                                                        ]
                        );



            ?>

                </h3>
            </div>
<?php
        }
    }
}
