<?php
// +++ NEW FILE: includes/class-wc-bani-blocks.php +++
if ( ! defined( 'ABSPATH' ) ) { exit; }

use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;

class WC_Bani_Blocks_Integration extends AbstractPaymentMethodType {
    protected $name = 'bani'; // must match gateway id

    public function initialize() {
        // Register the frontend script that tells the Blocks checkout about this method
        $handle   = 'wc-bani-blocks';
        $src      = plugins_url( 'assets/js/blocks-bani.js', WC_BANI_MAIN_FILE );
        $deps     = array( 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-i18n' );
        $version  = defined('WC_BANI_VERSION') ? WC_BANI_VERSION : '1.0.0';

        wp_register_script( $handle, $src, $deps, $version, true );

        // Localize minimal data used by the blocks UI
        wp_set_script_translations( $handle, 'bani-payments-for-woocommerce' );

        $gateway = wc()->payment_gateways()->payment_gateways()['bani'] ?? null;
        $active  = $gateway && $gateway->is_available();

        wp_localize_script( $handle, 'baniBlocksData', array(
            'isActive'   => (bool) $active,
            'title'      => $gateway ? $gateway->get_title() : __( 'Bani', 'bani-payments-for-woocommerce' ),
            'description'=> $gateway ? wp_strip_all_tags( $gateway->get_description() ) : '',
            'supports'   => array(), // extend if you add features
        ) );
    }

    public function get_payment_method_script_handles() {
        return array( 'wc-bani-blocks' );
    }

    public function is_active() {
        $gateway = wc()->payment_gateways()->payment_gateways()['bani'] ?? null;
        return $gateway ? $gateway->is_available() : false;
    }

    public function get_payment_method_data() {
        $gateway = wc()->payment_gateways()->payment_gateways()['bani'] ?? null;

        return array(
            'title'       => $gateway ? $gateway->get_title() : __( 'Bani', 'bani-payments-for-woocommerce' ),
            'description' => $gateway ? wp_strip_all_tags( $gateway->get_description() ) : '',
            'supports'    => array(), // extend if needed
        );
    }
}
