using System;
using System.Collections.Generic;
using OpenQA.Selenium;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading;

namespace SeleniumTests
{
    [TestClass]
    public class Careers
    {
        //This function will return true if the xpath given is found and not null
        //Then it will click the link for Utilities
        public static bool UtilitiesIndustryLink()
        {
            IWebElement utilitiesLink = Utilities.FindIwebElement(xpath: "//a[contains(text(),'Utilities')]");
            if (Utilities.ElementExists(utilitiesLink))
            {
                Utilities.ScrollToElement(utilitiesLink);
                Utilities.ClickElement(utilitiesLink);
                return true;
            }
            else { return false; }

        }

        //This function will return true if the xpath given is found and not null
        //Then it will click the link for Legal
        public static bool LegalIndustyLink()
        {
            IWebElement legalLink = Utilities.FindIwebElement(xpath: "//a[contains(text(),'Legal')]");
            if (Utilities.ElementExists(legalLink))
            {
                Utilities.ClickElement(legalLink);
                return true;
            }
            else { return false; }
        }

        //This function will return true if the xpath given is found and not null
        //Then it will click the link for Healthcare
        public static bool HealthcareIndustryLink()
        {
            IWebElement healthcareLink = Utilities.FindIwebElement(xpath: "//a[contains(text(),'Healthcare')]");
            if (Utilities.ElementExists(healthcareLink))
            {
                Utilities.ClickElement(healthcareLink);
                return true;
            }
            else { return false; }
        }

        //This function will return true if the xpath given is found and not null
        //Then it will click the link for Financial
        public static bool FinancialIndustryLink()
        {
            IWebElement financialLink = Utilities.FindIwebElement(xpath: "//a[contains(text(),'Financial Services')]");
            if (Utilities.ElementExists(financialLink))
            {
                Utilities.ClickElement(financialLink);
                return true;
            }
            else { return false; }
        }

        //This function will return true if the xpath given is found and not null
        //Then it will click the link for Logistic
        public static bool LogisticIndustryLink()
        {
            IWebElement logisticsLink = Utilities.FindIwebElement(xpath: "//a[contains(text(),'Logistics')]");
            if (Utilities.ElementExists(logisticsLink))
            {
                Utilities.ClickElement(logisticsLink);
                return true;
            }
            else { return false; }
        }

        //This function will return true if the xpath given is found and not null
        //Then it will click the link for Chicago
        public static bool ChicagoLink()
        {
            Utilities.WaitForElement("//a[contains(text(),'Chicagoland')]");
            IWebElement chicagolandLink = Utilities.FindIwebElement(xpath: "//a[contains(text(),'Chicagoland')]");
            

            if (Utilities.ElementExists(chicagolandLink))
            {
                Utilities.ScrollToElement(chicagolandLink);
                Utilities.ClickElement(chicagolandLink);

                //Thread.Sleep(15000);

                return true;
            }
            else { return false; }
        }

        //This function will return true if the xpath given is found and not null
        //Then it will click the link for East coast
        public static bool EastCoastLink()
        {
            IWebElement eastCoastLink = Utilities.FindIwebElement(xpath: "//a[contains(text(),'East Coast')]");
            if (Utilities.ElementExists(eastCoastLink))
            {
                Utilities.ClickElement(eastCoastLink);
                return true;
            }
            else { return false; }
        }

        //This function will return true if the xpath given is found and not null
        //Then it will click the link for Ireland
        public static bool BelfastLink()
        {
            IWebElement irelandLink = Utilities.FindIwebElement(xpath: "//a[contains(text(),'Northern Ireland')]");
            if (Utilities.ElementExists(irelandLink))
            {
                Utilities.ClickElement(irelandLink);
                return true;
            }
            else { return false; }
        }

        //This function will return true if the xpath given is found and not null
        //Then it will click the link for Argentina
        public static bool ArgentinaLink()
        {
            IWebElement argentinaLink = Utilities.FindIwebElement(xpath: "//a[contains(text(),'Argentina')]");
            if (Utilities.ElementExists(argentinaLink))
            {
                Utilities.ClickElement(argentinaLink);
                return true;
            }
            else { return false; }
        }

        //This function will return true if the xpath given is found and not null
        //Then it will click the link for Quality & Testing
        public static bool QualityTestingLink()
        {
            IWebElement testingQualityLink = Utilities.FindIwebElement(xpath: "//a[contains(text(),'software testing and quality assurance')]");
            if (Utilities.ElementExists(testingQualityLink))
            {
                Utilities.ClickElement(testingQualityLink);
                return true;
            }
            else { return false; }
        }

        //This function will return true if the xpath given is found and not null
        //Then it will click the link for Explore Opportunities under why work on Olenick? section
        public static bool WhySecionExploreOpp()
        {
            IWebElement exploreOppButton = Utilities.FindIwebElement(xpath: "(//a[@href='http://olenick.com/portal/'])[1]");
            if (Utilities.ElementExists(exploreOppButton))
            {
                Console.WriteLine("explore opp button exists");
                Utilities.ClickElement(exploreOppButton);
                return true;
            }
            else
            {
                return false;
            }
        }

        //This function will return true if the xpath given is found and not null
        //Then it will click the link for Explore Opportunities under Join the Olenick Team secion
        public static bool JoinSecionExploreOpp()
        {
            IWebElement exploreOppButton = Utilities.FindIwebElement(xpath: "(//a[@href='http://olenick.com/portal/'])[2]");
            if (Utilities.ElementExists(exploreOppButton))
            {
                Utilities.ClickElement(exploreOppButton);
                return true;
            }
            else return false;
        }


