"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, {
  createSmartBlockTestkit: () => createSmartBlockTestkit
});
module.exports = __toCommonJS(testkit_exports);
var import_ricos_types = require("./../ricos-types/index.js");
var import_data_hooks = require("./../_shared/data-hooks.js");
var import_wix_rich_content_common = require("./../wix-rich-content-common/index.js");
var import_data_hooks2 = require("./data-hooks.js");
const createSmartBlockTestkit = (getBase) => {
  const getSmartBlock = async (index) => {
    const smartBlocks = await getBase().getAll((0, import_wix_rich_content_common.dataHook)(import_data_hooks2.DATA_HOOKS.SMART_BLOCK));
    return smartBlocks.at(index);
  };
  const getVariantSwitcherPanel = () => {
    return getBase().$((0, import_wix_rich_content_common.dataHook)(import_data_hooks2.DATA_HOOKS.INSERT_MODAL));
  };
  const getVariantOption = (variant) => {
    return getVariantSwitcherPanel().$((0, import_wix_rich_content_common.dataHook)(`variant-option-${variant}`));
  };
  return {
    content: {
      atIndex: (index) => ({
        exists: async () => {
          try {
            const smartBlock = await getSmartBlock(index);
            return smartBlock.exists();
          } catch {
            return false;
          }
        },
        click: async () => {
          const smartBlock = await getSmartBlock(index);
          await smartBlock.click();
        },
        getVariantKey: async () => {
          const smartBlock = await getSmartBlock(index);
          return smartBlock.attr("data-type");
        },
        getCellCount: async () => {
          const smartBlock = await getSmartBlock(index);
          const cells = smartBlock.$$((0, import_wix_rich_content_common.dataHook)(import_data_hooks2.DATA_HOOKS.SMART_BLOCK_CELL));
          return cells.count();
        },
        getCellAtIndex: (cellIndex) => {
          const getCell = async () => {
            const smartBlock = await getSmartBlock(index);
            const cells = smartBlock.$$((0, import_wix_rich_content_common.dataHook)(import_data_hooks2.DATA_HOOKS.SMART_BLOCK_CELL));
            return cells.at(cellIndex);
          };
          return {
            exists: async () => {
              try {
                const cell = await getCell();
                return cell.exists();
              } catch {
                return false;
              }
            },
            getDragHandle: () => ({
              exists: async () => {
                try {
                  const cell = await getCell();
                  return cell.$((0, import_wix_rich_content_common.dataHook)(import_data_hooks2.DATA_HOOKS.SMART_BLOCK_CELL_HANDLE)).exists();
                } catch {
                  return false;
                }
              },
              click: async () => {
                const cell = await getCell();
                await cell.$((0, import_wix_rich_content_common.dataHook)(import_data_hooks2.DATA_HOOKS.SMART_BLOCK_CELL_HANDLE)).click();
              }
            }),
            getAddButton: () => ({
              exists: async () => {
                try {
                  const smartBlock = await getSmartBlock(index);
                  const cells = smartBlock.$$((0, import_wix_rich_content_common.dataHook)(import_data_hooks2.DATA_HOOKS.SMART_BLOCK_CELL));
                  const totalCells = await cells.count();
                  if (cellIndex !== totalCells - 1) {
                    return false;
                  }
                  return smartBlock.$((0, import_wix_rich_content_common.dataHook)(import_data_hooks2.DATA_HOOKS.SMART_BLOCK_CELL_ADD_BUTTON)).exists();
                } catch {
                  return false;
                }
              },
              click: async () => {
                const smartBlock = await getSmartBlock(index);
                await smartBlock.$((0, import_wix_rich_content_common.dataHook)(import_data_hooks2.DATA_HOOKS.SMART_BLOCK_CELL_ADD_BUTTON)).$("button").click();
              }
            }),
            getDeleteButton: () => ({
              exists: async () => {
                try {
                  const cell = await getCell();
                  return cell.$((0, import_wix_rich_content_common.dataHook)(import_data_hooks2.DATA_HOOKS.SMART_BLOCK_CELL_HANDLE)).exists();
                } catch {
                  return false;
                }
              },
              click: async () => {
                const cell = await getCell();
                await cell.$((0, import_wix_rich_content_common.dataHook)(import_data_hooks2.DATA_HOOKS.SMART_BLOCK_CELL_HANDLE)).click();
                await getBase().$((0, import_wix_rich_content_common.dataHook)(import_data_hooks.PLUGIN_TOOLBAR_DELETE_BUTTON)).click();
              }
            })
          };
        }
      })
    },
    toolbars: {
      createPluginToolbar: (getPluginToolbarBase) => ({
        openVariantSwitcher: async () => {
          const button = await getPluginToolbarBase(import_ricos_types.RicosPluginToolbarNames.SMART_BLOCK).get(
            (0, import_wix_rich_content_common.dataHook)(import_data_hooks2.DATA_HOOKS.VARIANT_BUTTON)
          );
          await button.click();
        },
        exists: async () => {
          try {
            return getPluginToolbarBase(import_ricos_types.RicosPluginToolbarNames.SMART_BLOCK).exists();
          } catch {
            return false;
          }
        }
      })
    },
    variantSwitcherPanel: {
      exists: async () => {
        try {
          return getVariantSwitcherPanel().exists();
        } catch {
          return false;
        }
      },
      waitForElement: async () => {
        const panel = getVariantSwitcherPanel();
        await panel.wait();
      },
      selectVariant: async (variant) => {
        const option = getVariantOption(variant);
        await option.click();
      },
      getSelectedVariant: async () => {
        return null;
      }
    }
  };
};
//# sourceMappingURL=testkit.js.map
