/**
 * SwitchButtons UI Elements
 *
 * !! no more used -> changed to css only solution !!
 */

import IGDATAPOOLFE from '@dp/ig_datapool_fe.js';

const switchButtonPlugin = {
    /**
     * Optional: initFields can just call init if the logic is the same
     */
    initFields(form) {
        this.init(form);
    },

    /**
     * Initializes switch buttons within a specific form
     * @param {HTMLElement} form - The raw DOM element
     */
    init(form) {
        const $form = $(form);

        // Find switchbutton containers within THIS form only
        $form.find('.dp-switchbutton').each(function() {
            const $container = $(this);
            const $input = $container.find('input[type=checkbox]');

            // Initialize the jQuery switchButton plugin
            $input.switchButton({
                on_label: $container.data('onlabel'),
                off_label: $container.data('offlabel')
            });
        });
    }
};
// The plugin registers itself automatically upon being imported
IGDATAPOOLFE.addPlugin('switchButton', switchButtonPlugin);

export default switchButtonPlugin;
