<?php
// SPDX-FileCopyrightText: IndieHosters <contact@indiehosters.net>
// SPDX-License-Identifier: AGPL-3.0-or-later

namespace OCA\CustomNav\Settings;

use OCA\CustomNav\AppInfo\Application;
use OCA\CustomNav\Service\Manager;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\Settings\ISettings;
use OCP\Util;

class Admin implements ISettings
{
    private Manager $manager;
    protected IInitialState $initialState;

    public function __construct(
        Manager $manager,
        IInitialState $initialState,
    ) {
        $this->manager = $manager;
        $this->initialState = $initialState;
    }

    public function getForm(): TemplateResponse
    {
        $apps = $this->manager->getDefaultApps();
        $overwrite = $this->manager->getSystemOverwrite();
        $this->initialState->provideInitialState("settings", [
            "isAdminPanel" => true,
            "disableUserEdit" => $this->manager->isDisableUserEdit(),
            "apps" => $this->manager->applyOverwrites($apps, $overwrite),
            "defaultApps" => $apps,
        ]);

        Util::addScript(Application::APP_ID, "customnav-admin");

        return new TemplateResponse(Application::APP_ID, "main");
    }

    public function getSection(): string
    {
        return Application::APP_ID;
    }

    public function getPriority(): int
    {
        return 70;
    }
}
