<template>
	<table v-if="resultset.length > 0" class="table table-striped">
		<thead>
			<tr>
				<th>Date/Time</th>
				<th>Location</th>
				<th style="text-align: right;">Status</th>
			</tr>
		</thead>
		<tbody>
			<tr v-for="item in resultset">
				<td>{{item.timestr}} {{item.datestr}}</td>
				<td>{{item.location}}</td>
				<td style="text-align: right;">{{item.status}}</td>
			</tr>
		</tbody>
	</table>
</template>

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

	export default {
		props: {
			client: Object,
			dfn: String,
			date_begin: Date,
			date_end: Date
		},
		data() {
			return {
				resultset: []
			};
		},
		computed: {
			params() {
				return { dfn: this.dfn, date_begin: strftime_vista(this.date_begin), date_end: strftime_vista(this.date_end) };
			}
		},
		watch: {
			async params(value) {
				try {
					this.resultset = (await this.client.ORWCV_VST(value.dfn, value.date_begin, value.date_end, '')).map(item => Object.assign({
						datestr: strptime_vista(item.datetime).toLocaleDateString('sv-SE'),
						timestr: strptime_vista(item.datetime).toLocaleTimeString('en-GB')
					}, item));
				} catch(ex) {
					this.resultset = [];
					console.warn(ex);
				}
			}
		}
	};
</script>
