import React from 'react';
import { DatePicker } from 'antd';

const { RangePicker } = DatePicker;

function DDDateRangeField(props) {
  const { format, disabled, onChange } = props;

  const handleChange = date => {
    let value = [date[0].format('YYYY-MM-DD'), date[1].format('YYYY-MM-DD')];
    onChange?.(JSON.stringify(value));
  };
  return (
    <RangePicker
      disabled={disabled}
      format={format.replace('yyyy', 'YYYY').replace('dd', 'DD')}
      onChange={handleChange}
    />
  );
}

export default DDDateRangeField;
