<?php

namespace App\Helpers;

use App\Models\PaymentModel;

class HomeHelper extends CommonHelper
{
    public function __construct()
    {
        parent::__construct();
        $this->setTitleField(field: PaymentModel::TITLE);
    }

    public function getFieldView(string $field, mixed $value, array $viewDatas, array $extras = []): string|null
    {
        switch ($field) {
            case 'type':
                $value = $viewDatas['control']['field_optons'][$field][$value];
                break;
            case 'amount':
                $value = 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;
    }
    public function getListButton(string $action, string $label, array $viewDatas, array $extras = []): string
    {
        switch ($action) {
            case 'new_service_view':
                $action = form_label(
                    $label ? $label : ICONS['SEARCH'],
                    $action,
                    [
                        "data-src" => '/admin/customer/service/view/' . $viewDatas['entity']->getPK(),
                        "data-bs-toggle" => "modal",
                        "data-bs-target" => "#modal_action_form",
                        "class"          => "btn btn-sm form-label-sm",
                        ...$extras,
                    ]
                );
                break;
            default:
                $action = parent::getListButton($action, $label, $viewDatas, $extras);
                break;
        }
        return $action;
    }
}
