pragma Singleton

import Quickshell
import QtQuick
import ZShell.Config
import qs.Helpers
import qs.Services

Singleton {
	id: root

	function create(parent: Item, props: var): void {
		chatComp.createObject(parent ?? dummy, props);
		Visibilities.getForActive().sidebar = false;
		ChatState.isWindow = true;
	}

	QtObject {
		id: dummy
	}

	Component {
		id: chatComp

		FloatingWindow {
			id: win

			property var props

			color: Colors.tPalette.m3surface
			implicitHeight: chat.implicitHeight
			implicitWidth: chat.implicitWidth
			minimumSize.height: Config.sidebar.sizes.width
			minimumSize.width: Config.sidebar.sizes.width
			surfaceFormat.opaque: false
			title: qsTr("ZShell - %1").arg(ChatState.title)

			Component.onCompleted: ChatState.screen = screen
			onVisibleChanged: {
				if (!visible) {
					destroy();
					ChatState.isWindow = false;
				}
			}

			SidebarView {
				id: chat

				anchors.fill: parent
			}
		}
	}
}
