import { Color, LayoutBase, Property } from '@nativescript/core';
export const paintStyleProperty = new Property({
    name: 'paintStyle',
    defaultValue: 'fill',
});
export const strokeWidthProperty = new Property({
    name: 'strokeWidth',
    defaultValue: 1,
});
export class Paint extends LayoutBase {
    constructor() {
        super(...arguments);
        this._paintStyleDirty = false;
        this._inGroup = false;
    }
    _addCanvas(canvas) {
        this._canvas = canvas;
    }
    [paintStyleProperty.setNative](value) {
        this._paintStyleDirty = true;
    }
    _getPaintStyle() {
        const paintStyle = this.paintStyle;
        if (paintStyle !== 'fill') {
            return paintStyle;
        }
        if (this._inGroup) {
            return this.parent.paintStyle;
        }
        return 'fill';
    }
    _getColor() {
        const color = this.color ?? new Color('black');
        const hex = color.hex;
        if (color.name !== 'black' || hex !== '#000000') {
            return hex;
        }
        return this.parent?.color?.hex ?? hex;
    }
    draw() {
        const color = this._getColor();
        const context = this._canvas.getContext('2d');
        context.lineWidth = this.strokeWidth;
        const style = this._getPaintStyle();
        if (style === 'fill') {
            context.fillStyle = color;
            context.fill();
        }
        else if (style === 'stroke') {
            context.strokeStyle = color;
            context.stroke();
        }
    }
}
paintStyleProperty.register(Paint);
strokeWidthProperty.register(Paint);
//# sourceMappingURL=Paint.js.map