<?php

namespace App\Helpers\Cloudflare;

use App\Helpers\CommonHelper;
use App\Models\Cloudflare\AuthModel;

class AuthHelper extends CommonHelper
{
    public function __construct()
    {
        parent::__construct();
    }
    public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
    {
        $value = $value ?: DEFAULTS['EMPTY'];
        switch ($field) {
            case AuthModel::TITLE:
                $form = form_input($field, $value, ["placeholder" => "예)test@example.com", ...$extras]);
                break;
            default:
                $form = parent::getFieldForm($field, $value, $viewDatas, $extras);
                break;
        }
        return $form;
    } //
    public function getFieldView(string $field, array $viewDatas, array $extras = []): string
    {
        $value = $viewDatas['entity']->$field ?: DEFAULTS['EMPTY'];
        switch ($field) {
            case AuthModel::TITLE:
                $value = anchor(
                    base_url() . $viewDatas['uri_path'] . 'account/reload/' . $viewDatas['entity']->getPK(),
                    ICONS["RELOAD"],
                    [
                        "class" => "btn btn-sm btn-primary btn-circle",
                        "target" => "_self"
                    ]
                ) . " " .
                    anchor(
                        base_url() . $viewDatas['uri_path'] . "account?auth_uid=" . $viewDatas['entity']->getPK(),
                        ICONS["FLAG"],
                        [
                            "class" => "btn btn-sm btn-primary btn-circle",
                            "target" => "_self"
                        ]
                    ) . " <span class=\"label_Auths\">{$value}</span>";
                break;
            default:
                $value = parent::getFieldView($field, $viewDatas, $extras);
                break;
        }
        return $value;
    } //
}
