import {
  iGetList,
  iChangeShowStatus,
  iUpdateItem
} from '@/api/indexModule'

import MODULETYPE from '@/const/moduleType'

import { translateLabel } from '@/utils'

const getList = async data => {
  const result = await iGetList(data)
  if (result.success) {
    const data = result.data
    result.data = data.map(x => ({
      id: x.id,
      sort: x.sort,
      moduleType: x.moduleType,
      moduleTypeName: translateLabel(MODULETYPE.INDEX_MODULE_TYPE, x.moduleType),
      isShow: x.isShow,
      showStatus: x.isShow ? '展示中' : '未展示'
    }))
  }
  return result
}

const changeShowStatus = async params => await iChangeShowStatus(params)

const updateItem = async params => await iUpdateItem(params)

export {
  getList,
  changeShowStatus,
  updateItem
}
