<?xml version="1.0" encoding="UTF-8"?>
<!--
 /**
  * Copyright © Magento, Inc. All rights reserved.
  * See COPYING.txt for license details.
  */
-->
<!-- Admin creates new custom website -->
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
    <actionGroup name="AdminCreateWebsiteActionGroup">
        <arguments>
            <argument name="newWebsiteName" type="string"/>
            <argument name="websiteCode" type="string"/>
        </arguments>
        <amOnPage url="{{AdminSystemStoreWebsitePage.url}}" stepKey="navigateToNewWebsitePage"/>
        <waitForPageLoad stepKey="waitForStoresPageLoad"/>
        <!--Create Website-->
        <fillField selector="{{AdminNewWebsiteSection.name}}" userInput="{{newWebsiteName}}" stepKey="enterWebsiteName" />
        <fillField selector="{{AdminNewWebsiteSection.code}}" userInput="{{websiteCode}}" stepKey="enterWebsiteCode" />
        <click selector="{{AdminNewWebsiteActionsSection.saveWebsite}}" stepKey="clickSaveWebsite" />
        <waitForElementVisible selector="{{AdminStoresGridSection.websiteFilterTextField}}" stepKey="waitForStoreGridToReload"/>
        <see userInput="You saved the website." stepKey="seeSavedMessage" />
    </actionGroup>

    <!--Get Website_id-->
    <actionGroup name="AdminGetWebsiteIdActionGroup">
        <arguments>
            <argument name="website"/>
        </arguments>
        <amOnPage url="{{AdminSystemStorePage.url}}" stepKey="amOnTheStorePage"/>
        <click selector="{{AdminDataGridHeaderSection.clearFilters}}" stepKey="clickClearFilters"/>
        <fillField selector="{{AdminStoresGridSection.websiteFilterTextField}}" userInput="{{website.name}}" stepKey="fillSearchWebsiteField"/>
        <click selector="{{AdminDataGridHeaderSection.applyFilters}}" stepKey="clickApplyFilters" />
        <see selector="{{AdminStoresGridSection.websiteNameInFirstRow}}" userInput="{{website.name}}" stepKey="verifyThatCorrectWebsiteFound"/>
        <click selector="{{AdminStoresGridSection.websiteNameInFirstRow}}" stepKey="clickEditExistingWebsite"/>
        <grabFromCurrentUrl regex="~(\d+)/~" stepKey="grabFromCurrentUrl"/>
    </actionGroup>

    <actionGroup name="AssertWebsiteInGrid">
        <arguments>
            <argument name="websiteName" type="string"/>
        </arguments>
        <amOnPage url="{{AdminSystemStorePage.url}}" stepKey="amOnAdminSystemStorePage"/>
        <waitForPageLoad stepKey="waitForAdminSystemStorePageLoad"/>
        <click selector="{{AdminStoresGridSection.resetButton}}" stepKey="resetSearchFilter"/>
        <fillField userInput="{{websiteName}}" selector="{{AdminStoresGridSection.websiteFilterTextField}}" stepKey="fillWebsiteField"/>
        <click selector="{{AdminStoresGridSection.searchButton}}" stepKey="clickSearchButton"/>
        <waitForPageLoad stepKey="waitForStoreToLoad"/>
        <seeElement selector="{{AdminStoresGridSection.websiteName(websiteName)}}" stepKey="seeAssertWebsiteInGrid"/>
    </actionGroup>

    <actionGroup name="AssertWebsiteForm">
        <arguments>
            <argument name="websiteName" type="string"/>
            <argument name="websiteCode" type="string"/>
        </arguments>
        <click selector="{{AdminStoresGridSection.websiteName(websiteName)}}" stepKey="clickWebsiteFirstRowInGrid"/>
        <waitForPageLoad stepKey="waitTillWebsiteFormPageIsOpened"/>
        <grabFromCurrentUrl regex="~(\d+)/~" stepKey="grabWebsiteIdFromCurrentUrl"/>
        <seeInCurrentUrl url="/system_store/editWebsite/website_id/{$grabWebsiteIdFromCurrentUrl}" stepKey="seeWebsiteId"/>
        <seeInField selector="{{AdminNewWebsiteSection.name}}" userInput="{{websiteName}}" stepKey="seeAssertWebsiteName"/>
        <seeInField selector="{{AdminNewWebsiteSection.code}}" userInput="{{websiteCode}}" stepKey="seeAssertWebsiteCode"/>
    </actionGroup>
</actionGroups>