@extends('base.base')
@section('base')
    <!-- 内容区域 -->
    <div class="main-panel">
        <div class="content-wrapper">
            <div class="page-header">
                <h3 class="page-title">
                     <span class="page-title-icon bg-gradient-primary text-white mr-2">
                        <i class="mdi mdi-settings"></i>
                    </span>
                    {{ __('auto.马甲切换网关') }}
                </h3>
            </div>
            <div class="row">
                <div class="col-lg-12 grid-margin stretch-card">
                    <div class="card">
                        <div class="card-body">
                            <table width="100%">
                                <tr>
                                    <td><h4>{{ __('auto.渠道名') }}: {{$config->Remarks}} </h4></td>
                                    <td><h4>AppKey:{{$config->AppKey}} </h4></td>
                                </tr>
                                <tr>

                                    <td><h4>{{ __('auto.包名') }}: {{$config->PackageName}} </h4></td>
                                   <td >
                                       <h4 id="finalURL">URL:</h4>
                                   </td>
                                </tr>

                                <tr>
                                    <td colspan="2">
                                        <h4 id="adjustNow">{{$config->AdjustToken}}</h4>
                                    </td>
                                </tr>
                            </table>

                            <form class="forms-sample form-ajax" id="form">

                                <div class="form-group">
                                    <label for="">{{ __('auto.设置开关绑定域名') }}:({{ __('auto.需要附带协议') }}http)</label>
                                    <input class="form-control" type="text" id="AppCheckDomain" name="AppCheckDomain" onblur="setDomain(this)" value="{{$config->AppCheckDomain}}">
                                </div>
                                <div class="form-group">
                                    <label for="">{{ __('auto.设置') }}AdjustToken:</label>
                                    <input class="form-control" type="text" name="AdjustToken"  id="AdjustToken" onblur="setAdjust(this)"  id="AdjustToken" value="{{$config->AdjustToken}}">
                                </div>

                                <div class="form-group">
                                    <label for="">{{ __('auto.配置Adjust事件') }}:</label>
                                    <input type="hidden" name="AdjustConfig" id="AdjustConfig" value="{{$config->AdjustConfig}}">
                                    <button type="button" class="btn btn-sm btn-gradient-success btn-icon-text" onclick="addEventsAll()">
                                        <i class="mdi mdi-plus btn-icon-prepend"></i>
                                        {{ __('auto.重新获取配置') }}
                                    </button>
                                    <button type="button" class="btn btn-sm btn-gradient-primary btn-icon-text"  onclick="copyConfig()">
                                        {{ __('auto.复制客户端配置') }}
                                    </button>
                                    <button type="button" class="btn btn-sm btn-gradient-primary btn-icon-text"  onclick="copyServerConfig()">
                                        {{ __('auto.复制服务端配置') }}
                                    </button>
                                </div>
                                <div class="form-group">
                                    <button class="btn btn-sm btn-gradient-primary">{{ __('auto.提交') }}</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>


        function setDomain(obj){
            if(obj){
                $("#finalURL").html("{{ __('auto.验证网关：') }}"+$(obj).val()+"/"+"{{$config->AppKey}}/?l=&a=");
            }


        }
        function setAdjust(obj){
            if(obj){
                $("#adjustNow").html("AdjustToken："+$(obj).val());
            }


        }
        setDomain($("#AppCheckDomain"))
        setAdjust($("#AdjustToken"))
    let adjust_config='{{$config->AdjustConfig}}'.split('|')[0]
    let adjust_server_config='{{$config->AdjustConfig}}'.split('|')[1]
    function copyConfig(){
        pasteboard(adjust_config)

    }
    function copyServerConfig(){
        pasteboard(adjust_server_config)

    }
        function pasteboard(str)
       {
           if (navigator.clipboard) {
               // clipboard api 复制
               navigator.clipboard.writeText(str);
           }else {
               var save = function (e) {
                   e.clipboardData.setData('text/plain', str);
                   e.preventDefault();
               }
               document.addEventListener('copy', save);
               document.execCommand('copy');
               document.removeEventListener('copy', save);
           }

       }




    </script>
@endsection
