"use strict";

/**
 * Servicenavigation toggle event dispatcher for z-index swapping
 */

;
(function ($, window, document, undefined) {
  'use strict';

  var $document = $(document);
  var init = function init() {
    $document.on('click', '.js-servicenavigation-trigger-open', function (e) {
      var dialogId = $(this).data('dialogId');
      var dialog = document.getElementById(dialogId);
      if (dialog === null) {
        return;
      }
      dialog.showModal();
    });
    $document.on('click', '.js-servicenavigation-trigger-close', function (e) {
      var dialogId = $(this).data('dialogId');
      var dialog = document.getElementById(dialogId);
      if (dialog === null) {
        return;
      }
      dialog.close();
    });
    $document.on('click', '.js-servicenavigation-dialog', function (e) {
      // jquery get clicked target
      var $target = $(e.target);
      console.log('clicked target', $target);
      if ($target.hasClass('js-servicenavigation-dialog')) {
        var dialogId = $target.attr('id');
        var dialog = document.getElementById(dialogId);
        if (dialog === null) {
          return;
        }
        dialog.close();
      }
    });
  };
  init();
})(jQuery, window, document);