@extends('views.layouts.master')
<link rel="stylesheet" href="{{ csset('/themes/kbgolf/pro/resources/css/user-auth.css') }}">
@section('content')

<!--=====================================
                    USER FORM PART START
        =======================================-->
        <section class="user-form-part login">
            <div class="container">
                <div class="row justify-content-center">
                    <div class="col-12 col-sm-10 col-md-12 col-lg-12 col-xl-5">
                        <!--
						<div class="user-form-logo">
                            <a href="index.html"><img src="images/logo.png" alt="logo"></a>
                        </div>
						-->
                        <div class="user-form-card">
                            <div class="user-form-title">
                                <p>가입하신 정보로 로그인해 주세요.</p>
                            </div>

                            <div class="user-form-group cursor-pointer">
                                <div class="form-button w-100">
                                    @foreach ($oauth2InfoList as $provider => $oauth2)
                                        <button type="button" style="cursor: pointer;" class="login_naver w-100 mt-2 bg-white text-dark sso-login-btn"
                                                onclick="window.location.href = '{{ route('social.redirectToProvider', [ 'oauth2Info' => $oauth2, 'provider' => $provider, 'target' => 'member' ]) }}'">
                                            <img class="w-auto" src="{{ asset('themes/dasol/pro/resources/images/login_' . $provider . '.png') }}">
                                            {{ $oauth2['LoginButtonString'] }}
                                        </button>
                                    @endforeach
                                </div>
                            </div>
                        </div>
                        <!--
						<div class="user-form-footer">
                            <p>Greeny | &COPY; Copyright by <a href="#">Mironcoder</a></p>
                        </div>
						-->
                    </div>
                </div>
            </div>
        </section>
        <!--=====================================
                    USER FORM PART END
        =======================================-->

<!-- Basic modal -->
<div id="modal-cancel-dormant-account" class="modal fade madd_list" tabindex="-1" data-backdrop="static">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title"></h5>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>

            <div class="modal-body text-center">
                <input type="hidden" id="member-id">
                <h1 class="mb-2" style="font-size: 2.5rem;">@lang('휴면 계정 해제 안내')</h1>
                <p class="text-primary" id="dorment-email-txt"></p>
                <p class="my-2">@lang('회원님의 계정이 1년간 로그인하지 않아 휴먼 계정으로 전환되었습니다.')</p>
                <p class="font-weight-bold mb-5">@lang('지금 휴먼 상태를 해제 하시겠습니까?')</p>

                <p class="text-grey-400">@lang('*제네시스핀은 정보통신망법에 따라, 회원님의 소중한 개인정보를 보호하기 위해 1년 동안 로그인 기록이 없는 계정을 휴먼전환하고 개인정보를 별도 분리하여 보관합니다.')</p>
                <div class="modal-footer">
                    <div class="d-flex justify-content-around w-100">
                        <button type="button" class="btn-secondary btn_ok" onclick="hide_cancel_dormant_modal()">@lang('다른 아이디로 로그인')</button>
                        <button type="button" class="btn btn_orange btn_ok" id="dormant-cancel-btn" onclick="go_to_your_account()">
                            <i class="spinner fa fa-spinner fa-spin"></i>
                            @lang('휴먼 상태를 해체 합니다')
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- /basic modal -->
@endsection

@once
@push('js')
    <script>
        $(document).ready(function () {
            if (@json(session('dormant_member'))) {
                const email = $('#email-txt').val()
                $('#modal-cancel-dormant-account').find('#dorment-email-txt').text(email)
                const member_id = @json(session('dormant_member_id'));
                $('#modal-cancel-dormant-account').find('#member-id').val(member_id)
                $('#modal-cancel-dormant-account').modal('show')
            }
        });

        async function go_to_your_account() {
            $('#dormant-cancel-btn').attr('disabled', true)
            $('#modal-cancel-dormant-account').find('.spinner').show()

            const member_id = $('#modal-cancel-dormant-account').find('#member-id').val()
            const dormant_member_recover = await get_api_data('dormant-member-recover', {
                MemberId: Number(member_id)
            })
            const dormant_member_recover_data = dormant_member_recover.data

            if (dormant_member_recover_data.apiStatus) {
                iziToast.error({ title: 'Error', message: dormant_member_recover_data.body ?? $('#api-request-failed-please-check').text() })
            } else {
                iziToast.success({ title: 'Success', message: $('#action-completed').text() })
                $('#modal-cancel-dormant-account.show').modal('hide');

                $('#modal-cancel-dormant-account-success').modal('show')
            }

        }

        function hide_cancel_dormant_modal() {
            $('.user-form-card').find('.spinner').hide()
            $('#member-signup-btn').attr('disabled', false)
            $('#modal-cancel-dormant-account').modal('hide')
        }
    </script>
@endpush
@endonce
