import _TimePicker from "@alifd/next/es/time-picker";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _DatePicker from "@alifd/next/es/date-picker";
import React, { Component } from 'react';
import { isJSExpression, isJSFunction, isJSSlot } from '@alilc/lowcode-utils';
import { isPlainObject } from './utils';
import moment from 'moment';
import ExpressionSetter from './setter/expression-setter';
import ColorSetter from './setter/color-setter';
import JsonSetter from './setter/json-setter';
import EventsSetter from './setter/events-setter';
import StyleSetterV2 from './setter/style-setter';
import IconSetter from './setter/icon-setter';
import FunctionSetter from './setter/function-setter';
import ClassNameSetter from './setter/classname-setter';
import StringSetter from './setter/string-setter';
import SelectSetter from './setter/select-setter';
import RadioGroupSetter from './setter/radiogroup-setter';
import BoolSetter from './setter/bool-setter';
import NumberSetter from './setter/number-setter';
import I18nSetter from './setter/i18n-setter';
import MixedSetter from './setter/mixed-setter';
import SlotSetter from './setter/slot-setter';
import TextAreaSetter from './setter/textarea-setter';
import ArraySetter from './setter/array-setter';
import ObjectSetter from './setter/object-setter';
import VariableSetter from './setter/variable-setter';
import EventBindDialog from './plugin/plugin-event-bind-dialog';
import VariableBindDialog from './plugin/plugin-variable-bind-dialog';
import './index.less';
import packagesInfo from '../package.json';
import AutoCompleteSetter from "./setter/autoComplete-setter";
import AntIconSetter from "./setter/ant-icon-setter";
export var DateYearSetter = _DatePicker.YearPicker;
export var DateMonthSetter = _DatePicker.MonthPicker;
export var DateRangeSetter = _DatePicker.RangePicker;
export { ExpressionSetter, EventsSetter, JsonSetter, IconSetter };

