@extends('yonetim.yonetim_master')

@section('cssler')
    <style>



        .toggle-switch {
            position: relative;
            display: inline-block;
            width: 50px;
            height: 26px;
        }

        .toggle-switch-checkbox {
            display: none;
        }



        .toggle-switch-slider {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: #ccc;
            border-radius: 13px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        .toggle-switch-slider:before {
            position: absolute;
            content: "";
            height: 20px;
            width: 20px;
            left: 3px;
            bottom: 3px;
            background-color: #fff;
            border-radius: 50%;
            transition: transform 0.3s ease;
        }

        .toggle-switch-checkbox:checked + .toggle-switch-slider {
            background-color: #4caf50;
        }

        .toggle-switch-checkbox:checked + .toggle-switch-slider:before {
            transform: translateX(24px);
        }

        /* El işareti */
        .toggle-switch-slider:before {
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
        }

        .toggle-switch:hover .toggle-switch-slider:before {
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
        }

        .toggle-switch-checkbox:focus + .toggle-switch-slider {
            box-shadow: 0 0 2px #2196f3;
        }


        .toggle-switch-paytr {
            position: relative;
            display: inline-block;
            width: 50px;
            height: 26px;
        }

        .toggle-switch-checkbox-paytr {
            display: none;
        }

        .toggle-switch-slider-paytr {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: #ccc;
            border-radius: 13px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        .toggle-switch-slider-paytr:before {
            position: absolute;
            content: "";
            height: 20px;
            width: 20px;
            left: 3px;
            bottom: 3px;
            background-color: #fff;
            border-radius: 50%;
            transition: transform 0.3s ease;
        }

        .toggle-switch-checkbox-paytr:checked + .toggle-switch-slider-paytr {
            background-color: #4caf50;
        }

        .toggle-switch-checkbox-paytr:checked + .toggle-switch-slider-paytr:before {
            transform: translateX(24px);
        }

        /* El işareti */
        .toggle-switch-slider-paytr:before {
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
        }

        .toggle-switch-paytr:hover .toggle-switch-slider-paytr:before {
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
        }

        .toggle-switch-checkbox-paytr:focus + .toggle-switch-slider-paytr {
            box-shadow: 0 0 2px #2196f3;
        }


        .toggle-switch-havale {
            position: relative;
            display: inline-block;
            width: 50px;
            height: 26px;
        }

        .toggle-switch-checkbox-havale {
            display: none;
        }

        .toggle-switch-slider-havale {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: #ccc;
            border-radius: 13px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        .toggle-switch-slider-havale:before {
            position: absolute;
            content: "";
            height: 20px;
            width: 20px;
            left: 3px;
            bottom: 3px;
            background-color: #fff;
            border-radius: 50%;
            transition: transform 0.3s ease;
        }

        .toggle-switch-checkbox-havale:checked + .toggle-switch-slider-havale {
            background-color: #4caf50;
        }

        .toggle-switch-checkbox-havale:checked + .toggle-switch-slider-havale:before {
            transform: translateX(24px);
        }

        /* El işareti */
        .toggle-switch-slider-havale:before {
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
        }

        .toggle-switch-havale:hover .toggle-switch-slider-havale:before {
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
        }

        .toggle-switch-checkbox-havale:focus + .toggle-switch-slider-havale {
            box-shadow: 0 0 2px #2196f3;
        }
    </style>
@endsection
@section('main')
    <section class="section">
        <div class="section-body">
            <div class="row">
                <div class="col-12">
                    <div class="card">
                        <div class="card-header">
                            <h4>Ödeme Yöntemleri</h4>


                        </div>
                        <div class="card-body">

                            <div class="table-responsive">
                                <table class="table table-striped" id="table-1">
                                    <thead>
                                    <tr>

                                        <th>Başlık</th>
                                        <th>Durum</th>


                                        <th>İşlemler</th>
                                    </tr>
                                    </thead>
                                    <tbody>

                                        <tr>

                                            <td>Banka Havalesi</td>
                                            <td>
                                                <label class="toggle-switch">
                                                    <input type="checkbox" class="toggle-switch-checkbox-havale" data-url="{{ route('hesap.havaletoggleDurum') }}" data-id="{{ $veriler->id }}" {{ $veriler->havale_durum == 1 ? 'checked' : '' }}>
                                                    <span class="toggle-switch-slider-havale"></span>
                                                </label>
                                            </td>



                                            <td>
                                                <a href="{{ route('hesap.all')}}" class="btn btn-warning"><i class="fa fa-edit"></i> Düzenle</a>

                                            </td>
                                        </tr>


                                        <tr>

                                            <td>Paytr</td>
                                                <td>



                                                    <label class="toggle-switch">
                                                        <input type="checkbox" class="toggle-switch-checkbox-paytr" data-url="{{ route('hesap.paytrtoggleDurum') }}" data-id="{{ $veriler->id }}" {{ $veriler->paytr_durum == 1 ? 'checked' : '' }}>
                                                        <span class="toggle-switch-slider-paytr"></span>
                                                    </label>

                                                </td>


                                            <td>
                                                <a href="{{ route('paytr.veriupdate')}}" class="btn btn-warning"><i class="fa fa-edit"></i> Düzenle</a>

                                            </td>
                                        </tr>




                                        <tr>

                                            <td>Paymax-Vallet</td>
                                            <td>
                                                <label class="toggle-switch">
                                                    <input type="checkbox" class="toggle-switch-checkbox" data-url="{{ route('hesap.valettoggleDurum') }}" data-id="{{ $veriler->id }}" {{ $veriler->vallet_durum == 1 ? 'checked' : '' }}>
                                                    <span class="toggle-switch-slider"></span>
                                                </label>
                                            </td>



                                            <td>
                                                <a href="{{ route('vallet.veriupdate')}}" class="btn btn-warning"><i class="fa fa-edit"></i> Düzenle</a>
                                            </td>
                                        </tr>





                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </section>
@endsection


@section('jsler')

    <script>
        $(document).ready(function() {


            $('.toggle-switch-checkbox-paytr').on('change', function() {
                const isChecked = $(this).prop('checked');
                const url = $(this).data('url');
                const id = $(this).data('id');

                // CSRF token değerini alın
                const csrfToken = $('meta[name="csrf-token"]').attr('content');

                // CSRF token değerini AJAX isteği başlığına ekleyin
                $.ajaxSetup({
                    headers: {
                        'X-CSRF-TOKEN': csrfToken
                    }
                });

                $.ajax({
                    url: url,
                    method: 'POST',
                    data: {
                        id: id,
                        isChecked: isChecked ? 1 : 0
                    },                            success: function (response) {
                        iziToast.success({
                            title: 'Başarılı',
                            message: response.success,
                            position: 'topRight',
                            timeout: 3000
                        });

                        if (!!window.performance && window.performance.navigation.type === 2) {
                            console.log('Reloading');
                            window.location.reload();
                        }
                    },
                    error: function(response) {
                        if (response.responseJSON && response.responseJSON.error) {
                            iziToast.error({
                                title: 'Başarısız',
                                message: response.responseJSON.error,
                                position: 'topRight',
                                timeout: 3000
                            });

                            setTimeout(function() {
                                window.location.reload();
                            }, 1500);

                        } else {
                            iziToast.error({
                                title: 'Başarısız',
                                message: 'Bir hata oluştu',
                                position: 'topRight',
                                timeout: 3000
                            });
                            setTimeout(function() {
                                window.location.reload();
                            }, 1500);

                        }

                    }
                });

            });

            $('.toggle-switch-checkbox').on('change', function() {
                const isChecked = $(this).prop('checked');
                const url = $(this).data('url');
                const id = $(this).data('id');

                // CSRF token değerini alın
                const csrfToken = $('meta[name="csrf-token"]').attr('content');

                // CSRF token değerini AJAX isteği başlığına ekleyin
                $.ajaxSetup({
                    headers: {
                        'X-CSRF-TOKEN': csrfToken
                    }
                });

                $.ajax({
                    url: url,
                    method: 'POST',
                    data: {
                        id: id,
                        isChecked: isChecked ? 1 : 0
                    },                            success: function (response) {
                        iziToast.success({
                            title: 'Başarılı',
                            message: response.success,
                            position: 'topRight',
                            timeout: 3000
                        });

                        if (!!window.performance && window.performance.navigation.type === 2) {
                            console.log('Reloading');
                            window.location.reload();
                        }
                    },
                    error: function(response) {
                        if (response.responseJSON && response.responseJSON.error) {
                            iziToast.error({
                                title: 'Başarısız',
                                message: response.responseJSON.error,
                                position: 'topRight',
                                timeout: 3000
                            });

                            setTimeout(function() {
                                window.location.reload();
                            }, 1500);

                        } else {
                            iziToast.error({
                                title: 'Başarısız',
                                message: 'Bir hata oluştu',
                                position: 'topRight',
                                timeout: 3000
                            });
                            setTimeout(function() {
                                window.location.reload();
                            }, 1500);

                        }

                    }
                });

            });



                $('.toggle-switch-checkbox-havale').change(function() {
                    var isChecked = $(this).prop('checked');
                    var url = $(this).data('url');
                    var id = $(this).data('id');

                    // CSRF token değerini alın
                    const csrfToken = $('meta[name="csrf-token"]').attr('content');

                    // CSRF token değerini AJAX isteği başlığına ekleyin
                    $.ajaxSetup({
                        headers: {
                            'X-CSRF-TOKEN': csrfToken
                        }
                    });

                    $.ajax({
                        url: url,
                        method: 'POST',
                        data: {
                            id: id,
                            isChecked: isChecked ? 1 : 0
                        },                        success: function(response) {
                            // Başarılı olduğunda yapılacak işlemler
                            if (response.success) {
                                iziToast.show({
                                    title: 'Başarılı',
                                    message: response.success,
                                    color: 'green',
                                    position: 'topRight',
                                    timeout: 3000
                                });

                                if (!!window.performance && window.performance.navigation.type === 2) {
                                    console.log('Reloading');
                                    window.location.reload();
                                }
                            }
                        },
                        error: function(xhr, status, error) {
                            // Hata olduğunda yapılacak işlemler
                            iziToast.show({
                                title: 'Başarılı',
                                message: response.error,
                                color: 'green',
                                position: 'topRight',
                                timeout: 3000
                            });

                        }
                    });
                });


        });
    </script>
@endsection
