<div id="pma_console_container">
    <div id="pma_console">
        <!-- Console toolbar -->
        <?= PMA\libraries\Template::get('console/toolbar')
        ->render(
            array(
                'parentDivClasses'  => 'collapsed',
                'contentArray'      => [
                    ['switch_button console_switch',    __('Console'),'image'=> $image],
                    ['button clear',                    __('Clear')],
                    ['button history',                  __('History')],
                    ['button options',                  __('Options')],
                    isset($cfgBookmark)
                    ? ['button bookmarks',              __('Bookmarks')] : null,
                    ['button debug hide',               __('Debug SQL')],
                ],
            )
        );
        ?>
        <!-- Toolbar end -->
        <!-- Console messages -->
        <div class="content">
            <div class="console_message_container">
                <div class="message welcome">
                    <span id="instructions-0">
                        <?= __('Press Ctrl+Enter to execute query') ; ?>
                    </span>
                    <span class="hide" id="instructions-1">
                        <?= __('Press Enter to execute query') ; ?>
                    </span>
                </div>
                <?php if (! empty($_sql_history)):
                    foreach (array_reverse($_sql_history) as $record):
                        $isSelect = preg_match(
                            '@^SELECT[[:space:]]+@i', $record['sqlquery']
                        );
                        $queriedTime = isset($record['timevalue'])
                                        ? $record['timevalue']
                                        : __('During current session');
                        ?>
                    <div class="message history collapsed hide <?= ($isSelect ? 'select' : '') ; ?>"
                        targetdb="<?= htmlspecialchars($record['db']) ; ?>" targettable="<?= htmlspecialchars($record['table']) ; ?>">
                        <?= PMA\libraries\Template::get('console/query_action')
                            ->render(
                                array(
                                    'parentDivClasses'  => 'action_content',
                                    'contentArray'      => [
                                        ['action collapse',     __('Collapse')],
                                        ['action expand',       __('Expand')],
                                        ['action requery',      __('Requery')],
                                        ['action edit',         __('Edit')],
                                        ['action explain',      __('Explain')],
                                        ['action profiling',    __('Profiling')],
                                        isset($cfgBookmark)
                                        ? ['action bookmark',   __('Bookmark')] : null,
                                        ['text failed',         __('Query failed')],
                                        ['text targetdb',       __('Database'), 'extraSpan' => htmlspecialchars($record['db'])],
                                        ['text query_time',     __('Queried time'), 'extraSpan' => $queriedTime],
                                    ],
                                )
                            );
                        ?>
                        <span class="query"> <?= htmlspecialchars($record['sqlquery']) ; ?> </span>
                    </div>
                    <?php endforeach ;
                 endif ; ?>
            </div> <!-- console_message_container -->
            <div class="query_input">
                <span class="console_query_input"></span>
            </div>
        </div> <!-- message end -->
        <!-- Drak the console with other cards over it -->
        <div class="mid_layer"></div>
        <!-- Debug SQL card -->
        <div class="card" id="debug_console">
            <?= PMA\libraries\Template::get('console/toolbar')
                ->render(
                    array(
                        'parentDivClasses'  => '',
                        'contentArray'      => [
                            ['button order order_asc',      __('ascending')],
                            ['button order order_desc',     __('descending')],
                            ['text',                        __('Order:')],
                            ['switch_button',               __('Debug SQL')],
                            ['button order_by sort_count',  __('Count')],
                            ['button order_by sort_exec',   __('Execution order')],
                            ['button order_by sort_time',   __('Time taken')],
                            ['text',                        __('Order by:')],
                            ['button group_queries',        __('Group queries')],
                            ['button ungroup_queries',      __('Ungroup queries')],
                        ]
                    )
                );
            ?>
            <div class="content debug">
                <div class="message welcome"></div>
                <div class="debugLog"></div>
            </div> <!-- Content -->
            <div class="templates">
                <?= PMA\libraries\Template::get('console/query_action')
                ->render(
                    array(
                        'parentDivClasses'  => 'debug_query action_content',
                        'contentArray'      => [
                            ['action collapse',         __('Collapse')],
                            ['action expand',           __('Expand')],
                            ['action dbg_show_trace',   __('Show trace')],
                            ['action dbg_hide_trace',   __('Hide trace')],
                            ['text count hide',         __('Count'), 'extraSpan' => ''],
                            ['text time',               __('Time taken'), 'extraSpan' => ''],
                        ]
                    )
                );
                ?>
            </div> <!-- Template -->
        </div> <!-- Debug SQL card -->
        <?php if ($cfgBookmark): ?>
        <div class="card" id="pma_bookmarks">
            <?= PMA\libraries\Template::get('console/toolbar')
            ->render(
                array(
                    'parentDivClasses'  => '',
                    'contentArray'      => [
                        ['switch_button',   __('Bookmarks')],
                        ['button refresh',  __('Refresh')],
                        ['button add',      __('Add')],
                    ]
                )
            );
            ?>
            <div class="content bookmark">
                <?= $bookmarkContent ; ?>
            </div>
            <div class="mid_layer"></div>
            <div class="card add">
                <?= PMA\libraries\Template::get('console/toolbar')
                ->render(
                    array(
                        'parentDivClasses'  => '',
                        'contentArray'      => [
                            ['switch_button',   __('Add bookmark')]
                        ]
                    )
                );
                ?>
                <div class="content add_bookmark">
                    <div class="options">
                        <label>
                            <?= __('Label') ; ?>: <input type="text" name="label">
                        </label>
                        <label>
                            <?= __('Target database') ; ?>: <input type="text" name="targetdb">
                        </label>
                        <label>
                            <input type="checkbox" name="shared"> <?= __('Share this bookmark') ; ?>
                        </label>
                        <button type="submit" name="submit">OK</button>
                    </div> <!-- options -->
                    <div class="query_input">
                        <span class="bookmark_add_input"></span>
                    </div>
                </div>
            </div> <!-- Add bookmark card -->
        </div> <!-- Bookmarks card -->
        <?php endif ; ?>
        <!-- Options card: -->
        <div class="card" id="pma_console_options">
            <?= PMA\libraries\Template::get('console/toolbar')
            ->render(
                array(
                    'parentDivClasses'  => '',
                    'contentArray'      => [
                        ['switch_button',   __('Options')],
                        ['button default',  __('Set default')]
                    ]
                )
            );
            ?>
            <div class="content">
                <label>
                    <input type="checkbox" name="always_expand"><?= __('Always expand query messages') ; ?>
                </label>
                <br>
                <label>
                    <input type="checkbox" name="start_history"><?= __('Show query history at start') ; ?>
                </label>
                <br>
                <label>
                    <input type="checkbox" name="current_query"><?= __('Show current browsing query')  ; ?>
                </label>
                <br>
                <label>
                    <input type="checkbox" name="enter_executes">
                        <?= __('Execute queries on Enter and insert new line with Shift + Enter. To make this permanent, view settings.') ; ?>
                </label>
                <br>
                <label>
                    <input type="checkbox" name="dark_theme"><?= __('Switch to dark theme') ; ?>
                </label>
                <br>
            </div>
        </div> <!-- Options card -->
        <div class="templates">
            <!-- Templates for console message actions -->
            <?= PMA\libraries\Template::get('console/query_action')
                ->render(
                    array(
                        'parentDivClasses'  => 'query_actions',
                        'contentArray'      => [
                            ['action collapse',     __('Collapse')],
                            ['action expand',       __('Expand')],
                            ['action requery',      __('Requery')],
                            ['action edit',         __('Edit')],
                            ['action explain',      __('Explain')],
                            ['action profiling',    __('Profiling')],
                            isset($cfgBookmark)
                            ? ['action bookmark',   __('Bookmark')] : null,
                            ['text failed',         __('Query failed')],
                            ['text targetdb',       __('Database'), 'extraSpan' => ''],
                            ['text query_time',     __('Queried time'), 'extraSpan' => ''],
                        ],
                    )
                );
            ?>
        </div>
    </div> <!-- #console end -->
</div> <!-- #console_container end -->
