import { QResizeObserver } from './QResizeObserver-41bc340b.js';
import { createComponent, emptyRenderFn, ref, computed, watch, onBeforeUnmount, hUniqueSlot, h, inject, layoutKey, getCurrentInstance, hSlot, resolveComponent, openBlock, createBlock, withCtx, createVNode, QAvatar, createTextVNode, createElementBlock, renderList, Fragment, QBtn, withDirectives, QIcon, toDisplayString, pushScopeId, popScopeId, createBaseVNode } from './__federation_expose_Modules-a9c6a6fc.js';
import { QSpace } from './QSpace-afce9c3e.js';
import { QItem, QItemSection } from './QItem-1f9e6dcc.js';
import { QList } from './QList-5be5d7fb.js';
import { QBtnDropdown } from './QBtnDropdown-795fbd07.js';
import { ClosePopup } from './ClosePopup-7098b59f.js';
import { vitePluginRequire_1688446744735_46067947 } from './Logo_D2-67d1a1d2.js';
import { _export_sfc } from './_plugin-vue_export-helper-e9a2c33e.js';

const QHeader = createComponent({
  name: 'QHeader',

  props: {
    modelValue: {
      type: Boolean,
      default: true
    },
    reveal: Boolean,
    revealOffset: {
      type: Number,
      default: 250
    },
    bordered: Boolean,
    elevated: Boolean,

    heightHint: {
      type: [ String, Number ],
      default: 50
    }
  },

  emits: [ 'reveal', 'focusin' ],

  setup (props, { slots, emit }) {
    const { proxy: { $q } } = getCurrentInstance();

    const $layout = inject(layoutKey, emptyRenderFn);
    if ($layout === emptyRenderFn) {
      console.error('QHeader needs to be child of QLayout');
      return emptyRenderFn
    }

    const size = ref(parseInt(props.heightHint, 10));
    const revealed = ref(true);

    const fixed = computed(() =>
      props.reveal === true
      || $layout.view.value.indexOf('H') > -1
      || ($q.platform.is.ios && $layout.isContainer.value === true)
    );

    const offset = computed(() => {
      if (props.modelValue !== true) {
        return 0
      }
      if (fixed.value === true) {
        return revealed.value === true ? size.value : 0
      }
      const offset = size.value - $layout.scroll.value.position;
      return offset > 0 ? offset : 0
    });

    const hidden = computed(() => props.modelValue !== true
      || (fixed.value === true && revealed.value !== true)
    );

    const revealOnFocus = computed(() =>
      props.modelValue === true && hidden.value === true && props.reveal === true
    );

    const classes = computed(() =>
      'q-header q-layout__section--marginal '
      + (fixed.value === true ? 'fixed' : 'absolute') + '-top'
      + (props.bordered === true ? ' q-header--bordered' : '')
      + (hidden.value === true ? ' q-header--hidden' : '')
      + (props.modelValue !== true ? ' q-layout--prevent-focus' : '')
    );

    const style = computed(() => {
      const
        view = $layout.rows.value.top,
        css = {};

      if (view[ 0 ] === 'l' && $layout.left.space === true) {
        css[ $q.lang.rtl === true ? 'right' : 'left' ] = `${ $layout.left.size }px`;
      }
      if (view[ 2 ] === 'r' && $layout.right.space === true) {
        css[ $q.lang.rtl === true ? 'left' : 'right' ] = `${ $layout.right.size }px`;
      }

      return css
    });

    function updateLayout (prop, val) {
      $layout.update('header', prop, val);
    }

    function updateLocal (prop, val) {
      if (prop.value !== val) {
        prop.value = val;
      }
    }

    function onResize ({ height }) {
      updateLocal(size, height);
      updateLayout('size', height);
    }

    function onFocusin (evt) {
      if (revealOnFocus.value === true) {
        updateLocal(revealed, true);
      }

      emit('focusin', evt);
    }

    watch(() => props.modelValue, val => {
      updateLayout('space', val);
      updateLocal(revealed, true);
      $layout.animate();
    });

    watch(offset, val => {
      updateLayout('offset', val);
    });

    watch(() => props.reveal, val => {
      val === false && updateLocal(revealed, props.modelValue);
    });

    watch(revealed, val => {
      $layout.animate();
      emit('reveal', val);
    });

    watch($layout.scroll, scroll => {
      props.reveal === true && updateLocal(revealed,
        scroll.direction === 'up'
        || scroll.position <= props.revealOffset
        || scroll.position - scroll.inflectionPoint < 100
      );
    });

    const instance = {};

    $layout.instances.header = instance;
    props.modelValue === true && updateLayout('size', size.value);
    updateLayout('space', props.modelValue);
    updateLayout('offset', offset.value);

    onBeforeUnmount(() => {
      if ($layout.instances.header === instance) {
        $layout.instances.header = void 0;
        updateLayout('size', 0);
        updateLayout('offset', 0);
        updateLayout('space', false);
      }
    });

    return () => {
      const child = hUniqueSlot(slots.default, []);

      props.elevated === true && child.push(
        h('div', {
          class: 'q-layout__shadow absolute-full overflow-hidden no-pointer-events'
        })
      );

      child.push(
        h(QResizeObserver, {
          debounce: 0,
          onResize
        })
      );

      return h('header', {
        class: classes.value,
        style: style.value,
        onFocusin
      }, child)
    }
  }
});

