const resetFormFilters = (formId, excludedInputName = null) => {
    const form = $('#' + formId);

    if (excludedInputName) {
        let twinId = null;
        const inputId = '#input_' + CSS.escape(excludedInputName);
        const faceInputId = '#text_' + CSS.escape(excludedInputName);
        let selector = '#tokenCSRF, ' + inputId + ', ' + faceInputId;

        if (typeof $(inputId).attr('data-multifilter-twin') !== 'undefined') {
            twinId = '#' + CSS.escape($('input[data-multifilter="'+$(inputId).attr('data-multifilter-twin')+'"]').attr('id'));
            selector += ', ' + twinId;
        }

        form.find('input').not(selector).val('');
    } else {
        form.find('input').not('#tokenCSRF').val('');
    }

    form.find('select').val('');
}

const resetWithSession = (formId, sessionFilters) => {
    resetFormFilters(formId);

    sessionFilters = JSON.parse(sessionFilters);
    for (let formName in sessionFilters) {
        const value = sessionFilters[formName];
        const inputId = '#input_' + CSS.escape(formName);
        const input = $(inputId);

        const faceInputId = '#text_' + CSS.escape(formName);
        if ($(faceInputId).length) {
            $(faceInputId).val(value);
            $(faceInputId).trigger('change');
        }
        if (typeof $(inputId).attr('data-multifilter-twin') !== 'undefined') {
            const twinInput = $('#' + CSS.escape($('input[data-multifilter="'+$(inputId).attr('data-multifilter-twin')+'"]').attr('id')));
            twinInput.val(value)
        }

        input.val(value);
    }
}