/*
    SPDX-FileCopyrightText: 2026 Marco Allegretti

    SPDX-License-Identifier: EUPL-1.2
*/

import QtQuick
import org.kde.kirigami as Kirigami
import org.kde.plasma.private.mobileshell as MobileShell

Rectangle {
    id: root

    color: "#0e0f16"

    property int stage

    readonly property bool busy: stage > 1 && stage < 6
    readonly property int longAnimationDuration: MobileShell.Motion.duration(MobileShell.Motion.EffectsDefault)
    readonly property int veryLongAnimationDuration: MobileShell.Motion.duration(MobileShell.Motion.EffectsSlow)
    readonly property int spinnerAnimationDuration: Math.round(MobileShell.Motion.duration(MobileShell.Motion.EffectsSlow) * 3.5)

    Item {
        id: content
        anchors.centerIn: parent
        width: Math.min(parent.width, Kirigami.Units.gridUnit * 24)
        height: Kirigami.Units.gridUnit * 12
        opacity: root.stage > 1 ? 1 : 0

        Behavior on opacity {
            OpacityAnimator {
                duration: root.veryLongAnimationDuration
                easing.type: MobileShell.Motion.easing(MobileShell.Motion.EffectsSlow)
            }
        }

        Text {
            id: wordmark
            anchors.centerIn: parent
            text: "SHIFT"
            color: "#fcfcfc"
            font.family: "Atkinson Hyperlegible Next"
            font.pixelSize: Math.round(Kirigami.Units.gridUnit * 3.2)
            font.weight: Font.DemiBold
            horizontalAlignment: Text.AlignHCenter
            verticalAlignment: Text.AlignVCenter
        }

        Rectangle {
            width: Math.round(Kirigami.Units.gridUnit * 5)
            height: Math.max(2, Math.round(Kirigami.Units.devicePixelRatio * 2))
            radius: height / 2
            color: "#2eb8a8"
            anchors.top: wordmark.bottom
            anchors.topMargin: Kirigami.Units.largeSpacing
            anchors.horizontalCenter: parent.horizontalCenter
        }

        Item {
            id: busyIndicator
            width: Kirigami.Units.gridUnit * 1.6
            height: width
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.top: wordmark.bottom
            anchors.topMargin: Kirigami.Units.gridUnit * 2.2
            opacity: root.busy ? 1 : 0

            Behavior on opacity {
                OpacityAnimator {
                    duration: root.longAnimationDuration
                    easing.type: MobileShell.Motion.easing(MobileShell.Motion.EffectsDefault)
                }
            }

            Rectangle {
                anchors.fill: parent
                radius: width / 2
                color: "transparent"
                border.width: Math.max(2, Math.round(Kirigami.Units.devicePixelRatio * 2))
                border.color: "#2eb8a8"
                opacity: 0.28
            }

            Rectangle {
                width: parent.width
                height: Math.max(2, Math.round(Kirigami.Units.devicePixelRatio * 2))
                radius: height / 2
                color: "#2eb8a8"
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.top: parent.top
            }

            RotationAnimator on rotation {
                from: 0
                to: 360
                duration: root.spinnerAnimationDuration
                loops: Animation.Infinite
                running: root.busy && MobileShell.Motion.enabled
            }
        }
    }
}