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

/**
 * Export calendar language strings to JavaScript.
 * Emits Calendar day/month names and UI strings consumed by the calendar widget.
 */
class Calendar extends AbstractExport
{
    public function rehashOutputFilename(array $hash): array
    {
        global $S;
        $hash['lang'] = $S['global']['lang'];
        return $hash;
    }

    public function gather(): static
    {
        $LANG = \App\Loader_Lang::getInstance()->loadAppFile('dateTime.lang.php')->getAll();

        foreach ($LANG['date']['day']['long'] as $l) {
            $this->data['Calendar._DN'][] = $l;
        }
        foreach ($LANG['date']['day']['short'] as $l) {
            $this->data['Calendar._SDN'][] = $l;
        }
        foreach ($LANG['date']['month']['long'] as $l) {
            $this->data['Calendar._MN'][] = $l;
        }
        foreach ($LANG['date']['month']['short'] as $l) {
            $this->data['Calendar._SMN'][] = $l;
        }

        $this->data['_TT']['INFO'] =       ($LANG['date']['calendar']['aboutSection'] ?? '');
        $this->data['_TT']['PREV_YEAR'] =  ($LANG['date']['calendar']['prevYear'] ?? '');
        $this->data['_TT']['PREV_MONTH'] = ($LANG['date']['calendar']['prevMonth'] ?? '');
        $this->data['_TT']['GO_TODAY'] =   ($LANG['date']['calendar']['goToday'] ?? '');
        $this->data['_TT']['NEXT_MONTH'] = ($LANG['date']['calendar']['nextMonth'] ?? '');
        $this->data['_TT']['NEXT_YEAR'] =  ($LANG['date']['calendar']['nextYear'] ?? '');
        $this->data['_TT']['SEL_DATE'] =   ($LANG['date']['calendar']['chooseDate'] ?? '');
        $this->data['_TT']['DRAG_TO_MOVE'] = ($LANG['date']['calendar']['dragToMove'] ?? '');
        $this->data['_TT']['PART_TODAY'] = ($LANG['date']['calendar']['todayPart'] ?? '');
        $this->data['_TT']['DAY_FIRST'] =  ($LANG['date']['calendar']['firstDay'] ?? '');
        $this->data['_TT']['CLOSE'] =      ($LANG['date']['calendar']['close'] ?? '');
        $this->data['_TT']['TODAY'] =      ($LANG['date']['calendar']['todayTitle'] ?? '');
        $this->data['_TT']['TIME_PART'] =  ($LANG['date']['calendar']['timeChange'] ?? '');
        $this->data['_TT']['WK'] =         ($LANG['date']['calendar']['weekShort'] ?? '');
        $this->data['_TT']['TIME'] =       ($LANG['date']['calendar']['time'] ?? '');

        return $this;
    }

    public function asJSON(): string
    {
        $output = [];
        $output[] = $this->exportBulkVariablesAndMerge("Calendar._DN",  $this->data['Calendar._DN'] ?? []);
        $output[] = $this->exportBulkVariablesAndMerge("Calendar._SDN", $this->data['Calendar._SDN'] ?? []);
        $output[] = $this->exportBulkVariablesAndMerge("Calendar._MN",  $this->data['Calendar._MN'] ?? []);
        $output[] = $this->exportBulkVariablesAndMerge("Calendar._SMN", $this->data['Calendar._SMN'] ?? []);
        $output[] = $this->exportBulkVariablesAndMerge("Calendar._TT",  $this->data['_TT'] ?? []);

        return implode("\n", $output);
    }

}
