<link href="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.18/summernote-bs4.min.css" rel="stylesheet">


    <!-- Include Bootstrap JS (Optional, if not already included) -->
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>

    <!-- Include Summernote JS -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.18/summernote-bs4.min.js"></script>
<!-- /.card-header -->
<div class="card-body">
    <form id="validation2" action="{{route('admin::save_product')}}" method="POST" enctype="multipart/form-data">
        @csrf


        <div class="row">
    <div class="col-sm-12">
        <div class="form-group">
            <label>Select Main Category</label>
            <select name="maincatid" class="form-control" id="main_cat_idd">
                <option value="">Select...</option>
                @foreach($maincatlist as $cat)
                <option value="{{$cat->id}}">{{$cat->maincategory}}</option>
                @endforeach
            </select>
        </div>
        @if ($errors->has('maincatid'))
        <span class="alert alert-danger">{{ $errors->first('maincatid') }}</span>
        @endif
    </div>
</div>
<br>

<div class="row">
    <div class="col-sm-12">
        <div class="form-group">
            <label>Select Sub Category</label>
            <select name="subcatid" class="form-control" id="subcat_idd">
                <option value="">Select...</option>
            </select>
        </div>
        @if ($errors->has('subcatid'))
        <span class="alert alert-danger">{{ $errors->first('subcatid') }}</span>
        @endif
    </div>
</div>

<div class="row">
    <div class="col-sm-12">
        <div class="form-group">
            <label>Select Child Category</label>
            <select name="childcatid" class="form-control" id="childcat_idd">
                <option value="">Select...</option>
            </select>
        </div>
        @if ($errors->has('childcatid'))
        <span class="alert alert-danger">{{ $errors->first('childcatid') }}</span>
        @endif
    </div>
</div>


        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label for="exampleInputFile">Product image</label><span style="color:red;">*</span>
                    <div class="input-group">
                        <div class="custom-file">
                            <input type="file" class="custom-file-input" name="product_image" id="exampleInputFile">
                            <label class="custom-file-label" for="exampleInputFile">Choose file</label>
                        </div>
                        <div class="input-group-append">
                            <span class="input-group-text">Upload</span>
                        </div>
                    </div>
                </div>

                @if ($errors->has('product_image'))
                <span class="alert alert-danger">{{ $errors->first('product_image') }}</span>
                @endif
            </div>
        </div>
        <br>


        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label>Product Name</label>
                    <input type="text" name="product_name" class=" form-control" placeholder="Enter ...">
                </div>
                @if ($errors->has('product_name'))
                <span class="alert alert-danger">{{ $errors->first('product_name') }}</span>
                @endif


            </div>
        </div>
        <br>


        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label>Product Code</label>
                    <input type="text" name="product_code" class=" form-control" placeholder="Enter ...">
                </div>
                @if ($errors->has('product_code'))
                <span class="alert alert-danger">{{ $errors->first('product_code') }}</span>
                @endif


            </div>
        </div>
        <br>

        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label>Product Quantity</label>
                    <input type="text" name="product_quantity" class=" form-control" placeholder="Enter ...">
                </div>
                @if ($errors->has('product_quantity'))
                <span class="alert alert-danger">{{ $errors->first('product_quantity') }}</span>
                @endif


            </div>
        </div>
        <br>



        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label>Product Original Price</label>
                    <input type="text" name="product_orgprice" class=" form-control" placeholder="Enter ...">
                </div>
                @if ($errors->has('product_orgprice'))
                <span class="alert alert-danger">{{ $errors->first('product_orgprice') }}</span>
                @endif


            </div>
        </div>
        <br>



        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label>Product Sale Price</label>
                    <input type="text" name="product_saleprice" class=" form-control" placeholder="Enter ...">
                </div>
                @if ($errors->has('product_saleprice'))
                <span class="alert alert-danger">{{ $errors->first('product_saleprice') }}</span>
                @endif


            </div>
        </div>
        <br>


        <div class="row">
            <div class="col-sm-12">

                <div class="form-group">
                    <label>Product Description</label><span style="color:#ff0000;">*</span>
                    <textarea name="product_dec" class="summernote" placeholder="Enter ..."></textarea>
                </div>
                @if ($errors->has('product_dec'))
                <span class="alert alert-danger">{{ $errors->first('product_dec') }}</span>
                @endif
            </div>
        </div>




        <div class="row">

            <div class="col-md-12">
                <div class="form-group" style="text-align:center">
                    <input type="submit" value="Submit" class="btn btn-primary">
                </div>
            </div>
        </div>
    </form>
</div>

<!-- /.card-body -->
<script type="text/javascript">
    jQuery("#validation2").validationEngine({
        promptPosition: 'inline'
    });
    $('.select2').select2();
</script>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<script>
    $(document).ready(function () {
        $('#main_cat_idd').change(function () {
            var mainCatId = $(this).val();
            if (mainCatId) {
                $.ajax({
                    type: "GET",
                    url: "{{ route('admin::getSubcategorieslist') }}",
                    data: {main_cat_id: mainCatId},
                    success: function (res) {
                        if (res) {
                            $("#subcat_idd").empty();
                            $("#subcat_idd").append('<option value="">Select...</option>');
                            $.each(res, function (key, value) {
                                $("#subcat_idd").append('<option value="' + key + '">' + value + '</option>');
                            });
                            $("#childcat_idd").empty(); // Clear child category when main category changes
                            $("#childcat_idd").append('<option value="">Select...</option>');
                        } else {
                            $("#subcat_idd").empty();
                            $("#childcat_idd").empty();
                        }
                    }
                });
            } else {
                $("#subcat_idd").empty();
                $("#childcat_idd").empty();
            }
        });

        $('#subcat_idd').change(function () {
            var subCatId = $(this).val();
            if (subCatId) {
                $.ajax({
                    type: "GET",
                    url: "{{ route('admin::getChildcategorieslist') }}",
                    data: {sub_cat_id: subCatId},
                    success: function (res) {
                        if (res) {
                            $("#childcat_idd").empty();
                            $("#childcat_idd").append('<option value="">Select...</option>');
                            $.each(res, function (key, value) {
                                $("#childcat_idd").append('<option value="' + key + '">' + value + '</option>');
                            });
                        } else {
                            $("#childcat_idd").empty();
                        }
                    }
                });
            } else {
                $("#childcat_idd").empty();
            }
        });
    });
</script>