/**
 * @since Last modified: 2024-08-06 09:30:35
 * @function getRectPoint
 * @description Determine whether the current touch point is outside the element's rectangular boundary.
 * @param {object} ev  - Can be any data
 * @param {getEl} elem  - Target element.
 * @returns {boolean}  - Return true or false
 * @see {@link https://codepen.io/axui/pen/wvLKRdx|demo @ codepen}
 * @example
 */
'use strict';
import { T_obj, T_sel } from '../../../types/ax';
import getEl from './getEl';
import isMobi from './isMobi';
const getRectPoints = (ev: T_obj, elem: T_sel): string[] => {
    let el = getEl(elem), result: string[] = [];
    if (!el || !ev) return result;
    let point = isMobi ? { x: ev.targetTouches[0].clientX, y: ev.targetTouches[0].clientY } : { x: ev.clientX, y: ev.clientY },
        x = point.x,
        y = point.y,
        size = { w: el.offsetWidth, h: el.offsetHeight },
        lt = { x: el.getBoundingClientRect().left, y: el.getBoundingClientRect().top },
        rb = { x: lt.x + size.w, y: lt.y + size.h },
        range = { 'h1/3': lt.y + size.h / 3, 'h1/2': lt.y + size.h / 2, 'h2/3': lt.y + size.h * 2 / 3, 'w1/3': lt.x + size.w / 3, 'w1/2': lt.x + size.w / 2, 'w2/3': lt.x + size.w * 2 / 3 };
    if (x >= lt.x && x <= rb.x && y >= lt.y && y <= rb.y) {
        result.push('inside');
        if (y < range['h1/3']) {
            result.push('t/3');
        } else if (y >= range['h1/3'] && y < range['h1/2']) {
            result.push('t/2');
        } else if (y >= range['h2/3']) {
            result.push('b/3');
        } else if (y >= range['h1/2']) {
            result.push('b/2');
        }
        if (x < range['w1/3']) {
            result.push('l/3');
        } else if (x >= range['w1/3'] && x < range['w1/2']) {
            result.push('l/2');
        } else if (x >= range['w2/3']) {
            result.push('r/3');
        } else if (x >= range['w1/2']) {
            result.push('r/2');
        }
    } else {
        result = ['outside'];
    }
    return result;
}
export default getRectPoints;
