import { dataHook } from "./../../wix-rich-content-common/index.js";
import { LIST_ITEM_SELECT } from "../list-item-select/data-hooks.js";
import {
  createListItemSelectDriver
} from "../list-item-select/list-item-select-uni-driver.js";
import { TOOLBAR_DROPDOWN_PANEL } from "./data-hooks.js";
const createDropdownModalUniDriver = (getBase, dropdownDataHook = TOOLBAR_DROPDOWN_PANEL) => {
  const getDropdownModal = async () => getBase().$(dataHook(dropdownDataHook));
  return {
    exists: async () => (await getDropdownModal()).exists(),
    waitForElement: async () => {
      await getBase().$(dataHook(dropdownDataHook));
    },
    optionAtIndex: async (index) => {
      const dropdownModal = await getDropdownModal();
      const options = await dropdownModal.$$(dataHook(LIST_ITEM_SELECT));
      return createListItemSelectDriver(() => options.at(index));
    },
    optionByValue: async (value) => {
      const dropdownModal = await getDropdownModal();
      const options = await dropdownModal.$$(dataHook(LIST_ITEM_SELECT));
      const optionsByValue = options.filter(async (option) => {
        const listItem = createListItemSelectDriver(() => option);
        const title = await listItem.getTitle();
        return title.includes(value);
      });
      return createListItemSelectDriver(() => optionsByValue.at(0));
    },
    optionByDataHook: async (hook) => {
      const dropdownModal = await getDropdownModal();
      const option = dropdownModal.$(`[data-hook~="${hook}"]`);
      return createListItemSelectDriver(() => option);
    },
    getNativeElement: async () => {
      const dropdownModal = await getDropdownModal();
      return dropdownModal.getNative();
    },
    getSelectedOption: async () => {
      const dropdownModal = await getDropdownModal();
      const options = await dropdownModal.$$(dataHook(LIST_ITEM_SELECT));
      const selectedOptions = options.filter(async (option) => {
        const listItem = createListItemSelectDriver(() => option);
        const isSelected = await listItem.isSelected();
        return isSelected;
      });
      return createListItemSelectDriver(() => selectedOptions.at(0));
    }
  };
};
export {
  createDropdownModalUniDriver
};
//# sourceMappingURL=dropdown-modal-uni-driver.js.map