const QToolbar = createComponent({
  name: 'QToolbar',

  props: {
    inset: Boolean
  },

  setup (props, { slots }) {
    const classes = computed(() =>
      'q-toolbar row no-wrap items-center'
      + (props.inset === true ? ' q-toolbar--inset' : '')
    );

    return () => h('div', { class: classes.value, role: 'toolbar' }, hSlot(slots.default))
  }
});

const Header_vue_vue_type_style_index_0_scoped_36dfc6f7_lang = '';

const _sfc_main = {
  name: 'Header',
  data() {
    return {
      flag: false,
      username: null,
      items: [{
        icon: 'fas fa-gear',
        label: 'Settings',
        routerLink: '/user-settings/information'
      },
      // {
      //     icon: 'fas fa-bell',
      //     label: 'Alarms',
      //     routerLink: '/user/alarms'
      // },
      {
        icon: 'fas fa-right-from-bracket',
        label: 'Log out',
        routerLink: '/logout'
      }]
    };
  },
  methods: {
    getUserInfo() {
      if (localStorage.getItem("auth")) {
        if (JSON.parse(localStorage.getItem("auth"))["accessToken"] != "") {
          this.flag = true;
          window.$http.get('/rest/v1/user').then(res => {
            this.username = res.data.details.username;
          }).catch(error => {
            console.log("get_user_info", error);
          });
        }
      } else {
        this.flag = false;
      }
    }
  },
  created() {
    this.getUserInfo();
  }
};
const _withScopeId = n => (pushScopeId("data-v-36dfc6f7"), n = n(), popScopeId(), n);
const _hoisted_1 = /*#__PURE__*/_withScopeId(() => /*#__PURE__*/createBaseVNode("img", {
  src: vitePluginRequire_1688446744735_46067947,
  alt: "logo"
}, null, -1));
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  const _component_router_link = resolveComponent("router-link");
  return openBlock(), createBlock(QToolbar, {
    class: "D2",
    style: {
      "padding-left": "20px"
    }
  }, {
    default: withCtx(() => [createVNode(_component_router_link, {
      to: "/home",
      style: {
        "align-content": "baseline",
        "text-decoration": "none",
        "color": "#0d0d0d"
      }
    }, {
      default: withCtx(() => [createVNode(QAvatar, null, {
        default: withCtx(() => [_hoisted_1]),
        _: 1
      }), createTextVNode(" D2 ")]),
      _: 1
    }), createVNode(QSpace), $data.flag ? (openBlock(), createBlock(QBtnDropdown, {
      key: 0,
      "no-caps": "",
      style: {
        "color": "#192e65"
      },
      flat: "",
      round: "",
      dense: "",
      icon: "fas fa-user",
      label: $data.username
    }, {
      default: withCtx(() => [createVNode(QList, {
        class: "menu-list"
      }, {
        default: withCtx(() => [(openBlock(true), createElementBlock(Fragment, null, renderList($data.items, item => {
          return withDirectives((openBlock(), createBlock(QItem, {
            to: item.routerLink,
            class: "menu-item",
            clickable: ""
          }, {
            default: withCtx(() => [createVNode(QItemSection, {
              avatar: ""
            }, {
              default: withCtx(() => [createVNode(QIcon, {
                size: "large",
                color: "primary",
                name: item.icon
              }, null, 8, ["name"])]),
              _: 2
            }, 1024), createVNode(QItemSection, {
              class: "q-item-text"
            }, {
              default: withCtx(() => [createTextVNode(toDisplayString(item.label), 1)]),
              _: 2
            }, 1024)]),
            _: 2
          }, 1032, ["to"])), [[ClosePopup]]);
        }), 256))]),
        _: 1
      })]),
      _: 1
    }, 8, ["label"])) : (openBlock(), createBlock(QBtn, {
      key: 1,
      style: {
        "margin-right": "10px"
      },
      "no-caps": "",
      outline: "",
      to: "/login"
    }, {
      default: withCtx(() => [createTextVNode("Log in")]),
      _: 1
    }))]),
    _: 1
  });
}
const Header = /*#__PURE__*/_export_sfc(_sfc_main, [['render', _sfc_render], ['__scopeId', "data-v-36dfc6f7"]]);

export { Header, QHeader };
