'use strict';

const React = require("react");
const createReactClass = require("create-react-class");

const filterAttributes = require("../../../ast/node/filter-attributes");
const filterNodes = require("../../../ast/node/filter-nodes");
const filterNodeSequences = require("../../../ast/node/filter-node-sequences");

const dependencies = require("../../circular-dependency-container")();

require("./sub-items/child")({dependencies});
require("./sub-items/child-sequence")({dependencies});
require("./item")({dependencies});

let GenericAstItem = createReactClass({
	displayName: "GenericAstItem",
	render: function () {
		let AstItem = dependencies.get("AstItem");

		let itemProps = {
			hasFunctionScope: (this.props.data._scopeType === 1),
			hasBlockScope: (this.props.data._scopeType === 2),
			type: this.props.data.type,
			scopeId: this.props.data._scopeId,
			scopeType: (this.props.data._scopeType === 1 ? "function" : "block"),
			attributes: filterAttributes(this.props.data),
			children: filterNodes(this.props.data),
			childSequences: filterNodeSequences(this.props.data)
		};

		return (<AstItem {...itemProps} data={this.props.data} />);
	}
});

dependencies.set("GenericAstItem", GenericAstItem);
module.exports = GenericAstItem;
