/**
 * @since Last modified: 2024/03/04 15:57:45
 * @function formReset
 * @description Clear the value of the form to zero.
 * @param {getEl} el - Form node.
 * @param {function} cb - The call back of reset.Paramsters are "parent" and "fileds".
 * @returns {null} - Return null.
 * @see {@link https://codepen.io/axui/pen/XWGNgwN|demo @ codepen}
 * @example
 * ax.formReset('#demo');
 * <!--return null-->
 */
'use strict';
import getEl from "./getEl";
const formReset = (el, cb) => {
    let parent = getEl(el), fields = [...parent.querySelectorAll('input:not([type="submit"],[type="reset"]),select,textarea')];
    if (fields.length > 0) {
        for (let k of fields) {
            let type = k.type;
            if (type?.includes('select')) {
                [...k.options].forEach((i) => i.selected = false);
            }
            else if (type === 'checkbox' || type === 'radio') {
                k.checked = false;
            }
            else if (['number', 'range'].includes(type)) {
                k.value = k.min ? k.min : '0';
            }
            else {
                k.value = '';
            }
        }
        cb && cb(parent, fields);
    }
};
export default formReset;
