<link href="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.18/summernote-bs4.min.css" rel="stylesheet">


    <!-- Include Bootstrap JS (Optional, if not already included) -->
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>

    <!-- Include Summernote JS -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.18/summernote-bs4.min.js"></script>
<!-- /.card-header -->
<div class="card-body">
    <form id="validation2" action="{{route('admin::update_breaking_news',$editnews['id'])}}" method="POST" enctype="multipart/form-data">
        @csrf


        <div class="row">
            <p style="color:red;">Note:Please choose Any One Input Type  Image or Video or YouTube Link </p>
            <div class="col-sm-12">
                <div class="form-group">
                    <label>Heading</label>
                    <input type="text" name="heading" value="{{$editnews['heading']}}" class="form-control" placeholder="Enter Heading ...">
                </div>
                @if ($errors->has('heading'))
                    <span class="alert alert-danger">{{ $errors->first('heading') }}</span>
                @endif
            </div>
        </div>

<div class="row">
    <div class="col-sm-12">
        <div class="form-group">
            <label>Main Category</label>
            <select id="mainCategory" name="maincat_id" class="form-control">
                <option value="">Select Main Category</option>
                @foreach($maincatlist as $list)
                <option value="{{$list->id}}" {{ (old('maincat_id', $editnews->maincat_id ?? '') == $list->id) ? 'selected' : '' }}>{{$list->category_name}}</option>
                @endforeach
            </select>
        </div>
        @if ($errors->has('maincat_id'))
            <span class="alert alert-danger">{{ $errors->first('maincat_id') }}</span>
        @endif
    </div>
</div>

<div class="row">
    <div class="col-sm-12">
        <div class="form-group">
            <label>Sub Category</label>
            <select id="subCategory" name="subcat_id" class="form-control">
                <option value="">Select Sub Category</option>
            </select>
        </div>
        @if ($errors->has('subcat_id'))
            <span class="alert alert-danger">{{ $errors->first('subcat_id') }}</span>
        @endif
    </div>
</div>


<div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label for="exampleInputEmail1">Preview Image</label>
                    <img src="{{asset($editnews['image'])}}" alt="No Picture Found" style="width: auto;height: 200px;object-fit: cover;">
                </div>
            </div>
</div>


        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label for="exampleInputFile">Choose Image</label><span style="color:red;">*</span>
                    <div class="input-group">
                        <div class="custom-file">
                            <input type="file" class="custom-file-input" name="image" id="exampleInputFile">
                            <label class="custom-file-label" for="exampleInputFile">Choose file</label>
                        </div>
                        <div class="input-group-append">
                            <span class="input-group-text">Upload</span>
                        </div>
                    </div>
                </div>

                @if ($errors->has('image'))
                    <span class="alert alert-danger">{{ $errors->first('image') }}</span>
                @endif
            </div>
        </div>
        <br>


        @if(!empty($editnews['video']))
    <video width="100%" height="400" controls autoplay>
        <source src="{{ $editnews['video'] }}" type="video/mp4">
        Your browser does not support the video tag.
    </video>
   @endif


        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label for="exampleInputFile">Choose Video</label><span style="color:red;">*</span>
                    <div class="input-group">
                        <div class="custom-file">
                            <input type="file" class="custom-file-input" name="video" id="exampleInputFile">
                            <label class="custom-file-label" for="exampleInputFile">Choose file</label>
                        </div>
                        <div class="input-group-append">
                            <span class="input-group-text">Upload</span>
                        </div>
                    </div>
                </div>

                @if ($errors->has('video'))
                    <span class="alert alert-danger">{{ $errors->first('video') }}</span>
                @endif
            </div>
        </div>
        <br>

        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label>YouTube Link</label><span style="color:red;">*</span>
                    <input type="text" name="youtube" class="form-control" placeholder="Enter Youtube ...">
                </div>
                @if ($errors->has('youtube'))
                    <span class="alert alert-danger">{{ $errors->first('youtube') }}</span>
                @endif
            </div>
        </div>

        <div class="row">
                <div class="col-sm-12">
                    <div class="form-group">
                        <label>Description</label><span style="color:#ff0000;">*</span>
                        <textarea name="description" id="description" class="summernote form-control" placeholder="Enter ...">
                        {!! $editnews['description'] !!}
                        </textarea>
                    </div>
                    @if ($errors->has('description'))
                        <span class="alert alert-danger">{{ $errors->first('description') }}</span>
                    @endif
                </div>
            </div>

            <!-- <div class="row">
                <div class="col-sm-12">
                    <div class="form-group" style="text-align:center">
                        <button type="button" id="translateToHindi" class="btn btn-secondary">Translate to Hindi</button>
                    </div>
                </div>
            </div> -->



        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label>Post By</label><span style="color:red;">*</span>
                    <input type="text" name="postby" class="form-control" placeholder="Enter  ..." value="{{$editnews['postby']}}">
                </div>
                @if ($errors->has('postby'))
                    <span class="alert alert-danger">{{ $errors->first('postby') }}</span>
                @endif
            </div>
        </div>


        

        <div class="row">

            <div class="col-md-12">
                <div class="form-group" style="text-align:center">
                    <input type="submit" value="Submit" class="btn btn-primary">
                </div>
            </div>
        </div>
    </form>
</div>

<!-- /.card-body -->
<script type="text/javascript">
    jQuery("#validation2").validationEngine({promptPosition: 'inline'});
    $('.select2').select2();
</script>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
        $(document).ready(function() {
            // Initialize Summernote editor
            $('#description').summernote();

            // Code for handling category selection (existing code)
            $('#mainCategory').change(function() {
                var maincatId = $(this).val();
                var subCategoryDropdown = $('#subCategory');

                // Clear previous subcategories
                subCategoryDropdown.empty();
                subCategoryDropdown.append('<option value="">Select Sub Category</option>');

                if (maincatId) {
                    $.ajax({
                        url: "{{ route('admin::getSubCategories') }}", // Replace with your route to fetch subcategories
                        type: 'GET',
                        data: { maincat_id: maincatId },
                        success: function(data) {
                            $.each(data, function(key, value) {
                                subCategoryDropdown.append('<option value="' + value.id + '">' + value.subcatname + '</option>');
                            });
                        }
                    });
                }
            });

            // New code for handling the translation button click
            $('#translateToHindi').click(function() {
                var descriptionContent = $('#description').summernote('code'); // Get content from Summernote

                // Example translation function (replace with actual translation logic)
                function translateToHindi(text) {
                    // This is a placeholder function, replace with actual translation API call
                    return "यह हिंदी में अनुवादित पाठ है"; // This is "This is translated text in Hindi" in Hindi
                }

                var translatedContent = translateToHindi(descriptionContent);
                $('#description').summernote('code', translatedContent); // Set translated content in Summernote
            });
        });
    </script>

