/*!
 * Crafted with ❤ by Salla
 */
import { r as registerInstance, h, H as Host } from './index-Cb4NFvMH.js';

var copyIcon = `<!-- Generated by IcoMoon.io -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
<title>swap-fill</title>
<path d="M28 10.667h-2.667c-0.736 0-1.333 0.596-1.333 1.333s0.597 1.333 1.333 1.333h2.667c0.735 0 1.333 0.597 1.333 1.333v13.333c0 0.736-0.599 1.333-1.333 1.333h-13.333c-0.735 0-1.333-0.597-1.333-1.333v-2.667c0-0.737-0.597-1.333-1.333-1.333s-1.333 0.596-1.333 1.333v2.667c0 2.205 1.795 4 4 4h13.333c2.205 0 4-1.795 4-4v-13.333c0-2.205-1.795-4-4-4zM21.333 17.333v-13.333c0-2.205-1.795-4-4-4h-13.333c-2.205 0-4 1.795-4 4v13.333c0 2.205 1.795 4 4 4h13.333c2.205 0 4-1.795 4-4zM2.667 17.333v-13.333c0-0.736 0.599-1.333 1.333-1.333h13.333c0.735 0 1.333 0.597 1.333 1.333v13.333c0 0.736-0.599 1.333-1.333 1.333h-13.333c-0.735 0-1.333-0.597-1.333-1.333z"></path>
</svg>
`;

const sallaOrderDetailsOptionsCss = "";

const SallaOrderDetailsOptions = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        /** Whether to show the options in a bordered container */
        this.bordered = true;
        /** Placeholder image URL when option image is not available */
        this.placeholderImage = 'images/placeholder.png';
        /** Parsed options data */
        this.optionsData = [];
    }
    componentWillLoad() {
        this.parseOptionsData();
    }
    componentWillUpdate() {
        this.parseOptionsData();
    }
    parseOptionsData() {
        if (!this.options) {
            this.optionsData = [];
            return;
        }
        if (typeof this.options === 'string') {
            try {
                this.optionsData = JSON.parse(this.options);
            }
            catch (e) {
                // Invalid options JSON, fallback to empty array
                this.optionsData = [];
            }
        }
        else {
            this.optionsData = Array.isArray(this.options) ? this.options : [];
        }
    }
    renderOptionValue(option) {
        // Handle image options
        if (option.is_image) {
            return (h("div", { class: "s-order-details-option-image-container" }, h("a", { href: option.value, target: "_blank" }, h("img", { class: "s-order-details-option-image", src: option.value || this.placeholderImage, alt: option.name }))));
        }
        // Handle color options
        if (option.color) {
            return (h("span", { title: option.value, class: "s-order-details-option-color-swatch", style: { backgroundColor: option.color } }));
        }
        // Handle file options
        if (option.is_file) {
            return (h("a", { href: option.value, target: "_blank", class: "s-order-details-option-file-link" }, salla.lang.get('common.elements.attachments')));
        }
        // Handle color picker options
        if (option.is_color_picker) {
            return (h("div", { class: "s-order-details-option-color-picker" }, h("div", { class: "s-order-details-option-color-picker-content" }, h("span", { class: "s-order-details-option-color-picker-text" }, option.value), h("span", { class: "s-order-details-option-color-picker-swatch", style: { backgroundColor: option.value, width: '1rem' } })), h("salla-button", { onClick: e => this.copyToClipboard(e, option.value), shape: "link", class: "s-order-details-option-color-picker-button" }, h("span", { class: "s-order-details-option-color-copy-icon", innerHTML: copyIcon }))));
        }
        // Handle map options
        if (option.is_map && option.latitude && option.longitude) {
            return (h("salla-map", { id: `location_map_${option.id}`, class: `map_${option.id}`, zoom: 15, readonly: true, lat: option.latitude, lng: option.longitude }, h("div", { slot: "button" }, h("button", { type: "button", class: "s-order-details-option-map-button", onClick: () => this.openMap(option.id) }, salla.lang.get('common.elements.show_location')))));
        }
        // Default text value
        return (h("span", { class: "s-order-details-option-default-text" }, option.display_value || option.value));
    }
    copyToClipboard(event, content) {
        event.preventDefault();
        if (navigator.clipboard) {
            navigator.clipboard.writeText(content);
        }
    }
    openMap(optionId) {
        const mapElement = document.querySelector(`salla-map.map_${optionId}`);
        if (mapElement && mapElement.open) {
            mapElement.open();
        }
    }
    render() {
        if (!this.optionsData.length) {
            return null;
        }
        const containerClasses = this.bordered
            ? 's-order-details-options-container'
            : 's-order-details-options-container-borderless';
        return (h(Host, { class: "s-order-details-options-wrapper" }, h("h2", { class: "s-order-details-options-title" }, salla.lang.get('pages.cart.item_options')), h("div", { class: containerClasses }, h("dl", { class: "s-order-details-options-list" }, this.optionsData.map(option => (h("div", { key: option.id, class: "s-order-details-options-item" }, h("dt", { class: "s-order-details-options-item-name" }, option.name, ":"), h("dd", { class: option.is_image
                ? 's-order-details-options-item-value-image'
                : 's-order-details-options-item-value-text' }, this.renderOptionValue(option)))))))));
    }
};
SallaOrderDetailsOptions.style = sallaOrderDetailsOptionsCss;

export { SallaOrderDetailsOptions as salla_order_details_options };
