import { createComponent, emptyRenderFn, computed, h, hSlot, inject, layoutKey, pageContainerKey, getCurrentInstance, openBlock, createBlock, withCtx, createVNode, renderSlot, normalizeClass, createElementBlock, createBaseVNode, toDisplayString, ref, onDeactivated, onActivated, onMounted, vmIsDestroyed, stopAndPrevent, nextTick, provide, formKey } from './__federation_expose_Modules-a9c6a6fc.js';
import { QPageContainer, QLayout, vitePluginRequire_1688446744735_46067947 } from './Logo_D2-67d1a1d2.js';
import { _export_sfc } from './_plugin-vue_export-helper-e9a2c33e.js';
import { addFocusFn } from './focus-manager-3034a851.js';

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

  props: {
    padding: Boolean,
    styleFn: Function
  },

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

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

    const $pageContainer = inject(pageContainerKey, emptyRenderFn);
    if ($pageContainer === emptyRenderFn) {
      console.error('QPage needs to be child of QPageContainer');
      return emptyRenderFn
    }

    const style = computed(() => {
      const offset
        = ($layout.header.space === true ? $layout.header.size : 0)
        + ($layout.footer.space === true ? $layout.footer.size : 0);

      if (typeof props.styleFn === 'function') {
        const height = $layout.isContainer.value === true
          ? $layout.containerHeight.value
          : $q.screen.height;

        return props.styleFn(offset, height)
      }

      return {
        minHeight: $layout.isContainer.value === true
          ? ($layout.containerHeight.value - offset) + 'px'
          : (
              $q.screen.height === 0
                ? (offset !== 0 ? `calc(100vh - ${ offset }px)` : '100vh')
                : ($q.screen.height - offset) + 'px'
            )
      }
    });

    const classes = computed(() =>
      `q-page${ props.padding === true ? ' q-layout-padding' : '' }`
    );

    return () => h('main', {
      class: classes.value,
      style: style.value
    }, hSlot(slots.default))
  }
});

const _sfc_main$3 = {};
function _sfc_render$1(_ctx, _cache) {
  return openBlock(), createBlock(QLayout, {
    view: "hHh LpR fFf"
  }, {
    default: withCtx(() => [createVNode(QPageContainer, {
      class: normalizeClass(`d1__authWrap`)
    }, {
      default: withCtx(() => [renderSlot(_ctx.$slots, "default")]),
      _: 3
    })]),
    _: 3
  });
}
const DefaultAuthLayout = /*#__PURE__*/_export_sfc(_sfc_main$3, [['render', _sfc_render$1]]);

const AlignCenterMiddleWrap_vue_vue_type_style_index_0_scoped_eebf02d6_lang = '';

const _sfc_main$2 = {};
const _hoisted_1$2 = {
  class: "align-center-middle-wrap"
};
function _sfc_render(_ctx, _cache) {
  return openBlock(), createElementBlock("div", _hoisted_1$2, [renderSlot(_ctx.$slots, "default", {}, undefined, true)]);
}
const AlignCenterMiddleWrap = /*#__PURE__*/_export_sfc(_sfc_main$2, [['render', _sfc_render], ['__scopeId', "data-v-eebf02d6"]]);

const LogoNameBox_vue_vue_type_style_index_0_scoped_be61ce64_lang = '';

const _hoisted_1$1 = {
  class: "row justify-center mobile__logo"
};
const _hoisted_2 = ["src"];
const _sfc_main$1 = {
  __name: 'LogoNameBox',
  setup(__props) {
    const logoName = 'D2';
    const logoSubName = 'Decision Dynamics';
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", _hoisted_1$1, [createBaseVNode("img", {
        class: "col-auto logo-img",
        src: (vitePluginRequire_1688446744735_46067947)
      }, null, 8, _hoisted_2), createBaseVNode("div", {
        class: "col-auto relative-position"
      }, [createBaseVNode("div", {
        class: "logo-position"
      }, toDisplayString(logoName)), createBaseVNode("div", {
        class: "logo-sub-position"
      }, toDisplayString(logoSubName)), createBaseVNode("div", {
        class: "logo-sub-position-width"
      }, toDisplayString(logoSubName))])]);
    };
  }
};
const LogoNameBox = /*#__PURE__*/_export_sfc(_sfc_main$1, [['__scopeId', "data-v-be61ce64"]]);

