@extends('base.base')
@section('base')
    <!-- 内容区域 -->
    <div class="main-panel">
        <div class="content-wrapper">
            <div class="row">
                <div class="col-lg-12 grid-margin stretch-card">
                    <div class="card">
                        <div class="card-body">
                            <h4 class="card-title">{{ __('auto.修改配置') }}</h4>
                            <form class="forms-sample" id="form">
                                <div class="form-group">
                                    <label>{{ __('auto.渠道号') }}</label>
                                    <input type="number" class="form-control" name="Channel" value="{{$info->Channel}}" readonly>
                                </div>
                                <div class="form-group">
                                    <label>{{ __('auto.包名') }}</label>
                                    <input type="text" class="form-control" name="PackageName" value="{{$info->PackageName}}">
                                </div>
                                <div class="form-group">
                                    @php $isRegionUnique = ($info->SpecialMode & 256) == 256; @endphp
                                    <label>RegionID{{__('auto.虚拟区域ID（账号隔离）')}}</label>
                                    <select class="form-control" name="RegionID" @if($isRegionUnique) disabled @endif>
                                        <option value="" @if($info->RegionID == '') selected @endif>None</option>
                                        @php $currentGroup = null; @endphp
                                        @foreach($regionList as $v)
                                            @if($currentGroup !== null && $currentGroup !== $v->GroupID)
                                                <option disabled>----------</option>
                                            @endif
                                            <option value="{{$v->RegionID}}" style="color: {{$groupColors[$v->GroupID] ?? '#000000'}};" @if($info->RegionID == $v->RegionID) selected @endif>{{$v->RegionID}}</option>
                                            @php $currentGroup = $v->GroupID; @endphp
                                        @endforeach
                                    </select>
                                    @if($isRegionUnique)
                                        <input type="hidden" name="RegionID" value="{{$info->RegionID}}">
                                    @endif
                                </div>
                                <div class="form-group">
                                    <label>{{ __('auto.备注') }}</label>
                                    <input type="text" class="form-control" name="Remarks" value="{{$info->Remarks}}">
                                </div>
                                <div class="form-group">
                                    <label>StateNo --- {{__('auto.模版状态编号')}}</label>
                                    <input type="number" class="form-control" name="StateNo" value="{{$info->StateNo}}">
                                </div>
                                <div class="form-group">
                                    <label>SpecialMode --- {{__('auto.特殊模式')}}</label>
                                    <div class="row">
                                        @foreach($specialModes as $val => $label)
                                            <div class="col-sm-6">
                                                <div class="form-check">
                                                    <label class="form-check-label">
                                                        <input type="checkbox" class="form-check-input" name="SpecialMode[]" value="{{$val}}" @if(($info->SpecialMode & $val) == $val) checked @endif @if($isRegionUnique && $val == 256) disabled @endif> {{$label}} ({{$val}})
                                                    </label>
                                                </div>
                                            </div>
                                        @endforeach
                                    </div>
                                    @if($isRegionUnique)
                                        <input type="hidden" name="SpecialMode[]" value="256">
                                    @endif
                                </div>
                                <div class="form-group">
                                    <label>RegOpen --- {{__('auto.开放注册方式')}}</label>
                                    <div class="row">
                                        @php $regOpen = explode(',', $info->RegOpen); @endphp
                                        @foreach(['id','phone','sms','mail','guest'] as $v)
                                            <div class="col-sm-2">
                                                <div class="form-check">
                                                    <label class="form-check-label">
                                                        <input type="checkbox" class="form-check-input" name="RegOpen[]" value="{{$v}}" @if(in_array($v, $regOpen)) checked @endif> {{$v}}
                                                    </label>
                                                </div>
                                            </div>
                                        @endforeach
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label>LoginOpen --- {{__('auto.开放登录方式')}}</label>
                                    <div class="row">
                                        @php $loginOpen = explode(',', $info->LoginOpen); @endphp
                                        @foreach(['id','phone','sms','mail','guest'] as $v)
                                            <div class="col-sm-2">
                                                <div class="form-check">
                                                    <label class="form-check-label">
                                                        <input type="checkbox" class="form-check-input" name="LoginOpen[]" value="{{$v}}" @if(in_array($v, $loginOpen)) checked @endif> {{$v}}
                                                    </label>
                                                </div>
                                            </div>
                                        @endforeach
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label>PlatformName --- {{__('auto.平台名称')}}</label>
                                    <select class="form-control" name="PlatformName">
                                        <option value="" @if($info->PlatformName == '') selected @endif>None</option>
                                        <option value="bigo" @if($info->PlatformName == 'bigo') selected @endif>BIGO</option>
                                        <option value="ios" @if($info->PlatformName == 'ios') selected @endif>iOS线上包</option>
                                        <option value="iosjump" @if($info->PlatformName == 'iosjump') selected @endif>iOS落地页+线上包</option>
                                        <option value="fb" @if($info->PlatformName == 'fb') selected @endif>Facebook (fb)</option>
                                        <option value="kwai" @if($info->PlatformName == 'kwai') selected @endif>海外快手 (kwai)</option>
                                        <option value="tt" @if($info->PlatformName == 'tt') selected @endif>Tiktok (tt)</option>
                                        <option value="gg" @if($info->PlatformName == 'gg') selected @endif>Google (gg)</option>
                                        <option value="apk" @if($info->PlatformName == 'apk') selected @endif>Apk落地页 (apk)</option>
                                        <option value="snapchat" @if($info->PlatformName == 'snapchat') selected @endif>snapchat</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>PlatformID (eg:pixelid)</label>
                                    <input type="text" class="form-control" name="PlatformID" value="{{$info->PlatformID}}">
                                </div>
                                <div class="form-group">
                                    <label>PlatformToken (Conversions API Token)</label>
                                    <textarea class="form-control" name="PlatformToken" rows="3" placeholder="长文本 Token，保存在 txt 字段中">{{$info->PlatformToken}}</textarea>
                                </div>
                                <div class="form-group">
                                    <label>BonusArr --- {{__('auto.(奖励数量/分)')}} (REG | MOBILE | EMAIL | PWA)</label>
                                    @php $bonusArr = explode('|', $info->BonusArr); @endphp
                                    <div class="row">
                                        <div class="col-sm-3">
                                            REG注册奖励<input type="number" class="form-control" name="BonusArr_REG" placeholder="REG" value="{{$bonusArr[0] ?? 0}}">
                                        </div>
                                        <div class="col-sm-3">
                                            MOBILE绑定手机奖励<input type="number" class="form-control" name="BonusArr_MOBILE" placeholder="MOBILE" value="{{$bonusArr[1] ?? 0}}">
                                        </div>
                                        <div class="col-sm-3">
                                            EMAIL验证邮箱奖励<input type="number" class="form-control" name="BonusArr_EMAIL" placeholder="EMAIL" value="{{$bonusArr[2] ?? 0}}">
                                        </div>
                                        <div class="col-sm-3">
                                            PWA安装奖励<input type="number" class="form-control" name="BonusArr_PWA" placeholder="PWA" value="{{$bonusArr[3] ?? 0}}">
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group" style="display: none">
                                    <label>ShadowChannel (rate%12|rate%13)</label>
                                    <input type="text" class="form-control" name="ShadowChannel" value="{{$info->ShadowChannel}}">
                                </div>
                                <div class="form-group">
                                    <label>LightApk (twa) --- {{__('auto.轻应用地址')}}</label>
                                    <input type="text" class="form-control" name="LightApk" value="{{$info->LightApk}}">
                                </div>
                                <div class="form-group">
                                    <label>FullApk (apk) --- {{__('auto.完整应用地址')}}</label>
                                    <input type="text" class="form-control" name="FullApk" value="{{$info->FullApk}}">
                                </div>

                                <button type="button" onclick="commit()" class="btn btn-sm btn-gradient-primary btn-icon-text">
                                    <i class="mdi mdi-file-check btn-icon-prepend"></i>
                                    {{ __('auto.提交') }}
                                </button>
                                <button type="button" onclick="cancel()" class="btn btn-sm btn-gradient-warning btn-icon-text">
                                    <i class="mdi mdi-reload btn-icon-prepend"></i>
                                    {{ __('auto.取消') }}
                                </button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        function commit() {
            var data = $("#form").serializeObject();
            myRequest("/admin/web_channel_config/update/{{$info->ID}}", "post", data, function (res) {
                layer.msg(res.msg)
                if (res.code == 200) {
                    setTimeout(function () {
                        parent.location.reload();
                    }, 1500)
                }
            });
        }
        function cancel() {
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        }
    </script>
@endsection
