"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = require("react");
var sdk_1 = require("@builder.io/sdk");
var builder_block_component_1 = require("./builder-block.component");
var react_native_1 = require("react-native");
// TODO: options to set direciotn
var BuilderBlocks = /** @class */ (function (_super) {
    __extends(BuilderBlocks, _super);
    function BuilderBlocks() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.onClickEmptyBlocks = function () {
            if (sdk_1.Builder.isIframe && _this.noBlocks) {
                window.parent.postMessage({
                    type: 'builder.clickEmptyBlocks',
                    data: {
                        parentElementId: _this.parentId,
                        dataPath: _this.path
                    }
                }, '*');
            }
        };
        return _this;
    }
    Object.defineProperty(BuilderBlocks.prototype, "isRoot", {
        get: function () {
            return !this.props.child;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BuilderBlocks.prototype, "noBlocks", {
        get: function () {
            var blocks = this.props.blocks;
            return !(blocks && blocks.length); // TODO: allow react nodes
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BuilderBlocks.prototype, "path", {
        get: function () {
            var pathPrefix = 'component.options.';
            var path = this.props.dataPath || 'children';
            var thisPrefix = 'this.';
            if (path.trim()) {
                if (path.startsWith(thisPrefix)) {
                    path = path.replace(thisPrefix, '');
                }
                else if (!path.startsWith(pathPrefix)) {
                    path = pathPrefix + path;
                }
            }
            return path;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(BuilderBlocks.prototype, "parentId", {
        get: function () {
            if (this.props.parentElementId) {
                return this.props.parentElementId;
            }
            return this.props.parent && this.props.parent.id;
        },
        enumerable: true,
        configurable: true
    });
    // <!-- Builder Blocks --> in comments hmm
    BuilderBlocks.prototype.render = function () {
        var _this = this;
        var blocks = this.props.blocks;
        // TODO: how deep check this automatically for mobx... hmmm optional / peer dependency?
        return (
        // TODO: component <Stack direction="vertical">
        // TODO: react.fragment instead?
        react_1.default.createElement(react_native_1.View, { style: __assign({}, this.props.style) }, (blocks &&
            Array.isArray(blocks) &&
            blocks.map(function (block, index) {
                return block && block['@type'] === '@builder.io/sdk:Element' ? (react_1.default.createElement(builder_block_component_1.BuilderBlock, { key: block.id, block: block, index: index, fieldName: _this.props.fieldName, child: _this.props.child, emailMode: _this.props.emailMode })) : (block);
            })) ||
            blocks));
    };
    return BuilderBlocks;
}(react_1.default.Component));
exports.BuilderBlocks = BuilderBlocks;
//# sourceMappingURL=builder-blocks.component.js.map