var Wick = Wick || {};
Wick.Notification = (function () {
    function Notification(params) {
        var self = this,
            iconSuccess =
                '<span class="icon notification__icon"><span class="fas fa-check-circle"></span></span>',
            iconWarning =
                '<span class="icon notification__icon"><span class="fas fa-exclamation-circle"></span></span>',
            iconError =
                '<span class="icon notification__icon"><span class="fas fa-times-circle"></span></span>',
            closeBtn =
                '<span class="icon notification__close"><span class="far fa-times"></span></span>';

        this.$self = $('<div/>', {
            class: 'notification notification_general notification_' + params.type,
            html: params.text,
        })
            .prepend(
                params.type === 'success'
                    ? iconSuccess
                    : params.type === 'warning'
                      ? iconWarning
                      : params.type === 'error'
                        ? iconError
                        : ''
            )
            .prepend(params.closeBtn ? closeBtn : '')
            .prependTo(params.container);

        this.hide = function () {
            self.$self.remove();
        };
    }

    $(document).on('click', '.notification__close', function () {
        $(this).parents('.notification, .notification_app, .sticky-wrapper').remove();
    });

    return {
        show: function (params) {
            var $oldNote = $(params.container).find('.notification');
            if ($oldNote.length) {
                $oldNote.remove();
            }

            var newNote = new Notification(params),
                offset = Wick.OfferBanner ? Wick.OfferBanner.$element.outerHeight(true) : 0,
                stickyHeaderOffset = $('body.tp-app').length
                    ? $('.sticky-header-wrapper').height() || 0
                    : 0;

            if (params.noScrolling === undefined) {
                $('html, body').animate(
                    { scrollTop: newNote.$self.offset()?.top - offset - stickyHeaderOffset - 30 },
                    300
                );
            }

            if (params.temporary !== undefined) {
                setTimeout(
                    function () {
                        newNote.hide();
                    },
                    params.delay ? params.delay : 5000
                );
            }
            return newNote;
        },
    };
})();
