/* Minification failed. Returning unminified contents.
(3,14-15): run-time error JS1005: Expected '(': ;
(3,14-15): run-time error JS1008: Expected '{': ;
(10,32): run-time error JS1004: Expected ';'
(30,22): run-time error JS1004: Expected ';'
(40,26): run-time error JS1004: Expected ';'
(50,26): run-time error JS1004: Expected ';'
(77,21): run-time error JS1004: Expected ';'
(88,22): run-time error JS1004: Expected ';'
(98,30): run-time error JS1004: Expected ';'
(111,23): run-time error JS1004: Expected ';'
(117,24): run-time error JS1004: Expected ';'
(121,26): run-time error JS1004: Expected ';'
(133,33): run-time error JS1004: Expected ';'
(139,37): run-time error JS1004: Expected ';'
(148,42): run-time error JS1004: Expected ';'
(155,43): run-time error JS1004: Expected ';'
(166,24): run-time error JS1004: Expected ';'
(173,42): run-time error JS1004: Expected ';'
(181,29): run-time error JS1004: Expected ';'
(186,33): run-time error JS1004: Expected ';'
(197,5-10): run-time error JS1010: Expected identifier: const
(197,39-40): run-time error JS1008: Expected '{': ;
(206,2-3): run-time error JS1010: Expected identifier: (
(206,10-11): run-time error JS1008: Expected '{': )
(206,2-10): run-time error JS1301: End of file encountered before function is properly closed: (jQuery)
(208,1): run-time error JS1107: Expecting more source characters
(208,1): run-time error JS1009: Expected '}'
(1,2-14): run-time error JS1301: End of file encountered before function is properly closed: function ($)
(208,1): run-time error JS1107: Expecting more source characters
(208,1): run-time error JS1006: Expected ')'
(8,9-19): run-time error JS1300: Strict-mode does not allow assignment to undefined variables: edgeKludge
(7,9-30): run-time error JS1300: Strict-mode does not allow assignment to undefined variables: scrollEdgeForgiveness
(4,9-23): run-time error JS1300: Strict-mode does not allow assignment to undefined variables: scrollDistance
 */
