@extends('admin.layouts.main')

@section('section')
    <!-- Page sidebar end-->
    <div class="page-body">
        <div class="container-fluid">
            <div class="row page-title">
                <div class="col-sm-6">
                    <h3>{{ $title }}</h3>
                </div>
                <div class="col-sm-6">
                    <nav>
                        <ol class="breadcrumb justify-content-sm-end align-items-center">
                            <li class="breadcrumb-item">
                                <a href="{{ route('dashboard') }}">
                                    <svg class="svg-color">
                                        <use href="{{ asset('assets/svg/iconly-sprite.svg#Home') }}"></use>
                                    </svg>
                                </a>
                            </li>
                            <li class="breadcrumb-item">Category</li>
                            <li class="breadcrumb-item">Category List</li>
                            <li class="breadcrumb-item active">{{ $title }}</li>
                        </ol>
                    </nav>
                </div>
            </div>
        </div>

        <!-- Container-fluid starts-->
        <div class="container-fluid">
            <div class="row">
                <div class="col-sm-12">
                    <div class="card">
                        <div class="card-body">

                            <!-- Display Validation Errors -->
                            @if ($errors->any())
                                <div class="alert alert-danger">
                                    <ul>
                                        @foreach ($errors->all() as $error)
                                            <li>{{ $error }}</li>
                                        @endforeach
                                    </ul>
                                </div>
                            @endif

                            <form class="form theme-form" action="{{ $url }}" method="POST">
                                @csrf
                                @if (isset($category))
                                    @method('PUT')
                                @endif

                                <div class="row">
                                    <div class="col-md-6 mb-3">
                                        <label for="name">Category Name</label>
                                        <input class="form-control @error('name') is-invalid @enderror" id="name"
                                            type="text" name="name" value="{{ old('name', $category->name ?? '') }}"
                                            placeholder="Category name *">
                                    </div>

                                    <div class="col-md-6 mb-3">
                                        <label for="slug">Slug</label>
                                        <input class="form-control @error('slug') is-invalid @enderror" id="slug"
                                            type="text" name="slug" value="{{ old('slug', $category->slug ?? '') }}"
                                            placeholder="Slug (e.g., category-name)">
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-md-6 mb-3">
                                        <label for="status">Status</label>
                                        <select class="form-select @error('status') is-invalid @enderror" id="status"
                                            name="status">
                                            <option value="1" {{ old('status', $category->status ?? '') == '1' ? 'selected' : '' }}>Active</option>
                                            <option value="0" {{ old('status', $category->status ?? '') == '0' ? 'selected' : '' }}>Inactive</option>
                                        </select>
                                    </div>
                                    <div class="col-md-6 mb-3">
                                        <label for="meta_keywords">Meta Keywords</label>
                                        <input class="form-control @error('meta_keywords') is-invalid @enderror"
                                            id="meta_keywords" type="text" name="meta_keywords"
                                            value="{{ old('meta_keywords', $category->meta_keywords ?? '') }}"
                                            placeholder="Keyword1, Keyword2">
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-md-12 mb-3">
                                        <label for="meta_description">Meta Description</label>
                                        <input class="form-control @error('meta_description') is-invalid @enderror"
                                            id="meta_description" type="text" name="meta_description"
                                            value="{{ old('meta_description', $category->meta_description ?? '') }}"
                                            placeholder="Short meta description">
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-12 mb-3">
                                        <label for="disc">Enter some Details</label>
                                        <textarea id="disc" class="form-control @error('description') is-invalid @enderror"
                                            rows="5" name="description"
                                            placeholder="Description">{{ old('description', $category->description ?? '') }}</textarea>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col text-end">
                                        <button class="btn btn-success me-3" type="submit">Save</button>
                                        <a class="btn btn-danger" href="{{ route('category.list') }}">Cancel</a>
                                    </div>
                                </div>
                            </form>

                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- Container-fluid ends -->
    </div>
@endsection