<?php $__env->startSection('content'); ?>
  <div class="content-wrapper">
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1>Edit Video</h1>
          </div>
        </div>
      </div>
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-md-12">
            <div class="card">
              <form action="<?php echo e(route('admin.videos.update')); ?>" method="post" enctype="multipart/form-data">
                <?php echo csrf_field(); ?>
                <div class="card-body">
                  <div class="form-group">
                    <label>Title</label>
                    <input type="text" class="form-control" name="title" value="<?php echo e(old('title', $video->title)); ?>" placeholder="Title">
                    <input type="hidden" class="form-control" name="video_id" value="<?php echo e($video->id); ?>">
                  </div>
                  <div class="form-group">
                    <label class="d-block">Select Category</label>
                    <select name="category_id" class="form-control select2" style="width: 100%">
                      <option selected disabled>Select Category</option>
                      <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($category->id); ?>" <?php if($video->category_id == $category->id): ?> selected <?php endif; ?>><?php echo e($category->name); ?></option>
                      <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                  </div>
                  <div class="form-group">
                    <label>Thumbnail Image</label>
                    <input type="file"  class="form-control" name="thumbnail_image">
                  </div>
                  <!-- Thumbnail Preview -->
                  <div class="form-group">
                    <img src="<?php echo e(asset($video->thumbnail_image)); ?>" alt="Thumbnail Preview" style="width: 140px; height: 200px;">
                  </div>
                  <div class="form-group">
                    <label class="d-block">Video Type</label>
                    <select name="video_type" id="videoType" class="form-control" style="width: 100%">
                      <option value="upload" <?php if($video && $video->video_type == 'upload'): ?> selected <?php endif; ?>>Video (Upload)</option>
                      <option value="youtube" <?php if($video && $video->video_type == 'youtube'): ?> selected <?php endif; ?>>Video (Youtbe URL)</option>
                      <option value="radio" <?php if($video && $video->video_type == 'radio'): ?> selected <?php endif; ?>>Video (Radio URL)</option>
                      <option value="other" <?php if($video && $video->video_type == 'other'): ?> selected <?php endif; ?>>Video (Other URL)</option>
                    </select>
                  </div>
                  <div class="form-group" id="videoField" style="display: none;">
                    <label>Upload Video</label>
                    <input type="file"  class="form-control" name="video" placeholder="Upload Video">
                    <?php if(!empty($video->video)): ?>
                      <video width="480" height="240" controls style="margin-top: 10px;">
                        <source src="<?php echo e(asset($video->video)); ?>" type="video/mp4">
                        <source src="<?php echo e(asset($video->video)); ?>" type="video/webm">
                        Your browser does not support the video tag.
                      </video>
                    <?php endif; ?>
                  </div>
                  <div class="form-group" id="youTubeUrlField" style="display: none;">
                    <label>YouTube URL</label>
                    <input type="text"  class="form-control" name="youtube_url" value="<?php echo e(old('youtube_url', $video->youtube_url)); ?>" placeholder="YouTube URL">
                  </div>
                  <div class="form-group" id="radioUrlField" style="display: none;">
                    <label>Radio URL</label>
                    <input type="text"  class="form-control" name="radio_url" value="<?php echo e(old('radio_url', $video->radio_url)); ?>" placeholder="Radio URL">
                  </div>
                  <div class="form-group" id="otherUrlField" style="display: none;">
                    <label>Other URL</label>
                    <input type="text"  class="form-control" name="other_url" value="<?php echo e(old('youtube_url', $video->other_url)); ?>" placeholder="Other URL">
                  </div>
                  <div class="form-group">
                    <label>Description</label>
                    <textarea
                      name="description"
                      class="form-control"
                      rows="5"
                    >
                      <?php echo old('description', $video->description); ?>

                    </textarea>
                  </div>
                  <div class="form-group">
                    <label>Status</label>
                    <select name="status" class="form-control">
                      <option value="0" <?php if($video->status == '0'): ?> selected <?php endif; ?>>Active</option>
                      <option value="1" <?php if($video->status == '1'): ?> selected <?php endif; ?>>Inactive</option>
                    </select>
                  </div>
                </div>
                <div class="card-footer">
                  <button type="submit" class="btn btn-primary">Update</button>
                </div>
              </form>
            </div>
          </div>
        </div>
      </div>
    </section>
  </div>

  <script src="<?php echo e(asset('assets/backend/plugins/ckeditor/ckeditor.js')); ?>"></script>
  <script>
    var editor = CKEDITOR.replace( 'description' , {
      toolbar: [
        { name: 'basicstyles', items: ['Bold', 'Italic', 'Underline', 'Strike'] },
        { name: 'paragraph', items: ['NumberedList', 'BulletedList'] },
        { name: 'links', items: ['Link', 'Unlink'] },
        { name: 'document', items: ['Source'] } // Source code view
      ],
      customConfig: "<?php echo e(asset('assets/backend/plugins/ckeditor/config.js')); ?>",
      removeButtons: 'Image',
      allowedContent: true,
    });
  </script>

  <script>
    document.addEventListener('DOMContentLoaded', function() {
      var videoTypeSelect = document.getElementById('videoType');
      var youTubeUrlField = document.getElementById('youTubeUrlField');
      var radioUrlField = document.getElementById('radioUrlField');
      var otherUrlField = document.getElementById('otherUrlField');
      var videoField = document.getElementById('videoField');

      function updateFieldVisibility() {
        if (videoTypeSelect.value === 'upload') {
          videoField.style.display = 'block';
          youTubeUrlField.style.display = 'none';
          radioUrlField.style.display = 'none';
          otherUrlField.style.display = 'none';
        } else if (videoTypeSelect.value === 'youtube') {
          videoField.style.display = 'none';
          youTubeUrlField.style.display = 'block';
          radioUrlField.style.display = 'none';
          otherUrlField.style.display = 'none';
        } else if (videoTypeSelect.value === 'radio') {
          videoField.style.display = 'none';
          youTubeUrlField.style.display = 'none';
          radioUrlField.style.display = 'block';
          otherUrlField.style.display = 'none';
        } else if (videoTypeSelect.value === 'other') {
          videoField.style.display = 'none';
          youTubeUrlField.style.display = 'none';
          radioUrlField.style.display = 'none';
          otherUrlField.style.display = 'block';
        } else {
          videoField.style.display = 'block';
          youTubeUrlField.style.display = 'none';
          radioUrlField.style.display = 'none';
          otherUrlField.style.display = 'none';
        }
      }

      // Update visibility based on the default selected value
      updateFieldVisibility();

      // Add event listener for when the select value changes
      videoTypeSelect.addEventListener('change', updateFieldVisibility);
    });
  </script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('backend.layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp\htdocs\miniOTTSports\resources\views/backend/admin/videos/edit.blade.php ENDPATH**/ ?>