"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get CHIP_CLASS () {
        return _utils.CHIP_CLASS;
    },
    get RENDERER_TYPE () {
        return RENDERER_TYPE;
    },
    get multiSelectRenderer () {
        return multiSelectRenderer;
    }
});
const _baseRenderer = require("../baseRenderer");
const _element = require("../../helpers/dom/element");
const _mixed = require("../../helpers/mixed");
const _utils = require("./utils/utils");
const RENDERER_TYPE = 'multiselect';
const MULTISELECT_RENDERER_CLASS = 'ht-multi-select-renderer';
const CHIPS_CONTAINER_CLASS = 'ht-multi-select-chips-container';
function multiSelectRenderer(hotInstance, TD, row, col, prop, value, cellProperties) {
    _baseRenderer.baseRenderer.apply(this, [
        hotInstance,
        TD,
        row,
        col,
        prop,
        value,
        cellProperties
    ]);
    let escaped = value;
    if (!escaped && cellProperties.placeholder) {
        escaped = cellProperties.placeholder;
        escaped = (0, _mixed.stringify)(escaped);
        (0, _element.fastInnerText)(TD, escaped);
        return;
    }
    const { rootDocument } = hotInstance;
    const isAriaEnabled = hotInstance.getSettings().ariaTags;
    const physicalRow = hotInstance.toPhysicalRow(row);
    const physicalColumn = typeof col === 'string' ? col : hotInstance.toPhysicalColumn(col);
    const sourceData = hotInstance.getSourceDataAtCell(physicalRow, physicalColumn);
    const values = (0, _utils.parseValue)(sourceData);
    (0, _element.empty)(TD);
    (0, _element.addClass)(TD, MULTISELECT_RENDERER_CLASS);
    if (values.length === 0) {
        TD.appendChild(rootDocument.createTextNode(''));
        return;
    }
    const chipsContainer = rootDocument.createElement('div');
    chipsContainer.className = CHIPS_CONTAINER_CLASS;
    values.forEach((item)=>{
        const chip = (0, _utils.createChipElement)(rootDocument, item, isAriaEnabled, row, prop);
        chipsContainer.appendChild(chip);
    });
    TD.appendChild(chipsContainer);
    (0, _utils.registerChipRemovingEvents)(hotInstance, RENDERER_TYPE);
    const columnWidth = (0, _utils.cacheColumnWidthAndRegisterResizeHook)(hotInstance, col);
    (0, _utils.handleChipsOverflow)(columnWidth, chipsContainer, rootDocument);
}
multiSelectRenderer.RENDERER_TYPE = RENDERER_TYPE;
