/**
 * @since Last modified: 2024-09-01 23:48:23
 * @function augment
 * @description Extend properties and methods for the AXUI framework.
 * @param {object} arg  - The paramsters.
 * @param {string} arg.name  - The prop name of method name.
 * @param {'prop'|'method'} [arg.type]  - Extend type, prop or method.If it is empty it means extend prop.
 * @param {string} [arg.target]  - The name of the attribute under the ax object.If it is empty it means 'ax'.
 * @param {any} [arg.data]  - Extend content,function or others.
 * @returns {null} - Return null.
 * @see {@link https://codepen.io/axui/pen/RwzYmbQ|demo @ codepen}
 * @example
 * ax.augment({name,target,type,data});
 * <!--return null-->
 */
'use strict';
import { T_obj } from "../../../types/ax";
import isNull from "./isNull";
const augment = function (this: any, arg: T_obj) {
    if (isNull(arg) || !arg.name) return;
    let target;
    if (!arg.target || arg.target === 'ax') {
        target = this;
    } else {
        for (let k in this) {
            if (this[k].name === arg.target) {
                target = this[k];
                break;
            }
        }
        if (!target) throw new Error(`Cannot find the ${arg.target} property in the ax object!`);
    }
    if (arg.type === 'method') {
        target[target.prototype ? 'prototype' : '__proto__'][arg.name] = arg.data;
    } else {
        Reflect.set(target, arg.name, arg.data);
    }
}
export default augment;
