"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.actionGroup = actionGroup;
exports.actions = actions;
exports.array = array;
exports.filter = filter;

function array(title, name, fields, main, arrayTitle) {
  return {
    title: title,
    children: [{
      name: name,
      title: arrayTitle,
      component: 'ArrayItems',
      items: {
        type: 'object',
        decorator: 'ArrayItems.Item',
        children: [{
          component: 'FormFlex',
          children: [{
            component: 'ArrayItems.SortHandle'
          }, {
            component: 'ArrayItems.Index'
          }]
        }, {
          name: 'drawer',
          component: 'Editable.Drawer',
          type: 'void',
          title: '编辑详情',
          reactions: {
            dependencies: [".drawer.layout.".concat(main ? main : fields[0].name)],
            fulfill: {
              schema: {
                title: '{{$deps[0]}}'
              }
            }
          },
          children: [{
            name: 'layout',
            component: 'FormLayout',
            props: {
              layout: 'vertical',
              labelAlign: 'left',
              colon: false,
              labelCol: 24,
              wrapperCol: 24
            },
            children: fields
          }]
        }, {
          component: 'ArrayItems.Remove'
        }]
      },
      children: [{
        component: 'ArrayItems.Addition',
        props: {
          title: '添加一条'
        }
      }]
    }]
  };
}

function actions(props) {
  var _ref = props || {},
      _ref$title = _ref.title,
      title = _ref$title === void 0 ? '操作项' : _ref$title,
      _ref$name = _ref.name,
      name = _ref$name === void 0 ? 'actions' : _ref$name,
      arrayTitle = _ref.arrayTitle;

  return array(title, name, [{
    name: 'children',
    title: '文字',
    component: 'Input',
    default: '操作'
  }, {
    name: 'icon',
    title: '图标',
    component: 'IconPicker',
    props: {
      width: '100%'
    }
  }, {
    name: 'type',
    title: '按钮类型',
    component: 'Select',
    dataSource: [{
      label: '普通',
      value: 'normal'
    }, {
      label: '次要',
      value: 'secondary'
    }, {
      label: '主要',
      value: 'primary'
    }]
  }, {
    name: 'config',
    type: 'object',
    children: [{
      name: 'type',
      title: '操作类型',
      component: 'Select',
      dataSource: [{
        label: '数据请求',
        value: 'request'
      }, {
        label: '跳转链接',
        value: 'link'
      }, {
        label: '二次确认',
        value: 'confirm'
      }, {
        label: '弹窗表单',
        value: 'dialog-form'
      }, {
        label: '弹窗表格',
        value: 'dialog-table'
      }, {
        label: '抽屉表单',
        value: 'drawer-form'
      }, {
        label: '抽屉表格',
        value: 'drawer-table'
      }],
      default: 'request'
    }, {
      name: 'to',
      title: '链接地址',
      component: 'Input',
      reactions: {
        dependencies: ['.type'],
        fulfill: {
          state: {
            visible: "{{$deps[0] === 'link'}}"
          }
        }
      }
    }, {
      name: 'blank',
      title: '打开新页面',
      component: 'Switch',
      reactions: {
        dependencies: ['.type'],
        fulfill: {
          state: {
            visible: "{{$deps[0] === 'link'}}"
          }
        }
      }
    }, {
      name: 'title',
      title: '标题',
      component: 'Input',
      reactions: {
        dependencies: ['.type'],
        fulfill: {
          state: {
            visible: "{{$deps[0] !== 'link' && $deps[0] !== 'request'}}"
          }
        }
      }
    }, {
      name: 'content',
      title: '确认内容',
      component: 'Input',
      reactions: {
        dependencies: ['.type'],
        fulfill: {
          state: {
            visible: "{{$deps[0] === 'confirm'}}"
          }
        }
      }
    }, {
      name: 'url',
      title: '请求地址',
      component: 'Input',
      reactions: {
        dependencies: ['.type'],
        fulfill: {
          state: {
            visible: "{{$deps[0] !== 'link'}}"
          }
        }
      }
    }, {
      name: 'method',
      title: '请求方式',
      component: 'Radio',
      dataSource: [{
        label: 'get',
        value: 'get'
      }, {
        label: 'post',
        value: 'post'
      }],
      reactions: {
        dependencies: ['.type'],
        fulfill: {
          state: {
            visible: "{{$deps[0] !== 'link'}}"
          }
        }
      }
    }, {
      name: 'params',
      title: '请求参数',
      component: 'JsonInput',
      reactions: {
        dependencies: ['.type'],
        fulfill: {
          state: {
            visible: "{{$deps[0] !== 'link'}}"
          }
        }
      }
    }, {
      name: 'initialValues',
      title: '表单初始值',
      component: 'Input',
      reactions: {
        dependencies: ['.type'],
        fulfill: {
          state: {
            visible: "{{$deps[0] === 'dialog-form' || $deps[0] === 'drawer-form'}}"
          }
        }
      }
    }, {
      name: 'schema',
      title: 'Schema',
      component: 'JsonInput',
      reactions: {
        dependencies: ['.type'],
        fulfill: {
          state: {
            visible: "{{$deps[0] !== 'link' && $deps[0] !== 'request' && $deps[0] !== 'confirm'}}"
          }
        }
      }
    }, {
      name: 'successMsg',
      title: '请求成功提示',
      component: 'Input',
      reactions: {
        dependencies: ['.type'],
        fulfill: {
          state: {
            visible: "{{$deps[0] !== 'link'}}"
          }
        }
      }
    }, {
      name: 'onSuccess',
      title: '请求成功回调',
      component: 'Input',
      reactions: {
        dependencies: ['.type'],
        fulfill: {
          state: {
            visible: "{{$deps[0] !== 'link'}}"
          }
        }
      }
    }]
  }, {
    name: 'visible',
    title: '是否可见',
    component: 'Input'
  }, {
    name: 'disabled',
    title: '是否禁用',
    component: 'Input'
  }], 'children', arrayTitle);
}

function actionGroup(title, name) {
  return {
    title: title,
    name: name,
    type: 'object',
    children: [{
      component: 'FormCollapse',
      children: [actions(), {
        title: '其他',
        children: [{
          name: 'type',
          title: '展示类型',
          component: 'Select',
          dataSource: [{
            label: '按钮',
            value: 'button'
          }, {
            label: '文字',
            value: 'text'
          }],
          default: 'button'
        }, {
          name: 'max',
          title: '最大展示数量',
          component: 'NumberPicker',
          default: 3
        }, {
          name: 'moreText',
          title: '"更多"文案',
          component: 'Input',
          default: '更多'
        }]
      }]
    }]
  };
}

function filter(name) {
  return {
    name: name,
    type: 'object',
    children: [array('表单项', 'schema', [{
      name: 'name',
      title: 'ID',
      component: 'Input',
      required: true
    }, {
      name: 'title',
      title: '标题',
      component: 'Input'
    }, {
      name: 'component',
      title: '组件类型',
      component: 'Select',
      dataSource: [{
        label: 'Input',
        value: 'Input'
      }, {
        label: 'Select',
        value: 'Select'
      }]
    }, array('数据源', 'dataSource', [{
      name: 'value',
      title: '值',
      component: 'Input',
      required: true
    }, {
      name: 'label',
      title: '文案',
      component: 'Input',
      required: true
    }, {
      name: 'color',
      title: '颜色',
      component: 'ColorPicker'
    }], undefined, '数据源'), {
      name: 'required',
      title: '是否必填',
      component: 'Switch'
    }, {
      name: 'props',
      title: '属性',
      component: 'JsonInput'
    }])]
  };
}