import QtQuick
import ZShell.Config
import qs.Components
import qs.Services

TextAreaBase {
	id: root

	readonly property alias bg: bg
	readonly property alias sendIcon: sendIcon

	signal sendPressed

	bottomPadding: Tokens.padding.large
	leftPadding: Tokens.padding.extraLarge
	rightPadding: sendIcon.width + sendIcon.anchors.rightMargin + Tokens.spacing.small
	topPadding: Tokens.padding.large
	wrapMode: TextAreaBase.Wrap

	background: CustomRect {
		id: bg

		anchors.fill: parent
		color: Colors.tPalette.m3surfaceContainer
		radius: Tokens.rounding.extraLarge

		StateLayer {
			id: stateLayer

			cursorShape: Qt.IBeamCursor
			enabled: !root.activeFocus
			manualPressOverride: tapHandler.pressed

			onClicked: root.forceActiveFocus()
		}
	}

	onPressed: {
		if (stateLayer.enabled)
			stateLayer.press(stateLayer.mouseX, stateLayer.mouseY);
	}

	CustomText {
		id: placeholder

		anchors.left: parent.left
		anchors.leftMargin: root.leftPadding
		anchors.verticalCenter: parent.verticalCenter
		color: root.placeholderTextColor
		font: root.font
		opacity: root.text ? 0 : 1
		text: root.placeholderText

		Behavior on opacity {
			Anim {
				type: Anim.DefaultEffects
			}
		}
	}

	IconButton {
		id: sendIcon

		anchors.right: parent.right
		anchors.rightMargin: Tokens.padding.small
		anchors.verticalCenter: parent.verticalCenter
		enabled: root.text
		icon: "upward_arrow"
		opacity: root.text ? 1 : 0
		radius: Tokens.rounding.full
		radiusMorph: false
		stateLayer.hoverEnabled: enabled
		type: IconButton.Text

		Behavior on opacity {
			Anim {
				type: Anim.DefaultEffects
			}
		}

		onClicked: root.sendPressed()
	}

	TapHandler {
		id: tapHandler
	}
}
