import {
  baseUniDriverFactory,
  UniDriver,
} from '@wix/wix-ui-test-utils/unidriver';
import { NestedTableParentCellUniDriver } from './NestedTableParentCell.uni.driver';

export function NestedTableRowUniDriver(base: UniDriver, body: UniDriver) {
  const getMainColumn = () =>
    NestedTableParentCellUniDriver(
      base.$('td[data-hook="nested-mode-main-column"]'),
      body,
    );

  return {
    ...baseUniDriverFactory(base),
    getMainColumn,
    isExpanded: () => getMainColumn().getExpandCollapseButton().isExpanded(),
    clickExpandToggleButton: () =>
      getMainColumn().getExpandCollapseButton().click(),
    getVirtualDirectChildrenCount: async () =>
      Number(await base.attr('data-virtual-direct-children-count')),
    getLevel: async () => Number(await base.attr('data-level')),
    getIndentationWidth: async () =>
      Number(await base.attr('data-indentation-width')),
    isExpandable: () => getMainColumn().getExpandCollapseButton().exists(),
    getKey: async () => {
      const dataHookAttr = await base.attr('data-hook');
      return dataHookAttr?.split('table-row-')[1];
    },
  };
}
