<template>
  <sd-list-picker
    single
    :load-list-data="loadFormList"
    v-bind="pickerMixinProps"
    v-on="$listeners"
  />
</template>

<script>
import axios from '@/common/services/axios-instance'
import pickerMixin from '@/common/components/sd-picker/picker-mixin'
import components from './_import-components/sd-form-picker-import'
export default {
  name: 'SdFormPicker',
  metaInfo: {
    title: '',
  },
  components,
  mixins: [pickerMixin],
  props: {
    appId: {
      type: String,
      default: undefined,
    },
  },
  data() {
    return {}
  },
  methods: {
    loadFormList() {
      return axios
        .post('api/framework/v1/onlineform/list', {
          maxResults: -1,
          startPosition: 0,
          expressions: [
            {
              dataType: 'str',
              name: 'formCategory',
              op: 'eq',
              stringValue: this.appId,
            },
            {
              dataType: 'str',
              name: 'isDbSynch',
              op: 'ne',
              stringValue: 'N',
            },
          ],
        })
        .then((res) =>
          res.data.data.map((form) => ({
            id: form.id,
            name: form.tableTxt,
            formType: form.formType,
          }))
        )
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
</style>
