import * as React from 'react';
import * as PropTypes from 'prop-types';
import weui from '../../utils/weui';

import classNames from '../../utils/classnames';

export default function TimePicker(props) {
  const { title, defaultValue, children, className } = props;

  const click = function () {
    const hour = [];
    const min = [];
    const sec = [];
    for (let i = 0; i < 60; i++) {
      if (i < 24) {
        hour.push({ label: i, value: i });
      }
      min.push({ label: i, value: i });
      sec.push({ label: i, value: i });
    }

    let fixedDefaultValue;
    if (defaultValue) {
      fixedDefaultValue = defaultValue.split(':');
    } else {
      const now = new Date();
      fixedDefaultValue = [now.getHours(), now.getMinutes(), now.getSeconds()];
    }

    weui.picker(hour, min, sec, {
      onChange() {
        // console.log(result);
      },
      onConfirm() {
        // console.log(result);
      },
      title,
      defaultValue: fixedDefaultValue,
    });
  };
  const cls = classNames({
    'weda-ui': true,
    'weda-time-picker': true,
    [className]: className,
  });

  return (
    <div className={cls} onClick={click}>
      {children}
    </div>
  );
}
