'use strict';
import { expect } from 'playwright/test';
import { resourceNames } from '../../fd-toolbox/resources/resource-names.js';
import { uiAssertInnerText, uiAssertInnerHtml, uiAssertElementVisibility } from './ui-asserts.js';
import { convertMarkdownToHTML } from '../../level2/server/markdown/markdown.js';
import { getToolbarSearchContextId } from '../../level2/fd-app-toolbox/search/Search.funcs.js';
import { getSearchResultTableId } from '../../level2/fd-app-toolbox/search/search-searchable-resource-results/SearchSearchableResourceResult.funcs.js';
import { getResourceListTableId } from '../../level2/meta/resource-list/ResourceList.funcs.js';
import { getResourceListCellElementId, getCellIconElementId } from '../../level2/meta/resource-list/resource-list-cell-element-ids.js';
import { tableElementSuffixes } from '../../level2/fd-component-toolbox/constants/table-element-suffixes.js';
import { elements } from '../../fd-toolbox/constants/elements.js';
import { elementSuffixes } from '../../fd-toolbox/constants/element-suffixes.js';
import { personProps } from '../../level2/common/dev/props/person-props.js';
import { htmlTags } from '../../base-repo/constants/html-element-names.js';
import { htmlAttributes } from '../constants/ui-tester/html-contants.js';
import { getUiTester } from '../ui-tester/global-ui-test.js';
import { headers } from '../constants/test-data/table-headers.js';
import { tablePoGetTableId } from '../page-objects/table-asserts.js';
import { commonLowerCaseWords } from '../../base-repo/constants/internal-common-strings.js';
import { getElementId } from '../../fd-toolbox/html/element-ids.js';
import { createError } from '../../fd-toolbox/errors/errors.js';
import { ensureNotNullOrUndefined } from '../../fd-toolbox/functions/value-checking-functions.js';

