// @flow
import React, { type Element } from 'react';
import PropTypes from 'prop-types';

export type SegmentedControlProps = {
  value: string | number,
  onChange: (string | number) => void,
  children: Array<Element<*>>,
};

export const segmentedControlPropTypes = {
  value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
  onChange: PropTypes.func.isRequired,
  children: PropTypes.arrayOf(PropTypes.node).isRequired,
};

export type SegmentedControlContextValue = {
  selectedValue: string | number,
  onItemClick: (string | number) => void,
};

export const SegmentedControlContext = React.createContext<SegmentedControlContextValue>(
  {
    selectedValue: 0,
    onItemClick: () => {},
  },
);
