/**
 * @since Last modified: 2024-09-10 10:56:14
 * @function allToEls
 * @description Convert any data to an array of nodes.
 * @param {string|HTMLElement|Nodelist|any[]} data  - The data.Supports multiple data formats.
 * @returns {HTMLElement|null} Return a node array.
 * @see {@link https://codepen.io/axui/pen/OJGaXQp|demo @ codepen}
 * @example
 * ax.allToEls('#demo');
 * <!--return the target node-->
 */
'use strict';
import { T_el, T_sel } from '../../../types/ax';
import config from '../global/config';
import getDataType from './getDataType';
import getEl from './getEl';
import isEmpty from './isEmpty';
import trim from './trim';
const allToEls = (data: T_el | string | NodeList | any[],parent?:T_sel): T_el[] => {
    if (isEmpty(data)) return [];
    let result: T_el[] = [],
        type = getDataType(data);
    if (type.includes('HTML')) {
        result.push(data as T_el);
    } else if (type === 'String') {
        let str = trim(data as string),
            separator = str.includes(config.splitHyphen) ? config.splitHyphen : config.wordHyphen;
        str.split(separator).forEach(k => {
            let el = getEl(k,parent);
            el && result.push(el);
        });
    } else if (type === 'Array') {
        (data as any[]).forEach(k => {
            let el = getEl(k,parent);
            el && result.push(el);
        });
    } else if (type === 'NodeList') {
        result = [...(data as NodeList)];
    }
    return result;
}
export default allToEls;
