<script lang="ts">
	import Composer from '$lib/core/refactor/Composer.svelte';
	import { assign } from 'xstate';
	import { coreServices } from '$lib/core/refactor/coreServices';
	import { queryMessages } from '$lib/data/queryMessages';

	let composer = {
		id: 'ComposerParent',
		machine: {
			initial: 'NOTREADY',
			states: {
				NOTREADY: {
					on: { TOGGLE: 'READY' }
				},
				READY: {
					on: { TOGGLE: 'NOTREADY' }
				}
			}
		},
		layout: {
			columns: '1fr 1fr',
			rows: '1fr 1fr',
			areas: `
				"top aside"
				"bottom aside"
			`
		},
		children: [
			{
				id: 'ComposerCharly',
				component: 'ComposerCharly',
				slot: 'aside',
				data: {},
				machine: {
					initial: 'LOADING',
					context: {
						hello: 'start',
						messages: []
					},
					states: {
						LOADING: {
							on: {
								TOGGLE: {
									target: 'READY',
									actions: assign({
										hello: (context, event) => 'this was updated from loading'
									})
								}
							}
						},
						READY: {
							on: {
								TOGGLE: {
									target: 'LOADING'
								}
							}
						}
					}
				}
			},
			{
				id: 'ComposerBob',
				component: 'ComposerBob',
				slot: 'top',
				machine: {
					initial: 'READY',
					states: {
						NOTREADY: {
							on: { TOGGLE: 'READY' }
						},
						READY: {
							on: { TOGGLE: 'NOTREADY' }
						}
					}
				}
			},
			{
				id: 'ComposerAlice',
				component: 'ComposerAlice',
				slot: 'bottom',
				machine: {
					initial: 'RED',
					states: {
						GREEN: {
							on: { SWITCH: 'YELLOW' }
						},
						YELLOW: {
							on: { SWITCH: 'RED' }
						},
						RED: {
							on: { SWITCH: 'GREEN' }
						}
					},
					on: {
						READY: 'GREEN',
						NOTREADY: 'RED'
					}
				}
			}
		]
	};
</script>

<Composer {composer} />
