<?php
namespace Engine\Theme\JSLoader\Export;

/**
 * Export generic language strings to JavaScript.
 * Emits the `_LANG` structure consumed across the UI.
 */
class Lang extends AbstractExport
{
    public function rehashOutputFilename(array $hash): array
    {
        global $S;
        $hash['lang'] = $S['global']['lang'];
        return $hash;
    }

    public function gather(): static
    {
        $LANG1 = \App\Loader_Lang::getInstance()->loadAppFile('global.lang.php')->getAll();
        $this->data['yes'] =        $LANG1['yes'];
        $this->data['no'] =         $LANG1['no'];
        $this->data['confirm'] =    $LANG1['confirm'];

        $LANG2 = \App\Loader_Lang::getInstance()->loadAppFile('events.lang.php')->getAll();
        $this->data['RemoteData/Calendar'] =    $LANG2['RemoteData/Calendar'];
        $this->data['notifications'] =          $LANG2['notifications'];

        $LANG3 = \App\Loader_Lang::getInstance()->loadAppFile('menu.lang.php')->getAll();
        $this->data['logoutConfirmation'] =     $LANG3['logoutConfirmation'];

        $LANG4 = \App\Loader_Lang::getInstance()->loadAppFile('travel.lang.php')->getAll();
        if (!empty($LANG4['travel']['services']['serviceDurationType'])) {
            $this->data['date']['days'] =     $LANG4['travel']['services']['serviceDurationType']['days'];
            $this->data['date']['nights'] =   $LANG4['travel']['services']['serviceDurationType']['nights'];
            $this->data['date']['hours'] =    $LANG4['travel']['services']['serviceDurationType']['hours'];
        }

        return $this;
    }

    public function asJSON(): string
    {
        $output = [];
        $output[] = $this->exportBulkVariables("_LANG", $this->data);
        return implode("\n", $output);
    }
}
