<?php

/**
 * Name: WHMCS Client Area Credit Widget
 * Description: This hook provides your customers with an easy to view panel on the client areas home page displaying their credit balance.
 * Version 1.0
 * Created by Mikro Cyber Cloud
 * Website: https://www.mikrocyber.org/
 */

add_hook('ClientAreaHomepagePanels', 1, function ($homePagePanels) {
    $client = Menu::context('client');

    if (!$client || !($clientId = intval($client->id))) {
        return;
    }

    $addFundsUrl = '/clientarea.php?action=addfunds';

    $homePagePanels
        ->addChild('clientCreditWidget', [
            'name'   => 'Account Credit',
            'label'  => Lang::trans('statscreditbalance'),
            'icon'   => 'fas fa-money-bill',
            'order'  => 99,
            'extras' => [
                'color'    => 'orange',
                'btn-link' => $addFundsUrl,
                'btn-text' => Lang::trans('addfunds'),
                'btn-icon' => 'fas fa-plus',
            ],
        ])
        ->addChild('clientCreditWidget-content', [
            'label' => sprintf(
                '<h3 class="text-center pt-3 pb-2">%s</h3>',
                formatcurrency($client->credit, $client->currencyId)
            ),
            'uri'   => $addFundsUrl,
            'order' => 1,
        ]);
});