"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const React = __importStar(require("react"));
const PropTypes = __importStar(require("prop-types"));
const utils_1 = require("../../utils");
const components_1 = require("../components");
const ReactContext_1 = __importDefault(require("../../ReactContext"));
const utils_2 = require("@rjsf/utils");
class ExtraLabelRowField extends React.Component {
    constructor() {
        super(...arguments);
        this.containerRef = React.createRef();
        this.getColContent = (label, i) => {
            const cols = this.getCols(label.size);
            const { Label } = this.props.formContext;
            const { Col } = this.context.theme;
            return (React.createElement(Col, Object.assign({}, cols, { key: i }),
                React.createElement(Label, { label: label.label, id: this.props.idSchema.$id, uiSchema: { "ui:help": label.help } })));
        };
        this.getCols = (property) => {
            const cols = { lg: 12, md: 12, sm: 12, xs: 12 };
            const options = (0, utils_1.getUiOptions)(this.props.uiSchema);
            Object.keys(cols).forEach(col => {
                const optionCol = options[col];
                if (typeof optionCol === "object") {
                    let selector = undefined;
                    if (optionCol[property])
                        selector = property;
                    else if (optionCol["*"])
                        selector = "*";
                    cols[col] = optionCol[selector];
                }
                else {
                    cols[col] = optionCol;
                }
            });
            return cols;
        };
    }
    getNextProps(props) {
        return {
            schema: Object.assign(Object.assign({}, props.schema), { title: "" }),
            uiSchema: (0, utils_1.getInnerUiSchema)(props.uiSchema),
            options: (0, utils_1.getUiOptions)(props.uiSchema)
        };
    }
    render() {
        const { SchemaField } = this.props.registry.fields;
        const TitleFieldTemplate = (0, utils_2.getTemplate)("TitleFieldTemplate", this.props.registry, (0, utils_1.getUiOptions)(this.props.uiSchema));
        const { labels, hiddenXs, affixed } = (0, utils_1.getUiOptions)(this.props.uiSchema);
        const cols = [];
        labels.forEach((label, i) => {
            cols.push(this.getColContent(label, i));
        });
        const title = this.props.schema.title !== undefined ? this.props.schema.title : this.props.name;
        const { Row } = this.context.theme;
        let labelRow = React.createElement(Row, { className: "laji-form-label-row" + (hiddenXs ? " hidden-xs" : "") + (affixed ? " affixed-labels" : "") }, cols);
        if (affixed) {
            labelRow = (React.createElement(components_1.Affix, { containerRef: this.containerRef, style: affixed ? { position: "relative", zIndex: 1 } : undefined, topOffset: this.props.formContext.topOffset, bottomOffset: this.props.formContext.bottomOffset }, labelRow));
        }
        return (React.createElement("div", { ref: this.containerRef },
            title
                ? (React.createElement(TitleFieldTemplate, { title: title, schema: this.props.schema, uiSchema: this.props.uiSchema, id: this.props.idSchema.$id, registry: this.props.registry })) : null,
            labelRow,
            React.createElement(SchemaField, Object.assign({}, this.props, this.getNextProps(this.props)))));
    }
}
ExtraLabelRowField.contextType = ReactContext_1.default;
ExtraLabelRowField.propTypes = {
    uiSchema: PropTypes.shape({
        "ui:options": PropTypes.shape({
            labels: PropTypes.arrayOf(PropTypes.object).isRequired,
            lg: PropTypes.oneOfType([PropTypes.number, PropTypes.object]),
            md: PropTypes.oneOfType([PropTypes.number, PropTypes.object]),
            sm: PropTypes.oneOfType([PropTypes.number, PropTypes.object]),
            xs: PropTypes.oneOfType([PropTypes.number, PropTypes.object]),
            hiddenXs: PropTypes.bool
        })
    }).isRequired,
    schema: PropTypes.shape({
        type: PropTypes.oneOf(["object", "array"])
    }).isRequired,
    formData: PropTypes.oneOfType([PropTypes.object, PropTypes.array]).isRequired
};
exports.default = ExtraLabelRowField;
