import { DisplayPosition } from '../position/display-position';
import React from 'react';
import { uuid } from '../../util/util';
import CnMessageAlc from '../../../lowcode/cn-message-alc';
import { createMessageSetters } from '@/common/util/message';
import isPlainObject from 'lodash/isPlainObject';

export const initialContentJSX = {
  type: 'js',
  source: 'function content(state) { \n  return <div>我是自定义内容</div> \n}',
  compiled:
    'function main(){\n    \n    "use strict";\n\nvar __compiledFunc__ = function content(state) {\n  return /*#__PURE__*/React.createElement("div", {}, "我是自定义内容");\n};\n    return __compiledFunc__.apply(this, arguments);\n  }',
  error: {},
};

const Message = {
  position: [
    DisplayPosition.formDialog,
    DisplayPosition.form,
    DisplayPosition.cnArraySubAreaCard,
  ],
  thumbUrl:
    'https://img.alicdn.com/imgextra/i1/O1CN01aP5EId26WSI0llfNz_!!6000000007669-2-tps-240-144.png',
  title: '信息提示',
  componentName: 'Message',
  formItemBeforeHandler: (formItem, config) => {
    const { formItemConfig = {}, formInstance } = config || {};
    if (formItem) {
      const decoratorProps = formItem?.['x-decorator-props'];
      if (isPlainObject(decoratorProps)) {
        decoratorProps.labelCol = {
          hidden: true,
        };
      }
      const { label } = formItemConfig;
      const componentProps = formItem['x-component-props'];
      if (componentProps) {
        if (label) {
          if (!componentProps.title) {
            componentProps.title = label;
          }
        }
        componentProps.getContext = () => {
          return config?._context;
        };
        componentProps._getFormValue = () => {
          return formInstance?.values;
        };
      }
      formItem.title = '';
    }
  },
  formComponent: CnMessageAlc,
  getFormItemDefaultProps: () => {
    return {
      label: '信息提示',
      name: `message_${uuid()}`,
    };
  },
  getPrototypeList: () => {
    return createMessageSetters();
  },
};
export default Message;
