import QtQuick
import qs.Modules.Lock.Weather
import ZShell.Config
import qs.Components
import qs.Helpers
import qs.Services

CustomRect {
	id: root

	required property int rootHeight
	readonly property bool showForecast: rootHeight >= 700

	color: Colors.tPalette.m3surfaceContainer
	implicitHeight: {
		const base = brief.implicitHeight + brief.anchors.topMargin;
		if (showForecast)
			return base + Tokens.spacing.largeIncreased + forecast.implicitHeight + forecast.anchors.margins;
		return base + brief.anchors.topMargin;
	}
	radius: Tokens.rounding.small

	Timer {
		interval: 900000 // 15 minutes
		repeat: true
		running: true
		triggeredOnStart: true

		onTriggered: Weather.reload()
	}

	BriefInfo {
		id: brief

		anchors.horizontalCenter: parent.horizontalCenter
		anchors.top: parent.top
		anchors.topMargin: Tokens.padding.extraLarge
		rootHeight: root.rootHeight
	}

	Loader {
		id: forecast

		active: root.showForecast
		anchors.bottom: parent.bottom
		anchors.left: parent.left
		anchors.margins: Tokens.padding.large
		anchors.right: parent.right
		asynchronous: true

		sourceComponent: Forecast {
		}
	}
}
