@extends('base.base')
@section('base')
<div class="main-panel">
    <div class="content-wrapper">
        <div class="page-header">
            <h3 class="page-title">{{ __('VIP 配置') }}</h3>
        </div>

        <div class="card">
            <div class="card-body">
                <!-- VIP配置表单 -->
                <form id="configForm">
                    <div class="form-row">
                        <div class="form-group col-md-2">
                            <label for="downDays">{{ __('VIP降级天数') }}</label>
                            <input type="number" class="form-control" id="downDays" name="down_days"
                                   value="{{ $downDays ?? 0 }}" min="1" required>
                            <small class="form-text text-muted">{{ __('必须为正整数') }}</small>
                        </div>
                        <div class="form-group col-md-2">
                            <label for="expireDays">{{ __('VIP过期天数') }}</label>
                            <input type="number" class="form-control" id="expireDays" name="expire_days"
                                   value="{{ $expireDays ?? 0 }}" min="1" required>
                            <small class="form-text text-muted">{{ __('必须为正整数') }}</small>
                        </div>
                        <div class="form-group col-md-2 d-flex align-items-center">
                            <button type="button" class="btn btn-sm btn-primary" onclick="saveConfig()">{{ __('保存') }}</button>
                        </div>
                    </div>
                </form>
                <button class="btn btn-sm btn-success mb-2" onclick="add()">新增等级</button>
                <table class="table table-bordered">
                    <thead>
                    <tr>
                        <th>ID</th>
                        <th>充值金额</th>
                        <th>VIP等级</th>
                        <th>最小充值</th>
                        <th>提现限额</th>
                        <th>茶叶次数</th>
                        <th>提现费率百分比</th>
                        <th>Alpha (签到、救济金系数)</th>
                        <th>客服类型 1 普通 2 一对一</th>
                        <th>商城充值额外赠送百分比</th>
                        <th>Superball每日赠送球数</th>
                        <th>生日礼价值</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($list as $row)
                        <tr>
                            <td>{{ $row->ID }}</td>
                            <td>{{ $row->Recharge }}</td>
                            <td>{{ $row->VIP }}</td>
                            <td>{{ $row->MinRecharge }}</td>
                            <td>{{ $row->WithdrawLimit }}</td>
                            <td>{{ $row->DailyWithdraws }}</td>
                            <td>{{ $row->WithdrawFeeRate }} %</td>
                            <td>{{ $row->Alpha }}</td>
                            <td>{{ $row->CustomServiceType }}</td>
                            <td>{{ $row->RechargeExtraSendRate }} %</td>
                            <td>{{ $row->SuperballNum }}</td>
                            <td>{{ intval($row->BirthdayValue/100) }}</td>
                            <td>
                                <button class="btn btn-sm btn-primary" onclick="edit({{ $row->ID }})">{{ __('修改') }}</button>
                                <button class="btn btn-sm btn-danger" onclick="del({{ $row->ID }})">{{ __('删除') }}</button>
                            </td>
                        </tr>
                    @endforeach
                    </tbody>
                </table>
            </div>
        </div>


    </div>
</div>

<script>
    function add(){
        layer.open({
            type:2,shade:0.8,area:['50%','70%'],
            content:'/admin/protect-level/add'
        });
    }
    function edit(id){
        layer.open({
            type:2,shade:0.8,area:['50%','70%'],
            content:'/admin/protect-level/edit/'+id
        });
    }
    function del(id){
        myConfirm('确认删除？', function(){
            myRequest('/admin/protect-level/delete/'+id,'post',{},function(){
                layer.msg('已删除'); location.reload();
            });
        });
    }
    function saveConfig(){
        var downDays = document.getElementById('downDays').value;
        var expireDays = document.getElementById('expireDays').value;
        
        // 验证输入
        if (!downDays || downDays <= 0 || isNaN(downDays)) {
            layer.msg('VIP降级时间必须为正整数');
            return;
        }
        if (!expireDays || expireDays <= 0 || isNaN(expireDays)) {
            layer.msg('VIP过期时间必须为正整数');
            return;
        }
        
        myRequest('/admin/protect-level/save-config','post',{
            down_days: downDays,
            expire_days: expireDays
        },function(){
            layer.msg('配置已保存');
        });
    }
</script>
@endsection
