import { Button, DatePicker, Form } from "antd";
import React from "react";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { queryReportingData } from "../../../redux/reporting/reporting.actions";
import moment from "moment";
const mapStateToProps = createStructuredSelector({
  //currentUser: selectCurrentUser
});
const mapDispatchToProps = (dispatch) => ({
  queryReportingData: (dates) => dispatch(queryReportingData(dates)),
});
export default connect(
  mapStateToProps,
  mapDispatchToProps
)(ReportingDatesMolecule);

export function ReportingDatesMolecule({ queryReportingData }) {
  const [form] = Form.useForm();

  const handleFinish = (values) => {
    queryReportingData({
      startDate: values.dateRange[0],
      endDate: values.dateRange[1],
    });
  };

  return (
    <Form form={form} onFinish={handleFinish}>
      <div style={{ display: "flex" }}>
        <Form.Item
          label="Ready for Payment Date Between"
          name="dateRange"
          rules={[{ type: "array", required: true }]}
        >
          <DatePicker.RangePicker
            format="MM/DD/YYYY"
            ranges={{
              Today: [moment(), moment()],
              "Last 14 days": [moment().subtract(14, "days"), moment()],
              "Last 7 days": [moment().subtract(7, "days"), moment()],
              "Next 7 days": [moment(), moment().add(7, "days")],
              "Next 14 days": [moment(), moment().add(14, "days")],
              "Last Month": [
                moment().startOf("month").subtract(1, "month"),
                moment().startOf("month").subtract(1, "month").endOf("month"),
              ],

              "This Month": [
                moment().startOf("month"),
                moment().endOf("month"),
              ],
              "Next Month": [
                moment().startOf("month").add(1, "month"),
                moment().startOf("month").add(1, "month").endOf("month"),
              ],
              "Last Quarter": [
                moment().startOf("quarter").subtract(1, "quarters"),
                moment().startOf("quarter").subtract(1, "day"),
              ],
              "This Quarter": [
                moment().startOf("quarter"),
                moment()
                  .startOf("quarter")
                  .add(1, "quarter")
                  .subtract(1, "day"),
              ],
              "Last 3 Months": [
                moment().startOf("month").subtract(3, "month"),
                moment().startOf("month").subtract(1, "month").endOf("month"),
              ],
            }}
          />
        </Form.Item>
        <Button type="primary" htmlType="submit">
          Run Search
        </Button>
      </div>
    </Form>
  );
}
