import { h } from './index-acdc1ac0.js';

var __rest = (undefined && undefined.__rest) || function (s, e) {
  var t = {};
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
    t[p] = s[p];
  if (s != null && typeof Object.getOwnPropertySymbols === "function")
    for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
      if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
        t[p[i]] = s[p[i]];
    }
  return t;
};
function getWrappedValue(key, dataWrapper) {
  if (!key.includes('.')) {
    return dataWrapper[key];
  }
  let data = dataWrapper;
  key.split('.').forEach(key => {
    if (!data) {
      return;
    }
    data = data[key];
  });
  return data;
}
function mapFields(params = {}) {
  const { conversionConfig } = params, data = __rest(params, ["conversionConfig"]);
  return convertValues(conversionConfig, data);
}
function convertValues(conversionConfig, data) {
  if (!conversionConfig) {
    return data;
  }
  Object.keys(conversionConfig).forEach(key => {
    const keyToUse = conversionConfig[key] || key;
    data[keyToUse] = getWrappedValue(key, data);
  });
  return data;
}
const generateActionComponent = (index, viewParams, item, actionClick, action, options) => {
  const { data, ui } = action;
  if (ui.componentTag) {
    // return the custom ui item
    const Tag = ui.componentTag;
    return h(Tag, { index: index, item: item });
  }
  const buttonType = ui.buttonType || 'button';
  const scale = ui.scale || 'medium';
  const shape = ui.shape || (ui.buttonType === 'icon-button' ? 'circle' : 'rectangular');
  const tint = ui.tint || 'primary';
  const view = ui.view || 'solid';
  // label is used as abbr title if the icon type is icon-button
  const abbrTitle = ui.buttonType === 'icon-button' ? ui.label : undefined;
  const label = ui.buttonType === 'icon-button' ? undefined : ui.label;
  const Tag = buttonType === 'button' ? 'dvn-button' : 'dvn-icon-button';
  // map the fields by using the 'conversionConfig' parameter
  const params = mapFields(Object.assign(Object.assign(Object.assign({}, ((data === null || data === void 0 ? void 0 : data.params) || {})), viewParams), { item: item }));
  return (h(Tag, { abbrTitle: abbrTitle, key: ui.name, scale: scale, shape: shape, tint: tint, view: view, iconName: ui.iconName, onClick: () => actionClick.emit(Object.assign(Object.assign({}, data), { name: ui.name, params })), leaned: options ? options.leaned : undefined }, label));
};

export { convertValues as c, generateActionComponent as g };
