$def with (query, profile, formatted_query, result, ipa_pronunciation, cmu_pronunciation, definition, rhymes, web_results, code_projects, code_files, books)
$var breadcrumbs = ("search", "Search")

<style>
pre {
  font-size: .8em;
  width: 100%; }
.profile * {
  vertical-align: top; }
.profile_summary p {
  font-size: .8em;
  margin-bottom: 0; }
.profile form {
  margin-top: 1em; }
</style>

<form style="margin:1em 0">
    <input name=q value="$query"> <button>Search</button>
</form>

$if profile:
    <div class=profile
        style="display:grid;grid-gap:1em;grid-template-columns:20% auto;margin:2em 0 0 0">
    $if photos := profile.get("icon"):
        $if not isinstance(photos, list):
            $ photos = [photos]
        <img src=$photos[0]["url"] style=width:100%>
    <div>
    <p style=margin:0><big><strong>$profile["name"]</strong></big><br>
    $ urls = profile["url"]
    $if not isinstance(urls, list):
        $ urls = [urls]
    <small>
    $for url in urls:
        <a href=$url>$url</a>
        $if not loop.last:
            &bull;
    </small></p>
    <div class=profile_summary>$:profile["summary"]</div>
    $if "tag" in profile:
        <div style=font-size:.8em>
        $for tag in profile["tag"]:
            $tag["name"]
            $if not loop.last:
                &bull;
        </div>
    $if tx.user.is_owner:
        <form action=/people method=post style=text-align:right>
            <input type=hidden name=identifier value="$query">
            <button>Follow</button>
        </form>
    </div>
    </div>
    <details>
    <summary>Full Summary</summary>
    <pre>$pformat(profile)</pre>
    </details>

$if result:
    <pre>$formatted_query<br>
    <big>$result</big></pre>

$if definition:
    <p><strong title="$cmu_pronunciation">$ipa_pronunciation</strong>, $definition<br>
    <small>rhymes: $", ".join(rhymes)</small></p>

<h2>Web</h2>
$if web_results:
    <ul>
    $for result in web_results:
        <li><a href="$webagt.uri(result.element.attrib['href'])['uddg'][0]">$result.text</a></li>
    </ul>
$else:
    <p>0 results</p>

<h2>Code</h2>
$if code_projects.most_common()[0][0]:
    <ul>
    $for project, file_count in code_projects.most_common():
        <li><a href=$tx.origin/code/projects/$project>$project</a>
        $ files = code_files[project]
        <small>\
        $for code_file in sorted(files)[:3]:
            <a href=$tx.origin/code/projects/$project/files/$code_file
            style=color:#777>$code_file</a>\
            $if not loop.last:
                , \
        $if len(files) > 3:
             <em>and $(file_count - 3) more</em>
        </small></li>
    </ul>
$else:
    <p>0 results</p>

$# <h2>Books</h2>
$# <p>found $books.pop("found") document out of $books.pop("out_of"),
$# search took $books.pop("search_time_ms")ms</p>
$# <ul>
$# $for book in books.pop("hits"):
$#     <li><p>$book.pop("document")</p>
$#     <p>$book.pop("highlights")</p>
$#     <pre>$pformat(book)</pre>
$#     </li>
$# </ul>
$# XXX <pre>$pformat(books)</pre>
