/*
    NexusOS Plasma startup splash.

    Deliberately plain QtQuick -- no PlasmaCore import. ksplashqml runs this
    before the session is up, and the fewer modules it has to resolve at that
    point the fewer ways it has to fail; sizes are proportional to the screen
    instead of Units.gridUnit for the same reason.

    ksplashqml drives `stage` from 0 to 6 as the session comes up, which fills
    the progress bar. The content is deliberately opaque from the start rather
    than faded in on stage 2 the way Breeze's splash does: if that signal never
    arrives -- as under `ksplashqml --test` -- a stage-gated splash shows nothing
    but a blank coloured screen. Palette matches assets/themes/_palette.py.
*/
import QtQuick 2.15

Rectangle {
    id: root
    color: "#1e1526"

    property int stage

    onStageChanged: {
        if (stage == 6) {
            outroAnimation.running = true;
        }
    }

    // Same brushed-metal ground as the Plymouth, SDDM and lock screens. Raster,
    // not the source SVG: QtSvg is Tiny 1.2 and drops the <pattern> textures.
    Image {
        anchors.fill: parent
        source: "images/background.png"
        fillMode: Image.PreserveAspectCrop
        smooth: true
        asynchronous: false
    }

    Item {
        id: content
        anchors.fill: parent

        Image {
            id: logo
            anchors.horizontalCenter: parent.horizontalCenter
            y: parent.height * 0.32
            source: "images/logo.png"
            width: Math.round(parent.width * 0.15)
            fillMode: Image.PreserveAspectFit
            smooth: true
            asynchronous: false
        }

        Text {
            id: brand
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.top: logo.bottom
            anchors.topMargin: Math.round(parent.height * 0.03)
            text: "NexusOS"
            color: "#f2f2f2"
            font.family: "Sans"
            font.pixelSize: Math.round(parent.height * 0.026)
            font.letterSpacing: 6
            font.weight: Font.Light
        }

        Rectangle {
            id: track
            anchors.horizontalCenter: parent.horizontalCenter
            y: Math.round(parent.height * 0.62)
            width: Math.round(parent.width * 0.18)
            height: 3
            radius: height / 2
            color: "#2e3236"

            Rectangle {
                height: parent.height
                radius: parent.radius
                color: "#8cc63f"
                width: parent.width * Math.min(root.stage / 6, 1)
                Behavior on width {
                    NumberAnimation { duration: 250; easing.type: Easing.InOutQuad }
                }
            }
        }
    }

    OpacityAnimator {
        id: outroAnimation
        target: content
        from: 1; to: 0
        duration: 400
        running: false
    }
}
