/**
 * @since Last modified: 2024/06/03 16:38:01
 * @function getTransform
 * @description Retrieve the transform object from the style.transform property, including the rotate, scale, translate, and skew attributes.
 * @param {getEl} elem - Target selector.
 * @param {array} [props=['translate', 'scale', 'rotate', 'skew']]  - Collection of properties of the transform object.
 * @param {boolean} [instead=false]  - Whether to use the positioned left and top values instead of x and y values.
 * @returns {function} - Return a object , including the rotate, scale, translate, and skew attributes..
 * @see {@link https://codepen.io/axui/pen/dyEvBMw|demo @ codepen}
 * @example
 * ax.getTransform('#demo');
 * <!--return {rotate,scale,translate,skew}-->
 */
'use strict';
import getEl from "./getEl";
import style from "./style";
const getTransform = (elem, props = ['translate', 'scale', 'rotate', 'skew'], instead = false) => {
    let dom = getEl(elem), styles = style(dom), value = dom?.style?.transform, result = {
        rotate: 0,
        scale: { x: 1, y: 1 },
        translate: { x: 0, y: 0 },
        skew: { x: 0, y: 0 }
    };
    if (value) {
        let getReg = (type) => new RegExp(`${type}\\(([^\\)]+)\\)`), getText = (type) => value.match(getReg(type));
        if (props.includes('translate') && value.includes('translate') && getText('translate')) {
            if (getText('translate')[1].includes(',')) {
                let arr = getText('translate')[1].split(',').map((k) => parseInt(k));
                result.translate = { x: arr[0], y: arr[1] };
            }
            else {
                result.translate = { x: parseInt(getText('translate')[1]), y: 0 };
            }
        }
        if (props.includes('scale') && value.includes('scale') && getText('scale')) {
            if (getText('scale')[1].includes(',')) {
                let arr = getText('scale')[1].split(',').map((k) => parseFloat(k));
                result.scale = { x: arr[0], y: arr[1] };
            }
            else {
                result.scale = { x: parseFloat(getText('scale')[1]), y: parseFloat(getText('scale')[1]) };
            }
        }
        if (props.includes('rotate') && value.includes('rotate') && getText('rotate')) {
            result.rotate = parseFloat(getText('rotate')[1]);
        }
        if (props.includes('skew') && value.includes('skew') && getText('skew')) {
            if (getText('skew')[1].includes(',')) {
                let arr = getText('skew')[1].split(',').map((k) => parseFloat(k));
                result.skew = { x: arr[0], y: arr[1] };
            }
            else {
                result.skew = { x: parseFloat(getText('skew')[1]), y: 0 };
            }
        }
    }
    if (instead) {
        result.translate = { x: parseInt(styles.left), y: parseInt(styles.top) };
    }
    return result;
};
export default getTransform;
