<?php
function getFieldLabel_DepositHelper($field, array $viewDatas): string
{
  $attributes = [];
  switch ($field) {
    default:
      if (strpos($viewDatas['fieldRules'][$field], 'required') !== false) {
        $attributes = ['style="color:red";'];
      }
      return sprintf("<span %s>%s</span>", implode(" ", $attributes), lang("{$viewDatas['className']}.label.{$field}"));
      break;
  }
}
//header.php에서 getFieldForm_Helper사용
function getFieldForm_DepositHelper($field, $value, array $viewDatas, array $attributes = array())
{
  $value = $value ?: DEFAULTS['EMPTY'];
  switch ($field) {

    case 'email':
      return form_input($field, $viewDatas['user']->email);
      break;
    case 'phone':
      return form_input($field, $viewDatas['user']->phone);
      break;
    default:
      return form_input($field, $value);
      break;
  }
} //

function getFieldView_DepositHelper($field, $entity, array $viewDatas)
{
  $value = $entity->$field ?: DEFAULTS['EMPTY'];
  switch ($field) {
    default:
      return in_array($field, $viewDatas['fieldFilters'])  && $value ? $viewDatas['fieldFormOptions'][$field][$value] : $value;
      break;
  }
} //

function getFieldFilter_DepositHelper($field, $value, array $viewDatas)
{
  $viewDatas['fieldFormOptions'][$field] = [DEFAULTS['EMPTY'] => lang("{$viewDatas['className']}.label.{$field}") . " 선택", ...$viewDatas['fieldFormOptions'][$field]];
  return form_dropdown($field, $viewDatas['fieldFormOptions'][$field], $value, ['class' => "select-field"]);
} //

function getFieldIndex_Column_DepositHelper($field, array $viewDatas)
{
  $label = lang("{$viewDatas['className']}.label.{$field}");
  if ($field == $viewDatas['order_field']) {
    $label .=  $viewDatas['order_value'] == 'ASC' ? ICONS['UP'] : ICONS['DOWN'];
  }
  $value = $viewDatas['order_value'] == 'DESC' ? "ASC" : "DESC";
  $viewDatas['uri']->addQuery('order_field', $field);
  $viewDatas['uri']->addQuery('order_value', $value);
  $columnData = anchor($viewDatas['uri'], $label);
  switch ($field) {
    case 'title':
    case 'name':
      return sprintf("<th class='col-4'>%s</th>", $columnData);
      break;
    default:
      return sprintf("<th>%s</th>", $columnData);
      break;
  }
} //

//Front용
function getFieldIndex_Row_DepositHelper($field, $entity, array $viewDatas): string
{
  switch ($field) {
    default:
      return getFieldView_DepositHelper($field, $entity, $viewDatas);
      break;
  }
} //