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