import React from 'react';
import { PisellDataSourceContainer } from '@pisell/materials';
import { Form, Button } from 'antd';
import dayjs from 'dayjs';
var useContainerContext = PisellDataSourceContainer.useContainerContext;
var FilterList = function FilterList(_ref) {
  var locales = _ref.locales,
    valueType = _ref.valueType,
    setValueType = _ref.setValueType;
  var form = Form.useFormInstance();
  var _useContainerContext = useContainerContext(),
    serverActions = _useContainerContext.serverActions;
  var list = serverActions.list;
  var handleTodayClick = function handleTodayClick() {
    var today = dayjs();
    var params = {
      orderDate: [today.startOf('day'), today.endOf('day')],
      payment_status: undefined
    };
    form.setFieldsValue(params);
    list.onSearch(params);
    setValueType(1);
  };
  var handleTodayToPayClick = function handleTodayToPayClick() {
    var today = dayjs();
    var params = {
      orderDate: [today.startOf('day'), today.endOf('day')],
      payment_status: ['payment_processing', 'unpaid'] // 默认需付款侧，也可改为其他待支付状态
    };
    form.setFieldsValue(params);
    list.onSearch(params);
    setValueType(2);
  };
  var handleTodayRefundsClick = function handleTodayRefundsClick() {
    var today = dayjs();
    var params = {
      orderDate: [today.startOf('day'), today.endOf('day')],
      payment_status: ["refunded", "partially_refunded"] // 默认设置为已退款
    };
    form.setFieldsValue(params);
    list.onSearch(params);
    setValueType(3);
  };
  var handleLast7DaysClick = function handleLast7DaysClick() {
    var today = dayjs();
    var sevenDaysAgo = today.subtract(6, 'day');
    var params = {
      orderDate: [sevenDaysAgo.startOf('day'), today.endOf('day')],
      payment_status: undefined
    };
    form.setFieldsValue(params);
    list.onSearch(params);
    setValueType(4);
  };
  return /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      gap: '8px'
    }
  }, /*#__PURE__*/React.createElement(Button, {
    type: "primary",
    ghost: valueType !== 1,
    onClick: handleTodayClick
  }, locales.getText('pisell2.orderList.filterButton.todayOrders')), /*#__PURE__*/React.createElement(Button, {
    type: "primary",
    ghost: valueType !== 2,
    onClick: handleTodayToPayClick
  }, locales.getText('pisell2.orderList.filterButton.todayPending')), /*#__PURE__*/React.createElement(Button, {
    type: "primary",
    ghost: valueType !== 3,
    onClick: handleTodayRefundsClick
  }, locales.getText('pisell2.orderList.filterButton.todayRefunds')), /*#__PURE__*/React.createElement(Button, {
    type: "primary",
    ghost: valueType !== 4,
    onClick: handleLast7DaysClick
  }, locales.getText('pisell2.orderList.filterButton.last7Days')));
};
export default FilterList;