/**
 * @since Last modified: 2024/04/20 14:39:01
 * @function getEl
 * @description Get a HTMLElement node.Support to get a real node or virtual node 
 * @param {string|HTMLElement} obj  - It can be node  or node selector such as#ID, .classname, NODENAME, [attribute]
 * @param {HTMLElement} parent  - Parent node, get sub-node from this node, default document.body
 * @returns {HTMLElement|null} Return a node or null
 * @see {@link https://codepen.io/axui/pen/JjxNQEO|demo @ codepen}
 * @example
 * ax.getEl('#demo');
 * <!--return a HTMLElement node-->
 */
'use strict';
import { T_el, T_sel } from '../../../types/ax';
import getDataType from './getDataType';
const getEl = (obj: T_sel, parent: T_sel = document.body) => {
    let type = getDataType(obj), result: T_el | null = null;
    if (obj) {
        if (type.includes('HTML')) {
            result = (obj as T_el);
        } else if (type === 'String') {
            try {
                result = (parent as T_el).querySelector((obj as string).trim());
            } catch {
                result = null;
            }
        }
    }
    return result;
}
export default getEl;
