/*!
 *
 * Copyright (c) 2020-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    DebugDataColumn.qml
 * \author  (last)      Behrouz NematiPour
 * \date    (last)      28-May-2023
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  23-Aug-2020
 *
 */

// Qt
import QtQuick 2.12

// Project

//  Qml imports
import "qrc:/globals"

Rectangle {  id: _root
    property var    model                   : []
    property var    label                   : []
    property string title                   : ""
    property int    fontPixelSizeTitle      : Fonts.fontPixelDebugTitle
    property int    fontPixelSizeText       : Fonts.fontPixelDebugText
    property int    fontPixelSizeLabel      : Fonts.fontPixelDebugLabel
    property string textObjectName          : "_DebugDataColumn"
    property int    horizontalAlignmentTitle: Text.AlignHCenter
    property int    horizontalAlignmentText : Text.AlignRight
    property bool   isTouchRect             : false
    property bool   isOpened                : false

    width       : isTouchRect ?  _column.implicitWidth : 258
    height      :  isTouchRect || isOpened ? _column.implicitHeight + 10 : _column.headerHeight
    radius      : 5
    color       : Colors.panelBackgroundColor
    clip        : true

    MouseArea {
        anchors.fill: parent
        onClicked   : {
            _root.isOpened = ! _root.isOpened
        }
        visible     : ! isTouchRect
    }

    Column { id: _column
        property alias headerHeight: _header.height
        width: parent.width

        Rectangle { id: _header
            width       : _column.width
            height      : _title.implicitHeight + 10
            color       : Colors.panelBackgroundColor
            radius      : 5
            visible     : _title.text.length > 0

            border {
                width: 1
                color: Colors.panelBorderColor
            }

            Text { id: _title
                text                : _root.title
                horizontalAlignment : _root.horizontalAlignmentTitle
                color               : Colors.offWhite
                font.pixelSize      : fontPixelSizeTitle
                font.family         : Fonts.fontFamilyFixed
                font.weight         : Font.Medium
                anchors.centerIn    : parent
            }
        }

        Repeater { id: _repeater
            model   : _root.model
            height  : delegate.implicitHeight
            width   : delegate.implicitWidth

            delegate : Grid { id: _delegate
                columns         : 2
                columnSpacing   : 5
                width           :  _text.implicitWidth + _value.width + leftPadding * 2 // content width + left and right padding
                height          : isTouchRect ? _value.implicitHeight : _text.implicitHeight + 1
                leftPadding     : isTouchRect ? 10 : 4
                rightPadding    : leftPadding

                Text { id: _value
                    objectName          : _root.textObjectName + index
                    text                : modelData
                    width               : isTouchRect ? Math.max(120, implicitWidth) : 120
                    height              : implicitHeight
                    horizontalAlignment : _root.horizontalAlignmentText
                    color               : Colors.offWhite
                    font {
                        pixelSize       : isTouchRect ? 23 : fontPixelSizeText
                        family          : Fonts.fontFamilyFixed
                        weight          : Font.Light
                    }
                    verticalAlignment   : Text.AlignTop
                    elide               : Text.ElideRight
                }

                Text { id: _text
                    objectName          : _root.textObjectName + "L" + index
                    text                : (index < _root.label.length) ? _root.label[index] : ""
                    color               : Colors.offWhite
                    height              : _value.implicitHeight
                    horizontalAlignment : Text.AlignLeft
                    font {
                        pixelSize       : fontPixelSizeLabel
                        family          : Fonts.fontFamilyFixed
                        weight          : Font.ExtraLight
                    }
                    verticalAlignment   : Text.AlignVCenter
                }
            }
        }
    }

    Behavior on height { NumberAnimation { duration: 250 } }
}
