<?php

namespace Korkz\Demirteknoloji\Controllers\Home;
use Exception;
use Korkz\Demirteknoloji\Models\Home\ProjectsModel;
use Korkz\Demirteknoloji\Router\View;
use Korkz\Demirteknoloji\traits\Lang;
use Korkz\Demirteknoloji\traits\TokenConfig;

class ProjectsControl extends ProjectsModel
{
    use TokenConfig;
    use Lang;

    /**
     * @param $page
     * @return void
     * @throws Exception
     */
    public function projectShow($page): void
    {
        $baseUrl = $this->baseUrl();
        $lang = $this->getLang();
        print $this->views("$page",["baseUrl" => $baseUrl, "token" => $this->tokenCreate(), "lang" => $this->getLang(), "data" => ["settings" => $this->settingData($lang), "head" => '',
            "footer" => '',
            "page" => $page,
            "dropDown"=>true
        ]]);
    }

//    public function projectsShow($page)
//    {
//        return "Projeler";
//    }

    private function views(string $page, array $dataBinds = []): array|string
    {

        ob_start();
        $lang = "";
        if (!empty($dataBinds)) {
            foreach ($dataBinds as $key => $dataBind) {
                View::bind($key, $dataBind);
                if (str_starts_with($key, "lang")) {
                    $lang = $dataBind;
                }
            }
        }
        View::render("home/project", ["header" => "home/layout/header", "footer" => "home/layout/footer"]);
        $content = ob_get_clean();
        return $this->langViews("home", "$page", $content, $lang);
    }

    /**
     * @param string $langActive
     * @return array
     * @throws Exception
     */

    private function settingData(string $langActive): array
    {
        $settings = $this->getData("settings", ["*"], ["Lang" => $langActive]);
        if ($settings) {
            return $settings[0];
        } else {
            return [];
        }
    }

    public function projects(): array
    {
        return ["/elzemservissistemi","/elzemgorevyonetimsistemi"];
    }


}