@extends('admin.layouts.app')

@section('content')
<div class="container-fluid">
    <h2>SMS 주소록 관리</h2>
    <hr/>
    @include('admin.messages')

    <form name="f_admin_write" id="fAdminWrite" method="post" action="{{ $actionURL }}">
        @csrf
        <input type="hidden" name="book" value="{{ $book }}"/>
        <div class="row mb-3">
            <label for="users" class="col-sm-2 col-form-label">회원 ID</label>
            <div class="col-sm-10">
                <button type="button" id="researchUserPop" class="btn btn-secondary">회원조회</button>
                <textarea name="users" id="users" class="form-control mt-2" rows="7" placeholder="쉼표(,) 로 구분 입력">{{ old('users') }}</textarea>
            </div>
        </div>
        <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.sms.book.user.index') }}?group={{ $book }}">취소하기</button>
        </div>
    </form>
</div>

<script>
$("#fAdminWrite").validate({
    rules: {
        users: {required: true}
    }
});

// 회원조회
$(document).on("click", "#researchUserPop", function() {
    popupCenter(ADMIN_URL + "/popup/user", "회원 검색", 970, 570);
});

// 회원추가
function setUser(users)
{
    if(users.length > 0) {
        let userID = [];
        users.forEach(function(i) {
            userID.push(i.id);
        });
        $("#users").val(userID.join(","));
    }
}
</script>
@endsection
