const compactComposerQuery = "(max-width: 640px)";

export function usesCompactComposerKeyboard(target = globalThis) {
  return Boolean(target.matchMedia?.(compactComposerQuery).matches);
}

export function shouldSubmitComposerKey(event, { compact = usesCompactComposerKeyboard() } = {}) {
  const isComposing = event.isComposing
    || event.nativeEvent?.isComposing
    || event.keyCode === 229
    || event.nativeEvent?.keyCode === 229;
  if (event.key !== "Enter" || isComposing || event.shiftKey) return false;
  return Boolean(event.ctrlKey || event.metaKey) || !compact;
}
