<?php declare(strict_types=1);

namespace Hubleto\Erp\Api;

class Dictionary extends \Hubleto\Erp\Controllers\ApiController
{

  public function renderJson(): array
  {
    $language = $this->router()->urlParamAsString('language', 'en');
    $addNew = $this->router()->urlParamAsArray('addNew');

    // $dictFile = __DIR__ . '/../../lang/' . $language . '.json';

    // if ($language == 'en') {
    //   return [];
    // }
    // if (!in_array($language, array_keys(\Hubleto\App\Community\Auth\Models\User::ENUM_LANGUAGES))) {
    //   return [];
    // }
    // if (!is_file($dictFile)) {
    //   return [];
    // }

    // $dict = $this->translator()->loadDictionary($language);

    if (
      isset($addNew['context'])
      && isset($addNew['contextInner'])
      && isset($addNew['orig'])
      && $language != 'en'
    ) {

      if (!empty($addNew['context']) && !empty($addNew['contextInner'])) {
        // $service = $this->getService($addNew['context']);
        $this->translator()->addToDictionary(
          $this,
          $language,
          $addNew['context'],
          $addNew['contextInner'],
          $addNew['orig']
        );
      }

      return ['status' => true];
    } else {
      return [];
    }
  }

}
