import { ElementIDUtils } from "@sankhyalabs/core";
import { h } from "@stencil/core";
export const DropdownItem = ({ item, hasIcon, hasChildren, isLockedLevels, onSubActionClick }) => {
  return (h("div", { class: "ez-dropdown__item-wrapper", title: item.label }, getContentLeft(item, hasIcon), h("span", { class: "ez-dropdown__item-label" }, item.label), getContentRight(item, hasChildren, isLockedLevels, onSubActionClick)));
};
const getContentLeft = (item, hasIcon) => {
  if (item == undefined || !hasIcon) {
    return;
  }
  if (item.iconName) {
    return (h("ez-icon", Object.assign({ class: "ez-dropdown__icon-left", iconName: item.iconName, size: "medium" }, { [ElementIDUtils.DATA_ELEMENT_ID_ATTRIBUTE_NAME]: `${item.id}_ezDropdownItemIcon` })));
  }
  return (h("ez-icon", { class: "ez-dropdown__icon-left ez-dropdown__hidden", size: "medium" }));
};
const getContentRight = (item, hasChildren, isLockedLevels, onClick) => {
  var _a, _b;
  if (item == undefined) {
    return;
  }
  if (!((_a = item.children) === null || _a === void 0 ? void 0 : _a.length) && item.subAction != undefined && Object.keys(item.subAction).length > 0) {
    return (h("span", Object.assign({ onClick: () => onClick(item), title: item.subAction.label, class: `ez-dropdown__link ez-dropdown__link--${item.subAction.type || "primary"}` }, { [ElementIDUtils.DATA_ELEMENT_ID_ATTRIBUTE_NAME]: `${item.subAction.id}_ezDropdownItemSubAction` }), item.subAction.label));
  }
  if (isLockedLevels || !hasChildren) {
    return;
  }
  if (((_b = item.children) === null || _b === void 0 ? void 0 : _b.length) > 0) {
    return (h("ez-icon", Object.assign({ class: "ez-dropdown__icon-right", iconName: "chevron-right", size: "medium" }, { [ElementIDUtils.DATA_ELEMENT_ID_ATTRIBUTE_NAME]: `${item.id}_ezDropdownIconOpenChildren` })));
  }
  return (h("ez-icon", { class: "ez-dropdown__icon-right ez-dropdown__hidden", size: "medium" }));
};
