<?php

// phpcs:disable WordPress.WP.I18n.TextDomainMismatch -- Bridge to pay4all-for-twint :
// this WooCommerce integration re-emits the TWINT gateway strings the free
// plugin already ships and translates. Reusing its text domain avoids
// duplicating dozens of msgids × 4 locales in pay4all-pro's .po files.

defined( 'ABSPATH' ) || exit;

add_filter( 'woocommerce_payment_methods_list_item', 'pay4all_for_twint_get_account_saved_payment_methods_list_item', 10, 2 );

// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Prefixed with plugin slug `pay4all-for-twint` ; Plugin Check does not auto-configure prefixes.
function pay4all_for_twint_get_account_saved_payment_methods_list_item( $item, $payment_token )
{
    if ( 't4a_twint' === strtolower( $payment_token->get_type() ) ) {
        $desc                        = $payment_token->get_description();
        /* translators: %1$s dynamic value(s). */
        $item[ 'method' ][ 'brand' ] = $desc ? sprintf( __( 'TWINT: %1$s', 'pay4all-for-twint' ), $desc ) : __( 'TWINT', 'pay4all-for-twint' );
        $item[ 'expires' ]           = $payment_token->get_expm() . '/' . $payment_token->get_expy();
    }

    return $item;
}
