/*
 * @Note:
 * @Author: 2058827620@qq.com
 * @Date: 2022-04-03 17:02:15
 */
import { useEffect, useRef, useState } from 'react';

import { ProForm, ModalForm, ProFormSelect, ProFormText, ProFormRadio } from '@ant-design/pro-components';

import services from '@/services/admin';

const { userLevelItems } = services.UserLevelController;
const { bonusGroupItems } = services.BonusGroupController;
const { deviceItems } = services.DeviceController;


export default ({ values, modalOpenState, onModalOpenState, onSubmit }) => {
  const restFormRef = useRef();

  useEffect(() => {
    restFormRef.current?.setFieldsValue(values);
  }, [values]);

  return (
    <>
      <ModalForm
        title="用户-分红设置"

        formRef={restFormRef}
        submitter={{
          searchConfig: {
            resetText: '重置',
          },
          resetButtonProps: {
            onClick: () => {
              restFormRef.current?.resetFields();
            },
          },
        }}
        initialValues={values}
        onFinish={onSubmit}
        open={modalOpenState}
        onOpenChange={onModalOpenState}
      >
        <ProFormText hidden={true} width="md" name="id" />
        <ProFormSelect
          rules={[{ required: true, message: '请选择' }]}
          name="level_id"
          label="分红等级"
          request={async () => {
            const { data } = await userLevelItems();
            let temp = [];
            data?.map((item) => {
              temp.push({
                label: `${item.name} - ${item.note}`,
                value: item.id
              });
            });
            return temp;
          }}
          placeholder="请选择"
        />

        <ProFormSelect
          rules={[{ required: true, message: '请选择' }]}
          name="group_id"
          label="选择分组"
          request={async () => {
            const { data } = await bonusGroupItems();
            let temp = [];
            data?.map((item) => {
              temp.push({
                label: `${item.num}组；人数上限：${item.user_num_use}/${item.user_num}；桩上限：${item.device_num_use}/${item.device_num}；桩上限（赠送）：${item.device_num_give_use}/${item.device_num_give}；`,
                value: item.id
              });
            });
            return temp;
          }}
          placeholder="请选择"
        />

      </ModalForm>
    </>
  );
};

