import{defineProperty as e,toConsumableArray as t}from"../../_virtual/_rollupPluginBabelHelpers.js";import{NavDirections as r}from"../../hooks/useFullKeyboardListeners.js";var n=function(t){var n,o=(e(n={},r.RIGHT,new Map),e(n,r.LEFT,new Map),e(n,r.UP,new Map),e(n,r.DOWN,new Map),n);return t.forEach((function(e){!function(e,t){var n=t.topElement,o=t.bottomElement,a=t.leftElement,l=t.rightElement;function i(e,t){throw Error("Circular positioning detected: the ".concat(e," element is already positioned to the ").concat(t," of the ").concat(t," element. This probably means the layout isn't ordered correctly."))}n&&o&&(e[r.UP].get(n)===o&&i("BOTTOM","TOP"),e[r.DOWN].get(o)===n&&i("TOP","BOTTOM")),a&&l&&(e[r.LEFT].get(a)===l&&i("RIGHT","LEFT"),e[r.RIGHT].get(l)===a&&i("LEFT","RIGHT"))}(o,e);var t=e.topElement,n=e.bottomElement,a=e.leftElement,l=e.rightElement;t&&n&&(o[r.UP].set(n,t),o[r.DOWN].set(t,n)),a&&l&&(o[r.LEFT].set(l,a),o[r.RIGHT].set(a,l))})),o},o=function(e){switch(e){case r.LEFT:return r.RIGHT;case r.RIGHT:return r.LEFT;case r.UP:return r.DOWN;case r.DOWN:return r.UP;default:throw Error("Unexpected direction: ".concat(e))}},a=function e(n,o){var a=n[o],i=t(a)[0];return i?function(e,t){var r=!1,n=t;for(;!r;){var o=l(e,n);o?n=o:r=!0}return n}(a,i[0]):[r.LEFT,r.RIGHT].includes(o)?e(n,r.UP):e(n,r.LEFT)},l=function e(t,r){var n,o=t.get(r);return o?!o.current||o.current.disabled||"true"===(null===(n=o.current.dataset)||void 0===n?void 0:n.disabled)?e(t,o):o:null};export{n as getDirectionMaps,l as getNextElementToFocusInDirection,o as getOppositeDirection,a as getOutmostElementInDirection};
