<?php

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

class Clielo_FedaPay {

    const API_BASE_LIVE    = 'https://api.fedapay.com/v1';
    const API_BASE_SANDBOX = 'https://sandbox-api.fedapay.com/v1';

    /* ─── Helpers ──────────────────────────────────────────────── */

    private static function api_base(): string {
        $s = self::get_settings();
        return ( $s['mode'] ?? 'sandbox' ) === 'live' ? self::API_BASE_LIVE : self::API_BASE_SANDBOX;
    }

    private static function secret_key(): string {
        $s = self::get_settings();
        return ( $s['mode'] ?? 'sandbox' ) === 'live'
            ? ( $s['live_secret_key'] ?? '' )
            : ( $s['sandbox_secret_key'] ?? '' );
    }

    private static function auth_headers(): array {
        return [
            'Authorization' => 'Bearer ' . self::secret_key(),
            'Content-Type'  => 'application/json',
        ];
    }

    public static function get_webhook_url(): string {
        return admin_url( 'admin-ajax.php?action=clielo_fedapay_webhook' );
    }

    /* ─── Settings ─────────────────────────────────────────────── */

    public static function get_settings(): array {
        $defaults = [
            'enabled'            => '0',
            'mode'               => 'sandbox',
            'live_secret_key'    => '',
            'sandbox_secret_key' => '',
        ];
        return wp_parse_args( get_option( 'clielo_fedapay_settings', [] ), $defaults );
    }

    public static function is_enabled(): bool {
        if ( ! clielo_is_premium() ) {
            return false;
        }
        $s = self::get_settings();
        return $s['enabled'] === '1' && ! empty( self::secret_key() );
    }

    public static function register_settings(): void {
        register_setting( 'clielo_fedapay_settings_group', 'clielo_fedapay_settings', [
            'sanitize_callback' => [ __CLASS__, 'sanitize_settings' ],
        ] );
    }

    public static function sanitize_settings( $input ): array {
        $clean                       = [];
        $clean['enabled']            = ! empty( $input['enabled'] ) ? '1' : '0';
        $clean['mode']               = in_array( $input['mode'] ?? '', [ 'sandbox', 'live' ], true ) ? $input['mode'] : 'sandbox';
        $clean['live_secret_key']    = sanitize_text_field( $input['live_secret_key'] ?? '' );
        $clean['sandbox_secret_key'] = sanitize_text_field( $input['sandbox_secret_key'] ?? '' );
        return $clean;
    }

    /* ─── Init ──────────────────────────────────────────────────── */

    public static function init(): void {
        add_action( 'wp_ajax_nopriv_clielo_fedapay_webhook', [ __CLASS__, 'handle_webhook_ajax' ] );
        add_action( 'wp_ajax_clielo_fedapay_webhook',        [ __CLASS__, 'handle_webhook_ajax' ] );

        if ( ! clielo_is_premium() ) {
            return;
        }

        add_action( 'admin_init', [ __CLASS__, 'register_settings' ] );

        if ( self::is_enabled() ) {
            add_action( 'wp_ajax_clielo_fedapay_checkout', [ __CLASS__, 'ajax_create_checkout' ] );
            add_action( 'template_redirect', [ __CLASS__, 'handle_return_redirect' ] );
        }
    }

    /* ─── Checkout AJAX ────────────────────────────────────────── */

