{% extends "base.html" %}

{% block title %}{{ file.filename }}{% endblock %}

{% block content %}
<h1>{{ file.filename }}</h1>

{% if saved %}
<p style="color: green; font-weight: bold;">Search text saved.</p>
{% endif %}

<table>
    <tr><th>File ID</th><td>{{ file.id }}</td></tr>
    <tr><th>Filename</th><td>{{ file.filename }}</td></tr>
    <tr><th>Content Type</th><td>{{ file.content_type or "unknown" }}</td></tr>
    <tr><th>Size</th><td>{{ file.size }} bytes</td></tr>
    {% if file.content_hash %}
    <tr><th>Content Hash</th><td>{{ file.content_hash }}</td></tr>
    {% endif %}
    {% if file.uploaded_by %}
    <tr><th>Uploaded By</th><td>{{ file.uploaded_by }}</td></tr>
    {% endif %}
    <tr><th>Created</th><td>{{ file.created_at }}</td></tr>
</table>

{% if file.content_type and file.content_type.startswith("image/") %}
<p><img src="/-/files/{{ file.id }}/download" alt="{{ file.filename }}" style="max-width: 600px;"></p>
{% endif %}

<p><a href="/-/files/{{ file.id }}/download">Download {{ file.filename }}</a></p>

<h2>Search text</h2>

{% if can_edit %}
<form method="post" action="/-/files/{{ file.id }}">
    <p>
        <textarea name="search_text" rows="4" cols="60" placeholder="Add searchable text for this file...">{{ file.search_text or "" }}</textarea>
    </p>
    <p><button type="submit">Save</button></p>
</form>
{% elif file.search_text %}
<p>{{ file.search_text }}</p>
{% else %}
<p><em>No search text set.</em></p>
{% endif %}
{% endblock %}
