/*!
 * Crafted with ❤ by Salla
 */
import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
import { c as closeModals } from './functions.js';
import { l as loyaltyProgramIcon } from './gift.js';
import { T as TrackedPromise } from './tracked-promise.js';
import { d as defineCustomElement$1 } from './salla-loading2.js';

const sallaLoyaltyProgramCss = "";

var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
        r = Reflect.decorate(decorators, target, key, desc);
    else
        for (var i = decorators.length - 1; i >= 0; i--)
            if (d = decorators[i])
                r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
const SallaRewardExchange = /*@__PURE__*/ proxyCustomElement(class SallaRewardExchange extends HTMLElement {
    constructor() {
        super();
        this.__registerHost();
        this.productId = null;
    }
    reset(timeout = 0) {
        setTimeout(() => {
            closeModals();
        }, timeout);
    }
    async handleConfirm() {
        try {
            await this.exchange(this.prize.id, null, this.productId);
            this.reset(300);
        }
        catch (error) {
            salla.logger.error(error);
            // Do NOT close the modal; let the error state render so the user sees feedback.
        }
    }
    handleCancel() {
        this.reset(0);
    }
    render() {
        return (h(Host, { key: 'b5b9a966f28520c30917887621e2358fdb9530be' }, h("div", { key: '4e87e3d0530a7fca6db1bf09fd1b059b85e56f10', class: "s-loyalty-program-exchange-heading" }, h("div", { key: '73b9aa3106336e8cdc81ce78371b3efc47b5c569', class: "s-loyalty-program-circle-base s-loyalty-program-circle-size-xl s-loyalty-program-circle-variant-fill" }, h("span", { key: '0e6c488afa39784a40bfed2f1d180fc48664a81a', innerHTML: loyaltyProgramIcon })), h("h2", { key: '7740e27318379264905ff695e0c0cf13b54800d0' }, salla.lang.get('pages.loyalty_program.redeem_reward')), h("p", { key: '81a7ba841e3e26c7c9fc1054745ad163cc347db7' }, salla.lang.get('pages.loyalty_program.redeem_confirmation'), " ", h("span", { key: '0f5d68dbe2de661c2aad02d237d3098349e94120' }, "(", this.prize.cost_points, " ", salla.lang.get('pages.loyalty_program.point'), ")"), " ", salla.lang.get('pages.loyalty_program.for'), " ", h("span", { key: '1daa10a1843938166c6834d0369edfe7e06dd54e' }, "(", this.prize.name, ")"))), h("div", { key: '42384b2df2cbb3775ccc6f7a017d9ef9f770baf5', class: "s-loyalty-program-exchange-btns" }, h("button", { key: 'b90b95adae80a9bcb47c0d039ea8bd9399ee5bc5', class: "s-loyalty-program-rewards-action-base s-loyalty-program-rewards-action-confirm", onClick: () => this.handleConfirm() }, h("span", { key: 'c108973d9729265fb35a0d0fa781d525388a4c12', style: {
                opacity: this.exchange.status !== 'pending' ? '1' : '0',
            } }, salla.lang.get('common.elements.confirm')), h("span", { key: '302a31b9095d153b4662ada13d45cdb6b15664ad', class: "s-loyalty-program-exchange-loading", style: {
                opacity: this.exchange.status === 'pending' ? '1' : '0',
            } }, h("salla-loading", { key: '3e305da32d469f6ec874c128a1fd68356280dc69', color: "primary", size: 24 }))), h("button", { key: '466f8cfea3e370bce9466e9571f4567fb5a7966d', class: "s-loyalty-program-rewards-action-base s-loyalty-program-rewards-action-cancel", onClick: () => this.handleCancel() }, salla.lang.get('common.elements.cancel')))));
    }
    static get style() { return sallaLoyaltyProgramCss; }
}, [0, "salla-reward-exchange", {
        "prize": [16],
        "productId": [2, "product-id"]
    }]);
__decorate([
    TrackedPromise(async (...args) => await salla.loyalty.exchange(...args))
], SallaRewardExchange.prototype, "exchange", void 0);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["salla-reward-exchange", "salla-loading"];
    components.forEach(tagName => { switch (tagName) {
        case "salla-reward-exchange":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, SallaRewardExchange);
            }
            break;
        case "salla-loading":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}
defineCustomElement();

export { SallaRewardExchange as S, defineCustomElement as d };
