/*!
 * Crafted with ❤ by Salla
 */
import { h } from "@stencil/core";
import { closeModals } from "./functions";
import SIGift from "../../assets/svg/gift.svg";
export class SallaLoyaltyReward {
    constructor() {
        this.size = 'md';
        this.isActionClickable = (prize) => {
            switch (prize.key?.toLowerCase()) {
                case 'free_product':
                    return prize.is_product_available;
                default:
                    return true;
            }
        };
        this.handleActionArea = () => {
            this.rewardModalOpen.emit(this.prize);
        };
        this.handleAction = () => {
            if (!this.isActionClickable(this.prize))
                return;
            if (!salla.config.isUser()) {
                closeModals(() => salla.event.dispatch('login::open'));
                return;
            }
            else {
                this.confirmModalOpen.emit(this.prize);
            }
        };
    }
    render() {
        return (h("div", { key: '38c63e250c45badf03516c87496619152b9a0af8', class: {
                's-loyalty-program-reward-container': true,
                's-loyalty-program-reward-xs': this.size === 'xs',
            } }, h("div", { key: '93e11a5c458aa3112b00bea4bc845733d8bf4415', onClick: this.handleActionArea, role: "button" }, h("div", { key: '67f5cfe1a3551832548d95bda9c6bcc6cdd26119', class: "s-loyalty-program-reward-img" }, h("img", { key: '36f6dc13da2b7c844d2318d4e9bafeb96d960f11', src: this.prize.image, class: "s-loyalty-program-rewards-img", alt: "" })), h("div", { key: 'c953cfeebaabdad22fba498903936e170aadcebe', class: "s-loyalty-program-reward-content" }, h("div", { key: '68f33aba783ffaef38ea9e4a3f9063b2f68bb2b1', class: "s-loyalty-program-reward-points" }, h("salla-badge", { key: 'bdac8babbf1bbabeec37e92053c4c7eab178a06f', size: "xs" }, h("span", { key: '367f3f154a6079781cece4018337b09996229001', innerHTML: SIGift }), h("span", { key: 'fd8cdd6bafe8a8f5f45f7a4e6df2f074ab2b5961', class: "s-loyalty-program-rewards-points" }, this.prize.cost_points, " ", salla.lang.get('pages.loyalty_program.points')))), h("div", { key: '84f6dbc80ecaa12ab9dacf48ec289bb3f5bdfc84', class: "s-loyalty-program-reward-title" }, h("span", { key: '1505f38884417eee9f266ab3ddb2f57096f6d0da' }, this.group)), h("div", { key: '82ced1df7118958153868c15c193ac03783dc383', class: "s-loyalty-program-reward-name" }, h("div", { key: 'a853fc37628c02ffe064608f6e52725d664fc259', class: "s-loyalty-program-rewards-name", id: `prize-${this.prize.id}` }, this.prize.name)))), h("div", { key: '584d6db1edfafc846eb8908d2762483d5e590296', class: "p-4" }, h("button", { key: 'ac0962db5b5d3121b4c6197c4c378db76a963950', onClick: this.handleAction, disabled: !this.isActionClickable(this.prize), class: {
                's-loyalty-program-rewards-action-base': true,
                's-loyalty-program-rewards-action-on': this.isActionClickable(this.prize),
                's-loyalty-program-rewards-action-off': !this.isActionClickable(this.prize),
            } }, this.isActionClickable(this.prize) ? salla.lang.get('pages.loyalty_program.redeem_reward') : salla.lang.get('pages.loyalty_program.out_of_stock')))));
    }
    static get is() { return "salla-loyalty-reward"; }
    static get originalStyleUrls() {
        return {
            "$": ["salla-loyalty-program.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["salla-loyalty-program.css"]
        };
    }
    static get properties() {
        return {
            "size": {
                "type": "string",
                "attribute": "size",
                "mutable": false,
                "complexType": {
                    "original": "'xs' | 'md'",
                    "resolved": "\"md\" | \"xs\"",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "'md'"
            },
            "prize": {
                "type": "unknown",
                "attribute": "prize",
                "mutable": false,
                "complexType": {
                    "original": "Prize",
                    "resolved": "Prize",
                    "references": {
                        "Prize": {
                            "location": "import",
                            "path": "./interfaces",
                            "id": "src/components/salla-loyalty-program/interfaces.ts::Prize"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false
            },
            "group": {
                "type": "string",
                "attribute": "group",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false
            }
        };
    }
    static get events() {
        return [{
                "method": "rewardModalOpen",
                "name": "rewardModalOpen",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "complexType": {
                    "original": "Prize",
                    "resolved": "Prize",
                    "references": {
                        "Prize": {
                            "location": "import",
                            "path": "./interfaces",
                            "id": "src/components/salla-loyalty-program/interfaces.ts::Prize"
                        }
                    }
                }
            }, {
                "method": "confirmModalOpen",
                "name": "confirmModalOpen",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "complexType": {
                    "original": "Prize",
                    "resolved": "Prize",
                    "references": {
                        "Prize": {
                            "location": "import",
                            "path": "./interfaces",
                            "id": "src/components/salla-loyalty-program/interfaces.ts::Prize"
                        }
                    }
                }
            }];
    }
}
