<!doctype html>
<html lang="<?php echo $cms['config']['lang']; ?>">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<?php
if ( is_admin() ) {
    echo "<title>".__('Admin')."</title>";
} elseif ( empty( $cms['config']['admin.mod.php']['admin_login'] ) && 
           empty( $cms['config']['admin.mod.php']['admin_password'] ) ) {
    echo "<title>".__('Install')."</title>";
} else {
    echo "<title>".__('Auth')."</title>";
} ?>
<link rel="icon" href="<?php echo $cms['base_path']; ?>img/favicon.png">
<link rel="stylesheet" type="text/css" href="<?php echo $cms['base_path']; ?>css/select2.min.css">
<script src="<?php echo $cms['base_path']; ?>js/jquery-3.5.1.min.js"></script>
<script src="<?php echo $cms['base_path']; ?>js/jquery.cookie.js"></script>
<script src="<?php echo $cms['base_path']; ?>js/jquery.form.min.js"></script>
<script src="<?php echo $cms['base_path']; ?>js/jquery.searcher.min.js"></script>

<?php cms_do_stage('admin_header'); ?>

<?php
$styles = array();
foreach( glob( $cms['cms_dir'].'/css/admin.*.css' ) as $file ) {
    preg_match( '/.*(\/admin\.(.*)\.(.*)\.css)/', $file, $m );
    echo "<link rel=stylesheet href='{$cms['base_path']}css{$m[1]}'>\n";
    array_push($styles,array($m[2],$m[3]));
}
echo "<script>\nadmin_styles = ".json_encode( $styles ).";\n";

if ( !empty( $cms['config']['locale'] ) ) {
    $lang = json_encode($cms["lang"]);
    $tr   = json_encode($cms["tr"]);
    echo "cms = {};
cms.locale = '{$cms['config']['locale']}';
cms.lang = {$lang};
cms.tr = {$tr};
</script>\n";
}
?>

</head>


<?php if (is_admin()): ?>

<body class="logged">
    <header>
        <div class="contlogo">
            <div class="contlogo-group">
                <div title="Coffee CMS" class="logo">
                    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 233.34 233.24"><defs><style>.a-logo{fill:#564c44;}</style></defs><path class="a-logo" d="M116.62,0c-1.63,0-3.25,0-4.87.11a112.56,112.56,0,0,0,1.74,44.51c6.09,24.94,16.07,49.17,26.47,72.77,15.52,35.21,24.37,70.68,21.06,107.13A116.63,116.63,0,0,0,116.62,0Z" transform="translate(0.05)"/><path class="a-logo" d="M120.92,233.16V233c7.12-39.29-3.54-75.28-21.28-109.75-19-36.9-30.46-74.6-27.76-114.33a116.64,116.64,0,0,0,44.7,224.36C118.06,233.24,119.49,233.21,120.92,233.16Z" transform="translate(0.05)"/></svg>
                </div>
                <div class="brand">Coffee CMS</div>
            </div>
        </div>
        <div class="contmenu">
            <div class="contmenu-group">
                <a href="/" class=open-front-page data-front target=_blank><?php echo __('Home'); ?></a>
                <a href="#" class=recreate-cache data-cache><?php echo __('Update Pages'); ?></a>
                <a href="#" class=theme-switcher data-theme><?php echo __('Theme'); ?></a>
                <a href="#" class=logout data-logout><?php echo __('Logout'); ?></a>
            </div>
            
            <div class="mobicontmenu">
                <div class="button-mobimenu-container" onclick="toggle_menu()">
                    <div class="menu-icon">
                        <span class="line-1"></span>
                        <span class="line-2"></span>
                    </div>
                </div>
                <div class="services-button">
                    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 30" style="display: block;"><defs><style>.a-sb{fill:none;}.b-sb{fill:#fff;}</style></defs><rect class="a-sb" width="48" height="30"/><circle class="b-sb" cx="12.03" cy="15" r="3.02"/><circle class="b-sb" cx="23.94" cy="15" r="3.02"/><circle class="b-sb" cx="35.97" cy="15" r="3.02"/></svg>
                </div>
            </div>

        </div>
    </header>

  <aside>
    <div class="adminmenuwrap">
        <div class="height-corrector">
