<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }

class Falcify_Plugin {
    private static $instance = null;
    public static function instance() {
        if ( self::$instance === null ) self::$instance = new self();
        return self::$instance;
    }
    private function __construct() {
        // Translations are loaded automatically by WordPress.org since WP 4.6.
        Falcify_Settings::init();
        Falcify_Admin::init();
        Falcify_Api::init();
        Falcify_Metabox::init();
        Falcify_Renderer::init();
        Falcify_Updater::init();
        Falcify_Usage::init();
        Falcify_History::init();
        Falcify_Support::init();
        Falcify_List_Columns::init();
        add_action( 'admin_notices', array( __CLASS__, 'connection_notice' ) );
    }

    public static function connection_notice() {
        if ( ! current_user_can( 'manage_options' ) ) return;
        $api_key = trim( (string) Falcify_Settings::get_value( 'api_key' ) );
        if ( $api_key !== '' ) return;

        // phpcs:ignore WordPress.Security.NonceVerification.Recommended
        $current_page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : '';
        if ( $current_page === 'falcify-connector' ) return;

        $settings_url = admin_url( 'admin.php?page=falcify-connector' );
        $signup_url   = 'https://www.falcify.fr/';
        ?>
        <div class="notice notice-warning is-dismissible">
            <p>
                <strong><?php esc_html_e( 'Falcify n\'est pas connecté.', 'falcify-connector' ); ?></strong>
                <?php esc_html_e( 'Pour générer des versions FALC de vos contenus, vous devez configurer votre clé API.', 'falcify-connector' ); ?>
            </p>
            <p>
                <a href="<?php echo esc_url( $settings_url ); ?>" class="button button-primary"><?php esc_html_e( 'Configurer maintenant', 'falcify-connector' ); ?></a>
                <a href="<?php echo esc_url( $signup_url ); ?>" class="button button-secondary" target="_blank" rel="noopener"><?php esc_html_e( 'Créer un compte / Voir les abonnements', 'falcify-connector' ); ?></a>
            </p>
        </div>
        <?php
    }
}
