// Base
import * as base from './_crud-base'

const path = '/api/v1/reference/healthcare'
const name = 'healthcare'

export function getList(params: any = null) {
  let url = path
  if (params?.healthcare) {
    url += `/${params.healthcare}`
    delete params.healthcare
  }
  if (params?.healthcareType) {
    url += `/${params.healthcareType}`
    delete params.healthcareType
  }
  return base.getList(url, params, name)
}

export async function getValueLabelList(params: any = null): Promise<{ value: string; label: string }[]> {
  let data: { value: string; label: string }[] = []
  const result = await getList(params)
  if (result.success) {
    const resultData = result.body?.response?.faskes || []
    const resultUnique = [...new Map(resultData.map((item: any) => [item.kode, item])).values()]
    data = resultUnique.map((item: any) => ({
      value: item.kode ? String(item.kode) : '',
      label: `${item.kode} - ${item.nama}`,
    }))
  }
  return data
}