const _hoisted_1 = {
  class: "auth-title"
};
const _sfc_main = {
  __name: 'AuthTitle',
  props: {
    title: {
      type: String,
      default: "Log in to your account"
    }
  },
  setup(__props) {
    const props = __props;
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", _hoisted_1, toDisplayString(props.title), 1);
    };
  }
};

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

  props: {
    autofocus: Boolean,
    noErrorFocus: Boolean,
    noResetFocus: Boolean,
    greedy: Boolean,

    onSubmit: Function
  },

  emits: [ 'reset', 'validationSuccess', 'validationError' ],

  setup (props, { slots, emit }) {
    const vm = getCurrentInstance();
    const rootRef = ref(null);

    let validateIndex = 0;
    const registeredComponents = [];

    function validate (shouldFocus) {
      const focus = typeof shouldFocus === 'boolean'
        ? shouldFocus
        : props.noErrorFocus !== true;

      const index = ++validateIndex;

      const emitEvent = (res, ref) => {
        emit('validation' + (res === true ? 'Success' : 'Error'), ref);
      };

      const validateComponent = comp => {
        const valid = comp.validate();

        return typeof valid.then === 'function'
          ? valid.then(
            valid => ({ valid, comp }),
            err => ({ valid: false, comp, err })
          )
          : Promise.resolve({ valid, comp })
      };

      const errorsPromise = props.greedy === true
        ? Promise
          .all(registeredComponents.map(validateComponent))
          .then(res => res.filter(r => r.valid !== true))
        : registeredComponents
          .reduce(
            (acc, comp) => acc.then(() => {
              return validateComponent(comp).then(r => {
                if (r.valid === false) { return Promise.reject(r) }
              })
            }),
            Promise.resolve()
          )
          .catch(error => [ error ]);

      return errorsPromise.then(errors => {
        if (errors === void 0 || errors.length === 0) {
          index === validateIndex && emitEvent(true);
          return true
        }

        // if not outdated already
        if (index === validateIndex) {
          const { comp, err } = errors[ 0 ];

          err !== void 0 && console.error(err);
          emitEvent(false, comp);

          if (focus === true) {
            // Try to focus first mounted and active component
            const activeError = errors.find(({ comp }) => (
              typeof comp.focus === 'function'
              && vmIsDestroyed(comp.$) === false
            ));

            if (activeError !== void 0) {
              activeError.comp.focus();
            }
          }
        }

        return false
      })
    }

    function resetValidation () {
      validateIndex++;

      registeredComponents.forEach(comp => {
        typeof comp.resetValidation === 'function' && comp.resetValidation();
      });
    }

    function submit (evt) {
      evt !== void 0 && stopAndPrevent(evt);

      const index = validateIndex + 1;

      validate().then(val => {
        // if not outdated && validation succeeded
        if (index === validateIndex && val === true) {
          if (props.onSubmit !== void 0) {
            emit('submit', evt);
          }
          else if (evt !== void 0 && evt.target !== void 0 && typeof evt.target.submit === 'function') {
            evt.target.submit();
          }
        }
      });
    }

    function reset (evt) {
      evt !== void 0 && stopAndPrevent(evt);

      emit('reset');

      nextTick(() => { // allow userland to reset values before
        resetValidation();
        if (props.autofocus === true && props.noResetFocus !== true) {
          focus();
        }
      });
    }

    function focus () {
      addFocusFn(() => {
        if (rootRef.value === null) { return }

        const target = rootRef.value.querySelector('[autofocus][tabindex], [data-autofocus][tabindex]')
          || rootRef.value.querySelector('[autofocus] [tabindex], [data-autofocus] [tabindex]')
          || rootRef.value.querySelector('[autofocus], [data-autofocus]')
          || Array.prototype.find.call(rootRef.value.querySelectorAll('[tabindex]'), el => el.tabIndex > -1);

        target !== null && target !== void 0 && target.focus({ preventScroll: true });
      });
    }

    provide(formKey, {
      bindComponent (vmProxy) {
        registeredComponents.push(vmProxy);
      },

      unbindComponent (vmProxy) {
        const index = registeredComponents.indexOf(vmProxy);
        if (index > -1) {
          registeredComponents.splice(index, 1);
        }
      }
    });

    let shouldActivate = false;

    onDeactivated(() => {
      shouldActivate = true;
    });

    onActivated(() => {
      shouldActivate === true && props.autofocus === true && focus();
    });

    onMounted(() => {
      props.autofocus === true && focus();
    });

    // expose public methods
    Object.assign(vm.proxy, {
      validate,
      resetValidation,
      submit,
      reset,
      focus,
      getValidationComponents: () => registeredComponents
    });

    return () => h('form', {
      class: 'q-form',
      ref: rootRef,
      onSubmit: submit,
      onReset: reset
    }, hSlot(slots.default))
  }
});

export { AlignCenterMiddleWrap, DefaultAuthLayout, LogoNameBox, QForm, QPage, _sfc_main };
