<?php

namespace UltraguardPro\modules\compliance_reports\pages;

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

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

class ComplianceReportsSettings 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( 'compliance_reports' );
        $nonce    = $this->create_nonce( 'ultraguard_admin_nonce' );

        return [
            'type'      => 'page',
            'id'        => 'compliance-reports-settings',
            'page_slug' => 'compliance-reports-settings',
            'header'    => [
                'title'    => __( 'Compliance Reports Settings', 'ultraguard-security-suite' ),
                'subtitle' => __( 'Configure branding, monthly automation, and report delivery preferences.', 'ultraguard-security-suite' ),
                'actions'  => [
                    $this->create_url_button( __( 'Back to Reports', 'ultraguard-security-suite' ), $this->get_page_url( 'compliance-reports' ), 'secondary', 'dashicons-arrow-left-alt' ),
                ],
            ],
            'data'      => [
                [
                    'type'  => 'card',
                    'title' => __( 'Branding & Contacts', 'ultraguard-security-suite' ),
                    'data'  => [
                        [ 'type' => 'text', 'name' => 'compliance_reports_organization_name', 'label' => __( 'Organisation name', 'ultraguard-security-suite' ), 'value' => (string) ( $settings['compliance_reports_organization_name'] ?? get_bloginfo( 'name' ) ) ],
                        [ 'type' => 'text', 'name' => 'compliance_reports_contact_name', 'label' => __( 'Contact name', 'ultraguard-security-suite' ), 'value' => (string) ( $settings['compliance_reports_contact_name'] ?? '' ) ],
                        [ 'type' => 'text', 'name' => 'compliance_reports_contact_email', 'label' => __( 'Contact email', 'ultraguard-security-suite' ), 'value' => (string) ( $settings['compliance_reports_contact_email'] ?? get_option( 'admin_email', '' ) ) ],
                        [ 'type' => 'toggle', 'name' => 'compliance_reports_include_logo', 'label' => __( 'Include logo on reports', 'ultraguard-security-suite' ), 'value' => ! empty( $settings['compliance_reports_include_logo'] ) ],
                        [ 'type' => 'text', 'name' => 'compliance_reports_logo_url', 'label' => __( 'Logo URL', 'ultraguard-security-suite' ), 'value' => (string) ( $settings['compliance_reports_logo_url'] ?? '' ), 'description' => __( 'Paste the media URL for the logo to include on the cover page.', 'ultraguard-security-suite' ) ],
                    ],
                ],
                [
                    'type'  => 'card',
                    'title' => __( 'Automation & Output', 'ultraguard-security-suite' ),
                    'data'  => [
                        [ 'type' => 'toggle', 'name' => 'compliance_reports_auto_monthly', 'label' => __( 'Auto-generate monthly security audit report', 'ultraguard-security-suite' ), 'value' => ! empty( $settings['compliance_reports_auto_monthly'] ) ],
                        [ 'type' => 'toggle', 'name' => 'compliance_reports_email_monthly', 'label' => __( 'Email monthly report to admin', 'ultraguard-security-suite' ), 'value' => ! empty( $settings['compliance_reports_email_monthly'] ) ],
                        [ 'type' => 'text', 'name' => 'compliance_reports_watermark', 'label' => __( 'Report watermark text', 'ultraguard-security-suite' ), 'value' => (string) ( $settings['compliance_reports_watermark'] ?? '' ), 'placeholder' => __( 'CONFIDENTIAL', 'ultraguard-security-suite' ) ],
                        [ 'type' => 'toggle', 'name' => 'compliance_reports_include_raw_logs', 'label' => __( 'Include raw log data in reports', 'ultraguard-security-suite' ), 'value' => ! empty( $settings['compliance_reports_include_raw_logs'] ), 'description' => __( 'Warning: raw logs can make reports much larger.', 'ultraguard-security-suite' ) ],
                    ],
                ],
            ],
            'form'      => [
                'enable' => true,
                'id'     => 'compliance-reports-settings-form',
                'ajax'   => true,
                'action' => 'ultraguard_save_compliance_reports_settings',
                'nonce'  => $nonce,
                'submit' => [
                    'text'         => __( 'Save Settings', 'ultraguard-security-suite' ),
                    'button_style' => 'primary',
                    'icon'         => 'dashicons-saved',
                ],
            ],
        ];
    }
}
