<?php

namespace App\Admin\Controllers;

use App\Admin\Controllers\Chart\OrderChart;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\Dashboard;
use Encore\Admin\Layout\Column;
use Encore\Admin\Layout\Content;
use Encore\Admin\Layout\Row;
use Encore\Admin\Widgets\InfoBox;

class HomeController extends Controller
{
    public function index(Content $content)
    {
//        dd(\Admin::user()->isRole('financial_staff'));
        if (\Admin::user()->isRole('financial_staff')){
            return redirect('admin/refund_applications');
        }
        return $content
            ->title('欢迎进入后台管理系统')
            ->description('后台数据中心')
            ->row('<h1 text-align="center">订单概况</h1>')
            ->row(function (Row $row) {
                // 产品类型(1.电话咨询 2.图文咨询 3.门诊预约 4.疫苗接种预约 5.儿保预约 6.服务包 7.充值)
                $row->column(3, function (Column $column) {
                    $column->append(infoBox('新增电话咨询订单', 'dropbox', '/admin/consulting_orders?product_type=1', 'green', Sta::getOrderCount(1)));
                });
                $row->column(3, function (Column $column) {
                    $column->append(\App\Admin\Controllers\infoBox('新增图文咨询订单', 'dropbox', '/admin/consulting_orders?product_type=2', 'green', Sta::getOrderCount(2)));
                });

                $row->column(3, function (Column $column) {
                    $column->append(infoBox('新增门诊预约订单', 'user-plus', '/admin/booking_order?product_type=3', 'green',Sta::getOrderCount(3)));
                });

                $row->column(3, function (Column $column) {
                    $column->append(\App\Admin\Controllers\infoBox('新增计免预约订单', 'user-plus', '/admin/booking_order?product_type=4', 'green', Sta::getOrderCount(4)));
                });
            })
            ->row(function (Row $row) {
                //产品类型(1.电话咨询 2.图文咨询 3.门诊预约 4.疫苗接种预约 5.儿保预约 6.服务包 7.充值)
                $row->column(3, function (Column $column) {
                    $column->append(\App\Admin\Controllers\infoBox('新增儿保订单', 'dropbox', '/admin/booking_order?product_type=5', 'green', Sta::getOrderCount(5)));
                });
                $row->column(3, function (Column $column) {
                    $column->append(\App\Admin\Controllers\infoBox('历史总订单', 'dropbox', 'javascript:void(0)', 'green', Sta::getOrderCount(0)));
                });
            })
            ->row('<h1 text-align="center">订单走势</h1>')
            ->row(function (Row $row) {
                //产品类型(1.电话咨询 2.图文咨询 3.门诊预约 4.疫苗接种预约 5.儿保预约 6.服务包 7.充值)
                $row->column(3, function (Column $column) {
                    $column->append(\App\Admin\Controllers\infoBox('今日订单', 'dropbox', 'javascript:void(0)', 'green', Sta::getOrderCount(7,1)));
                });
                $row->column(3, function (Column $column) {
                    $column->append(\App\Admin\Controllers\infoBox('昨日订单', 'dropbox', 'javascript:void(0)', 'green', Sta::getOrderCount(7,-1)));
                });
                $row->column(3, function (Column $column) {
                    $column->append(\App\Admin\Controllers\infoBox('近七日订单', 'dropbox', 'javascript:void(0)', 'green', Sta::getOrderCount(7,7)));
                });
                $row->column(3, function (Column $column) {
                    $column->append(\App\Admin\Controllers\infoBox('近三十日订单', 'dropbox', 'javascript:void(0)', 'green', Sta::getOrderCount(7,30)));
                });
//                1=>'今日订单总数(单)',
//                        1=>'昨日订单总数(单)',
//                        1=>'近七日订单总数(单)',
//                        1=>'订单总数(单)',
            })
            ->row(function (Row $row){
                (new OrderChart())->chart($row);
            })
            ;
    }

}
/**
 * 消息框
 * @param $name
 * @param $icon
 * @param $link
 * @param $color
 * @param $info
 * @return string HTML
 */

function infoBox($name, $icon, $link, $color, $info)
{
    return (new InfoBox($name, $icon, $color, $link, $info))->render();
}
