export function createReferenceClass(options) {

    let x, y;
    let referenceClassGroup;
    let textGroup;

    let labels;
    let lang;
    let colours;
    let font;

    function referenceClass(selection) {

        referenceClassGroup = selection
            .append('g')
            .attr('transform', 'translate(' + x + ',' + y + ')')
            .attr('class', 'reference-class');

        referenceClassGroup
            .append('rect')
            .attr('class', 'reference-class-background')
            .attr('transform', 'translate(' + (-5 * font.ratio.large) + ', ' + (-15 * font.ratio.large) + ')')
            .attr('width', font.ratio.large * 10.5 + 'em')
            .attr('height', 2 * font.ratio.large + 'em')
            .attr('fill', colours.bright);

        textGroup = referenceClassGroup.append('text');

        // referenceClassGroup
        textGroup
            .attr('fill', colours.text);

        textGroup.append('tspan')
            .attr('attr', 'reference-class-size')
            .attr('font-size', font.ratio.large + 'em')
            .text(labels.per[lang] + String.fromCharCode(options.common.spaceFormat) + labels.referenceGroup.size);
    }

    referenceClass.x = function(val) {
        if(!arguments.length) {
            return x;
        }
        x = val;
        return referenceClass;
    };

    referenceClass.font = function(val) {
        if(!arguments.length) {
            return font;
        }
        font = val;
        return referenceClass;
    };

    referenceClass.y = function(val) {
        if(!arguments.length) {
            return y;
        }
        y = val;
        return referenceClass;
    };

    referenceClass.labels = function(val) {
        if(!arguments.length) {
            return labels;
        }
        labels = val;
        return referenceClass;
    };

    referenceClass.lang = function(val) {
        if(!arguments.length) {
            return lang;
        }
        lang = val;
        return referenceClass;
    };

    referenceClass.colours = function(val) {
        if(!arguments.length) {
            return colours;
        }
        colours = val;
        return referenceClass;
    };

    referenceClass.colours(options.common.colours);
    referenceClass.labels(options.common.labels);
    referenceClass.lang(options.common.lang);
    referenceClass.font(options.common.font);
    referenceClass.x(options.x);
    referenceClass.y(options.y);
    return referenceClass;
}