// eslint-disable-next-line react/no-multi-comp
var StringDateSetter = /*#__PURE__*/function (_Component) {
  function StringDateSetter() {
    return _Component.apply(this, arguments) || this;
  }
  _inheritsLoose(StringDateSetter, _Component);
  var _proto = StringDateSetter.prototype;
  _proto.render = function render() {
    var _this$props = this.props,
      _onChange = _this$props.onChange,
      value = _this$props.value,
      showTime = _this$props.showTime;
    return /*#__PURE__*/React.createElement(_DatePicker, {
      value: moment(value),
      showTime: showTime,
      onChange: function onChange(val) {
        _onChange(val ? val.format() : val);
      }
    });
  };
  return StringDateSetter;
}(Component); // eslint-disable-next-line react/no-multi-comp
var StringTimePicker = /*#__PURE__*/function (_Component2) {
  function StringTimePicker() {
    return _Component2.apply(this, arguments) || this;
  }
  _inheritsLoose(StringTimePicker, _Component2);
  var _proto2 = StringTimePicker.prototype;
  _proto2.render = function render() {
    var _this$props2 = this.props,
      _onChange2 = _this$props2.onChange,
      value = _this$props2.value;
    return /*#__PURE__*/React.createElement(_TimePicker, {
      value: moment(value),
      onChange: function onChange(val) {
        _onChange2(val ? val.format('HH:mm:ss') : val);
      }
    });
  };
  return StringTimePicker;
}(Component);
var DataExpressionSetter = {
  component: ExpressionSetter,
  condition: function condition(field) {
    var v = field.getValue();
    return isJSExpression(v);
  },
  valueType: ['JSExpression'],
  defaultProps: {
    placeholder: '请输入表达式'
  },
  title: '表达式输入',
  recommend: true
};
var DataVariableSetter = {
  component: VariableSetter,
  condition: function condition(field) {
    var v = field.getValue();
    return isJSExpression(v);
  },
  valueType: ['JSExpression'],
  title: '变量输入',
  recommend: true
};
var FunctionBindSetter = {
  component: FunctionSetter,
  title: '函数绑定',
  condition: function condition(field) {
    var v = field.getValue();
    return isJSFunction(v);
  },
  valueType: ['JSFunction']
};
var DataJsonSetter = {
  component: JsonSetter,
  valueType: ['object', 'array']
};
var DataArraySetter = {
  component: ArraySetter,
  defaultProps: {},
  title: 'ArraySetter',
  condition: function condition(field) {
    var v = field.getValue();
    return v == null || Array.isArray(v);
  },
  initialValue: [],
  recommend: true,
  valueType: ['array']
};
var DataObjectSetter = {
  component: ObjectSetter,
  // todo: defaultProps
  defaultProps: {},
  title: 'ObjectSetter',
  // TODO
  condition: function condition(field) {
    var v = field.getValue();
    return v == null || isPlainObject(v);
  },
  initialValue: {},
  recommend: true
};
var DataSlotSetter = {
  component: SlotSetter,
  title: {
    type: 'i18n',
    'zh-CN': '插槽输入',
    'en-US': 'Slot Setter'
  },
  condition: function condition(field) {
    return isJSSlot(field.getValue());
  },
  initialValue: function initialValue(field, value) {
    if (isJSSlot(value)) {
      return value;
    }
    return {
      type: 'JSSlot',
      value: value
    };
  },
  recommend: true,
  valueType: ['JSSlot']
};
var EngineExt = {
  setters: {
    StringSetter: StringSetter,
    NumberSetter: NumberSetter,
    BoolSetter: BoolSetter,
    SelectSetter: SelectSetter,
    VariableSetter: DataVariableSetter,
    ExpressionSetter: DataExpressionSetter,
    RadioGroupSetter: RadioGroupSetter,
    TextAreaSetter: TextAreaSetter,
    DateSetter: StringDateSetter,
    TimePicker: StringTimePicker,
    DateYearSetter: DateYearSetter,
    DateMonthSetter: DateMonthSetter,
    DateRangeSetter: DateRangeSetter,
    EventsSetter: EventsSetter,
    ColorSetter: ColorSetter,
    JsonSetter: DataJsonSetter,
    StyleSetter: StyleSetterV2,
    IconSetter: IconSetter,
    ClassNameSetter: ClassNameSetter,
    I18nSetter: I18nSetter,
    FunctionSetter: FunctionBindSetter,
    MixedSetter: MixedSetter,
    SlotSetter: DataSlotSetter,
    ArraySetter: DataArraySetter,
    ObjectSetter: DataObjectSetter
  },
  setterMap: {
    StringSetter: StringSetter,
    NumberSetter: NumberSetter,
    BoolSetter: BoolSetter,
    SelectSetter: SelectSetter,
    VariableSetter: DataVariableSetter,
    ExpressionSetter: DataExpressionSetter,
    RadioGroupSetter: RadioGroupSetter,
    TextAreaSetter: TextAreaSetter,
    DateSetter: StringDateSetter,
    TimePicker: StringTimePicker,
    DateYearSetter: DateYearSetter,
    DateMonthSetter: DateMonthSetter,
    DateRangeSetter: DateRangeSetter,
    EventsSetter: EventsSetter,
    ColorSetter: ColorSetter,
    JsonSetter: DataJsonSetter,
    StyleSetter: StyleSetterV2,
    IconSetter: IconSetter,
    ClassNameSetter: ClassNameSetter,
    I18nSetter: I18nSetter,
    FunctionSetter: FunctionBindSetter,
    MixedSetter: MixedSetter,
    SlotSetter: DataSlotSetter,
    ArraySetter: DataArraySetter,
    ObjectSetter: DataObjectSetter
  },
  pluginMap: {
    EventBindDialog: EventBindDialog,
    VariableBindDialog: VariableBindDialog
  },
  registerSetter: function registerSetter(key, value) {
    // @ts-ignore
    this.setters[key] = value;
    // @ts-ignore
    this.setterMap[key] = value;
  }
};
EngineExt.registerSetter(AutoCompleteSetter.displayName, AutoCompleteSetter);
EngineExt.registerSetter(AntIconSetter.displayName, AntIconSetter);
// @ts-ignore
EngineExt.version = packagesInfo.version;
// @ts-ignore
window.AliLowCodeEngineExt = EngineExt;
console.log(
// @ts-ignore
'%c AliLowCodeExt %c v'.concat(EngineExt.version, ' '), 'padding: 2px 1px; border-radius: 3px 0 0 3px; color: #fff; background: #5584ff; font-weight: bold;', 'padding: 2px 1px; border-radius: 0 3px 3px 0; color: #fff; background: #42c02e; font-weight: bold;');
export default EngineExt;

// registerSetter(builtinSetters);