import { r as registerInstance, c as createEvent, h, g as getElement } from './index-f1d2a96f.js';
import { _ as __ } from './default-i18n-91ef32a0.js';
import './index-0a61debd.js';
import { o as openWormhole } from './consumer-7a54eb9f.js';
import { s as stopAnimations, g as getAnimation, a as animateTo, c as shimKeyframesHeightAuto, b as setDefaultAnimation } from './animation-registry-e97b1b9d.js';
import './_commonjsHelpers-9943807e.js';

const scOrderSummaryCss = ":host{display:block;font-family:var(--sc-font-sans);font-size:var(--sc-checkout-font-size, 16px)}.collapse-link{display:flex;align-items:center;gap:0.35em}.summary__content--empty{display:none}.collapse-link__icon{width:18px;height:18px;color:var(--sc-color-gray-500)}.item__product+.item__product{margin-top:20px}.empty{color:var(--sc-color-gray-500)}.summary{position:relative;user-select:none;cursor:pointer}.summary .collapse-link__icon{transition:transform 0.25s ease-in-out}.summary--open .collapse-link__icon{transform:rotate(180deg)}::slotted(*){margin:4px 0 !important}::slotted(sc-divider){margin:16px 0 !important}sc-line-item~sc-line-item{margin-top:14px}";

const ScOrderSummary = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.scShow = createEvent(this, "scShow", 7);
    this.scHide = createEvent(this, "scHide", 7);
    this.closedText = __('Show Summary', 'surecart');
    this.openText = __('Summary', 'surecart');
    this.collapsible = false;
  }
  componentDidLoad() {
    this.body.hidden = this.collapsed;
    this.body.style.height = !this.collapsed ? 'auto' : '0';
  }
  handleClick(e) {
    e.preventDefault();
    if (this.empty && !this.loading)
      return;
    this.collapsed = !this.collapsed;
  }
  renderHeader() {
    var _a;
    // loading state
    if (this.loading && !((_a = this.order) === null || _a === void 0 ? void 0 : _a.id)) {
      return (h("sc-line-item", null, h("sc-skeleton", { slot: "title", style: { width: '120px', display: 'inline-block' } }), h("sc-skeleton", { slot: "price", style: { 'width': '70px', 'display': 'inline-block', '--border-radius': '6px' } }), h("sc-skeleton", { slot: "currency", style: { width: '30px', display: 'inline-block' } })));
    }
    return (h("sc-line-item", { style: { '--price-size': 'var(--sc-font-size-x-large)' } }, h("span", { class: "collapse-link", slot: "title", onClick: e => this.handleClick(e) }, this.collapsed ? this.closedText : this.openText, h("svg", { xmlns: "http://www.w3.org/2000/svg", class: "collapse-link__icon", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor" }, h("path", { "stroke-linecap": "round", "stroke-linejoin": "round", "stroke-width": "2", d: "M19 9l-7 7-7-7" }))), h("span", { slot: "description" }, h("slot", { name: "description" })), h("span", { slot: "price" }, h("sc-total", { total: 'total', order: this.order }))));
  }
  async handleOpenChange() {
    if (!this.collapsed) {
      this.scShow.emit();
      await stopAnimations(this.body);
      this.body.hidden = false;
      const { keyframes, options } = getAnimation(this.el, 'summary.show');
      await animateTo(this.body, shimKeyframesHeightAuto(keyframes, this.body.scrollHeight), options);
      this.body.style.height = 'auto';
    }
    else {
      this.scHide.emit();
      await stopAnimations(this.body);
      const { keyframes, options } = getAnimation(this.el, 'summary.hide');
      await animateTo(this.body, shimKeyframesHeightAuto(keyframes, this.body.scrollHeight), options);
      this.body.hidden = true;
      this.body.style.height = 'auto';
    }
  }
  render() {
    return (h("div", { class: { 'summary': true, 'summary--open': !this.collapsed } }, this.collapsible && this.renderHeader(), h("div", { ref: el => (this.body = el), class: {
        'summary__content': true,
        'summary__content--empty': this.empty && !this.loading,
      } }, h("slot", null)), this.empty && !this.loading && h("p", { class: "empty" }, __('Your cart is empty.', 'surecart'))));
  }
  get el() { return getElement(this); }
  static get watchers() { return {
    "collapsed": ["handleOpenChange"]
  }; }
};
setDefaultAnimation('summary.show', {
  keyframes: [
    { height: '0', opacity: '0' },
    { height: 'auto', opacity: '1' },
  ],
  options: { duration: 250, easing: 'ease' },
});
setDefaultAnimation('summary.hide', {
  keyframes: [
    { height: 'auto', opacity: '1' },
    { height: '0', opacity: '0' },
  ],
  options: { duration: 250, easing: 'ease' },
});
openWormhole(ScOrderSummary, ['order', 'loading', 'empty'], false);
ScOrderSummary.style = scOrderSummaryCss;

export { ScOrderSummary as sc_order_summary };
