/*
    SPDX-FileCopyrightText: 2013-2015 Sebastian Kügler <sebas@kde.org>

    SPDX-License-Identifier: LGPL-2.0-or-later
*/

import QtQuick
import QtQuick.Layouts
import org.kde.plasma.components as PlasmaComponents
import org.kde.kirigami as Kirigami

/*!
 * Internal type containing the default layout of a tooltip.
 */
Item {
    id: root
    property Item toolTip
    property int preferredTextWidth: Kirigami.Units.gridUnit * 20

    implicitWidth: mainLayout.implicitWidth + Kirigami.Units.largeSpacing * 2
    implicitHeight: mainLayout.implicitHeight + Kirigami.Units.largeSpacing * 2

    LayoutMirroring.enabled: Application.layoutDirection === Qt.RightToLeft
    LayoutMirroring.childrenInherit: true

    Kirigami.Theme.colorSet: Kirigami.Theme.Window
    Kirigami.Theme.inherit: false

    RowLayout {
        id: mainLayout
        anchors.centerIn: parent
        anchors.margins: Kirigami.Units.largeSpacing

        spacing: Kirigami.Units.gridUnit

        Image {
            source: root.toolTip ? root.toolTip.image : ""
            visible: root.toolTip !== null && root.toolTip.image !== ""
            Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
        }

        Kirigami.Icon {
            animated: false
            source: root.toolTip ? root.toolTip.icon : ""
            Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
            visible: root.toolTip !== null && root.toolTip.icon !== "" && root.toolTip.image === "" && valid
            Layout.preferredWidth: Kirigami.Units.iconSizes.medium
            Layout.preferredHeight: Kirigami.Units.iconSizes.medium
        }

        ColumnLayout {
            Layout.maximumWidth: root.preferredTextWidth
            spacing: 0

            Kirigami.Heading {
                level: 3
                Layout.fillWidth: true
                elide: Text.ElideRight
                wrapMode: Text.Wrap
                text: root.toolTip ? root.toolTip.mainText : ""
                textFormat: Text.PlainText
                visible: text !== ""
            }

            PlasmaComponents.Label {
                Layout.fillWidth: true
                wrapMode: Text.WordWrap
                text: root.toolTip ? root.toolTip.subText : ""
                textFormat: root.toolTip ? root.toolTip.textFormat : Text.AutoText
                opacity: 0.75
                visible: text !== ""
                maximumLineCount: 8
            }
        }
    }
}
