import { PageText } from "./types";
export let data: { [propName: string]: PageText } = {}

export function refresh() {
	const itemsStr = localStorage.getItem('saved')
	if (itemsStr) {
		const items = JSON.parse(itemsStr)

		items.forEach(item => {
			const a = {} as any

			a.bg = item.bg

			if (item.actions.length) {
				a.actions = item.actions.map(_ => ({
					prop: _.prop,
					value: !!_.value
				}))
			}

			a.text = item.text.map(_ => {
				const b = {} as any

				b.value = _.value

				if (_.conditions.length) {
					b.conditions = _.conditions.map(__ => ({
						prop: __.prop,
						value: !!__.value
					}))
				}
				return b
			})

			if (item.quest) {
				a.quest = item.quest
			}

			data[item.name] = a
		}, {})
	}
}

refresh()

