<?php

namespace Modules\Mall\Http\Controllers\Admin;

use Encore\Admin\Layout\Column;
use Encore\Admin\Layout\Content;
use Encore\Admin\Layout\Row;
use Encore\Admin\Widgets\InfoBox;
use Illuminate\Routing\Controller;
use Modules\Mall\Models\Goods;
use Modules\Mall\Models\Order;
use Modules\Mall\Models\Refund;
use Modules\Mall\Models\Shop;

class DashboardController extends Controller
{

    public function index(Content $content): Content
    {
        return $content
            ->header('商城看板')
            ->description('商城数据概览')
            ->row(function (Row $row) {
                $row->column(3, function (Column $column) {
                    $column->append(new InfoBox('店铺数量',
                            'anchor',
                            'blue',
                            route('admin.mall.shops.index'),
                            Shop::count()
                        )
                    );
                });

                $row->column(3, function (Column $column) {
                    $column->append(new InfoBox('商品数量',
                            'anchor',
                            'blue',
                            route('admin.mall.goods.index'),
                            Goods::count()
                        )
                    );
                });

                $row->column(3, function (Column $column) {
                    $column->append(new InfoBox('订单总数',
                            'anchor',
                            'blue',
                            route('admin.mall.orders.index'),
                            Order::count()
                        )
                    );
                });

                $row->column(3, function (Column $column) {
                    $column->append(new InfoBox('退款订单',
                            'anchor',
                            'blue',
                            route('admin.mall.refunds.index'),
                            Refund::count()
                        )
                    );
                });
            });

    }

}