"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.inputPropHandler = exports.stylePropHandler = exports.basePropHandler = exports.svgPropHandler = exports.htmlPropHandler = exports.elementPropHandler = exports.makeAttrHandler = void 0;
const applyAttr_1 = require("./applyAttr");
const style_1 = require("./style");
function makeAttrHandler(element, name) {
    return (data) => {
        if (data === undefined) {
            element.removeAttribute(name);
        }
        else {
            element.setAttribute(name, data);
        }
    };
}
exports.makeAttrHandler = makeAttrHandler;
function elementPropHandler(component, element, DEFAULT_STYLE) {
    return Object.assign(Object.assign({}, basePropHandler(component, element, DEFAULT_STYLE)), stylePropHandler(component, element, DEFAULT_STYLE));
}
exports.elementPropHandler = elementPropHandler;
function htmlPropHandler(component, element, DEFAULT_STYLE) {
    return Object.assign(Object.assign({}, elementPropHandler(component, element, DEFAULT_STYLE)), { innerText: (innerText) => {
            element.innerText = innerText || '';
        } });
}
exports.htmlPropHandler = htmlPropHandler;
function svgPropHandler(component, element, DEFAULT_STYLE) {
    return Object.assign(Object.assign({}, basePropHandler(component, element, DEFAULT_STYLE)), stylePropHandler(component, element, DEFAULT_STYLE));
}
exports.svgPropHandler = svgPropHandler;
function basePropHandler(component, element, DEFAULT_STYLE) {
    return {
        attr: (attr) => {
            (0, applyAttr_1.default)(element, attr);
        },
        style: (style = {}) => {
            (0, style_1.applyStyle)(element, Object.assign(Object.assign({}, DEFAULT_STYLE), style));
        },
        className: makeAttrHandler(element, 'className'),
        id: makeAttrHandler(element, 'id'),
        tabIndex: makeAttrHandler(element, 'tabIndex'),
        title: makeAttrHandler(element, 'title'),
        draggable: makeAttrHandler(element, 'draggable'),
    };
}
exports.basePropHandler = basePropHandler;
function stylePropHandler(component, element, DEFAULT_STYLE) {
    return {
        style: (style = {}) => {
            (0, style_1.applyDynamicStyle)(component, element, Object.assign(Object.assign({}, DEFAULT_STYLE), style));
        },
    };
}
exports.stylePropHandler = stylePropHandler;
function inputPropHandler(element, VALUE_NAME, DEFAULT_VALUE) {
    return {
        value: (value) => {
            element[VALUE_NAME] = value || DEFAULT_VALUE;
        },
        placeholder: (placeholder) => {
            // @ts-ignore
            element.placeholder = placeholder !== null && placeholder !== void 0 ? placeholder : '';
        },
        disabled: makeAttrHandler(element, 'disabled'),
    };
}
exports.inputPropHandler = inputPropHandler;
//# sourceMappingURL=propHandler.js.map