    public static function ajax_create_checkout(): void {
        check_ajax_referer( 'clielo_nonce', 'nonce' );

        if ( ! is_user_logged_in() ) {
            wp_send_json_error( [ 'message' => __( 'Vous devez être connecté.', 'clielo' ) ], 403 );
        }

        $client_id = get_current_user_id();
        $post_id   = absint( $_POST['post_id'] ?? 0 );

        if ( ! $post_id ) {
            wp_send_json_error( [ 'message' => __( 'Service introuvable.', 'clielo' ) ], 400 );
        }

        $selected_pack_idx = absint( $_POST['selected_pack'] ?? 0 );
        $selected_indices  = json_decode( sanitize_text_field( wp_unslash( $_POST['selected_indices'] ?? '[]' ) ), true ) ?: [];
        $adv_raw           = json_decode( sanitize_text_field( wp_unslash( $_POST['advanced_options_data'] ?? '[]' ) ), true ) ?: [];

        $packs   = Clielo_Options::get_packs( $post_id );
        $options = Clielo_Options::get_options( $post_id );

        if ( empty( $packs ) || ! isset( $packs[ $selected_pack_idx ] ) ) {
            wp_send_json_error( [ 'message' => __( 'Pack introuvable.', 'clielo' ) ], 400 );
        }

        $base_offer = $packs[ $selected_pack_idx ];
        $selected   = [];
        foreach ( $selected_indices as $idx ) {
            if ( isset( $options[ $idx ] ) ) {
                $selected[] = $options[ $idx ];
            }
        }

        // Options avancées
        $extra_pages = 0; $extra_page_price = 0.0;
        $maintenance_price = 0.0; $express_days = 0; $express_price = 0.0;
        if ( is_array( $adv_raw ) ) {
            foreach ( $adv_raw as $asel ) {
                $ai    = absint( $asel['index'] ?? -1 );
                $qty   = absint( $asel['qty'] ?? 0 );
                $mode  = sanitize_text_field( $asel['mode'] ?? '' );
                $price = floatval( $asel['price'] ?? 0 );
                if ( $mode === 'daily' ) {
                    $express_days  += $qty;
                    $express_price  = $price;
                } elseif ( $mode === 'unit' ) {
                    $extra_pages      += $qty;
                    $extra_page_price  = $price;
                } elseif ( $mode === 'monthly' ) {
                    $maintenance_price = $price;
                }
            }
        }

        $tax_rate       = floatval( Clielo_Invoices::get_settings()['tax_rate'] ?? 0 );
        $payment_mode   = Clielo_Options::get_payment_mode( $post_id );
        $installments_n = Clielo_Options::get_installments_count( $post_id );
        $currency       = Clielo_Admin::get_currency();

        $single_ttc = Clielo_Payments::compute_total_ttc(
            $base_offer, $selected, $extra_pages, $extra_page_price,
            $maintenance_price, $express_days, $express_price, $tax_rate
        );

        if ( $payment_mode === 'monthly' ) {
            $upfront_ttc = Clielo_Payments::get_monthly_fee( $single_ttc, $installments_n );
        } else {
            $upfront_ttc = Clielo_Payments::get_upfront_amount( $single_ttc, $payment_mode );
        }

        // XOF/XAF/GNF/CDF : entiers. USD/EUR : centimes.
        $no_cents   = in_array( $currency, [ 'XOF', 'XAF', 'CDF', 'GNF' ], true );
        $amount_int = $no_cents ? (int) round( $upfront_ttc ) : (int) round( $upfront_ttc * 100 );

        $user         = get_userdata( $client_id );
        $service_page = get_permalink( $post_id );
        $return_url   = add_query_arg( [ 'fedapay_return' => '1', 'post_id' => $post_id ], $service_page );

        /* ── Étape 1 : créer la transaction ── */
        $first_name = sanitize_text_field( $user->first_name ?: $user->display_name );
        $raw_last   = sanitize_text_field( $user->last_name );
        $last_name  = strlen( $raw_last ) >= 2 ? $raw_last : ( strlen( $user->display_name ) >= 2 ? $user->display_name : '--' );

        $txn_body = wp_json_encode( [
            'description'  => sprintf( /* translators: %s: service title */ __( 'Commande — %s', 'clielo' ), get_the_title( $post_id ) ),
            'amount'       => $amount_int,
            'currency'     => [ 'iso' => $currency ],
            'callback_url' => $return_url,
            'customer'     => [
                'firstname' => $first_name,
                'lastname'  => $last_name,
                'email'     => sanitize_email( $user->user_email ),
            ],
        ] );

        $txn_response = wp_remote_post( self::api_base() . '/transactions', [
            'headers'     => self::auth_headers(),
            'body'        => $txn_body,
            'timeout'     => 30,
            'data_format' => 'body',
        ] );

        if ( is_wp_error( $txn_response ) ) {
            wp_send_json_error( [ 'message' => $txn_response->get_error_message() ], 500 );
        }

        $txn_data = json_decode( wp_remote_retrieve_body( $txn_response ), true );
        $txn_id   = $txn_data['v1/transaction']['id'] ?? null;

        if ( ! $txn_id ) {
            $err = $txn_data['errors'][0]['message'] ?? ( $txn_data['message'] ?? wp_json_encode( $txn_data ) );
            wp_send_json_error( [ 'message' => 'FedaPay: ' . $err ], 500 );
        }

        /* ── Étape 2 : obtenir le token / URL de paiement ── */
        $token_response = wp_remote_post( self::api_base() . '/transactions/' . absint( $txn_id ) . '/token', [
            'headers'     => self::auth_headers(),
            'body'        => '{}',
            'timeout'     => 30,
            'data_format' => 'body',
        ] );

        if ( is_wp_error( $token_response ) ) {
            wp_send_json_error( [ 'message' => $token_response->get_error_message() ], 500 );
        }

        $token_data  = json_decode( wp_remote_retrieve_body( $token_response ), true );
        $payment_url = $token_data['url'] ?? '';

        if ( ! $payment_url ) {
            wp_send_json_error( [ 'message' => __( 'URL de paiement FedaPay introuvable.', 'clielo' ) ], 500 );
        }

        // Stocker les métadonnées pour le retour client
        $token = $token_data['token'] ?? '';
        set_transient( 'clielo_fp_' . $txn_id, [
            'post_id'            => $post_id,
            'client_id'          => $client_id,
            'base_offer'         => $base_offer,
            'selected'           => $selected,
            'payment_mode'       => $payment_mode,
            'installments_count' => $installments_n,
            'full_total_ttc'     => $single_ttc,
            'upfront_ttc'        => $upfront_ttc,
            'extra_pages'        => $extra_pages,
            'extra_page_price'   => $extra_page_price,
            'maintenance_price'  => $maintenance_price,
            'express_days'       => $express_days,
            'express_price'      => $express_price,
            'currency'           => $currency,
        ], DAY_IN_SECONDS );

        wp_send_json_success( [ 'checkout_url' => $payment_url ] );
    }

