@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-palette"></i>
                    </span>
                    {{ __('auto.主题配置管理') }}
                </h3>
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="#">{{ __('auto.渠道管理') }}</a></li>
                        <li class="breadcrumb-item active" aria-current="page">{{ __('auto.主题配置管理') }}</li>
                    </ol>
                </nav>
            </div>
            <div class="row">
                <div class="col-lg-12 grid-margin stretch-card">
                    <div class="card">
                        <div class="card-body">
                            <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
                                <h4 class="card-title">{{ __('auto.主题列表') }}</h4>
                                <a href="{{ url('admin/web_theme_config/add') }}" class="btn btn-gradient-primary">{{ __('auto.添加主题') }}</a>
                            </div>
                            <table class="table table-bordered">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>{{ __('auto.主题KEY') }}</th>
                                    <th>{{ __('auto.绑定的Region ID') }}</th>
                                    <th>{{ __('auto.操作') }}</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($list as $v)
                                    <tr>
                                        <td>{{$v->id}}</td>
                                        <td>{{$v->ThemeKey}}</td>
                                        <td>
                                            @if($v->BindRegions)
                                                {{ is_array($v->BindRegions) ? implode(',', $v->BindRegions) : $v->BindRegions }}
                                            @endif
                                        </td>
                                        <td>
                                            <a href="{{ url('admin/web_theme_config/edit/'.$v->id) }}" class="btn btn-sm btn-gradient-info">{{ __('auto.编辑') }}</a>
                                            <button class="btn btn-sm btn-gradient-danger" onclick="deleteTheme({{$v->id}})">{{ __('auto.删除') }}</button>
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                            <div class="box-footer clearfix" id="pages">
                                {{ __('auto.总共') }} <b>{{ $list->total() }}</b> {{ __('auto.条,分为') }}<b>{{ $list->lastPage() }}</b>{{ __('auto.页') }}
                                {!! $list->links() !!}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        function deleteTheme(id) {
            if (confirm('确认删除此主题配置？')) {
                $.ajax({
                    url: '/admin/web_theme_config/delete/' + id,
                    type: 'POST',
                    success: function(res) {
                        if (res.code === 200) {
                            alert('删除成功');
                            location.reload();
                        } else {
                            alert(res.msg || '删除失败');
                        }
                    }
                });
            }
        }
    </script>
@endsection
