<?php
/**
 * CargoHub Free Security Class
 * 
 * Handles security features for the FREE version
 */

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

class CargoHub_Free_Security {
    
    /**
     * Verify nonce
     * 
     * @param string $nonce
     * @param string $action
     * @return bool
     */
    public static function verify_nonce($nonce, $action = 'cargohub_free_nonce') {
        return wp_verify_nonce($nonce, $action);
    }
    
    /**
     * Create nonce
     * 
     * @param string $action
     * @return string
     */
    public static function create_nonce($action = 'cargohub_free_nonce') {
        return wp_create_nonce($action);
    }
    
    /**
     * Check if user can manage tracking
     * 
     * @return bool
     */
    public static function can_manage_tracking() {
        return current_user_can('manage_woocommerce');
    }
    
    /**
     * Sanitize input data
     * 
     * @param mixed $data
     * @param string $type
     * @return mixed
     */
    public static function sanitize_input($data, $type = 'text') {
        switch ($type) {
            case 'text':
                return sanitize_text_field($data);
            case 'textarea':
                return sanitize_textarea_field($data);
            case 'email':
                return sanitize_email($data);
            case 'url':
                return esc_url_raw($data);
            case 'int':
                return absint($data);
            default:
                return sanitize_text_field($data);
        }
    }
    
    /**
     * Escape output data
     * 
     * @param mixed $data
     * @param string $type
     * @return mixed
     */
    public static function escape_output($data, $type = 'html') {
        switch ($type) {
            case 'html':
                return esc_html($data);
            case 'attr':
                return esc_attr($data);
            case 'url':
                return esc_url($data);
            case 'js':
                return esc_js($data);
            default:
                return esc_html($data);
        }
    }
}
