'use strict';
import { Controller } from '@hotwired/stimulus';
/**
 * Offer card controller. Owns the heart button on each card and delegates
 * to the `ferienpass--cms-wishlists` controller on the filter panel.
 *
 * Why this controller exists at all (instead of putting the action directly
 * on the card markup): the wishlists controller needs to know which card
 * triggered the menu, so it can anchor the popover to that card's heart.
 */
export default class default_1 extends Controller {
    openWishlistMenu(event) {
        event.preventDefault();
        event.stopPropagation();
        const wishlists = this.findWishlistsController();
        if (!wishlists)
            return;
        // Anchor the popover at the button that was clicked — a card may carry
        // several hearts (e.g. offer details sidebar + application form).
        const anchor = event.currentTarget instanceof HTMLElement ? event.currentTarget : undefined;
        wishlists.requestCardPopover(this.element, anchor);
    }
    findWishlistsController() {
        const el = document.querySelector('[data-controller~="ferienpass--cms-wishlists"]');
        if (!el)
            return null;
        const app = this.application;
        const ctrl = app.getControllerForElementAndIdentifier(el, 'ferienpass--cms-wishlists');
        return ctrl ? ctrl : null;
    }
}
default_1.values = { offerId: Number };
