<template>
	<Content app-name="AgencyData">
		<b-container v-if="isLoading"
			fluid>
			<h3>Agenturdaten</h3>
			<FormulateForm
				v-model="agency"
				@submit="submitHandler">
				<b-row>
					<b-col>
						<FormulateInput name="name"
							label="Agenturname"
							type="text" />
					</b-col>
				</b-row>
				<b-row>
					<b-col>
						<FormulateInput name="inhaber"
							label="Agenturinhaber"
							type="text" />
					</b-col>
				</b-row>
				<b-row>
					<b-col>
						<FormulateInput name="street"
							label="Straße"
							type="text" />
					</b-col>
				</b-row>
				<b-row>
					<b-col>
						<FormulateInput name="city"
							label="Stadt"
							type="text" />
					</b-col>
				</b-row>
				<b-row>
					<b-col>
						<FormulateInput name="plz"
							label="PLZ"
							type="text"
							:validation="[
								['required'],
								['max', 99999],
								['min', 10000]
							]" />
					</b-col>
				</b-row>
				<b-row>
					<b-col>
						<FormulateInput name="agencymail"
							label="Agentur-Email-Adressedd"
							type="text" />
					</b-col>
				</b-row>
				<b-row>
					<b-col>
						<FormulateInput name="phone"
							label="Telefonnummer"
							type="text" />
					</b-col>
				</b-row>
				<b-row class="mt-2">
					<b-col>
						<b-button
							variant="secondary"
							type="submit">
							Aktualisieren
						</b-button>
					</b-col>
				</b-row>
			</FormulateForm>
		</b-container>
		<b-container v-if="!isLoading" class="d-flex justify-content-center">
			<b-spinner type="grow" />
		</b-container>
	</Content>
</template>
<script>
import Content from '@nextcloud/vue/dist/Components/Content'
import { generateUrl } from '@nextcloud/router'
import '@braid/vue-formulate/themes/snow/snow.scss'
// const axios = require('axios').default
import axios from '@nextcloud/axios'

export default ({
	name: 'AgencyData',
	components: {
		Content,
	},
	data() {
		return {
			agency: null,
			isLoading: false,
		}
	},
	created() {
		this.loadingAgencyData()
	},
	methods: {
		async loadingAgencyData() {
			const agencydata = await axios.get(generateUrl('/apps/agency/getagencydata'))
			this.agency = agencydata.data
			this.isLoading = true
		},
		async submitHandler(data) {
			const response = await axios.put(generateUrl('/apps/agency/updateagencydata'), data)
			console.log(response)
		},
	},
})
</script>
