<!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>
                    Partner
                    <small>Manage Partner</small>
                </h1>
                <ol class="breadcrumb">
                    <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                    <li><a href="#">Partner</a></li>
                    <li class="active">Partner</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">Partner Management</h3>
                        <div class="box-tools pull-right">
                            <button type="button" data-toggle="modal" data-target="#add_modal" class="btn btn-block btn-primary btn-flat"
                                data-toggle="tooltip" title="Create System User">
                                <i class="fa fa-plus"></i> Create Partner </button>

                                <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 Partner</h4>
                                        </div>
                                        <div class="modal-body">
                                          <form method="POST" action="{{route('partner.store')}}" enctype="multipart/form-data">
                                            @csrf
                                            <div class="form-group">
                                                <label>Add Partner 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="">
                                            </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 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>
                                                    <!-- Add your action buttons or links here -->
                                                    {{-- Example: --}}
                                                    <button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#editModal{{ $record->id }}">
                                                        Edit
                                                    </button>
                                                    <a href="#" class="btn btn-danger btn-sm"
                                                        onclick="confirmDelete('{{ route('partner.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('partner.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>
