"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const __1 = require("../");
const TextBox_1 = require("../editor/boxes/TextBox");
const PiUtils_1 = require("./PiUtils");
class PiProjectionUtil {
    static textBox(element, property) {
        let result = null;
        const value = element[property];
        if (value !== undefined && value !== null && typeof value === "string") {
            result = new TextBox_1.TextBox(element, "textbox-" + property, () => element[property], (v) => (element[property] = v), {
                placeHolder: `<${property}>`
            });
        }
        else {
            PiUtils_1.PiUtils.CHECK(false, "Property " + property + " does not exist or is not a string: " + value);
        }
        return result;
    }
    static booleanBox(elem, role, propertyName, labels = {
        yes: "yes",
        no: "no"
    }) {
        const value = elem[propertyName];
        if (value !== undefined && value !== null && typeof value === "boolean") {
            return new __1.SelectBox(elem, role, "<optional>", () => [{ id: labels.yes, label: labels.yes }, { id: labels.no, label: labels.no }], () => {
                if (elem[propertyName]) {
                    return { id: labels.yes, label: labels.yes };
                }
                else {
                    return { id: labels.no, label: labels.no };
                }
                return null;
            }, option => {
                if (option.label === labels.yes) {
                    elem[propertyName] = true;
                }
                else if (option.label === labels.no) {
                    elem[propertyName] = false;
                }
            });
        }
        else {
            PiUtils_1.PiUtils.CHECK(false, "Property " + propertyName + " does not exist or is not a boolean: " + value);
            return null;
        }
    }
}
exports.PiProjectionUtil = PiProjectionUtil;
//# sourceMappingURL=PiProjectionUtil.js.map