import { j as l } from "../../../_virtual/jsx-runtime.js";
import { useRef as p, useEffect as o } from "react";
import { useHasFocus as b } from "../../../hooks/useHasFocus.js";
import { useKeyPress as x } from "../../../hooks/useKeyPress.js";
import { TabWrapper as j } from "../styles.js";
function h({
  tab: r,
  selected: e,
  narrow: u,
  expandClickFlag: t,
  setSelectedRef: m,
  onChange: i,
  testId: d,
  trackId: c
}) {
  const s = p(null), { hasFocus: f } = b(s), a = x("Enter", s);
  return o(() => {
    e && m(s);
  }, [e]), o(() => {
    a && f && !r.disabled && i(r);
  }, [a, f]), o(() => {
    var n;
    t && ((n = s.current) == null || n.scrollIntoView());
  }, [t]), /* @__PURE__ */ l.jsx(
    j,
    {
      ref: s,
      tabIndex: 0,
      role: "tab",
      "aria-selected": e ? "true" : "false",
      narrow: u,
      selected: e,
      disabled: r.disabled,
      onClick: () => i(r),
      "data-testid": d,
      "data-trackid": c,
      children: r.label
    }
  );
}
export {
  h as Tab
};
