@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">Edit Service</h5>
    </div>

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

        <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', $service->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', $service->name) }}" required>
        </div>

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

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

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

        @if($isAdminOrSuper)
          <div class="col-12 form-check">
            <input class="form-check-input" type="checkbox" name="is_active" value="1" @checked($service->is_active)>
            <label class="form-check-label">Active</label>
          </div>
        @else
          <div class="col-md-6">
            <label class="form-label">Status</label>
            <div>
              <span class="badge bg-label-{{ $service->is_active ? 'success' : 'warning' }}">
                {{ $service->is_active ? 'Active' : 'Pending' }}
              </span>
            </div>
          </div>
        @endif

        <div class="col-12">
          <button class="btn btn-primary">Update</button>
        </div>
      </form>

      <form method="POST" action="{{ route('admin.services.destroy', $service) }}" class="mt-3">
        @csrf
        @method('DELETE')
        <button class="btn btn-outline-danger">Delete</button>
      </form>
    </div>
  </div>
</div>
@endsection
