"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseProperty = void 0;
const lodash_1 = require("lodash");
const dimension_style_parser_1 = require("../style/dimension-style.parser");
const base_parser_1 = require("./base-parser");
const show_in_device_parser_1 = require("./show-in-device.parser");
class NumericParser extends base_parser_1.Parser {
    parse(value) {
        const dimensionVal = new dimension_style_parser_1.DimensionStyleParser('dimension').parse(value).dimension;
        return `{${dimensionVal}}`;
    }
    parseBind(value) {
        return `fragment.toNumber(${value})`;
    }
}
class BooleanParser extends base_parser_1.Parser {
    parse(value) {
        if (value === 'true' || value === 'false') {
            return `{${(value === 'true')}}`;
        }
        return super.parse(value);
    }
    parseBind(value) {
        return `fragment.toBoolean(${value})`;
    }
}
const NUMERIC_PARSER = new NumericParser();
const BOOLEAN_PARSER = new BooleanParser();
const STRING_PARSER = new base_parser_1.Parser();
const PARSER_MAP = new Map([['base', new Map([
            ['animationinterval', NUMERIC_PARSER],
            ['autofocus', BOOLEAN_PARSER],
            ['autocomplete', BOOLEAN_PARSER],
            ['autotrim', BOOLEAN_PARSER],
            ['backbutton', BOOLEAN_PARSER],
            ['cache', BOOLEAN_PARSER],
            ['checkedvalue', BOOLEAN_PARSER],
            ['collapsible', BOOLEAN_PARSER],
            ['columnwidth', NUMERIC_PARSER],
            ['closable', BOOLEAN_PARSER],
            ['defaultpaneindex', NUMERIC_PARSER],
            ['disabled', BOOLEAN_PARSER],
            ['disableitem', BOOLEAN_PARSER],
            ['encodeurl', BOOLEAN_PARSER],
            ['expanded', BOOLEAN_PARSER],
            ['flexgrow', NUMERIC_PARSER],
            ['flexshrink', NUMERIC_PARSER],
            ['hideclose', BOOLEAN_PARSER],
            ['iconsize', NUMERIC_PARSER],
            ['imageheight', NUMERIC_PARSER],
            ['imagequality', NUMERIC_PARSER],
            ['imagetargetwidth', NUMERIC_PARSER],
            ['imagetargetheight', NUMERIC_PARSER],
            ['imagewidth', NUMERIC_PARSER],
            ['index', NUMERIC_PARSER],
            ['limit', NUMERIC_PARSER],
            ['minchars', NUMERIC_PARSER],
            ['maxchars', NUMERIC_PARSER],
            ['maxsize', NUMERIC_PARSER],
            ['maxvalue', NUMERIC_PARSER],
            ['minvalue', NUMERIC_PARSER],
            ['modal', BOOLEAN_PARSER],
            ['refreshdataonattach', BOOLEAN_PARSER],
            ['readonly', BOOLEAN_PARSER],
            ['required', BOOLEAN_PARSER],
            ['scrollable', BOOLEAN_PARSER],
            ['show', BOOLEAN_PARSER],
            ['showindevice', show_in_device_parser_1.SHOW_IN_DEVICE_PARSER],
            ['showclear', BOOLEAN_PARSER],
            ['searchbutton', BOOLEAN_PARSER],
            ['selectfirstitem', BOOLEAN_PARSER],
            ['showcaptions', BOOLEAN_PARSER],
            ['showheader', BOOLEAN_PARSER],
            ['step', NUMERIC_PARSER],
            ['uncheckedvalue', BOOLEAN_PARSER],
            ['vertical', BOOLEAN_PARSER],
            ['xscolumnwidth', NUMERIC_PARSER],
            ['cancelable', BOOLEAN_PARSER],
            ['highlightpoints', BOOLEAN_PARSER],
            ['tooltips', BOOLEAN_PARSER],
            ['showvalues', BOOLEAN_PARSER],
            ['showyaxis', BOOLEAN_PARSER],
            ['showxaxis', BOOLEAN_PARSER],
            ['wrap', BOOLEAN_PARSER],
        ])
    ], ['wm-checkbox', new Map([
            ['datavalue', BOOLEAN_PARSER]
        ])], ['wm-toggle', new Map([
            ['datavalue', BOOLEAN_PARSER]
        ])], ['wm-rating', new Map([
            ['datavalue', NUMERIC_PARSER]
        ])], ['wm-slider', new Map([
            ['datavalue', NUMERIC_PARSER]
        ])], ['wm-progress-bar', new Map([
            ['datavalue', NUMERIC_PARSER]
        ])], ['wm-progress-circle', new Map([
            ['datavalue', NUMERIC_PARSER]
        ])]]);
const parseProperty = (value, propertyName, widgetName, runtime = false) => {
    var _a, _b;
    if ((0, lodash_1.isUndefined)(value)) {
        return `""`;
    }
    let parser = (_a = PARSER_MAP.get(widgetName)) === null || _a === void 0 ? void 0 : _a.get(propertyName);
    parser = parser || ((_b = PARSER_MAP.get('base')) === null || _b === void 0 ? void 0 : _b.get(propertyName));
    if (parser) {
        return runtime ? parser.parseBind(value) : parser.parse(value);
    }
    return runtime ? STRING_PARSER.parseBind(value) : STRING_PARSER.parse(value);
};
exports.parseProperty = parseProperty;
//# sourceMappingURL=property-parser.js.map