@extends('admin.masterAdmin')
@section('content')
    <div class="card">
        <div class="card-header">
            <h5>Add Service</h5>
        </div>
        <div class="card-body">
            <form action="{{ isset($service) ? route('service.update', $service->id) : route('service.store') }}"
                method="POST" enctype="multipart/form-data">
                @csrf
                @if (isset($service))
                    @method('PUT')
                @endif

                <div class="mb-3">
                    <label>Title</label>
                    <input type="text" name="title" class="form-control" value="{{ old('title', $service->title ?? '') }}"
                        required>
                </div>

                <div class="mb-3">
                    <label>Subtitle</label>
                    <input type="text" name="subtitle" class="form-control"
                        value="{{ old('subtitle', $service->subtitle ?? '') }}">
                </div>

                <div class="mb-3">
                    <label>Short Description</label>
                    <textarea name="short_description" class="form-control" rows="2">{{ old('short_description', $service->short_description ?? '') }}</textarea>
                </div>

                <div class="mb-3">
                    <label>Description</label>
                    <textarea name="description" class="form-control" rows="4">{{ old('description', $service->description ?? '') }}</textarea>
                </div>

                <div class="mb-3">
                    <label>Category</label>
                    <select name="category_id" class="form-control" required>
                        <option value="">Select Category</option>
                        @foreach ($categories as $category)
                            <option value="{{ $category->id }}"
                                {{ old('category_id', $service->category_id ?? '') == $category->id ? 'selected' : '' }}>
                                {{ $category->name }}
                            </option>
                        @endforeach
                    </select>
                </div>

                <div class="mb-3">
                    <label>Image</label>
                    <input type="file" name="image" accept="image/*" class="form-control">
                    @if (isset($service) && $service->image)
                        <div class="mt-2">
                            <img src="{{ asset('storage/' . $service->image) }}" alt="Service Image" width="120">
                        </div>
                    @endif
                </div>

                <button class="btn btn-success mt-3">{{ isset($service) ? 'Update' : 'Save' }}</button>
                <a href="{{ route('service.index') }}" class="btn btn-secondary mt-3">Cancel</a>
            </form>

        </div>
    </div>
@endsection
