<?php
/**
 * Created by PhpStorm
 * DateTime: 2022/10/3 1:01
 *
 * @description
 */
namespace App\Admin\Metrics\Examples;
use App\Models\Product;
use App\Models\StatProductDownload;
use Dcat\Admin\Admin;
use Dcat\Admin\Grid;
use Dcat\Admin\Widgets\Metrics\Line;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;

class ProductDownload extends Line
{

    protected $title = '下载数据';


    /**
     * 初始化卡片内容
     */
    public function init()
    {
        parent::init();

        $color = Admin::color();
        // 标题
        $this->title($this->title);


//        $this->height(380);
//        $this->chartHeight(330);
//        $this->chartOption('chart.sparkline.enabled', false);
//        $this->chartOption('legend.position', 'top');
//        $this->chartColors([$color->primary(), $color]);
//
//        $this->chartOption('stroke.width', [2.5, 2.5]);
//        $this->chartOption('stroke.dashArray', [0, 5]);
//
//        $this->chartSmooth();
//
//        // 卡片内容
//        $this->withContent(mt_rand(1000, 5000).'k');

        $this->content($this->grid());
    }

    public function grid()
    {
        $grid = new Grid();
        $grid->filter(function (Grid\Filter $filter) {
            $filter->panel();
            $filter->equal('product_id')->select(function (){
                return Product::select(['id','name'])->get()->pluck('name','id')->toArray();
            })->width(2);
            $filter->like('name')->width(2);
        });
        return $grid;
    }

    public function handle(Request $request)
    {
        // dd($contractNum);
        $this->withChart($this->contractNum, $this->receiptNum);
    }


    public function withContent($content)
    {
        return $this->content(
            <<<HTML
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
    <h2 class="ml-1 font-lg-1">{$content}</h2>
    <span class="mb-0 mr-1 text-80">{$this->label}</span>
</div>
HTML
        );
    }

    public function withChart($series)
    {
        return $this->chart([
            'series' => [$series],
            'xaxis' => [
                'categories' => $this->categories
            ],
        ]);
    }
}
