config = $config;
    }
}
/*
 * Sent when the setup page is ready to be added to
 */
class SetupBuildingEvent extends Event
{
    protected SetupTheme $theme;
    public SetupPanel $panel;
    public function __construct(SetupPanel $panel)
    {
        parent::__construct();
        $this->panel = $panel;
    }
}
class SetupPanel
{
    /** @var SetupBlock[]  */
    public array $blocks = [];
    public BaseConfig $config;
    public function __construct(BaseConfig $config)
    {
        $this->config = $config;
    }
    public function create_new_block(string $title): SetupBlock
    {
        $block = new SetupBlock($title, $this->config);
        $this->blocks[] = $block;
        return $block;
    }
}
class SetupBlock extends Block
{
    public ?string $header;
    public ?string $body;
    public BaseConfig $config;
    public function __construct(string $title, BaseConfig $config)
    {
        parent::__construct($title, "", "main", 50);
        $this->config = $config;
    }
    public function add_label(string $text)
    {
        $this->body .= $text;
    }
    public function start_table()
    {
        $this->body .= "
";
    }
    public function start_table_row()
    {
        $this->body .= "";
    }
    public function end_table_row()
    {
        $this->body .= " ";
    }
    public function start_table_head()
    {
        $this->body .= "";
    }
    public function end_table_head()
    {
        $this->body .= " ";
    }
    public function add_table_header($content, int $colspan = 2)
    {
        $this->start_table_head();
        $this->start_table_row();
        $this->add_table_header_cell($content, $colspan);
        $this->end_table_row();
        $this->end_table_head();
    }
    public function start_table_cell(int $colspan = 1)
    {
        $this->body .= "";
    }
    public function end_table_cell()
    {
        $this->body .= " ";
    }
    public function add_table_cell($content, int $colspan = 1)
    {
        $this->start_table_cell($colspan);
        $this->body .= $content;
        $this->end_table_cell();
    }
    public function start_table_header_cell(int $colspan = 1, string $align = 'right')
    {
        $this->body .= "";
    }
    public function end_table_header_cell()
    {
        $this->body .= " ";
    }
    public function add_table_header_cell($content, int $colspan = 1)
    {
        $this->start_table_header_cell($colspan);
        $this->body .= $content;
        $this->end_table_header_cell();
    }
    private function format_option(
        string $name,
        $html,
        ?string $label,
        bool $table_row,
        bool $label_row = false
    ) {
        if ($table_row) {
            $this->start_table_row();
        }
        if ($table_row) {
            $this->start_table_header_cell($label_row ? 2 : 1, $label_row ? 'center' : 'right');
        }
        if (!is_null($label)) {
            $this->body .= "{$label} ";
        }
        if ($table_row) {
            $this->end_table_header_cell();
        }
        if ($table_row && $label_row) {
            $this->end_table_row();
            $this->start_table_row();
        }
        if ($table_row) {
            $this->start_table_cell($label_row ? 2 : 1);
        }
        $this->body .= $html;
        if ($table_row) {
            $this->end_table_cell();
        }
        if ($table_row) {
            $this->end_table_row();
        }
    }
    public function add_text_option(string $name, string $label=null, bool $table_row = false)
    {
        $val = html_escape($this->config->get_string($name));
        $html = "{$label} ";
        }
        $html .= "{$label} ";
        }
        $html .= "";
        foreach ($options as $optname => $optval) {
            if ($optval == $current) {
                $selected=" selected";
            } else {
                $selected="";
            }
            $html .= "$optname \n";
        }
        $html .= " ";
        $html .= "";
        foreach ($options as $optname => $optval) {
            if (in_array($optval, $current)) {
                $selected=" selected";
            } else {
                $selected="";
            }
            $html .= "$optname \n";
        }
        $html .= " ";
        $html .= "(Javascript inactive, can't test!) $nicescript");
        $sb = $event->panel->create_new_block("Remote API Integration");
        $sb->add_label("Akismet ");
        $sb->add_text_option("comment_wordpress_key", "ReCAPTCHA ");
        $sb->add_text_option("api_recaptcha_privkey", "\n";
            print "\t\teg 'config get db_version'\n\n";
        }
        if ($event->cmd == "config") {
            global $cache, $config;
            $cmd = $event->args[0];
            $key = $event->args[1];
            switch ($cmd) {
                case "get":
                    print($config->get_string($key) . "\n");
                    break;
                case "set":
                    $config->set_string($key, $event->args[2]);
                    break;
            }
            $cache->delete("config");
        }
    }
    public function onPageSubNavBuilding(PageSubNavBuildingEvent $event)
    {
        global $user;
        if ($event->parent==="system") {
            if ($user->can(Permissions::CHANGE_SETTING)) {
                $event->add_nav_link("setup", new Link('setup'), "Board Config", null, 0);
            }
        }
    }
    public function onUserBlockBuilding(UserBlockBuildingEvent $event)
    {
        global $user;
        if ($user->can(Permissions::CHANGE_SETTING)) {
            $event->add_link("Board Config", make_link("setup"));
        }
    }
    public function onParseLinkTemplate(ParseLinkTemplateEvent $event)
    {
        global $config;
        $event->replace('$base', $config->get_string('base_href'));
        $event->replace('$title', $config->get_string(SetupConfig::TITLE));
    }
}