@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-earth"></i>
                    </span>
                    {{ __('auto.编辑虚拟分区配置') }}
                </h3>
            </div>
            <div class="row">
                <div class="col-12 grid-margin">
                    <div class="card">
                        <div class="card-body">
                            <form id="regionForm">
                                <div class="form-group">
                                    <label>RegionID</label>
                                    <input type="text" class="form-control" name="RegionID" value="{{$info->RegionID}}" required>
                                </div>
                                <div class="form-group">
                                    <label>DomainUrl</label>
                                    <input type="text" class="form-control" name="DomainUrl" value="{{$info->DomainUrl}}">
                                </div>
                                <div class="form-group">
                                    <label>LogoUrl</label>
                                    <input type="text" class="form-control" name="LogoUrl" value="{{$info->LogoUrl}}">
                                </div>
                                <div class="form-group">
                                    <label>IconUrl</label>
                                    <input type="text" class="form-control" name="IconUrl" value="{{$info->IconUrl}}">
                                </div>
                                <div class="form-group">
                                    <label>GroupID</label>
                                    <input type="number" class="form-control" name="GroupID" value="{{$info->GroupID}}">
                                </div>
                                <div class="form-group">
                                    <label>GameDesc</label>
                                    <textarea class="form-control" name="GameDesc" rows="3">{{$info->GameDesc}}</textarea>
                                </div>
                                <div class="form-group">
                                    <label>SuggestChannel</label>
                                    <input type="text" class="form-control" name="SuggestChannel" value="{{$info->SuggestChannel}}">
                                </div>
                                <div class="form-group">
                                    <label>BindChannels (多个用逗号分隔)</label>
                                    <input type="text" class="form-control" name="BindChannels"
                                        value="{{ is_array($info->BindChannels) ? implode(',', $info->BindChannels) : $info->BindChannels }}">
                                </div>
                                <div class="form-group">
                                    <label>{{ __('auto.主题配色') }}</label>
                                    <select class="form-control" name="ThemeKey">
                                        <option value="">-- 无主题 --</option>
                                        @foreach($themes as $theme)
                                            <option value="{{$theme->ThemeKey}}" {{ $info->ThemeKey == $theme->ThemeKey ? 'selected' : '' }}>
                                                {{$theme->ThemeKey}}
                                            </option>
                                        @endforeach
                                    </select>
                                </div>
                                <button type="submit" class="btn btn-gradient-primary mr-2">{{ __('auto.提交') }}</button>
                                <a href="{{ url('admin/web_region_config') }}" class="btn btn-light">{{ __('auto.取消') }}</a>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        $('#regionForm').on('submit', function(e) {
            e.preventDefault();

            var formData = $(this).serialize();

            $.ajax({
                url: '{{ url("admin/web_region_config/edit/".$info->id) }}',
                type: 'POST',
                data: formData,
                success: function(res) {
                    if (res.code === 200) {
                        alert('更新成功');
                        window.location.href = '{{ url("admin/web_region_config") }}';
                    } else {
                        alert(res.msg || '更新失败');
                    }
                }
            });
        });
    </script>
@endsection
