/**
 * @since Last modified: 2024-08-02 10:13:04
 * @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_null, T_sel } from '../../../types/ax';
import getDataType from './getDataType';
interface T_getEl {
    (obj: T_sel, wrap?: T_el | string | T_null): T_el | null;
}
const getEl: T_getEl = (obj, wrap) => {
    let objType = getDataType(obj),
        parType = getDataType(wrap),
        parent = parType.includes('HTML') ? wrap : document.body.querySelector(wrap as string),
        result: T_el | null = null;
    if (obj) {
        if (objType.includes('HTML')) {
            result = (obj as T_el);
        } else if (objType === 'String') {
            try {
                result = ((parent as T_el) || document.body).querySelector((obj as string).trim());
            } catch {
                result = null;
            }
        }
    }
    return result;
}
export default getEl;
