<x-app-layout>
    <x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
            {{ __('Realizar Arqueo / Cierre de Caja') }}
        </h2>
    </x-slot>

    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
            <div class="p-4 sm:p-8 bg-white dark:bg-gray-800 shadow sm:rounded-lg">
                <div class="max-w-2xl">
                    <header class="mb-6">
                        <h2 class="text-lg font-medium text-gray-900 dark:text-gray-100">
                            {{ __('Resumen de Turno') }}
                        </h2>
                        <p class="text-sm text-gray-600 dark:text-gray-400">
                            Desde el {{ $cashReconciliation->opened_at->format('d/m/y H:i') }}
                        </p>
                    </header>

                    <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
                        <div class="p-4 bg-gray-50 dark:bg-gray-700/50 rounded-lg">
                            <span class="text-xs uppercase text-gray-500">Saldo Inicial</span>
                            <div class="text-xl font-bold">S/ {{ number_format($cashReconciliation->opening_balance, 2) }}</div>
                        </div>
                        <div class="p-4 bg-green-50 dark:bg-green-900/10 rounded-lg">
                            <span class="text-xs uppercase text-gray-500">Ventas en Efectivo</span>
                            <div class="text-xl font-bold text-green-600">+ S/ {{ number_format($salesTotal, 2) }}</div>
                        </div>
                        <div class="p-4 bg-red-50 dark:bg-red-900/10 rounded-lg">
                            <span class="text-xs uppercase text-gray-500">Egresos Registrados</span>
                            <div class="text-xl font-bold text-red-600">- S/ {{ number_format($expensesTotal, 2) }}</div>
                        </div>
                        <div class="p-4 bg-blue-50 dark:bg-blue-900/10 rounded-lg">
                            <span class="text-xs uppercase text-gray-500 text-blue-800 dark:text-blue-300">Saldo Esperado en Caja</span>
                            <div class="text-2xl font-bold text-blue-800 dark:text-blue-300">S/ {{ number_format($expectedBalance, 2) }}</div>
                        </div>
                    </div>

                    <form method="POST" action="{{ route('cash.storeClose', $cashReconciliation) }}" class="space-y-6">
                        @csrf
                        
                        <div>
                            <x-input-label for="actual_balance" :value="__('Monto Real contado en Efectivo')" />
                            <x-text-input id="actual_balance" name="actual_balance" type="number" step="0.01" class="mt-1 block w-48" required autofocus />
                            <x-input-error class="mt-2" :messages="$errors->get('actual_balance')" />
                            <p class="text-xs text-gray-500 mt-1">Cuenta todo el dinero físico que hay en la gaveta.</p>
                        </div>

                        <div>
                            <x-input-label for="notes" :value="__('Observaciones / Notas')" />
                            <textarea id="notes" name="notes" rows="3" class="mt-1 block w-full border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 focus:border-indigo-500 dark:focus:border-indigo-600 focus:ring-indigo-500 dark:focus:ring-indigo-600 rounded-md shadow-sm"></textarea>
                            <x-input-error class="mt-2" :messages="$errors->get('notes')" />
                        </div>

                        <div class="flex items-center gap-4">
                            <x-danger-button>{{ __('Confirmar Cierre de Caja') }}</x-danger-button>
                            <a href="{{ route('cash.index') }}" class="text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 underline">
                                {{ __('Cancelar') }}
                            </a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</x-app-layout>
