<?php
/**
 * Notifications tab — email channel + quiet hours + daily digest.
 *
 * @package Brainwerk Security Suite
 */

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

$keys = array(
    'notify_email_enabled', 'notify_email_to',
    'notify_quiet_hours', 'digest_enabled',
);
$qh = Shieldforge_Settings::get( 'notify_quiet_hours', array( 'start' => '22:00', 'end' => '07:00' ) );
?>
<form method="post" class="shieldforge-form">
    <?php wp_nonce_field( Shieldforge_Admin::NONCE ); ?>
    <input type="hidden" name="shieldforge_action" value="save_settings">
    <?php foreach ( $keys as $k ) : ?>
        <input type="hidden" name="shieldforge_tab_keys[]" value="<?php echo esc_attr( $k ); ?>">
    <?php endforeach; ?>

    <div class="shieldforge-card">
        <h2><?php esc_html_e( 'Email notifications', 'brainwerk-security-suite' ); ?></h2>
        <label class="shieldforge-toggle">
            <input type="checkbox" name="shieldforge[notify_email_enabled]" value="1"
                <?php checked( Shieldforge_Settings::get( 'notify_email_enabled' ) ); ?>>
            <span><?php esc_html_e( 'Send email alerts on critical events', 'brainwerk-security-suite' ); ?></span>
        </label>

        <table class="form-table" role="presentation">
            <tr>
                <th><?php esc_html_e( 'Recipient', 'brainwerk-security-suite' ); ?></th>
                <td>
                    <input type="email" name="shieldforge[notify_email_to]" class="regular-text"
                           value="<?php echo esc_attr( Shieldforge_Settings::get( 'notify_email_to', get_option( 'admin_email' ) ) ); ?>">
                </td>
            </tr>
            <tr>
                <th><?php esc_html_e( 'Quiet hours', 'brainwerk-security-suite' ); ?></th>
                <td>
                    <input type="time" name="shieldforge[notify_quiet_hours][start]" value="<?php echo esc_attr( $qh['start'] ); ?>">
                    —
                    <input type="time" name="shieldforge[notify_quiet_hours][end]" value="<?php echo esc_attr( $qh['end'] ); ?>">
                    <p class="description"><?php esc_html_e( 'During these hours only critical alerts are sent. Daily digest is unaffected.', 'brainwerk-security-suite' ); ?></p>
                </td>
            </tr>
        </table>
    </div>

    <div class="shieldforge-card">
        <h2><?php esc_html_e( 'Daily digest', 'brainwerk-security-suite' ); ?></h2>
        <label class="shieldforge-toggle">
            <input type="checkbox" name="shieldforge[digest_enabled]" value="1"
                <?php checked( Shieldforge_Settings::get( 'digest_enabled' ) ); ?>>
            <span><?php esc_html_e( 'Send a daily summary email at 07:00', 'brainwerk-security-suite' ); ?></span>
        </label>
    </div>

    <p><button type="submit" class="button button-primary"><?php esc_html_e( 'Save changes', 'brainwerk-security-suite' ); ?></button></p>
</form>
