import _ConfigProvider from "@alifd/next/es/config-provider";
import _extends from "@babel/runtime/helpers/extends";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
var _common$utils$createI, _common$utils;
import * as React from 'react';
import Layout from './pro/layout';
import Font from './pro/font';
import Border from './pro/border';
import Background from './pro/background';
import CssCode from './components/css-code';
import enUS from '@alifd/next/lib/locale/en-us';
import zhCN from '@alifd/next/lib/locale/zh-cn';
import { common } from '@alilc/lowcode-engine';
import './index.less';
var _ref = ((_common$utils$createI = (_common$utils = common.utils).createIntl) === null || _common$utils$createI === void 0 ? void 0 : _common$utils$createI.call(_common$utils)) || {},
  getLocale = _ref.getLocale;
var locale = (getLocale === null || getLocale === void 0 ? void 0 : getLocale()) || 'zh-CN';
var localeSource = {
  'en-US': enUS,
  'zh-CN': zhCN
};
var StyleSetterV2 = /*#__PURE__*/function (_React$PureComponent) {
  function StyleSetterV2() {
    var _this;
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _React$PureComponent.call.apply(_React$PureComponent, [this].concat(args)) || this;
    _this.state = {
      styleData: {},
      cssCodeVisiable: false,
      initFlag: false
    };
    _this.changeCssCodeVisiable = function (visible) {
      _this.setState({
        cssCodeVisiable: !visible
      });
    };
    /**
     * style更改
     * @param styleKey
     * @param value
     */
    _this.onStyleChange = function (styleDataList) {
      var onChange = _this.props.onChange;
      var styleData = Object.assign({}, _this.state.styleData);
      styleDataList && styleDataList.map(function (item) {
        if (item.value == undefined || item.value == null) {
          delete styleData[item.styleKey];
        } else {
          styleData[item.styleKey] = item.value;
        }
      });
      _this.setState({
        styleData: styleData
      });
      onChange && onChange(styleData);
    };
    _this.onStyleDataChange = function (styleData) {
      _this.setState({
        styleData: styleData
      });
      var onChange = _this.props.onChange;
      onChange && onChange(styleData);
    };
    return _this;
  }
  _inheritsLoose(StyleSetterV2, _React$PureComponent);
  var _proto = StyleSetterV2.prototype;
  _proto.componentDidMount = function componentDidMount() {
    var value = this.props.value;
    if (value) {
      this.setState({
        styleData: value
      });
    }
    this.setState({
      initFlag: true
    });
  };
  _proto.render = function render() {
    var _this$props = this.props,
      isShowCssCode = _this$props.isShowCssCode,
      showModuleList = _this$props.showModuleList;
    var _this$state = this.state,
      styleData = _this$state.styleData,
      cssCodeVisiable = _this$state.cssCodeVisiable,
      initFlag = _this$state.initFlag;
    return /*#__PURE__*/React.createElement(_ConfigProvider, {
      locale: localeSource[locale]
    }, /*#__PURE__*/React.createElement("div", {
      className: "lowcode-setter-style-v2"
    }, isShowCssCode && /*#__PURE__*/React.createElement("div", {
      className: "top-bar"
    }, /*#__PURE__*/React.createElement(CssCode, {
      styleData: styleData,
      onStyleDataChange: this.onStyleDataChange
    })), showModuleList.filter(function (item) {
      return item == 'layout';
    }).length > 0 && /*#__PURE__*/React.createElement(Layout, _extends({
      onStyleChange: this.onStyleChange,
      styleData: styleData
    }, this.props)), showModuleList.filter(function (item) {
      return item == 'font';
    }).length > 0 && /*#__PURE__*/React.createElement(Font, _extends({
      onStyleChange: this.onStyleChange,
      styleData: styleData
    }, this.props)), showModuleList.filter(function (item) {
      return item == 'background';
    }).length > 0 && /*#__PURE__*/React.createElement(Background, _extends({
      onStyleChange: this.onStyleChange,
      styleData: styleData
    }, this.props)), showModuleList.filter(function (item) {
      return item == 'border';
    }).length > 0 && /*#__PURE__*/React.createElement(Border, _extends({
      onStyleChange: this.onStyleChange,
      styleData: styleData
    }, this.props))));
  };
  return StyleSetterV2;
}(React.PureComponent);
StyleSetterV2.defaultProps = {
  // 默认单位
  unit: 'px',
  // 默认计算尺寸缩放
  placeholderScale: 1,
  // 展示板块
  showModuleList: ['background', 'border', 'font', 'layout', 'position'],
  // 是否展示css源码编辑面板
  isShowCssCode: true,
  // layout 配置面板
  layoutPropsConfig: {
    // display 展示列表
    showDisPlayList: ['inline', 'flex', 'block', 'inline-block', 'none'],
    isShowPadding: true,
    isShowMargin: true,
    isShowWidthHeight: true
  },
  fontPropsConfig: {
    // fontFamily列表
    fontFamilyList: [{
      value: 'Helvetica',
      label: 'Helvetica'
    }, {
      value: 'Arial',
      label: 'Arial'
    }, {
      value: 'serif',
      label: 'serif'
    }]
  },
  // position 配置面板
  positionPropsConfig: {
    isShowFloat: true,
    isShowClear: true
  }
};
export { StyleSetterV2 as default };