@extends('layouts.admin')
@section('styles')
@endsection
@section('app')
    <div class="container-fluid">
        <div class="row size-column">
            <div class="col-xxl-10 col-md-12 box-col-8 grid-ed-12">
                <div class="row">
                    <div class="col-xxl-7 col-md-12 ">
                        <div class="row">
                            @if (in_array(auth()->user()->role_id, [1, 2, 3]))
                                <div class="col-sm-12">
                                    <div class="card o-hidden">
                                        <div class="card-body balance-widget">
                                            <span class="f-w-500 f-light">{{ auth()->user()->barbershop->name }}</span>
                                            <h4 class="mb-3 mt-1 f-w-500 mb-0 f-22">
                                                <span class="counter">{{ formatToRupiah($cash) }}</span>
                                            </h4>
                                            @if (auth()->user()->role_id !== 5 && auth()->user()->role_id !== 2)
                                                <a class="purchase-btn btn btn-primary btn-hover-effect f-w-500"
                                                    href="{{ route('finance.cashes') }}">Tambah Kas</a>
                                            @else
                                                <span class=" f-w-500"></span>
                                            @endif
                                            <div class="mobile-right-img">
                                                <img class="mobile-img" src="{{ asset('assets/admin/images/mobile.png') }}"
                                                    alt="mobile with coin">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            @endif
                            <div class="col-6">
                                <div class="card small-widget">
                                    <div class="card-body primary">
                                        <span class="f-light">Pendapatan</span>
                                        <div class="d-flex align-items-end gap-1">
                                            <h4>{{ formatToRupiah($todayIncome) }}</h4>
                                            <span class="font-primary f-12 f-w-500">
                                                <span>
                                                    {{ formatToRupiah($yesterdayIncome) }}</span>
                                            </span>
                                        </div>
                                        <div class="bg-gradient">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-6">
                                <div class="card small-widget">
                                    <div class="card-body warning">
                                        <span class="f-light">Cukur</span>
                                        <div class="d-flex align-items-end gap-1">
                                            <h4>{{ $todayShaving }}</h4>
                                            <span class="font-warning f-12 f-w-500">
                                                <span>{{ $yesterdayShaving }}</span>
                                            </span>
                                        </div>
                                        <div class="bg-gradient">
                                            <svg class="stroke-icon svg-fill">
                                            </svg>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-6">
                                <div class="card small-widget">
                                    <div class="card-body secondary">
                                        <span class="f-light">Pengeluaran</span>
                                        <div class="d-flex align-items-end gap-1">
                                            <h4>{{ formatToRupiah($todayExpense) }}</h4>
                                            <span class="font-secondary f-12 f-w-500">
                                                <span>
                                                    {{ formatToRupiah($yesterdayExpense) }}</span>
                                            </span>
                                        </div>
                                        <div class="bg-gradient">
                                            <svg class="stroke-icon svg-fill">
                                            </svg>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-6">
                                <div class="card small-widget">
                                    <div class="card-body success">
                                        <span class="f-light">Pelanggan Baru</span>
                                        <div class="d-flex align-items-end gap-1">
                                            <h4>{{ $todayNewCustomer }}</h4>
                                            <span class="font-success f-12 f-w-500">
                                                <span>
                                                    {{ $yesterdayNewCustomer }}</span>
                                            </span>
                                        </div>
                                        <div class="bg-gradient">
                                            <svg class="stroke-icon svg-fill">
                                            </svg>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            @if (in_array(auth()->user()->role_id, [3, 4, 5]))
                                <div class="col-lg-12">
                                    <div class="card small-widget">
                                        <div class="card-body success">
                                            <span class="w-500">SOP</span>
                                            <span class="f-light">{{ auth()->user()->sop }}</span>
                                        </div>
                                    </div>
                                </div>
                            @endif
                        </div>
                    </div>
                    <div class="col-xxl-5 col-md-12 ">
                        <div class="appointment">
                            <div class="card">
                                <div class="card-header card-no-border">
                                    <div class="header-top">
                                        <h5 class="m-0">Top Pelanggan</h5>
                                    </div>
                                </div>
                                <div class="card-body pt-0">
                                    <div class="table-responsive custom-scrollbar">
                                        <table class="table table-dashed">
                                            <thead>
                                                <tr>
                                                    <th>Nama</th>
                                                    <th>Kontak</th>
                                                    <th>Jumlah Transaksi</th>
                                                    <th>Total Transakski</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                @foreach ($topCustomersByTotal as $item)
                                                    <tr>
                                                        <td>{{ $item->customer->name ?? '--deleted--' }}</td>
                                                        <td>{{ $item->customer->contact_number ?? '-' }}</td>
                                                        <td>{{ $item->transaction_count }}</td>
                                                        <td>{{ formatToRupiah($item->total_transaction) }}</td>
                                                    </tr>
                                                @endforeach
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                            <div class="card">
                                <div class="card-header card-no-border">
                                    <div class="header-top">
                                        <h5 class="m-0">Pendapatan Barber</h5>
                                    </div>
                                </div>
                                <div class="card-body pt-0">
                                    <div class="table-responsive custom-scrollbar">
                                        <table class="table table-dashed">
                                            <thead>
                                                <tr>
                                                    <th>Nama</th>
                                                    <th>Jumlah Transaksi</th>
                                                    <th>Total Transakski</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                @foreach ($incomeByBarber as $item)
                                                    <tr>
                                                        <td>{{ $item->biography->full_name ?? '--deleted--' }}</td>
                                                        <td>{{ $item->transactions_count }}</td>
                                                        <td>{{ formatToRupiah($item->transactions_sum_total) }}</td>
                                                    </tr>
                                                @endforeach
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
@section('afterScript')
@endsection
