<!-- Main content -->
<?php if (isset($component)) { $__componentOriginal566f40242755341fef381206827a6570 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal566f40242755341fef381206827a6570 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.admin.contents','data' => []] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>
<?php $component->withName('admin.contents'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag && $constructor = (new ReflectionClass(Illuminate\View\AnonymousComponent::class))->getConstructor()): ?>
<?php $attributes = $attributes->except(collect($constructor->getParameters())->map->getName()->all()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
     <?php $__env->slot('title', null, []); ?> <?php echo e($data['title']); ?> <?php $__env->endSlot(); ?>
     <?php $__env->slot('menuOpen', null, []); ?> <?php echo e($data['menuOpen']); ?>  <?php $__env->endSlot(); ?>
     <?php $__env->slot('menuActive', null, []); ?> <?php echo e($data['menuActive']); ?>  <?php $__env->endSlot(); ?>
     <?php $__env->slot('page', null, []); ?> <?php echo e($data['page']); ?> <?php $__env->endSlot(); ?>
     <?php $__env->slot('head', null, []); ?> 
        <link rel="stylesheet" href="<?php echo e(asset('')); ?>assets/admin/plugins/icheck-bootstrap/icheck-bootstrap.min.css">
        <link rel="stylesheet" href="<?php echo e(asset('')); ?>assets/admin/plugins/sweetalert2/sweetalert2.min.css">
     <?php $__env->endSlot(); ?>


    <section class="content">

        <!-- Default box -->
        <div class="row">
            <div class="col-lg-12">
                <?php if (isset($component)) { $__componentOriginal88b0e6813f5b80100a19437aa80e29ba = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal88b0e6813f5b80100a19437aa80e29ba = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.message','data' => []] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>
<?php $component->withName('message'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag && $constructor = (new ReflectionClass(Illuminate\View\AnonymousComponent::class))->getConstructor()): ?>
<?php $attributes = $attributes->except(collect($constructor->getParameters())->map->getName()->all()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?> <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal88b0e6813f5b80100a19437aa80e29ba)): ?>
<?php $attributes = $__attributesOriginal88b0e6813f5b80100a19437aa80e29ba; ?>
<?php unset($__attributesOriginal88b0e6813f5b80100a19437aa80e29ba); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal88b0e6813f5b80100a19437aa80e29ba)): ?>
<?php $component = $__componentOriginal88b0e6813f5b80100a19437aa80e29ba; ?>
<?php unset($__componentOriginal88b0e6813f5b80100a19437aa80e29ba); ?>
<?php endif; ?>
                <div class="card card-primary card-outline">
                    <div class="card-header">
                        <button class="btn btn-primary float-right" data-toggle="modal" data-target="#tambah"><i
                                class="fa fa-plus-circle mr-2"></i>
                            Item
                            Baru</button>
                        <h3 class="card-title"><i class="fa fa-server text-primary"></i> <?php echo e($data['page']); ?></h3>
                    </div>
                    <div class="card-body">
                        <form class="form-inline float-right">
                            <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search"
                                name="cari">
                            <button class="btn btn-primary " type="submit"> <i class="fa fa-search mr-2"></i>
                                Cari!</button>
                        </form>


                        <button class="btn btn-default shadow-sm">
                            <div class="icheck-blue d-inline " style="margin-right: -7px">
                                <input type="checkbox" id="cekall">
                                <label for="cekall">
                                </label>
                            </div>
                        </button>
                        <button class="btn btn-danger" id="pilih_hapus"><i class="fa fa-trash"></i> Hapus</button>
                        <table class="table table-bordered table-hover myTable tab mt-2">
                            <thead>
                                <tr>
                                    <th width="2%">No</th>
                                    <th width="5%">#</th>
                                    <th width="5%">#</th>
                                    <th>Kode Item</th>
                                    <th>Nama Item</th>
                                    <th>Stok</th>
                                    <th>Ditukar</th>
                                    <th>Poin Penukaran</th>
                                    <th>Tgl. Input</th>
                                    <th width="20%">Opsi</th>
                                </tr>
                            </thead>
                            <tbody id="view">
                                <?php $__empty_1 = true; $__currentLoopData = $hadiah; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $h): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                    <tr>
                                        <td class="text-center"><?php echo e($no++); ?></td>
                                        <td class="text-center">
                                            <div class="icheck-blue d-inline " style="margin-right: -7px">
                                                <input type="checkbox" name="id[]" id="cek<?php echo e($h->id); ?>"
                                                    class="ceklis" value="<?php echo e($h->id); ?>">
                                                <label for="cek<?php echo e($h->id); ?>">
                                                </label>
                                            </div>
                                        </td>
                                        <td class="text-center">
                                            <img alt="Avatar" class="table-avatar"
                                                src="<?php echo e(asset('/storage/produk/' . $h->gambar)); ?>" width="40px">
                                        </td>
                                        <td><?php echo e($h->kd_hadiah); ?></td>
                                        <td><?php echo e($h->nm_hadiah); ?></td>
                                        <td class="text-center"> <?php echo e($h->stok - stok_item($h->kd_hadiah)); ?>

                                        </td>
                                        <td class="text-center"><?php echo e(stok_item($h->kd_hadiah)); ?></td>
                                        <td class="text-center"><?php echo e($h->poin); ?></td>
                                        <td><?php echo e(tgl_inf($h->created_at)); ?> </td>
                                        <td class="text-center">
                                            <button class="btn btn-sm btn-primary" data-toggle="modal"
                                                data-target="#edit<?php echo e($h->id); ?>"><i class="fa fa-edit mr-2"></i>
                                                Edit</button>
                                            <button class="btn btn-sm btn-danger hapus" data-nm="<?php echo e($h->nm_hadiah); ?>"
                                                data-id="<?php echo e($h->id); ?>"><i class="fa fa-trash mr-2"></i>
                                                Hapus</button>
                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                    <tr>
                                        <td colspan="10" class="text-center">Data masih kosong</td>
                                    </tr>
                                <?php endif; ?>
                            </tbody>
                        </table>
                        <?php echo e($hadiah->links('components.admin.pagination')); ?>

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


        </div>
        <!-- /.card -->

    </section>

    
    <div class="modal fade" id="tambah">
        <div class="modal-dialog ">
            <div class="modal-content">
                <div class="modal-header bg-primary ">
                    Tambah Item Hadiah Baru
                </div>
                <form action="<?php echo e(route('hadiah-point.store')); ?>" method="post" enctype="multipart/form-data">
                    <?php echo csrf_field(); ?>
                    <div class="modal-body">

                        <div class="form-group">
                            <label>Kode Item</label>
                            <input type="text" name="kd_hadiah" class="form-control" placeholder="Kode Item"
                                autofocus required value="<?php echo e(old('kd_hadiah')); ?>">
                            <?php $__errorArgs = ['kd_hadiah'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                <small class="text-danger mt-2">
                                    <?php echo e($message); ?>

                                </small>
                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                        </div>

                        <div class="form-group">
                            <label>Nama Item</label>
                            <input type="text" name="nm_hadiah" class="form-control" placeholder="Nama Item" required
                                value="<?php echo e(old('nm_hadiah')); ?>">
                        </div>

                        <div class="row">
                            <div class="col-md-6">

                                <div class="form-group">
                                    <label>Stok Item</label>
                                    <input type="text" name="stok" class="form-control numbers"
                                        placeholder="0 Item" required value="<?php echo e(old('stok')); ?>">
                                </div>

                            </div>

                            <div class="col-md-6">

                                <div class="form-group">
                                    <label>Poin Penukaran</label>
                                    <input type="text" name="poin" class="form-control numbers"
                                        placeholder="0 Poin" required value="<?php echo e(old('poin')); ?>">

                                </div>

                            </div>

                        </div>

                        <div class="form-group">
                            <label>Deskripsi</label>
                            <textarea name="keterangan" id="" class="form-control" required><?php echo e(old('keterangan')); ?></textarea>
                        </div>

                        <div class="form-group">
                            <label>Gambar </label>
                            <div class="custom-file">
                                <input type="file" name="gambar" class="custom-file-input exampleInputFile"
                                    id="exampleInputFile">
                                <label class="custom-file-label" for="exampleInputFile">Cari
                                    file</label>
                                <?php $__errorArgs = ['gambar'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                    <small class="text-danger mt-2">
                                        <?php echo e($message); ?>

                                    </small>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>
                            <br>
                            <br>

                        </div>
                        <div class="d-flex justify-content-center">
                            <div style="height: 180px; width: 40%; border:1px solid  #eaedf0" class="gambar"></div>
                        </div>

                    </div>
                    <div class="modal-footer justify-content-between">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        <button type="submit" class="btn btn-primary"><i class="fa fa-save mr-2"></i>Simpan</button>
                    </div>
                </form>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <?php $__currentLoopData = $hadiah; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $h): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <div class="modal fade" id="edit<?php echo e($h->id); ?>">
            <div class="modal-dialog ">
                <div class="modal-content">
                    <div class="modal-header bg-primary ">
                        Edit Item Hadiah
                    </div>
                    <form action="<?php echo e(route('hadiah-point.update')); ?>" method="post" enctype="multipart/form-data">
                        <?php echo csrf_field(); ?>
                        <?php echo method_field('put'); ?>
                        <div class="modal-body">
                            <input type="hidden" name="id" value="<?php echo e($h->id); ?>">
                            <input type="hidden" name="kdlama" value="<?php echo e($h->kd_hadiah); ?>">
                            <input type="hidden" name="gbrlama" value="<?php echo e($h->gambar); ?>">

                            <div class="form-group">
                                <label>Kode Item</label>
                                <input type="text" name="kd_hadiah" class="form-control" placeholder="Kode Item"
                                    autofocus required value="<?php echo e($h->kd_hadiah); ?>">
                                <?php $__errorArgs = ['kd_hadiah'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                    <small class="text-danger mt-2">
                                        <?php echo e($message); ?>

                                    </small>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>

                            <div class="form-group">
                                <label>Nama Item</label>
                                <input type="text" name="nm_hadiah" class="form-control" placeholder="Nama Item"
                                    required value="<?php echo e($h->nm_hadiah); ?>">
                            </div>

                            <div class="row">
                                <div class="col-md-6">

                                    <div class="form-group">
                                        <label>Stok Item</label>
                                        <input type="text" name="stok" class="form-control numbers"
                                            placeholder="0 Item" required value="<?php echo e($h->stok); ?>">
                                    </div>

                                </div>

                                <div class="col-md-6">

                                    <div class="form-group">
                                        <label>Poin Penukaran</label>
                                        <input type="text" name="poin" class="form-control numbers"
                                            placeholder="0 Poin" required value="<?php echo e($h->poin); ?>">

                                    </div>

                                </div>

                            </div>

                            <div class="form-group">
                                <label>Deskripsi</label>
                                <textarea name="keterangan" id="" class="form-control" required><?php echo e($h->keterangan); ?></textarea>
                            </div>

                            <div class="form-group">
                                <label>Gambar </label>
                                <div class="custom-file">
                                    <input type="file" name="gambar" data-id="<?php echo e($h->id); ?>"
                                        class="custom-file-input exampleInputFile" id="exampleInputFile">
                                    <label class="custom-file-label" for="exampleInputFile">Cari
                                        file</label>
                                    <?php $__errorArgs = ['gambar'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                        <small class="text-danger mt-2">
                                            <?php echo e($message); ?>

                                        </small>
                                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>
                                <br>
                                <br>

                            </div>
                            <div class="d-flex justify-content-center">
                                <div style="height: 180px; width: 40%; border:1px solid  #eaedf0" class="gambar">
                                    <img alt="Avatar" class="table-avatar"
                                        src="<?php echo e(asset('/storage/produk/' . $h->gambar)); ?>" width="100%"
                                        id="img<?php echo e($h->id); ?>">
                                </div>
                            </div>

                        </div>
                        <div class="modal-footer justify-content-between">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                            <button type="submit" class="btn btn-primary"><i class="fa fa-save mr-2"></i>Edit
                                Item</button>
                        </div>
                    </form>
                </div>
                <!-- /.modal-content -->
            </div>
            <!-- /.modal-dialog -->
        </div>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

     <?php $__env->slot('foot', null, []); ?> 
        <script src="<?php echo e(asset('assets/')); ?>/admin/plugins/bs-custom-file-input/bs-custom-file-input.min.js"></script>

        <script src="<?php echo e(asset('')); ?>assets/admin/plugins/sweetalert2/sweetalert2.all.min.js"></script>
        <script>
            bsCustomFileInput.init();

            $(".exampleInputFile").change(function() {
                var id = $(this).attr('data-id')
                filePreview(this, id);
            });

            function filePreview(input, id) {
                if (input.files && input.files[0]) {
                    var reader = new FileReader();
                    reader.onload = function(e) {
                        $('#img').remove();
                        $('#img' + id).remove();
                        $('.gambar').append('<img src="' + e.target.result +
                            '" width="100%" height="180px" id="img' + id + '">');
                    };
                    reader.readAsDataURL(input.files[0]);
                }
            }


            $('#view').on('click', '.hapus', function() {
                var id = $(this).attr('data-id');
                var nama = $(this).attr('data-nm');

                Swal.fire({
                    title: "Apa anda yakin?",
                    text: "Item  dengan Nama ( " + nama + " ) akan di hapus!",
                    icon: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#3085d6",
                    cancelButtonColor: "#d33",
                    confirmButtonText: "Ya, Hapus!"
                }).then((result) => {
                    if (result.isConfirmed) {
                        document.location.href = "delete-hadiah/" + id;
                    }
                });

            });

            $("#cekall").change(function() {
                if ($(this).prop("checked")) {
                    $(".ceklis").prop("checked", true);
                } else {
                    $(".ceklis").prop("checked", false);
                }
            });

            $("#pilih_hapus").click(function() {
                var allVals = [];
                $(".ceklis:checked").each(function() {
                    allVals.push($(this).val());
                });
                var token = $("meta[name='csrf-token']").attr("content");

                if (allVals.length <= 0) {
                    Toast.fire({
                        icon: "error",
                        title: "Ceklis data yang akan dihapus!!!.",
                    });
                } else {
                    Swal.fire({
                        title: "Pastikan dengan benar!",
                        text: "Data yang anda pilih akan dihapus!",
                        icon: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#3085d6",
                        cancelButtonColor: "#d33",
                        confirmButtonText: "Ya, Hapus!",
                    }).then((result) => {
                        if (result.isConfirmed) {
                            $.ajax({
                                type: "DELETE",
                                url: "deleteall-hadiah",
                                data: {
                                    allVals: allVals,
                                    _token: token,
                                },
                                beforeSend: function() {
                                    $("#pilih_hapus").html(
                                        '<i class="fas fa-spinner fa-spin"></i> Tunggu..'
                                    );
                                    $("#pilih_hapus").attr("disabled", true);
                                },
                                success: function(data) {
                                    // alert(data)
                                    $("#pilih_hapus").html(
                                        '<i class="fa fa-trash"></i>'
                                    );
                                    $("#pilih_hapus").attr("disabled", true);
                                    Swal.fire({
                                        icon: "success",
                                        title: "Berhasil",
                                        text: "Data berhasil dihapus!",
                                    }).then((result) => {
                                        if (result.isConfirmed) {
                                            document.location.href = "";
                                        }
                                    });
                                },
                            });
                        }
                    });
                }
            });
        </script>
     <?php $__env->endSlot(); ?>
 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal566f40242755341fef381206827a6570)): ?>
<?php $attributes = $__attributesOriginal566f40242755341fef381206827a6570; ?>
<?php unset($__attributesOriginal566f40242755341fef381206827a6570); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal566f40242755341fef381206827a6570)): ?>
<?php $component = $__componentOriginal566f40242755341fef381206827a6570; ?>
<?php unset($__componentOriginal566f40242755341fef381206827a6570); ?>
<?php endif; ?>
<?php /**PATH /Applications/XAMPP/xamppfiles/htdocs/e-CommerceLv11/resources/views/admin/hadiah/hadiah_poin.blade.php ENDPATH**/ ?>