<?php

namespace Korkz\Demirteknoloji\Controllers\Admin;

use Exception;
use Korkz\Demirteknoloji\Connect\DbOperations;
use Korkz\Demirteknoloji\Router\View;
use Korkz\Demirteknoloji\traits\AuthControl;
use Korkz\Demirteknoloji\traits\Lang;
use Korkz\Demirteknoloji\traits\Settings;
use Korkz\Demirteknoloji\traits\TokenAndValidControl;
use Korkz\Demirteknoloji\traits\TokenConfig;

class BlankController extends DbOperations
{
    use AuthControl;
    use Lang;
    use TokenConfig;
    use TokenAndValidControl;
    use Settings;

    /**
     * @throws Exception
     */
    public function show(string|array $paths, $prefix): void
    {
        $baseUrl = $this->baseUrl();
        self::checkAccess($paths, $prefix);
        $userCode = isset($_SESSION["userCode"]) ? $this->openKey($_SESSION["userCode"]) : null;
        $user = $this->usersData($userCode);
        $lang = $this->getLang();
        $settings=$this->settingData($lang);
        print $this->views(["baseUrl" => $baseUrl, "tittle" => " Demirteknoloji yönetim paneli", "token" => $this->tokenCreate(), "lang" => $lang, "open_tab" => "blank", "active" => "blank", "themeMode" => $_SESSION["theme_mode"] ?? "", "themeColor" => $_SESSION["theme_color"] ?? "theme-blue", "data" => ["user" => $user, "settings" => $settings,"head" => '', "script" => '']]);

    }

    /**
     * @param array $dataBinds
     * @return array|string
     */
    private function views(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("admin/blank", ["header" => "admin/layout/header", "footer" => "admin/layout/footer"]);
        $content = ob_get_clean();
        return $this->langViews("admin", "blank", $content, $lang);
    }


}
