<?php
function find_wordpress_root($start_path) {
    while (!file_exists($start_path . '/wp-load.php')) {
        $start_path = dirname($start_path);
        if ($start_path === '/') {
            return false;
        }
    }
    return $start_path;
}
$wordpress_root = find_wordpress_root(__DIR__);
require_once $wordpress_root. '/wp-load.php';
global $wpdb;
$getTabs=$wpdb->get_row('SELECT * FROM ' . $wpdb->prefix . 'hd_webapp_tab_bar where status=1' );
if(!empty($getTabs)){
    ?>
    <style>
        <?php
                if(isset($_GET["mobile"])){
                ?>
        body {
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f5f5f5;
        }

        .mobile-view-container {
            width: 414px; /* Typical mobile width */
            height: 896px; /* Typical mobile height */
            box-shadow: 0 0 15px rgba(0, 0, 0, 0.2); /* شبیه‌سازی سایه برای موبایل */
            border-radius: 10px;
            overflow: hidden;
            background-color: white;
        }

        .hd-container {
            position: relative;
            left: 0;
            right: 0;
            bottom: 0;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .hd-menu {
            display: flex;
            flex-grow: 1;
            height: 65px;
            border-radius: 0;
            overflow: hidden;
            background-color: <?=$getTabs->background_color?>;
            box-shadow: 0 0 1px 0 rgb(52 46 173 / 25%), 0 15px 30px 0 rgb(52 46 173 / 10%);
            position: absolute;
            width: 100%;
            bottom: 0;
        }
        <?php } else {?>
        .hd-container {
            z-index:10000000000;
            position: absolute;
            left: 0;
            right: 0;
            bottom: 0;
            width: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
            height: 65px;
        }
        .hd-menu {
            display: flex;
            flex-grow: 1;
            height: 65px;
            border-radius: 0;
            overflow: hidden;
            background-color: <?=$getTabs->background_color?>;
            box-shadow: 0 0 1px 0 rgb(52 46 173 / 25%), 0 15px 30px 0 rgb(52 46 173 / 10%);
            position: fixed;
            width: 100%;
            bottom: 0;
        }
        <?php } ?>
        .hd-menu-item .mdi {
            font-size: 0px;
            color: #555;
            padding-bottom: 3px;
        }
        .hd-menu-item .mdi img {
            width: 20px;
            height: 20px;
        }



        .hd-menu-item {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            flex-grow: 1;
            text-decoration: none;
        }
        .hd-menu-item:focus, .hd-menu-item:hover {
            outline: none;
        }
        .hd-menu-item:focus .hd-material-icons, .hd-menu-item:hover .hd-material-icons {
            font-family: "Material Icons";
            color:  <?=$getTabs->active_text_color?>;
        }
        .hd-menu-item:focus .hd-menu-item-label, .hd-menu-item:hover .hd-menu-item-label {
            color:  <?=$getTabs->active_text_color?>;
        }
        .hd-menu-item-label.active {
            color: <?=$getTabs->active_text_color?>;
            font-weight: bold;
        }
        .hd-material-icons {
            font-family: "Material Icons Outlined";
            display: block;
            margin-bottom: 4px;
            font-size: 26px;
            color: #aeabde;
            transition: 0.25s ease;
        }
        .hd-menu-item-label {
            display: block;
            font-size: 14px;
            color:  <?=$getTabs->deactive_text_color?>;
            transition: 0.25s ease;
            margin: 2px 0 0 0;
        }
        .test-iframe{
            width: 100%;
            height: 100%;
            border: none; /* حذف خطوط حاشیه iframe */
            overflow: hidden;
        }

    </style>
    <?php
    if(isset($_GET["mobile"]))
        echo '<div class="mobile-view-container">';
    $tabs=json_decode($getTabs->tabs);
    if(!empty($tabs)){
        ?>

        <?php
        if(!empty($_GET["hdw_mobile_hd_tabs"])){
            ?>
            <iframe src="<?=get_site_url();?>"  class="test-iframe"></iframe>
            <?php
        }
        ?>

        <div class="hd-container">
            <nav class="hd-menu">
                <?php
                $current_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http");
                $current_url .= "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

                foreach($tabs as $tab){
                    $is_active = $tab->icon_url === $current_url ? 'active' : '';
                    ?>
                    <a href="<?=$tab->icon_url?>" class="hd-menu-item">
                        <span class="mdi"><img src="<?=$tab->icon?>"></span>
                        <span class="hd-menu-item-label <?= $is_active ?>" ><?=esc_html($tab->text)?></span>
                    </a>
                    <?php
                }
                ?>
            </nav>
        </div>
        <?php
    }

    if (isset($_GET["mobile"]))
        echo '</div>';

}
?>



