import { Component, OnInit } from '@angular/core';
import { ToastController } from '@ionic/angular';

@Component({
	selector: 'app-refer',
	templateUrl: './refer.component.html',
	styleUrls: ['./refer.component.scss'],
})
export class ReferComponent implements OnInit {

	constructor(
		public toastController: ToastController
	) { }

	ngOnInit() { }

	copy() {
		var copyText = document.getElementById("clipboard") as HTMLInputElement;
		copyText.select();
		copyText.setSelectionRange(0, 99999); /*For mobile devices*/

		/* Copy the text inside the text field */
		document.execCommand("copy");

		/* Alert the copied text */
		this.presentToast("Copied the text: " + copyText.value);
	}

	async presentToast(text: string) {
		const toast = await this.toastController.create({
			message: text,
			position: 'bottom',
			duration: 2000,
			color: 'dark',
			buttons: [
				{
					text: 'Done',
				}
			]
		});
		toast.present();
	}

}
