@extends('admin.layouts.app')

@section('content')
<div class="container-fluid">
    <h2>SMS 자주 보내는 문자 @if($favoriteID) 수정 @else 등록 @endif</h2>
    <hr/>
    @include('admin.messages')

    <form name="f_admin_write" id="fAdminWrite" method="post" action="{{ $actionURL }}">
        @csrf
        @if($favoriteID)
            <input type="hidden" name="favorite_id" value="{{ $favoriteID }}" />
            @method('PUT')
        @endif
        <div class="row mb-3">
            <label for="type_1" class="col-sm-2">형식</label>
            <div class="col-sm-10">
                <div class="form-check form-check-inline">
                    <input type="radio" name="type" id="type_1" class="form-check-input" value="1" @if(($smsFavoriteData->type ?? old('type')) == 1) checked @endif />
                    <label for="type_1" class="form-check-label">SMS</label>
                </div>
                <div class="form form-check-inline">
                    <input type="radio" name="type" id="type_2" class="form-check-input" value="2" @if(($smsFavoriteData->type ?? old('type')) == 2) checked @endif />
                    <label for="type_2" class="form-check-label">LMS</label>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="subject" class="col-sm-2 col-form-label">제목</label>
            <div class="col-sm-10">
                <input type="text" name="subject" id="subject" class="form-control" value="{{ $smsFavoriteData->subject ?? old('subject') }}" />
            </div>
        </div>
        <div class="row mb-3">
            <label for="contents" class="col-sm-2 col-form-label">내용</label>
            <div class="col-sm-10">
                <textarea name="content" id="contents" class="form-control" rows="10">{{ $smsFavoriteData->content ?? old('content') }}</textarea>
                <div class="row mt-2">
                    <div class="col">
                         <span class="form-text text-muted">
                            <span id="contentByte">0</span> / 2000 byte
                        </span>
                    </div>
                    <div class="col text-end">
                        <div class="d-grid gap-2 d-md-block position-relative">
                            <button type="button" class="btn btn-dark btn-sm rounded-start dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">특수문자</button>
                            <div class="dropdown-menu">
                                <button type="button" class="btn btn-sm" onclick="add('■');">■</button>
                                <button type="button" class="btn btn-sm" onclick="add('□');">□</button>
                                <button type="button" class="btn btn-sm" onclick="add('▣');">▣</button>
                                <button type="button" class="btn btn-sm" onclick="add('◈');">◈</button>
                                <button type="button" class="btn btn-sm" onclick="add('◆');">◆</button>
                                <button type="button" class="btn btn-sm" onclick="add('◇');">◇</button>
                                <button type="button" class="btn btn-sm" onclick="add('♥');">♥</button>
                                <button type="button" class="btn btn-sm" onclick="add('♡');">♡</button>
                                <button type="button" class="btn btn-sm" onclick="add('●');">●</button>
                                <button type="button" class="btn btn-sm" onclick="add('○');">○</button>
                                <button type="button" class="btn btn-sm" onclick="add('▲');">▲</button>
                                <button type="button" class="btn btn-sm" onclick="add('▼');">▼</button>
                                <button type="button" class="btn btn-sm" onclick="add('▶');">▶</button>
                                <button type="button" class="btn btn-sm" onclick="add('▷');">▷</button>
                                <button type="button" class="btn btn-sm" onclick="add('◀');">◀</button>
                                <button type="button" class="btn btn-sm" onclick="add('◁');">◁</button>
                                <button type="button" class="btn btn-sm" onclick="add('☎');">☎</button>
                                <button type="button" class="btn btn-sm" onclick="add('☏');">☏</button>
                                <button type="button" class="btn btn-sm" onclick="add('♠');">♠</button>
                                <button type="button" class="btn btn-sm" onclick="add('♤');">♤</button>
                                <button type="button" class="btn btn-sm" onclick="add('♣');">♣</button>
                                <button type="button" class="btn btn-sm" onclick="add('♧');">♧</button>
                                <button type="button" class="btn btn-sm" onclick="add('★');">★</button>
                                <button type="button" class="btn btn-sm" onclick="add('☆');">☆</button>
                                <button type="button" class="btn btn-sm" onclick="add('☞');">☞</button>
                                <button type="button" class="btn btn-sm" onclick="add('☜');">☜</button>
                                <button type="button" class="btn btn-sm" onclick="add('▒');">▒</button>
                                <button type="button" class="btn btn-sm" onclick="add('⊙');">⊙</button>
                                <button type="button" class="btn btn-sm" onclick="add('㈜');">㈜</button>
                                <button type="button" class="btn btn-sm" onclick="add('№');">№</button>
                                <button type="button" class="btn btn-sm" onclick="add('㉿');">㉿</button>
                                <button type="button" class="btn btn-sm" onclick="add('♨');">♨</button>
                                <button type="button" class="btn btn-sm" onclick="add('™');">™</button>
                                <button type="button" class="btn btn-sm" onclick="add('℡');">℡</button>
                                <button type="button" class="btn btn-sm" onclick="add('∑');">∑</button>
                                <button type="button" class="btn btn-sm" onclick="add('∏');">∏</button>
                                <button type="button" class="btn btn-sm" onclick="add('♬');">♬</button>
                                <button type="button" class="btn btn-sm" onclick="add('♪');">♪</button>
                                <button type="button" class="btn btn-sm" onclick="add('♩');">♩</button>
                                <button type="button" class="btn btn-sm" onclick="add('♭');">♭</button>
                                <button type="button" class="btn btn-sm" onclick="add('*^^*');">*^^*</button>
                                <button type="button" class="btn btn-sm" onclick="add('♡.♡');">♡.♡</button>
                                <button type="button" class="btn btn-sm" onclick="add('@_@');">@_@</button>
                                <button type="button" class="btn btn-sm" onclick="add('☞_☜');">☞_☜</button>
                                <button type="button" class="btn btn-sm" onclick="add('ㅠ ㅠ');">ㅠ ㅠ</button>
                                <button type="button" class="btn btn-sm" onclick="add('Θ.Θ');">Θ.Θ</button>
                                <button type="button" class="btn btn-sm" onclick="add('^_~♥');">^_~♥</button>
                                <button type="button" class="btn btn-sm" onclick="add('~o~');">~o~</button>
                                <button type="button" class="btn btn-sm" onclick="add('★.★');">★.★</button>
                                <button type="button" class="btn btn-sm" onclick="add('(!.!)');">(!.!)</button>
                                <button type="button" class="btn btn-sm" onclick="add('⊙.⊙');">⊙.⊙</button>
                                <button type="button" class="btn btn-sm" onclick="add('q.p');">q.p</button>
                                <button type="button" class="btn btn-sm" onclick="add('┏( \'\')┛');">┏( \'\')┛</button>
                                <button type="button" class="btn btn-sm" onclick="add('@)-)--');">@)-)--')</button>
                                <button type="button" class="btn btn-sm" onclick="add('↖(^-^)↗');">↖(^-^)↗</button>
                                <button type="button" class="btn btn-sm" onclick="add('(*^-^*)');">(*^-^*)</button>
                            </div>
                            <button type="button" class="btn btn-dark btn-sm rounded-end dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">이모티콘</button>
                            <div class="dropdown-menu">
                                <button type="button" class="btn btn-sm" onclick="add('*^^*');">*^^*</button>
                                <button type="button" class="btn btn-sm" onclick="add('♡.♡');">♡.♡</button>
                                <button type="button" class="btn btn-sm" onclick="add('@_@');">@_@</button>
                                <button type="button" class="btn btn-sm" onclick="add('☞_☜');">☞_☜</button>
                                <button type="button" class="btn btn-sm" onclick="add('ㅠ ㅠ');">ㅠ ㅠ</button>
                                <button type="button" class="btn btn-sm" onclick="add('Θ.Θ');">Θ.Θ</button>
                                <button type="button" class="btn btn-sm" onclick="add('^_~♥');">^_~♥</button>
                                <button type="button" class="btn btn-sm" onclick="add('~o~');">~o~</button>
                                <button type="button" class="btn btn-sm" onclick="add('★.★');">★.★</button>
                                <button type="button" class="btn btn-sm" onclick="add('(!.!)');">(!.!)</button>
                                <button type="button" class="btn btn-sm" onclick="add('⊙.⊙');">⊙.⊙</button>
                                <button type="button" class="btn btn-sm" onclick="add('q.p');">q.p</button>
                                <button type="button" class="btn btn-sm" onclick="add('┏( \'\')┛');">┏( \'\')┛</button>
                                <button type="button" class="btn btn-sm" onclick="add('@)-)--');">@)-)--')</button>
                                <button type="button" class="btn btn-sm" onclick="add('↖(^-^)↗');">↖(^-^)↗</button>
                                <button type="button" class="btn btn-sm" onclick="add('(*^-^*)');">(*^-^*)</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        @isset($smsFavoriteData->updated_at)
        <div class="row mb-3">
            <label class="col-sm-2">수정일시</label>
            <div class="col-sm-10">
                {{ $smsFavoriteData->updated_at }}
            </div>
        </div>
        @endisset
        @isset($smsFavoriteData->created_at)
        <div class="row">
            <label class="col-sm-2">등록일시</label>
            <div class="col-sm-10">
                {{ $smsFavoriteData->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.sms.favorite.index') }}">취소하기</button>
        </div>
    </form>
</div>

<script>
var contents = "contents";
var contentByte = "contentByte";

$(function() {
    $("#fAdminWrite").validate({
        rules: {
            type: {required: true, number: true},
            subject: {required: true, maxlength: 30},
            content: {required: true, maxlength: 2000}
        }
    });

    byteCheck(contents, contentByte);
    document.getElementById(contents).focus();
});

// 문자 내용 입력 시
$(document).on('keydown keyup', '#' + contents, function() {
    byteCheck(contents, contentByte);
});

function add(str) {
    let content = document.getElementById(contents);
    content.focus();
    content.value += str;
    byteCheck(contents, contentByte);
    return true;
}
</script>
@endsection
