@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-image-multiple"></i>
                    </span>
                    {{ __('auto.添加Banner') }}
                </h3>
            </div>
            <div class="row">
                <div class="col-12 grid-margin">
                    <div class="card">
                        <div class="card-body">
                            <form id="bannerForm">
                                <div class="form-group">
                                    <label>{{ __('auto.图片URL') }} *</label>
                                    <input type="text" class="form-control" name="img" required>
                                </div>
                                <div class="form-group">
                                    <label>{{ __('auto.葡萄牙语图片URL') }}</label>
                                    <input type="text" class="form-control" name="img_pt">
                                </div>
                                <div class="form-group">
                                    <label>{{ __('auto.西班牙语图片URL') }}</label>
                                    <input type="text" class="form-control" name="img_es">
                                </div>
                                <div class="form-group">
                                    <label>Alt Text</label>
                                    <input type="text" class="form-control" name="alt">
                                </div>
                                <div class="form-group">
                                    <label>Link Game ID</label>
                                    <input type="number" class="form-control" name="link_game">
                                </div>
                                <div class="form-group">
                                    <label>Link Module ID</label>
                                    <input type="number" class="form-control" name="link_module">
                                </div>
                                <div class="form-group">
                                    <label>{{ __('auto.事件') }} (link)</label>
                                    <input type="text" class="form-control" name="link" placeholder="事件链接/标识，例如 /activity/xxx 或活动唯一标识" maxlength="200">
                                    <small class="form-text text-muted">用于在"同步到其他主题"时识别事件是否已存在</small>
                                </div>
                                <div class="form-group">
                                    <label>{{ __('auto.排序') }} (b_order)</label>
                                    <input type="number" class="form-control" name="b_order" placeholder="数字越小越靠前，留空为末尾">
                                </div>
                                <div class="form-group">
                                    <label>{{ __('auto.状态') }} (state)</label>
                                    <input type="number" class="form-control" name="state" value="127" placeholder="默认 127">
                                </div>
                                <div class="form-group">
                                    <label>{{ __('auto.主题KEY') }}</label>
                                    <select class="form-control" name="theme_key">
                                        <option value="">-- 无主题 --</option>
                                        @foreach($themes as $theme)
                                            <option value="{{$theme->ThemeKey}}">{{$theme->ThemeKey}}</option>
                                        @endforeach
                                    </select>
                                </div>
                                <button type="submit" class="btn btn-gradient-primary mr-2">{{ __('auto.提交') }}</button>
                                <a href="{{ url('admin/banner') }}" class="btn btn-light">{{ __('auto.取消') }}</a>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

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

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

            $.ajax({
                url: '{{ url("admin/banner/add") }}',
                type: 'POST',
                data: formData,
                success: function(res) {
                    if (res.code === 200) {
                        alert('添加成功');
                        window.location.href = '{{ url("admin/banner") }}';
                    } else {
                        alert(res.msg || '添加失败');
                    }
                }
            });
        });
    </script>
@endsection
