import { Component, State, h } from '@stencil/core';
import { FacilitatorService } from '../../../../services/facilitator.service';
import facilitatorStore from '../../../../stores/facilitator.store';
import { AssetsService } from '../../../../services';
import { EnvironmentConfigService } from "../../../../services/environment/environment-config.service";
export class SparkleOnlineStudents {
  constructor() {
    this.showAllModules = true;
  }
  async componentWillLoad() {
    const sparkleConfig = EnvironmentConfigService.getInstance().get('sparkle');
    this.tocData = await AssetsService.getInstance().loadJsonFile(sparkleConfig.tocPath);
  }
  async componentDidLoad() {
    await this.fetchData();
  }
  async fetchData() {
    await FacilitatorService.getInstance().fetchDashboardData({ ClassId: 1 });
  }
  renderClassFeedPosts() {
    var _a, _b;
    return (h("table", { class: "table" },
      h("thead", null,
        h("tr", null,
          h("th", { scope: "col" }, "Name"),
          h("th", { scope: "col" }, "Email"),
          h("th", { scope: "col" }, "Post Text"),
          h("th", { scope: "col" }, "App Name"),
          h("th", { scope: "col" }, "Comment"),
          h("th", { scope: "col" }, "Visibility"))),
      h("tbody", null, (_a = facilitatorStore.state.dashboardData) === null || _a === void 0 ? void 0 :
        _a.ClassFeedPosts.map(item => h("tr", null,
          h("td", null, item.UserName),
          h("td", null, item.Email),
          h("td", null, item.PostText),
          h("td", null, item.MiniAppName),
          h("td", null, item.CommentsCount),
          h("td", null, item.PostVisibility))),
        this.renderLoadingOrNoData(6, (_b = facilitatorStore.state.dashboardData) === null || _b === void 0 ? void 0 : _b.ClassFeedPosts))));
  }
  renderLoadingOrNoData(colspan, items) {
    let status = facilitatorStore.state.dashboardDataLoading ? "Loading..." : ((items === null || items === void 0 ? void 0 : items.length) == 0 ? "No Data" : "");
    if (status) {
      return (h("tr", null,
        h("td", { colSpan: colspan }, status)));
    }
    return null;
  }
  renderStudentsAssignment() {
    var _a, _b;
    return (h("table", { class: "table" },
      h("thead", null,
        h("tr", null,
          h("th", { scope: "col" }, "Name"),
          h("th", { scope: "col" }, "Email"),
          h("th", { scope: "col" }, "Assignment Name"),
          h("th", { scope: "col" }, "Submited Date"),
          h("th", { scope: "col" }, "Assignment Data"))),
      h("tbody", null, (_a = facilitatorStore.state.dashboardData) === null || _a === void 0 ? void 0 :
        _a.StudentAssignments.map(item => h("tr", null,
          h("td", null, item.Name),
          h("td", null, item.Email),
          h("td", null, item.AssignmentName),
          h("td", null, item.SubmittedDate),
          h("td", null, item.AssignmentData))),
        this.renderLoadingOrNoData(5, (_b = facilitatorStore.state.dashboardData) === null || _b === void 0 ? void 0 : _b.StudentAssignments))));
  }
  renderStudentsQuizResponses() {
    var _a, _b;
    return (h("table", { class: "table" },
      h("thead", null,
        h("tr", null,
          h("th", { scope: "col" }, "Name"),
          h("th", { scope: "col" }, "Email"),
          h("th", { scope: "col" }, "Response Type"),
          h("th", { scope: "col" }, "Submitted Date"),
          h("th", { scope: "col" }, "Questions"),
          h("th", { scope: "col" }, "Response"))),
      h("tbody", null, (_a = facilitatorStore.state.dashboardData) === null || _a === void 0 ? void 0 :
        _a.StudentQuizResponses.map(item => h("tr", null,
          h("td", null, item.Name),
          h("td", null, item.Email),
          h("td", null, item.ResponseType),
          h("td", null, item.SubmittedDate),
          h("td", null, item.Question),
          h("td", null, item.Response))),
        this.renderLoadingOrNoData(6, (_b = facilitatorStore.state.dashboardData) === null || _b === void 0 ? void 0 : _b.StudentQuizResponses))));
  }
  renderDiscussion() {
    return (h("div", { class: "accordion", id: "accordionExample" },
      h("div", { class: "accordion-item" },
        h("h2", { class: "accordion-header", id: "headingOne" },
          h("button", { class: "accordion-button", type: "button", "data-bs-toggle": "collapse", "data-bs-target": "#collapseOne", "aria-expanded": "true", "aria-controls": "collapseOne" }, "Accordion Item #1")),
        h("div", { id: "collapseOne", class: "accordion-collapse collapse show", "aria-labelledby": "headingOne", "data-bs-parent": "#accordionExample" },
          h("div", { class: "accordion-body" },
            h("strong", null, "This is the first item's accordion body."),
            " It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the ",
            h("code", null, ".accordion-body"),
            ", though the transition does limit overflow."))),
      h("div", { class: "accordion-item" },
        h("h2", { class: "accordion-header", id: "headingTwo" },
          h("button", { class: "accordion-button collapsed", type: "button", "data-bs-toggle": "collapse", "data-bs-target": "#collapseTwo", "aria-expanded": "false", "aria-controls": "collapseTwo" }, "Accordion Item #2")),
        h("div", { id: "collapseTwo", class: "accordion-collapse collapse", "aria-labelledby": "headingTwo", "data-bs-parent": "#accordionExample" },
          h("div", { class: "accordion-body" },
            h("strong", null, "This is the second item's accordion body."),
            " It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the ",
            h("code", null, ".accordion-body"),
            ", though the transition does limit overflow."))),
      h("div", { class: "accordion-item" },
        h("h2", { class: "accordion-header", id: "headingThree" },
          h("button", { class: "accordion-button collapsed", type: "button", "data-bs-toggle": "collapse", "data-bs-target": "#collapseThree", "aria-expanded": "false", "aria-controls": "collapseThree" }, "Accordion Item #3")),
        h("div", { id: "collapseThree", class: "accordion-collapse collapse", "aria-labelledby": "headingThree", "data-bs-parent": "#accordionExample" },
          h("div", { class: "accordion-body" },
            h("strong", null, "This is the third item's accordion body."),
            " It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the ",
            h("code", null, ".accordion-body"),
            ", though the transition does limit overflow.")))));
  }
  renderFacilitators() {
    var _a, _b;
    return (h("table", { class: "table" },
      h("thead", null,
        h("tr", null,
          h("th", { scope: "col" }, "Name"),
          h("th", { scope: "col" }, "Email"))),
      h("tbody", null, (_a = facilitatorStore.state.dashboardData) === null || _a === void 0 ? void 0 :
        _a.Facilitators.map(item => h("tr", null,
          h("td", null, item.Name),
          h("td", null, item.Email))),
        this.renderLoadingOrNoData(2, (_b = facilitatorStore.state.dashboardData) === null || _b === void 0 ? void 0 : _b.Facilitators))));
  }
  renderStudents() {
    var _a, _b;
    return (h("table", { class: "table" },
      h("thead", null,
        h("tr", null,
          h("th", { scope: "col" }, "Name"),
          h("th", { scope: "col" }, "Email"))),
      h("tbody", null, (_a = facilitatorStore.state.dashboardData) === null || _a === void 0 ? void 0 :
        _a.Students.map(item => h("tr", null,
          h("td", null, item.Name),
          h("td", null, item.Email))),
        this.renderLoadingOrNoData(2, (_b = facilitatorStore.state.dashboardData) === null || _b === void 0 ? void 0 : _b.Students))));
  }
  onModuleDropdownChange(e) {
    this.selectedModule = e.target.value;
    this.selectedSession = "";
    this.selectedPage = "";
  }
  onSessionDropdownChange(e) {
    this.selectedSession = e.target.value;
    this.selectedPage = "";
  }
  filterData() {
  }
  render() {
    return (h("div", null,
      h("nav", { class: "navbar navbar-light bg-light" },
        h("form", { class: "container-fluid justify-content-space-between" },
          h("div", { class: "form-check" },
            h("input", { class: "form-check-input", type: "checkbox", value: "", id: "flexCheckChecked", onInput: (e) => this.showAllModules = e.target.checked, checked: this.showAllModules }),
            h("label", { class: "form-check-label", htmlFor: "flexCheckChecked" }, "All Modules")),
          h("button", { class: "btn btn-primary pull-right", type: "button", onClick: () => this.fetchData() }, "Refresh")),
        !this.showAllModules &&
          h("div", { class: "d-flex" },
            h("div", { class: "p-1" },
              h("select", { class: "form-select", "aria-label": "Default select example", onChange: (e) => this.onModuleDropdownChange(e) },
                h("option", { value: "", selected: this.selectedModule == "" }, "Select Module"),
                this.tocData.courseModules.map(item => h("option", { value: item.urlName, selected: item.urlName == this.selectedModule }, item.name)))),
            h("div", { class: "p-1" }, this.selectedModule && h("select", { class: "form-select", "aria-label": "Default select example", onChange: (e) => this.onSessionDropdownChange(e) },
              h("option", { value: "", selected: this.selectedSession == "" }, "Select Session"),
              this.tocData.courseModules.find(x => x.urlName == this.selectedModule).sessions.map(item => h("option", { value: item.urlName, selected: item.urlName == this.selectedSession }, item.name)))),
            h("div", { class: "p-1" }, this.selectedModule && this.selectedSession && h("select", { class: "form-select", "aria-label": "Default select example", onChange: (e) => this.selectedPage = e.target.value },
              h("option", { value: "", selected: this.selectedPage == "" }, "Select Page"),
              this.tocData.courseModules.find(x => x.urlName == this.selectedModule).sessions.find(x => x.urlName == this.selectedSession).pages.map(item => h("option", { value: item.urlName, selected: item.urlName == this.selectedPage }, item.name)))),
            this.selectedModule && this.selectedSession && this.selectedPage &&
              h("div", { class: "p-1" },
                h("button", { class: "btn btn-primary", type: "button", onClick: () => this.filterData() }, "Filter")))),
      h("div", null,
        h("div", null,
          h("h1", null, "Class Feed Posts"),
          this.renderClassFeedPosts()),
        h("div", null,
          h("h1", null, "Student Assignments"),
          this.renderStudentsAssignment()),
        h("div", null,
          h("h1", null, "Quiz Responses"),
          this.renderStudentsQuizResponses()),
        h("div", null,
          h("h1", null, "Discussions"),
          this.renderDiscussion()),
        h("div", { class: "row" },
          h("div", { class: "col-sm-6" },
            h("h1", null, "Facilitators"),
            this.renderFacilitators()),
          h("div", { class: "col-sm-6" },
            h("h1", null, "Students"),
            this.renderStudents())))));
  }
  static get is() { return "sparkle-facilitator-dashboard"; }
  static get originalStyleUrls() { return {
    "$": ["facilitator-dashboard.css"]
  }; }
  static get styleUrls() { return {
    "$": ["facilitator-dashboard.css"]
  }; }
  static get states() { return {
    "tocData": {},
    "selectedModule": {},
    "selectedSession": {},
    "selectedPage": {},
    "showAllModules": {}
  }; }
}
