@extends('admin.layouts.app')

@section('content')
<div class="container-fluid">
    <h2>회원 @if($uid) 수정 @else 등록 @endif</h2>
    <hr/>
    @include('admin.messages')

    <form name="f_admin_write" id="fAdminWrite" method="post" action="{{ $actionURL }}" enctype="multipart/form-data">
        @csrf
        @if($uid)
            <input type="hidden" name="uid" value="{{ $uid }}" />
            @method('PUT')
        @endif
        <div class="row mb-3">
            <label for="email" class="col-sm-2 col-form-label"><span class="text-danger">*</span> 이메일</label>
            <div class="col-sm-10">
                <input type="text" name="email" id="email" class="form-control" value="{{ $userData->email ?? old('email') }}" />
            </div>
        </div>
        <div class="row mb-3">
            <label for="password" class="col-sm-2 col-form-label">@if(!$uid)<span class="text-danger">*</span>@endif 비밀번호</label>
            <div class="col-sm-10">
                <input type="password" name="password" id="password" class="form-control" autocomplete="off"/>
            </div>
        </div>
        <div class="row mb-3">
            <label for="passwordConfirmation" class="col-sm-2 col-form-label">@if(!$uid)<span class="text-danger">*</span>@endif 비밀번호 재입력</label>
            <div class="col-sm-10">
                <input type="password" name="password_confirmation" id="passwordConfirmation" class="form-control" autocomplete="off"/>
            </div>
        </div>
        <div class="row mb-3">
            <label for="name" class="col-sm-2 col-form-label"><span class="text-danger">*</span> 이름</label>
            <div class="col-sm-10">
                <input type="text" name="name" id="name" class="form-control" value="{{ $userData->name ?? old('name') }}" />
            </div>
        </div>
        <div class="row mb-3">
            <label for="nickname" class="col-sm-2 col-form-label"><span class="text-danger">*</span> 닉네임</label>
            <div class="col-sm-10">
                <input type="text" name="nickname" id="nickname" class="form-control" value="{{ $userData->nickname ?? old('nickname') }}" />
            </div>
        </div>
        <div class="row mb-3">
            <label class="col-sm-2 col-form-label">프로필 이미지</label>
            <div class="col-sm-10">
                @if($userData->thumb ?? '')
                    <img src="{{ asset($userData->thumb) }}" />
                    <div class="form-check mt-2">
                        <input type="checkbox" name="thumb_del" id="thumbDel" class="form-check-input" value="1" />
                        <input type="hidden" name="thumb_url" id="thumbURL" value="{{ $userData->thumb }}" />
                        <label for="thumbDel" class="form-check-label">삭제</label>
                    </div>
                @else
                    <input type="file" name="thumb" id="thumb" value="{{ $userData->thumb ?? old('thumb') }}" accept="image/gif,image/jpeg,image/png" />
                    <div class="form-text text-muted">
                         96 x 96px 에 최적화되어있습니다., gif, jpg, png 확장자만 첨부 가능합니다.
                    </div>
                @endif
            </div>
        </div>
        <div class="row mb-3">
            <label for="aboutMe" class="col-sm-2 col-form-label">자기소개</label>
            <div class="col-sm-10">
                <textarea name="about_me" id="aboutMe" class="form-control" rows="5">{{ $userData->about_me ?? old('about_me') }}</textarea>
            </div>
        </div>
        <div class="row mb-3">
            <label for="receiveEmail" class="col-sm-2">이메일 수신</label>
            <div class="col-sm-10">
                <div class="form-check">
                    <input type="checkbox" name="receive_email" id="receiveEmail" class="form-check-input" value="1" @if($userData->receive_email ?? old('receive_email')) checked @endif/>
                    <label for="receiveEmail" class="form-check-label">수신</label>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="isDenied" class="col-sm-2">차단 여부</label>
            <div class="col-sm-10">
                <div class="form-check">
                    <input type="checkbox" name="is_denied" id="isDenied" class="form-check-input" value="1" @if($userData->is_denied ?? old('is_denied')) checked @endif/>
                    <label for="isDenied" class="form-check-label">차단</label>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="isWithdraw" class="col-sm-2">탈퇴 여부</label>
            <div class="col-sm-10">
                <div class="form-check">
                    <input type="checkbox" name="is_withdraw" id="isWithdraw" class="form-check-input" value="1" @if($userData->is_withdraw ?? old('is_withdraw')) checked @endif/>
                    <label for="isWithdraw" class="form-check-label">탈퇴</label>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="isAdmin" class="col-sm-2">관리자 여부</label>
            <div class="col-sm-10">
                <div class="form-check">
                    <input type="checkbox" name="is_admin" id="isAdmin" class="form-check-input" value="1" @if($userData->is_admin ?? old('is_admin')) checked @endif/>
                    <label for="isAdmin" class="form-check-label">관리자</label>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="isOpenProfile" class="col-sm-2">정보 공개 여부</label>
            <div class="col-sm-10">
                <div class="form-check">
                    <input type="checkbox" name="is_open_profile" id="isOpenProfile" class="form-check-input" value="1" @if($userData->is_open_profile ?? old('is_open_profile')) checked @endif/>
                    <label for="isOpenProfile" class="form-check-label">공개</label>
                </div>
            </div>
        </div>
        @isset($userData->updated_at)
        <div class="row mb-3">
            <label class="col-sm-2">수정일시</label>
            <div class="col-sm-10">
                {{ $userData->updated_at }}
            </div>
        </div>
        @endisset
        @isset($userData->created_at)
        <div class="row">
            <label class="col-sm-2">등록일시</label>
            <div class="col-sm-10">
                {{ $userData->created_at }}
            </div>
        </div>
        @endisset
        <hr/>
        <div class="text-end">
            <button type="submit" class="btn btn-success">저장하기</button>
            <button type="button" class="btn btn-light btn-write-cancel" value="{{ route('admin.user.list.index') }}">취소하기</button>
        </div>
    </form>
</div>

<script src="http://dmaps.daum.net/map_js_init/postcode.v2.js"></script>
<script type="module">
$("#fAdminWrite").validate({
    rules: {
        name: {required: true, minlength: 2, maxlength: 20},
        nickname: {required: true, minlength: 2, maxlength: 20},
        email: {required: true, email: true},
        @if(!$uid)
        password: {required: true, minlength: 6},
        password_confirmation: {required: true, minlength: 4, equalTo: '#password'},
        @endif
        thumb: {accept: "image/gif,image/jpeg,image/png"},
        about_me: {required: false, maxlength: 500},
        receive_email: {required: false, number: true},
        is_denied: {required: false, number: true},
        is_withdraw: {required: false, number: true},
        is_admin: {required: false, number: true},
        is_open_profile: {required: false, number: true}
    }
});
</script>
@endsection
