<?php

namespace App\Admin\Controllers;

use App\Admin\Actions\Phone\Import;
use App\Model\PhoneInfo;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class PhoneInfoController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '物联网手机号';

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

        $grid->disableCreateButton(false);
        $grid->column('id', __('编号'));
        $grid->column('device_name', __('设备名称'));
        $grid->column('phone', __('物联网卡号'));
        // 将导入操作加入到表格的工具条中
        $grid->tools(function (Grid\Tools $tools) {
            $tools->append(new Import());
        });

        return $grid;
    }

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


        return $show;
    }

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

        $form->text('device_name', __('设备名称'))->width('150px');
        $form->text('phone', __('物联网号码'))->width('150px');;


        return $form;
    }
}
