export function createLoadingButton(config = {}) {
    const settings = {
        text: '.loading-button__text',
        loader: '.loading-button__loader',
        loadingClass: 'loading-button--loading',
        ...config,
    };

    function setLoading($button, isLoading) {
        if (!$button.length) {
            return;
        }

        $button.toggleClass(settings.loadingClass, isLoading);
        $button.find(settings.text).toggleClass('d-none', isLoading);
        $button.find(settings.loader).toggleClass('d-none', !isLoading);
    }

    function start($button) {
        setLoading($button, true);
    }

    function stop($button) {
        setLoading($button, false);
    }

    function isLoading($button) {
        return $button.hasClass(settings.loadingClass);
    }

    return {
        setLoading,
        start,
        stop,
        isLoading,
    };
}
