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

// Qt
import QtQuick 2.12
import QtGraphicalEffects 1.0

// Project

//  Qml imports
import "qrc:/globals"

/*!
 * \brief   UltrafiltrationButton.qml is the option button
 *          to choose the method to adjust the treatment ultrafiltration
 */
Rectangle  { id: _root
    enum ButtonType {
        UltrafiltrationRate ,
        TreatmentDuration
    }

    readonly property alias  title       : _title.text
    readonly property alias  description : _description.text

    property string titleString       : ""
    property string descriptionString : ""
    property string valueText   : ""

    property color  textColor   : Colors.textMain
    property int    buttonType  : UltrafiltrationButton.ButtonType.UltrafiltrationRate
    property bool   isIncrease  : true
    property bool   selected    : false
    property bool   disabled    : false

    readonly property int  leftMargin : 35
    readonly property int rightMargin : 28


    signal clicked()

    width   : Variables.ultrafiltrationAdjustmtenOptionWidth
    height  : Variables.ultrafiltrationAdjustmtenOptionHeight
    clip    : true

    color   : disabled ?
                  "transparent" :
                  selected ?
                      Qt.lighter(Colors.backgroundUltrafiltrationButton, 1.1) : // little lighter to distinguish selection
                      Colors.backgroundUltrafiltrationButton
    radius  : 12
    border  {
        width: 2
        color: selected ? Colors.borderButton : "Transparent"
    }

    Text { id: _title
        text: _root.titleString.arg(disabled ? qsTr("Invalid") : isIncrease ? qsTr("Increase") : qsTr("Decrease"))
        font.pixelSize: 35
        font.weight: Font.DemiBold
        color: disabled ? Colors.textDisableButton : textColor
        anchors {
            top     : parent.top
            topMargin : 25
            left    : parent.left
            leftMargin: 35
        }
    }

    Text { id: _description
        text: disabled ? qsTr("Due to out of range adjustment, this option\nis disabled.") : _root.descriptionString.arg(isIncrease ? "increases" : "decreases")
        font.pixelSize: 26
        color: disabled ? Colors.textDisableButton : textColor
        anchors {
            top     : parent.top
            topMargin : 85
            left    : parent.left
            leftMargin: leftMargin
        }
    }

    ImageWave { id: _diffImageWave
        visible     : !disabled && buttonType === UltrafiltrationButton.ButtonType.UltrafiltrationRate
        isIncrease  : _root.isIncrease
        anchors {
            right   : _root.right
            bottom  : _root.bottom
            margins : _root.rightMargin
        }
    }

    ImageClock { id: _diffImageClock
        visible     : !disabled && buttonType === UltrafiltrationButton.ButtonType.TreatmentDuration
        isIncrease  : _root.isIncrease
        anchors {
            right   : _root.right
            bottom  : _root.bottom
            margins : _root.rightMargin
        }
    }

    Text { id: _textValue
        text        : valueText
        font.pixelSize: 26
        color       : disabled ? Colors.textDisableButton : Colors.textValueUltrafiltrationButtonFg
        anchors {
            left    : _root.left
            bottom  : _root.bottom
            leftMargin  : _root. leftMargin
            bottomMargin: _root.rightMargin
        }
    }

    MouseArea { id: _mouseArea
        anchors.fill: parent
        onClicked: {
            if (! disabled) {
                _root.clicked()
            }
        }
    }
}
