/*
 * Copyright (c) 2012-2016. Sencha Inc.
 */

"use strict";

var Fashion = require('../Base.js');
var Type = require('./Type.js');
var Numeric = require('./Numeric.js');

class ColorStop extends Type {
    constructor(color, stop) {
        super();
        this.color = color;
        this.stop = stop;
    }

    doVisit(visitor) {
        visitor.colorstop(this);
    }

    descend(visitor) {
        visitor.visit(this.color);
        visitor.visit(this.stop);
    }

    toString() {
        var string = this.color.toString(),
            stop = this.stop;

        if (stop) {
            stop = stop.copy();
            string += ' ';
            if (!stop.unit) {
                stop.value *= 100;
                stop.unit = '%';
            }
            string += stop.toString();
        }

        return string;
    }

    toOriginalWebkitString() {
        var stop = this.stop;

        if (!stop) {
            stop = new Numeric(0, '%');
        }

        stop = stop.copy();
        if (!stop.unit) {
            stop.value *= 100;
            stop.unit = '%';
        }

        return 'color-stop(' + stop.toString() + ', ' + this.color.toString() + ')';
    }

    copy() {
        return new ColorStop(this.color, this.stop);
    }
}

Fashion.apply(ColorStop.prototype, {
    type: 'colorstop',
    $isFashionColorStop: true,
    $canUnbox: false,
    color: null,
    stop: null
});

module.exports = ColorStop;
