package com.playwrightdemo.pages;

import com.microsoft.playwright.Page;
import com.playwrightdemo.Base.TestBase;

import java.io.IOException;
import java.util.List;

public class AttendancePage extends BasePage {


    String menuAttendance = "li[data-label='attendance']";
    String txtMenuAttdCal = "a:has-text('Attendance Calendar')";
    String txtMenuApplyAttd = "a:has-text('Apply Attendance')";
    String txtHeaderAttendanceCal = "div.card.form_card h5";
    String txtHeaderApplyAttendance = "div.card.form_card h5";

    String calendar = "input#date_for";

    String tableData = "div.datepicker-days table.table-condensed";

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

    String reasonDropDown = "select#reason";

    String selectorPunchInTime = "input#punch_in";

    String selectorPunchOutTime = "input#punch_out";
    String txtboxValidReason = "textarea[name='validreason']";

    String btnAttendanceSubmit = "button#submit-attn";

    String timePickHour = "input.bootstrap-timepicker-hour";

    String timePickMins = "input.bootstrap-timepicker-minute";

    String arrowdownCounter = "a[data-action='decrementHour']";

    String arrowUPCounterHour = "a[data-action='incrementHour']";

    String arrowUPCounterMinute = "a[data-action='incrementMinute']";


    String btnNoAtPopup = "div.modal-dialog button.btn.btn-default";

    String btnYesAtPopup = "div.modal-dialog button.btn.btn-primary";

    String txtFormSubmitErrorMessage = "div.alert.alert-danger";

    String attendanceTableData = "table#attendance-table tbody tr";

    String txtAttndnceReqList = "div.card.table_card h5";

    String fromCalendarPicker = "div#fromdate";

    String toCalendarPicker = "div#todate";

    String btnSearch = "button#btnsearch";

    String searchTableData = "table#dataTables-attendence td";

    String attendanceCalendarFromDate = "input#date_frm";

    String attendanceCalendaToDate = "input#date_to";

    String empModeDropdown = "select#employement";

    String employeeDropdown = "select#emp";

    String attendanceCalendarSearchButton = "button#btnsearch";

    String attendanceCalendarTable="table#attendance-table tbody td";

    String txtAvgTimeSpent="div.card.table_card h5";

    String txtFormSubmissionSuccess="div.alert.alert-success";

   String attdListFromcalendar ="div#fromdate";

    String attdListTocalendar ="div#todate";



    // Page page;


    public AttendancePage() throws IOException {

        //this.page=page;
    }


    public void selectAttendanceMenu() {

        doClickSelector(menuAttendance);

    }

    public String getApplyAttendanceMenuName() {

        return getTextFromSelector(txtMenuApplyAttd);


    }


    public String getAttendanceCalendarMenuName() {

        return getTextFromSelector(txtMenuAttdCal);


    }

    public void clickApplyAttendanceLink() {

        doClickSelector(txtMenuApplyAttd);


    }


    public void clickAttendanceCalLink() {

        doClickSelector(txtMenuAttdCal);


    }

    public String getApplyAttendancePageText() {

        return getTextFromSelector(txtHeaderApplyAttendance);

    }


    public String getAttendanceCalPageText() {

        return getTextFromSelector(txtHeaderAttendanceCal);

    }

    public void getDataFromCalendar(String dateValue) {

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


    }

    public void selectValueFromReasonDropdown(String dropdownValue) {

        selectFromDropdown(reasonDropDown, dropdownValue);

    }

    public void setPunchInTime(int hour, int mins) throws InterruptedException {

        doClickSelector(selectorPunchInTime);

        selectHourTimer(hour, arrowUPCounterHour);

        selectMinuteTimer(mins,arrowUPCounterMinute);



    }

    public void setPunchOutTime(int hour, int mins) throws InterruptedException {

        doClickSelector(selectorPunchOutTime);

        selectHourTimer(hour, arrowUPCounterHour);

        selectMinuteTimer(mins,arrowUPCounterMinute);


    }

    public void enterValidReason(String validReason) {

        doClickSelector(txtboxValidReason);

        fillFields(txtboxValidReason, validReason);

    }

    public void submitAttendanceForm() {

        doClickSelector(btnAttendanceSubmit);
    }


    public void dismissPopup() {

        doClickSelector(btnNoAtPopup);

    }

    public void acceptPopup() {

        doClickSelector(btnYesAtPopup);

    }


    public void getAlertText() {


    }

    public String getAttendanceListext() {

        return getTextFromSelector(txtAttndnceReqList);

    }


    public String getAttendanceFormSubmissionError() {

        return getTextFromSelector(txtFormSubmitErrorMessage);

    }

    public void clickSearchButton() {

        doClickSelector(btnSearch);


    }

    public void selectFromDateCalendar() {

        doClickSelector(fromCalendarPicker);

    }


    public void selectToDateCalendar() {

        doClickSelector(toCalendarPicker);


    }

    public List getResultTableData() {

        return page.locator(searchTableData).allTextContents();

    }

    public void selectEmpDropdown(String empName) {

        selectFromDropdown(employeeDropdown, empName);
    }

    public void selectEmpModeDropdown(String empMode) {

        selectFromDropdown(empModeDropdown, empMode);

    }

    public void selectfromDateAttndCalendar(String dateValue) {

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

    }

    public void selectToDateAttndCalendar(String dateValue) {

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


    public void clickSearchAttendanceCalendar() {


    doClickSelector(attendanceCalendarSearchButton);
}


public List getAttendanceCalendarTableData () {

        return page.locator(attendanceCalendarTable).allTextContents();

}

public String getAverageTimeSpent() {

      return getTextFromSelector(txtAvgTimeSpent);

}

public String getAttendanceFormSubmissionSuccess() {

        return getTextFromSelector(txtFormSubmissionSuccess);
}


    public void getDataFromCalendarAttndlist(String dateValue) {

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


    }

    public void getDataToCalendarAttndlist(String dateValue) {

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


    }

}
