import { Component, Prop, Host, h, State, Listen } from '@stencil/core';
export class SparkleQuizContainer {
  constructor() {
    this.showInstantResult = false;
    this.submitted = false;
    this.answers = {};
  }
  //TODO: not working
  pageDidLoadHandler($event) {
    if ($event) {
      this.pageInfo = $event.detail.pageInfo;
      console.log("pageInfo", this.pageInfo);
    }
  }
  updateQuizAnswerModelHandler(obj) {
    if (obj.detail.question) {
      this.answers[obj.detail.question.questionId] = {
        question: obj.detail.question,
        answer: obj.detail.answer
      };
    }
    console.log(this.answers);
  }
  submitQuiz() {
    this.submitted = true;
    let model = {
      pageInfo: this.pageInfo,
      quiz: this.answers
    };
    console.log(model);
    //post api
  }
  render() {
    return (h(Host, null,
      this.questionIds && this.questionIds.split(",").map((id => h("sparkle-quiz-v1", { questionId: +id, submitted: this.submitted, showInstantResult: this.showInstantResult }))),
      h("ion-button", { slot: "end", onClick: () => this.submitQuiz() }, "Submit")));
  }
  static get is() { return "sparkle-quiz-container"; }
  static get originalStyleUrls() { return {
    "$": ["sparkle-quiz-container.css"]
  }; }
  static get styleUrls() { return {
    "$": ["sparkle-quiz-container.css"]
  }; }
  static get properties() { return {
    "questionIds": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "question-ids",
      "reflect": false
    },
    "showInstantResult": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "show-instant-result",
      "reflect": false,
      "defaultValue": "false"
    }
  }; }
  static get states() { return {
    "submitted": {}
  }; }
  static get listeners() { return [{
      "name": "pageDidLoad",
      "method": "pageDidLoadHandler",
      "target": "document",
      "capture": false,
      "passive": false
    }, {
      "name": "quizAnswerChanged",
      "method": "updateQuizAnswerModelHandler",
      "target": "body",
      "capture": false,
      "passive": false
    }]; }
}
