<?php

namespace App\Helpers\Part;

use App\Models\Part\DISKModel;

class DISKHelper extends PartHelper
{
    public function __construct()
    {
        parent::__construct();
        $this->setTitleField(field: DISKModel::TITLE);
    }

    public function getFieldView(string $field, mixed $value, array $viewDatas, array $extras = []): string|null
    {
        switch ($field) {
            case 'format':
                $value = sprintf(
                    "<div class=\"text-center\"><a href=\"/admin/part/disk/complete/%s\" class=\"btn btn-outline btn-secondary btn-circle form-label-sm\">%s</a></div>",
                    $viewDatas['entity']->getPK(),
                    number_format($value),
                );
                break;
            default:
                $value = parent::getFieldView($field, $value, $viewDatas, $extras);
                break;
        }
        if (is_array($value)) {
            throw new \Exception(__METHOD__ . "에서 오류: {$field}의 값이 Array형태입니다");
        }
        return $value;
    }
}
