<div class="search-component">
    <div class="search-header">
        <div class="search-input-group">
            <input
                type="text"
                name="query"
                class="search-input"
                placeholder="{{searchPlaceholder}}"
                value="{{query}}"
                data-live-action="search"
                data-live-debounce="300"
            />
            <if condition="showClearButton">
                <button
                    class="search-clear"
                    data-live-action="clear"
                    aria-label="Clear search"
                >
                    ✕
                </button>
            </if>
        </div>

        <div class="search-filters">
            <for items="targetOptions" as="option">
                <button
                    class="filter-btn {{option.isActive ? 'active' : ''}}"
                    data-live-action="changeTarget"
                    data-param-target="{{option.value}}"
                >
                    {{option.label}}
                </button>
            </for>
        </div>
    </div>

    <if condition="hasQuery">
        <div class="search-stats">
            <span class="result-count">{{resultText}}</span>
            <if condition="showPerformanceMetric">
                <span class="execution-time">{{execution_time_ms}}ms</span>
            </if>
        </div>

        <div class="search-results">
            <if condition="hasResults">
                <!-- Users Results -->
                <if condition="results.users">
                    <div class="result-category">
                        <h3 class="category-title">Users</h3>
                        <div class="result-list">
                            <for items="results.users" as="user">
                                <div class="result-item user-result">
                                    <div class="result-icon">👤</div>
                                    <div class="result-content">
                                        <div class="result-title">{{user.name}}</div>
                                        <div class="result-meta">{{user.email}} • {{user.role}}</div>
                                    </div>
                                </div>
                            </for>
                        </div>
                    </div>
                </if>

                <!-- Products Results -->
                <if condition="results.products">
                    <div class="result-category">
                        <h3 class="category-title">Products</h3>
                        <div class="result-list">
                            <for items="results.products" as="product">
                                <div class="result-item product-result">
                                    <div class="result-icon">📦</div>
                                    <div class="result-content">
                                        <div class="result-title">{{product.title}}</div>
                                        <div class="result-meta">{{product.price}} • {{product.category}}</div>
                                    </div>
                                </div>
                            </for>
                        </div>
                    </div>
                </if>

                <!-- Articles Results -->
                <if condition="results.articles">
                    <div class="result-category">
                        <h3 class="category-title">Articles</h3>
                        <div class="result-list">
                            <for items="results.articles" as="article">
                                <div class="result-item article-result">
                                    <div class="result-icon">📄</div>
                                    <div class="result-content">
                                        <div class="result-title">{{article.title}}</div>
                                        <div class="result-meta">by {{article.author}} • {{article.date}}</div>
                                    </div>
                                </div>
                            </for>
                        </div>
                    </div>
                </if>
            </if>

            <if condition="!hasResults">
                <div class="no-results">
                    <div class="no-results-icon">🔍</div>
                    <div class="no-results-text">No results found for "{{query}}"</div>
                    <div class="no-results-hint">Try different keywords or search in a specific category</div>
                </div>
            </if>
        </div>
    </if>

    <if condition="!hasQuery">
        <div class="search-empty">
            <div class="empty-icon">🔎</div>
            <div class="empty-text">{{emptyStateMessage}}</div>
            <div class="empty-hint">Search across users, products, and articles</div>
        </div>
    </if>
</div>

<style>
.search-component {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.search-header {
    margin-bottom: 1.5rem;
}

.search-input-group {
    position: relative;
    margin-bottom: 1rem;
}

.search-input {
    width: 100%;
    padding: 0.75rem 1rem;
    padding-right: 3rem;
    font-size: 1rem;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    transition: border-color 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: #2196F3;
}

.search-clear {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: #f5f5f5;
    border: none;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.search-clear:hover {
    background: #e0e0e0;
}

.search-filters {
    display: flex;
    gap: 0.5rem;
}

.filter-btn {
    padding: 0.5rem 1rem;
    border: 1px solid #e0e0e0;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.filter-btn:hover {
    background: #f5f5f5;
}

.filter-btn.active {
    background: #2196F3;
    color: white;
    border-color: #2196F3;
}

.search-stats {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid #e0e0e0;
    margin-bottom: 1rem;
    font-size: 0.875rem;
    color: #666;
}

.result-count {
    font-weight: 600;
}

.execution-time {
    color: #999;
}

.result-category {
    margin-bottom: 1.5rem;
}

.category-title {
    font-size: 0.875rem;
    text-transform: uppercase;
    color: #666;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.result-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.result-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    background: #f9f9f9;
    border-radius: 6px;
    transition: background 0.2s;
    cursor: pointer;
}

.result-item:hover {
    background: #f0f0f0;
}

.result-icon {
    font-size: 1.5rem;
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    border-radius: 50%;
}

.result-content {
    flex: 1;
}

.result-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.result-meta {
    font-size: 0.875rem;
    color: #666;
}

.no-results,
.search-empty {
    text-align: center;
    padding: 3rem 1rem;
}

.no-results-icon,
.empty-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.no-results-text,
.empty-text {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.no-results-hint,
.empty-hint {
    color: #666;
    font-size: 0.875rem;
}
</style>
