<?php
/**
 * Additional Helper Functions
 * File: app/Helpers/additional.php
 * Add these to your existing helpers or create new file
 */

/**
 * Format currency in Nigerian Naira
 */
if (!function_exists('format_currency')) {
    function format_currency($amount) {
        return '₦' . number_format((float)$amount, 2);
    }
}

/**
 * Format money (alias for format_currency)
 */
if (!function_exists('format_money')) {
    function format_money($amount) {
        return format_currency($amount);
    }
}

/**
 * Get status badge HTML
 */
if (!function_exists('get_status_badge')) {
    function get_status_badge($status) {
        $badges = [
            'pending' => '<span class="badge bg-warning">Pending</span>',
            'confirmed' => '<span class="badge bg-info">Confirmed</span>',
            'ongoing' => '<span class="badge bg-primary">Ongoing</span>',
            'completed' => '<span class="badge bg-success">Completed</span>',
            'cancelled' => '<span class="badge bg-danger">Cancelled</span>',
            'rejected' => '<span class="badge bg-danger">Rejected</span>',
            'approved' => '<span class="badge bg-success">Approved</span>',
            'active' => '<span class="badge bg-success">Active</span>',
            'inactive' => '<span class="badge bg-secondary">Inactive</span>',
            'paid' => '<span class="badge bg-success">Paid</span>',
            'unpaid' => '<span class="badge bg-warning">Unpaid</span>',
            'processing' => '<span class="badge bg-info">Processing</span>',
            'failed' => '<span class="badge bg-danger">Failed</span>',
        ];
        
        return $badges[strtolower($status)] ?? '<span class="badge bg-secondary">' . ucfirst($status) . '</span>';
    }
}

/**
 * Get payment status badge
 */
if (!function_exists('get_payment_status_badge')) {
    function get_payment_status_badge($status) {
        $badges = [
            'pending' => '<span class="badge bg-warning">Pending</span>',
            'paid' => '<span class="badge bg-success">Paid</span>',
            'failed' => '<span class="badge bg-danger">Failed</span>',
            'refunded' => '<span class="badge bg-info">Refunded</span>',
        ];
        
        return $badges[strtolower($status)] ?? '<span class="badge bg-secondary">' . ucfirst($status) . '</span>';
    }
}

/**
 * Time ago helper
 */
if (!function_exists('time_ago')) {
    function time_ago($datetime, $full = false) {
        $now = new DateTime;
        $ago = new DateTime($datetime);
        $diff = $now->diff($ago);

        $diff->w = floor($diff->d / 7);
        $diff->d -= $diff->w * 7;

        $string = [
            'y' => 'year',
            'm' => 'month',
            'w' => 'week',
            'd' => 'day',
            'h' => 'hour',
            'i' => 'minute',
            's' => 'second',
        ];
        
        foreach ($string as $k => &$v) {
            if ($diff->$k) {
                $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
            } else {
                unset($string[$k]);
            }
        }

        if (!$full) $string = array_slice($string, 0, 1);
        return $string ? implode(', ', $string) . ' ago' : 'just now';
    }
}

/**
 * Escape HTML
 */
if (!function_exists('esc')) {
    function esc($string) {
        return htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
    }
}