<?php

/**
 * Footer Block Template.
 *
 * @param   array $block The block settings and attributes.
 * @param   string $content The block inner HTML (empty).
 * @param   bool $is_preview True during backend preview render.
 * @param   int $post_id The post ID the block is rendering content against.
 *          This is either the post ID currently being displayed inside a query loop,
 *          or the post ID of the post hosting this block.
 * @param   array $context The context provided to the block by the post or it's parent block.
 */

// Support custom "anchor" values.
$anchor = '';
if (! empty($block['anchor'])) {
  $anchor = 'id="' . esc_attr($block['anchor']) . '" ';
}

// Load values and assign defaults.
$class_name = 'olympus-footer';
$styles = '';

$logo_footer = get_field('logo_footer', 'option');
$background_color = get_field('background_color', 'option');
$custom_background_color = get_field('custom_background_color', 'option');
$text_color = get_field('text_color', 'option');

$class_name .= ' background-color-' . $background_color;
$class_name .= ' text-color-' . $text_color;

if ($custom_background_color) {
  $styles .= 'background:' . $custom_background_color . ';';
}

$wrapper_attributes = get_block_wrapper_attributes(
  [
    'class' => $class_name,
    'style' => $styles
  ]
);
?>
<div <?php echo $anchor ?><?php echo $wrapper_attributes; ?>>
  <div class="olympus-footer-wrapper">
    <div class="olympus-footer-col">
      <a href="<?php echo get_site_url(); ?>" class="olympus-footer-logo">
        <?php if ($logo_footer): ?>
          <img src="<?php echo $logo_footer['url'] ?>" alt="<?php echo $logo_footer['alt'] ?>" />
        <?php endif; ?>
      </a>
      <?php
      if (have_rows('general_contact_info', 'option')):
        while (have_rows('general_contact_info', 'option')) : the_row();
          $icon = get_sub_field('icon');
          if ($icon) {
            $icon = file_get_contents(get_template_directory() . '/admin/img/acf/' . $icon . '.svg');
          }
          $link = get_sub_field('link');
          if ($link):
      ?>
            <a href="<?php $link['url'] ?>" href="<?php echo $link['target'] ?>" class="olympus-footer-icon-link">
              <div class="olympus-footer-link-icon"><?php echo $icon ?></div>
              <span><?php echo $link['title'] ?></span>
            </a>
      <?php
          endif;
        endwhile;
      endif;
      ?>
      <div class="olympus-footer-socials">
        <?php
        if (have_rows('social_icons', 'option')):
          while (have_rows('social_icons', 'option')) : the_row();
            $icon = get_sub_field('icon');
            if ($icon) {
              $icon = file_get_contents(get_template_directory() . '/admin/img/acf/' . $icon . '.svg');
            }
            $link = get_sub_field('link');
            if ($link):
        ?>
              <a href="<?php $link['url'] ?>" href="<?php echo $link['target'] ?>" class="olympus-footer-icon-link">
                <div class="olympus-footer-link-icon"><?php echo $icon ?></div>
              </a>
        <?php
            endif;
          endwhile;
        endif;
        ?>
      </div>
    </div>
    <?php
    if (have_rows('f_menu_cols', 'option')):
      while (have_rows('f_menu_cols', 'option')) : the_row();
    ?>
        <div class="olympus-footer-col">
          <?php
          if (have_rows('f_menu', 'option')):
            while (have_rows('f_menu', 'option')) : the_row();
              $item = get_sub_field('item');
              if ($item):
          ?>
                <a href="<?php echo $item['url'] ?>" class="olympus-footer-link"><?php echo $item['title'] ?></a>
          <?php
              endif;
            endwhile;
          endif;
          ?>
        </div>
    <?php
      endwhile;
    endif;
    ?>
  </div>
</div>
<?php if (get_field('floating_dock_script', 'option')): ?>
  <?php echo get_field('floating_dock_script', 'option') ?>
<?php endif; ?>