<?php

namespace App\Admin\Controllers\ServicePacksManagment;

use App\Models\Servebanner;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class ServebannerController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '服务包海报';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Servebanner());

        $grid->column('id', __('Id'));
        $grid->column('image', __('海报'))->image('',100,100);
        $grid->column('url', __('链接'));
        $states = [
            'on'  => ['value' => 1, 'text' => '启用', 'color' => 'success'],
            'off' => ['value' => 0, 'text' => '禁用', 'color' => 'danger'],
        ];
        $grid->column('status','状态')->switch($states);
        $grid->column('created_at', __('创建时间'));
        $grid->column('updated_at', __('更新时间'));

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Servebanner::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('image', __('Image'))->image('',100,100);
        $show->field('url', __('Url'));
        $show->field('status', __('Status'));
        $show->field('updated_at', __('Updated at'));
        $show->field('created_at', __('Created at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Servebanner());

        $form->image('image', __('海报'))->rules('required' ,['required'=>'请选择图片！']);
        $form->text('url', __('链接'));
        $states = [
            'off' => ['value' => 0, 'text' => '禁用', 'color' => 'danger'],
            'on'  => ['value' => 1, 'text' => '启用', 'color' => 'success'],
        ];
        $form->switch('status','状态')->states($states);

        return $form;
    }
}
