import type { Snippet } from 'svelte';

export interface OffCanvasContent {
	title?: string;
	content: Snippet;
	width?: string;
	class?: string;
}

export interface OffCanvasState {
	isOpen: boolean;
	content: OffCanvasContent | null;
}

function createOffCanvasStore() {
	let right = $state<OffCanvasState>({
		isOpen: false,
		content: null
	});

	return {
		get right() {
			return right;
		},
		get isRightOpen() {
			return right.isOpen;
		},
		get rightContent() {
			return right.content;
		},

		showRight(content: OffCanvasContent) {
			right = {
				isOpen: true,
				content
			};
		},

		closeRight() {
			right = {
				isOpen: false,
				content: null
			};
		},

		closeAll() {
			right = {
				isOpen: false,
				content: null
			};
		}
	};
}

export const offCanvas = createOffCanvasStore();
