
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14
import QtQuick.Scene3D 2.14
import Qt3D.Core 2.14
import Qt3D.Render 2.14
import Qt3D.Input 2.14
import Qt3D.Extras 2.14

import QtQuick 2.14 as QQ2
import QtQuick.Dialogs 1.3
import QtQuick.Window 2.2
import QtQuick.Controls 2.5


Window {
    id: messageWindow
    title : "Output Messages"
    width: 480
    height: 320
    flags:  Qt.Dialog 
            | Qt.WindowSystemMenuHint | Qt.WindowTitleHint 
            | Qt.WindowCloseButtonHint | Qt.WindowOkButtonHint 
            | Qt.FrameWindowHint

    visible: true
    color: activePalette.window
    function append(str) {
        textArea.text += str
    }
    function error(str) {
        textArea.text += "\n[ERROR] " + Qt.formatDateTime(new Date(), "| yyyy-MM-dd hh:mm:ss | ") + str + "\n"
        messageWindow.show()
    }
    function info(str) {
        textArea.text += "\n[INFO] " + Qt.formatDateTime(new Date(), "| yyyy-MM-dd hh:mm:ss | ") + str + "\n"
        messageWindow.show()
    }
    function warn(str) {
        textArea.text += "\n[WARN] " + Qt.formatDateTime(new Date(), "| yyyy-MM-dd hh:mm:ss | ") + str + "\n"
        messageWindow.show()
    }
    ColumnLayout {
        id: columns
        x: 20
        spacing: 10
        Rectangle {
            height: 10
        }
        Rectangle {
            width: messageWindow.width - 40
            height: messageWindow.height - 90
            color: activePalette.dark
            ScrollView {
                id: view
                anchors.fill: parent

                TextArea {
                    id: textArea
                    readOnly: true
                    selectByMouse: true
                    wrapMode: TextEdit.Wrap
                    color: activePalette.text
                    selectionColor: activePalette.highlight
                    selectedTextColor: activePalette.highlightedText
                    text: ""
                }
            }
            Rectangle {
                anchors.top: parent.bottom
                anchors.topMargin: 20
                anchors.right: parent.right
                width: 200
                height: 30
                color: "transparent" 
                RowLayout {
                    spacing: 20
                    DefaultButton {
                        focusPolicy: Qt.ClickFocus
                        text: "Clear" 
                        implicitWidth: 70
                        implicitHeight: 30
                        onClicked: {
                            textArea.text = ""
                        }
                    }
                    DefaultButton {
                        focusPolicy: Qt.ClickFocus
                        text: "Close"
                        implicitWidth: 70
                        implicitHeight: 30
                        onClicked: messageWindow.close()
                    }
                }
            }
        }
        Rectangle {
            height: 10
        }
    }
}