import {apiPost, horizontalFormOptions} from '../constants.js'
import {confirmPasswordFormItem, emailFormItem, passwordFormItem} from "./dialog-user-item.js";

export function userRegisterDialog() {
  return {
    actionType: 'dialog',
    dialog: {
      title: '用户注册',
      actions: [
        {
          type: 'reset',
          label: '清空',
        },
        {
          type: 'submit',
          label: '注册',
          level: 'primary',
        },
      ],
      body: {
        type: 'form',
        api: apiPost('${base}/user/register'),
        ...horizontalFormOptions(),
        body: [
          emailFormItem('username'),
          passwordFormItem('password'),
          confirmPasswordFormItem('confirm-password', 'password'),
          {
            type: 'radios',
            name: 'role',
            label: '角色',
            required: true,
            selectFirst: true,
            options: [
              { label: '数据提供方', value: 'PROVIDER' },
              { label: '数据使用方', value: 'CUSTOMER' },
              { label: '审查监管方', value: 'CHECKER' },
            ],
          },
        ],
      },
    },
  }
}

export function userAdministratorRegisterDialog() {
  return {
    actionType: 'dialog',
    dialog: {
      title: '用户注册',
      actions: [
        {
          type: 'reset',
          label: '清空',
        },
        {
          type: 'submit',
          label: '注册',
          level: 'primary',
        },
      ],
      body: {
        type: 'form',
        api: apiPost('${base}/user_management/register'),
        ...horizontalFormOptions(),
        body: [
          emailFormItem('username'),
          passwordFormItem('password'),
          confirmPasswordFormItem('confirm-password', 'password'),
          {
            type: 'radios',
            name: 'role',
            label: '角色',
            required: true,
            selectFirst: true,
            inline: false,
            columnsCount: 2,
            options: [
              { label: '数据提供方', value: 'PROVIDER' },
              { label: '数据使用方', value: 'CUSTOMER' },
              { label: '审查监管方', value: 'CHECKER' },
            ],
          },
        ],
      },
    },
  }
}
