<?php $__env->startSection('title', __('trans.lecture.title')); ?>

<?php $__env->startSection('content'); ?>
    <div class="card">

        <h5 class="card-header">
            <a href="<?php if(request('unit_id')): ?> <?php echo e(url('admin/lectures')); ?>?unit_id=<?php echo e(request('unit_id')); ?> <?php else: ?> <?php echo e(url('admin/lectures')); ?> <?php endif; ?>"
                class="btn rounded-pill btn-label-primary">
                <i class="ti me-2 ti-arrow-forward-up"></i> <?php echo e(__('trans.lecture.title')); ?>

            </a>
            <?php echo $__env->yieldContent('title'); ?>
        </h5>

        <div class="card-body">

            <form action="<?php echo e(route('lectures.store')); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <div class="row">


                    <div class="col-md-12 mb-3">
                        <label class="form-label"><?php echo e(__('trans.lecture.name')); ?> <b class="text-danger">*</b></label>
                        <input type="text" class="form-control" required name="title" value="<?php echo e(old('title')); ?>"
                            placeholder="<?php echo e(__('trans.lecture.name')); ?>" />
                    </div>


                    <div class="col-md-12 mb-3">
                        <label class="form-label"><?php echo e(__('trans.lecture.description')); ?></label>
                        <textarea name="description" class="form-control" rows="5" placeholder="<?php echo e(__('trans.lecture.description')); ?>"><?php echo e(old('description')); ?></textarea>
                    </div>


                    <div class="col-md-12 mb-3">
                        <label class="form-label"><?php echo e(__('trans.lecture.video_id')); ?> <b class="text-danger">*</b></label>
                        <input type="text" class="form-control" required name="video_id" value="<?php echo e(old('video_id')); ?>"
                            placeholder="<?php echo e(__('trans.lecture.video_id')); ?>" oninput="displayVideo()" id="video-id" />
                    </div>

                    <div>
                        <iframe width="560" height="315" id="video-player" src="" title="YouTube video player"
                            frameborder="0"
                            allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
                            referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>

                    </div>

                    <div class="col-md-12 mb-3">
                        <label class="form-label"><?php echo e(__('trans.lecture.file')); ?></label>
                        <div class="input-group">

                            <a id="lfm" data-input="thumbnail" data-preview="holder"
                                class="UploadFile btn btn-primary">
                                <i class="fa fa-paperclip me-1"></i> <?php echo e(__('trans.choose')); ?>

                            </a>
                            <input id="thumbnail" class="form-control" type="text" name="file"
                                value="<?php echo e(old('file')); ?>" placeholder="<?php echo e(__('trans.no_file_chosen')); ?>" readonly />
                            <button type="button" class="btn btn-danger" id="clear-file">
                                <i class="fa fa-times"></i>
                            </button>
                        </div>
                    </div>

                    <?php if(!empty($existedUnit)): ?>
                        <div class="col-md-6 mb-3">
                            <label class="form-label"><?php echo e(__('trans.lecture.category_id')); ?> <b
                                    class="text-danger">*</b></label>
                            <input type="hidden" name="category_id" value="<?php echo e($existedUnit->category->id); ?>">
                            <input type="text" class="form-control" required value="<?php echo e($existedUnit->category->name); ?>"
                                placeholder="<?php echo e(__('trans.lecture.category_id')); ?>" readonly />
                        </div>


                        <div class="col-md-6 mb-3">
                            <label class="form-label"><?php echo e(__('trans.lecture.course_id')); ?> <b
                                    class="text-danger">*</b></label>
                            <input type="hidden" name="course_id" value="<?php echo e($existedUnit->course->id); ?>">
                            <input type="text" class="form-control" required value="<?php echo e($existedUnit->course->title); ?>"
                                placeholder="<?php echo e(__('trans.lecture.course_id')); ?>" readonly />
                        </div>


                        <div class="col-md-6 mb-3">
                            <label class="form-label"><?php echo e(__('trans.lecture.chapter_id')); ?> <b
                                    class="text-danger">*</b></label>
                            <input type="hidden" name="chapter_id" value="<?php echo e($existedUnit->chapter->id); ?>">
                            <input type="text" class="form-control" required value="<?php echo e($existedUnit->chapter->title); ?>"
                                placeholder="<?php echo e(__('trans.lecture.chapter_id')); ?>" readonly />
                        </div>


                        <div class="col-md-6 mb-3">
                            <label class="form-label"><?php echo e(__('trans.lecture.unit_id')); ?> <b
                                    class="text-danger">*</b></label>
                            <input type="hidden" name="unit_id" value="<?php echo e($existedUnit->id); ?>">
                            <input type="text" class="form-control" required value="<?php echo e($existedUnit->title); ?>"
                                placeholder="<?php echo e(__('trans.lecture.unit_id')); ?>" readonly />
                        </div>
                    <?php elseif(!empty($categories)): ?>
                        <div class="col-md-6 mb-3">
                            <label class="form-label"><?php echo e(__('trans.lecture.category_id')); ?> <b
                                    class="text-danger">*</b></label>
                            <select name="category_id" class="select2 form-select" id="category" required>
                                <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($category->id); ?>" <?php if(old('category_id') == $category->id): echo 'selected'; endif; ?>>
                                        <?php echo e($category->name); ?>

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


                        <div class="col-md-6 mb-3">
                            <label class="form-label"><?php echo e(__('trans.lecture.course_id')); ?> <b
                                    class="text-danger">*</b></label>
                            <select class="select2 form-select" name="course_id" id="course" required></select>
                        </div>


                        <div class="col-md-6 mb-3">
                            <label class="form-label"><?php echo e(__('trans.lecture.chapter_id')); ?> <b
                                    class="text-danger">*</b></label>
                            <select class="select2 form-select" name="chapter_id" id="chapter" required></select>
                        </div>

                        <div class="col-md-6 mb-3">
                            <label class="form-label"><?php echo e(__('trans.lecture.unit_id')); ?> <b
                                    class="text-danger">*</b></label>
                            <select class="select2 form-select" name="unit_id" id="unit" required></select>
                        </div>

                    <?php endif; ?>
                    <div class="col-md-12 mt-3">
                        <button class="btn btn-primary btn-create w-100"><?php echo e(__('trans.save')); ?></button>
                    </div>
                </div>
            </form>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('css'); ?>
    <link rel="stylesheet" href="<?php echo e(asset('admin/vendor/libs/select2/select2.css')); ?>" />
