@page "{id:int}"
@model Admin.Pages.Member.List.EditModel
@using Domain.Entities.Members.ValueObject
@{
    ViewData["Title"] = "회원 수정";
}

<div class="container">
    <h3>@ViewData["Title"]</h3>
    <hr />

    <partial name="_StatusMessage" />

    <form name="f_admin_write" id="fAdminWrite" method="post" accept-charset="utf-8" autocomplete="off" enctype="multipart/form-data">
        <input type="hidden" asp-for="Input.ID" />
        <input type="hidden" asp-for="QueryString" />

        <div class="row mb-2">
            <label class="col-sm-2 col-form-label"><span>*</span> PK</label>
            <div class="col-sm-10">
                <input type="text" readonly class="form-control-plaintext" value="@Model.Input.ID" />
            </div>
        </div>
        <div class="row mb-2">
            <label asp-for="Input.MemberGradeID" class="col-sm-2 col-form-label"></label>
            <div class="col-sm-10">
                <select asp-for="Input.MemberGradeID" class="form-select w-auto" asp-items="Model.MemberGradeList">
                    <option value="">등급 선택</option>
                </select>
                <span asp-validation-for="Input.MemberGradeID" class="text-danger"></span>
            </div>
        </div>
        <div class="row mb-2">
            <label for="Input_Email" class="col-sm-2 col-form-label"><span>*</span> 이메일</label>
            <div class="col-sm-10">
                <input type="email" asp-for="Input.Email" class="form-control" required maxlength="60" placeholder="중복 시 등록이 불가합니다. 60자 이내" />
                <span asp-validation-for="Input.Email" class="text-danger"></span>
            </div>
        </div>
        <div class="row mb-2">
            <label for="Input_Name" class="col-sm-2 col-form-label"><span>*</span> 별명</label>
            <div class="col-sm-10">
                <input type="text" asp-for="Input.Name" class="form-control" required maxlength="20" placeholder="중복 시 등록이 불가합니다. 20자 이내" />
                <span asp-validation-for="Input.Name" class="text-danger"></span>
            </div>
        </div>
        <div class="row mb-2">
            <label asp-for="Input.Password" class="col-sm-2 col-form-label"></label>
            <div class="col-sm-10">
                <input type="password" asp-for="Input.Password" class="form-control" minlength="4" />
                <span asp-validation-for="Input.Password" class="text-danger"></span>
            </div>
        </div>
        <div class="row mb-2">
            <label for="RePassword" class="col-sm-2 col-form-label">비밀번호 확인</label>
            <div class="col-sm-10">
                <input type="password" name="RePassword" id="RePassword" class="form-control" minlength="4" />
                <span class="form-text text-muted">비밀번호는 변경할 경우 입력합니다.</span>
            </div>
        </div>
        <hr/>
        <div class="row mb-2">
            <label asp-for="Input.FirstName" class="col-sm-2 col-form-label"></label>
            <div class="col-sm-10">
                <input type="text" asp-for="Input.FirstName" class="form-control" maxlength="20" placeholder="최대 20자" />
                <span asp-validation-for="Input.FirstName" class="text-danger"></span>
            </div>
        </div>
        <div class="row mb-2">
            <label asp-for="Input.LastName" class="col-sm-2 col-form-label"></label>
            <div class="col-sm-10">
                <input type="text" asp-for="Input.LastName" class="form-control" maxlength="40" placeholder="최대 40자" />
                <span asp-validation-for="Input.LastName" class="text-danger"></span>
            </div>
        </div>
        <div class="row mb-2">
            <label asp-for="Input.Intro" class="col-sm-2"></label>
            <div class="col-sm-10">
                <textarea asp-for="Input.Intro" class="form-control" placeholder="최대 1000자" rows="2" maxlength="1000"></textarea>
                <span asp-validation-for="Input.Intro" class="text-danger"></span>
            </div>
        </div>
        <div class="row mb-2">
            <label asp-for="Input.Summary" class="col-sm-2"></label>
            <div class="col-sm-10">
                <input type="text" asp-for="Input.Summary" class="form-control" maxlength="50" placeholder="50자 이내"/>
                <span asp-validation-for="Input.Summary" class="text-danger"></span>
            </div>
        </div>
        <div class="row mb-2">
            <label asp-for="Input.Phone" class="col-sm-2"></label>
            <div class="col-sm-10">
                <input type="text" asp-for="Input.Phone" class="form-control" maxlength="15" placeholder="010-0000-0000 형식으로 입력하세요." pattern="010-\d{4}-\d{4}" />
                <span asp-validation-for="Input.Phone" class="text-danger"></span>
            </div>
        </div>
        <div class="row mb-2">
            <label asp-for="Input.Gender" class="col-sm-2 col-form-label"></label>
            <div class="col-sm-10 align-content-center">
                <div class="form-check-inline">
                    <input type="radio" asp-for="Input.Gender" id="male" class="form-check-input" value="@Gender.Male" />
                    <label class="form-check-label" for="male">남자</label>
                </div>
                <div class="form-check-inline">
                    <input type="radio" asp-for="Input.Gender" id="female" class="form-check-input" value="@Gender.Female" />
                    <label class="form-check-label" for="female">여자</label>
                </div>
                <span asp-validation-for="Input.Gender" class="text-danger"></span>
            </div>
        </div>
        <div class="row mb-2">
            <label asp-for="Input.Birthday" class="col-sm-2"></label>
            <div class="col-sm-10">
                <input type="date" asp-for="Input.Birthday" class="form-control w-auto" />
                <span asp-validation-for="Input.Birthday" class="text-danger"></span>
            </div>
        </div>
        <div class="row mb-2">
            <label asp-for="Input.Thumb" class="col-sm-2 col-form-label"></label>
            <div class="col-sm-10">
                @if (!string.IsNullOrEmpty(Model.Thumb))
                {
                    <img src="@Url.Content(Model.Thumb)" class="img-fluid img-thumbnail" alt="사진" /><br />
                    <div class="form-check-inline">
                        <input type="checkbox" name="isThumbRemove" id="IsThumbRemove" class="form-check-input" value="true" />
                        <label for="IsThumbRemove" class="form-check-label">삭제</label>
                    </div>
                }
                else
                {
                    <div id="thumbPrev" hidden><img class="img-fluid img-thumbnail" alt="사진 미리보기" /></div>
                    <input type="file" asp-for="Input.Thumb" class="form-control" accept="image/*" />
                    <span asp-validation-for="Input.Thumb" class="text-danger"></span>
                }
            </div>
        </div>
        <div class="row mb-2">
            <label asp-for="Input.Icon" class="col-sm-2 col-form-label"></label>
            <div class="col-sm-10">
                @if (!string.IsNullOrEmpty(Model.Icon))
                {
                    <img src="@Url.Content(Model.Icon)" class="img-fluid img-thumbnail" alt="아이콘" />
                    <br />
                    <div class="form-check-inline">
                        <input type="checkbox" name="isIconRemove" id="IsIconRemove" class="form-check-input" value="true" />
                        <label for="IsIconRemove" class="form-check-label">삭제</label>
                    </div>
                }
                else
                {
                    <div id="iconPrev" hidden><img class="img-fluid img-thumbnail" alt="아이콘 미리보기" /></div>
                    <input type="file" asp-for="Input.Icon" class="form-control" accept="image/*" />
                    <span asp-validation-for="Input.Icon" class="text-danger"></span>
                }
            </div>
        </div>
        <hr />
        <div class="row mb-2">
            <label asp-for="Input.IsEmailVerified" class="col-sm-2 col-form-label"></label>
            <div class="col-sm-10 align-content-center">
                <div class="form-check-inline">
                    <input type="checkbox" asp-for="Input.IsEmailVerified" class="form-check-input" />
                    <label class="form-check-label" for="Input_IsEmailVerified">인증 했습니다.</label>
                    <span asp-validation-for="Input.IsEmailVerified" class="text-danger"></span>
                    @if (Model.EmailVerifiedAt is not null)
                    {
                        <span class="form-text text-muted">@Model.EmailVerifiedAt</span>
                    }
                </div>
            </div>
        </div>
        <div class="row mb-2">
            <label asp-for="Input.IsAuthCertified" class="col-sm-2 col-form-label"></label>
            <div class="col-sm-10 align-content-center">
                <div class="form-check-inline">
                    <input type="checkbox" asp-for="Input.IsAuthCertified" class="form-check-input" />
                    <label class="form-check-label" for="Input_IsAuthCertified">인증 했습니다.</label>
                    <span asp-validation-for="Input.IsAuthCertified" class="text-danger"></span>
                    @if (Model.AuthCertifiedAt is not null)
                    {
                        <span class="form-text text-muted">@Model.AuthCertifiedAt</span>
                    }
                </div>
            </div>
        </div>
        <div class="row mb-2">
            <label asp-for="Input.IsDenied" class="col-sm-2 col-form-label"></label>
            <div class="col-sm-10 align-content-center">
                <div class="form-check-inline">
                    <input type="checkbox" asp-for="Input.IsDenied" class="form-check-input" />
                    <label class="form-check-label" for="Input_IsDenied">차단합니다.</label>
                    <span asp-validation-for="Input.IsDenied" class="text-danger"></span>
                    @if (Model.DeniedAt is not null)
                    {
                        <span class="form-text text-muted">@Model.DeniedAt</span>
                    }
                </div>
            </div>
        </div>
        <div class="row mb-2">
            <label asp-for="Input.IsAdmin" class="col-sm-2 col-form-label"></label>
            <div class="col-sm-10 align-content-center">
                <div class="form-check-inline">
                    <input type="checkbox" asp-for="Input.IsAdmin" class="form-check-input" />
                    <label class="form-check-label" for="Input_IsAdmin">관리자입니다.</label>
                    <span asp-validation-for="Input.IsAdmin" class="text-danger"></span>
                </div>
            </div>
        </div>
        <div class="row mb-2">
            <label asp-for="Input.IsWithdraw" class="col-sm-2 col-form-label"></label>
            <div class="col-sm-10 align-content-center">
                <div class="form-check-inline">
                    <input type="checkbox" asp-for="Input.IsWithdraw" class="form-check-input" />
                    <label class="form-check-label" for="Input_IsWithdraw">탈퇴했습니다.</label>
                    <span asp-validation-for="Input.IsWithdraw" class="text-danger"></span>
                    @if (Model.DeletedAt is not null)
                    {
                        <span class="form-text text-muted">@Model.DeletedAt</span>
                    }
                </div>
            </div>
        </div>
        @if (Model.UpdatedAt is not null)
        {
            <div class="row mb-2">
                <label class="col-sm-2 col-form-label">수정일시</label>
                <div class="col-sm-10">
                    <input class="form-control-plaintext" type="text" readonly value="@Model.UpdatedAt" />
                </div>
            </div>
        }
        @if (Model.CreatedAt is not null)
        {
            <div class="row mb-2">
                <label class="col-sm-2 col-form-label">등록일시</label>
                <div class="col-sm-10">
                    <input class="form-control-plaintext" type="text" readonly value="@Model.CreatedAt" />
                </div>
            </div>
        }
        <hr/>
        <div class="d-grid gap-2 text-center d-md-block">
            <button type="submit" class="btn btn-success">저장</button>
            <a href="/Member/List?@Model.QueryString" class="btn btn-secondary">취소</a>
        </div>
        <br/>
    </form>
</div>

@section Scripts {
    <script>
        setupImagePreview("Input_Thumb", "thumbPrev");
        setupImagePreview("Input_Icon", "iconPrev");

        $(document).on("submit", "#fAdminWrite", function(e) {
            e.preventDefault();
            const password = e.target.elements["Input.Password"].value;
            const rePassword = e.target.elements["RePassword"].value;
            if (password !== rePassword) {
                alert("비밀번호가 일치하지 않습니다.");
                return false;
            }
            this.submit();
        });
    </script>
}