@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"><h1>Edit Plan</h1></div></div>
    </div>
  </section>
  <section class="content">
    <div class="container-fluid">
      <div class="row"><div class="col-md-12">
        <div class="card">
          <form action="{{ route('admin.subscription-plans.update') }}" method="post">
            @csrf
            <input type="hidden" name="plan_id" value="{{ $plan->id }}">
            <div class="card-body">
              @if($errors->any())
                <div class="alert alert-danger"><ul class="mb-0">@foreach($errors->all() as $e)<li>{{ $e }}</li>@endforeach</ul></div>
              @endif

              <div class="form-group">
                <label>Plan Name <span class="text-danger">*</span></label>
                <input type="text" class="form-control" name="name" value="{{ old('name', $plan->name) }}">
              </div>
              <div class="form-group">
                <label>Price (USD) <span class="text-danger">*</span></label>
                <input type="number" class="form-control" name="price" value="{{ old('price', $plan->price) }}" step="0.01" min="0">
              </div>
              <div class="form-group">
                <label>Duration (days) <span class="text-danger">*</span></label>
                <input type="number" class="form-control" name="duration_days" value="{{ old('duration_days', $plan->duration_days) }}" min="1">
              </div>
              <div class="form-group">
                <label>Features (one per line)</label>
                <textarea name="features" class="form-control" rows="5">{{ old('features', $plan->features ? implode("\n", $plan->features) : '') }}</textarea>
              </div>
              <div class="form-group">
                <label>Description</label>
                <textarea name="description" class="form-control" rows="3">{{ old('description', $plan->description) }}</textarea>
              </div>
              <div class="form-group">
                <label>Sort Order</label>
                <input type="number" class="form-control" name="sort_order" value="{{ old('sort_order', $plan->sort_order) }}" min="0">
              </div>
              <div class="form-group">
                <div class="custom-control custom-checkbox">
                  <input type="checkbox" class="custom-control-input" id="isActive" name="is_active" value="1" {{ $plan->is_active ? 'checked' : '' }}>
                  <label class="custom-control-label" for="isActive">Active</label>
                </div>
              </div>
            </div>
            <div class="card-footer">
              <button type="submit" class="btn btn-primary">Update Plan</button>
              <a href="{{ url('admin/subscription-plans') }}" class="btn btn-secondary ml-2">Cancel</a>
            </div>
          </form>
        </div>
      </div></div>
    </div>
  </section>
</div>
@endsection
