/* eslint-disable */
import React from 'react';
import { connect } from "../../../redux";
import styled from 'styled-components';
import { i18n } from '@fishx/i18n';
import { Collapse } from '@whalecloud/fdx';
import { getActiveElementWithChildren, getParentFormWidthChildren } from "../../../selectors";
import VisibleRelation from "./VisibleRelation";
import DisableRelation from "./DisableRelation";
import DatasourceRelation from "./DatasourceRelation";
import RequiredRelation from "./RequiredRelation";
import { toolCollapseAttr } from "../../../utils";
/**
 * cascadeSet
 * 设置表单级联属性
 */

var Panel = Collapse.Panel;
var FormContainer = /*#__PURE__*/styled('div', {
  target: "e1a4whe70",
  label: "FormContainer"
})({
  padding: 5
});

var Settings = function Settings(props) {
  var updateElement = props.updateElement,
      element = props.element,
      formElement = props.formElement;
  var formItems = [];
  var relateOptions = [];

  var getFormItems = function getFormItems(ele) {
    var _ele$elements = ele.elements,
        elements = _ele$elements === void 0 ? [] : _ele$elements;

    if (elements.length > 0) {
      elements.forEach(function (item) {
        if (item.data.formItemSettings) {
          var formSettings = item.data.formSettings;
          if (!formSettings) return;
          formItems.push({
            name: formSettings.name,
            type: item.type,
            label: formSettings.label,
            id: item.id
          });

          if (item.id !== element.id) {
            relateOptions.push({
              label: formSettings.name,
              value: formSettings.name,
              title: formSettings.label
            });
          }
        } else {
          getFormItems(item);
        }
      });
    }
  };

  getFormItems(formElement);
  return /*#__PURE__*/React.createElement(FormContainer, null, /*#__PURE__*/React.createElement(Collapse, Object.assign({}, toolCollapseAttr, {
    defaultActiveKey: ['1', '2']
  }), element.type === 'select' && /*#__PURE__*/React.createElement(Panel, {
    header: i18n('PAGEBUIDER_SETTINGS_DATASOURCE_RELATION'),
    key: "2"
  }, /*#__PURE__*/React.createElement(DatasourceRelation, {
    element: element,
    relateOptions: relateOptions,
    formItems: formItems,
    updateElement: updateElement
  })), /*#__PURE__*/React.createElement(Panel, {
    header: i18n('PAGEBUIDER_SETTINGS_VISIBLE_RELATION'),
    key: "1"
  }, /*#__PURE__*/React.createElement(VisibleRelation, {
    element: element,
    relateOptions: relateOptions,
    formItems: formItems,
    updateElement: updateElement
  })), /*#__PURE__*/React.createElement(Panel, {
    header: i18n('PAGEBUIDER_SETTINGS_DISABLE_RELATION'),
    key: "3"
  }, /*#__PURE__*/React.createElement(DisableRelation, {
    element: element,
    relateOptions: relateOptions,
    formItems: formItems,
    updateElement: updateElement
  })), /*#__PURE__*/React.createElement(Panel, {
    header: i18n('PAGEBUIDER_SETTINGS_REQUIRE_RELATION'),
    key: "4"
  }, /*#__PURE__*/React.createElement(RequiredRelation, {
    element: element,
    relateOptions: relateOptions,
    formItems: formItems,
    updateElement: updateElement
  }))));
};

var mapDispatchToProps = function mapDispatchToProps(dispatch) {
  return {
    updateElement: function updateElement(payload) {
      dispatch({
        type: 'appBuilder/updateAndFlattenElement',
        payload: payload
      });
    }
  };
};

export default connect(function (state) {
  var element = getActiveElementWithChildren(state);
  return {
    element: element,
    formElement: element ? getParentFormWidthChildren(state, element.id) : null
  };
}, mapDispatchToProps)(Settings);
//# sourceMappingURL=Settings.js.map