// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.2 OR LicenseRef-Slint-commercial

import { TabBarBase } from "../common/tabwidget-base.slint";

export component TabWidgetImpl inherits NativeTabWidget { }

export component TabImpl inherits NativeTab {
    accessible-role: tab;
    accessible-label <=> root.title;
}

export component TabBarImpl inherits TabBarBase {
    // injected properties:
    // The currently focused tab
    in-out property <int> current-focused: i-focus-scope.has-focus ? root.current : -1;

    accessible-role: tab-list;
    accessible-delegate-focus: root.current;

    Rectangle {
        // The breeze style draws outside of the tab bar, which is clip by default with Qt
        clip: true;

        HorizontalLayout {
            // Qt renders Tabs next to each other and renders "spacing" as part of the tab itself
            spacing: 0px;
            alignment: NativeStyleMetrics.tab-bar-alignment;
            @children
        }
    }

    i-focus-scope := FocusScope {
        x: 0;
        // Do not react on clicks
        width: 0px;

        key-pressed(event) => {
            if (event.text == Key.LeftArrow) {
                root.current = root.previous-tab();
                return accept;
            }
            if (event.text == Key.RightArrow) {
                root.current = root.next-tab();
                return accept;
            }
            return reject;
        }
    }
}

export component TabWidget inherits TabWidget { }
