"use strict";

exports.__esModule = true;
exports.useProfileState = useProfileState;
exports.useProfileDispatch = useProfileDispatch;

var _router = require("next/router");

var _lib = require("@sentecacommerce-theme/lib");

function useProfileState() {
  var _router$query$tab, _router$query$tab2;

  var router = (0, _router.useRouter)();

  var _useWindowDimensions = (0, _lib.useWindowDimensions)(),
      width = _useWindowDimensions.width;

  if (((_router$query$tab = router.query.tab) == null ? void 0 : _router$query$tab[0]) === undefined && width > 768) {
    return {
      profileTab: 'personal-info'
    };
  }

  return {
    profileTab: ((_router$query$tab2 = router.query.tab) == null ? void 0 : _router$query$tab2[0]) || ''
  };
}

function useProfileDispatch() {
  var router = (0, _router.useRouter)();
  var actions = {
    change: function change(payload) {
      if (payload === 'favorites') router.push('/favorites');
      router.push("/profile/" + payload, undefined, {
        shallow: true
      });
    },
    reset: function reset() {
      router.push("/profile");
    }
  };
  return function (_ref) {
    var type = _ref.type,
        payload = _ref.payload;

    if (!actions[type]) {
      throw new Error('useProfileDispatch action type not found');
    }

    actions[type](payload);
  };
}
//# sourceMappingURL=profile.context.js.map