<?php

namespace Transvision;

// RTL support
$direction1 = RTLSupport::getDirection($source_locale);
$direction2 = RTLSupport::getDirection($locale);
if ($url['path'] == '3locales') {
    $direction3 = RTLSupport::getDirection($locale2);
    $extra_column_header = "<th>{$locale2}</th>";
} else {
    $extra_column_header = '';
}
$entities = ShowResults::searchEntities($tmx_source, $search->getRegex());
// Display a search hint for the closest string we have if we have no search results
if (count($entities) == 0) {
    $merged_strings = [];
    $best_matches = Strings::getSimilar($initial_search, array_keys($tmx_source), 3);
    include VIEWS . 'results_similar.php';
    return;
}
        // We have results, we won't display search suggestions but search results
        $search_yields_results = true;
        $search_id = strtolower(str_replace('-', '', $key));
        $message_count = $real_search_results > $limit_results ? "<span class=\"results_count_{$search_id}\">{$limit_results} results</span> out of {$real_search_results}" : "<span class=\"results_count_{$search_id}\">" . Utils::pluralize(count($search_results), 'result') . '</span>';
        $output[$key] = "<h2>Displaying {$message_count} for the string " . "<span class=\"searchedTerm\">{$initial_search_decoded}</span> in {$key}:</h2>";
        $output[$key] .= ShowResults::resultsTable($search_id, $search_results, $initial_search, $source_locale, $locale, $check);
    } else {
        $output[$key] = "<h2>No matching results for the string " . "<span class=\"searchedTerm\">{$initial_search_decoded}</span>" . " for the locale {$key}</h2>";
    }
}
// Remove duplicated components
$components = array_unique($components);
// Display a search hint for the closest string we have if we have no search results
if (!$search_yields_results) {
    $merged_strings = [];
    foreach ($data as $key => $values) {
        $merged_strings = array_merge($merged_strings, array_values($values));
    }
    $best_matches = Strings::getSimilar($initial_search, $merged_strings, 3);
    include VIEWS . 'results_similar.php';
    return;
} else {
    if (in_array($check['repo'], $desktop_repos)) {
        // Build logic to filter components
        $javascript_include[] = '/js/component_filter.js';
        $filter_block = '';
        foreach ($components as $value) {
            $filter_block .= " <a href='#{$value}' id='{$value}' class='filter'>{$value}</a>";
        }
    }
}