import { getHumanDiscount } from '../../../../functions/price';
import { Component, h, Prop } from '@stencil/core';
import { __ } from '@wordpress/i18n';
import { openWormhole } from 'stencil-wormhole';
export class ScOrderConfirmationTotals {
  renderDiscountLine() {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
    if (!((_c = (_b = (_a = this.order) === null || _a === void 0 ? void 0 : _a.discount) === null || _b === void 0 ? void 0 : _b.promotion) === null || _c === void 0 ? void 0 : _c.code)) {
      return null;
    }
    let humanDiscount = '';
    if ((_e = (_d = this.order) === null || _d === void 0 ? void 0 : _d.discount) === null || _e === void 0 ? void 0 : _e.coupon) {
      humanDiscount = getHumanDiscount((_g = (_f = this.order) === null || _f === void 0 ? void 0 : _f.discount) === null || _g === void 0 ? void 0 : _g.coupon);
    }
    return (h("sc-line-item", { style: { marginTop: 'var(--sc-spacing-small)' } },
      h("span", { slot: "description" },
        __('Discount', 'surecart'),
        h("br", null),
        ((_k = (_j = (_h = this.order) === null || _h === void 0 ? void 0 : _h.discount) === null || _j === void 0 ? void 0 : _j.promotion) === null || _k === void 0 ? void 0 : _k.code) && (h("sc-tag", { type: "success", size: "small" }, (_o = (_m = (_l = this.order) === null || _l === void 0 ? void 0 : _l.discount) === null || _m === void 0 ? void 0 : _m.promotion) === null || _o === void 0 ? void 0 : _o.code))),
      humanDiscount && (h("span", { class: "coupon-human-discount", slot: "price-description" },
        "(",
        humanDiscount,
        ")")),
      h("sc-format-number", { slot: "price", type: "currency", currency: (_p = this.order) === null || _p === void 0 ? void 0 : _p.currency, value: -((_q = this.order) === null || _q === void 0 ? void 0 : _q.discount_amount) })));
  }
  render() {
    return (h("div", { class: { 'line-item-totals': true } },
      h("sc-line-item-total", { order: this.order, total: "subtotal" },
        h("span", { slot: "description" }, __('Subtotal', 'surecart'))),
      this.renderDiscountLine(),
      h("sc-divider", { style: { '--spacing': 'var(--sc-spacing-small)' } }),
      h("sc-line-item-total", { order: this.order, size: "large", "show-currency": true },
        h("span", { slot: "description" }, __('Total', 'surecart')))));
  }
  static get is() { return "sc-order-confirmation-totals"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() { return {
    "$": ["sc-order-confirmation-totals.css"]
  }; }
  static get styleUrls() { return {
    "$": ["sc-order-confirmation-totals.css"]
  }; }
  static get properties() { return {
    "order": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Order",
        "resolved": "Order",
        "references": {
          "Order": {
            "location": "import",
            "path": "../../../../types"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    }
  }; }
}
openWormhole(ScOrderConfirmationTotals, ['order', 'busy', 'loading', 'empty'], false);
