/*!
 *
 * 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    FooterStatic.qml
 * \author  (last)      Behrouz NematiPour
 * \date    (last)      22-May-2021
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  15-May-2021
 *
 */

// Qt
import QtQuick 2.12

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

/*!
 * \brief   Denali project Footer section which gives all the children same width with same spacing, aligned in center.
 * \details It's been created because the row layout is always keeping it's children aligned at left and not at center.
 *          It's also not using row layout and sets it's children by itself.
 *          This mainly being used to keep buttons on a screen alinged with the same width and space between them and horisontalley centered
 *          on the bottom of the screen (footer),
 *          and with enough bottom marging to give room to the alarm bar.
 * \note    The main difference between FooterStatic and Footer is that once it sets it's children posision will not re arrnage them if they become hidden or visible.
 */
Item { id: _root
    property int    childrenWidth   : _root.width / (childrenCount * 2 + 1 )
    property int    childrenCount   : children.length
    property real   spacing         : _private.spacing

    QtObject { id: _private
        property int spacing    : 0
    }

    // this code will run once and will not run for each child,
    // that's becuase the available property to add children is the children property
    // and that property can only change by assigning a list to it.
    // so it happens once with no performance issue of multiple redundant call.
    onVisibleChanged: {
        // check there is a child
        let count = childrenCount
        if ( ! count ) return

        let width   = childrenWidth
        let spacing = (_root.width - (width * count)) / (count + 1)

        for (let i = 0; i < count; i++) {
            let child = children[i]
            if (child.width !== width) {
                child.width   = width
            }
            child.x = ( spacing * (i+1)) + (childrenWidth * i)
        }

        _private.spacing = spacing
    }

    height                  : childrenCount ? Variables.touchRectHeight : 0
    anchors.left            : parent.left
    anchors.right           : parent.right
    anchors.bottom          : parent.bottom
    anchors.bottomMargin    : Variables.notificationHeight + Variables.minVGap
}
