<?php

defined('ABSPATH') || exit;

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

class ADAPAYFWC_Blocks extends AbstractPaymentMethodType
{
    private ADAPAYFWC_GateWay $gateway;
    protected  $name = 'ada_payment';
    public  $settings;

    public function initialize(): void
    {
        $this->settings = get_option('woocommerce_ada_payment_settings', []);
        $this->gateway = new ADAPAYFWC_GateWay();
    }

    public function isActive(): bool
    {
        return $this->gateway->is_available();
    }

    public function get_payment_method_script_handles(): array
    {
        $asset_path   = ADAPAYFWC_PLUGIN_DIR . 'build/index.asset.php';
        $version      = null;
        $dependencies = array('wp-element', 'wp-components', 'wp-data', 'wp-i18n', 'wc-blocks-data-store');
        if (file_exists($asset_path)) {
            $asset        = require $asset_path;
            $version      = isset($asset['version']) ? $asset['version'] : $version;
            $dependencies = isset($asset['dependencies']) ? $asset['dependencies'] : $dependencies;
        }

        // # disabling becuase this has too many rules. Rules should be minimum and structural only
        // wp_enqueue_style('tailwind-css', ADAPAYFWC_PLUGIN_URL . 'css/main.css', array(), '2.2.19');

        wp_register_script(
            'ada_payment-blocks-integration',
            ADAPAYFWC_PLUGIN_URL . 'build/index.js',
            $dependencies,
            $version,
            true
        );

        wp_script_add_data('ada_payment-blocks-integration', 'type', 'module');

        if (function_exists('wp_set_script_translations')) {
            wp_set_script_translations('ada_payment-blocks-integration');
        }
        return ['ada_payment-blocks-integration'];
    }

    public function get_payment_method_data(): array
    {
        return [
            'title'       => $this->gateway->title,
            'description' => $this->gateway->get_dynamic_description(),
            'supports'    => $this->gateway->supports,
        ];
    }
}
