'use strict';

var keysTransform = require('../utils/keys-transform.js');
var defaults = require('../../value/types/maps/defaults.js');
var models = require('../../projection/geometry/models.js');
var DOMVisualElement = require('../dom/DOMVisualElement.js');
var camelToDash = require('../dom/utils/camel-to-dash.js');
var buildAttrs = require('./utils/build-attrs.js');
var camelCaseAttrs = require('./utils/camel-case-attrs.js');
var isSvgTag = require('./utils/is-svg-tag.js');
var render = require('./utils/render.js');
var scrapeMotionValues = require('./utils/scrape-motion-values.js');

class SVGVisualElement extends DOMVisualElement.DOMVisualElement {
    constructor() {
        super(...arguments);
        this.type = "svg";
        this.isSVGTag = false;
        this.measureInstanceViewportBox = models.createBox;
    }
    getBaseTargetFromProps(props, key) {
        return props[key];
    }
    readValueFromInstance(instance, key) {
        if (keysTransform.transformProps.has(key)) {
            const defaultType = defaults.getDefaultValueType(key);
            return defaultType ? defaultType.default || 0 : 0;
        }
        key = !camelCaseAttrs.camelCaseAttributes.has(key) ? camelToDash.camelToDash(key) : key;
        return instance.getAttribute(key);
    }
    scrapeMotionValuesFromProps(props, prevProps, visualElement) {
        return scrapeMotionValues.scrapeMotionValuesFromProps(props, prevProps, visualElement);
    }
    build(renderState, latestValues, props) {
        buildAttrs.buildSVGAttrs(renderState, latestValues, this.isSVGTag, props.transformTemplate, props.style);
    }
    renderInstance(instance, renderState, styleProp, projection) {
        render.renderSVG(instance, renderState, styleProp, projection);
    }
    mount(instance) {
        this.isSVGTag = isSvgTag.isSVGTag(instance.tagName);
        super.mount(instance);
    }
}

exports.SVGVisualElement = SVGVisualElement;
