<?php

namespace App\Admin\Controllers\Content;

use App\Http\Controllers\Controller;
use App\Models\LtApppointment;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;

//use Encore\Admin\Grid;

class RcstfwltController extends Controller
{
    use HasResourceActions;

    /**
     * Index interface.
     *
     * @param Content $content
     * @return Content
     */
    public function index(Content $content)
    {
        return $content
            ->header('服务事项预约列表')
            ->description(' ')
            ->body($this->grid());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new LtApppointment);
        $grid->model()->orderBy('id', 'DESC');

        $status = \Illuminate\Support\Facades\Request::input('status', 99);
        if ($status != 99) {
            $grid->model()->where('status', '=', $status);
        } else {
            $grid->model()->where('status', '<', 2);
        }


        $grid->number('预约号码')->width(200);
        $grid->username('真实姓名')->width(150);
        $grid->phone('手机')->width(150);
        $grid->service('服务事项')->width(300);
        $grid->content('说明')->width(600);
        $grid->createtime('登记时间')->width(300);
        $grid->is_talent('是否认证人才')->width(300)->display(function () {
            if ($this->is_talent == 0) {
                return '<span style="color: #909399">未认证人才</span>';
            } else if ($this->is_talent == 1) {
                return '<span style="color: #67C23A">已认证人才</span>';
            }

            return '';
        });
        $grid->evaluate('评价')->display(function () {
            if ($this->is_talent == 1) {
                if (empty($this->evaluate)) {
                    return '<span style="color: #E6A23C">未评价</span>';
                } else {
                    return '<span style="color: #67C23A">' . $this->evaluate . '</span>';
                }
            } else {
                return '<span style="color: #909399">不需要评价</span>';
            }
            return '';
        });

        $grid->actions(function ($actions) {
            $actions->disableView(false);
        });

        $grid->filter(function ($filter) {
            $filter->disableIdFilter();
            $filter->like('number', '预约单号');
            $filter->like('username', '姓名');
            $type_option = ['0' => '未认证人才', '1' => '已认证人才', '99' => '全部'];
            $filter->where(function ($query) {
                if ($this->input != 99) {
                    $query->where('is_talent', '=', "{$this->input}");
                }
            }, '是否认证人才', 'is_talent')->radio($type_option);
        });

        return $grid;
    }

    public function show($id, Content $content)
    {
        return $content
            ->header('详情')
            ->description()
            ->body($this->detail($id));
    }

    protected function detail($id)
    {
        $show = new Show(LtApppointment::findOrFail($id));

        $show->number('预约号码');
        $show->username('真实姓名');
        $show->phone('手机');
        $show->service('服务事项');
        $show->content('说明');
        $show->createtime('登记时间');
        $show->is_talent('是否认证人才')->display(function () {
            if ($this->is_talent == 0) {
                return '<span style="color: #909399">未认证人才</span>';
            } else if ($this->is_talent == 1) {
                return '<span style="color: #67C23A">已认证人才</span>';
            }

            return '';
        });
        $show->evaluate('评价')->display(function () {
            if ($this->is_talent == 1) {
                if (empty($this->evaluate)) {
                    return '<span style="color: #E6A23C">未评价</span>';
                } else {
                    return '<span style="color: #67C23A">' . $this->evaluate . '</span>';
                }
            } else {
                return '<span style="color: #909399">不需要评价</span>';
            }
            return '';
        });

        return $show;
    }

}