$(document).ready(function () {
  // Wait for locales to load before setting up cart handlers
  // CartManager uses i18next for notifications
  window.CRM.onLocalesReady(function () {
    $('a[data-bs-toggle="tab"]').on("shown.bs.tab", function (e) {
      var target = $(e.target).attr("href"); // activated tab
      $(target + " .choiceSelectBox").each(function () {
        if (!this.tomselect) new TomSelect(this);
      });
    });

    $(".choiceSelectBox").each(function () {
      if (!this.tomselect) new TomSelect(this);
    });

    $("#AddAllToCart").click(function () {
      // Use CartManager with notifications
      window.CRM.cartManager.addPerson(listPeople, {
        showNotification: true,
      });
    });

    $("#RemoveAllFromCart").click(function () {
      // Use CartManager with confirmation and notifications
      window.CRM.cartManager.removePerson(listPeople, {
        confirm: true,
        showNotification: true,
      });
    });
  });
});
