import './labelFormCentric.scss';
import {createElement} from "../../_global/scripts/helpers";

export const createLabelFormCentric = ({
    text = 'Benutzername',
    forAttribute = 'name',
    isRequired = false,
    isHidden = false,
    labelType = 'not-set',
}) => {
    let labelField;
    if (labelType === 'text') {
        labelField = createElement('label', ['mwf-textinput__label'], text);
        labelField.htmlFor = forAttribute;
        if (isRequired) {
            const asterix = createElement('span', ['mwf-textinput__required','mwf-required'], '*', labelField);
            asterix.title = 'Pflichtfeld';
        }
    }
    else if (labelType === 'checkbox') {
        labelField = createElement('label', ['mwf-checkbox__label']);
        labelField.htmlFor = forAttribute;
        createElement('span', ['mwf-checkbox__text'], text, labelField);
    }
    else if (labelType === 'radio') {
        labelField = createElement('label', ['mwf-radio__label']);
        labelField.htmlFor = forAttribute;
        createElement('span', ['mwf-radio__text'], text, labelField);
    }
    else if (labelType === 'select') {
        labelField = createElement('label', ['mwf-select__label'], text);
        labelField.htmlFor = forAttribute;
        if (isRequired) {
            const asterix = createElement('span', ['mwf-select__required','mwf-required'], '*', labelField);
            asterix.title = 'Pflichtfeld';
        }
    }
    else if (labelType === 'textarea') {
        labelField = createElement('label', ['mwf-textarea__label'], text);
        labelField.htmlFor = forAttribute;
        if (isRequired) {
            const asterix = createElement('span', ['mwf-textarea__required','mwf-required'], '*', labelField);
            asterix.title = 'Pflichtfeld';
        }
    }
    else {
        labelField = createElement('label', ['mwf-textinput__label'], text);
        labelField.htmlFor = forAttribute;
    }

    return labelField;
}