<?php

namespace Modules\User\Http\Controllers\Admin;

use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Layout\Content;
use Modules\User\Models\SignConfig;
use Encore\Admin\Form\EmbeddedForm;

class SignConfigController extends AdminController
{

    protected $title = '签到配置管理';

    public function index(Content $content)
    {
        return redirect(admin_url('users/signs/1/edit'));
    }

    public function form(): Form
    {
        SignConfig::firstOrCreate(['id' => 1]);

        $form = new Form(new SignConfig());
        $form->disableCreatingCheck();
        $form->disableEditingCheck();
        $form->tools(function (Form\Tools $tools) {
            $tools->disableDelete();
            $tools->disableView();
            $tools->disableList();
        });
        $form->embeds('params', '配置', function (EmbeddedForm $form) {
            $form->radio('open', '是否开启')->options([
                0 => '关闭',
                1 => '开启',
            ])->required();
            $form->text('rule_name', '签到账变关键字')->default('');
            $form->radio('show_type', '签到展示类型')
                ->options(SignConfig::SHOWTYPES)
                ->default(SignConfig::SHOWTYPES_DAY)
                ->required();
            $form->radio('type', '签到类型')
                ->options(SignConfig::TYPES)
                ->required();
            $form->number('single_number', '单次奖励')->default(0);
            $form->number('continuous_base', '连续基础值')->default(0);
            $form->number('continuous_incremental', '连续增量')->default(0);
            $form->number('cycle_day', '周期天数')->default(0);
            $form->number('cycle_base', '周期基础值')->default(0);
            $form->number('cycle_incremental', '周期增量')->default(0);
        });
        $form->table('tasks', '特殊奖励', function ($form) {
            $form->number('day', '天数')->default(0);
            $form->number('number', '奖励')->default(0);
        });

        return $form;
    }

}
