

import { mapState } from 'vuex'
import { calculateDistance } from '@/utils/position'
export default {
	data() {
		return {
		}
	},
	computed: {
        ...mapState(['position']),
	},
	methods: {
        calculateDistanceAddress(teacherAddress) {
            if (!teacherAddress || 
                teacherAddress.length == 0 ||
                !this.position || 
                !this.position.latitude || 
                !this.position.longitude) {
                return 0
            }

            let minDistance = 0

            teacherAddress.forEach(item => {
                let distance = calculateDistance(
                    this.position.latitude,
                    this.position.longitude,
                    item.latitude,
                    item.longitude,
                )
                minDistance = Math.min(minDistance, distance)
            })

            return minDistance
        }
	}
}