import { Injectable } from '@angular/core';
import { Utils } from '@nativescript/core';

/**
 * Service takes care of common functionality
 */
@Injectable()
export class UtilsService {
    /**
     * It open specific address in google maps app or google maps in browsers
     * Structure of url for Google Maps: https://developers.google.com/maps/documentation/urls/guide
     * Maybe need add url for iOS: https://stackoverflow.com/questions/37685105/nativescript-openurl
     *
     * @param {string} street
     * @param {string} postcode
     * @param {string} city
     * @param {string} state
     */
    openAddress(street: string, postcode: string, city: string, state: string) {
        const encodedAddress = encodeURI(`${street}, ${city} ${postcode}, ${state}`);
        Utils.openUrl(`https://www.google.com/maps/search/?api=1&query=${encodedAddress}`);
    }

}
