import { isFunction, isObject, isString, isNumber, isBoolean, isArray } from '@antv/util';
/**
 * 获得映射函数
 * @param mappingFields
 * @param callback
 */
export function getMappingFunction(mappingFields, callback) {
    return function () {
        var args = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            args[_i] = arguments[_i];
        }
        var params = {};
        mappingFields.forEach(function (f, index) {
            params[f] = args[index];
        });
        delete params['undefined'];
        return callback(params);
    };
}
var MappingAttribute = /** @class */ (function () {
    function MappingAttribute() {
    }
    MappingAttribute.shape = function (layer, shape) {
        /**
         * shape 的几种情况
         * layer.shape('cicle');
         * layer.shape('shape', ['cicle', 'square']);
         * layer.shape('x', (x) => 'cicle');
         * layer.shape('x*y', (x, y) => 'cicle');
         */
        if (isString(shape)) {
            layer.shape(shape);
        }
        else if (isFunction(shape)) {
            // TODO: shape mappingFields
            var mappingFields = [];
            layer.shape(mappingFields.join('*'), getMappingFunction(mappingFields, shape));
        }
        else if (isObject(shape)) {
            var field = shape.field ? shape.field : '';
            if (isFunction(shape.value)) {
                var mappingFields = isArray(field) ? field : field.split('*');
                layer.shape(field, getMappingFunction(mappingFields, shape.value));
            }
            else {
                layer.shape(field, shape.value);
            }
            // scale
            if (isString(field) && shape.scale) {
                MappingAttribute.scale(layer, field, shape.scale);
            }
        }
    };
    MappingAttribute.size = function (layer, size) {
        /**
         * size 的几种情况
         * layer.size(10);
         * layer.size('size', [10, 20]);
         * layer.size('x', (x) => 10);
         * layer.size('x*y', (x, y) => 10);
         */
        if (isNumber(size)) {
            layer.size(size);
        }
        else if (isArray(size)) {
            layer.size(size);
        }
        else if (isFunction(size)) {
            // TODO: size mappingFields
            var mappingFields = [];
            layer.size(mappingFields.join('*'), getMappingFunction(mappingFields, size));
        }
        else if (isObject(size)) {
            var field = size.field ? size.field : '';
            if (isFunction(size.value)) {
                var mappingFields = isArray(field) ? field : field.split('*');
                layer.size(field, getMappingFunction(mappingFields, size.value));
            }
            else {
                layer.size(field, size.value);
            }
            // scale
            if (isString(field) && size.scale) {
                MappingAttribute.scale(layer, field, size.scale);
            }
        }
    };
    MappingAttribute.color = function (layer, color) {
        /**
         * color 的几种情况
         * layer.color('red');
         * layer.color('color', ['red', 'blue']);
         * layer.color('x', (x) => 'red');
         * layer.color('x*y', (x, y) => 'red');
         */
        if (isString(color)) {
            layer.color(color);
        }
        else if (isFunction(color)) {
            // TODO: color mappingFields
            var mappingFields = [];
            layer.color(mappingFields.join('*'), getMappingFunction(mappingFields, color));
        }
        else if (isObject(color)) {
            var field = color.field ? color.field : '';
            if (isFunction(color.value)) {
                var mappingFields = isArray(field) ? field : field.split('*');
                layer.color(field, getMappingFunction(mappingFields, color.value));
            }
            else {
                layer.color(field, color.value);
            }
            // scale
            if (isString(field) && color.scale) {
                MappingAttribute.scale(layer, field, color.scale);
            }
        }
    };
    MappingAttribute.scale = function (layer, field, cfg) {
        /**
         * scale 的几种情况
         * layer.scale('name', {type: 'cat'});
         * layer.scale({name: {type: 'cat'}, value: {type: 'linear'}});
         */
        layer.scale(field, cfg);
    };
    MappingAttribute.rotate = function (layer, rotate) {
        /**
         * rotate 的几种情况
         * layer.rotate(45);
         * layer.rotate('rotate', [45, 90]);
         * layer.rotate('x', (x) => 45);
         * layer.rotate('x*y', (x, y) => 45);
         */
        if (isString(rotate)) {
            // TODO: L7 rotate
            // layer.rotate(rotate);
        }
        else if (isFunction(rotate)) {
            // TODO: rotate isFunction
        }
        else if (isObject(rotate)) {
            // TODO: L7 rotate
        }
    };
    MappingAttribute.texture = function (layer, texture) {
        /**
         * texture 的几种情况
         * layer.texture('plane');
         */
        if (isString(texture)) {
            layer.texture(texture);
        }
    };
    MappingAttribute.animate = function (layer, animate) {
        /**
         * animate 的几种情况
         * layer.animate(true);
         * layer.animate({rings: 10});
         */
        if (isBoolean(animate) || isObject(animate)) {
            layer.animate(animate);
        }
    };
    MappingAttribute.filter = function (layer, filter) {
        /**
         * scale 的几种情况
         * layer.filter('name', ({ name }) => name === 'name');
         */
        var field = filter.field ? filter.field : '';
        var mappingFields = isArray(field) ? field : field.split('*');
        layer.filter(mappingFields.join('*'), getMappingFunction(mappingFields, filter.value));
    };
    MappingAttribute.style = function (layer, style) {
        style && layer.style(style);
    };
    MappingAttribute.state = function (layer, state) {
        var active = state.active, select = state.select;
        active && layer.active(active);
        select && layer.select(select);
    };
    return MappingAttribute;
}());
export { MappingAttribute };
//# sourceMappingURL=index.js.map