<?php

namespace UltraguardPro\modules\woo_security\pages;

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

use UltraguardPro\Plugin;
use UltraguardPro\modules\core\BasePage;

class WooSecuritySettings extends BasePage {

    public function __construct( Plugin $plugin ) {
        parent::__construct( $plugin );
        $this->ajax_nonce_action = 'ultraguard_admin_nonce';
    }

    public function get_scheme( $context ): array {
        $settings = $this->settings->get_module_settings( 'woo_security' );
        $nonce    = $this->create_nonce( 'ultraguard_admin_nonce' );

        return [
            'type'      => 'page',
            'id'        => 'woo-security-settings',
            'page_slug' => 'woo-security-settings',
            'header'    => [
                'title'    => __( 'WooCommerce Security Settings', 'ultraguard-security-suite' ),
                'subtitle' => __( 'Tune skimmer scanning, checkout hardening, honeypots, and PCI-conscious store protections.', 'ultraguard-security-suite' ),
                'actions'  => [
                    $this->create_url_button( __( 'Back to Dashboard', 'ultraguard-security-suite' ), $this->get_page_url( 'woo-security' ), 'secondary', 'dashicons-arrow-left-alt' ),
                ],
            ],
            'data'      => [
                [
                    'type'  => 'card',
                    'title' => __( 'Core Protection', 'ultraguard-security-suite' ),
                    'data'  => [
                        [ 'type' => 'toggle', 'name' => 'woo_security_enabled', 'label' => __( 'Enable WooCommerce Security Mode', 'ultraguard-security-suite' ), 'value' => ! empty( $settings['woo_security_enabled'] ) ],
                        [ 'type' => 'toggle', 'name' => 'woo_security_skimmer_detection', 'label' => __( 'Enable card skimmer detection', 'ultraguard-security-suite' ), 'value' => ! empty( $settings['woo_security_skimmer_detection'] ) ],
                        [ 'type' => 'toggle', 'name' => 'woo_security_strict_csp', 'label' => __( 'Enable strict CSP on checkout/cart/account pages', 'ultraguard-security-suite' ), 'value' => ! empty( $settings['woo_security_strict_csp'] ) ],
                        [ 'type' => 'textarea', 'name' => 'woo_security_allowed_script_domains', 'label' => __( 'Allowed external script domains for checkout CSP', 'ultraguard-security-suite' ), 'description' => __( 'One domain per line for payment gateway scripts.', 'ultraguard-security-suite' ), 'value' => (string) ( $settings['woo_security_allowed_script_domains'] ?? '' ) ],
                    ],
                ],
                [
                    'type'  => 'card',
                    'title' => __( 'Checkout Protection', 'ultraguard-security-suite' ),
                    'data'  => [
                        [ 'type' => 'toggle', 'name' => 'woo_security_checkout_honeypot', 'label' => __( 'Enable checkout honeypot', 'ultraguard-security-suite' ), 'value' => ! empty( $settings['woo_security_checkout_honeypot'] ) ],
                        [ 'type' => 'toggle', 'name' => 'woo_security_block_honeypot_order', 'label' => __( 'Block order if honeypot triggered', 'ultraguard-security-suite' ), 'value' => ! empty( $settings['woo_security_block_honeypot_order'] ) ],
                        [ 'type' => 'toggle', 'name' => 'woo_security_secure_headers', 'label' => __( 'Apply PCI-conscious security headers to store pages', 'ultraguard-security-suite' ), 'value' => ! empty( $settings['woo_security_secure_headers'] ) ],
                        [ 'type' => 'toggle', 'name' => 'woo_security_alert_on_skimmer', 'label' => __( 'Alert when suspected skimmer code is detected', 'ultraguard-security-suite' ), 'value' => ! empty( $settings['woo_security_alert_on_skimmer'] ) ],
                        [ 'type' => 'toggle', 'name' => 'woo_security_block_suspicious_orders', 'label' => __( 'Block suspicious orders from bot IPs', 'ultraguard-security-suite' ), 'value' => ! empty( $settings['woo_security_block_suspicious_orders'] ) ],
                    ],
                ],
            ],
            'form'      => [
                'enable' => true,
                'id'     => 'woo-security-settings-form',
                'ajax'   => true,
                'action' => 'ultraguard_save_woo_security_settings',
                'nonce'  => $nonce,
                'submit' => [
                    'text'         => __( 'Save Settings', 'ultraguard-security-suite' ),
                    'button_style' => 'primary',
                    'icon'         => 'dashicons-saved',
                ],
            ],
        ];
    }
}
