(function () {
    'use strict';

    angular
        .module('setoresApp')
        .factory('InfoWindowReferencia', InfoWindowReferencia);

    InfoWindowReferencia.$inject = ['infowindowTemplates', 'mapsSingletonService'];

    /* @ngInject */
    function InfoWindowReferencia(infowindowTemplates, mapsSingletonService) {

        function InfoWindowReferencia(data, codigoRef) {
            this.codigoReferencia = codigoRef;
            this.tipo = data.tipo;
            this.descricao = data.descricao;
            this.identificador = data.identificador;
            this.contato = data.contato;
            this.telefone = data.telefone;
            this.endereco = data.endereco;
            this.bairro = data.bairro;
            this.cidade = data.cidade;
            this.observacao = data.observacao;

            InfoWindowReferencia.prototype.inicializar = function () {
                this.mapa = mapsSingletonService.getMap();
            };

            InfoWindowReferencia.prototype.exibirInfoWindowMarker = function () {
                const type = 'referencia';
                const options = new InlogMaps.PopupOptions();

                options.marker = type;
                options.conditionMarker = (data) => data === this.codigoReferencia;
                options.content = infowindowTemplates.montarInfoWindowReferencia('Referência', this)
                options.object = this.codigoReferencia;

                this.mapa.drawPopup(type, options);
            };

            InfoWindowReferencia.prototype.exibirInfoWindowPolygon = function (object) {
                const options = new InlogMaps.PopupOptions(object.latlng);
                options.content = infowindowTemplates.montarInfoWindowReferencia('Referência', this)
                options.object = this.codigoReferencia;

                this.mapa.drawPopup('referencia', options);
            };

            InfoWindowReferencia.prototype.ocultarInfoWindow = function () {
                this.mapa.closePopup('referencia');
            };
        }

        return InfoWindowReferencia;
    }
})();
