<?php
/**
 * Frontend output for the AUX Sign-Up Feature component
 * AUX documentation: https://aggieux.tamu.edu/?path=/docs/components-sign-up-feature-about-sign-up-features--docs
 *
 * Outline:
 * 1. Set variables to null
 * 2. Get fields from the post, if they have values, wrap in html
 * 3. Build the component html
 * 4. Sanitize and output
 *
 * @author Hailey Sanders
 * @since 1.0.0
 */

use WP_AUX\Entities\AuxFramework\Partials\HeadingGroupEntity;
use WP_AUX\Entities\AuxFramework\Partials\ImageEntity;
use WP_AUX\Services\AuxFramework\ElementClassesService;
use WP_AUX\Services\HtmlService;

// Set variables to null
$style = null;


// Set component variables from user input
$style = aux_get_field('section_style');
$alignment = aux_get_field('signup_feature_alignment');
$heading = aux_get_field('signup_feature_heading');
$description = aux_get_field('signup_feature_desc');
$image = aux_get_field('signup_feature_image');
$formId = aux_get_field('signup_feature_id');


// Setting style and alignment
$componentClasses = ElementClassesService::buildClasses('signup-feature', $style);
if (in_array($alignment, ['left', 'right'])) {
    $componentClasses->addModifier($alignment);
}

// Setting image
// if there is an image, grab the url
if ($image) {
    $image = aux_get_field('signup_feature_image')['url'];
}

// Setting heading
$heading = HtmlService::formattedValue($heading, '<h2>%s</h2>');

// Setting description
$description = HtmlService::formattedValue($description, '<p>%s</p>');


// <div class="heading-group heading-group--feature">
// $heading
// </div>
// $description
// <form class="email" id="" action="">
// <label class="sr-only" for="signup">Enter your email address</label>
// <input
//   type="email"
//   id="signup"
//   name="signup"
//   placeholder="email@tamu.edu"
// />
// <button type="submit" class="btn btn--primary">Subscribe</button>
// </form>


$shortcode = do_shortcode('[gravityform id="' . $formId . '"]');

// Output
// Form button destination to be included at a later date
$output = <<<HTML
<section
  class="$componentClasses"
  style="background-image:url($image)"
>
  <div class="signup-feature__container">
    <div class="signup-feature__content">
      $shortcode
    </div>
  </div>
</section>
HTML;

echo $output;
