<?php
namespace ModulesGarden\OpenXchangeAddon\App\UI\Admin\Settings\Pages;

use ModulesGarden\OpenXchangeAddon\Core\UI\Widget\Forms\Fields;
use ModulesGarden\OpenXchangeAddon\Core\UI\Interfaces\AdminArea;
use ModulesGarden\OpenXchangeAddon\Core\UI\Widget\Forms\Sections;
use ModulesGarden\OpenXchangeAddon\Core\UI\Widget\Forms\Fields\Switcher;
use ModulesGarden\OpenXchangeAddon\App\UI\Admin\Settings\Providers\SettingsDataProvider;
use ModulesGarden\OpenXchangeAddon\Core\UI\Widget\Forms\BaseStandaloneFormExtSections;
//use ModulesGarden\Servers\OpenXchange\App\UI\Client\Others\Fields\OptGroupSelect;

class SettingsPage extends BaseStandaloneFormExtSections implements AdminArea
{
    protected $id = 'configForm';
    protected $name = 'configForm';

    public function initContent()
    {
        $this->setProvider(new SettingsDataProvider());

        /**
         * LOGO SETTINGS
         */
        $leftSection = new Sections\HalfPageSection();
        $leftSection->setId('statusColor');
        $rightSection = new Sections\HalfPageSection();
        $rightSection->setId('statusColorright');

        $logoUrlLightField = new Fields\Text('logoUrlLight');
        $leftSection->addField($logoUrlLightField);
        $logoUrlDarkField = new Fields\Text('logoUrlDark');
        $rightSection->addField($logoUrlDarkField);

        $logoHeight = new Fields\Text('logoHeight');
        $leftSection->addField($logoHeight);

        $logoWidth = new Fields\Text('logoWidth');
        $rightSection->addField($logoWidth);

        $section = new Sections\BoxSection();
        $section->setId('statusColor1');
        $section->setTitle('logoSettings');
        $section->addSection($leftSection);
        $section->addSection($rightSection);
        $this->addSection($section);

        /**
         * THEME SETTINGS
         */
        $leftSection2 = new Sections\HalfPageSection();
        $leftSection2->setId('colorsleft');
        $rightSection2 = new Sections\HalfPageSection();
        $rightSection2->setId('colorsright');

        $uiTable = [
            'mainColor', 'topbarBackground', 'topbarHover', 'linkHover', 'linkColor', 'listSelectedFocus', 'listSelected', 'listHover',
        ];

        foreach ($uiTable as $field) {
            $field1 = new Fields\ColorSwitcher($field);
            $field1->setHtmlAttributes([
                'onchange' => 'disableColorPicker(event)',
                'onload' => 'disableColorPicker(event)',
            ]);
            $leftSection2->addField($field1);
            $fieldName = $field . 'Picker';
            $field2 = new Fields\ColorPicker($fieldName);
            $rightSection2->addField($field2);
        }

        $section2 = new Sections\BoxSection();
        $section2->setId('statusColor2');
        $section2->setTitle('UISettings');
        $section2->addSection($leftSection2);
        $section2->addSection($rightSection2);
        $this->addSection($section2);
        
        /**
         * Configuration settings
         */
        $leftSection3 = new Sections\HalfPageSection();
        $leftSection3->setId('configSection');
        $rightSection3 = new Sections\HalfPageSection();
        $rightSection3->setId('configSectionRight');

        //portal url field
        $portalUrlField3 = new Fields\Text('portalURL');
        $leftSection3->addField($portalUrlField3);
        
        $portalNameField = new Fields\Text('portalName');
        $leftSection3->addField($portalNameField);

        //default timezone dropdown
        //$this->generateDoubleSection([(new OptGroupSelect('timezone'))->notEmpty(), (new Select('language'))->notEmpty()]);
        $timezone3 = new Fields\Select('timezone');
        $leftSection3->addField($timezone3);

        $language3 = new Fields\Select('language');
        $language3->enableMultiple();
        $rightSection3->addField($language3);

        $language3 = new Fields\Select('languagedef');
        $rightSection3->addField($language3);

        $autofill3 = new Fields\Switcher('autofill');
        $rightSection3->addField($autofill3);

        $section3 = new Sections\BoxSection();
        $section3->setId('configSection');
        $section3->setTitle('configSettings');
        $section3->addSection($leftSection3);
        $section3->addSection($rightSection3);
        $this->addSection($section3);

        $this->loadDataToForm();
    }
}
