<!DOCTYPE html>
<html>

@include('includes.head')


<body class="hold-transition skin-blue fixed sidebar-mini">
    <!-- Site wrapper -->
    <div class="wrapper">

        @include('includes.header')
        <!-- =============================================== -->

        <!-- Left side column. contains the sidebar -->
        @include('includes.side-nav')

        <!-- =============================================== -->

        <!-- Content Wrapper. Contains page content -->
        <div class="content-wrapper">
            <!-- Content Header (Page header) -->
            <section class="content-header">
                <h1>
                    Gallery
                    <small>Manage Gallery</small>
                </h1>
                <ol class="breadcrumb">
                    <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                    <li><a href="#">Gallery</a></li>
                    <li class="active">Gallery</li>
                </ol>
            </section>

            <!-- Main content -->
            <section class="content">
                @include('includes.messages')
                <!-- Default box -->
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title">Gallery Management</h3>
                        <div class="box-tools pull-right">
                            <a href="{{route('gallery.create')}}"  class="btn btn-block btn-primary btn-flat"
                                 title="Create System User">
                                <i class="fa fa-plus"></i> Create Gallery </a>

                                <div class="modal fade" id="add_modal">
                                    <div class="modal-dialog">
                                      <div class="modal-content">
                                        <div class="modal-header">
                                          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                            <span aria-hidden="true">&times;</span></button>
                                          <h4 class="modal-title">Create Gallery</h4>
                                        </div>
                                        <div class="modal-body">
                                          <form method="POST" action="{{route('gallery.store')}}" enctype="multipart/form-data">
                                            @csrf
                                            <div class="form-group">
                                                <label>Add  Image</label>
                                              <input type="file" class="form-control"  required="" name="img">
                                            </div>
                                            <div class="form-group">
                                              <input type="submit" class="btn btn-info" value="submit" name="name">
                                            </div>
                                          </form>
                                        </div>
                                      </div>
                                      <!-- /.modal-content -->
                                    </div>
                                    <!-- /.modal-dialog -->
                                  </div>
                                  <!-- /.modal -->

                        </div>

                    </div>
                    <div class="row">
                        <div class="col-md-12">
                            <div class="box-body">
                                <table class="table table-bordered table-hover">
                                    <thead>
                                        <tr>
                                            <th>Sl No</th>

                                            <th>Image</th>
                                            <th>Name</th>

                                            <th style="width: 200px">Action</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @foreach ($records as $record)
                                            <tr>
                                                <td>{{ $loop->iteration }}</td>




                                                <td>

                                                    @if ($record->img)
                                                        <img src="{{ $record->img }}"
                                                            style="width: 100px;  border:2px solid #101010"
                                                            alt="">
                                                    @else
                                                        No Image
                                                    @endif
                                                </td>
                                                <td>{{$record->name}}</td>
                                                <td>
                                                    <!-- Add your action buttons or links here -->
                                                    {{-- Example: --}}
                                                    <a type="button" class="btn btn-primary btn-sm" href="{{route('gallery.edit',$record->id)}}">
                                                        Edit
                                                    </a>
                                                    <a href="#" class="btn btn-danger btn-sm"
                                                        onclick="confirmDelete('{{ route('gallery.delete', $record->id) }}')">Delete</a>

                                                    <script>
                                                        function confirmDelete(url) {
                                                            if (confirm('Are you sure you want to delete this?')) {
                                                                window.location.href = url;
                                                            }
                                                        }
                                                    </script>
                                                </td>
                                            </tr>


                                            <!-- Update Partner Modal -->
        <div class="modal fade" id="editModal{{ $record->id }}" tabindex="-1" aria-labelledby="editModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="editModalLabel">Update Image</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                    </div>
                    <div class="modal-body">
                        <form action="{{ route('gallery.update', $record->id) }}" method="POST" enctype="multipart/form-data">
                            @csrf
                            @method('POST')

                            <!-- Image Upload -->
                            <div class="mb-3">
                                <label for="img" class="form-label">Upload New Image</label>
                                <input type="file" class="form-control" name="img" accept="image/*">
                                @if ($record->img)
                                    <img src="{{ asset($record->img) }}" style="width: 100px; margin-top: 10px;" alt="">
                                @endif
                            </div>

                            <!-- Submit Button -->
                            <button type="submit" class="btn btn-success">Update Image</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
                                        @endforeach

                                    </tbody>
                                </table>

                            </div>
                            <!-- /.box-body -->

                        </div>

                    </div>

                </div>
                <!-- /.box -->

            </section>
            <!-- /.content -->
        </div>
        <!-- /.content-wrapper -->

        @include('includes.footer')

    </div>
    <!-- ./wrapper -->

    @include('includes.scripts')
</body>

</html>
