@extends('eventmie::o_dashboard.index')

@section('title')
    @lang('eventmie-pro::em.dashboard')
@endsection

@section('o_dashboard')
    <div class="container-fluid my-2">
        <!-- Dashboard Greeting Section -->
        <div class="dashboard-greeting">
            <div class="greeting-content">
                <h3 class="greeting-title">@lang('eventmie-pro::em.hello') {{ Auth::user()->name }}</h3>
                <p class="greeting-subtitle">@lang('eventmie-pro::em.organizer_dashboard_activity')</p>
            </div>
            <div class="greeting-icon">
                <i class="fas fa-chart-line"></i>
            </div>
        </div>
        
        <!-- Stats Grid -->
        <div class="stats-grid">
            <div class="stat-card">
                <div class="stat-icon fa-calendar-alt">
                    <i class="fas fa-calendar-alt"></i>
                </div>
                <div class="stat-content">
                    <div class="stat-number">{{ $total_events }}</div>
                    <div class="stat-currency text-uppercase">@lang('eventmie-pro::em.total')</div>
                    <div class="stat-label">@lang('eventmie-pro::em.events')</div>
                </div>
            </div>

            @if (Auth::user()->hasRole('organiser'))
            <div class="stat-card">
                <div class="stat-icon fa-tag">
                    <i class="fas fa-tag"></i>
                </div>
                <div class="stat-content">
                    @foreach ($total_earning as $earning)
                    <div class="border-bottom my-1  border-gray" >
                        <div class="stat-number stat-discounts">{{ $earning->promocode_total ?? 0 }}</div>
                        <div class="stat-currency">{{ $earning->currency }}</div>
                    </div>
                    @endforeach
                    <div class="stat-label">@lang('eventmie-pro::em.discounts')</div>

                </div>
            </div>

            <div class="stat-card">
                <div class="stat-icon fa-percentage">
                    <i class="fas fa-percentage"></i>
                </div>
                <div class="stat-content">
                    @foreach ($total_earning as $earning)
                    <div class="border-bottom my-1  border-gray" >
                        <div class="stat-number stat-admin-fees">{{ $earning->admin_commission_total ?? 0 }}</div>
                        <div class="stat-currency">{{ $earning->currency }}</div>
                    </div> 
                    @endforeach
                    <div class="stat-label">@lang('eventmie-pro::em.admin_fees')</div>
                </div>
            </div>

            <div class="stat-card">
                <div class="stat-icon fa-wallet">
                    <i class="fas fa-wallet"></i>
                </div>
                <div class="stat-content">
                    @foreach ($total_earning as $earning)
                    <div class="border-bottom my-1  border-gray" >
                        <div class="stat-number stat-earnings">{{ $earning->organiser_earning_total  ?? 0}}</div>
                        <div class="stat-currency">{{ $earning->currency }}</div>
                    </div>    
                    @endforeach
                    <div class="stat-label">@lang('eventmie-pro::em.earnings')</div>
                </div>
            </div>

            <div class="stat-card">
                <div class="stat-icon fa-ticket-alt">
                    <i class="fas fa-ticket-alt"></i>
                </div>
                <div class="stat-content">
                    <div class="stat-number">{{ $total_bookings }}</div>
                    <div class="stat-currency text-uppercase">@lang('eventmie-pro::em.total')</div>
                    <div class="stat-label">@lang('eventmie-pro::em.tickets_sold')</div>
                </div>
            </div>
            @endif
        </div>

        <div class="row">
            <div class="col-lg-12 col-md-12 col-12">
                <!-- Card -->
                <div class="card mb-3 border-0 shadow-sm dashboard-chart-card">
                    <!-- Card body -->
                    <div class="card-body rounded-3 p-4">
                        <div class="d-flex align-items-center justify-content-between mb-4">
                            <h4 class="card-title mb-0 fw-bold text-dark">{{ __('eventmie-pro::em.top_selling_events') }}</h4>
                            <div class="chart-icon-wrapper">
                                <i class="fas fa-chart-line"></i>
                            </div>
                        </div>
                        <!-- Earning chart -->
                        <div id="earning" class="apex-charts">
                            {!! $eventsChart->container() !!}
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-12 col-md-12 col-12">
                <!-- Card -->
                <div class="card mb-3 border-0 shadow-sm dashboard-chart-card">
                    <!-- Card body -->
                    <div class="card-body rounded-3 p-4">
                        <div class="d-flex align-items-center justify-content-between mb-4">
                            <h4 class="card-title mb-0 fw-bold text-dark">{{ __('eventmie-pro::em.event_tickets_statistics') }}</h4>
                            <div class="chart-icon-wrapper">
                                <i class="fas fa-chart-bar"></i>
                            </div>
                        </div>
                        <!-- Earning chart -->
                        <div id="earning" class="apex-charts">
                            @if (Auth::user()->hasRole('organiser'))
                                <event-total :event_total_route="{{ json_encode(route('event_total')) }}"></event-total>
                            @elseif (Auth::user()->hasRole('pos'))
                                <event-total :event_total_route="{{ json_encode(route('pos.event_total')) }}"></event-total>
                            @elseif (Auth::user()->hasRole('scanner'))
                                <event-total
                                    :event_total_route="{{ json_encode(route('scanner.event_total')) }}"></event-total>
                            @endif
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('javascript')
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js"></script>
    {!! $eventsChart->script() !!}
    @vite(['resources/js/event_dashboard/index.js'])
@stop
