<?php

declare(strict_types=1);

namespace Seka\Portal\Modul\Statistiky\Http\Controllers\Frontend;

use Seka\Portal\Modul\Statistiky\Entities\Zaznam\Enums\DruhSubjektuZaznamuEnum;
use Seka\Portal\Modul\Statistiky\Http\View\ZaznamDatumFilterEnum;
use Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Presenters\Summary\ZaznamPracoviskoSummaryPresenter;
use Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\ZaznamPracoviskoSummaryDataTableTransformer;
use Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\ZaznamPracoviskoSummaryEChartsDataTransformer;

/**
 * Class PracoviskoController
 *
 * @package Seka\Portal\Modul\Statistiky\Http\Controllers\Frontend
 */
final class PracoviskoController extends FilterController
{
    /**
     * @param \Seka\Portal\Modul\Statistiky\Http\View\ZaznamDatumFilterEnum $dateFilter
     *
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Foundation\Application|\Illuminate\View\View
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
     * @throws \Prettus\Repository\Exceptions\RepositoryException
     */
    protected function makeView(ZaznamDatumFilterEnum $dateFilter)
    {
        $pekId = auth()->user()->pracovisko->id;

        list($from, $to) = $this->getFromDate($dateFilter);
        $data = $this->getData($pekId, $from, $to, DruhSubjektuZaznamuEnum::PRACOVISKO);
        $summaryDataTables = (new ZaznamPracoviskoSummaryPresenter(new ZaznamPracoviskoSummaryDataTableTransformer()))->present($data);
        $summaryECharts = (new ZaznamPracoviskoSummaryPresenter(new ZaznamPracoviskoSummaryEChartsDataTransformer()))->present($data);

        return view('Statistiky::frontend.pages.pracovisko.index')
            ->with([
                'datumOd' => $from->format('d.m.Y'),
                'datumDo' => $to->format('d.m.Y'),
                'form_datefilter' => $dateFilter,
                'form_date_from' => $from->format('Y-m-d'),
                'form_date_to' => $to->format('Y-m-d'),
                'filterFormActionRoute' => route('modul.statistiky.frontend.pracovisko.filter'),
            ])
            ->with($summaryDataTables)
            ->with($summaryECharts);
    }
}
