/*!
 * Crafted with ❤ by Salla
 */
import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';

const sallaOrderEditProductCardCss = ":host{display:block;min-width:0}";

const SallaOrderEditProductCard$1 = /*@__PURE__*/ proxyCustomElement(class SallaOrderEditProductCard extends HTMLElement {
    constructor() {
        super();
        this.__registerHost();
        this.orderEditProductSelected = createEvent(this, "orderEditProductSelected", 7);
    }
    get productData() {
        if (!this.product) {
            return {};
        }
        if (typeof this.product === 'object') {
            return this.product;
        }
        try {
            return JSON.parse(this.product);
        }
        catch (_error) {
            return {};
        }
    }
    handleSelectProduct() {
        this.orderEditProductSelected.emit({ product: this.productData });
    }
    render() {
        const product = this.productData;
        const productName = product?.name || salla.lang.getWithDefault('common.elements.product', 'منتج');
        const price = product?.price;
        return (h(Host, { key: 'e5837d7ec53f2566fe981f02a95b52c7c817821c' }, h("button", { key: '415861262349f83c3c7d1dc72d9f8f01f855317e', type: "button", class: "s-order-edit-product-card", onClick: () => this.handleSelectProduct() }, h("div", { key: '072d3af840d5044636380f5620703cc446877162', class: "s-order-edit-product-card-media" }, product?.image?.url ? (h("img", { src: product.image.url, alt: product.image.alt || productName, class: "s-order-edit-product-card-image" })) : (h("div", { class: "s-order-edit-product-card-placeholder" }, h("i", { class: "sicon-shopping-bag" })))), h("div", { key: 'ac51822bbcf1f2213b11204fa968a40e7de164a3', class: "s-order-edit-product-card-content" }, h("h3", { key: 'e817582bf88db2ed6ac47a37a5d2b4e4ac953770', class: "s-order-edit-product-card-title" }, productName), price != null && (h("p", { key: 'efbf1b16d7c6d73de76bab1e8715a474f812fde4', class: "s-order-edit-product-card-price", innerHTML: salla.money(price) }))))));
    }
    static get style() { return sallaOrderEditProductCardCss; }
}, [0, "salla-order-edit-product-card", {
        "product": [1]
    }]);
function defineCustomElement$1() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["salla-order-edit-product-card"];
    components.forEach(tagName => { switch (tagName) {
        case "salla-order-edit-product-card":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, SallaOrderEditProductCard$1);
            }
            break;
    } });
}
defineCustomElement$1();

const SallaOrderEditProductCard = SallaOrderEditProductCard$1;
const defineCustomElement = defineCustomElement$1;

export { SallaOrderEditProductCard, defineCustomElement };
