import React from 'react' import { Tag, Space, Badge } from 'antd' import { LoadingOutlined } from '@ant-design/icons' import { isArray, isString, isObject, flatten, isExist } from '@fexd/tools' import useRemoteOptions from './useRemoteOptions' const flattenChildren = (arr: any[]): any[] => arr.map((item) => [item, flattenChildren(item?.children ?? [])]) export default function RemoteOptionsView(props: any): any { const { loading, options: remoteOptions, isRemote } = useRemoteOptions(props?.options) if (!isExist(props?.value)) { return '--' } const options = flatten(flattenChildren([...remoteOptions, ...(props.extraOptions ?? [])])) ?.filter(Boolean) ?.map((item: any) => ({ ...item, label: item?.label ?? item?.title, })) if (isRemote && loading) { return } if (isArray(props?.value)) { // const targets = props?.value.map((value: any) => options.find((item: any) => item?.value === value)) if (props?.value?.length === 0) { return '--' } return ( {props?.value .filter((value) => isExist(isExist) && value !== '') .map((value: any, idx: number) => { const target: any = options.find((item: any) => String(item?.value) === String(value)) return ( {target?.label ?? value ?? '--'} ) })} ) // if (options.some((item: any) => !!item?.tag)) { // return ( // // {targets.map((target: any, idx: number) => ( // // {target?.label} // // ))} // // ) // } // return targets?.length > 0 // ? targets // .map((target: any) => target?.label) // .filter(Boolean) // .join(', ') // : '--' } if (props?.value === '') { return '--' } const target = options.find((item: any) => String(item?.value) === String(props?.value)) // if (!target?.label) { // return '--' // } if (target?.badge) { const isStatus = ['success', 'processing', 'default', 'error', 'warning'].includes(target?.badge) return ( ) } return ( {target?.label ?? props?.value ?? '--'} ) }