import { __assign, __spreadArray } from "tslib";
import fmtEvent from './fmtEvent';
function removeNullProps(props) {
    var newProps = {};
    for (var key in props) {
        if (props[key] !== null) {
            newProps[key] = props[key];
        }
    }
    return newProps;
}
function buildProperties(props) {
    var newProperties = {};
    for (var key in props) {
        var type = null;
        switch (typeof props[key]) {
            case 'string':
                type = String;
                break;
            case 'number':
                type = Number;
                break;
            case 'boolean':
                type = Boolean;
                break;
        }
        newProperties[key] = {
            type: type,
            value: props[key],
        };
    }
    return newProperties;
}
function mergeDefaultProps(defaultProps) {
    if (defaultProps === void 0) { defaultProps = {}; }
    return __assign({}, defaultProps);
}
function ComponentImpl(defaultProps, methods, data, mixins, instanceMethods) {
    Component(__assign({ props: removeNullProps(mergeDefaultProps(defaultProps)), methods: methods, mixins: mixins || [], data: data }, instanceMethods));
}
export function triggerEvent(instance, eventName, value, e) {
    // 首字母大写，然后加上 on
    var alipayCallbackName = 'on' + eventName.charAt(0).toUpperCase() + eventName.slice(1);
    var props = instance.props;
    if (props[alipayCallbackName]) {
        props[alipayCallbackName](value, fmtEvent(props, e));
    }
}
export function triggerEventOnly(instance, eventName, e) {
    // 首字母大写，然后加上 on
    var alipayCallbackName = 'on' + eventName.charAt(0).toUpperCase() + eventName.slice(1);
    var props = instance.props;
    if (props[alipayCallbackName]) {
        props[alipayCallbackName](fmtEvent(props, e));
    }
}
export function triggerEventValues(instance, eventName, values, e) {
    // 首字母大写，然后加上 on
    var alipayCallbackName = 'on' + eventName.charAt(0).toUpperCase() + eventName.slice(1);
    var props = instance.props;
    if (props[alipayCallbackName]) {
        props[alipayCallbackName].apply(props, __spreadArray(__spreadArray([], values, false), [fmtEvent(props, e)], false));
    }
}
export function triggerCatchEvent(instance, eventName, e) {
    var props = instance.props;
    if (props[eventName]) {
        props[eventName](fmtEvent(props, e));
    }
}
export function getValueFromProps(instance, propName) {
    var value;
    var props = instance.props;
    if (!propName) {
        return props;
    }
    if (typeof propName === 'string') {
        value = props[propName];
    }
    if (Array.isArray(propName)) {
        value = propName.map(function (name) { return props[name]; });
    }
    return value;
}
export { ComponentImpl as Component };
