@section('title', 'Sliders Management')
@section('sliders-management', 'active')
@include('adminDashboard.layout.header')

<div class="main-content">
    <section class="section">
        <div class="section-body">
            <div class="row">
                <div class="col-12">
                    <div class="card">
                        <div class="card-header">
                            <h4>Slider Management</h4>
                            <button type="button" onclick="" class="badge badge-success" style="border:none;" data-toggle="modal" data-target="#exampleModal">Add</button>
                        </div>
                        <div class="card-body p-0">
                            <div class="table-responsive">
                                <table class="table table-striped table-md">
                                    <tr>
                                        <th>ID</th>
                                        <th>Title</th>
                                        <th>Type</th>
                                        <th>File</th>
                                        <th>Action</th>
                                    </tr>
                                    @foreach($sliders as $key => $slider)
                                    <tr>
                                        <td>{{++$key}}</td>
                                        <td>{{$slider->banner_title}}</td>
                                        <td>{{$slider->type}}</td>
                                        @if($slider->type == "image")
                                        <td><img src="{{asset('assets/img/'.$slider->path)}}" width="100px"></td>
                                        @else
                                        <td>{{$slider->path}}</td>
                                        @endif
                                        <td>

                                            <a href="{{url('/admin/slider-management/delete/'.$slider->id)}}" class="text-decoration-none">
                                                <div class="badge badge-danger"><i class="material-icons font_size_14">delete</i></div>
                                            </a>
                                        </td>
                                    </tr>
                                    @endforeach
                                </table>
                            </div>
                        </div>
                        <div class="card-footer text-right">
                            <nav class="d-inline-block">
                                {{$sliders->links('adminDashboard.pagination')}}
                            </nav>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="formModal" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="formModal">New Slider</h5>
                    <button type="button" class="close" id="modal_dismiss" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <form method="post" action="{{url('/admin/slider-management')}}" enctype="multipart/form-data">
                        @csrf
                        <div class="row">
                            <div class="col-12">
                                <div class="form-group">
                                    <label>Title</label>
                                    <input type="text" class="form-control" name="banner_title" required>
                                </div>
                            </div>
                            <div class="col-12">
                                <div class="form-group">
                                    <label>Type</label>
                                    <select class="form-control" name="type" onchange="action_changed(this.value)">
                                        <option value="image">Image</option>
                                        <option value="video">Video</option>
                                    </select>
                                </div>
                            </div>

                            <div class="col-12">
                                <div class="form-group" id="action_field">
                                    <label>Image</label>
                                    <input type="file" class="form-control" name="file_name" required>
                                </div>
                            </div>

                            <div class="col-12 text-center" id="order_actions">
                                <div class="text-right">
                                    <button class="btn btn-primary mr-1" type="submit">Submit</button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    function action_changed(value) {
        if (value == "image") {
            $('#action_field').html(`
            <label>Image</label>
            <input type="file" class="form-control" name="file_name" required>
            `);
        } else if (value == "video") {
            $('#action_field').html(`
            <label>Video Link</label>
            <input type="text" class="form-control" name="file_name" required>
            `);
        }
    }
</script>
@include('adminDashboard.layout.footer')