"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.inputPropHandler = exports.stylePropHandler = exports.basePropHandler = exports.svgPropHandler = exports.htmlPropHandler = exports.attrHandler = void 0;
const applyAttr_1 = require("./applyAttr");
const style_1 = require("./style");
function attrHandler(element, name) {
    return (data) => {
        if (data === undefined) {
            element.removeAttribute(name);
        }
        else {
            element.setAttribute(name, data);
        }
    };
}
exports.attrHandler = attrHandler;
function htmlPropHandler(component, DEFAULT_STYLE) {
    return Object.assign(Object.assign(Object.assign({}, basePropHandler(component.$element, DEFAULT_STYLE)), stylePropHandler(component, DEFAULT_STYLE)), { innerText: (innerText) => {
            component.$element.innerText = innerText || '';
        } });
}
exports.htmlPropHandler = htmlPropHandler;
function svgPropHandler(component, DEFAULT_STYLE) {
    return Object.assign(Object.assign({}, basePropHandler(component.$element, DEFAULT_STYLE)), stylePropHandler(component, DEFAULT_STYLE));
}
exports.svgPropHandler = svgPropHandler;
function basePropHandler(element, DEFAULT_STYLE) {
    return {
        attr: (attr) => {
            (0, applyAttr_1.default)(element, attr);
        },
        style: (style = {}) => {
            (0, style_1.default)(element, Object.assign(Object.assign({}, DEFAULT_STYLE), style));
        },
        className: attrHandler(element, 'className'),
        id: attrHandler(element, 'id'),
        tabIndex: attrHandler(element, 'tabIndex'),
        title: attrHandler(element, 'title'),
        draggable: attrHandler(element, 'draggable'),
    };
}
exports.basePropHandler = basePropHandler;
function stylePropHandler(component, DEFAULT_STYLE) {
    return {
        style: (style = {}) => {
            (0, style_1.applyDynamicStyle)(component, 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: attrHandler(element, 'disabled'),
    };
}
exports.inputPropHandler = inputPropHandler;
//# sourceMappingURL=propHandler.js.map