<?php

namespace App\Helpers\Customer;

use App\Models\Customer\ClientModel;
use CodeIgniter\HTTP\IncomingRequest;

class ClientHelper extends CustomerHelper
{
    protected ?IncomingRequest $request = null;
    public function __construct(?IncomingRequest $request = null)
    {
        parent::__construct($request);
        $this->setTitleField(ClientModel::TITLE);
    }
    public function getFieldView(string $field, mixed $value, array $viewDatas, array $extras = []): string|null
    {
        switch ($field) {
            case 'account_balance':
                $extras = ["class" => "btn btn-link", "target" => "_self", ...$extras];
                $value = form_label(
                    number_format(intval($value)) . "원",
                    'index',
                    [
                        "data-src" => "/admin/customer/account?clientinfo_uid={$viewDatas['entity']->getPK()}&ActionTemplate=popup",
                        "data-bs-toggle" => "modal",
                        "data-bs-target" => "#index_action_form",
                        ...$extras
                    ]
                );
                break;
            case 'coupon_balance':
                $extras = ["class" => "btn btn-link", "target" => "_self", ...$extras];
                $value = form_label(
                    number_format(intval($value)) . "개",
                    'index',
                    [
                        "data-src" => "/admin/customer/coupon?clientinfo_uid={$viewDatas['entity']->getPK()}&ActionTemplate=popup",
                        "data-bs-toggle" => "modal",
                        "data-bs-target" => "#index_action_form",
                        ...$extras
                    ]
                );
                break;
            case 'point_balance':
                $extras = ["class" => "btn btn-link", "target" => "_self", ...$extras];
                $value = form_label(
                    number_format(intval($value)) . "원",
                    'index',
                    [
                        "data-src" => "/admin/customer/point?clientinfo_uid={$viewDatas['entity']->getPK()}&ActionTemplate=popup",
                        "data-bs-toggle" => "modal",
                        "data-bs-target" => "#index_action_form",
                        ...$extras
                    ]
                );
                break;
            default:
                $value = parent::getFieldView($field, $value, $viewDatas, $extras);
                break;
        }
        if (is_array($value)) {
            echo __METHOD__ . "에서 오류: {$field}의 값이 Array형태입니다";
            exit;
        }
        return $value;
    } //
}
