@extends('base.base')
@section('base')
    <!-- {{ __('messages.内容区域') }} -->
    <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-wrench"></i>
                    </span>
                    {{ __('messages.管理员') }}
                </h3>
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="#">{{ __('messages.系统设置') }}</a></li>
                        <li class="breadcrumb-item active" aria-current="page">{{ __('messages.管理员管理') }}</li>
                    </ol>
                </nav>
            </div>
            <div class="row">
                <div class="col-lg-12 grid-margin stretch-card">
                    <div class="card">
                        <div class="card-body">
                            <h4 class="card-title">{{ __('messages.管理员列表') }}</h4>
                            <p class="card-description">
                                <button type="button" class="btn btn-sm btn-gradient-success btn-icon-text" onclick="add()">
                                    <i class="mdi mdi-plus btn-icon-prepend"></i>
                                    {{ __('messages.添加管理员') }}
                                </button>
                            </p>
                            <table class="table table-bordered">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>{{ __('messages.头像') }}</th>
                                    <th>{{ __('messages.昵称') }}</th>
                                    {{--                                    <th>{{ __('messages.创建时间') }}</th>--}}
                                    {{--                                    <th>{{ __('messages.更新时间') }}</th>--}}
                                    <th>{{ __('messages.账号') }}</th>
                                    <th>{{ __('messages.角色') }}</th>
                                    <th>{{ __('messages.语言') }}</th>
                                    <th>{{ __('messages.当前彩金额度') }}</th>
                                    <th>{{ __('messages.历史已消耗彩金额度') }}</th>
                                    <th>{{ __('messages.当前单控送金额度') }}</th>
                                    <th>{{ __('messages.历史单控送金额度') }}</th>
                                    <th>{{ __('messages.渠道号') }}</th>
                                    <th>{{ __('messages.状态') }}</th>
                                    <th width="15%">{{ __('messages.操作') }}</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($admins as $admin)
                                    <tr>
                                        <td>{{ $admin->id }}</td>
                                        <td>
                                            @if($admin->avatar)
                                                <img class="avatar" src="{{ $admin->avatar ?? "" }}" alt="image">
                                            @endif
                                        </td>
                                        <td>{{ $admin->nickname }}</td>
                                        {{--                                        <td>{{ $admin->created_at }}</td>--}}
                                        {{--                                        <td>{{$admin->updated_at}}</td>--}}
                                        <td>{{ $admin->account }}</td>
                                        <td>
                                            @foreach($admin->roles as $role)
                                                {{ $role->name }}
                                            @endforeach
                                        </td>
                                        <td>{{$admin->locale}}</td>
                                        <td>{{$admin->lottery_amount}}</td>
                                        <td>{{$admin->history_lottery_amount}}</td>
                                        <td>{{$admin->recharge_amount}}</td>
                                        <td>{{$admin->history_recharge_amount}}</td>
                                        <td style=" word-wrap: break-word;
                                        word-break: break-all; /* 任何字符间换行 */
                                        white-space: normal; /* 允许自动换行 */
                                        max-width: 30%; /* 设置一个最大宽度，根据需要调整 */">{{implode(",",json_decode($admin->channel,true))}}</td>
                                        <td>
                                            @if ($admin->status == 1)
                                                {{ __('messages.正常') }}
                                            @else
                                                {{ __('messages.禁用') }}
                                            @endif
                                        </td>
                                        <td>
                                            <button type="button" class="btn btn-sm btn-gradient-dark btn-icon-text" onclick="update({{ $admin->id }})">
                                                {{ __('messages.修改') }}
                                                <i class="mdi mdi-file-check btn-icon-append"></i>
                                            </button>
                                            <button type="button" class="btn btn-sm btn-gradient-danger btn-icon-text" onclick="del({{ $admin->id }})">
                                                <i class="mdi mdi-delete btn-icon-prepend"></i>
                                                {{ __('messages.删除') }}
                                            </button>
                                            <button type="button" class="btn btn-sm btn-gradient-dark btn-icon-text" onclick="block({{ $admin->id }})">
                                                @if ($admin->status == 1)
                                                    {{ __('messages.禁用') }}
                                                @else
                                                    {{ __('messages.启用') }}
                                                @endif
                                                <i class="mdi mdi-file-check btn-icon-append"></i>
                                            </button>
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                            <div class="box-footer clearfix" id = "pages">
                                {{ __('messages.总共') }} <b>{{ $admins->appends([

                                    ])->total() }}</b> {{ __('messages.条,分为') }}<b>{{ $admins->lastPage() }}</b> {{ __('messages.页') }}
                                {!! $admins->links() !!}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>

    <script>

        function add(){
            layer.open({
                type: 2,
                title: '{{ __('messages.添加管理员') }}',
                shadeClose: true,
                shade: 0.8,
                area: ['100%', '100%'],
                content: '/admin/administrator/add'
            });
        }

        function update(id){
            var page = layer.open({
                type: 2,
                title: '{{ __('messages.修改管理员') }}',
                shadeClose: true,
                shade: 0.8,
                area: ['70%', '90%'],
                content: '/admin/administrator/update/'+id
            });
        }

        function del(id){
            myConfirm("{{ __('messages.删除操作不可逆,是否继续?') }}",function(){
                myRequest("/admin/administrator/del/"+id,"post",{},function(res){
                    layer.msg(res.msg)
                    setTimeout(function(){
                        window.location.reload();
                    },1500)
                });
            });
        }

        function block(id){
            myConfirm("{{ __('messages.是否继续?') }}",function(){
                myRequest("/admin/administrator/block/"+id,"post",{},function(res){
                    layer.msg(res.msg)
                    setTimeout(function(){
                        window.location.reload();
                    },1500)
                });
            });
        }

    </script>

@endsection
