import {Matrix} from '../css/property-descriptors/transform';
import {Path} from './path';

export const enum EffectType {
    TRANSFORM = 0,
    CLIP = 1,
    OPACITY = 2
}

export const enum EffectTarget {
    BACKGROUND_BORDERS = 1 << 1,
    CONTENT = 1 << 2
}

export interface IElementEffect {
    readonly type: EffectType;
    readonly target: number;
}

export class TransformEffect implements IElementEffect {
    readonly type: EffectType = EffectType.TRANSFORM;
    readonly target: number = EffectTarget.BACKGROUND_BORDERS | EffectTarget.CONTENT;
    readonly offsetX: number;
    readonly offsetY: number;
    readonly matrix: Matrix;

    constructor(offsetX: number, offsetY: number, matrix: Matrix) {
        this.offsetX = offsetX;
        this.offsetY = offsetY;
        this.matrix = matrix;
    }
}

export class ClipEffect implements IElementEffect {
    readonly type: EffectType = EffectType.CLIP;
    readonly target: number;
    readonly path: Path[];

    constructor(path: Path[], target: EffectTarget) {
        this.target = target;
        this.path = path;
    }
}

export class OpacityEffect implements IElementEffect {
    readonly type: EffectType = EffectType.OPACITY;
    readonly target: number = EffectTarget.BACKGROUND_BORDERS | EffectTarget.CONTENT;
    readonly opacity: number;

    constructor(opacity: number) {
        this.opacity = opacity;
    }
}

export const isTransformEffect = (effect: IElementEffect): effect is TransformEffect =>
    effect.type === EffectType.TRANSFORM;
export const isClipEffect = (effect: IElementEffect): effect is ClipEffect => effect.type === EffectType.CLIP;
export const isOpacityEffect = (effect: IElementEffect): effect is OpacityEffect => effect.type === EffectType.OPACITY;