    /* ─── Webhook FedaPay ──────────────────────────────────────── */

    public static function handle_webhook_ajax(): void {
        $raw  = file_get_contents( 'php://input' );
        $data = json_decode( $raw, true );

        $event_name = $data['name'] ?? '';
        $txn        = $data['data']['object'] ?? null;

        if ( $event_name !== 'transaction.approved' || ! $txn ) {
            status_header( 200 );
            exit;
        }

        $txn_id = absint( $txn['id'] ?? 0 );
        if ( $txn_id ) {
            self::process_completed_payment( $txn_id, $txn );
        }

        status_header( 200 );
        header( 'Content-Type: application/json' );
        echo wp_json_encode( [ 'status' => 'ok' ] );
        exit;
    }

    /* ─── Retour client ────────────────────────────────────────── */

    public static function handle_return_redirect(): void {
        if ( ! isset( $_GET['fedapay_return'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
            return;
        }

        $post_id = absint( $_GET['post_id'] ?? 0 ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
        $txn_id  = absint( $_GET['id'] ?? 0 );       // phpcs:ignore WordPress.Security.NonceVerification.Recommended

        if ( ! $txn_id || ! $post_id ) {
            return;
        }

        // Vérification côté API
        $response = wp_remote_get( self::api_base() . '/transactions/' . $txn_id, [
            'headers' => self::auth_headers(),
            'timeout' => 20,
        ] );

        if ( is_wp_error( $response ) ) {
            return;
        }

        $data   = json_decode( wp_remote_retrieve_body( $response ), true );
        $status = $data['v1/transaction']['status'] ?? '';

        if ( $status === 'approved' ) {
            self::process_completed_payment( $txn_id, $data['v1/transaction'] ?? [] );
        }
    }

    /* ─── Traitement paiement confirmé ────────────────────────── */

    private static function process_completed_payment( int $txn_id, array $txn_data = [] ): void {
        // Idempotence : vérifier si commande déjà créée pour cette transaction
        global $wpdb;
        $orders_table = $wpdb->prefix . 'clielo_orders';
        // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
        $existing = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$orders_table} WHERE stripe_session_id = %s LIMIT 1", 'fp_' . $txn_id ) );
        if ( $existing ) {
            return;
        }

        $meta = get_transient( 'clielo_fp_' . $txn_id );
        if ( ! $meta ) {
            // Fallback : on ne peut pas reconstruire la commande sans les métadonnées
            return;
        }

        $post_id            = absint( $meta['post_id'] );
        $client_id          = absint( $meta['client_id'] );
        $base_offer         = $meta['base_offer'];
        $selected           = $meta['selected'];
        $payment_mode       = $meta['payment_mode'];
        $installments_count = absint( $meta['installments_count'] );
        $full_total_ttc     = floatval( $meta['full_total_ttc'] );
        $extra_pages        = absint( $meta['extra_pages'] );
        $extra_page_price   = floatval( $meta['extra_page_price'] );
        $maintenance_price  = floatval( $meta['maintenance_price'] );
        $express_days       = absint( $meta['express_days'] );
        $express_price      = floatval( $meta['express_price'] );
        $tax_rate           = floatval( Clielo_Invoices::get_settings()['tax_rate'] ?? 0 );

        $order_id = Clielo_Orders::create_order_paid( [
            'post_id'            => $post_id,
            'client_id'          => $client_id,
            'base_offer'         => $base_offer,
            'selected_options'   => $selected,
            'payment_mode'       => $payment_mode,
            'installments_count' => $installments_count,
            'full_total_ttc'     => $full_total_ttc,
            'extra_pages'        => $extra_pages,
            'extra_page_price'   => $extra_page_price,
            'maintenance_price'  => $maintenance_price,
            'express_days'       => $express_days,
            'express_price'      => $express_price,
            'stripe_session_id'  => 'fp_' . $txn_id, // préfixe fp = FedaPay
        ] );

        if ( ! $order_id ) {
            return;
        }

        delete_transient( 'clielo_fp_' . $txn_id );

        // Message récap dans le chat
        $currency = $meta['currency'] ?? Clielo_Admin::get_currency();
        $lines    = [];
        $lines[]  = "\xF0\x9F\x93\x8B " . __( 'Ma sélection :', 'clielo' );
        $lines[]  = "\xF0\x9F\x93\xA6 " . ( $base_offer['name'] ?? 'Pack' ) . ' — ' . number_format( floatval( $base_offer['price'] ?? 0 ), 0, ',', ' ' ) . ' ' . $currency;
        foreach ( $selected as $opt ) {
            $lines[] = "\xE2\x9C\x85 " . ( $opt['name'] ?? 'Option' ) . ' — ' . number_format( floatval( $opt['price'] ?? 0 ), 0, ',', ' ' ) . ' ' . $currency;
        }
        $lines[] = "\xF0\x9F\x92\xB0 " . __( 'Total :', 'clielo' ) . ' ' . number_format( $full_total_ttc, 0, ',', ' ' ) . ' ' . $currency;
        if ( $payment_mode !== 'single' ) {
            $upfront = floatval( $meta['upfront_ttc'] ?? 0 );
            $lines[] = "\xF0\x9F\x92\xB3 " . __( 'Acompte payé via FedaPay :', 'clielo' ) . ' ' . number_format( $upfront, 0, ',', ' ' ) . ' ' . $currency;
        }
        $lines[] = "\xF0\x9F\x94\x97 " . __( 'Transaction FedaPay :', 'clielo' ) . ' #' . $txn_id;

        global $wpdb;
        $messages_table = $wpdb->prefix . 'clielo_messages';
        // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery
        $wpdb->insert( $messages_table, [
            'post_id'    => $post_id,
            'client_id'  => $client_id,
            'user_id'    => 0,
            'message'    => implode( "\n", $lines ),
            'created_at' => current_time( 'mysql' ),
        ] );

        // Échéancier si mode non-single
        if ( $payment_mode !== 'single' ) {
            Clielo_Payments::create_schedule_for_order( $order_id );
            Clielo_Invoices::create_partial_invoice( $order_id );
        }
    }

    /* ─── Settings UI (onglet dans page Paiements) ─────────────── */

    public static function render_tab_content(): void {
        $s     = self::get_settings();
        $color = esc_attr( Clielo_Admin::get_color() );
        $nonce = wp_create_nonce( 'clielo_fedapay_settings' );
        ?>
        <form method="post" action="options.php">
            <?php settings_fields( 'clielo_fedapay_settings_group' ); ?>

            <?php // ── Activation ── ?>
            <div style="background:#fff;border:1px solid #e0e0e0;border-radius:10px;padding:20px 24px;margin-bottom:20px">
                <h2 style="font-size:15px;margin:0 0 16px 0"><?php esc_html_e( 'Activation', 'clielo' ); ?></h2>
                <label style="display:flex;align-items:center;gap:10px;cursor:pointer">
                    <input type="checkbox" name="clielo_fedapay_settings[enabled]" value="1" <?php checked( $s['enabled'], '1' ); ?> style="width:18px;height:18px" />
                    <span><?php esc_html_e( 'Activer FedaPay Checkout', 'clielo' ); ?></span>
                </label>
            </div>

            <?php // ── Mode ── ?>
            <div style="background:#fff;border:1px solid #e0e0e0;border-radius:10px;padding:20px 24px;margin-bottom:20px">
                <h2 style="font-size:15px;margin:0 0 16px 0"><?php esc_html_e( 'Environnement', 'clielo' ); ?></h2>
                <div style="display:flex;gap:12px">
                    <label style="display:flex;align-items:center;gap:8px;cursor:pointer;padding:10px 20px;border:2px solid <?php echo $s['mode'] === 'sandbox' ? esc_attr( $color ) : '#e0e0e0'; ?>;border-radius:8px">
                        <input type="radio" name="clielo_fedapay_settings[mode]" value="sandbox" <?php checked( $s['mode'], 'sandbox' ); ?> />
                        <?php esc_html_e( 'Sandbox (test)', 'clielo' ); ?>
                    </label>
                    <label style="display:flex;align-items:center;gap:8px;cursor:pointer;padding:10px 20px;border:2px solid <?php echo $s['mode'] === 'live' ? esc_attr( $color ) : '#e0e0e0'; ?>;border-radius:8px">
                        <input type="radio" name="clielo_fedapay_settings[mode]" value="live" <?php checked( $s['mode'], 'live' ); ?> />
                        <?php esc_html_e( 'Live (production)', 'clielo' ); ?>
                    </label>
                </div>
            </div>

            <?php // ── Clés API ── ?>
            <div style="background:#fff;border:1px solid #e0e0e0;border-radius:10px;padding:20px 24px;margin-bottom:20px">
                <h2 style="font-size:15px;margin:0 0 16px 0"><?php esc_html_e( 'Clés API', 'clielo' ); ?></h2>
                <p style="margin:0 0 16px;font-size:13px;color:#555">
                    <?php esc_html_e( 'Dashboard FedaPay → Paramètres → Clés d\'API.', 'clielo' ); ?>
                    <a href="https://dashboard.fedapay.com" target="_blank" rel="noopener">dashboard.fedapay.com</a>
                </p>

                <div style="margin-bottom:20px;padding-bottom:20px;border-bottom:1px solid #f0f0f0">
                    <h3 style="font-size:13px;color:#666;margin:0 0 12px"><?php esc_html_e( 'Sandbox (test)', 'clielo' ); ?></h3>
                    <div style="margin-bottom:12px">
                        <label style="display:block;font-size:13px;font-weight:600;margin-bottom:6px"><?php esc_html_e( 'Clé secrète Sandbox', 'clielo' ); ?></label>
                        <input type="password" name="clielo_fedapay_settings[sandbox_secret_key]" value="<?php echo esc_attr( $s['sandbox_secret_key'] ); ?>" placeholder="sk_sandbox_..." style="width:100%;max-width:480px;padding:8px 12px;border:1px solid #d0d5dd;border-radius:6px" />
                        <p style="margin:4px 0 0;font-size:12px;color:#777"><?php esc_html_e( 'Commence par sk_sandbox_', 'clielo' ); ?></p>
                    </div>
                </div>

                <div>
                    <h3 style="font-size:13px;color:#666;margin:0 0 12px"><?php esc_html_e( 'Production (live)', 'clielo' ); ?></h3>
                    <div>
                        <label style="display:block;font-size:13px;font-weight:600;margin-bottom:6px"><?php esc_html_e( 'Clé secrète Live', 'clielo' ); ?></label>
                        <input type="password" name="clielo_fedapay_settings[live_secret_key]" value="<?php echo esc_attr( $s['live_secret_key'] ); ?>" placeholder="sk_live_..." style="width:100%;max-width:480px;padding:8px 12px;border:1px solid #d0d5dd;border-radius:6px" />
                        <p style="margin:4px 0 0;font-size:12px;color:#777"><?php esc_html_e( 'Commence par sk_live_', 'clielo' ); ?></p>
                    </div>
                </div>
            </div>

            <?php // ── Devise ── ?>
            <?php
            $global_currency = Clielo_Admin::get_currency();
            $fp_supported    = [ 'XOF', 'XAF', 'USD', 'EUR', 'GNF', 'CDF' ];
            $fp_ok           = in_array( $global_currency, $fp_supported, true );
            ?>
            <div style="background:<?php echo $fp_ok ? '#f0f4ff' : '#fff8e1'; ?>;border:1px solid <?php echo $fp_ok ? '#c7d7fa' : '#f59e0b'; ?>;border-radius:10px;padding:16px 24px;margin-bottom:20px">
                <p style="margin:0;font-size:13px;color:#374151">
                    <strong><?php esc_html_e( 'Devise :', 'clielo' ); ?></strong>
                    <?php echo esc_html( $global_currency ); ?>
                    <?php if ( $fp_ok ) : ?>
                        <span style="color:#16a34a">✓ <?php esc_html_e( 'Compatible FedaPay', 'clielo' ); ?></span>
                    <?php else : ?>
                        <span style="color:#b45309">⚠️ <?php esc_html_e( 'Non compatible. FedaPay accepte :', 'clielo' ); ?> <?php echo esc_html( implode( ', ', $fp_supported ) ); ?></span>
                    <?php endif; ?>
                    — <?php esc_html_e( 'Configurez dans', 'clielo' ); ?>
                    <a href="<?php echo esc_url( admin_url( 'admin.php?page=clielo-settings' ) ); ?>"><?php esc_html_e( 'Réglages → Devise', 'clielo' ); ?></a>.
                </p>
            </div>

            <?php // ── URL Webhook ── ?>
            <div style="background:#fff;border:1px solid #e0e0e0;border-radius:10px;padding:20px 24px;margin-bottom:20px">
                <h2 style="font-size:15px;margin:0 0 8px 0"><?php esc_html_e( 'URL Webhook', 'clielo' ); ?></h2>
                <p style="margin:0 0 12px;font-size:13px;color:#555"><?php esc_html_e( 'Copiez cette URL dans FedaPay → Webhooks (événement : transaction.approved).', 'clielo' ); ?></p>
                <div style="display:flex;gap:8px;align-items:center">
                    <input type="text" readonly value="<?php echo esc_url( self::get_webhook_url() ); ?>" style="width:100%;max-width:560px;padding:8px 12px;border:1px solid #d0d5dd;border-radius:6px;background:#f9f9f9;font-size:12px" />
                    <button type="button" onclick="navigator.clipboard.writeText('<?php echo esc_js( self::get_webhook_url() ); ?>');this.textContent='<?php esc_attr_e( 'Copié !', 'clielo' ); ?>';setTimeout(()=>{this.textContent='<?php esc_attr_e( 'Copier', 'clielo' ); ?>'},2000)" style="padding:8px 16px;border:1px solid #d0d5dd;border-radius:6px;background:#fff;cursor:pointer;font-size:13px;white-space:nowrap">
                        <?php esc_html_e( 'Copier', 'clielo' ); ?>
                    </button>
                </div>
            </div>

            <?php submit_button( __( 'Enregistrer', 'clielo' ) ); ?>
        </form>
        <?php
    }

    public static function render_settings_page(): void {
        $color = esc_attr( Clielo_Admin::get_color() );
        ?>
        <div class="wrap" style="max-width:750px">
            <h1 style="display:flex;align-items:center;gap:10px;margin-bottom:24px">
                <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="<?php echo esc_attr( $color ); ?>" stroke-width="2"><rect x="1" y="4" width="22" height="16" rx="2"/><line x1="1" y1="10" x2="23" y2="10"/></svg>
                <?php esc_html_e( 'Paiement FedaPay', 'clielo' ); ?>
            </h1>
            <?php self::render_tab_content(); ?>
        </div>
        <?php
    }
}
