import time
from selenium.webdriver.common.by import By
from Base.BasePage import BasePage
from common.cutils import get_text
from common.untils import DriverTools
from config import password, user_name
from paga.LoginPage import Login
from paga.RaysModernPaperBookPage import RAYSMPB
from paga.AIEditingRoomPage import AIER
from paga.DelPage import Del


class DEA(BasePage):
    def __init__(self):
        super().__init__('web')
        # 数字编辑助理
        self.Digital_editorial_assistant = (By.XPATH,
                                            "(//div[@class='studio-name'][contains(text(),'数字编辑助理')])[1]")
        # 更多
        self.More = (By.XPATH, "//div[@class='button-list-item more-btn hover-bg-color hover-text-color']")
        # 数字编辑助理-制作英语听力配音
        self.Make_English_listening_dubbing = (
            By.XPATH, "//div[@class='button-type-list']//div[1]//div[2]//div[1]//div[1]//div[1]")
        # 输入框
        self.Input_field = (By.XPATH, "//div[@role='textbox']")
        # 发送
        self.send = (By.XPATH, "//button[@class='send-button']")
        # 数字编辑助理-推送英语配音
        self.Make_dubbing = (By.XPATH,
                             "//span[contains(text(),'制作英语听力')]")
        # 数字编辑助理-制作多角色配音
        self.Make_multi_character_voice_overs = (
        By.XPATH, "//div[@class='button-type-list']//div[1]//div[2]//div[2]//div[1]//div[1]")
        # 数字编辑助理-推送多角色配音
        self.multi_role = (By.XPATH,
                           "(//span[contains(text(),'制作配音')])[1]")
        # 数字编辑助理-现代纸书一键制作
        self.Modern_paper_book_one_key_production_resource_allocation = (By.XPATH,
                                                                         "//div[contains(@class,'ant-popover button-list-more-popover ant-popover-placement-topRight')]//div[2]//div[2]//div[1]//div[1]//div[1]")
        # 数字编辑助理-书刊名称输入框
        self.Book_title = (By.XPATH, "//input[@placeholder='请输入书刊名称']")
        # 数字编辑助理-书刊点击查询
        self.Click_query = (By.XPATH, "//div[@class='CreatBookModal-header']//span")
        # 数字编辑助理-勾选应用音频
        self.Audio_frequency = (By.XPATH, "//div[@class='sourceType']//label[2]//span[1]//input[1]")
        # 数字编辑助理-勾选应用读者交流圈
        self.Reader_circle = (By.XPATH, "//label[3]//span[1]//input[1]")
        # 数字编辑助理-一键制作
        self.click_fabrication = (By.XPATH, "//button[@class='ant-btn ant-btn-primary']//span")
        # AI编辑室返回AI编辑工作室首页
        self.Home_page = (By.XPATH, "//span[@class='clickable']")
        # AI编辑工作室返回RAYS现代纸书首页
        self.Home_page01 = (By.XPATH, "//div[@class='system-title']")
        # 数字编辑助理-一键制作-去调整
        self.To_adjust = (By.XPATH, "(//span[contains(text(),'去调整')])[2]")
        # 数字编辑助理-推送一键制作
        self.Modern_paper_book = (By.XPATH,
                           "//span[contains(text(),'制作现代纸书')]")
        # 数字编辑助理-提供资源选题方案灵感
        self.Provide_inspiration_for_resource_selection_schemes = (By.XPATH, "//div[contains(@class,'ant-popover button-list-more-popover ant-popover-placement-topRight')]//div[3]//div[2]//div[1]//div[1]//div[1]")
        # 数字编辑助理-提供资源选题方案灵感-书刊分类-K12中小学教辅
        self.Classification = (By.XPATH, "//div[contains(text(),'K12')]")
        # 数字编辑助理-提供资源选题方案灵感-书刊分类-幼小衔接
        self.Classification01 = (By.XPATH, "//li[@title='幼小衔接']//div[1]")
        # 数字编辑助理-提供资源选题方案灵感-书刊分类-语文
        self.Classification02 = (By.XPATH, "//li[@title='语文']//div[1]")


    #AI编辑室返回AI编辑工作室首页
    def Back(self):
        self.find_ele(self.Home_page).click()
        time.sleep(3)
        self.find_ele(self.Home_page01).click()
        time.sleep(5)

        # 画师
        self.Painter_page=(By.XPATH,"(//div[@class='studio-name'][contains(text(),'AI画师')])[1]")
        #画面描述
        self.Picture_description=(By.XPATH,"//textarea[@placeholder='请输入画面描述，或者点击右上角画图模版，快速生成同款图片']")
        #画图模版
        self.Drawing_template=(By.XPATH,"//div[@class='AiPainterSelectTemplate']//span[1]")
        # 词库
        self.Lexicon = (By.XPATH, "//div[@class='SelectCallWord']//span[1]")
        # 不希望出现的内容
        self.Unwanted_content=(By.XPATH,"//input[@id='negativePrompt']")
        # 立即生成
        self.Immediate_generation=(By.XPATH,"//button[@type='submit']")

        # 书评助理
        self.Book_review_assistant = (By.XPATH, "(//div[@class='studio-name'][contains(text(),'书评助理')])[1]")
        # 童书书评
        self.Children_book_review=(By.XPATH,"(//div[@class='name'][contains(text(),'童书书评')])[1]")
        # 书名
        self.Book_name=(By.XPATH,"//*[@id='App']/div/section/div[1]/div[2]/div/div/div/div/div[2]/div/div/div[2]/div[1]/div[2]/div/div[2]/div[1]/div/div[2]/div")
        # 内容简介
        self.Content_introduction=(By.XPATH,"//*[@id='App']/div/section/div[1]/div[2]/div/div/div/div/div[2]/div/div/div[2]/div[1]/div[2]/div/div[2]/div[1]/div/div[3]/div")
        # 作者简介
        self.Author_introduction=(By.XPATH,"//*[@id='App']/div/section/div[1]/div[2]/div/div/div/div/div[2]/div/div/div[2]/div[1]/div[2]/div/div[2]/div[1]/div/div[4]/div")
        # 发送
        self.Send=(By.XPATH,"//button[contains(text(),'发送')]")
        # 文学书评
        self.Literary_review=(By.XPATH,"(//div[@class='name'][contains(text(),'文学书评')])[1]")
        # 社科书评
        self.Social_science_review=(By.XPATH,"//div[@id='button-2']//div[@class='button-list-item-inner']//div[1]")


    #数字编辑助理 - 制作英语听力配音
    # 数字编辑助理 - 制作英语听力配音
    def meld(self):
        self.find_ele(self.Digital_editorial_assistant).click()
        time.sleep(2)
        self.find_ele(self.More).click()
        time.sleep(2)
        self.find_ele(self.Make_English_listening_dubbing).click()
        time.sleep(2)
        self.windows_change(-1)
        self.close_window()
        self.windows_change(-1)
        self.find_ele(self.Input_field).send_keys("制作英语听力")
        time.sleep(2)
        self.find_ele(self.send).click()
        time.sleep(6)
        a = get_text(self.Make_dubbing)
        print(a)
        self.find_ele(self.Make_dubbing).click()
        time.sleep(3)
        self.windows_change(-1)
        self.close_window()
        self.windows_change(-1)

    # 数字编辑助理 - 制作多角色配音
    def mmcvo(self):
        self.find_ele(self.More).click()
        time.sleep(3)
        self.find_ele(self.Make_multi_character_voice_overs).click()
        time.sleep(3)
        self.windows_change(-1)
        self.close_window()
        self.windows_change(-1)
        self.find_ele(self.Input_field).send_keys("英语配音")
        time.sleep(3)
        self.find_ele(self.send).click()
        time.sleep(6)
        b = get_text(self.multi_role)
        print(b)
        self.find_ele(self.multi_role).click()
        time.sleep(3)
        self.windows_change(-1)
        self.close_window()
        self.windows_change(-1)

    #数字编辑助理 - 现代纸书一键制作-点击
    def mpbokpra(self):
        self.find_ele(self.More).click()
        time.sleep(3)
        self.find_ele(self.Modern_paper_book_one_key_production_resource_allocation).click()
        time.sleep(3)
        self.find_ele(self.Book_title).send_keys("红楼梦")
        time.sleep(3)
        self.find_ele(self.Click_query).click()
        time.sleep(6)
        # self.find_ele(self.Audio_frequency).click()
        # time.sleep(1)
        # self.find_ele(self.Reader_circle).click()
        # time.sleep(1)
        self.find_ele(self.click_fabrication).click()
        time.sleep(6)
        self.find_ele(self.To_adjust).click()
        time.sleep(3)
        self.windows_change(-1)
        self.close_window()
        self.windows_change(-1)


    # 数字编辑助理 - 现代纸书一键制作-输入
    def mpbokpra_input(self):
        self.find_ele(self.Input_field).send_keys("现代纸书制作")
        time.sleep(3)
        self.find_ele(self.send).click()
        time.sleep(6)
        c = get_text(self.Modern_paper_book)
        print(c)
        self.find_ele(self.Modern_paper_book).click()
        time.sleep(3)
        self.find_ele(self.Book_title).send_keys("红楼梦")
        time.sleep(3)
        self.find_ele(self.Click_query).click()
        time.sleep(6)
        # self.find_ele(self.Audio_frequency).click()
        # time.sleep(1)
        # self.find_ele(self.Reader_circle).click()
        # time.sleep(1)
        self.find_ele(self.click_fabrication).click()
        time.sleep(6)
        self.find_ele(self.To_adjust).click()
        time.sleep(3)
        self.windows_change(-1)
        self.close_window()
        self.windows_change(-1)


    # 数字编辑助理 - 提供资源选题方案灵感
    def pifrss(self):
        self.find_ele(self.More).click()
        time.sleep(3)
        self.find_ele(self.Provide_inspiration_for_resource_selection_schemes).click()
        time.sleep(3)
        self.find_ele(self.Classification).click()
        time.sleep(3)
        self.find_ele(self.Classification01).click()
        time.sleep(3)
        self.find_ele(self.Classification02).click()
        time.sleep(6)


    # 画师-画图
    def painter(self):
        self.find_ele(self.Painter_page).click()
        time.sleep(3)
        self.find_ele(self.Picture_description).send_keys("美丽的花朵")
        time.sleep(3)
        # self.find_ele(self.Drawing_template).click()
        # time.sleep(3)
        # self.find_ele(self.Lexicon).click()
        # time.sleep(3)
        self.find_ele(self.Unwanted_content).send_keys("水滴")
        time.sleep(3)
        self.find_ele(self.Immediate_generation).click()
        time.sleep(120)

    # 书评助理
    def bookreview(self):
        self.find_ele(self.Book_review_assistant).click()
        time.sleep(3)
        self.find_ele(self.Children_book_review).click()
        time.sleep(3)
        self.find_ele(self.Book_name).send_keys("西游记")
        time.sleep(3)
        self.find_ele(self.Content_introduction).send_keys("唐僧西天取经")
        time.sleep(3)
        self.find_ele(self.Author_introduction).send_keys("罗贯中")
        time.sleep(3)
        self.find_ele(self.Send).click()
        time.sleep(60)


if __name__ == '__main__':
    DriverTools.get_driver().get('https://rays7.5rs.me/login')
    Login().login(user_name, password)
    RAYSMPB().to_ai_studio()
    AIER().to_ai_room()
    DEA().meld()
    # Del().delete()
    DriverTools.quit_driver()
