@extends('layouts.app')

@section('content')
    <x-common.page-breadcrumb pageTitle="{{ $title ?? 'Log Mutasi Kas' }}" />

    {{-- Back Button --}}
    <div class="mb-6">
        <a href="{{ route('finance.cash') }}" class="inline-flex items-center gap-2 text-sm text-gray-600 hover:text-gray-800 dark:text-gray-400 dark:hover:text-white">
            <svg class="size-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/>
            </svg>
            Kembali ke Laporan Kas
        </a>
    </div>

    {{-- Mutations Table --}}
    <div class="rounded-2xl border border-gray-200 bg-white dark:border-gray-800 dark:bg-white/[0.03]">
        <div class="border-b border-gray-200 px-5 py-4 dark:border-gray-800">
            <h3 class="text-lg font-semibold text-gray-800 dark:text-white/90">Riwayat Mutasi Kas</h3>
        </div>

        <div class="overflow-x-auto">
            <table class="w-full">
                <thead>
                    <tr class="border-b border-gray-200 bg-gray-50 dark:border-gray-800 dark:bg-gray-900/50">
                        <th class="px-5 py-3 text-left text-xs font-semibold uppercase text-gray-500">Tanggal</th>
                        <th class="px-5 py-3 text-left text-xs font-semibold uppercase text-gray-500">Dari</th>
                        <th class="px-5 py-3 text-left text-xs font-semibold uppercase text-gray-500">Ke</th>
                        <th class="px-5 py-3 text-right text-xs font-semibold uppercase text-gray-500">Jumlah</th>
                        <th class="px-5 py-3 text-left text-xs font-semibold uppercase text-gray-500">Catatan</th>
                        <th class="px-5 py-3 text-left text-xs font-semibold uppercase text-gray-500">Oleh</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-gray-200 dark:divide-gray-800">
                    @forelse($mutations as $mutation)
                    <tr class="hover:bg-gray-50 dark:hover:bg-white/[0.02]">
                        <td class="px-5 py-4 text-sm text-gray-600 dark:text-gray-400">{{ $mutation->mutation_date->format('d/m/Y') }}</td>
                        <td class="px-5 py-4">
                            <span class="inline-flex items-center rounded-full bg-gray-100 px-2 py-1 text-xs font-medium text-gray-700 dark:bg-gray-700 dark:text-gray-300">
                                {{ $mutation->getFromAccountLabel() }}
                            </span>
                        </td>
                        <td class="px-5 py-4">
                            <span class="inline-flex items-center rounded-full bg-brand-50 px-2 py-1 text-xs font-medium text-brand-700 dark:bg-brand-500/20 dark:text-brand-400">
                                {{ $mutation->getToAccountLabel() }}
                            </span>
                        </td>
                        <td class="px-5 py-4 text-right text-sm font-semibold text-gray-800 dark:text-white">Rp {{ number_format($mutation->amount, 0, ',', '.') }}</td>
                        <td class="px-5 py-4 text-sm text-gray-500 dark:text-gray-400">{{ $mutation->notes ?? '-' }}</td>
                        <td class="px-5 py-4 text-sm text-gray-600 dark:text-gray-400">{{ $mutation->user->name ?? '-' }}</td>
                    </tr>
                    @empty
                    <tr>
                        <td colspan="6" class="px-5 py-12 text-center text-sm text-gray-500">Belum ada mutasi kas</td>
                    </tr>
                    @endforelse
                </tbody>
            </table>
        </div>

        @if($mutations->hasPages())
        <div class="border-t border-gray-200 px-5 py-4 dark:border-gray-800">
            {{ $mutations->links() }}
        </div>
        @endif
    </div>
@endsection
