<?php
/**
 * The component for displaying the footer default/legacy layout
 *
 * @global $options
 * @global $footer_background_color
 * @global $footer_color_contrast
 *
 * @package Reach
 */

 use Reach\App\Theme\ThemeStyles;
 use Reach\App\Attachments\Media;

 // get our color settings for this element
 $background_color               = ! empty( $options['footer_color'] ) ? $options['footer_color'] : '#000000';
 $color_contrast                 = ThemeStyles::colorLightOrDark( $background_color, 'dark', 'light' );
 $footer_widget_text_alignment   = ! empty( $options['footer_widget_text_align'] ) ? 'content-' . $options['footer_widget_text_align'] : 'content-left';
 $footer_widget_text_color       = ! empty( $options['footer_widget_text_color'] ) ? $options['footer_widget_text_color'] : '#ffffff';
 $logo                           = ! empty( $options['footer_logo'] ) ? Media::getAttachmentByID( $options['footer_logo'] ) : false;
 $logo_url                       = ! empty( $logo->url ) ?  $logo->url : AD_THEME_DIR_URI . 'assets/images/rl-logo.png';
 $logo_alt                       = ! empty( $logo->alt ) ?  $logo->alt : __( 'Powered by ReachLocal Logo', 'reach' );

?>

<div class="footer-layout-default">
  <footer class="footer <?php echo 'text--' . $color_contrast; ?>" role="contentinfo"
          style="background: <?php echo $background_color; ?>">
      <div class="container">

          <?php if ( is_active_sidebar( 'footer-sidebar' ) ) : ?>
              <div class="footer__flex--sidebar <?php echo $footer_widget_text_alignment; ?>"
                   style="color: <?php echo $footer_widget_text_color; ?>">
                  <?php dynamic_sidebar( 'footer-sidebar' ); ?>
              </div>
          <?php endif; ?>

          <?php
          // Loads the menu/footer.php template.
          get_template_part( 'menu/footer' );

          // Loads the menu/footer-utility.php template.
          get_template_part( 'menu/footer', 'utility' );
          ?>

          <div class="footer__bottom">
              <div class="footer__copyright">
                <div class="footer__copyright--text">
                  <?php
                  printf(
                      '&copy %1$s %2$s. ' . __( 'All Rights Reserved.', 'reach' ),
                      date( 'Y' ),
                      get_bloginfo( 'name' )
                  );
                  ?>
                </div>

                  <?php
                  // Loads the menu/footer-auxiliary.php template.
                  get_template_part( 'menu/footer', 'auxiliary' );
                  ?>

              </div>

              <?php
              if( empty( $options['hide_footer_logo'] ) ) {
                echo '<div class="footer__logo"><img src="' . esc_url( $logo_url ) . '" alt="' . $logo_alt . '"></div>';
              }

              // Loads the components/footer-socials.php template.
              get_template_part( 'components/footer', 'socials' );
              ?>
          </div>
      </div>
  </footer>
</div>
