@include('includes.header')

<div class="page-wrapper">
    <div class="page-content">

        <!-- Page Header + Controls -->
        <div class="card border-0 shadow-sm mb-3">
            <div class="card-body d-flex justify-content-between align-items-center">

                <div>
                    <h5 class=" mb-0 text-uppercase">Add Product</h5>
                    <small class="text-muted">Create a new Product</small>
                </div>

                <a href="{{ route('store.product.index') }}" class="btn btn-outline-secondary btn-sm">
                    <i class="bx bx-arrow-back"></i> Back
                </a>

            </div>


            <!-- Form Card -->
            <div class="card border-0 shadow-sm">
                <div class="card-body p-4">

                    <form action="{{ route('store.product.store') }}" method="POST" enctype="multipart/form-data">
                        @csrf

                        <div class="row g-3">

                            <!-- Category -->
                            <div class="col-md-6">
                                <label class="form-label">Category</label>
                                <select name="category_id"
                                    class="form-control @error('category_id') is-invalid @enderror">
                                    <option value="">Select Category</option>
                                    @foreach ($category as $cat)
                                        <option value="{{ $cat->id }}"
                                            {{ old('category_id') == $cat->id ? 'selected' : '' }}>
                                            {{ $cat->name }}
                                        </option>
                                    @endforeach
                                </select>
                                @error('category_id')
                                    <small class="text-danger">{{ $message }}</small>
                                @enderror
                            </div>

                            <!-- Product Name -->
                            <div class="col-md-6">
                                <label class="form-label">Product Name</label>
                                <input type="text" name="name" value="{{ old('name') }}"
                                    class="form-control @error('name') is-invalid @enderror"
                                    placeholder="Enter product name">
                                @error('name')
                                    <small class="text-danger">{{ $message }}</small>
                                @enderror
                            </div>

                            <!-- Main Image -->
                            <div class="col-md-6">
                                <label class="form-label">Main Image</label>
                                <input type="file" name="image"
                                    class="form-control @error('image') is-invalid @enderror">
                                @error('image')
                                    <small class="text-danger">{{ $message }}</small>
                                @enderror
                            </div>

                            <!-- Gallery -->
                            <div class="col-md-6">
                                <label class="form-label">Gallery (Max 5 Images)</label>
                                <input type="file" name="gallery[]" multiple
                                    class="form-control @error('gallery') is-invalid @enderror @error('gallery.*') is-invalid @enderror">

                                @error('gallery')
                                    <small class="text-danger">{{ $message }}</small>
                                @enderror

                                @error('gallery.*')
                                    <small class="text-danger">{{ $message }}</small>
                                @enderror
                            </div>

                            <!-- Purity -->
                            <div class="col-md-6">
                                <label class="form-label">Purity</label>
                                <input type="text" name="purity" value="{{ old('purity') }}"
                                    class="form-control @error('purity') is-invalid @enderror" placeholder="Eg: 22K">
                                @error('purity')
                                    <small class="text-danger">{{ $message }}</small>
                                @enderror
                            </div>

                            <!-- Weight -->
                            <div class="col-md-6">
                                <label class="form-label">Weight</label>
                                <input type="text" name="weight" value="{{ old('weight') }}"
                                    class="form-control @error('weight') is-invalid @enderror" placeholder="Eg: 10g">
                                @error('weight')
                                    <small class="text-danger">{{ $message }}</small>
                                @enderror
                            </div>

                            <!-- Making Charge -->
                            <div class="row g-3">

                                <!-- Making Charge -->
                                <div class="col-md-4">
                                    <label class="form-label">Making Charge</label>
                                    <input type="number" name="making_charge" value="{{ old('making_charge') }}"
                                        placeholder="Enter making charge"
                                        class="form-control @error('making_charge') is-invalid @enderror">
                                    @error('making_charge')
                                        <small class="text-danger">{{ $message }}</small>
                                    @enderror
                                </div>

                                <!-- Price -->
                                <div class="col-md-4">
                                    <label class="form-label">Price</label>
                                    <input type="number" name="price" value="{{ old('price') }}"
                                        placeholder="Enter product price"
                                        class="form-control @error('price') is-invalid @enderror">
                                    @error('price')
                                        <small class="text-danger">{{ $message }}</small>
                                    @enderror
                                </div>

                                <!-- Stock -->
                                <div class="col-md-4">
                                    <label class="form-label">Stock</label>
                                    <input type="number" name="stock" value="{{ old('stock') }}"
                                        placeholder="Enter available stock"
                                        class="form-control @error('stock') is-invalid @enderror">
                                    @error('stock')
                                        <small class="text-danger">{{ $message }}</small>
                                    @enderror
                                </div>

                            </div>

                            <!-- Description -->
                            <div class="col-md-12">
                                <label class="form-label">Description</label>
                                <textarea name="description" class="form-control @error('description') is-invalid @enderror">{{ old('description') }}</textarea>
                                @error('description')
                                    <small class="text-danger">{{ $message }}</small>
                                @enderror
                            </div>

                        </div>

                        <div class="d-flex justify-content-end mt-4">
                            <a href="{{ route('store.product.index') }}" class="btn btn-light px-4">Cancel</a>
                            <button type="submit" class="btn btn-success px-4">Save</button>
                        </div>
                    </form>

                </div>
            </div>
        </div>
    </div>
</div>

@include('includes.footer')
