{% extends "base.html" %}

{% block title %}Wyniki wyszukiwania{% if query %} - {{ query }}{% endif %} - Norda Biznes Hub{% endblock %}

{% block extra_css %}
<style>
    .search-header {
        margin-bottom: var(--spacing-xl);
    }

    .search-header h1 {
        font-size: var(--font-size-3xl);
        color: var(--text-primary);
        margin-bottom: var(--spacing-md);
    }

    .search-meta {
        color: var(--text-secondary);
        font-size: var(--font-size-lg);
    }

    .search-query {
        color: var(--primary);
        font-weight: 600;
    }

    /* Reuse company grid styles from index.html */
    .companies-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
        gap: var(--spacing-lg);
        margin-bottom: var(--spacing-2xl);
    }

    .company-card {
        background-color: var(--surface);
        border-radius: var(--radius-lg);
        padding: var(--spacing-lg);
        box-shadow: var(--shadow);
        transition: var(--transition);
        display: flex;
        flex-direction: column;
        height: 100%;
    }

    .company-card:hover {
        box-shadow: var(--shadow-lg);
        transform: translateY(-2px);
    }

    .company-header {
        margin-bottom: var(--spacing-md);
    }

    .company-category {
        display: inline-block;
        padding: var(--spacing-xs) var(--spacing-sm);
        background-color: var(--background);
        color: var(--text-secondary);
        font-size: var(--font-size-sm);
        border-radius: var(--radius);
        margin-bottom: var(--spacing-sm);
    }

    .company-name {
        font-size: var(--font-size-xl);
        font-weight: 600;
        color: var(--text-primary);
        margin-bottom: var(--spacing-sm);
        text-decoration: none;
        display: block;
    }

    .company-name:hover {
        color: var(--primary);
    }

    .company-description {
        color: var(--text-secondary);
        font-size: var(--font-size-sm);
        line-height: 1.6;
        margin-bottom: var(--spacing-md);
        flex: 1;
    }

    .company-contact {
        display: flex;
        flex-direction: column;
        gap: var(--spacing-xs);
        font-size: var(--font-size-sm);
        color: var(--text-secondary);
        padding-top: var(--spacing-md);
        border-top: 1px solid var(--border);
    }

    .company-contact-item {
        display: flex;
        align-items: center;
        gap: var(--spacing-sm);
    }

    .company-contact a {
        color: var(--primary);
        text-decoration: none;
    }

    .company-contact a:hover {
        text-decoration: underline;
    }

    .empty-state {
        text-align: center;
        padding: var(--spacing-2xl);
        background: white;
        border-radius: var(--radius-xl);
        box-shadow: var(--shadow);
    }

    .empty-state svg {
        opacity: 0.3;
        margin-bottom: var(--spacing-md);
    }

    .empty-state h2 {
        margin-bottom: var(--spacing-md);
    }

    @media (max-width: 768px) {
        .companies-grid {
            grid-template-columns: 1fr;
        }
    }
</style>
{% endblock %}

{% block content %}
<div class="search-header">
    <h1>Wyniki wyszukiwania</h1>
    {% if query %}
    <p class="search-meta">
        Znaleziono <strong>{{ companies|length }}</strong> firm dla zapytania: <span class="search-query">"{{ query }}"</span>
    </p>
    {% else %}
    <p class="search-meta">
        Znaleziono <strong>{{ companies|length }}</strong> firm
    </p>
    {% endif %}
</div>

{% if companies %}
<div class="companies-grid">
    {% for company in companies %}
    <div class="company-card">
        <div class="company-header">
            {% if company.category %}
            <span class="company-category">{{ company.category.name }}</span>
            {% endif %}
            <a href="{{ url_for('company_detail', company_id=company.id) }}" class="company-name">
                {{ company.name }}
            </a>
        </div>

        <div class="company-description">
            {{ company.description_short|truncate(150) if company.description_short else 'Brak opisu' }}
        </div>

        <div class="company-contact">
            {% if company.website %}
            <div class="company-contact-item">
                <svg width="16" height="16" fill="none" stroke="currentColor" stroke-width="2">
                    <circle cx="8" cy="8" r="7"/>
                    <path d="M1 8h14M8 1a11 11 0 0 1 0 14 11 11 0 0 1 0-14"/>
                </svg>
                <a href="{{ company.website }}" target="_blank" rel="noopener noreferrer">
                    {{ company.website|replace('https://', '')|replace('http://', '')|replace('www.', '')|truncate(30) }}
                </a>
            </div>
            {% endif %}

            {% if company.phone %}
            <div class="company-contact-item">
                <svg width="16" height="16" fill="none" stroke="currentColor" stroke-width="2">
                    <path d="M3 2a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h10a1 1 0 0 0 1-1V3a1 1 0 0 0-1-1H3z"/>
                </svg>
                <a href="tel:{{ company.phone }}">{{ company.phone }}</a>
            </div>
            {% endif %}

            {% if company.address_city %}
            <div class="company-contact-item">
                <svg width="16" height="16" fill="none" stroke="currentColor" stroke-width="2">
                    <path d="M8 2l6 6-6 6-6-6 6-6z"/>
                </svg>
                {{ company.address_city }}
            </div>
            {% endif %}
        </div>
    </div>
    {% endfor %}
</div>
{% else %}
<div class="empty-state">
    <svg width="120" height="120" viewBox="0 0 120 120" fill="none">
        <circle cx="60" cy="60" r="50" stroke="currentColor" stroke-width="4"/>
        <circle cx="50" cy="50" r="15" stroke="currentColor" stroke-width="4"/>
        <path d="M62 62l20 20" stroke="currentColor" stroke-width="4" stroke-linecap="round"/>
        <path d="M40 50h20M50 40v20" stroke="currentColor" stroke-width="3" stroke-linecap="round"/>
    </svg>
    <h2>Nie znaleziono wyników</h2>
    <p style="color: var(--text-secondary); margin-bottom: var(--spacing-lg);">
        {% if query %}
        Spróbuj użyć innych słów kluczowych lub skorzystaj z AI chatu aby znaleźć odpowiednią firmę.
        {% else %}
        Nie znaleziono firm spełniających kryteria wyszukiwania.
        {% endif %}
    </p>
    <div style="display: flex; gap: var(--spacing-md); justify-content: center;">
        <a href="{{ url_for('index') }}" class="btn btn-outline">Katalog firm</a>
        <a href="{{ url_for('chat') }}" class="btn btn-primary">Zapytaj AI</a>
    </div>
</div>
{% endif %}
{% endblock %}
