import { Property } from '@nativescript/core';
import { Paint } from '../Paint';
import { Path2D } from '../../Canvas2D';
export const pathProperty = new Property({
    name: 'path',
    valueChanged(target, oldValue, newValue) {
        target.invalidate();
    },
});
export const startProperty = new Property({
    name: 'start',
    valueChanged(target, oldValue, newValue) {
        target.invalidate();
    },
});
export const endProperty = new Property({
    name: 'end',
    valueChanged(target, oldValue, newValue) {
        target.invalidate();
    },
});
export class Path extends Paint {
    constructor() {
        super(...arguments);
        this._path = new Path2D();
    }
    [pathProperty.setNative](value) {
        if (value) {
            this._path = new Path2D(value);
        }
    }
    [startProperty.setNative](value) {
        if (typeof value === 'number' && typeof this.end === 'number') {
            this._path.trim(value, this.end);
        }
    }
    [endProperty.setNative](value) {
        if (typeof value === 'number' && typeof this.start === 'number') {
            this._path.trim(this.start, value);
        }
    }
    draw() {
        if (this._path === undefined) {
            return;
        }
        const override_color = this.parent._overrideColor;
        const context = this._canvas.getContext('2d');
        const style = this._getPaintStyle();
        const color = this._getColor();
        if (style === 'fill') {
            context.fillStyle = color;
            context.fill(this._path);
        }
        else if (style === 'stroke') {
            context.lineWidth = this._getStrokeWidth();
            context.lineJoin = this._getStrokeJoin();
            context.strokeStyle = color;
            context.stroke(this._path);
        }
    }
    addPath(path, transform) {
        this._path.addPath(path, transform);
    }
    arc(x, y, radius, startAngle, endAngle, anticlockwise = false) {
        this._path.arc(x, y, radius, startAngle, endAngle, anticlockwise ?? false);
    }
    arcTo(x1, y1, x2, y2, radius) {
        this._path.arcTo(x1, y1, x2, y2, radius);
    }
    bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
        this._path.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
    }
    closePath() {
        this._path.closePath();
    }
    ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise = false) {
        this._path.ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise ?? false);
    }
    lineTo(x, y) {
        this._path.lineTo(x, y);
    }
    moveTo(x, y) {
        this._path.moveTo(x, y);
    }
    quadraticCurveTo(cpx, cpy, x, y) {
        this._path.quadraticCurveTo(cpx, cpy, x, y);
    }
    rect(x, y, width, height) {
        this._path.rect(x, y, width, height);
    }
    roundRect(x, y, width, height, radii) {
        this._path.roundRect(x, y, width, height, radii);
    }
}
pathProperty.register(Path);
//# sourceMappingURL=Path.js.map