"use strict";

exports.__esModule = true;
exports.EditableCellUniDriver = EditableCellUniDriver;
var _unidriver = require("../../unidriver");
var _EditUni = require("./cellTypes/text/Edit.uni.driver");
var _EditUni2 = require("./cellTypes/number/Edit.uni.driver");
var _EditUni3 = require("./cellTypes/url/Edit.uni.driver");
var _EditUni4 = require("./cellTypes/boolean/Edit.uni.driver");
var _SpecificValuesEditUni = require("./cellTypes/text/SpecificValuesEdit.uni.driver");
var _EditUni5 = require("./cellTypes/date/Edit.uni.driver");
var _EditUni6 = require("./cellTypes/reference/Edit.uni.driver");
function EditableCellUniDriver(base, body) {
  return {
    ...(0, _unidriver.baseUniDriverFactory)(base),
    /** Click the cell (focuses it) */
    click: () => base.click(),
    /** Double-click the cell (starts editing). UniDriver has no doubleClick, so dispatch native event. */
    doubleClick: async () => {
      const el = await base.getNative();
      if ((0, _unidriver.isSled2)(el)) {
        const elementHandle = await base.unwrap();
        await elementHandle.click({
          clickCount: 2
        });
      } else if ((0, _unidriver.isSled3)(el)) {
        const locator = await base.unwrap();
        await locator.dblclick();
      } else {
        el.dispatchEvent(new MouseEvent('dblclick', {
          bubbles: true
        }));
      }
    },
    /** Get the displayed text value of the cell */
    getDisplayValue: () => base.text(),
    /** Whether this cell is focused */
    isFocused: async () => (await base.attr('tabindex')) === '0',
    /** Whether this cell is in editing mode */
    isEditing: async () => (await base.attr('data-editing')) === 'true',
    /** Whether this cell is selected (part of a selection range) */
    isSelected: async () => (await base.attr('aria-selected')) === 'true',
    /** Whether this cell is read-only (not editable) */
    isReadOnly: async () => (await base.attr('aria-readonly')) === 'true',
    /** Whether this cell has a validation error */
    isInvalid: async () => (await base.attr('aria-invalid')) === 'true',
    /** Get the row key from data attribute */
    getRowKey: () => base.attr('data-row-key'),
    /** Get the column id from data attribute */
    getColumnId: () => base.attr('data-column-id'),
    /** Whether the cell contains a validation indicator icon */
    hasValidationIndicator: () => base.$('[data-hook="validation-indicator"]').exists(),
    /** Get the text cell edit driver (for text columns) */
    getTextEdit: () => (0, _EditUni.TextEditUniDriver)(base, body),
    /** Get the number cell edit driver (for number columns) */
    getNumberEdit: () => (0, _EditUni2.NumberEditUniDriver)(base, body),
    /** Get the url cell edit driver (for url columns) */
    getUrlEdit: () => (0, _EditUni3.UrlEditUniDriver)(base, body),
    /** Get the boolean cell edit driver (for boolean columns) */
    getBooleanEdit: () => (0, _EditUni4.BooleanEditUniDriver)(base, body),
    /** Get the specific-values (autocomplete) edit driver (for text columns with specificValues validation) */
    getSpecificValuesEdit: () => (0, _SpecificValuesEditUni.SpecificValuesEditUniDriver)(base, body),
    /** Get the date cell edit driver (for date columns) */
    getDateEdit: () => (0, _EditUni5.DateEditUniDriver)(base, body),
    /** Get the reference cell edit driver (for reference columns) */
    getReferenceEdit: () => (0, _EditUni6.ReferenceEditUniDriver)(base, body),
    /** Right-click the cell (opens context menu) */
    rightClick: async () => {
      const el = await base.getNative();
      if ((0, _unidriver.isSled2)(el)) {
        // Puppeteer — unwrap to get the actual ElementHandle
        const elementHandle = await base.unwrap();
        await elementHandle.click({
          button: 'right'
        });
      } else if ((0, _unidriver.isSled3)(el)) {
        const locator = await base.unwrap();
        await locator.click({
          button: 'right'
        });
      } else {
        // jsdom HTMLElement
        const rect = el.getBoundingClientRect();
        el.dispatchEvent(new MouseEvent('contextmenu', {
          bubbles: true,
          clientX: rect.left + 5,
          clientY: rect.top + 5
        }));
      }
    },
    /** Get the bounding box of the cell — returns {x, y, width, height} across all envs */
    getBoundingBox: async () => {
      const el = await base.getNative();
      if ((0, _unidriver.isSled2)(el)) {
        const elementHandle = await base.unwrap();
        return elementHandle.boundingBox();
      }
      if ((0, _unidriver.isSled3)(el)) {
        const locator = await base.unwrap();
        return locator.boundingBox();
      }
      return el.getBoundingClientRect();
    },
    /** Press a key on the cell (native dispatch — useCellFocusAndEditing uses native addEventListener) */
    pressKey: async (key, opts) => {
      const el = await base.getNative();
      if ((0, _unidriver.isSled2)(el)) {
        const elementHandle = await base.unwrap();
        await elementHandle.press(key);
      } else if ((0, _unidriver.isSled3)(el)) {
        const locator = await base.unwrap();
        await locator.press(key);
      } else {
        el.dispatchEvent(new KeyboardEvent('keydown', {
          key,
          bubbles: true,
          ...opts
        }));
      }
    }
  };
}
//# sourceMappingURL=EditableCell.uni.driver.js.map