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

<!--=====================================
                    USER FORM PART START
        =======================================-->
        <section class="user-form-part find_id">
            <div class="container">
                <div class="row justify-content-center">
                    <div class="col-12">
                        <!--
						<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">
								<h2>아이디찾기</h2>
                                <p>고객님의 정보와 일치하는 아이디 목록입니다.</p>
                            </div>

							<div class="col-lg-12">
								<div class="table-scroll">
									<table class="table-list">
										<thead>
											<tr>
												<th scope="col">아이디</th>
												<th scope="col">가입일</th>
												<th scope="col">회원상태</th>
											</tr>
										</thead>
										<tbody>
                                        @forelse ($memberPage['Page'] ?? [] as $member)
                                            <tr class="text-center">
                                                <td>
                                                    <div class="radioSec">
                                                        <input type="radio" id="email-radio-{{ $member['Id'] }}" name="email">
                                                        <label class="mr-3 tw-cursor-pointer email-label" for="email-radio-{{ $member['Id'] }}"
                                                               data-sso-brand="{{ $member['SsoBrand'] }}">
                                                            {{ $member['Email'] }}
                                                            @if ($member['SsoBrand'])
                                                                ({{ $member['SsoBrand'] }} 로그인)
                                                            @endif
                                                        </label>
                                                    </div>
                                                </td>
                                                <td>{{ Carbon\Carbon::createFromTimestamp($member['CreatedOn'])->format('Y.m.d') }}</td>
                                                <td>{{ DataConverter::execute($member['Status'], "status('member')") }}</td>
                                            </tr>
                                        @empty
                                            <tr><td class="text-center" colspan="3">데이터가 없습니다</td></tr>
                                        @endforelse
										</tbody>
									</table>
								</div>
							</div>

							<div class="text-center flex-row">
								<button type="button" class="btn btn_prime btn_round" onclick="route_page('member-login')">로그인</button>
								<button type="button" class="btn btn_round btn-outline" onclick="route_page('find-pw')">비밀번호 찾기</button>
							</div>
                    </div>
                    </div>
                </div>
            </div>
        </section>
        <!--=====================================
                    USER FORM PART END
        =======================================-->
@endsection

@push('js')
    <script>
        function route_page($type) {
            const checked_label = $('input:radio[name=email]:checked')
            const label = $(checked_label).prop('labels')

            let url
            switch ($type) {
                case 'member-login':
                    if (isEmpty(label) || ! isEmpty($(label).data('sso-brand'))) {
                        url = "{{ route('member-login') }}"
                    } else {
                        url = "{{ route('member-login', [ 'email' => '' ]) }}"
                    }
                    break;
                case 'find-pw':
                    if (isEmpty(label)) {
                        url = "{{ route('find-member-pw-memcheck.index') }}"
                    } else if (! isEmpty($(label).data('sso-brand')) ) {
                        url = "{{ route('member-login') }}"
                    } else {
                        url = "{{ route('find-member-pw-verify.index', [ 'email' => '' ]) }}"
                    }
                    break;
            }

            url = url.replace('email=', `email=${trim($(label).text())}`)

            // console.log(url)

            window.location.href = url
        }
    </script>
@endpush
