import React from 'react';

export interface TransformTimeProps {
  onChange?: (val: any) => void;
  value?: any;
}

const TransformTime: React.FC<TransformTimeProps> = (props) => {
  const { children, onChange, value } = props;

  let newValue = value ? Number(value) / 60 : 0;

  const handleChange = (e: any) => {
    const val = e.target.value;
    const newVal = val ? Number(val) * 60 : 0;
    onChange && onChange(newVal);
  };

  return (
    <>
      {React.Children.map(children, (child: any) =>
        React.cloneElement(child, {
          onChange: handleChange,
          value: newValue
        })
      )}
    </>
  );
};

export default TransformTime;
