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

const PlatformTest = (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 platform = {};
    let allFields = parmarForm.getFieldsValue(true);
    Object.keys(allFields).map(item => {
      platform[formValue.lines.find(ele => ele.Description == item).Name] = allFields[item];
    });
    obj = { ...obj, platform };
    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="PlatformWebUrl">
          <Input placeholder="请填写网页跳转路径" />
        </Form.Item>
        <Form.Item label="APP跳转路径" name="PlatformAppUrl">
          <Input placeholder="请填写APP跳转路径" />
        </Form.Item>
        <Form.Item label="视频地址" name="PlatformVideoUrl">
          <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(PlatformTest);
