<?php
/**
 * Headline templates
 *
 * Building the custom headline that can be configured via post page.
 *
 * Themes that wishes to implement the Headline element
 * must copy this template to the theme folder and
 * call it as normal template would be eg. using get_template_part()
 * or get_sidebar().
 *
 * @author jason.xie@victheme.com
 */
?>
<?php

// Don't Proceed any further if no VicTheme Headline plugin is enabled.
if (!defined('VTCORE_HEADLINE_LOADED')) {
  return;
}

// Booting headline
$instance = VTCore_Headline_Utility::getHeadline();

if (!isset($instance['background'])) {
  $instance['background'] = FALSE;
}

// Non empty array will throw false true.
if (isset($instance['background']['video'])) {
  $instance['background']['video'] = array_filter($instance['background']['video']);
}

// User disabled the headline, bailing out!.
if (!VTCore_Headline_Utility::checkEnabled('general', $instance)) {
  return;
}

?>

<header id="headline" class="animated in startblank fadeIn vertical-center">

  <?php if (VTCore_Headline_Utility::checkEnabled('masking', $instance)) : ?>
    <div class="headline-mask"></div>
  <?php endif; ?>



  <?php if (isset($instance['background']['video']) && !empty($instance['background']['video'])) : ?>

    <!-- Video Background -->
    <div class="headline-background"
         data-mode="video-background"
         data-autoplay="true"
         data-loop="true"
         data-scale="true"
         data-position="<?php echo esc_attr(VTCore_Headline_Utility::getBackgroundPosition($instance)); ?>"

      <?php foreach ($instance['background']['video'] as $type => $id) : ?>
        data-<?php echo esc_attr($type); ?>="<?php echo esc_url(wp_get_attachment_url($id)); ?>"
      <?php endforeach; ?>

      <?php if (isset($instance['background']['image'])) : ?>
        data-poster="<?php echo esc_url(wp_get_attachment_url($instance['background']['image'])); ?>"
      <?php endif; ?>
      ></div>
  <?php endif; ?>


  <?php if (!isset($instance['background']['video']) || empty($instance['background']['video'])) : ?>
    <div class="headline-background"></div>
  <?php endif; ?>

  <div class="area">
    <div class="container-fluid clearfix">
      <div class="row">
        <div
          class="headline-left vertical-target animated in startblank fadeInLeft <?php echo esc_attr(VTCore_Headline_Utility::getHeadlineColumn($instance)); ?>"
          data-vertical-offset="0">

          <?php if (isset($instance['general']['title'])
            && !empty($instance['general']['title'])
          ) : ?>

            <h1 class="headline-title"
              <?php if (isset($instance['general']['title_color'])
                && !empty($instance['general']['title_color'])
              ) : ?>
                style="color:<?php echo esc_attr($instance['general']['title_color']); ?>"
              <?php endif; ?>
              >

              <?php echo wp_kses_post($instance['general']['title']); ?>

            </h1>
          <?php endif; ?>

          <?php if (isset($instance['general']['subtitle'])
            && !empty($instance['general']['subtitle'])
          ) : ?>
            <div class="headline-subtitle"
              <?php if (isset($instance['general']['subtitle_color'])
                && !empty($instance['general']['subtitle_color'])
              ) : ?>
                style="color:<?php echo esc_attr($instance['general']['subtitle_color']); ?>"
              <?php endif; ?>
              >

              <?php echo wp_kses_post($instance['general']['subtitle']); ?>
            </div>
          <?php endif; ?>


        </div>

        <?php if (isset($instance['items']) && !empty($instance['items'])) : ?>
          <div
            class="headline-right vertical-target animated in startblank fadeInRight <?php echo esc_attr(VTCore_Headline_Utility::getItemColumn($instance)); ?>"
            data-vertical-offset="0">

            <?php foreach ($instance['items'] as $delta => $data) : ?>

              <h2
                class="headline-title inline headline-elements-<?php echo esc_attr($delta); ?>">

                <?php if (isset($data['icon']) && $data['icon'] != 'none') : ?>
                  <?php echo VTCore_Headline_Utility::getItemIcon($data); ?>
                <?php endif ?>

                <?php if (isset($data['title']) && !empty($data['title'])) : ?>
                  <span class="headline-item-title"
                    <?php if (isset($data['title_color']) && !empty($data['title_color'])) : ?>
                      style="color: <?php echo esc_attr($data['title_color']); ?>"
                    <?php endif; ?>>

		            <?php echo wp_kses_post($data['title']); ?>
		        </span>
                <?php endif; ?>

                <?php if (isset($data['text']) && !empty($data['text'])) : ?>
                  <small class="headline-item-text"
                    <?php if (isset($data['text_color']) && !empty($data['text_color'])) : ?>
                      style="color: <?php echo esc_attr($data['text_color']); ?>"
                    <?php endif; ?>>

                    <?php echo wp_kses_post($data['text']); ?>
                  </small>
                <?php endif; ?>

              </h2>

            <?php endforeach; ?>
          </div>
        <?php endif; ?>
      </div>
    </div>
  </div>
</header>