import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

ColumnLayout {
    property bool onSubPage: false

    height: parent.height
    spacing: 0
    z: 3

    Component.onCompleted: {
        onSubPage = Qt.binding(() => contentStack.depth > 1);
    }

    anchors {
        left: parent.left
        top: parent.top
    }
    ButtonGroup {
        id: mainNav

    }
    BarButton {
        ButtonGroup.group: mainNav
        icon.source: "qrc:/images/Square3Stack3D-Outline.svg"
        target: "/Gui/Dashboard.qml"
        text: qsTr("Dashboard")
        visible: !onSubPage
    }
    BarButton {
        ButtonGroup.group: mainNav
        icon.source: "qrc:/images/UserGroup-Outline.svg"
        target: "/Gui/CustomersTable.qml"
        text: qsTr("Kunden")
        visible: !onSubPage
    }
    BarButton {
        ButtonGroup.group: mainNav
        icon.source: "qrc:/images/BuildingOffice2-Outline.svg"
        target: "/Gui/ObjectsTable.qml"
        text: qsTr("Objekt")
        visible: !onSubPage
    }
    BarButton {
        ButtonGroup.group: mainNav
        icon.source: "qrc:/images/Identification-Outline.svg"
        target: "/Gui/Employees/EmployeesTable.qml"
        text: qsTr("Mitarbeiter")
        visible: !onSubPage
    }
    BarButton {
        ButtonGroup.group: mainNav
        icon.source: "qrc:/images/RectangleStack-Outline.svg"
        target: "/Gui/OffersTable.qml"
        text: qsTr("Angebote")
        visible: !onSubPage
    }
    BarButton {
        ButtonGroup.group: mainNav
        icon.source: "qrc:/images/Wallet-Outline.svg"
        text: qsTr("Abrechnung")
        visible: !onSubPage
    }
    BarButton {
        icon.source: "qrc:/images/ArrowLeftCircle-Outline.svg"
        text: qsTr("Zurück")
        visible: onSubPage
        checkable: false

        onClicked: contentStack.pop();
    }
    Item {
        Layout.fillHeight: true
    }
    BarButton {
        checkable: false
        icon.source: "qrc:/images/Bars3.svg"

        onClicked: mainMenu.open()

        Menu {
            id: mainMenu

            MenuItem {
                text: qsTr("Einstellungen")

                onTriggered: {
                    // TODO: Check if logged-in user is admin first!!

                    contentStack.push("PyqcrmConf.qml");

                }
            }
            MenuSeparator {
            }
            MenuItem {
                text: qsTr("Als PDF exportieren")
            }
            MenuSeparator {
            }
            MenuItem {
                text: qsTr("Drucken")
            }
            MenuItem {
                text: qsTr("Erweiterter Druck")

                onTriggered: printerDialog.show()
            }
            MenuSeparator {
            }
            MenuItem {
                text: qsTr("Über PYQCRM")

                onTriggered: readMeWin.show()
            }
        }
    }
}

