<?php
/**
 * Frontend output for the AUX Search Block component
 * AUX documentation: https://aggieux.tamu.edu/?path=/story/navigation-search-block--example-search-block
 *
 * 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
$heading =
$background =
$style = null;


// Set component variables from user input
$style = aux_get_field('section_style');
$background = aux_get_field('section_background');
$heading = aux_get_field('search_block_heading');


// Setting style and alignment
$sectionClasses = ElementClassesService::buildClasses('section-wrap', '', $background);
$componentClasses = ElementClassesService::buildClasses('search-block', $style, $sectionClasses);

// Setting heading
$heading = HtmlService::formattedValue($heading, '<div class="heading-group heading-group--feature"><h2>%s</h2></div>');


// Output
// LINKS TO BE ADDED AT A LATER DATE
$output = <<<HTML
<section class="$sectionClasses">
  <div class="$componentClasses">
    $heading
    <div class="search">
      <form class="search__form">
        <label for="search" class="sr-only">Search</label>
        <input
          type="search"
          name="search"
          placeholder="placeholder"
          id="search"
          class="search__input"
        />

        <button type="submit" class="btn btn--primary btn--icon">
          Search
          <svg><use href="#aux_angles-right"></use></svg>
        </button>
      </form>
    </div>
  </div>
</section>
HTML;

echo $output;
