{% import 'macros/form.html' as form %}

<div class="d-flex mb-3">
    <a class="me-3" href="https://datashades.github.io/ckanext-selfinfo/selftools/categories/datastore/" target="_blank">
        {{ _('Documentation') }}
    </a>
    <a class="me-3" href="https://docs.ckan.org/en/latest/maintaining/datastore.html#the-data-api" target="_blank">
        {{ _('Datastore API') }}
    </a>
</div>

<div class="">
    <form class="form-control border-0 shadow-none p-0" hx-post="{{ h.url_for('selftools_htmx.selftools_datastore_query') }}" hx-trigger="submit" hx-target="#datastore-query-resp" hx-swap="innerHTML">
        <div class="info-block mb-3">
            <i class="fa fa-info-circle"></i>
            {{ _('Search Datastore tables by resource ID (table name). Leave empty to show all tables.') }}
        </div>

        <div class="mb-3">
            {{ form.input('q', label=_('Search by Resource ID'), error='') }}
        </div>

        <div class="mb-3">
            <div class="form-check">
                <input class="form-check-input" type="checkbox" name="orphaned_only" id="orphaned_only" value="true">
                <label class="form-check-label" for="orphaned_only">
                    <i class="fa fa-exclamation-triangle text-warning"></i>
                    {{ _('Show only orphaned tables (without CKAN resources)') }}
                </label>
                <div class="form-text text-muted small">
                    <i class="fa fa-clock-o"></i>
                    {{ _('Note: With large number of tables, this may take some time to process.') }}
                </div>
            </div>
        </div>

        <div class="mt-3 mb-3">
            <label for="limit">{{ _('Limit') }}</label>
            <input type="number" name="limit" min="1" max="{{ h.get_operations_limit() }}" step="1" value="100" class="" required />
        </div>

        <button type="submit" class="btn btn-dark mt-2">{{ _('Search') }}</button>
    </form>
</div>

<div id="datastore-query-resp" class="bg-light p-3 border rounded mt-3">
    <p class="text-muted">{{ _('Enter search term or click "Search" to view datastore tables...') }}</p>
</div>