var __defProp=Object['defineProperty'],__name=(_0x108cfb,_0x25658a)=>__defProp(_0x108cfb,'name',{'value':_0x25658a,'configurable':!![]});const htmlRoleNames={'table':commonLowerCaseWords['table']};async function assertTableElementCount(_0x5845fc,_0x5546cb){const _0x44cf82=getUiTester(),_0x4da8c5=tablePoGetTableId(_0x5845fc),_0x12baa4=getElementId(_0x4da8c5,elements['table']['row'],''),_0x1b913f=await _0x44cf82['getPrefixesById'](_0x12baa4),_0x161dfc=_0x1b913f['length'];expect(_0x161dfc)['toBe'](_0x5546cb);}__name(assertTableElementCount,'assertTableElementCount');async function assertElementHaveCheckmark(_0x4d20c1){const _0x3eaeb7=getUiTester(),_0x147ca9=await _0x3eaeb7['getById'](_0x4d20c1);await expect(_0x147ca9)['toBeVisible']();}__name(assertElementHaveCheckmark,'assertElementHaveCheckmark');async function assertTableColumnHasValues(_0x3df492,_0xd1d53b,_0x46b12b){const _0x5aad3f=getUiTester(),_0x4ecd49=getResourceListTableId(_0x3df492),_0x266dbe=_0x4ecd49+_0xd1d53b+tableElementSuffixes['cell'],_0x1febb7=await _0x5aad3f['getPrefixesById'](_0x266dbe);for(const _0x3e03a5 of _0x1febb7){await expect(_0x3e03a5)['toHaveText'](_0x46b12b);}}__name(assertTableColumnHasValues,'assertTableColumnHasValues');async function assertTableDataDisplayed(_0x25ac5d){const _0x7b6bdc=tablePoGetTableId(_0x25ac5d);await assertTableDisplayed(_0x7b6bdc);const _0x526ffe=getUiTester(),_0x1d7027=getElementId(_0x7b6bdc,elements['table']['row']),_0xe725e1=await _0x526ffe['waitForElementToLoad'](_0x1d7027);expect(_0xe725e1)['toBe'](!![]);}__name(assertTableDataDisplayed,'assertTableDataDisplayed');async function assertTablePerson(_0x4c634f){await assertTableHeaderPerson(),await assertTableRowPerson(_0x4c634f);}__name(assertTablePerson,'assertTablePerson');async function assertTableRowPerson(_0x48faed){const _0x2f88e9=getResourceListTableId(resourceNames['person']),_0xfa0207=await getRowIndexByText(_0x48faed['name']);await assertTableCellValue(_0x48faed['name'],_0xfa0207,personProps['name'],_0x2f88e9),await assertTableCellValue(ensureNotNullOrUndefined(_0x48faed['lastName']),_0xfa0207,personProps['lastName'],_0x2f88e9),await assertTableCellValue(_0x48faed['age']['toString'](),_0xfa0207,personProps['age'],_0x2f88e9),await assertTableMarkdownCellValue(_0xfa0207,personProps['description'],_0x2f88e9,ensureNotNullOrUndefined(_0x48faed['description'])),await assertTableBoolCellValue(_0xfa0207,personProps['isMarried'],_0x2f88e9,_0x48faed['isMarried']),await assertTableCellValue(ensureNotNullOrUndefined(_0x48faed['favoriteNumber'])['toString'](),_0xfa0207,personProps['favoriteNumber'],_0x2f88e9),await assertTableBoolCellValue(_0xfa0207,personProps['hasKids'],_0x2f88e9,_0x48faed['hasKids']),await assertTableBoolCellValue(_0xfa0207,personProps['areKidsVaccinated'],_0x2f88e9,_0x48faed['areKidsVaccinated']),await assertTableCellValue(ensureNotNullOrUndefined(_0x48faed['firstbornName']),_0xfa0207,personProps['firstbornName'],_0x2f88e9),await assertEmptyTableCellValue(_0xfa0207,personProps['education'],_0x2f88e9),await assertEmptyTableCellValue(_0xfa0207,personProps['bio'],_0x2f88e9);}__name(assertTableRowPerson,'assertTableRowPerson');async function assertSearchTableElementCount(_0x5f1141,_0x47696d,_0x55e1a5){const _0xe7b1fa=getUiTester(),_0x3fa602=getSearchResultTableId(getToolbarSearchContextId(),_0x5f1141),_0x17f603=getElementId(_0x3fa602,_0x47696d,''),_0x21cc2f=await _0xe7b1fa['getPrefixesById'](_0x17f603),_0x55a4a9=_0x21cc2f['length'];expect(_0x55a4a9)['toBe'](_0x55e1a5);}__name(assertSearchTableElementCount,'assertSearchTableElementCount');async function assertTablePagerVisibility(_0x517937,_0x17103d){const _0x162423=getUiTester(),_0xdc91f0=await _0x162423['getById'](_0x517937),_0x3c5296=_0x162423['page']['getByRole'](htmlRoleNames['table'])['filter']({'has':_0xdc91f0}),_0x47805f=_0x3c5296['locator'](await _0x162423['getById'](elements['pager']['previousPageButton'])),_0x523b3a=_0x3c5296['locator'](await _0x162423['getById'](elements['pager']['nextPageButton']));expect(_0x47805f)['toBeVisible']({'visible':_0x17103d}),expect(_0x523b3a)['toBeVisible']({'visible':_0x17103d});}__name(assertTablePagerVisibility,'assertTablePagerVisibility');async function assertTableHeaderPerson(){await assertTableHeaderValue(personProps['name'],headers['name']),await assertTableHeaderValue(personProps['lastName'],headers['lastName']),await assertTableHeaderValue(personProps['age'],headers['age']),await assertTableHeaderValue(personProps['description'],headers['description']),await assertTableHeaderValue(personProps['isMarried'],headers['isMarried']),await assertTableHeaderValue(personProps['favoriteNumber'],headers['favoriteNumber']),await assertTableHeaderValue(personProps['phoneBrandId'],headers['phoneBrandId']),await assertTableHeaderValue(personProps['hasKids'],headers['hasKids']),await assertTableHeaderValue(personProps['areKidsVaccinated'],headers['areKidsVaccinated']),await assertTableHeaderValue(personProps['firstbornName'],headers['firstbornName']),await assertTableHeaderValue(personProps['education'],headers['education']),await assertTableHeaderValue(personProps['bio'],headers['bio']),await assertTableHeadersDoesNotExists(personProps['middleName']),await assertTableHeadersDoesNotExists(personProps['numberOfFamilyMembers']);}__name(assertTableHeaderPerson,'assertTableHeaderPerson');async function assertTableCellValue(_0x3caca6,_0x329bea,_0x6331c5,_0x1d79ff){const _0x13360a=getResourceListCellElementId(_0x1d79ff,_0x6331c5,_0x329bea);await uiAssertInnerText(_0x13360a,_0x3caca6);}__name(assertTableCellValue,'assertTableCellValue');async function assertEmptyTableCellValue(_0x31d653,_0xc8331e,_0x586152){await assertTableCellValue('',_0x31d653,_0xc8331e,_0x586152);}__name(assertEmptyTableCellValue,'assertEmptyTableCellValue');async function assertTableMarkdownCellValue(_0x35e4d7,_0x312d91,_0x43ff92,_0x5c6576){const _0x45cbb8=getResourceListCellElementId(_0x43ff92,_0x312d91,_0x35e4d7),_0x3462e9='<'+htmlTags['div']+'>'+convertMarkdownToHTML(_0x5c6576)+'</'+htmlTags['div']+'>';await uiAssertInnerHtml(_0x45cbb8,_0x3462e9);}__name(assertTableMarkdownCellValue,'assertTableMarkdownCellValue');async function assertTableHeaderValue(_0x5d5217,_0x485860){await uiAssertInnerText(_0x5d5217+elementSuffixes['header'],_0x485860);}__name(assertTableHeaderValue,'assertTableHeaderValue');async function assertTableHeadersDoesNotExists(_0x536547){const _0x14bd01=getUiTester(),_0x4fb55d=_0x536547+elementSuffixes['header'],_0x266a7d=await _0x14bd01['isElementExists'](_0x4fb55d);expect(_0x266a7d)['toBe'](![]);}__name(assertTableHeadersDoesNotExists,'assertTableHeadersDoesNotExists');async function assertTableBoolCellValue(_0x1f9918,_0x2fb58d,_0x58fb9d,_0x5de854){const _0x3837fa=getCellIconElementId(_0x58fb9d,_0x2fb58d,_0x1f9918),_0x40470c=_0x5de854??![];await uiAssertElementVisibility(_0x3837fa,_0x40470c);}__name(assertTableBoolCellValue,'assertTableBoolCellValue');async function assertTableDisplayed(_0x5e2c3f){const _0x3463a4=getUiTester(),_0x503379=await _0x3463a4['waitForElementToLoad'](_0x5e2c3f);expect(_0x503379)['toBe'](!![]);}__name(assertTableDisplayed,'assertTableDisplayed');async function getRowIndexByText(_0x1a5dd6){const _0x2ad9ba=getUiTester(),_0x27a095=htmlAttributes['dataRowIndex'],_0x193941=_0x2ad9ba['page']['getByRole']('row')['filter']({'hasText':_0x1a5dd6})['first'](),_0x114924=_0x193941['locator']('span['+_0x27a095+']'),_0x3d1ac3=await _0x114924['getAttribute'](_0x27a095);if(!_0x3d1ac3)throw createError('Row\x20containing\x20text\x20\x27'+_0x1a5dd6+'\x27\x20not\x20found\x20in\x20the\x20table');return _0x3d1ac3;}__name(getRowIndexByText,'getRowIndexByText');

export { assertElementHaveCheckmark, assertSearchTableElementCount, assertTableColumnHasValues, assertTableDataDisplayed, assertTableElementCount, assertTablePagerVisibility, assertTablePerson, assertTableRowPerson };
