import {Line} from '@int/geotoolkit/scene/shapes/Line';
import {Point} from '@int/geotoolkit/util/Point';
import {ComponentNode} from '@int/geotoolkit/schematics/scene/ComponentNode';
import {Rect} from '@int/geotoolkit/util/Rect';
import {obfuscate} from '@int/geotoolkit/lib';

class NodeTubingBW extends ComponentNode {
    constructor (data) {
        super();
        this._linePos = new Line({
            'from': new Point(0, 0),
            'to': new Point(0, 100),
            'linestyle': 'red'
        });
        this._lineNeg = new Line({
            'from': new Point(100, 0),
            'to': new Point(100, 100),
            'linestyle': 'blue'
        });
        super.setData(data);
        this.addChild([this._linePos, this._lineNeg]);
    }

    setGeometryData (geometry) {
        if (!geometry) {
            return;
        }
        super.setGeometryData(geometry);

        // const radInner = geometry['diameter']['inner'] / 2;
        const radOuter = geometry['diameter']['outer'] / 2;
        const depthMin = geometry['depth']['from'];
        const depthMax = geometry['depth']['to'];
        this.setNotification(false);
        this._linePos.setLine({
            'from': new Point(radOuter, depthMin),
            'to': new Point(radOuter, depthMax)
        });
        this._lineNeg.setLine({
            'from': new Point(-radOuter, depthMin),
            'to': new Point(-radOuter, depthMax)
        });
        this.setNotification(true);
        this._geometryBounds = new Rect(-radOuter, depthMin, radOuter, depthMax);
    }

    checkCollision (context) {
        this.updateShapeGeometry(context);
        return super.checkCollision(context);
    }

    render (context) {
        this.updateShapeGeometry(context);
        super.render(context);
    }

    getGeometryBounds () {
        return this._geometryBounds;
    }
}
obfuscate(NodeTubingBW);
export {NodeTubingBW};

