/* eslint-disable unicorn/prefer-ternary */
import hud from '#/utils/hud'

export function useOtherType() {
  const { formData, editQuestion } = inject('sharedData') as any

  const onTypeChange = () => {
    // basic-data/index.vue 初始化
    if (editQuestion.value.answer?.length) {
      formData.value.answer = editQuestion.value.answer[0]
    } else {
      formData.value.answer = undefined
    }
  }

  const submit = () => {
    // answer-data/index.vue 提交
    if (!formData.value.answer) {
      hud.error('请填写答案')
      return
    }
    return {
      answer: JSON.stringify([formData.value.answer]),
    }
  }

  return {
    submit,
    onTypeChange,
  }
}
