<?php

$pageURL = get_the_ID();

$siteMainMenuItemLabel = array();
$siteMainMenuItemURL = array();
$itemClass = array();
$counter=0;

if(have_rows('siteMainMenuItems',CONST_CUSTOM_PAGE_ID)){
  while(have_rows('siteMainMenuItems',CONST_CUSTOM_PAGE_ID)){
      the_row();

      $siteMainMenuItemLabel[] = get_sub_field('siteMainMenuItemLabel',CONST_CUSTOM_PAGE_ID);
      $siteMainMenuItemURL[] = get_the_permalink(get_sub_field('siteMainMenuItemURL',CONST_CUSTOM_PAGE_ID));

      $siteSubMenuItemLabel[$counter] = array();
      $siteSubMenuItemURL[$counter] = array();
      $subItemClass[$counter] = array();

      $temp_main_class = "";
      
      if($pageURL == get_sub_field('siteMainMenuItemURL',CONST_CUSTOM_PAGE_ID)){
        $temp_main_class = "active";
      }

      while(have_rows('siteSubMenuItems',CONST_CUSTOM_PAGE_ID)){
        the_row();

        $siteSubMenuItemLabel[$counter][] = get_sub_field('siteSubMenuItemLabel',CONST_CUSTOM_PAGE_ID);
        $temp_value = "";
        if(get_sub_field('siteSubMenuItemAnchor',CONST_CUSTOM_PAGE_ID)){
          $temp_value = "#".get_sub_field('siteSubMenuItemAnchor',CONST_CUSTOM_PAGE_ID);
        }
        $siteSubMenuItemURL[$counter][] = get_the_permalink(get_sub_field('siteSubMenuItemURL',CONST_CUSTOM_PAGE_ID)).$temp_value;

        $temp_sub_class = "";
      
        if($pageURL == get_sub_field('siteSubMenuItemURL',CONST_CUSTOM_PAGE_ID)){
          $temp_sub_class = "active";
          $temp_main_class = "active";
        }

        $subItemClass[$counter][] = $temp_sub_class;

      }
      
      $itemClass[] = $temp_main_class;
      $counter++;
    }
}

$socialIconLabel = array();

if(have_rows('socialIconListing',CONST_CUSTOM_PAGE_ID)){
    while(have_rows('socialIconListing',CONST_CUSTOM_PAGE_ID)){
        the_row();
        $socialIconLabel[] = get_sub_field('socialIconLabel',CONST_CUSTOM_PAGE_ID);
        $socialURL[] = get_sub_field('socialIconURL',CONST_CUSTOM_PAGE_ID);

    }
}

?>

<nav id="mobile-menu" class="dark style1" data-behaviour="thb-default" data-animation="style1">
<div class="home-icon">
    <a href="<?php echo get_site_url();?>" target="" class="" data-content="Create IT" data-menubg="">
        <svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 576 512"><!--! Font Awesome Free 6.4.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. --><path d="M575.8 255.5c0 18-15 32.1-32 32.1h-32l.7 160.2c0 2.7-.2 5.4-.5 8.1V472c0 22.1-17.9 40-40 40H456c-1.1 0-2.2 0-3.3-.1c-1.4 .1-2.8 .1-4.2 .1H416 392c-22.1 0-40-17.9-40-40V448 384c0-17.7-14.3-32-32-32H256c-17.7 0-32 14.3-32 32v64 24c0 22.1-17.9 40-40 40H160 128.1c-1.5 0-3-.1-4.5-.2c-1.2 .1-2.4 .2-3.6 .2H104c-22.1 0-40-17.9-40-40V360c0-.9 0-1.9 .1-2.8V287.6H32c-18 0-32-14-32-32.1c0-9 3-17 10-24L266.4 8c7-7 15-8 22-8s15 2 21 7L564.8 231.5c8 7 12 15 11 24z"></path></svg>
    </a>
</div>
 
    <div class="menubg-placeholder"></div>

    <div class="custom_scroll" id="menu-scroll">
        <div class="mobile-menu-container">
            <div class="mobile-menu-top">
                <ul id="menu-navigation" class="thb-mobile-menu">
                    <?php
                    for($counter=0; $counter < sizeof($siteMainMenuItemLabel); $counter++ ){
                    ?>
                    <li>
                        <div class="link_container">
                            <div class="link_inner">
                                <a href="<?= $siteMainMenuItemURL[$counter]; ?>" target="" class="<?= $itemClass[$counter]; ?>" data-content="Case Studies"
                                   data-menubg="">
                                    <?= $siteMainMenuItemLabel[$counter]; ?></a>
                            </div>
                        </div>
                        <?php
                        if(sizeof($siteSubMenuItemLabel[$counter]) > 0 ){
                        ?>
                        <ul class="sublink_container">
                            <?php
                            for($innercounter=0; $innercounter < sizeof($siteSubMenuItemLabel[$counter]); $innercounter++ ){
                            ?>
                            <li>
                                <div class="link_container">
                                    <div class="link_inner">
                                        <a href="<?= $siteSubMenuItemURL[$counter][$innercounter]; ?>" class="<?= $subItemClass[$counter][$innercounter]; ?>">
                                             <?= $siteSubMenuItemLabel[$counter][$innercounter]; ?>                                 </a>
                                    </div>
                                </div>
                            </li>

                                <?php
                            }
                            ?>
                        </ul>
                            <?php
                        }
                        ?>
                    </li>
                        <?php
                    }
                    ?>
                </ul>
            </div>
        </div>
    </div>
</nav>