<?php
namespace OxygenApp\Hooks;
if ( ! defined( 'ABSPATH' ) ) exit;

use OxygenApp\Utils\OptionUtils;
use OxygenApp\Utils\Sanitizer;

class ActionSettings implements IHook {

    static function register() {
        add_action('admin_init', [self::class, 'registerSettingsGroups']);
    }

    static function registerSettingsGroups(): void {
        $options_group_slug = OptionUtils::OPTION_GROUP_SLUG;
        register_setting($options_group_slug, $options_group_slug, [
            'type' => 'array',
            'sanitize_callback' => [self::class, 'sanitizeOptions']
        ]);
    }

    static function sanitizeOptions($options): array {

        if (!is_array($options)) {
            return $options;
        }

        return Sanitizer::sanitize_data($options);
    }
    
}