import React from 'react';
import { Drawer, notification } from 'antd';
import WebConfigForm from './webConfigForm';
import { postEditWebConfig } from '@/services/webConfig/api';

export default props => {
  const { visible, onClose, config, hasIntegerate, isEdit, onOk, submitting, productList } = props;

  return (
    <Drawer
      title={isEdit ? '查看/编辑网站配置' : '新增网站'}
      width={620}
      closable
      onClose={onClose}
      visible={visible}
      maskClosable
      destroyOnClose
    >
      <WebConfigForm
        hasIntegerate={hasIntegerate}
        productList={productList}
        isEdit={isEdit}
        config={config}
        onCancel={onClose}
        submitting={submitting}
        onOk={values => {
          console.log(values, 'values');
          if (!values.homePage && values.hideMap) {
            notification.error({
              message: '在按需加载地图的模式下，请配置主页路径',
              duration: '3',
            });
            return;
          }
          console.log(values.alarmWays, typeof values.alarmWays);
          if (values.alarmWays) {
            values.alarmWays =
              typeof values.alarmWays === 'string'
                ? values.alarmWays
                : values.alarmWays.join(',') || '';
          }
          // eslint-disable-next-line no-unused-expressions
          onOk && onOk(values);
        }}
      />
    </Drawer>
  );
};
