<template>
	<ViewData name="Labs" :resultset="resultset" />
</template>

<script>
	import { strftime_vista } from './util.mjs';

	import ViewData from './ViewData.vue';

	function normalize(rs) {
		return rs.map(function(x) {
			return {
				time: x.time_collected,
				name: x.name,
				unit: x.unit,
				range: x.range,
				value: x.value,
				flag: x.flag,
				comment: x.comment
			}
		});
	}

	export default {
		components: {
			ViewData
		},
		props: {
			client: Object,
			dfn: String,
			date_begin: Date,
			date_end: Date
		},
		data() {
			return {
				resultset: null
			};
		},
		computed: {
			params() {
				return { dfn: this.dfn, date_begin: strftime_vista(this.date_begin), date_end: strftime_vista(this.date_end) };
			}
		},
		watch: {
			async params(value) {
				this.resultset = normalize(await this.client.ORWLRR_INTERIM_RESULTS(value.dfn, value.date_end, value.date_begin));
			}
		}
	};
</script>
