@extends('admin.layouts.app')

@section('panel')
    <div class="row justify-content-center">
        <div class="col-md-12">
            <div class="card b-radius--10">
                <div class="card-body p-0">
                    <div class="table-responsive--sm table-responsive">
                        <table class="table table--light style--two ">
                            <thead>
                                <tr>
                                    <th>@lang('Social Media')</th>
                                    <th>@lang('Media Link')</th>
                                    <th>@lang('Media Image')</th>
                                    <th>@lang('Status')</th>
                                    <th>@lang('Action')</th>
                                </tr>
                            </thead>
                            <tbody>
                                @forelse($SocialMedia as $media)
                                    <tr>
                                        <td>
                                            <span class="fw-bold">{{ $media->social_media_name }}</span>
                                        </td>
                                        <td>
                                            <span class="fw-bold">{{ $media->social_media_link }}</span>
                                        </td>
                                        <td>
                                            <img src="{{ getImage(getFilePath('withdrawMethod') . '/' . $media->social_media_icon, getFileSize('withdrawMethod')) }}"
                                                alt="{{ $media->social_media_name }}" height="50px" width="50px">
                                        </td>
                                        <td>@php echo $media->statusBadge @endphp</td>
                                        <td>
                                            @haspermission('social_media:edit', 'admin')
                                                <button type="button" class="btn btn-sm btn-outline--primary editBtn"
                                                    data-bs-route="{{ route('admin.media.edit', $media->id) }}"
                                                    data-bs-title="@lang('Edit Social Media : ') {{ $media->social_media_name }}"
                                                    data-bs-toggle="modal" data-bs-target="#couponModal">
                                                    <i class="la la-pen"></i> @lang('Edit')
                                                </button>
                                            @endhaspermission
                                        </td>
                                    </tr>
                                @empty
                                    <tr>
                                        <td class="text-muted text-center" colspan="100%">{{ __($emptyMessage) }}</td>
                                    </tr>
                                @endforelse
                            </tbody>
                        </table><!-- table end -->
                    </div>
                </div>
                @if ($SocialMedia->hasPages())
                    <div class="card-footer py-4">
                        @php echo paginateLinks($SocialMedia) @endphp
                    </div>
                @endif
            </div><!-- card end -->
        </div>
    </div>

    <div class="modal fade" id="couponModal" tabindex="-1" role="dialog" aria-labelledby="couponModalLabel"
        aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="couponModalLabel"></h5>
                    <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
                        <i class="las la-times"></i>
                    </button>
                </div>
                <div class="modal-body">
                </div>
            </div>
        </div>
    </div>
@endsection



@push('breadcrumb-plugins')

    @haspermission('social_media:create', 'admin')
        <button type="button" class="btn btn-sm btn-outline--primary editBtn" data-bs-route="{{ route('admin.media.edit') }}"
            data-bs-title="@lang('Create Social Media')" data-bs-toggle="modal" data-bs-target="#couponModal">
            <i class="la la-plus"></i> @lang('Create')
        </button>
    @endhaspermission

    <x-search-form dateSearch='no' />
@endpush


@push('script')
    <script>
        (function($) {
            $('.editBtn').on('click', function() {
                var modal = $('#couponModal');
                modal.find('#couponModalLabel').text($(this).data('bs-title'));
                var url = $(this).data('bs-route');
                $.ajax({
                    url: url,
                    method: 'GET',
                    success: function(response) {
                        modal.find('.modal-title').text($(this).data('bs-title'));
                        modal.find('.modal-body').html(response);
                        modal.modal('show');
                    }
                });
            });
        })(jQuery);
    </script>
@endpush
