@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="{{ route('admin.sms.config.store') }}">
        @csrf
        <div class="row mb-3">
            <label for="useSms" class="col-sm-2">SMS 기능</label>
            <div class="col-sm-10">
                <div class="form-check">
                    <input type="checkbox" name="use_sms" id="useSms" class="form-check-input" value="1" @if(config('use_sms')) checked @endif />
                    <label for="useSms" class="form-check-label">
                        사용합니다.
                    </label>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="smsIcodeID" class="col-sm-2 col-form-label">아이코드 ID</label>
            <div class="col-sm-10">
                <input type="text" name="sms_icode_id" id="smsIcodeID" class="form-control w-auto" value="{{ config('sms_icode_id') }}" />
                <div class="form-text text-muted">
                    아이코드 가입하기 : <a href="http://www.icodekorea.com">http://www.icodekorea.com</a>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="smsIcodePw" class="col-sm-2 col-form-label">아이코드 PW</label>
            <div class="col-sm-10 form-inline">
                <input type="password" name="sms_icode_pw" id="smsIcodePw" class="form-control" value="{{ config('sms_icode_pw') }}" />
            </div>
        </div>
        <div class="row mb-3">
            <label for="smsIcodeCallNum" class="col-sm-2 col-form-label">문자 발송 번호</label>
            <div class="col-sm-10">
                <input type="text" name="sms_icode_call_num" id="smsIcodeCallNum" class="form-control w-auto" value="{{ config('sms_icode_call_num') }}" />
                <div class="form-text text-muted">
                    보내는 사람의 번호입니다. ‘발신번호사전등록’된 번호만 이용 가능 합니다. (예외사업자 제외)
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="smsIcodeHost" class="col-sm-2 col-form-label">서버 IP</label>
            <div class="col-sm-10">
                <input type="text" name="sms_icode_host" id="smsIcodeHost" class="form-control w-auto" value="{{ config('sms_icode_host') }}" />
                <div class="form-text text-muted">
                    소켓 수신 전용서버
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="smsIcodePort" class="col-sm-2 col-form-label">서버 Port</label>
            <div class="col-sm-10">
                <input type="text" name="sms_icode_port" id="smsIcodePort" class="form-control only-digits-input w-auto" value="{{ config('sms_icode_port') }}" />
                <div class="form-text text-muted">
                    모든 요금제 통합 포트번호.
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="smsIcodeToken" class="col-sm-2 col-form-label">토큰키 (Token key)</label>
            <div class="col-sm-10">
                <input type="text" name="sms_icode_token" id="smsIcodeToken" class="form-control col-md-4" value="{{ config('sms_icode_token') }}" />
                <div class="form-text text-muted">
                    토큰키는 고객사 사이트(프로그램)에서 문자 전송시 아이디와 비밀번호 대신 이용하게 될 인증키로 쓰여집니다.
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label class="col-sm-2">요금제</label>
            <div class="col-sm-10">
                 <div class="form-text text-muted">
                     <?php
                     $paymentStr = $icodeRet['payment'] ?? '';
                     if ($paymentStr === 'C') {
                         echo '정액제';
                     } elseif ($paymentStr === 'A') {
                         echo '충전제';
                     } else {
                         echo '-';
                     }
                     ?>
                 </div>
            </div>
        </div>
        <div class="row mb-3">
            <label class="col-sm-2">충전 잔액</label>
            <div class="col-sm-10">
                <div class="form-text text-muted">
                    {{ $icodeRet['coin'] ?? '-' }} 원
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label class="col-sm-2">건별 잔액</label>
            <div class="col-sm-10">
                <div class="form-text text-muted">
                    {{ $icodeRet['gpay'] ?? '-' }} 원
                </div>
            </div>
        </div>
        <hr/>
        <div class="text-end">
            <button type="submit" class="btn btn-success">저장하기</button>
        </div>
    </form>
</div>

<script type="module">
$("#fAdminWrite").validate({
    rules: {
        use_sms: {number: true},
        sms_icode_id: {required: true},
        sms_icode_pw: {required: true},
        sms_icode_call_num: {required: true},
        sms_icode_host: {required: true},
        sms_icode_port: {required: true, number: true},
        sms_icode_token: {required: true}
    }
});
</script>
@endsection
