<?php

namespace App\Distributor\Controllers;


use App\Distributor\Repositories\DistAppearance;
use App\Distributor\Actions\AppearanceEnable;
use App\Distributor\Repositories\DistAdminDistributor;
use App\Libraries\CommonHelper;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Layout\Content;

class DistAppearanceController extends AdminDistController
{
    /**
     * page index
     */
    public function index(Content $content)
    {
        return $content
            ->header(admin_trans( 'admin.appearance'))
            ->description('')
            ->breadcrumb(['text'=>'list','url'=>''])
            ->body($this->grid());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $distInfo = DistAdminDistributor::getInfo();
        return Grid::make(new DistAppearance(), function (Grid $grid) use ($distInfo) {
            $grid->column('id')->sortable();
            // 标题
            $grid->column('title');
            // 封面图
            $grid->column('cover_image')->display(function ($image) {
                $dataImages = [$image];
                return CommonHelper::displayImage($dataImages,100);
            });
            $grid->column('describe');
            $grid->column('isEnabled')->display(function () use ($distInfo) {
                if ($this->id == $distInfo->appearance_id) {
                    return '<span class="label" style="background:#21b978;">Yes</span>';
                } else {
                    return '<span class="label" style="background:#d2d6de;">No</span>';
                }

            });
            //按钮
            $grid->disableCreateButton();
            $grid->disableDeleteButton();
            $grid->disableBatchDelete();
            // 操作
            $grid->actions(function (Grid\Displayers\Actions $actions) {
                $actions->disableDelete();
                $actions->disableEdit();
                $actions->disableView();
                $actions->append(new AppearanceEnable());
            });
            //排序
            $grid->model()->where('enabled',1)->orderBy('order',);
        });
    }


}
