package com.playwrightdemo.pages;

import com.microsoft.playwright.options.SelectOption;

import java.util.List;

public class WorklogPage extends BasePage {

    String worklgMenuTxt = "li[title='Worklog'] span";

    String txtFillWorklogMenuLink = "a:has-text('Fill Worklog')";
    String txtWorklogReportMenuLink = "a:has-text('Worklog Report')";

    String titleTextfillWorklogPage = "div.card.form_card h5";

    String titleTextWorklogReportPage = "div.card.form_card h5";

    String btnFillWorklog = "button#myBtn";
    String txtTitleFillWorklogForm = "div.add_worklog_txt";
    String txtWorklogFormDateField = "div.worklog_date_bx input#worklog_date";
    String dropdownSelectProjWorkLogForm = "select.form-control.selectpicker";
    String timeSpentPickerWorklogForm = "div#fromdate";
    String txtAreaTaskDescriptWorklogForm = "div#comments_0 textarea";
    String btnSaveWorklogForm = "button#save";
    String btnAddTaskWorklogForm = "a#new-row";
    String btnDeleteProjWorklogForm = "div.delete_project";
    String txtSucessWorklogFormSubmission = "div#success-message";
    String btnDeleteWorklog = "a.delete_cls";
    String btnOKConfirmationPopup = "div.modal-dialog button.btn.btn-primary";
    String btnCancelConfirmationPopup = "div.modal-dialog button.btn.btn-default";
    String txtMessageConfirmationPopup = "div.bootstrap-dialog-message";
    String txtDeleteWorklogSuccessMessage = "div.alert.alert-success";


    String dropDownUnit = "select#unit";
    String dropDownSupervisor = "select#userid";
    String dropDownProjects = "select#proid";
    String dropDownResource = "select#empid";
    String fromCalendarWorklogReport = "input#startdate";

    String  calendarFromWorklogReport="div#start_date";
    String calendarToWorklogReport ="div#end_date";



    String toCalendarWorklogReport = "input#enddate";
    String btnSearchWorklogReport = "button#btn_search";

    String dayPicker = "//table[@class='table-condensed']//td[@class='day'] [text()='%s']";

    String resultsWorkLogTable="table#users-table tbody";






    public String getWorklogMenuText() {

        return getTextFromSelector(worklgMenuTxt);


    }

    public void selectWorklogMenu() {

        doClickSelector(worklgMenuTxt);

    }

    public String getFillWorklogMenuText() {

        return getTextFromSelector(txtFillWorklogMenuLink);

    }

    public String getWorklogReportMenuText() {

        return getTextFromSelector(txtWorklogReportMenuLink);
    }

    public void clickFillWorklogLink() {

        doClickSelector(txtFillWorklogMenuLink);

    }

    public void clickWorklogReportLink() {

        doClickSelector(txtWorklogReportMenuLink);

    }

    public String getWorklogPageText() {


        return getTextFromSelector(titleTextfillWorklogPage);

    }

    public String getWorklogReportPageText() {

        return getTextFromSelector(titleTextWorklogReportPage);

    }


    public String getFillWorklogButtonText() {

        return getTextFromSelector(btnFillWorklog);
    }

    public void clickFillWorkLogButon() {

        doClickSelector(btnFillWorklog);
    }

    public String getWorkLogFormTitle() {

        return getTextFromSelector(txtTitleFillWorklogForm);
    }

    public void selectProjDropdownWorkLogForm() {

        selectFromDropdown(dropdownSelectProjWorkLogForm, "ISHIR / Other Internal Projects");
    }

    public void enterTimeSpentWorkLogForm() {

        fillFields(timeSpentPickerWorklogForm, "1:15");
    }

    public void enterTaskDescription() {
        fillFields(txtAreaTaskDescriptWorklogForm, "This is for testing purpose, dont approve");
    }

    public void clickSaveButtonWorkLogForm() {

        doClickSelector(btnSaveWorklogForm);
    }

    public String getWorkLogFormSubmitSuccessMessage() {

        return getTextFromSelector(txtSucessWorklogFormSubmission);


    }

    public void deleteWorkogEntry() {

        doClickSelector(btnDeleteWorklog);

    }

    public String getDeleteConfrmationpPopupText() {

        return getTextFromSelector(txtMessageConfirmationPopup);
    }

    public void confirmDeletePopUp() {

        doClickSelector(btnOKConfirmationPopup);
    }

    public void cancelDeletePopUp() {

        doClickSelector(btnCancelConfirmationPopup);

    }

    public String getWorklogEntyDeleteSuccessMessage() {

        return getTextFromSelector(txtDeleteWorklogSuccessMessage);
    }

public void selectUnitDropdown(String [] unitNames){

        SelectFromMultiSelectDropdown(dropDownUnit,unitNames);

}

    public void selectSupervisorDropdown(String[] superVisorNames){

        SelectFromMultiSelectDropdown(dropDownResource,superVisorNames);
    }

    public void selectProjectsDropdown(String [] projNames){

        SelectFromMultiSelectDropdown(dropDownResource,projNames);
    }

    public void selectResourcesDropdown(String [] resourceNames){

        SelectFromMultiSelectDropdown(dropDownResource,resourceNames);

    }


    public void selectFromDateWorklogReport(String dateValue) {

        doClickSelector(calendarFromWorklogReport);
        doClickSelector(String.format(dayPicker, dateValue));

    }

    public void selectToDateWorklogReport(String dateValue) {

        doClickSelector(calendarToWorklogReport);
        doClickSelector(String.format(dayPicker, dateValue));
    }


    public void clickSearchButton(){

        doClickSelector(btnSearchWorklogReport);
    }


public List<String> getWorkLogTableData(){

String rowsLocator=resultsWorkLogTable+" "+"tr";
String rowDataLocator=rowsLocator+" "+"td";
List<String> rowdata=  page.locator(rowDataLocator).allInnerTexts();
return rowdata;

}



}
