
<?php $__env->startSection('content'); ?>
    <div class="container-fluid">
        <!-- ========== title-wrapper start ========== -->
        <div class="title-wrapper pt-30">
            <div class="row align-items-center">
                <div class="col-md-6">
                    <div class="title">
                        <h2>Materi</h2>
                    </div>
                </div>
                <!-- end col -->
                <div class="col-md-6">
                    <div class="breadcrumb-wrapper">
                        <nav aria-label="breadcrumb">
                            <ol class="breadcrumb">
                                <li class="breadcrumb-item">
                                    <a href="#0">Materi</a>
                                </li>
                                <li class="breadcrumb-item">
                                    <a href="<?php echo e(URL::to('/materi-admin')); ?>">Dashboard</a>
                                </li>
                            </ol>
                        </nav>
                    </div>
                </div>
                <!-- end col -->
            </div>
            <!-- end row -->
        </div>
        <!-- ========== title-wrapper end ========== -->
        <div class="tables-wrapper">
            <div class="row">
                <div class="col-lg-12">
                    <div class="card-style mb-30">
                        <div class="d-flex justify-content-between mb-15">
                            <h6 class="mb-25">Materi</h6>
                            <a href="<?php echo e(URL::to('/materi-admin')); ?>" class="btn btn-sm btn-primary">Kembali</a>
                        </div>
                        <form action="<?php echo e(url('/materi/update')); ?>" method="POST" enctype="multipart/form-data">

                            <?php echo csrf_field(); ?>

                            <div class="select-style-1 w-50">
                                <label for="">kategori</label>
                                <div class="select-position">
                                    <select name="kategori">
                                        <?php $__currentLoopData = $kategori; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $p): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($p->id); ?>" <?php echo e($data->category_id == $p->id ? 'selected' : ''); ?>>
                                                <?php echo e($p->nama_kategori); ?>

                                            </option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                </div>
                            </div>



                            <div class="input-style-1">
                                <label>
                                    Judul
                                </label>
                                <input type="text" id="title" name="title" required value="<?php echo e($data->judul); ?>" />

                            </div>



                            <div class="input-style-1">
                                <label>
                                    Deskripsi
                                </label>
                                <textarea rows="10" id="description" name="description"><?php echo e($data->deskripsi); ?></textarea>

                            </div>

                            <div class="select-style-1">
                                <label for="">Kasus</label>
                                <div class="select-position">
                                    <select name="case">
                                        <?php $__currentLoopData = $case; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $p): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($p->id); ?>" <?php echo e($data->case_id == $p->id ? 'selected' : ''); ?>>
                                                <?php echo e($p->title); ?>

                                            </option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                </div>
                            </div>
                            <label>
                                File
                            </label>
                            <?php if($data->pdf != null): ?>
                                <div class="d-flex gap-4 mb-15">

                                    <iframe src="<?php echo e(asset('uploads/materi/' . $data->pdf)); ?>" width="100%" height="600" style="
                                                                                                            border:none;
                                                                                                            border-radius:12px;
                                                                                                            background:#f9fafb;
                                                                                                        ">
                                    </iframe>
                                </div>
                            <?php endif; ?>

                            <!-- <div class="input-style-1">

                                                                                <input type="file" name="file" accept="application/pdf">


                                                                            </div> -->
                            <div class="input-group mb-3">
                                <input type="file" name="file" accept="application/pdf" class="form-control">
                                <button class="btn btn-outline-secondary " type="button"
                                    onclick="hapusPdf(<?php echo e($data->id); ?>)">Hapus PDF</button>
                            </div>


                            <div class="input-style-1">
                                <label>
                                    Url Youtube
                                </label>
                                <input type="text" name="video" value="<?php echo e($data->video); ?>" />

                            </div>
                            <input type="hidden" name="id" value="<?php echo e($data->id); ?>">
                            <button type="submit" class="main-btn primary-btn btn-hover">
                                Simpan
                            </button>

                        </form>
                    </div>
                    <!-- end card -->
                </div>
                <!-- end col -->
            </div>
            <!-- end row -->
        </div>
        <!-- end row -->
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('script'); ?>
    <script>
        document.getElementById('video').addEventListener('change', function () {
            const maxSize = 50 * 1024 * 1024; // 50 MB

            if (this.files[0] && this.files[0].size > maxSize) {
                alert('Ukuran video maksimal 50 MB');
                this.value = '';
            }
        });

        function hapusVideo(id) {
            Swal.fire({
                title: "Hapus Video Materi ini?",
                icon: "warning",
                showCancelButton: true,
                confirmButtonText: "Ya",
            }).then((result) => {
                /* Read more about isConfirmed, isDenied below */
                if (result.isConfirmed) {
                    $.ajax({
                        url: "<?php echo e(URL::to('/materi/delete-video')); ?>" + '/' + id,
                        type: "GET",
                        success: function (response) {
                            location.reload();
                        }
                    })
                };
            });
        }

        function hapusPdf(id) {
            Swal.fire({
                title: "Hapus PDF Materi ini?",
                icon: "warning",
                showCancelButton: true,
                confirmButtonText: "Ya",
            }).then((result) => {
                /* Read more about isConfirmed, isDenied below */
                if (result.isConfirmed) {
                    $.ajax({
                        url: "<?php echo e(URL::to('/materi/delete-pdf')); ?>" + '/' + id,
                        type: "GET",
                        success: function (response) {
                            location.reload();
                        }
                    })
                };
            });
        }
    </script>
<?php $__env->stopSection(); ?>

<!-- ========== section end ========== -->

<!-- ========== footer start =========== -->
<?php echo $__env->make('layouts.v_template', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH D:\Yudi\WEB\project\a\project_learning\resources\views/admin/materi/detail.blade.php ENDPATH**/ ?>