var EditorProps = {
    LABEL: "label",
    getSheetProperties: function (type, data) {
        var props = [];
        switch (type) {
            case "group":
                EditorProps._appendProps(type, data, props, EditorProps.LABEL_PROPERTIES, {label_zh: "标签Label", label: "Label"})
                EditorProps._appendProps(type, data, props, EditorProps.INFO_PROPERTIES, {label_zh: "信息Info", label: "Info"})
                EditorProps._appendProps(type, data, props, EditorProps.GROUP_PROPERTIES, {label_zh: "分组Group(展开)", label: "Group(Expand)"})
                EditorProps._appendProps(type, data, props, EditorProps.NODE_PROPERTIES, {label_zh: "节点Node(关闭)", label: "Node(Collapse)"})
                break;
            case "node":
                EditorProps._appendProps(type, data, props, EditorProps.LABEL_PROPERTIES, {label_zh: "标签Label", label: "Label"})
                EditorProps._appendProps(type, data, props, EditorProps.INFO_PROPERTIES, {label_zh: "信息Info", label: "Info"})
                EditorProps._appendProps(type, data, props, EditorProps.NODE_PROPERTIES, {label_zh: "节点Node", label: "Node"})
                break;
            case "link":
                EditorProps._appendProps(type, data, props, EditorProps.LABEL_PROPERTIES, {label_zh: "标签Label", label: "Label"})
                EditorProps._appendProps(type, data, props, EditorProps.INFO_PROPERTIES, {label_zh: "信息Info", label: "Info"})
                EditorProps._appendProps(type, data, props, EditorProps.LINK_PROPERTIES, {label_zh: "链路Link", label: "Link"})
                break;
            case "view":
                EditorProps._appendProps(type, data, props, EditorProps.GVIEW_PROPERTIES, {label_zh: "全局属性", label: "Global"}, true)
                EditorProps._appendProps(type, data, props, EditorProps.LABEL_PROPERTIES, {label_zh: "标签Label", label: "Label"}, true)
                EditorProps._appendProps(type, data, props, EditorProps.INFO_PROPERTIES, {label_zh: "信息Info", label: "Info"}, true)
                EditorProps._appendProps(type, data, props, EditorProps.NODE_PROPERTIES, {label_zh: "节点Node", label: "Node"}, "node")
                EditorProps._appendProps(type, data, props, EditorProps.LINK_PROPERTIES, {label_zh: "链路Link", label: "Link"}, "link")
                EditorProps._appendProps(type, data, props, EditorProps.GROUP_PROPERTIES, {label_zh: "分组Group", label: "Group"}, "group")
                break;
        }
        EditorProps._updateLang(props, "name")
        return props;
    },
    _updateLang: function (props, field_name) {
        (props || []).forEach(function (item) {
            item[field_name] = item[EditorProps.LABEL] || item.label;
            if (EditorProps.LABEL.startsWith("label")) {
                delete item[EditorProps.LABEL]
            }
            delete item["label"]
            if (item.options) {
                EditorProps._updateLang(item.options, field_name);
            }
            EditorProps._updateLang(item.children, field_name);
        });
    },
    _appendProps: function (type, data, prop_arr, itemProps, groupLabel, prefix) {
        if (itemProps.length > 0) {
            var results = [];
            z.util.eachArray(itemProps, function (item) {
                EditorProps._appendPropItem(type, data, results, item, prefix);
            });
            if (groupLabel) {
                var item = {
                    children: results
                }
                if (z.type.isObject(groupLabel)) {
                    item = z.util.mergeObject(item, groupLabel);
                } else {
                    item.label = groupLabel;
                }
                prop_arr.push(item)
            } else {
                z.util.mergeArray(prop_arr, results);
            }
        }
    },
    _appendPropItem: function (type, data, prop_arr, item, prefix) {
        if (item.isVisible) {
            if (item.isVisible(type, data) === false) {
                return;
            }
        }
        var property = item.property;
        var children = item.children;
        if (prefix && property) {
            if (prefix === true) {
                property = item.view_property || property;
            } else {
                property = item.view_property || (prefix + "_" + property);
            }
        }
        var _children = [];
        if (children) {
            children.forEach(function (childItem) {
                EditorProps._appendPropItem(type, data, _children, childItem, prefix);
            });
        }
        var funcMap = z.util.filterObject(item, function (key, value) {
            return z.type.isFunction(value);
        })
        delete funcMap.isVisible;
        item = JSON.parse(JSON.stringify(item));
        item = z.util.mergeObject(item, funcMap);
        if (_children.length > 0) {
            item.children = _children;
        }
        if (property) {
            item.property = property;
        }
        prop_arr.push(item);
        return item;
    },
    _getOptions: function (arr, withNullOpt) {
        arr = z.util.mergeArray([], arr);
        if (withNullOpt === true) {
            arr.unshift({label: "", value: ""});
        }
        return arr;
    },
    _getBaseShapeOptions: function (withNullOpt) {
        return EditorProps._getOptions(EditorProps.SHAPE_TYPES, withNullOpt);
    },
    _appendJSONProp: function (options) {
        return z.util.mergeObject(options, {
            getValue: function (value) {
                if (value) {
                    return JSON.parse(value);
                }
            },
            setValue: function (propertyRowData, value, valueField) {
                if (value) {
                    value = JSON.stringify(value);
                }
                propertyRowData.set(valueField, value);
            }
        });
    },
    _getArrowShapeOptions: function (withNullOpt) {
        // return z.util.mergeArray(EditorProps._getBaseShapeOptions(withNullOpt), EditorProps.ARROW_TYPES)
        return z.util.mergeArray(EditorProps._getOptions(EditorProps.ARROW_TYPES, withNullOpt), EditorProps.SHAPE_TYPES)
    },
    _appendDashProp: function (item, dash_items) {
        z.util.mergeObject(item, {
            type: "select",
            options: EditorProps._getOptions(dash_items || ["[6,1]", "[6,2]", "[6,3]"], true)
        })
        EditorProps._appendJSONProp(item);
        return item;
    }
};
z.util.mergeObject(EditorProps, {
    LABEL_POSITIONS: [
        {label_zh: "中间", label: "center", value: "center"},
        {label_zh: "上", label: "Top", value: "top"},
        {label_zh: "下", label: "Bottom", value: "bottom"},
        {label_zh: "左", label: "Left", value: "left"},
        {label_zh: "右", label: "Right", value: "right"}
    ],
    ARROW_TYPES: [
        {label_zh: "箭头", label: "Arrow", value: "arrow"},
        {label_zh: "燕尾形箭头", label: "Stealth Arrow", value: "stealth_arrow"},
        {label_zh: "开放形箭头", label: "Open Arrow", value: "open_arrow"}
    ],
    LINK_TYPES: [
        {
            label_zh: "折线", label: "Right Angle", children: [
                {label_zh: "横-竖", label: "HV", value: "ra_hv"},
                {label_zh: "竖-横", label: "VH", value: "ra_vh"},
                {label_zh: "上", label: "Top", value: "ra_top"},
                {label_zh: "下", label: "Bottom", value: "ra_bottom"},
                {label_zh: "左", label: "Left", value: "ra_left"},
                {label_zh: "右", label: "Right", value: "ra_right"},
                {label_zh: "横-竖-横", label: "HVH", value: "ra_hvh"},
                {label_zh: "竖-横-竖", label: "VHV", value: "ra_vhv"}]
        },
        {
            label_zh: "曲线", label: "Curve", children: [
                {label_zh: "二次", label: "Quadratic", value: "quadratic"},
                {label_zh: "三次", label: "Cubic", value: "cubic"}]
        }
    ],

    SHAPE_TYPES: [
        {label_zh: "矩形", label: "Rect", value: "rect"},
        {label_zh: "圆形", label: "Circle", value: "circle"},
        {label_zh: "椭圆", label: "Ellipse", value: "ellipse"},
        {label_zh: "圆角矩形", label: "RoundRect", value: "roundrect"},
        {label_zh: "三角形", label: "Triangle", value: "triangle"},
        {label_zh: "直角三角形", label: "Right Triangle", value: "right_triangle"},
        {label_zh: "菱形", label: "Diamond", value: "diamond"},
        {label_zh: "五边形", label: "Pentagon", value: "pentagon"},
        {label_zh: "六边形", label: "Hexagon", value: "hexagon"},
        {label_zh: "星形", label: "Star", value: "star"},
        {label_zh: "平行四边形", label: "Parallelogram", value: "parallelogram"},
        {label_zh: "云", label: "Cloud", value: "cloud"}
    ],
    SELECT_STYLES: [
        {label_zh: "边框", label: "Border(Default)", value: "border"},
        {label_zh: "阴影", label: "Shadow", value: "shadow"}
    ],
    LINE_CAPS: [
        {label_zh: "无线帽(默认)", label: "butt(Default)", value: "butt"},
        {label_zh: "圆形线帽", label: "round", value: "round"},
        {label_zh: "正方形线帽", label: "square", value: "square"}
    ],
    LINE_JOINS: [
        {label_zh: "尖角(默认)", label: "miter(Default)", value: "miter"},
        {label_zh: "圆角", label: "round", value: "round"},
        {label_zh: "斜角", label: "bevel", value: "bevel"}
    ],
    FONTS: [
        "16px arial, sans-serif",
        "italic 20px arial, serif",
        "italic small-caps bold 16px/2 cursive",
        "small-caps bold 24px/1 sans-serif",
        "caption"
    ],
    GROUP_SHAPE_TYPES: [
        {label_zh: "矩形", label: "Rect", value: "rect"},
        {label_zh: "圆角矩形", label: "RoundRect", value: "roundrect"},
        {label_zh: "圆形", label: "Circle", value: "circle"},
        {label_zh: "椭圆", label: "Ellipse", value: "ellipse"},
        {label_zh: "平行四边形", label: "Parallelogram", value: "parallelogram"},
        {label_zh: "凸多边形", label: "CovexHull", value: "covexhull"}],

    NODE_IMAGES: [
        {label: "Router", value: "../_icons/topology/cisco/router.svg"},
        {label: "Layer3 Switch", value: "../_icons/topology/cisco/layer3_switch.svg"},
        {label: "Layer2 Switch", value: "../_icons/topology/cisco/workgroup_switch.svg"}]

})
z.util.mergeObject(EditorProps, {
    LABEL_PROPERTIES: [
        {label_zh: "显示标签", label: "Label Visible", property: "label_visible", type: "check"},
        {label_zh: "颜色", label: "Label Color", property: "label_fill", type: "color"},
        {label_zh: "字体", label: "Label Font", property: "label_font", type: "select", options: EditorProps._getOptions(EditorProps.FONTS, true)},
        {
            label_zh: "位置(节点)", label: "Label Position(Node)", property: "label_position", type: "select",
            options: EditorProps._getOptions(EditorProps.LABEL_POSITIONS, true),
            isVisible: function (type, data) {
                return z.type.isView(data) || z.type.isNode(data);
            }
        },
        {label_zh: "横向偏移", label: "Label Offset X", property: "label_offset_x", type: "number", attributes: {min: 1, max: 20, step: 1}},
        {label_zh: "竖向偏移", label: "Label Offset Y", property: "label_offset_y", type: "number", attributes: {min: 1, max: 20, step: 1}},
        {
            label_zh: "旋转(Link)", label: "Label Rotation(Link)", property: "label_rotation", type: "check", default_value: true,
            isVisible: function (type, data) {
                return z.type.isView(data) || z.type.isLink(data);
            }
        },
        {
            label_zh: "标签填充", label: "Label Box", children: [
                {label_zh: "标签填充", label: "Box Fill", property: "label_box_fill", type: "color"},
                {label_zh: "标签边框颜色", label: "Box Stroke", property: "label_box_stroke", type: "color"},
                {label_zh: "标签边框线宽", label: "Box Stroke Line Width", property: "label_box_stroke_line_width", type: "number", attributes: {min: 0, max: 10, step: 1}},
                EditorProps._appendDashProp({label_zh: "标签边框虚线", label: "Box Stroke Line Dash", property: "label_box_stroke_line_dash"})
            ]
        }
    ],
    INFO_PROPERTIES: [
        {label_zh: "显示信息", label: "Info Visible", property: "info_visible", type: "check"},
        {label_zh: "颜色", label: "Info Color", property: "info_fill", type: "color"},
        {label_zh: "字体", label: "Info Font", property: "info_font", type: "select", options: EditorProps._getOptions(EditorProps.FONTS, true)},
        {label_zh: "横向偏移", label: "Info Offset X", property: "info_offset_x", type: "number", attributes: {min: 1, max: 20, step: 1}},
        {label_zh: "竖向偏移", label: "Info Offset Y", property: "info_offset_y", type: "number", attributes: {min: 1, max: 20, step: 1}},
        {
            label_zh: "信息填充", label: "Info Box", children: [
                {label_zh: "信息填充", label: "Box Fill", property: "info_box_fill", type: "color"},
                {label_zh: "信息边框颜色", label: "Box Stroke", property: "info_box_stroke", type: "color"},
                {label_zh: "信息边框线宽", label: "Box Stroke Line Width", property: "info_box_stroke_line_width", type: "number", attributes: {min: 0, max: 10, step: 1}},
                EditorProps._appendDashProp({label_zh: "信息边框虚线", label: "Box Stroke Line Dash", property: "info_box_stroke_line_dash"})
            ]
        }
    ],
    NODE_PROPERTIES: [
        {
            label_zh: "X坐标", label: "X", property: "x", type: "number", attributes: {min: 1, step: 1}, value_type: "int",
            isVisible: function (type, data) {
                return z.type.isNode(data) && !z.type.isGroup(data);
            }
        },
        {
            label_zh: "Y坐标", label: "Y", property: "y", type: "number", attributes: {min: 1, step: 1}, value_type: "int",
            isVisible: function (type, data) {
                return z.type.isNode(data) && !z.type.isGroup(data);
            }
        },
        {label_zh: "宽", label: "Width", property: "width", type: "number", attributes: {min: 1, step: 1}},
        {label_zh: "高", label: "Height", property: "height", type: "number", attributes: {min: 1, step: 1}},
        {
            label_zh: "形状", label: "Shape", property: "shape", type: "select",
            options: EditorProps._getBaseShapeOptions(true)
        },
        {label_zh: "透明度", label: "Alpha", property: "alpha", view_property: "data_alpha", type: "number", attributes: {min: 0, max: 1, step: 0.1}},
        {label_zh: "旋转", label: "Rotation", property: "rotation", view_property: "rotation", type: "number", attributes: {min: 0, max: 360, step: 1}},
        {
            label_zh: "图标", label: "Image", property: "image", type: "select", is_gv: false,
            options: EditorProps._getOptions(EditorProps.NODE_IMAGES, true),
            isVisible: function (type, data) {
                return z.type.isNode(data);
            }
        },
        {
            label_zh: "渲染样式", label: "Render Style", children: [
                {label_zh: "填充颜色", label: "Fill", property: "fill", type: "color"},
                {label_zh: "边框颜色", label: "Stroke", property: "stroke", type: "color"},
                {label_zh: "边框线宽", label: "Stroke Line Width", property: "stroke_line_width", type: "number", attributes: {min: 0, max: 10, step: 1}},
                EditorProps._appendDashProp({label_zh: "边框虚线", label: "Stroke Line Dash", property: "stroke_line_dash"})
            ]
        },
        {
            label_zh: "箭头样式(路径)", label: "Arrow Style(Path)", children: [
                {label_zh: "结束箭头形状", label: "End Arrow Shape", property: "end_arrow_shape", type: "select", options: EditorProps._getArrowShapeOptions(true)},
                {label_zh: "结束箭头大小", label: "End Arrow Size", property: "end_arrow_size", type: "select", options: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]},
                {label_zh: "结束箭头偏移", label: "End Arrow Offset", property: "end_arrow_offset", type: "number", attributes: {min: 0, max: 20, step: 0.1}},
                {label_zh: "开始箭头形状", label: "Begin Arrow Shape", property: "begin_arrow_shape", type: "select", options: EditorProps._getArrowShapeOptions(true)},
                {label_zh: "开始箭头大小", label: "Begin Arrow Size", property: "begin_arrow_size", type: "select", options: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]},
                {label_zh: "开始箭头偏移", label: "Begin Arrow Offset", property: "begin_arrow_offset", type: "number", attributes: {min: 0, max: 20, step: 0.1}}
            ]
        },
        {
            label_zh: "外边框样式", label: "Outline Style", children: [
                {label_zh: "外边框色", label: "Outline Stroke", property: "outline_stroke", type: "color"},
                {label_zh: "外边框线宽", label: "Outline Stroke Line Width", property: "outline_stroke_line_width", type: "number", attributes: {min: 0, max: 10, step: 1}},
                EditorProps._appendDashProp({label_zh: "外边框虚线", label: "Outline Stroke Line Dash", property: "outline_stroke_line_dash"})
            ]
        },
        {
            label_zh: "类型样式", label: "By Type Style", children: [
                EditorProps._appendJSONProp({
                    label_zh: "圆角矩形半径", label: "RoundRect Radius", property: "roundrect_radius", view_property: "roundrect_radius",
                    type: "select", options: EditorProps._getOptions(["10", "[10]", "[10,20]", "[10,20,30]", "[10,20,30,40]"])
                })
            ]
        }
    ],
    LINK_PROPERTIES: [
        {
            label_zh: "类型", label: "Type", property: "type", type: "select",
            options: EditorProps._getOptions(EditorProps.LINK_TYPES, true)
        },
        {label_zh: "颜色", label: "Stroke", property: "stroke", type: "color"},
        {label_zh: "线宽", label: "Stroke Line Width", property: "stroke_line_width", type: "number", attributes: {min: 0, max: 10, step: 1}},
        EditorProps._appendDashProp({label_zh: "虚线", label: "Stroke Line Dash", property: "stroke_line_dash"}),
        {label_zh: "透明度", label: "Alpha", property: "alpha", view_property: "data_alpha", type: "number", attributes: {min: 0, max: 1, step: 0.1}},

        {label_zh: "起始偏移", label: "From Offset", property: "from_offset", type: "number", attributes: {min: 0, max: 20, step: 1}},
        {label_zh: "结束偏移", label: "To Offset", property: "to_offset", type: "number", attributes: {min: 0, max: 20, step: 1}},
        {label_zh: "拐角半径", label: "Corner Radius", property: "corner_radius", type: "number", attributes: {min: 0, max: 20, step: 1}},
        {label_zh: "曲线弯曲度", label: "Curvature", property: "curvature", type: "number", attributes: {min: 0, max: 1, step: 0.1}},
        {
            label_zh: "箭头", label: "Arrow", children: [
                {label_zh: "目的箭头形状", label: "To Arrow Shape", property: "to_arrow_shape", type: "select", options: EditorProps._getArrowShapeOptions(true)},
                {label_zh: "目的箭头大小", label: "To Arrow Size", property: "to_arrow_size", type: "select", options: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]},
                {label_zh: "目的箭头偏移", label: "To Arrow Offset", property: "to_arrow_offset", type: "number", attributes: {min: 0, max: 20, step: 0.1}},
                {label_zh: "源箭头形状", label: "From Arrow Shape", property: "from_arrow_shape", type: "select", options: EditorProps._getArrowShapeOptions(true)},
                {label_zh: "源箭头大小", label: "From Arrow Size", property: "from_arrow_size", type: "select", options: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]},
                {label_zh: "源箭头偏移", label: "From Arrow Offset", property: "from_arrow_offset", type: "number", attributes: {min: 0, max: 20, step: 0.1}}
            ]
        }
    ],
    GROUP_PROPERTIES: [
        {
            label_zh: "展开形状", label: "Expand Shape", property: "expand_shape", type: "select",
            options: EditorProps._getOptions(EditorProps.GROUP_SHAPE_TYPES, true)
        },
        {label_zh: "展开边距", label: "Expand Padding", property: "expand_padding", type: "number", attributes: {min: 1, max: 50, step: 1}},
        {label_zh: "展开填充色", label: "Expand Fill", property: "expand_fill", type: "color"},
        {label_zh: "展开边框色", label: "Expand Stroke", property: "expand_stroke", type: "color"},
        {label_zh: "展开边框线宽", label: "Expand Stroke Line Width", property: "expand_stroke_line_width", type: "number", attributes: {min: 1, max: 10, step: 1}},
        EditorProps._appendDashProp({label_zh: "展开边框虚线", label: "Expand Stroke Line Dash", property: "expand_stroke_line_dash"})
    ],

    GVIEW_PROPERTIES: [
        {
            label_zh: "网格线", label: "Grid Line",
            children: [
                {label_zh: "显示网格线", label: "Grid Line Visible", property: "grid_line_visible", type: "check"},
                {label_zh: "网格线间距", label: "Grid Line Space", property: "grid_line_space", type: "number", attributes: {min: 10, max: 100, step: 10}}
            ]
        },
        {
            label_zh: "线段样式", label: "Line Style",
            children: [
                {label_zh: "末端线帽样式", label: "Line Cap", property: "line_cap", type: "select", options: EditorProps._getOptions(EditorProps.LINE_CAPS, true)},
                {label_zh: "线交点样式", label: "Line Join", property: "line_join", type: "select", options: EditorProps._getOptions(EditorProps.LINE_JOINS, true)}
            ]
        },
        {
            label_zh: "选中样式", label: "Select Style",
            children: [
                {label_zh: "选中样式", label: "Select Style", property: "select_style", type: "select", options: EditorProps._getOptions(EditorProps.SELECT_STYLES, true)},
                {label_zh: "选中边框边距", label: "Select Border Padding", property: "select_border_padding", type: "number", attributes: {min: 1, max: 20, step: 1}},
                {label_zh: "选中边框色", label: "Select Border Stroke", property: "select_border_stroke", type: "color"},
                {label_zh: "选中边框线宽", label: "Select Border Line Width", property: "select_border_stroke_line_width", type: "number", attributes: {min: 1, max: 10, step: 1}},
                EditorProps._appendDashProp({label_zh: "选中边框虚线", label: "Select Border Line Dash", property: "select_border_stroke_line_dash"}),

                {label_zh: "选中阴影模糊", label: "Select Shadow Blur", property: "select_shadow_blur", type: "number", attributes: {min: 1, max: 20, step: 1}},
                {label_zh: "选中阴影颜色", label: "Select Shadow Color", property: "select_shadow_color", type: "color"},
                {label_zh: "选中阴影横向偏移", label: "Select Shadow Offset X", property: "select_shadow_offset_x", type: "number", attributes: {min: 1, max: 20, step: 1}},
                {label_zh: "选中阴影竖向偏移", label: "Select Shadow Offset Y", property: "select_shadow_offset_y", type: "number", attributes: {min: 1, max: 20, step: 1}}
            ]
        },
        {
            label_zh: "其他", label: "Other Style",
            children: [
                {label_zh: "链路间距", label: "Link Gap", property: "link_gap", type: "number", attributes: {min: 10, max: 30, step: 1}},
                {label_zh: "选中范围", label: "Hit Padding", property: "hit_padding", type: "number", attributes: {min: 0, max: 5, step: 1}}
            ]
        }
    ]
})