@extends('layouts.admin')

@section('content')
<div class="card mb-3">
  <div class="card-header">
    <h5 class="mb-0">Payment Patterns & Frequency</h5>
  </div>
  <div class="card-body">
    <!-- Date Filter Form -->
    <form method="GET" action="{{ url('/trends/payment-patterns') }}" class="row g-3 mb-4">
      <div class="col-md-4">
        <label for="start_date" class="form-label">Start Date</label>
        <input type="date" name="start_date" class="form-control"
               value="{{ $startDate ?? now()->format('Y-m-d') }}">
      </div>
      <div class="col-md-4">
        <label for="end_date" class="form-label">End Date</label>
        <input type="date" name="end_date" class="form-control"
               value="{{ $endDate ?? now()->format('Y-m-d') }}">
      </div>
      <div class="col-md-4 align-self-end">
        <button type="submit" class="btn btn-primary btn-sm">
          <i class="fas fa-search"></i> Filter
        </button>
      </div>
    </form>

    <!-- Table -->
    <div class="dt-responsive table-sm table-responsive">
      <table id="basic-btn" class="table table-sm table-striped table-bordered nowrap">
        <thead class="bg-200 text-900">
          <tr>
            <th>#</th>
            <th>Member Name</th>
            <th>Total Payments</th>
            <th>First Payment Date</th>
            <th>Last Payment Date</th>
            <th>Payments Per Month</th>
          </tr>
        </thead>
        <tbody>
          @foreach ($paymentPatterns as $row)
          <tr>
            <td>{{ $loop->iteration }}</td>
            <td>{{ $row->member_name }}</td>
            <td>{{ $row->total_payments }}</td>
            <td>{{ $row->first_payment_date }}</td>
            <td>{{ $row->last_payment_date }}</td>
            <td>{{ $row->payments_per_month }}</td>
          </tr>
          @endforeach
        </tbody>
      </table>
    </div>
  </div>
</div>
@endsection
