@extends('admin.layouts.app')

@section('content')
<div class="container-fluid">
    <h2>토스 인증</h2>
    <hr/>
    @include('admin.messages')
    @include('admin.config.register.navTabs')

    <form name="f_admin_write" id="fAdminWrite" method="post" action="{{ route('admin.config.register.toss.store') }}" enctype="multipart/form-data">
        @csrf
        <div class="row mb-3">
            <label for="tossCertIsTest_0" class="col-sm-2 col-form-label">토스 인증서</label>
            <div class="col-sm-10">
                <div class="form-check form-check-inline">
                    <input type="radio" name="toss_cert_is_test" id="tossCertIsTest_0" class="form-check-input" value="0" @if(!($config->toss_cert_is_test ?? old('toss_cert_is_test'))) checked @endif/>
                    <label for="tossCertIsTest_0" class="form-check-label">Live</label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="radio" name="toss_cert_is_test" id="tossCertIsTest_1" class="form-check-input" value="1" @if($config->toss_cert_is_test ?? old('toss_cert_is_test')) checked @endif/>
                    <label for="tossCertIsTest_1" class="form-check-label">Test</label>
                </div>
                <div class="form-text text-muted">
                    토스 인증서 테스트 사용 여부 (https://toss.im/tosscert/docs/guides/test)
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label class="col-sm-2">Live</label>
            <div class="col-sm-10">
                <div class="row">
                    <div class="col-12 col-sm">
                        <label for="liveTossCertClientID" class="form-label">Client ID</label>
                        <input type="text" name="live_toss_cert_client_id" id="liveTossCertClientID" class="form-control" value="{{ $config->live_toss_cert_client_id ?? old('live_toss_cert_client_id') }}" />
                    </div>
                    <div class="col-12 col-sm">
                        <label for="liveTossCertClientSecret" class="form-label">Secret ID</label>
                        <input type="text" name="live_toss_cert_client_secret" id="liveTossCertClientSecret" class="form-control" value="{{ $config->live_toss_cert_client_secret ?? old('live_toss_cert_client_secret') }}" />
                    </div>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label class="col-sm-2">Test</label>
            <div class="col-sm-10">
                <div class="row">
                    <div class="col-12 col-sm">
                        <label for="testTossCertClientID" class="form-label">Client ID</label>
                        <input type="text" name="test_toss_cert_client_id" id="testTossCertClientID" class="form-control" value="{{ $config->test_toss_cert_client_id ?? old('test_toss_cert_client_id') }}" />
                    </div>
                    <div class="col-12 col-sm">
                        <label for="testTossCertClientSecret" class="form-label">Secret ID</label>
                        <input type="text" name="test_toss_cert_client_secret" id="testTossCertClientSecret" class="form-control" value="{{ $config->test_toss_cert_client_secret ?? old('test_toss_cert_client_secret') }}" />
                    </div>
                </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: {
        toss_cert_is_test: {required: true},
        live_toss_cert_client_id: {required: "#tossCertIsTest_0:checked", maxlength: 255},
        live_toss_cert_client_secret: {required: "#tossCertIsTest_0:checked", maxlength: 255},
        test_toss_cert_client_id: {required: "#tossCertIsTest_1:checked", maxlength: 255},
        test_toss_cert_client_secret: {required: "#tossCertIsTest_1:checked", maxlength: 255}
    }
});
</script>
@endsection
