@extends('layouts.app')
@section('title', 'Transactions ')
@section('content')
    <!-- Main Content -->
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h4>Transactions</h4>
                    <div class="card-header-form">
                        <x-search-bar route="{{ route('transactions.index') }}" />
                    </div>
                </div>
                <div class="card-body p-2">
                    <div class="table-responsive">
                        <table id="myTable" class="table table-striped">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Name</th>
                                    <th>phone</th>
                                    <th>Type</th>
                                    <th>Purpose</th>
                                    <th>Amount (₹)</th>
                                    <th>Created At</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach ($transactions as $transaction)
                                    <tr>
                                        <td> <span class="badge badge-primary">{{ $transaction->id }}</span></td>
                                        <td>{{ $transaction->user->name }}</td>
                                        <td>{{ $transaction->user->phone }}</td>
                                        <td>
                                            <span class="badge badge-info"> {{ $transaction->type }}</span>
                                        </td>
                                        <td>
                                            <span class="badge badge-info">
                                                {{ str_replace('_', ' ', $transaction->purpose) }}</span>
                                        </td>
                                        <td>{{ number_format($transaction->amount) }}</td>
                                        <td>{{ $transaction->created_at->format('h:m a d-m-y') }}</td>
                                    </tr>
                                @endforeach
                            </tbody>
                        </table>
                        {{ $transactions->links() }}
                        @unless (filled($transactions))
                            <div class="mx-4 my-4 d-flex justify-content-center">
                                <h5> No transactions added yet.</h5>
                            </div>
                        @endunless
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
