/**
 * @since Last modified: 2024/04/20 14:42:05
 * @function getBetweenEls
 * @description Find the middle node from the start to the end node.
 * @param  {string} selector - Selector for the middle node.
 * @param  {string|HTMLElement} start - Selector for the start node.Usage is the same as getEl.
 * @param  {string|HTMLElement} end - Selector for the end node.Usage is the same as getEl.
 * @param  {string|HTMLElement} [parent=document.body] - Selector for the parent node.Usage is the same as getEl.
 * @returns {boolean} Return between elements.
 * @see {@link https://codepen.io/axui/pen/LYvgQEd|demo @ codepen}
 * @example
 * ax.getBetweenEls({selector:'h2',start:'#start',end:'#end'});
 * <!--return elements array-->
 */
'use strict';
import getEl from "./getEl";
import getEls from "./getEls";
const getBetweenEls = ({ selector, start, end, parent }) => {
    let parentEl = getEl(parent) || document.body, startEl = getEl(start), endEl = getEl(end), els = getEls(selector, parentEl), result = [];
    if (els.length === 0) {
        return result;
    }
    if (startEl && !endEl) {
        result = els.filter((k) => {
            return startEl.compareDocumentPosition(k) & Node.DOCUMENT_POSITION_FOLLOWING;
        });
    }
    else if (!startEl && endEl) {
        result = els.filter((k) => {
            return endEl.compareDocumentPosition(k) & Node.DOCUMENT_POSITION_PRECEDING;
        });
    }
    else if (startEl && endEl) {
        result = els.filter((k) => {
            return (startEl.compareDocumentPosition(k) & Node.DOCUMENT_POSITION_FOLLOWING) && endEl.compareDocumentPosition(k) & Node.DOCUMENT_POSITION_PRECEDING;
        });
    }
    return result;
};
export default getBetweenEls;
