import ConditionalDisplay from '../classes/ConditionalDisplay.js';

jQuery(function ($) {

  const loadConditionalDisplay = (element) => {
    let field = $(element).data('conditional-field');
    let key = $(element).data('conditional-key');
    let condition = $(element).data('conditional-condition');
    new ConditionalDisplay(element, field, key, condition);
  }

  $('.o2-conditional-display').each(function () {
    loadConditionalDisplay(this);
  });

  $(document).on('RepeatAdd', ({ detail }) => {
    const el = detail.el;
    $('.o2-conditional-display', el).each(function () {
      loadConditionalDisplay(this);
    });
  });

});