import { ApplicationContext, HTMLBuilder } from '@sankhyalabs/core';
import { getViewPortHeight } from '../GridEditorUtils';
import { StringUtils } from "@sankhyalabs/core";
export const buildSearch = ({ name, required, readOnly, eGridCell, dataUnit }) => {
  var _a;
  const ezSearch = HTMLBuilder.parseElement(`<ez-search
          class="ez-grid grid_editor"
          mode="slim"
          suppress-empty-option=${required}
          enabled=${!readOnly}
    />`);
  const loader = ApplicationContext.getContextValue("__EZUI__SEARCH__OPTION__LOADER__");
  const metadata = dataUnit.getField(name);
  ezSearch.optionLoader = (argument) => loader(argument, name, dataUnit);
  ezSearch.ensureClearButtonVisible = true;
  ezSearch.suppressPreLoad = true;
  ezSearch.listOptionsPosition = { verticalPosition: 29, bottomLimit: getViewPortHeight(eGridCell), hardPosition: true };
  ezSearch.stopPropagateEnterKeyEvent = true;
  ezSearch.ignoreLimitCharsToSearch = StringUtils.getBooleanValue((_a = metadata === null || metadata === void 0 ? void 0 : metadata.properties) === null || _a === void 0 ? void 0 : _a.ignoreLimitCharsToSearch);
  ezSearch.autoFocus = true;
  ezSearch.valueGetter = () => ezSearch.getValueAsync();
  return ezSearch;
};
