"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useSelectWithArrowKeys = void 0;
var dom_1 = require("../../utils/dom");
var tiles_1 = require("../../utils/tiles");
exports.useSelectWithArrowKeys = function (containerRef, _a) {
    var selected = _a.selected, onSelect = _a.onSelect, numTiles = _a.numTiles;
    var onKeyDown = function (e) {
        var _a, _b;
        var container = containerRef.current;
        if (e.key === 'ArrowLeft') {
            e.preventDefault();
            var prev = Math.max(selected - 1, 0);
            onSelect(prev);
            (_a = dom_1.getFirstFocusableElement(tiles_1.getTile(container, prev))) === null || _a === void 0 ? void 0 : _a.focus();
        }
        else if (e.key === 'ArrowRight') {
            e.preventDefault();
            var next = Math.min(selected + 1, numTiles - 1);
            onSelect(next);
            (_b = dom_1.getFirstFocusableElement(tiles_1.getTile(container, next))) === null || _b === void 0 ? void 0 : _b.focus();
        }
    };
    return { onKeyDown: onKeyDown };
};
