import React, { useState, useEffect, forwardRef, useImperativeHandle } from 'react';
import { Form, Input, Select, Divider, TreeSelect, Empty, Switch, Button, message } from 'antd';

const ShortMessageTest = (props, ref) => {
  const { formValue } = props;
  const [form] = Form.useForm();
  const [parmarForm] = Form.useForm();
  useEffect(() => {
    if (!formValue) {
      return;
    }
  }, [formValue]);
  useImperativeHandle(ref, () => ({
    getParmar,
  }));
  const getParmar = () => {
    // let obj = form.getFieldsValue(true);
    let obj = {};
    let sms = {};
    let allFields = parmarForm.getFieldsValue(true);
    Object.keys(allFields).map(item => {
      sms[formValue.lines.find(ele => ele.Description == item).Name] = allFields[item];
    });
    obj = { ...obj, sms };
    return obj;
  };

  return (
    <div>
      {/* <Form form={form} labelCol={{ span: 3 }} wrapperCol={{ span: 21 }} labelAlign="left">
        <Form.Item label="网页跳转路径" name="PlatformWebUrl">
          <Input placeholder="请填写网页跳转路径" />
        </Form.Item>
        <Form.Item label="APP跳转路径" name="PlatformAppUrl">
          <Input placeholder="请填写APP跳转路径" />
        </Form.Item>
        <Form.Item label="视频地址" name="  ">
          <Input placeholder="请填写视频地址" />
        </Form.Item>
      </Form> */}
      <Divider
        orientation="left"
        style={{
          borderTopColor: '#99bbe8',
          color: '#15428b',
          fontWeight: 700,
          marginTop: '0px',
        }}
      >
        参数配置
      </Divider>
      <Form form={parmarForm} labelCol={{ span: 3 }} wrapperCol={{ span: 21 }} labelAlign="left">
        {formValue.lines?.map(item => (
          <Form.Item
            label={item.Description}
            name={item.Description}
            key={item.Name}
            initialValue={item.DefaultValue}
          >
            <Input placeholder={`请填写${item.Description}`} />
          </Form.Item>
        ))}
      </Form>
    </div>
  );
};

export default forwardRef(ShortMessageTest);
