<?php $menu = app('App\Models\Other\Other'); ?>

<?php $__env->startSection('container'); ?>
    <div class="row">
        <!-- left column -->
        <div class="col-md-12">
            <!-- jquery validation -->
            <?php if(session()->has('error')): ?>
                <div class="alert alert-danger text-center">
                    <?php echo e(session()->get('error')); ?>

                </div>
            <?php endif; ?>
            <?php if(session()->has('success')): ?>
                <div class="alert alert-success text-center">
                    <?php echo e(session()->get('success')); ?>

                </div>
            <?php endif; ?>
            <div class="card card-primary">
                <div class="card-header">
                    <h3 class="card-title">เพิ่มข้อมูลสินค้า</h3>
                </div>
                <!-- /.card-header -->
                <!-- form start -->
                <form action="<?php echo e(route('products.store')); ?>" method="post" enctype="multipart/form-data">
                    <?php echo csrf_field(); ?>
                    <div class="card-body">
                        <div class="form-group">
                            <label for="exampleInputEmail1">ชื่อสินค้า <small class="text-danger">*</small></label>
                            <input type="text" name="products_name" class="form-control" id="products_name"
                                placeholder="ชื่อสินค้า" value="<?php echo e(old('products_name')); ?>">
                            <small class="text-danger"><?php echo e($errors->first('products_name')); ?></small>
                        </div>
                        <div class="form-group">
                            <label for="exampleInputEmail1">ราคา <small class="text-danger">*</small></label>
                            <input type="number" name="products_price" class="form-control" id="products_price"
                                placeholder="ราคา" value="<?php echo e(old('products_price')); ?>" step="any">
                            <small class="text-danger"><?php echo e($errors->first('products_price')); ?></small>
                        </div>
                        <div class="form-group">
                            <label for="exampleInputEmail1">หมวดหมู่ <small class="text-danger">*</small></label>
                            <?php
                                $datamenu = $menu->productmenu();
                            ?>
                            <select name="products_categorys" id="products_categorys" class="form-control">
                                <?php $__currentLoopData = $datamenu; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $rows): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($rows->id); ?>"><?php echo e($rows->categorys_names); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                            <small class="text-danger"><?php echo e($errors->first('products_categorys')); ?></small>
                        </div>
                        <div class="form-group">
                            <label for="exampleInputEmail1">คุณลักษณะ <small class="text-danger">*</small></label>
                            <input type="text" name="products_attribute" class="form-control" id="products_attribute"
                                placeholder="คุณลักษณะ" value="<?php echo e(old('products_attribute')); ?>">
                            <small class="text-danger"><?php echo e($errors->first('products_attribute')); ?></small>
                        </div>
                        <div class="form-group">
                            <label for="exampleInputEmail1">คุณสมบัติ <small class="text-danger">*</small></label>
                            <input type="text" name="products_detail" class="form-control" id="products_detail"
                                placeholder="คุณสมบัติ" value="<?php echo e(old('products_detail')); ?>">
                            <small class="text-danger"><?php echo e($errors->first('products_detail')); ?></small>
                        </div>
                        <div class="form-group">
                            <label for="exampleInputEmail1">การใช้งาน <small class="text-danger">*</small></label>
                            <input type="text" name="products_usability" class="form-control" id="products_usability"
                                placeholder="คุณลักษณะ" value="<?php echo e(old('products_usability')); ?>">
                            <small class="text-danger"><?php echo e($errors->first('products_usability')); ?></small>
                        </div>
                        <div class="form-group">
                            <label for="exampleInputEmail1">ข้อควรระวัง <small class="text-danger">*</small></label>
                            <input type="text" name="products_warning" class="form-control" id="products_warning"
                                placeholder="คุณลักษณะ" value="<?php echo e(old('products_warning')); ?>">
                            <small class="text-danger"><?php echo e($errors->first('products_warning')); ?></small>
                        </div>
                        <div class="form-group">
                            <label for="exampleInputEmail1">รูปภาพโชว์สินค้า <small class="text-danger">*</small></label>
                            <input class="form-control" type="file" id="files" name="files" onchange="previewFile()">
                            <small class="text-danger"><?php echo e($errors->first('files')); ?></small>
                            <span id="imgshow"></span>
                        </div>
                        <div class="form-group">
                            <label for="exampleInputEmail1">รูปภาพสินค้าทั้งหมด <span
                                    class="text-danger">(**สามารถอัพได้หลายไฟล์ กด Shift ค้างไว้ตอนเลือกรูปภาพ**)</span>
                                <small class="text-danger">*</small></label>
                            <input class="form-control" type="file" id="files_multi" name="files_multi[]"
                                onchange="previewFilesmulti()" multiple>
                            <small class="text-danger"><?php echo e($errors->first('files_multi')); ?></small>
                            <br />
                            <span id="imgshowmulti"></span>
                        </div>
                    </div>
                    <!-- /.card-body -->
                    <div class="card-footer text-center">
                        <a href="<?php echo e(asset('admin/products')); ?>"><button type="button"
                                class="btn btn-danger">ยกเลิก</button></a>
                        <button type="submit" class="btn btn-success">เพิ่มข้อมูล</button>
                    </div>

                </form>
            </div>
            <!-- /.card -->
        </div>
        <!--/.col (left) -->

    </div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('scriptadd'); ?>
    <script>
        function previewFile() {
            $("#imgshow").empty();
            const preview = document.querySelector('#imgshow');
            const file = document.querySelector('input[id=files]').files[0];
            const reader = new FileReader();

            reader.addEventListener("load", function() {
                var image = new Image();
                image.height = 300;
                image.title = file.name;
                image.src = this.result;
                preview.appendChild(image);
            }, false);

            if (file) {
                reader.readAsDataURL(file);
            }
        }

        function previewFilesmulti() {
            $("#imgshowmulti").empty();
            var preview = document.querySelector('#imgshowmulti');
            var files = document.querySelector('input[id=files_multi]').files;

            function readAndPreview(file) {
                // Make sure `file.name` matches our extensions criteria
                if (/\.(jpe?g|png|gif)$/i.test(file.name)) {
                    var reader = new FileReader();
                    reader.addEventListener("load", function() {
                        var image = new Image();
                        image.height = 300;
                        image.title = file.name;
                        image.src = this.result;
                        preview.appendChild(image);
                    }, false);

                    reader.readAsDataURL(file);
                }

            }

            if (files) {
                [].forEach.call(files, readAndPreview);
            }

        }
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layouts.main', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/thaiuppc/domains/thaiupp.com/public_html/site/resources/views/admin/form/products/products.blade.php ENDPATH**/ ?>