<?php

namespace UltraguardPro\modules\upgrade_manager\pages;

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

class UpgradeManagerSettings extends UpgradeManagerPage {

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

        return [
            'type'      => 'page',
            'id'        => 'ultraguard-upgrade-manager-settings',
            'page_slug' => 'upgrade-manager-settings',
            'header'    => [
                'title'    => __( 'License & Upgrade Settings', 'ultraguard-security-suite' ),
                'subtitle' => __( 'Control how UltraGuard presents upgrade nudges and which pricing, billing, or support URLs the license center uses.', 'ultraguard-security-suite' ),
                'actions'  => [
                    $this->create_url_button( __( 'Back to Dashboard', 'ultraguard-security-suite' ), $this->get_page_url( 'upgrade-manager' ), 'secondary', 'dashicons-arrow-left-alt' ),
                    $this->create_ajax_button( __( 'Refresh License Status', 'ultraguard-security-suite' ), 'ultraguard_upgrade_manager_refresh_status', [], 'secondary', 'dashicons-update' ),
                ],
            ],
            'data'      => [
                [
                    'type'  => 'card',
                    'title' => __( 'Behavior', 'ultraguard-security-suite' ),
                    'icon'  => 'dashicons-admin-settings',
                    'data'  => [
                        [
                            'type'      => 'toggle',
                            'name'      => 'upgrade_manager_show_inline_nudges',
                            'label'     => __( 'Show inline upgrade nudges on free-only actions', 'ultraguard-security-suite' ),
                            'value'     => (bool) $this->get_setting( 'upgrade_manager_show_inline_nudges', true ),
                            'help_text' => __( 'When enabled, free users still see contextual upgrade hints inside locked actions instead of a silent block.', 'ultraguard-security-suite' ),
                        ],
                    ],
                ],
                [
                    'type'  => 'card',
                    'title' => __( 'Commercial Links', 'ultraguard-security-suite' ),
                    'icon'  => 'dashicons-admin-links',
                    'data'  => [
                        [
                            'type'        => 'text',
                            'name'        => 'upgrade_manager_external_upgrade_url',
                            'label'       => __( 'Pricing / upgrade URL', 'ultraguard-security-suite' ),
                            'value'       => (string) $this->get_setting( 'upgrade_manager_external_upgrade_url', \UltraguardPro\support\UpgradeManager::EXTERNAL_UPGRADE_URL ),
                    'placeholder' => 'https://ultraguard.net/pricing',
                        ],
                        [
                            'type'        => 'text',
                            'name'        => 'upgrade_manager_billing_portal_url',
                            'label'       => __( 'Billing portal URL override', 'ultraguard-security-suite' ),
                            'value'       => (string) $this->get_setting( 'upgrade_manager_billing_portal_url', '' ),
                    'placeholder' => 'https://ultraguard.net/awesome-login/',
                            'help_text'   => __( 'Used when the license API does not return a billing or account-management URL for the current subscription.', 'ultraguard-security-suite' ),
                        ],
                        [
                            'type'        => 'text',
                            'name'        => 'upgrade_manager_support_url',
                            'label'       => __( 'Support URL', 'ultraguard-security-suite' ),
                    'value'       => (string) $this->get_setting( 'upgrade_manager_support_url', 'https://ultraguard.net/contact' ),
                    'placeholder' => 'https://ultraguard.net/contact',
                        ],
                    ],
                ],
            ],
            'form'      => [
                'enable' => true,
                'id'     => 'upgrade-manager-settings-form',
                'ajax'   => true,
                'action' => 'ultraguard_save_upgrade_manager_settings',
                'nonce'  => $nonce,
                'submit' => [
                    'text'         => __( 'Save Settings', 'ultraguard-security-suite' ),
                    'button_style' => 'primary',
                    'icon'         => 'dashicons-saved',
                ],
            ],
        ];
    }
}
