import { ComponentMetadata } from '@alilc/lowcode-types';
import snippets from './snippets';

const Register2Meta: ComponentMetadata = {
  componentName: 'Register2',
  title: '注册 2.0',
  docUrl: '',
  screenshot: '',
  category: '表单',
  devMode: 'proCode',
  npm: {
    package: '@pisell/private-materials',
    version: '1.0.0',
    exportName: 'Register2',
    main: 'src/index.tsx',
    destructuring: true,
    subName: '',
  },
  props: [],
  configure: {
    props: [
      {
        title: {
          label: '注册方式配置',
        },
        type: 'group',
        display: 'block',
        items: [
          {
            name: 'config.registrationMethods',
            title: { label: '注册方式列表' },
            propType: 'array',
            isRequired: true,
            description: '数组顺序决定显示顺序，第一项为默认注册方式',
            setter: {
              componentName: 'ArraySetter',
              props: {
                itemSetter: {
                  componentName: 'ObjectSetter',
                  props: {
                    config: {
                      items: [
                        {
                          name: 'type',
                          title: '注册方式类型',
                          setter: {
                            componentName: 'SelectSetter',
                            props: {
                              options: [
                                { label: '邮箱', value: 'email' },
                                { label: '手机', value: 'phone' },
                                { label: 'Google', value: 'google' },
                                { label: 'Facebook', value: 'facebook' },
                                { label: 'Apple', value: 'apple' },
                              ],
                            },
                          },
                          isRequired: true,
                        },
                        {
                          name: 'verificationMethod',
                          title: '验证方式（邮箱/手机）',
                          description: '仅对邮箱/手机注册有效，邮箱支持验证链接/验证码/无需验证，手机仅支持验证码',
                          setter: {
                            componentName: 'SelectSetter',
                            props: {
                              options: [
                                { label: '验证链接', value: 'verification_link' },
                                { label: '验证码', value: 'verification_code' },
                                { label: '无需验证', value: 'none' },
                              ],
                            },
                          },
                          defaultValue: 'verification_code',
                        },
                        {
                          name: 'clientId',
                          title: 'Client ID（三方注册）',
                          description: 'Google/Apple 的 Client ID',
                          setter: 'StringSetter',
                        },
                        {
                          name: 'appId',
                          title: 'App ID（Facebook）',
                          description: 'Facebook 的 App ID',
                          setter: 'StringSetter',
                        },
                      ],
                    },
                  },
                },
              },
            },
          },
        ],
      },
      {
        title: {
          label: 'UI 配置',
        },
        type: 'group',
        display: 'block',
        items: [
          {
            name: 'config.ui.logo',
            title: { label: 'Logo' },
            propType: 'object',
            setter: {
              componentName: 'ObjectSetter',
              props: {
                config: {
                  items: [
                    {
                      name: 'show',
                      title: '显示 Logo',
                      setter: 'BoolSetter',
                      defaultValue: true,
                    },
                    {
                      name: 'url',
                      title: 'Logo 图片',
                      setter: 'ImageSetter',
                    },
                    {
                      name: 'position',
                      title: '位置',
                      setter: {
                        componentName: 'RadioGroupSetter',
                        props: {
                          options: [
                            { label: '居左', value: 'left' },
                            { label: '居中', value: 'center' },
                            { label: '居右', value: 'right' },
                          ],
                        },
                      },
                      defaultValue: 'center',
                    },
                  ],
                },
              },
            },
          },
          {
            name: 'config.ui.title',
            title: { label: '欢迎语'},
            propType: 'object',
            setter: {
              componentName: 'ObjectSetter',
              props: {
                config: {
                  items: [
                    {
                      name: 'show',
                      title: '显示',
                      setter: 'BoolSetter',
                      defaultValue: true,
                    },
                    {
                      name: 'text',
                      title: '文案',
                      setter: 'PisellI18nSetter',
                    },
                    {
                      name: 'align',
                      title: '对齐方式',
                      setter: {
                        componentName: 'RadioGroupSetter',
                        props: {
                          options: [
                            { label: '居左', value: 'left' },
                            { label: '居中', value: 'center' },
                            { label: '居右', value: 'right' },
                          ],
                        },
                      },
                      defaultValue: 'center',
                    },
                  ],
                },
              },
            },
          },
          {
            name: 'config.ui.subtitle',
            title: { label: '标题' },
            propType: 'object',
            setter: {
              componentName: 'ObjectSetter',
              props: {
                config: {
                  items: [
                    {
                      name: 'show',
                      title: '显示',
                      setter: 'BoolSetter',
                      defaultValue: true,
                    },
                    {
                      name: 'text',
                      title: '文案',
                      setter: 'PisellI18nSetter',
                    },
                    {
                      name: 'align',
                      title: '对齐方式',
                      setter: {
                        componentName: 'RadioGroupSetter',
                        props: {
                          options: [
                            { label: '居左', value: 'left' },
                            { label: '居中', value: 'center' },
                            { label: '居右', value: 'right' },
                          ],
                        },
                      },
                      defaultValue: 'center',
                    },
                  ],
                },
              },
            },
          },
          {
            name: 'config.ui.desc',
            title: { label: '副标题'},
            propType: 'object',
            setter: {
              componentName: 'ObjectSetter',
              props: {
                config: {
                  items: [
                    {
                      name: 'show',
                      title: '显示',
                      setter: 'BoolSetter',
                      defaultValue: false,
                    },
                    {
                      name: 'text',
                      title: '文案',
                      setter: 'PisellI18nSetter',
                      defaultValue: 'Welcome back! Please enter your details.',
                    },
                    {
                      name: 'align',
                      title: '对齐方式',
                      setter: {
                        componentName: 'RadioGroupSetter',
                        props: {
                          options: [
                            { label: '居左', value: 'left' },
                            { label: '居中', value: 'center' },
                            { label: '居右', value: 'right' },
                          ],
                        },
                      },
                      defaultValue: 'center',
                    },
                  ],
                },
              },
            },
          },
          {
            name: 'config.ui.formLabels',
            title: { label: '表单标签配置' },
            propType: 'object',
            setter: {
              componentName: 'ObjectSetter',
              props: {
                config: {
                  items: [
                    {
                      name: 'email',
                      title: '邮箱标签',
                      setter: {
                        componentName: 'ObjectSetter',
                        props: {
                          config: {
                            items: [
                              {
                                name: 'show',
                                title: '显示标签',
                                setter: 'BoolSetter',
                                defaultValue: true,
                              },
                              {
                                name: 'text',
                                title: '标签文案',
                                setter: 'PisellI18nSetter',
                              },
                            ],
                          },
                        },
                      },
                    },
                    {
                      name: 'phone',
                      title: '手机标签',
                      setter: {
                        componentName: 'ObjectSetter',
                        props: {
                          config: {
                            items: [
                              {
                                name: 'show',
                                title: '显示标签',
                                setter: 'BoolSetter',
                                defaultValue: true,
                              },
                              {
                                name: 'text',
                                title: '标签文案',
                                setter: 'PisellI18nSetter',
                              },
                            ],
                          },
                        },
                      },
                    },
                    {
                      name: 'password',
                      title: '密码标签',
                      setter: {
                        componentName: 'ObjectSetter',
                        props: {
                          config: {
                            items: [
                              {
                                name: 'show',
                                title: '显示标签',
                                setter: 'BoolSetter',
                                defaultValue: true,
                              },
                              {
                                name: 'text',
                                title: '标签文案',
                                setter: 'PisellI18nSetter',
                              },
                            ],
                          },
                        },
                      },
                    },
                    {
                      name: 'verificationCode',
                      title: '验证码标签',
                      setter: {
                        componentName: 'ObjectSetter',
                        props: {
                          config: {
                            items: [
                              {
                                name: 'show',
                                title: '显示标签',
                                setter: 'BoolSetter',
                                defaultValue: true,
                              },
                              {
                                name: 'text',
                                title: '标签文案',
                                setter: 'PisellI18nSetter',
                              },
                            ],
                          },
                        },
                      },
                    },
                  ],
                },
              },
            },
          },
          {
            name: 'config.ui.themeColor',
            title: { label: '主题色' },
            propType: 'string',
            defaultValue: '#7F56D9',
            setter: 'ColorSetter',
          },
        ],
      },
      {
        title: {
          label: '其他配置',
        },
        type: 'group',
        display: 'block',
        items: [
          {
            name: 'config.channel',
            title: { label: '渠道标识' },
            propType: 'string',
            setter: 'StringSetter',
            description: '用于区分不同来源的注册请求',
          },
          {
            name: 'config.legalTerms',
            title: { label: '法律条款设置' },
            propType: 'object',
            setter: {
              componentName: 'ObjectSetter',
              props: {
                config: {
                  items: [
                    {
                      name: 'enabled',
                      title: '启用法律条款',
                      setter: 'BoolSetter',
                      defaultValue: false,
                      description: '是否在页面底部显示法律条款',
                    },
                    {
                      name: 'terms',
                      title: '法律条款列表',
                      propType: 'array',
                      setter: {
                        componentName: 'ArraySetter',
                        props: {
                          itemSetter: {
                            componentName: 'ObjectSetter',
                            props: {
                              config: {
                                items: [
                                  {
                                    name: 'name',
                                    title: '条款名称',
                                    propType: 'string',
                                    setter: 'StringSetter',
                                    isRequired: true,
                                    description: '如：服务条款、隐私协议',
                                  },
                                  {
                                    name: 'url',
                                    title: '条款链接',
                                    propType: 'string',
                                    setter: 'StringSetter',
                                    isRequired: true,
                                    description: '条款文档的完整URL',
                                  },
                                ],
                              },
                            },
                          },
                        },
                      },
                      description: '配置需要显示的法律条款',
                    },
                    {
                      name: 'textTemplate',
                      title: '文本模板',
                      propType: 'string',
                      setter: 'StringSetter',
                      description: '自定义显示文本，使用 {terms} 占位符表示条款链接',
                    },
                  ],
                },
              },
            },
          },
        ],
      },
      {
        title: {
          label: '邮件链接验证',
        },
        type: 'group',
        display: 'block',
        items: [
          {
            name: 'config.emailLinkVerification',
            title: { label: '邮件链接验证模式' },
            propType: 'object',
            setter: {
              componentName: 'ObjectSetter',
              props: {
                config: {
                  items: [
                    {
                      name: 'enabled',
                      title: '启用验证模式',
                      setter: 'BoolSetter',
                      defaultValue: false,
                      description: '从邮件链接跳转过来时启用此模式',
                    },
                    {
                      name: 'code',
                      title: '验证码',
                      setter: 'StringSetter',
                      description: '从 URL 参数中获取的 code（如：602ec2dc2ab8954b2b7bc63a5d920662）',
                    },
                  ],
                },
              },
            },
          },
        ],
      },
      {
        title: {
          label: '其他配置',
        },
        type: 'group',
        display: 'block',
        items: [
          {
            name: 'visible',
            title: { label: '显示组件' },
            propType: 'bool',
            defaultValue: true,
            setter: 'BoolSetter',
          },
          {
            name: 'className',
            title: { label: '自定义类名' },
            propType: 'string',
            setter: 'StringSetter',
          },
        ],
      },
    ],
    supports: {
      style: true,
      events: [
        {
          name: 'onRegister',
          description: '注册回调，参数：(data: RegisterFormData, method: AuthMethodType, channel?: string)',
        },
        {
          name: 'onOAuthLogin',
          description: '三方登录回调，参数：(provider: "google" | "facebook" | "apple", channel?: string)',
        },
        {
          name: 'onSendVerificationCode',
          description: '发送验证码回调，参数：(account: string, type: "email" | "phone", channel?: string)',
        },
        {
          name: 'onEmailLinkExpired',
          description: '邮件链接过期回调，点击"Back to Registration"按钮时触发',
        },
        {
          name: 'onGoToLogin',
          description: '跳转到登录页回调',
        },
        {
          name: 'onClose',
          description: '关闭组件回调',
        },
      ],
    },
    component: {
      isContainer: false,
    },
  },
};

export default {
  ...Register2Meta,
  snippets,
};

