<div
    class="tabs-component"
    data-live-component="{{componentId}}"
    data-state='{{stateJson}}'
>
    <!-- Tab Navigation -->
    <div class="tabs-nav">
        <div class="tabs-list">
            <for items="prepared_tabs" as="tab">
                <button
                    class="{{tab.css_class}}"
                    data-live-action="switchTab"
                    data-param-tab-id="{{tab.id}}"
                    title="{{tab.title}}"
                >
                    <span class="tab-title">{{tab.title}}</span>
                    <button
                        class="tab-close"
                        data-live-action="closeTab"
                        data-param-tab-id="{{tab.id}}"
                        onclick="event.stopPropagation()"
                        title="Tab schließen"
                        if="tab.is_closable"
                    >
                        ✕
                    </button>
                </button>
            </for>
        </div>

        <button
            class="tab-add-button"
            data-live-action="addTab"
            data-param-title="Neuer Tab"
            data-param-content="<p>Neuer Tab-Inhalt</p>"
            title="Neuen Tab hinzufügen"
            if="show_add_button"
        >
            +
        </button>
    </div>

    <!-- Tab Content -->
    <div class="tabs-content">
        <for items="prepared_tabs" as="tab">
            <div class="{{tab.pane_class}}" data-tab-id="{{tab.id}}">
                {{{tab.content}}}
            </div>
        </for>

        <div class="tabs-empty" if="!has_tabs">
            <div class="empty-icon">📑</div>
            <div class="empty-text">Keine Tabs vorhanden</div>
            <button
                class="btn btn-primary"
                data-live-action="addTab"
                data-param-title="Erster Tab"
                data-param-content="<p>Willkommen beim ersten Tab!</p>"
                if="allow_add"
            >
                Ersten Tab erstellen
            </button>
        </div>
    </div>

    <!-- Error Display -->
    <div class="tabs-error" if="has_error">
        ⚠️ {{error}}
    </div>
</div>

<style>
.tabs-component {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Tab Navigation */
.tabs-nav {
    display: flex;
    align-items: center;
    background: #f9f9f9;
    border-bottom: 2px solid #e0e0e0;
    padding: 0.5rem;
    gap: 0.5rem;
}

.tabs-list {
    display: flex;
    gap: 0.25rem;
    flex: 1;
    overflow-x: auto;
    scrollbar-width: thin;
}

.tabs-list::-webkit-scrollbar {
    height: 4px;
}

.tabs-list::-webkit-scrollbar-track {
    background: transparent;
}

.tabs-list::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 2px;
}

/* Tab Button */
.tab-button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 6px 6px 0 0;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    position: relative;
    color: #666;
    font-weight: 500;
    font-size: 0.875rem;
}

.tab-button:hover {
    background: #f5f5f5;
    color: #333;
}

.tab-button.active {
    background: white;
    border-bottom-color: white;
    color: #2196F3;
    border-color: #2196F3;
    border-bottom: 2px solid white;
    margin-bottom: -2px;
    z-index: 1;
}

.tab-title {
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}

/* Tab Close Button */
.tab-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    background: transparent;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    color: #999;
    font-size: 0.875rem;
    transition: all 0.2s;
    padding: 0;
}

.tab-close:hover {
    background: rgba(244, 67, 54, 0.1);
    color: #f44336;
}

/* Add Tab Button */
.tab-add-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: #2196F3;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.25rem;
    font-weight: bold;
    transition: all 0.2s;
    flex-shrink: 0;
}

.tab-add-button:hover {
    background: #1976D2;
    transform: scale(1.05);
}

.tab-add-button:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

/* Tab Content */
.tabs-content {
    padding: 1.5rem;
    min-height: 200px;
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Empty State */
.tabs-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: #999;
}

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

.empty-text {
    font-size: 1rem;
    margin-bottom: 1.5rem;
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-primary {
    background: #2196F3;
    color: white;
}

.btn-primary:hover {
    background: #1976D2;
}

/* Error Display */
.tabs-error {
    background: #ffebee;
    color: #c62828;
    padding: 0.75rem 1rem;
    margin: 1rem;
    border-radius: 4px;
    border-left: 4px solid #f44336;
    animation: slideDown 0.3s ease-in-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Tab Styles Variants */
.tabs-component[data-style="pills"] .tab-button {
    border-radius: 20px;
    margin-bottom: 0;
}

.tabs-component[data-style="pills"] .tab-button.active {
    background: #2196F3;
    color: white;
    border-color: #2196F3;
}

.tabs-component[data-style="underline"] .tabs-nav {
    background: transparent;
    border-bottom: 1px solid #e0e0e0;
}

.tabs-component[data-style="underline"] .tab-button {
    background: transparent;
    border: none;
    border-radius: 0;
    border-bottom: 3px solid transparent;
    margin-bottom: 0;
}

.tabs-component[data-style="underline"] .tab-button:hover {
    background: transparent;
    border-bottom-color: #ccc;
}

.tabs-component[data-style="underline"] .tab-button.active {
    background: transparent;
    border-bottom-color: #2196F3;
}

/* Responsive */
@media (max-width: 768px) {
    .tabs-nav {
        padding: 0.25rem;
    }

    .tab-button {
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
    }

    .tab-title {
        max-width: 100px;
    }

    .tabs-content {
        padding: 1rem;
    }

    .tab-add-button {
        width: 32px;
        height: 32px;
        font-size: 1.125rem;
    }
}
</style>