(function ($) {
    class ScrollTabListContainer {
        $this;
        scrollDistance = 0.9;
        $tabs;
        scrollContainer;
        scrollEdgeForgiveness = 0.2;
        edgeKludge = 5;
        $scrollContainer;
        constructor($container) {
            this.$this = $container;
            this.$scrollContainer = this.$this.find('.scroll-interior');
            this.$tabs = $container.find('[role="tab"][aria-controls]');
            if (this.$tabs.length) {
                this.scrollContainer = $container.find('.scroll-interior')[0];
                this.updateScrollButtons();
                this.$scrollContainer.on("scroll", $.throttle(200, false, this.updateScrollButtons.bind(this)));
                this.resizeObserver = new ResizeObserver($.throttle(200, false, this.updateScrollButtons.bind(this)));
                this.resizeObserver.observe(this.scrollContainer);
                const $firstTab = this.$tabs.first();
                this.showActiveTab($firstTab);
                this.$tabs.on('click', this.handleClick.bind(this));
                this.$this.find('.scroll-pre button').on('click', this.scrollLeft.bind(this));
                this.$this.find('.scroll-post button').on('click', this.scrollRight.bind(this));
                this.$this.find('[role="tab"]').on('keydown', this.handleKeyboard.bind(this));
                this.$this.addClass("loaded");
            }
        }

        $getNextTab() {
            var $current = this.$getActiveTab();
            var ariaControls = $current.attr('aria-controls');
            var $nextTab = this.$this.find('[aria-controls="' + ariaControls + '"] + [aria-controls]');
            if (!$nextTab.length) {
                return this.$this.find('[aria-controls]').first();
            }
            return $nextTab;
        }

        $getPreviousTab() {
            var $current = this.$getActiveTab();
            for (var i = 0; i < this.$tabs.length; i++) {
                if ($current.is(this.$tabs[i])) {
                    return this.$tabs.eq((i === 0 ? this.$tabs.length : i) - 1);
                }
            }
            throw Error('What just happened?!');
        }

        handleKeyboard(e) {
            switch (e.keyCode) {
                case 39:
                case 40:
                    e.preventDefault();
                    this.setActiveTab(this.$getNextTab(), true);
                    break;
                case 37:
                case 38:
                    e.preventDefault();
                    this.setActiveTab(this.$getPreviousTab(), true);
                    break;
                case 32:
                case 13:
                    e.preventDefault();
                    this.activateTab(this.$getActiveTab());
                    break;
                case 33: //page up/page down - it just makes the scrolly area wiggle when you do that
                case 34: // ....so prevent
                    e.preventDefault();
                    break;
                default:
                    break;
            }
        }


        scrollLeft() {
            var myScrollLeft = Math.max(0, this.scrollContainer.scrollLeft - (this.scrollContainer.clientWidth * this.scrollDistance));

            if (myScrollLeft < this.scrollContainer.clientWidth * this.scrollEdgeForgiveness) {
                myScrollLeft = 0;
            }


            $(this.scrollContainer).animate({ scrollLeft: myScrollLeft }, 400, "swing", this.updateScrollButtons.bind(this));
        }

        scrollRight() {
            var myScrollRight = Math.min(this.scrollContainer.scrollWidth - this.scrollContainer.clientWidth, this.scrollContainer.scrollLeft + (this.scrollContainer.clientWidth * this.scrollDistance));

            if (myScrollRight > this.scrollContainer.scrollWidth - this.scrollContainer.clientWidth - (this.scrollContainer.clientWidth * this.scrollEdgeForgiveness)) {
                myScrollRight = this.scrollContainer.scrollWidth - this.scrollContainer.clientWidth;
            }

            $(this.scrollContainer).animate({ scrollLeft: myScrollRight }, 400, "swing", this.updateScrollButtons.bind(this)); //Note: still setting scrollLeft (instead of scrollRight) b/c its about how far from the left
        }

        updateScrollButtons() {
            if (this.scrollContainer.scrollLeft > this.edgeKludge) {
                this.$this.removeClass('scrolled-left');
            } else {
                this.$this.addClass('scrolled-left');
            }
            if (this.scrollContainer.scrollLeft < this.scrollContainer.scrollWidth - this.scrollContainer.clientWidth - this.edgeKludge) {
                this.$this.removeClass('scrolled-right');
            } else {
                this.$this.addClass('scrolled-right');
            }
        }

        handleClick(e) {
            e.preventDefault();
            this.activateTab($(e.currentTarget));
            this.setActiveTab($(e.currentTarget), true)
        }

        $getActiveTab() {
            return this.$this.find('[aria-controls][tabindex="0"]');
        }

        activateTab($tab) {
            var _this = this;
            this._focusTab($tab);
            this.$tabs.each(function () {
                if ($tab.is(this)) {
                    _this._showContent($tab, true);
                } else {
                    _this._showContent($(this), false);
                }
            })
        }

        _showContent($tab, show) {
            this.viewTransition(function () {
                this.setActiveContent($tab, show);
            }.bind(this));
        }

        setActiveContent($tab, show) {
            const controlId = $tab.attr('aria-controls');
            if (show) {
                $("#" + controlId + ".scroll-tab-list-component").css('display', 'block');
            } else {
                $("#" + controlId + ".scroll-tab-list-component").hide();
            }
        }

        setActiveTab($tab, focus = false) {
            this.viewTransition(function () {
                this.showActiveTab($tab, focus);
            }.bind(this));

        }

        showActiveTab($tab, focus = false) {
            const _this = this;
            this.$tabs.each(function () {
                if ($tab.is(this)) {
                    _this._activateTab($tab, focus);
                } else {
                    _this._deactivateTab($(this));
                }
            })
        }

        _focusTab($tab) {
            var x = $tab.position().left;
            $tab.focus();
            // Scrolls to the element, and adds 1/3 width of the bar so it's not under the left arrow
            this.$scrollContainer.scrollLeft(x + this.$scrollContainer.scrollLeft() - this.$scrollContainer.width() / 3);
        }

        _activateTab($tab, focus = false) {

            $tab.attr('tabindex', '0');
            if (focus) {
                this._focusTab($tab);
            }
        }

        _deactivateTab($tab) {
            const controlId = $tab.attr('aria-controls');
            $tab.attr('tabindex', '-1');
        }

        viewTransition(callback) {
            if (document.startViewTransition) {
                document.startViewTransition(() => {
                    callback();
                });
            } else {
                callback();
            }
        }
    }

    const scrollTabListContainers = [];

    $(".scroll-container").each(function () {
        scrollTabListContainers.push(new ScrollTabListContainer($(this)));
    })

    window.wsecu = window.wsecu || {};

    window.wsecu.scrollTabListContainers = scrollTabListContainers;
}(jQuery));
;
