<div>
    <div>

        <div class="p-4 bg-white block sm:flex items-center justify-between dark:bg-gray-800 dark:border-gray-700">
            <div class="w-full mb-1">
                <div class="mb-4">
                    <h1 class="text-xl font-semibold text-gray-900 sm:text-2xl dark:text-white">@lang('modules.expenses.reports.expenseSummaryReport')</h1>
                </div>
                <div class="items-center justify-between block sm:flex ">
                    <div class="lg:flex items-center mb-4 sm:mb-0">
                        <form class="sm:pr-3" action="#" method="GET">

                            <div class="lg:flex gap-2 items-center">
                                <x-select id="dateRangeType" class="block w-fit" wire:model.defer="dateRangeType"
                                    wire:change="setDateRange">
                                    <option value="today">@lang('app.today')</option>
                                    <option value="currentWeek">@lang('app.currentWeek')</option>
                                    <option value="lastWeek">@lang('app.lastWeek')</option>
                                    <option value="last7Days">@lang('app.last7Days')</option>
                                    <option value="currentMonth">@lang('app.currentMonth')</option>
                                    <option value="lastMonth">@lang('app.lastMonth')</option>
                                    <option value="currentYear">@lang('app.currentYear')</option>
                                    <option value="lastYear">@lang('app.lastYear')</option>
                                </x-select>

                                <div id="date-range-picker" class="flex flex-col w-full gap-2 sm:flex-row">
                                    <div class="relative flex-1">
                                        <div class="absolute inset-y-0 flex items-center pointer-events-none start-0 ps-3">
                                            <svg class="w-4 h-4 text-gray-500 dark:text-gray-400" aria-hidden="true"
                                                xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
                                                <path
                                                    d="M20 4a2 2 0 0 0-2-2h-2V1a1 1 0 0 0-2 0v1h-3V1a1 1 0 0 0-2 0v1H6V1a1 1 0 0 0-2 0v1H2a2 2 0 0 0-2 2v2h20V4ZM0 18a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8H0v10Zm5-8h10a1 1 0 0 1 0 2H5a1 1 0 0 1 0-2Z" />
                                            </svg>
                                        </div>
                                        <x-datepicker wire:model.live='startDate' placeholder="@lang('app.selectStartDate')" class="pl-10" />
                                    </div>
                                    <span class="self-center hidden text-gray-500 sm:block">@lang('app.to')</span>
                                    <div class="relative flex-1">
                                        <div class="absolute inset-y-0 flex items-center pointer-events-none start-0 ps-3">
                                            <svg class="w-4 h-4 text-gray-500 dark:text-gray-400" aria-hidden="true"
                                                xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
                                                <path
                                                    d="M20 4a2 2 0 0 0-2-2h-2V1a1 1 0 0 0-2 0v1h-3V1a1 1 0 0 0-2 0v1H6V1a1 1 0 0 0-2 0v1H2a2 2 0 0 0-2 2v2h20V4ZM0 18a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8H0v10Zm5-8h10a1 1 0 0 1 0 2H5a1 1 0 0 1 0-2Z" />
                                            </svg>
                                        </div>
                                        <x-datepicker wire:model.live='endDate' placeholder="@lang('app.selectEndDate')" class="pl-10" />
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>

                    <a href="javascript:;" wire:click='exportReport'
                        class="inline-flex items-center justify-center w-1/2 px-3 py-2 text-sm font-medium text-center text-gray-900 bg-white border border-gray-300 rounded-lg hover:bg-gray-100 focus:ring-4 focus:ring-primary-300 sm:w-auto dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700 dark:focus:ring-gray-700">
                        <svg class="w-5 h-5 mr-2 -ml-1" fill="currentColor" viewBox="0 0 20 20"
                            xmlns="http://www.w3.org/2000/svg">
                            <path fill-rule="evenodd"
                                d="M6 2a2 2 0 00-2 2v12a2 2 0 002 2h8a2 2 0 002-2V7.414A2 2 0 0015.414 6L12 2.586A2 2 0 0010.586 2H6zm5 6a1 1 0 10-2 0v3.586l-1.293-1.293a1 1 0 10-1.414 1.414l3 3a1 1 0 001.414 0l3-3a1 1 0 00-1.414-1.414L11 11.586V8z"
                                clip-rule="evenodd"></path>
                        </svg>
                        @lang('app.export')
                    </a>

                </div>
            </div>

        </div>

        <div class="flex flex-col">
            <div class="overflow-x-auto">
                <div class="inline-block min-w-full align-middle">
                    <div class="overflow-hidden shadow">

                        <table class="min-w-full divide-y divide-gray-200 table-fixed dark:divide-gray-600">
                            <thead>
                                <tr class="bg-gray-100 dark:bg-gray-700">
                                    {{-- <th
                                        class="py-2 px-4 text-xs font-medium text-left text-gray-500 uppercase dark:text-gray-400">
                                    </th> --}}
                                    <th
                                        class="py-2 px-4 text-xs font-medium text-left text-gray-500 uppercase dark:text-gray-400">
                                        @lang('modules.expenses.category')</th>
                                    <th
                                        class="py-2 px-4 text-xs font-medium text-left text-gray-500 uppercase dark:text-gray-400">
                                        @lang('modules.expenses.total_expense')</th>
                                    <th
                                        class="py-2 px-4 text-xs font-medium text-left text-gray-500 uppercase dark:text-gray-400">
                                        @lang('modules.expenses.percentage_of_total')</th>
                                    {{-- <th
                                        class="py-2 px-4 text-xs font-medium text-left text-gray-500 uppercase dark:text-gray-400">

                                    </th> --}}

                                </tr>
                            </thead>
                            <tbody class="bg-white divide-y divide-gray-200 dark:bg-gray-800 dark:divide-gray-700" wire:key='menu-item-list-{{ microtime() }}'>
                                @foreach ($expenses as $expense)
                                    <tr class="hover:bg-gray-100 dark:hover:bg-gray-700" wire:key='menu-item-{{ $loop->index . microtime() }}' wire:loading.class.delay='opacity-10'>
                                          {{-- <td
                                            class="py-2 px-4 text-xs font-medium text-left text-gray-500 uppercase dark:text-gray-400">
                                           </td> --}}
                                        <td
                                            class="py-2 px-4 text-xs font-medium text-left text-gray-500 uppercase dark:text-gray-400">
                                            {{ $expense->category->name ?? __('modules.expenses.reports.unknownCategory') }}</td>
                                        <td
                                            class="py-2 px-4 text-xs font-medium text-left text-gray-500 uppercase dark:text-gray-400">
                                            {{ isset($expense->total_amount) ? currency_format($expense->total_amount, restaurant()->currency_id) : currency_format(0, restaurant()->currency_id) }}</td>
                                        <td
                                            class="py-2 px-4 text-xs font-medium text-left text-gray-500 uppercase dark:text-gray-400">
                                            {{ $totalAmount > 0 && isset($expense->total_amount) ? number_format(($expense->total_amount / $totalAmount) * 100, 2) . '%' : '-' }}
                                        </td>
                                        {{-- <td
                                            class="py-2 px-4 text-xs font-medium text-left text-gray-500 uppercase dark:text-gray-400">
                                        </td> --}}
                                    </tr>
                                @endforeach

                                <!-- Total Row -->
                                @if ($totalAmount > 0)
                                    <tr class="bg-gray-100 dark:bg-gray-700">
                                        <td class="py-2 px-4 text-xs text-left border-gray-700"></td>
                                        <td class="py-2 px-4 text-xs text-left border-gray-700">@lang('modules.order.total')</td>
                                        <td class="py-2 px-4 text-xs text-left border-gray-700">
                                            {{ currency_format($totalAmount, restaurant()->currency_id) }}
                                        </td>
                                        {{-- <td class="py-2 px-4 text-xs text-left border-gray-700"></td> --}}
                                    </tr>
                                @else
                                    <tr>
                                        <td colspan="4" class="py-4 px-4 text-center text-gray-500">
                                            @lang('modules.expenses.reports.NoReportsFound')
                                        </td>
                                @endif

                            </tbody>
                        </table>


                    </div>
                </div>
            </div>
        </div>

    </div>
</div>
