<?php

namespace App\Http\Controllers;

use App\Charts\PaymentBarChart;
use App\Charts\PaymentDonutChart;
use App\DataTables\PaymentDataTable;
use App\Models\Payment;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Illuminate\Http\Request;

class PaymentsController extends Controller
{
    public function index(PaymentDataTable $dataTable, PaymentBarChart $barchart,PaymentDonutChart $donutchart){

        
        $count_total = Payment::query()->count();
        $success_amt = Payment::query()->where('status', 'success')->sum('amount');
        $count_success = Payment::query()->where('status', 'success')->count();
        $count_pending = Payment::query()->where('status', 'pending')->count();
        $count_failed = Payment::query()->where('status', 'failed')->orWhere('status', 'TIMEOUT')->orWhere('status','WRONG_PIN')->count();
        return view('admin.index', compact('count_total','success_amt','count_success','count_pending','count_failed'),['barchart' => $barchart->build(), 'donutchart'=>$donutchart->build()]);
    }
    public function indexReport(PaymentDataTable $dataTable){

        return $dataTable->render('admin.report');
    }


    public function show($id){
        $show = Payment::find($id);
        return view('admin.show', compact('show'));
    }

    public function pieChart(PaymentBarChart $barchart)
    {
        return view('admin.analytics', ['barchart' => $barchart->build()]);
        // return $dataTable->render('admin.analytics');
    }
}
