/*!
 *
 * Copyright (c) 2021-2024 Diality Inc. - All Rights Reserved.
 * \copyright
 * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN
 * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER.
 *
 * \file    StepIndicator.qml
 * \author  (last)      Behrouz NematiPour
 * \date    (last)      06-Jul-2021
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  11-Jan-2021
 *
 */

// Qt
import QtQuick 2.12

// Project
//  Qml imports
import "qrc:/globals"
import "qrc:/components"

/*!
 * \brief   StepIndicator
 * \details The Step indicator can have list of the steps and will show a bullet for each step with name and a line between each bullet.
 *          If the currentStepIndex has been set to any value in the range of the 0 to stepNames.length
 *          all the steps' bullets and the line between them from the beginning up to the currentStepIndex will be activated/highlighted.
 */
Rectangle { id: _root
    property bool   currentComplete     : false
    property bool   hideLabels          : false
    property var    stepNames           : []
    property var    subSteps            : []
    property int    spacing             : 5
    property int    spacerLineLength    : 75
    property int    currentStepIndex    : 0
    property int    diameter            : 20
    property int    subStepIndex        : 0

    width   : _row.width
    height  : _row.height
    color   : Colors.transparent

    Row { id: _row
        spacing         : _root.spacing
        anchors.centerIn: parent

        Repeater { id: repeater
            model: _root.stepNames

            Grid { id: _gridSteps
                rows            : 1
                columns         : 0
                rowSpacing      : _root.spacing
                columnSpacing   : _root.spacing
                verticalItemAlignment   : Grid.AlignVCenter
                horizontalItemAlignment : Grid.AlignHCenter

                Line { id   : _spacerLine
                    orientation: _root.vertical ? Line.Orientation.Vertical : Line.Orientation.Horizontal
                    length  : _root.spacerLineLength
                    color   : _stepsBullet.color
                    visible : index !== 0 // do not show fist line onl lines inbetween bullets
                }

                StepBullet { id: _stepsBullet
                    diameter        : _root.diameter
                    currentComplete : _root.currentComplete
                    hideLabels      : _root.hideLabels
                    text            : modelData
                    complete        : index <  currentStepIndex
                    current         : index === currentStepIndex

                    SubStepIndicator { id: _subStep
                        anchors {
                            top             : parent.bottom
                            topMargin       : 25
                            horizontalCenter: parent.horizontalCenter
                        }

                        subStepIndex    : _root.subStepIndex
                        subStepsLength  : _root.subSteps[index] ?? 0
                        height          : 10
                        width           : _stepsBullet.width * _root.subSteps[index]
                        complete        : _stepsBullet.complete
                    }
                }
            }
        }
    }
}
