using ESuite.UI.E2E.Helpers;
using OpenQA.Selenium;

namespace ESuite.UI.E2E.Pages
{
    public class DomainEditPage
    {
        private readonly IWebDriver driver;

        // Constructor to initialize the driver
        public DomainEditPage(IWebDriver driver)
        {
            this.driver = driver;
        }

        // Page elements
        public By EditButton(string? name) => By.XPath($"//td[text()='{name}']/following-sibling::td/a[contains(@class, 'btn-primary')]/*[@data-icon='pen-to-square']");
        public By EditPageTitle => By.XPath("//h1[text()='Edit']");
        public By TemplateNameInList(string? name) => By.XPath($"//ul[@class='mail-types']/li[text()='{name}']");

        public By RoleAccessCheckbox(string? name) => By.CssSelector($"input#{name}");
        public static By SubjectInput => By.CssSelector("input#subject");
        public By SubjectNameInField(string name) => By.XPath($"//input[@id='subject'][@value='{name}']");

        public static By AddUserToRoleButton => By.Id("btnAddUserToRole");
        public By MailTemplateFormByName(string name) => By.XPath($"//form[@template-name='{name}']");
        public static By RoleSaveButton => By.XPath("//button[contains(@class, 'btn-primary') and text()='Save']");

        // Page actions
        public void ChooseMailTemplate(string? templateName)
        {
            By template = TemplateNameInList(templateName);
            I.WaitForVisible(template);
            I.Click(template);
            I.WaitForVisible(MailTemplateFormByName(templateName!.Replace(" ","")));
        }

    }
}