"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var testkit_exports = {};
__export(testkit_exports, {
  createInlineAiTestkit: () => createInlineAiTestkit
});
module.exports = __toCommonJS(testkit_exports);
var import_unidriver = require("@wix/design-system/dist/testkit/unidriver.js");
var import_wix_rich_content_common = require("./../wix-rich-content-common/index.js");
var import_data_hooks = require("./data-hooks.js");
const createInlineAiTestkit = (getBase) => {
  return {
    content: {},
    modal: {
      exists: async () => {
        try {
          return getBase().$((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_MODAL_ROOT)).exists();
        } catch {
          return false;
        }
      },
      waitForElement: async () => {
        await getBase().get((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_MODAL_ROOT));
      },
      promptInput: {
        exists: async () => {
          try {
            return getBase().$((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_PROMPT_INPUT)).exists();
          } catch {
            return false;
          }
        },
        waitForElement: async () => {
          await getBase().get((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_PROMPT_INPUT));
        },
        getValue: async () => {
          const input = getBase().$((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_PROMPT_INPUT));
          const native = await input.getNative();
          return native.value;
        },
        enterText: async (text) => {
          const input = getBase().$((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_PROMPT_INPUT));
          const native = await input.getNative();
          const textarea = native;
          textarea.focus();
          const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
            window.HTMLTextAreaElement.prototype,
            "value"
          )?.set;
          if (nativeInputValueSetter) {
            nativeInputValueSetter.call(textarea, text);
          } else {
            textarea.value = text;
          }
          const inputEvent = new Event("input", { bubbles: true });
          textarea.dispatchEvent(inputEvent);
        },
        submit: async () => {
          const input = getBase().$((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_PROMPT_INPUT));
          const native = await input.getNative();
          const textarea = native;
          const enterEvent = new KeyboardEvent("keydown", {
            key: "Enter",
            code: "Enter",
            bubbles: true
          });
          textarea.dispatchEvent(enterEvent);
        }
      }
    },
    spinner: {
      exists: async () => {
        try {
          return getBase().$((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_SPINNER)).exists();
        } catch {
          return false;
        }
      },
      waitForElement: async () => {
        await getBase().get((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_SPINNER));
      },
      stopButton: (0, import_unidriver.IconButtonUniDriver)(
        getBase().$((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_SPINNER_STOP_BUTTON)),
        getBase()
      )
    },
    pager: {
      exists: async () => {
        try {
          return getBase().$((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_PAGER)).exists();
        } catch {
          return false;
        }
      },
      waitForElement: async () => {
        await getBase().get((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_PAGER));
      },
      prevButton: (0, import_unidriver.IconButtonUniDriver)(
        getBase().$((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_PAGER_PREV_BUTTON)),
        getBase()
      ),
      nextButton: (0, import_unidriver.IconButtonUniDriver)(
        getBase().$((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_PAGER_NEXT_BUTTON)),
        getBase()
      )
    },
    beforeAfterButton: (0, import_unidriver.ButtonUniDriver)(
      getBase().$((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_BEFORE_AFTER_BUTTON)),
      getBase()
    ),
    acceptAllButton: (0, import_unidriver.ButtonUniDriver)(getBase().$((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_ACCEPT_ALL_BUTTON)), getBase()),
    rejectAllButton: (0, import_unidriver.ButtonUniDriver)(getBase().$((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_REJECT_ALL_BUTTON)), getBase()),
    error: {
      exists: async () => {
        try {
          return getBase().$((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_ERROR_CONTAINER)).exists();
        } catch {
          return false;
        }
      },
      waitForElement: async () => {
        await getBase().get((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_ERROR_CONTAINER));
      },
      getText: async () => {
        const container = getBase().$((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_ERROR_CONTAINER));
        return container.text();
      }
    },
    textResponse: {
      exists: async () => {
        try {
          return getBase().$((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_TEXT_RESPONSE_CONTAINER)).exists();
        } catch {
          return false;
        }
      },
      waitForElement: async () => {
        await getBase().get((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_TEXT_RESPONSE_CONTAINER));
      },
      getText: async () => {
        const container = getBase().$((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_TEXT_RESPONSE_CONTAINER));
        return container.text();
      }
    },
    aiRegionViewer: {
      exists: async () => {
        try {
          return await getBase().$$((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_AI_REGION_VIEWER)).count() > 0;
        } catch {
          return false;
        }
      },
      waitForElement: async () => {
        await getBase().get((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_AI_REGION_VIEWER));
      },
      count: async () => {
        try {
          const allRegions = await getBase().getAll((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_AI_REGION_VIEWER));
          return allRegions.count();
        } catch {
          return 0;
        }
      },
      isCompleted: async () => {
        try {
          const allRegions = await getBase().getAll((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_AI_REGION_VIEWER));
          const count = await allRegions.count();
          if (count === 0) {
            return false;
          }
          const completedRegions = await getBase().getAll((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_AI_REGION_COMPLETED));
          const completedCount = await completedRegions.count();
          return count === completedCount;
        } catch {
          return false;
        }
      },
      atIndex: (index) => {
        const getRegion = () => getBase().$$((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_AI_REGION_VIEWER)).at(index);
        return {
          exists: async () => {
            try {
              return (await getRegion()).exists();
            } catch {
              return false;
            }
          },
          isCompleted: async () => {
            try {
              const region = await getRegion();
              const native = await region.getNative();
              const element = native;
              return element.getAttribute("data-hook")?.includes(import_data_hooks.INLINE_AI_AI_REGION_COMPLETED) ?? false;
            } catch {
              return false;
            }
          },
          click: async () => {
            const acceptButton = await getBase().$((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_AI_REGION_ACCEPT_BUTTON));
            const exists = await acceptButton.exists();
            if (!exists) {
              throw new Error("AI region accept button not found");
            }
            await acceptButton.click();
          }
        };
      }
    },
    streamingCursor: {
      exists: async () => {
        try {
          return getBase().$((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_STREAMING_CURSOR)).exists();
        } catch {
          return false;
        }
      },
      flag: {
        exists: async () => {
          try {
            return getBase().$((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_STREAMING_CURSOR_FLAG)).exists();
          } catch {
            return false;
          }
        },
        getText: async () => {
          const flag = getBase().$((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_STREAMING_CURSOR_FLAG));
          return flag.text();
        }
      }
    },
    acceptChanges: async () => {
      const acceptButton = await getBase().$((0, import_wix_rich_content_common.dataHook)(import_data_hooks.INLINE_AI_AI_REGION_ACCEPT_BUTTON));
      const exists = await acceptButton.exists();
      if (!exists) {
        throw new Error("AI region accept button not found");
      }
      acceptButton.click();
    }
  };
};
//# sourceMappingURL=testkit.js.map
