import PathNode from './path-node';
import NODE_MAP from './node-map';

var RectNode = (function (PathNode) {
    function RectNode () {
        PathNode.apply(this, arguments);
    }

    if ( PathNode ) RectNode.__proto__ = PathNode;
    RectNode.prototype = Object.create( PathNode && PathNode.prototype );
    RectNode.prototype.constructor = RectNode;

    RectNode.prototype.geometryChange = function geometryChange () {
        var geometry = this.srcElement.geometry();
        this.attr("x", geometry.origin.x);
        this.attr("y", geometry.origin.y);
        this.attr("width", geometry.size.width);
        this.attr("height", geometry.size.height);
        this.invalidate();
    };

    RectNode.prototype.size = function size () {
        return this.srcElement.geometry().size;
    };

    RectNode.prototype.origin = function origin () {
        return this.srcElement.geometry().origin;
    };

    RectNode.prototype.template = function template () {
        return "<rect " + (this.renderId()) + " " + (this.renderStyle()) + " " + (this.renderOpacity()) + " x='" + (this.origin().x) + "' y='" + (this.origin().y) + "' " +
                    "width='" + (this.size().width) + "' height='" + (this.size().height) + "' " + (this.renderStroke()) + " " +
                    (this.renderFill()) + " " + (this.renderDefinitions()) + " " + (this.renderTransform()) + " />";
    };

    return RectNode;
}(PathNode));

NODE_MAP.Rect = RectNode;

export default RectNode;