<?php $__env->stopSection(); ?>

<?php $__env->startSection('js'); ?>
    <script src="<?php echo e(asset('admin/vendor/libs/select2/select2.js')); ?>"></script>
    <script>
        $('.select2').select2();

        function displayVideo() {
            let newVideoId = $('#video-id').val();

            let newSrc = "https://www.youtube.com/embed/" + newVideoId;

            $('#video-player').attr('src', newSrc);
        }

        $('#clear-file').on('click', function() {
            $('#thumbnail').val('');
        });

        $(window).on('load', function() {
            $('#category').trigger('input');
        });

        $('#category').on('input', function() {
            var MyVal = $(this).val();
            $.ajax({
                type: 'get',
                url: "<?php echo e(url('admin/ajax/courses')); ?>",
                data: {
                    category_id: MyVal,
                },
                beforeSend: function() {
                    $("#course").html('');
                },
            }).done(function(res) {
                $.each(res.data, function(key, val) {
                    $("#course").append(
                        "<option value='" + val.id + "'>" +
                        val.title + "</option>");
                });
                $('#course').trigger('input');
            });
        });

        $('#course').on('input', function() {
            var MyVal = $(this).val();
            $.ajax({
                type: 'get',
                url: "<?php echo e(url('admin/ajax/chapters')); ?>",
                data: {
                    course_id: MyVal,
                },
                beforeSend: function() {
                    $("#chapter").html('');
                },
            }).done(function(res) {
                $.each(res.data, function(key, val) {
                    $("#chapter").append(
                        "<option value='" + val.id + "'>" +
                        val.title + "</option>");
                });
                $('#chapter').trigger('input');
            });
        });

        $('#chapter').on('input', function() {
            var MyVal = $(this).val();
            $.ajax({
                type: 'get',
                url: "<?php echo e(url('admin/ajax/units')); ?>",
                data: {
                    chapter_id: MyVal,
                },
                beforeSend: function() {
                    $("#unit").html('');
                },
            }).done(function(res) {
                $.each(res.data, function(key, val) {
                    $("#unit").append(
                        "<option value='" + val.id + "'>" +
                        val.title + "</option>");
                });
            });
        });
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.admin.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH E:\projects\doctorito\resources\views/admin/lecture/create.blade.php ENDPATH**/ ?>