import CalendarUtils from "@dvn/core/util/calendar";
import { SozlukApi } from "@dvn/sozluk/api";
import { Component, h, Host, Prop, Event, State } from "@stencil/core";
import { sozlukEntries } from "../sozluk-entries";
import { mentornityAnnouncementWrapperI18nDefault, MentornityAnnouncementWrapperI18nKey } from "./i18n";
export class MentornityAnnouncementsMailingReport {
  constructor() {
    this.setDictionaryLanguage = async () => {
      const apiSozluk = new SozlukApi().setLanguage(this.item.language).setContents(sozlukEntries);
      this.strings = await apiSozluk.getContent(MentornityAnnouncementWrapperI18nKey, mentornityAnnouncementWrapperI18nDefault);
    };
  }
  componentWillLoad() {
    this.setDictionaryLanguage();
  }
  render() {
    var _a, _b, _c, _d, _e, _f, _g;
    const { strings } = this;
    if (!strings)
      return;
    const hasSentEmails = ((_b = (_a = this.item) === null || _a === void 0 ? void 0 : _a.targetList) === null || _b === void 0 ? void 0 : _b.length) > 0;
    const sentEmailsDate = ((_d = (_c = this.item) === null || _c === void 0 ? void 0 : _c.sentEmailsAt) === null || _d === void 0 ? void 0 : _d.length) > 0 && CalendarUtils.format(((_e = this.item) === null || _e === void 0 ? void 0 : _e.sentEmailsAt[((_g = (_f = this.item) === null || _f === void 0 ? void 0 : _f.sentEmailsAt) === null || _g === void 0 ? void 0 : _g.length) - 1]) * 1000, `DD-MM-YYYY - ${CalendarUtils.timeFormat === '12-hour' ? 'hh:mm A' : 'HH:mm'}`); // get latest sent date
    return (h(Host, null, hasSentEmails ?
      h("div", { class: "d-flex align-items-center" },
        h("p", { class: "m-0" }, SozlukApi.build(strings.sentOn, { date: sentEmailsDate })),
        h("strong", { class: "m-0 ml-3", style: { cursor: 'pointer' }, onClick: () => this.openAnnouncementReport.emit(this.item) },
          h("dvn-icon", { iconName: "uil uil-envelope-check" }),
          strings.checkReport))
      :
        h("div", { class: "d-flex align-items-center" },
          h("dvn-button", { tint: "primary", leaned: true, scale: "small", onClick: () => this.openSelectUsersDialog.emit(this.item) }, strings.sendNow),
          h("p", { class: "m-0 ml-3" }, strings.notSent))));
  }
  static get is() { return "mentornity-announcements-mailing-report"; }
  static get properties() { return {
    "item": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "DataModel",
        "resolved": "DataModel",
        "references": {
          "DataModel": {
            "location": "import",
            "path": "@dvn/core/models/data-model"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    }
  }; }
  static get states() { return {
    "strings": {}
  }; }
  static get events() { return [{
      "method": "openSelectUsersDialog",
      "name": "openSelectUsersDialog",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }, {
      "method": "openAnnouncementReport",
      "name": "openAnnouncementReport",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }]; }
}
