"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var React = _interopRequireWildcard(require("react"));

var _pickerView = _interopRequireDefault(require("../picker-view"));

var _Container = _interopRequireDefault(require("./Container"));

var Picker = function Picker(props) {
  var className = props.className,
      style = props.style,
      title = props.title,
      confirmText = props.confirmText,
      cancelText = props.cancelText,
      value = props.value,
      defaultValue = props.defaultValue,
      wheelDefaultValue = props.wheelDefaultValue,
      dataSource = props.dataSource,
      fieldNames = props.fieldNames,
      itemRender = props.itemRender,
      cols = props.cols,
      maskClosable = props.maskClosable,
      mountContainer = props.mountContainer,
      forceRender = props.forceRender,
      destroy = props.destroy,
      safeArea = props.safeArea,
      onChange = props.onChange,
      onConfirm = props.onConfirm,
      onCancel = props.onCancel,
      visible = props.visible;
  var pickerViewRef = React.useRef(null);

  var handleChange = function handleChange(changedValue, items, index) {
    visible && (onChange === null || onChange === void 0 ? void 0 : onChange(changedValue, items, index));
  };

  var handleConfirm = function handleConfirm() {
    var _pickerViewRef$curren, _pickerViewRef$curren2;

    onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm((_pickerViewRef$curren = pickerViewRef.current) === null || _pickerViewRef$curren === void 0 ? void 0 : _pickerViewRef$curren.value, (_pickerViewRef$curren2 = pickerViewRef.current) === null || _pickerViewRef$curren2 === void 0 ? void 0 : _pickerViewRef$curren2.items);
  };

  var handleCancel = function handleCancel() {
    var _pickerViewRef$curren3, _pickerViewRef$curren4;

    (_pickerViewRef$curren3 = pickerViewRef.current) === null || _pickerViewRef$curren3 === void 0 ? void 0 : (_pickerViewRef$curren4 = _pickerViewRef$curren3.reset) === null || _pickerViewRef$curren4 === void 0 ? void 0 : _pickerViewRef$curren4.call(_pickerViewRef$curren3);
    onCancel === null || onCancel === void 0 ? void 0 : onCancel();
  };

  return /*#__PURE__*/React.createElement(_Container.default, {
    title: title,
    className: className,
    style: style,
    confirmText: confirmText,
    cancelText: cancelText,
    visible: visible,
    maskClosable: maskClosable,
    forceRender: forceRender,
    destroy: destroy,
    safeArea: safeArea,
    mountContainer: mountContainer,
    onConfirm: handleConfirm,
    onCancel: handleCancel,
    onClose: handleCancel
  }, /*#__PURE__*/React.createElement(_pickerView.default, {
    ref: pickerViewRef,
    value: value,
    defaultValue: defaultValue,
    wheelDefaultValue: wheelDefaultValue,
    dataSource: dataSource,
    cols: cols,
    fieldNames: fieldNames,
    itemRender: itemRender,
    onChange: handleChange
  }));
};

Picker.defaultProps = {
  dataSource: [],
  cols: Infinity,
  maskClosable: true,
  destroy: false
};
var _default = Picker;
exports.default = _default;