<?php

namespace App\Admin\Selectable;

use App\Models\Area;
use Encore\Admin\Widgets\Table;
use Illuminate\Contracts\Support\Renderable;

class AreaStockAble implements Renderable
{

    public function render($key = null): string
    {
        $area   = Area::find($key);
        $stocks = $area->stocks()->exists();
        $data   = [];
        if ($stocks) {
            $data = $area->stocks()->select('amount', 'stock', 'created_at')->get()->toArray();
        }

        $table = new Table(['变动值', '当前库存', '操作时间'], $data);
        return $table->render();
    }

}
