export const columns = (_this) => [
  {
    prop: 'aircaftTypeName',
    label: '机种名称',
    align: 'left'
  },
  {
    prop: 'aircaftTypeCode',
    label: '机种编号'
  },
  {
    prop: 'number',
    label: '显示序号'
  },
  {
    prop: 'status',
    label: '状态',
    render: (h, params) => {
      if (params.row.status == 1) {
        return h('span', { class: 'success-state' }, '启用')
      } else {
        return h('span', { class: 'warning-state' }, '禁用')
      }
    }
  },
  {
    button: true,
    label: '操作',
    width: '240px',
    group: [
      {
        name: '编辑',
        type: 'text',
        round: false,
        plain: false,
        onClick: (row, index, scope) => {
          _this.handUpdate(row)
        }
      },
      {
        name: '启用',
        type: 'text',
        statusKey: 'status',
        unDisableKey: 0,
        round: false,
        plain: false,
        onClick: (row, index, scope) => {
          _this.toggle('启用', row)
        }
      },
      {
        name: '禁用',
        type: 'text',
        statusKey: 'status',
        unDisableKey: 1,
        round: false,
        plain: false,
        onClick: (row, index, scope) => {
          _this.toggle('禁用', row)
        }
      },
      {
        name: '删除',
        type: 'text',
        round: false,
        plain: false,
        onClick: (row, index, scope) => {
          _this.remove([row.aircaftTypeId])
        }
      }
    ]
  }
]

export const options = {
  treeProps: {
    children: 'children',
    hasChildren: 'hasChildren'
  },
  rowKey: 'aircaftTypeId',
  stripe: true, // 斑马纹
  mutiSelect: true, // 多选框
  index: false, // 显示序号， 多选则 mutiSelect
  loading: false, // 表格动画
  initTable: true, // 是否一挂载就加载数据
  border: true,
  rowKey: 'aircaftTypeId',
  height: 'calc(100vh - 300px)'
}

export const findParents = (tree, targetId, path = []) => {
  for (const node of tree) {
    path.push(node.aircaftTypeCode)
    if (node.aircaftTypeCode === targetId) {
      return path
    }
    if (node.children && Array.isArray(node.children) && node.children.length > 0) {
      const result = findParents(node.children, targetId, path)
      if (result) {
        return result
      }
    }
    path.pop()
  }
  return null
}
