(function ($) {
	"use strict";
	var WidgetWhatsapp = function ($scope, $) {
		var container      = $scope.find( '#ec-wp-send-it' ),
			containerclose = $scope.find( '.ec-wp-close-chat' ),
			containerbtn   = $scope.find( '.ec-wp-chat-button' );

		container.on(
			"click",
			function (e) {
				var input = document.getElementById( "ec-wp-chat-input" );
				if ("" != input.value) {
					var number = $( this ).closest( '.ec-whasapp-wrapper-main' ).find( "#ec-wp-get-number" ).text(),
					valueget   = input.value,
					link       = "https://web.whatsapp.com/send",
					numfin     = number,
					finval     = "&text=" + valueget;
					if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( navigator.userAgent )
					) {
						var link = "whatsapp://send";
					}

					var final = link + "?phone=" + numfin + finval;
					window.open( final, "_blank" );
				}
			}
		),

		containerclose.on(
			"click",
			function (e) {
				$( this ).closest( '.ec-whasapp-wrapper-main' ).find( "#ec-whasapp-wrapper" ).addClass( "ec-wp-hide" ).removeClass( "ec-whasapp-show" );
			}
		),

		containerbtn.on(
			"click",
			function (e) {
				$( this ).closest( '.ec-whasapp-wrapper-main' ).find( "#ec-whasapp-wrapper" ).addClass( "ec-whasapp-show" ).removeClass( "ec-wp-hide" );
			}
		);

	};
	$( window ).on(
		'elementor/frontend/init',
		function () {
			elementorFrontend.hooks.addAction( 'frontend/element_ready/ecafe-whatsapp.default', WidgetWhatsapp );
		}
	);
})( jQuery );