"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.setFieldStyle = setFieldStyle;
const ns_1 = __importDefault(require("../../ns"));
const solid_logic_1 = require("solid-logic");
const fieldParams_1 = require("./fieldParams");
const fieldFunction_1 = require("./fieldFunction");
const STYLE_URI_PREFIX = 'https://www.w3.org/ns/css#';
/* eslint-disable no-console */
function setFieldStyle(ele, field) {
    const classUri = (0, fieldFunction_1.mostSpecificClassURI)(field);
    const params = fieldParams_1.fieldParams[classUri] || {};
    const style = solid_logic_1.store.any(field, ns_1.default.ui('style'));
    if (!style) {
        if (params.style) {
            ele.setAttribute('style', params.style);
        }
        return;
    }
    if (style.termType === 'Literal') {
        if (style)
            ele.setAttribute('style', style.value);
    }
    else {
        const sts = solid_logic_1.store.statementsMatching(style, null, null, field.doc());
        sts.forEach(st => {
            if (st.predicate.uri && st.predicate.uri.startsWith(STYLE_URI_PREFIX)) {
                const cssAttribute = st.predicate.uri.slice(STYLE_URI_PREFIX.length);
                try {
                    ele.style[cssAttribute] = st.object.value;
                }
                catch (err) {
                    console.warn(`setFieldStyle: Error setting element style ${cssAttribute} to "${st.object.value}"`);
                    console.warn(`setFieldStyle:   ... Element tagName was "${ele.tagName || '???'}"`);
                }
            }
        });
    }
}
//# sourceMappingURL=formStyle.js.map