<?php
foreach( $cms['admin_sections'] as $section_name => $section ) {
    if ( !isset($section['hide']) || isset($section['hide']) && !$section['hide'] ) {
        echo '<div class="adminmenubox">';
        echo "<h1>{$cms['admin_sections'][$section_name]['title']}</h1>";
        # Пункты секции
        if ( !empty( $cms['admin_sections'][$section_name]['items'] ) )
        foreach( $cms['admin_sections'][$section_name]['items'] as $page_name => $page ) {
            if ( !isset($page['hide']) || isset($page['hide']) && !$page['hide'] ) {
                $title = __($page['title'],$page['module']);
                if ( !empty($page['class']) ) {
                    $class = " class='{$page['class']}'";
                } else {
                    $class = "";
                }
                if ( empty( $page['external_url'] ) ) {
                    echo "<a href='#{$page_name}' data-am-page='{$page_name}'{$class}>{$title}</a>";
                } else {
                    echo "<a href='{$page['external_url']}' {$class}>{$title}</a>";
                }
            }
        }
        echo '</div>';
    }
}
?>

        </div>
    </div>
  </aside>


  <main>

<?php
    $hello = __("Hello!");
    if ( cms_base_connect() === false ) {
        $base_ok = __("The first step is to set up your database connection.");
    } else {
        $base_ok = __("This is the start page. Select the item on the left.");
    }

    echo <<<EOS
    <section id="start" class="module-settings" data-settings="start">
        <div class="main-header"></div>
        <div class="main-main">
            <div class="info-grid">
                <h1>{$hello}</h1>
                <p>{$base_ok}</p>
            </div>
        </div>
        <div class="main-footer"></div>
    </section>
EOS;

    foreach( $cms['admin_pages'] as $name => $page ) {
        echo "<section id='{$name}' class='module-settings' data-settings='{$name}'>{$page}</section>";
    }
    
?>

  </main>

  <div class="bg-reset"></div>

<?php else: ?>

<body class="login">
  
    <header>
        <div class="contlogo">
            <div class="contlogo-group">
                <div title="Coffee CMS" class="logo">
                    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 233.34 233.24"><defs><style>.a-logo{fill:#564c44;}</style></defs><path class="a-logo" d="M116.62,0c-1.63,0-3.25,0-4.87.11a112.56,112.56,0,0,0,1.74,44.51c6.09,24.94,16.07,49.17,26.47,72.77,15.52,35.21,24.37,70.68,21.06,107.13A116.63,116.63,0,0,0,116.62,0Z" transform="translate(0.05)"/><path class="a-logo" d="M120.92,233.16V233c7.12-39.29-3.54-75.28-21.28-109.75-19-36.9-30.46-74.6-27.76-114.33a116.64,116.64,0,0,0,44.7,224.36C118.06,233.24,119.49,233.21,120.92,233.16Z" transform="translate(0.05)"/></svg>
                </div>
                <div class="brand">Coffee CMS</div>
            </div>
        </div>
        <div class="contmenu">
            <div class="contmenu-group">
                <?php
                if ( empty( $cms['config']['admin.mod.php']['admin_password'] ) ) {
                
                    // Scan all locales
                    echo "<a href='?locale=en_US.UTF-8' >en_US.UTF-8</a>";
                    foreach( glob( 'lang/*.UTF-8',  GLOB_ONLYDIR ) as $locale ) {
                        $locale = preg_replace( '/.*\//', '', $locale );
                        echo "<a href='?locale={$locale}' >{$locale}</a>";
                    }
    
                }
                ?>
                <a href="#" class=theme-switcher data-theme><?php echo __('Theme'); ?></a>
            </div>
        </div>
    </header>

    <div class="authorization-box">
        <?php if ( empty( $cms['config']['admin.mod.php']['admin_login'] ) && 
                   empty( $cms['config']['admin.mod.php']['admin_password'] ) ) {
            echo "<div class='setup-auth'>".__('Setup Login and Password')."</div>";
        } ?>
        <div class="authorization">
            <div class="authorization-input-log">
                <input placeholder="<?php echo __('Login or Email'); ?>" name="login" type="text" class="authorization-settingx-log">
            </div>
            <div class="authorization-input-pass">
                <input placeholder="<?php echo __('Password'); ?>" name="password" type="password" class="authorization-settingx-pass">
                <div title="<?php echo __('Enter'); ?>" class="button-adminix-avtor" type="submit" data-login-btn></div>
            </div>
        </div>
    </div>
    
<?php endif; ?>
    
    <div class="log-info-box">
        <!-- div for messages -->
    </div>
</body>
</html>
