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

const WeChatTest = (props, ref) => {
  const { menuWebList, menuMoblieList, 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 wechat = {};
    let allFields = parmarForm.getFieldsValue(true);
    Object.keys(allFields).map(item => {
      wechat[formValue.lines.find(ele => ele.Description == item).Name] = allFields[item];
    });
    obj = { ...obj, wechat };
    return obj;
  };

  return (
    <div>
      <Divider
        orientation="left"
        style={{
          borderTopColor: '#99bbe8',
          color: '#15428b',
          fontWeight: 700,
          marginTop: '0px',
        }}
      >
        基础配置
      </Divider>
      <Form form={form} labelCol={{ span: 3 }} wrapperCol={{ span: 21 }} labelAlign="left">
        <Form.Item label="跳转路径" name="WechatUrl">
          <Input placeholder="请填写跳转路径" />
        </Form.Item>
      </Form>
      <Divider
        orientation="left"
        style={{
          borderTopColor: '#99bbe8',
          color: '#15428b',
          fontWeight: 700,
          marginTop: '0px',
          display: formValue.lines?.length > 0 ? 'flex' : 'none',
        }}
      >
        参数配置
      </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(WeChatTest);
