<?php declare(strict_types=1); ?>

<!-- Advanced search form -->
<form class="form-horizontal" action="search.php" method="post" role="form" accept-charset="UTF-8">
    
    <!-- Search terms -->
    <div class="col-md-6 offset-md-3 form-group input-group">
      <input type="text" class="form-control is-valid" name="searchTerms" id="searchTerms" 
          <?php if (isset($terms) && !empty($terms)): ?>
            value="<?php echo htmlspecialchars($terms, ENT_QUOTES, "UTF-8", false); ?>"
          <?php else: ?>
            placeholder="<?php echo TFISH_SEARCH_ENTER_TERMS; ?>" 
          <?php endif; ?>				   
      required>
    </div>
    
    <!-- Search type -->
    <div class="col-md-6 offset-md-3 form-group input-group">
      <select class="form-control custom-select is-valid" name="searchType" id="searchType">
        <option <?php if (isset($type) && $type === "AND") echo "selected"; ?> value="AND"><?php echo TFISH_SEARCH_ALL; ?></option>
        <option <?php if (isset($type) && $type === "OR") echo "selected"; ?> value="OR"><?php echo TFISH_SEARCH_ANY; ?></option>
        <option <?php if (isset($type) && $type === "exact") echo "selected"; ?> value="exact"><?php echo TFISH_SEARCH_EXACT; ?></option>	
        </select>
    </div>
    
    <!-- Submit -->
    <div class="form-group col-md-6 offset-md-3 clearfix">
        <input type="hidden" name="op" value="search" />
        <button type="submit" class="btn btn-primary float-left"><?php echo TFISH_SEARCH ?></button>
    </div>
    
</form>

<?php if (isset($searchResults)): ?>
<!-- Search results -->
<hr>
<div class="text-left">
    <?php if (!empty($searchResults)): ?>
    <h2><?php echo $tfValidator->escapeForXss($resultsCount) . ' ' . TFISH_SEARCH_RESULTS . ':'; ?></h2><hr>
    <?php foreach ($searchResults as $key => $object): ?>
    <div class="clearfix">
        <h3><a href="<?php echo $object->getUrl($targetFileName); ?>"><?php echo $object->icon; ?> <?php echo $object->escapeForXss('title'); ?></a></h3>
        <?php if ($object->image): ?>
        <div class="float-left">
            <figure class="figure-left">
                <a href="<?php echo $object->getUrl($targetFileName); ?>">
                    <img class="img-responsive" src="<?php echo $object->getCachedImage(100); ?>" 
                         <?php if ($object->caption): ?>title="<?php echo $object->escapeForXss('caption'); ?>" 
                         alt="<?php echo $object->escapeForXss('caption'); ?>"<?php endif; ?> />
                </a>
            </figure>
        </div>
        <?php endif; ?>
        <?php echo $object->escapeForXss('teaser'); ?>
    </div>
    <?php endforeach; ?>
    <?php else: ?>
    <h2><?php echo TFISH_SEARCH_NO_RESULTS; ?></h2><hr>
    <?php endif; ?>
</div>
<?php endif; ?>