        public static bool OpenAdvisorForm()
        {
            IWebElement consultTAAdvisor = Utilities.FindIwebElement(xpath: "//a[@class='fl-button fl-button-lightbox']");
            if (Utilities.ElementExists(consultTAAdvisor))
            {
                Utilities.ClickElement(consultTAAdvisor);
                return true;
            }
            else { return false; }
        }

        
        public static bool SendAdvisorForm()
        {
            IWebElement nameTextbox = Utilities.FindIwebElement(id: "fl-name");
            Utilities.ElementExists(nameTextbox);
            Utilities.Type(nameTextbox, "Tester");

            IWebElement emailTextbox = Utilities.FindIwebElement(id: "fl-email");
            Utilities.ElementExists(emailTextbox);
            Utilities.Type(emailTextbox, "test@email");

            IWebElement messageTextbox = Utilities.FindIwebElement(id: "fl-message");
            Utilities.ElementExists(messageTextbox);
            Utilities.Type(messageTextbox, "This is a test");

            IWebElement sendButton = Utilities.FindIwebElement(xpath: "//form[@class='fl-contact-form']//a[@class='fl-button']");
            Utilities.ElementExists(sendButton);
            Utilities.ClickElement(sendButton);

            IWebElement errormessage = Utilities.FindIwebElement(xpath: "//span[contains(text(),'Please enter a valid email.')]");
            if (Utilities.ElementExists(errormessage))
            {
                return false;
                //Console.WriteLine("Error message for email");
            }
            else { return true; }
        }

        //This function will get the xpath for How Does it Work accordion
        //it comfirms it is not open else return false.
        //then it click the accordion the return whether the accordion opened
        public static string OpenWorkAccordion()
        {
            IWebElement accordion = Utilities.FindIwebElement(xpath: "//a[contains(text(), 'How Does It Work?')]");
            string accordionatt = Utilities.FindIwebElement(xpath: "//div[contains(@id, 'tab-0')]").GetAttribute("aria-expanded");
            if (accordionatt == "false")
            {
                if (Utilities.ElementExists(accordion))
                {
                    Utilities.ClickElement(accordion);
                    IWebElement textDisplay = Utilities.FindIwebElement(xpath: "//div[contains(@id,'panel-0')]");
                    string display = textDisplay.GetAttribute("style");
                    return display;
                }
                else { return null; }
            }
            else { return null; }
        }

        //This function will get the xpath for How Does it Work accordion
        //it comfirms it is open else return false.
        //then it click the accordion the return whether the accordion closed
        public static string CloseWorkAccordion()
        {
            IWebElement accordion = Utilities.FindIwebElement(xpath: "//a[contains(text(), 'How Does It Work?')]");
            string accordionatt = Utilities.FindIwebElement(xpath: "//div[contains(@id, 'tab-0')]").GetAttribute("aria-expanded");
            if (accordionatt == "true")
            {
                if (Utilities.ElementExists(accordion))
                {
                    Utilities.ClickElement(accordion);
                    IWebElement textdisplay = Utilities.FindIwebElement(xpath: "//div[contains(@id,'panel-0')]");
                    string display = textdisplay.GetAttribute("style");
                    return display;
                }
                else {
                    Utilities.TakeScreenShot("close");
                    return null; 
                }
            }
            else return null;
        }

        //This function will get the xpath for What Can I Hope to Acquire accordion
        //it comfirms it is not open else return false.
        //then it click the accordion the return whether the accordion opened
        public static string OpenAcquireAccordion()
        {
            IWebElement accordion = Utilities.FindIwebElement(xpath: "//div[contains(@id,'tab-1')]");
            string accordionatt = accordion.GetAttribute("aria-expanded");
            if (accordionatt == "false")
            {
                if (Utilities.ElementExists(accordion))
                {
                    Utilities.ClickElement(accordion);
                    IWebElement textdisplay = Utilities.FindIwebElement(xpath: "//div[contains(@id,'panel-1')]");
                    string display = textdisplay.GetAttribute("style");
                    return display;
                }
                else { return null; }
            }
            else return null;
        }

        //This function will get the xpath for What Can I Hope to Acquire accordion
        //it comfirms it is open else return false.
        //then it click the accordion the return whether the accordion closed
        public static string CloseAcquireAccordion()
        {
            IWebElement accordion = Utilities.FindIwebElement(xpath: "//div[contains(@id,'tab-1')]");
            Console.WriteLine("Text displayed in Accordion {0}", accordion.Text);

            accordion.Click();

            string accordionatt = accordion.GetAttribute("aria-expanded");

            Console.WriteLine("Check for accordionatt aria-expanded " + accordionatt);

            if (accordionatt == "true")
            {
                if (Utilities.ElementExists(accordion))
                {
                    //if Accordion element is found on the page
                    Utilities.ScrollToElement(accordion);
                    Utilities.ClickElement(accordion);
                    IWebElement textdisplay = Utilities.FindIwebElement(xpath: "//div[contains(@id,'panel-1')]");
                    string display = textdisplay.GetAttribute("style");
                    return display;
                }
                else
                {
                    Utilities.ScrollToElement(accordion);
                    return null;
                }
            }
            else
            {
                Utilities.ScrollToElement(accordion);
                return null;
            }
        }

        //This function will return true if the xpath given is found and not null
        //Then it will click the link for Learn More
        public static bool LearnMoreButton()
        {
            IWebElement learnMoreButton = Utilities.FindIwebElement(xpath: "//span[contains(text(),'Learn More')]");
            if (Utilities.ElementExists(learnMoreButton))
            {
                Utilities.ClickElement(learnMoreButton);
                return true;
            }
            else return false;

        }

    }
}
-
GoBack