import { UniDriver } from '@wix/wix-ui-test-utils/unidriver';
import { baseUniDriverFactory } from '../../unidriver';
import { ExpandCollapseButtonUniDriver } from './ExpandCollapseButton.uni.driver';
import { getUniDriverStyle } from '../../test-utils/getUniDriverStyle';

export function NestedTableParentCellUniDriver(
  base: UniDriver,
  body: UniDriver,
) {
  const getWrapper = () => base.$('[data-hook="indentation-wrapper"]');

  return {
    ...baseUniDriverFactory(base),
    getTitle: () => getWrapper().$('[data-hook="title"]').text(),
    getSubtitle: () => getWrapper().$('[data-hook="subtitle"]').text(),
    getDragHandle: () => getWrapper().$('[data-hook="drag-handle"]'),
    getExpandCollapseButton: () =>
      ExpandCollapseButtonUniDriver(
        getWrapper().$('[data-hook="expand-collapse-wrapper"]'),
        body,
      ),

    getIndentationDepth: async () => {
      const padding = Number(
        (await getUniDriverStyle(getWrapper()))['padding-inline-start']?.split(
          'px',
        )[0],
      );
      const indentationWidth = Number(
        await getWrapper().attr('data-indentation-width'),
      );
      return padding / indentationWidth;
    },
  };
}
