@extends('layouts.app')

@section('content')
<div class="container-xxl flex-grow-1 container-p-y">
  <div class="card">
    <div class="card-header">
      <h5 class="mb-0">Create Service</h5>
    </div>

    <div class="card-body">
      <form method="POST" action="{{ route('admin.services.store') }}" class="row g-3">
        @csrf

        <div class="col-md-6">
          <label class="form-label">Category</label>
          <select name="category_id" class="form-select" required>
            @foreach($categories as $category)
              <option value="{{ $category->id }}" @selected((int) old('category_id') === (int) $category->id)>
                {{ $category->name }}
              </option>
            @endforeach
          </select>
        </div>

        <div class="col-md-6">
          <label class="form-label">Name</label>
          <input name="name" class="form-control" value="{{ old('name') }}" required>
        </div>

        <div class="col-md-6">
          <label class="form-label">Slug</label>
          <input name="slug" class="form-control" value="{{ old('slug') }}">
        </div>

        <div class="col-md-6">
          <label class="form-label">Logo URL</label>
          <input name="logo" class="form-control" value="{{ old('logo') }}">
        </div>

        <div class="col-12">
          <label class="form-label">Description</label>
          <textarea name="description" class="form-control">{{ old('description') }}</textarea>
        </div>

        @if($isAdminOrSuper)
          <div class="col-12 form-check">
            <input class="form-check-input" type="checkbox" name="is_active" value="1" checked>
            <label class="form-check-label">Active</label>
          </div>
        @else
          <div class="col-12">
            <div class="alert alert-warning mb-0">
              New service will be created as <strong>Pending</strong>. Admin or Super Admin will activate it.
            </div>
          </div>
        @endif

        @if($categories->isEmpty())
          <div class="col-12">
            <div class="alert alert-danger mb-0">
              No category available. Create your category first.
            </div>
          </div>
        @endif

        <div class="col-12">
          <button class="btn btn-primary" @disabled($categories->isEmpty())>Save</button>
        </div>
      </form>
    </div>
  </div>
</div>
@endsection
