import QtQuick 2.0
import QtQuick.Controls 2.9
import QtQuick.Controls.Material 2.0

ItemDelegate {
    id: control

    property string value: ""

    onClicked: {
        if(value === "")
            colorPicker.value = "#FFFFFF"
        else
        colorPicker.value = value
        textEditDialog.open()
    }

    Chip {
        anchors {
            right: nextPageIconText.left
            verticalCenter: parent.verticalCenter
            rightMargin: control.padding
        }

        width: parent.width * 0.15
        height: parent.height * 0.6

        color: control.value === "" ? "#FFFFFF":control.value

        text: value === "" ? "Not set": value

        onClicked: {
            control.clicked()
        }
    }

    Text {
        id: nextPageIconText

        anchors {
            right: parent.right
            verticalCenter: parent.verticalCenter
            rightMargin: control.padding
        }

        font.pixelSize: parent.height * 0.5
        font.styleName: fontAwesome.name

        verticalAlignment: Text.AlignVCenter

        text: "\uf105"
    }

    Dialog {
        id: textEditDialog
        parent: Overlay.overlay

        x: (parent.width - width) / 2
        y: (parent.height - height) / 2

        width: parent.width * 0.9
        height: Math.min(parent.height, contentHeight)

        contentWidth: parent.width * 0.9 - leftInset - rightInset
        contentHeight: contentWidth

        Material.theme: control.Material.theme
        Material.accent: control.Material.accent
        modal: true

        title: control.text

        standardButtons: Dialog.Ok | Dialog.Cancel

        contentItem: ColorPicker {
            id: colorPicker
            value: control.value
        }

        onAccepted: {
            control.value = colorPicker.value
        }
    }
}
