@extends('layouts.admin') @section('content')

<div class="row mb-4">
  <!-- ✅ Total SMS -->
  <div class="col-md-3">
    <div class="card border shadow-sm">
      <div class="card-body text-center p-3">
        <i class="fas fa-envelope fa-2x text-primary"></i>
        <h6 class="card-title mt-2 text-muted">Total SMS</h6>
        <p class="card-text fw-bold h5">{{ $total }}</p>
      </div>
    </div>
  </div>

  <!-- ✅ Successful SMS -->
  <div class="col-md-3">
    <div class="card border shadow-sm">
      <div class="card-body text-center p-3">
        <i class="fas fa-check-circle fa-2x text-success"></i>
        <h6 class="card-title mt-2 text-muted">Successful SMS</h6>
        <p class="card-text fw-bold h5">{{ $successful }}</p>
      </div>
    </div>
  </div>

  <!-- ✅ Failed SMS -->
  <div class="col-md-3">
    <div class="card border shadow-sm">
      <div class="card-body text-center p-3">
        <i class="fas fa-times-circle fa-2x text-danger"></i>
        <h6 class="card-title mt-2 text-muted">Failed SMS</h6>
        <p class="card-text fw-bold h5">{{ $failed }}</p>
      </div>
    </div>
  </div>

  <!-- ✅ SMS Usage -->
  <div class="col-md-3">
    <div class="card border shadow-sm">
      <div class="card-body text-center p-3">
        <i class="fas fa-chart-line fa-2x text-info"></i>
        <h6 class="card-title mt-2 text-muted">Usage Rate</h6>
        <p class="card-text fw-bold h5">{{ $usage }}%</p>
      </div>
    </div>
  </div>
</div>


<div class="card mb-3">
  <div class="card-body pt-0">
    <div class="col-lg-4 pt-3 pt-lg-0">
      <div class="d-flex flex-between-center mb-3">
        <div class="d-flex align-items-center">
          <div class="icon-item icon-item-sm bg-soft-primary shadow-none me-2 bg-soft-success"><span class="fas fa-calendar-week text-success"></span></div>
          <h6 class="mb-0">Search Per Date</h6>
        </div>
      </div>
      <div class="d-flex">
        <div class="d-flex">
          <form class="form-material" method="POST" action="{{ url('sms') }}">
            @csrf
            <br>
            <input type="date" value="{{ date('Y-m-d') }}" required class="form-control" name="start_date">
            <br>
            <input type="date" value="{{ date('Y-m-d') }}" required class="form-control" name="end_date">
            <br>
            <button type="submit" class="btn btn-primary btn-sm" aria-placeholder="Search"><i class="fas fa-search"></i>Submit</button>
          </form>
        </div>
      </div>
    </div>
  </div>
</div>
<div class="card mb-3">
  <div class="card-header">
    <div class="row flex-between-end">
      <div class="col-auto align-self-center">
        <form class="form-material" method="POST" action="{{ url ('/searchSms')}}">
          @csrf
          <input type="text" required class="form-control" placeholder="Search by Payment ID" name="search" id="search">
          <br>
          <button type="submit" class="btn btn-primary btn-sm"><i class="fas fa-search"></i> Advanced Search</button>
        </form>
      </div>

      <!-- ✅ Show "Resend Failed SMS" Button Only for Admins (Role 3) -->
      @if(Auth::user()->role == 3)
      <div class="col-auto">
        <a href="{{ route('admin.resend.failed.sms') }}" class="btn btn-danger btn-sm">
          <i class="fas fa-sync"></i> Resend Failed SMS
        </a>
      </div>
      @endif
    </div>
  </div>
  <div class="card-body pt-0">
    &nbsp;
    <br>
    <br>
    <h5 class="mb-0" data-anchor="data-anchor">List of all SMS Records</h5>
    <!-- Update the count and total based on your SMS model -->
    <p>Displaying {{ $smsRecords->count() }} of {{ $total}} SMS Records</p>
    <small>If you can't find the SMS record you are looking for, please use the advanced search option.</small>
    <!-- The table to display SMS records -->
    <div class="dt-responsive table-sm table-responsive">
      <small>
        <table id="order-table" class="table table-sm text-sm table-striped table-bordered nowrap">
          <thead class="bg-200 text-900">
            <tr>
              <th>#</th> <!-- ✅ New Column for Row Numbers -->
              <th>Action</th>
              <th>Destination Number</th>
              <th>Payment ID</th>
              <th>Policy #</th>
              <th>Date Sent</th>
            </tr>
          </thead>
          <tbody>
            @foreach ($smsRecords as $index => $sms)
            <tr>
              <td>{{ $index + 1 }}</td> <!-- ✅ Display Row Number -->
              <td><a class="btn-primary btn-sm" href="{{ url('/sms/' . $sms->id) }}">View</a></td>
              <td>{{ $sms->destination_number }} - @if($sms->status == 1)
                <span class="badge bg-success">Sent</span>
                @else
                <span class="badge bg-danger">Failed</span>
                @endif
              </td>
              <td>{{ $sms->payment_id }}</td>
              <td>{{ $sms->member->national_id }}</td>
              <td>{{ $sms->created_at->format('d-M-Y H:i:s') }}</td>
            </tr>
            @endforeach
          </tbody>
        </table>

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

<script>
  // Your delete script remains unchanged
</script>

@endsection