@extends('backend.layouts.app')
@section('content')
<div class="content-wrapper">
  <section class="content-header">
    <div class="container-fluid">
      <div class="row mb-2">
        <div class="col-sm-6 pb-2 pb-sm-0"><h1>Subscription Plans</h1></div>
        <div class="col-sm-6 text-sm-right">
          <a href="{{ url('admin/subscription-plans/add') }}" class="btn btn-primary">Add Plan</a>
          <a href="{{ url('admin/user-subscriptions') }}" class="btn btn-info ml-2">User Subscriptions</a>
        </div>
      </div>
    </div>
  </section>
  <section class="content">
    <div class="container-fluid">
      @if(session('success'))<div class="alert alert-success">{{ session('success') }}</div>@endif
      <div class="row">
        <div class="col-md-12">
          <div class="card">
            <div class="card-body table-responsive p-3">
              <table id="planTable" style="width:100%;" class="table table-striped">
                <thead>
                  <tr>
                    <th>S.No.</th><th>Name</th><th>Price</th><th>Duration</th>
                    <th>Subscribers</th><th>Status</th><th>Actions</th>
                  </tr>
                </thead>
                <tbody></tbody>
              </table>
            </div>
          </div>
        </div>
      </div>
    </div>
  </section>
</div>
@endsection
@push('scripts')
<script>
$(document).ready(function () {
  $('#planTable').DataTable({
    processing: true, serverSide: true,
    ajax: { url: '{{ route('admin.subscription-plans.index') }}' },
    columns: [
      { data: null, orderable: false, searchable: false, render: (d,t,r,m) => m.row+1 },
      { data: 'name', name: 'name' },
      { data: 'price', name: 'price' },
      { data: 'duration_days', name: 'duration_days', render: d => d + ' days' },
      { data: 'subscribers', name: 'subscribers', orderable: false, searchable: false },
      { data: 'is_active', name: 'is_active' },
      { data: 'actions', name: 'actions', orderable: false, searchable: false },
    ],
    responsive: true,
  });
});
</script>
@endpush
