<?php

namespace App\Filament\Widgets;

use App\Services\BeemSmsService;
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;

class SmsBalanceWidget extends BaseWidget
{
    protected static ?int $sort = 5;

    protected function getStats(): array
    {
        $smsService = new BeemSmsService();
        $result = $smsService->getBalance();

        if ($result['success']) {
            $balance = $result['data']['data']['credit_balance'] ?? 'N/A';
            $currency = $result['data']['data']['currency'] ?? '';
            
            return [
                Stat::make('SMS Balance', "{$balance} {$currency}")
                    ->description('Current SMS credit balance')
                    ->descriptionIcon('heroicon-m-currency-dollar')
                    ->color('success'),
            ];
        }

        return [
            Stat::make('SMS Balance', 'Not Available')
                ->description('Configure SMS settings to view balance')
                ->descriptionIcon('heroicon-m-exclamation-triangle')
                ->color('warning'),
        ];
    }
}
