@extends('base.base')
@section('base')
    <!-- 内容区域 -->
    <div class="main-panel">
        <div class="content-wrapper">
            <div class="row">
                <div class="col-12 grid-margin stretch-card">
                    <div class="card">
                        <div class="card-body">
                            <h4 class="card-title">修改充值礼包</h4>

                            <form class="forms-sample" id="form">
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>*礼包ID</label>
                                            <input type="number" class="form-control required" name="gift_id" value="{{ $info->gift_id }}">
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>*礼包名称</label>
                                            <input type="text" class="form-control required" name="gift_name" value="{{ $info->gift_name }}">
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-md-3">
                                        <div class="form-group">
                                            <label>*总获得(%)</label>
                                            <input type="number" class="form-control required" name="total_bonus" value="{{ $info->total_bonus }}">
                                        </div>
                                    </div>
                                    <div class="col-md-3">
                                        <div class="form-group">
                                            <label>*立即获得(%)</label>
                                            <input type="number" class="form-control required" name="bonus_instantly" value="{{ $info->bonus_instantly }}">
                                        </div>
                                    </div>
                                    <div class="col-md-3">
                                        <div class="form-group">
                                            <label>*配置倒计时时间(小时)</label>
                                            <input type="number" class="form-control required" name="valid_h" value="{{ $info->valid_h }}">
                                        </div>
                                    </div>
                                    <div class="col-md-3">
                                        <div class="form-group">
                                            <label>到期后每天倒计时时间(小时)</label>
                                            <input type="number" class="form-control" name="valid_h_2" value="{{ $info->valid_h_2 ?? 0 }}">
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label>是否首充</label>
                                            <select class="form-control" name="first_pay">
                                                <option value="0" @if($info->first_pay == 0) selected @endif>否</option>
                                                <option value="1" @if($info->first_pay == 1) selected @endif>是</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label>是否VIP</label>
                                            <select class="form-control" name="is_vip">
                                                <option value="0" @if($info->is_vip == 0) selected @endif>否</option>
                                                <option value="1" @if($info->is_vip == 1) selected @endif>是</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label>推荐充值档位值</label>
                                            <input type="number" step="0.01" class="form-control" name="recommend" placeholder="推荐充值金额" value="{{ number_format($info->recommend ?? 0, 2, '.', '') }}">
                                        </div>
                                    </div>
                                </div>

                                <hr>
                                <h5>每日奖励配置 <input type="checkbox" name="day_rewards_enable" value="1" @if($info->day_rewards) checked @endif></h5>
                                <div class="row" id="day_rewards_section" style="display:{{ $info->day_rewards ? 'flex' : 'none' }};">
                                    <div class="col-md-3">
                                        <div class="form-group">
                                            <label>充值金额(%)</label>
                                            <input type="number" step="0.01" class="form-control" name="day_rewards_total_bonus" value="{{ $info->day_rewards['total_bonus'] ?? '' }}">
                                        </div>
                                    </div>
                                    <div class="col-md-3">
                                        <div class="form-group">
                                            <label>奖励天数</label>
                                            <input type="number" class="form-control" name="day_rewards_bonus_day" value="{{ $info->day_rewards['bonus_day'] ?? '' }}">
                                        </div>
                                    </div>
                                    <div class="col-md-3">
                                        <div class="form-group">
                                            <label>起始天数</label>
                                            <input type="number" class="form-control" name="day_rewards_start_day" value="{{ $info->day_rewards['start_day'] ?? '' }}">
                                        </div>
                                    </div>
                                    <div class="col-md-3">
                                        <div class="form-group">
                                            <label>每天奖励(逗号分隔)</label>
                                            <input type="text" class="form-control" name="day_rewards_bonus" value="{{ isset($info->day_rewards['bonus']) ? implode(',', $info->day_rewards['bonus']) : '' }}">
                                        </div>
                                    </div>
                                </div>

                                <hr>
                                <h5>下注奖励配置 <input type="checkbox" name="betting_bonus_enable" value="1" @if($info->betting_bonus) checked @endif></h5>
                                <div class="row" id="betting_bonus_section" style="display:{{ $info->betting_bonus ? 'flex' : 'none' }};">
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label>充值金额(%)</label>
                                            <input type="number" step="0.01" class="form-control" name="betting_bonus_total_bonus" value="{{ $info->betting_bonus['total_bonus'] ?? '' }}">
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label>累计下注</label>
                                            <input type="number" class="form-control" name="betting_bonus_per_bet" value="{{ $info->betting_bonus['per_bet'] ?? '' }}">
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label>下注满奖励(%)</label>
                                            <input type="number" step="0.01" class="form-control" name="betting_bonus_per_bet_bonus" value="{{ $info->betting_bonus['per_bet_bonus'] ?? '' }}">
                                        </div>
                                    </div>
                                </div>

                                <hr>
                                <h5>下注任务配置 <input type="checkbox" name="betting_task_enable" value="1" @if($info->betting_task) checked @endif></h5>
                                <div class="row" id="betting_task_section" style="display:{{ $info->betting_task ? 'flex' : 'none' }};">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>充值金额(%)</label>
                                            <input type="number" step="0.01" class="form-control" name="betting_task_total_bonus" value="{{ $info->betting_task['total_bonus'] ?? '' }}">
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>累计下注充值倍数</label>
                                            <input type="number" class="form-control" name="betting_task_bet_pay_times" value="{{ $info->betting_task['bet_pay_times'] ?? '' }}">
                                        </div>
                                    </div>
                                </div>

                                <hr>
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>每日任务奖励</label>
                                            <input type="number" step="0.01" class="form-control" name="task_bonus" placeholder="请输入每日任务奖励金额（支持两位小数）" value="{{ $info->task_bonus !== null ? number_format($info->task_bonus, 2, '.', '') : '0' }}">
                                            <small class="form-text text-muted">每日任务奖励金额，支持两位小数</small>
                                        </div>
                                    </div>
                                </div>

                                <button type="button" onclick="commit({{ $info->id }})" class="btn btn-gradient-primary">
                                    <i class="mdi mdi-file-check btn-icon-prepend"></i>
                                    提交
                                </button>
                                <button type="button" onclick="cancel()" class="btn btn-gradient-warning">
                                    <i class="mdi mdi-reload btn-icon-prepend"></i>
                                    取消
                                </button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        $(document).ready(function() {
            $('input[name="day_rewards_enable"]').change(function() {
                if($(this).is(':checked')) {
                    $('#day_rewards_section').show();
                } else {
                    $('#day_rewards_section').hide();
                }
            });
            
            $('input[name="betting_bonus_enable"]').change(function() {
                if($(this).is(':checked')) {
                    $('#betting_bonus_section').show();
                } else {
                    $('#betting_bonus_section').hide();
                }
            });
            
            $('input[name="betting_task_enable"]').change(function() {
                if($(this).is(':checked')) {
                    $('#betting_task_section').show();
                } else {
                    $('#betting_task_section').hide();
                }
            });
        });

        function commit(id) {
            if (!checkForm()) {
                return false;
            }
            var data = $("#form").serializeObject();
            myRequest("/admin/recharge/gift_update/" + id, "post", data, function(res) {
                layer.msg(res.msg);
                if (res.code == '200') {
                    setTimeout(function() {
                        parent.location.reload();
                    }, 1500);
                }
            });
        }

        function cancel() {
            parent.layer.closeAll();
        }
    </script>
@endsection
