<?php

use App\Services\WhmcsServices;
use Carbon\Carbon;

function getUserRegistrationSessionName(){
    return 'user_data';
}


function forgetRegistrationSession(){
    session()->forget('user_data');
    session()->forget('verify');
    session()->forget('f2');
}


function GetStatusName($id){
    switch($id){
        case 1:
            echo 'Operational';
            break;
        case 2:
            echo 'Under maintenance';
            break;
        case 3:
            echo 'Degraded performance';
            break;  
        case 4:
            echo 'Partial outage';
            break; 
        case 5:
            echo 'Major outage';
            break;           
    }

}


function getClientDetails(){
    $whmcsServices = new WhmcsServices;

    $client = $whmcsServices->getClientsBySearch(['search'=>auth()->user()->email]);

    if(isset($client['clients']['client']) and count($client['clients']['client']) > 0){
        return $client['clients']['client'][0];
    }else{
        return [];
    }
}


function getHumanDiffBetweenDates($date){
    $registrationDate = Carbon::parse($date); // Replace with actual client registration date
    $now = Carbon::now();

    $diff = $registrationDate->diffForHumans($now);

    // Remove the "ago" from the string
    $formattedDiff = str_replace('ago', '', $diff);
    $formattedDiff = str_replace('before', '', $diff);

    return $formattedDiff;

}