import React from 'react'
import { constVoid } from 'fp-ts/lib/function'
import * as O from 'fp-ts/lib/Option'
import { pipe } from 'fp-ts/lib/pipeable'
import * as RNEA from 'fp-ts/lib/ReadonlyNonEmptyArray'
import {
Colors,
flexFlow,
FontSizes,
getColor,
typography,
} from '@monorail/helpers/exports'
import styled from '@monorail/helpers/styled-components'
import {
Banner,
CustomNoData,
IconBox,
} from '@monorail/visualComponents/dataStates/DataStates'
import { Icon } from '@monorail/visualComponents/icon/Icon'
import { IconType } from '@monorail/visualComponents/icon/IconType'
import { Choice } from '@monorail/visualComponents/inputs/Choice'
import {
ListItemPrimaryText,
ListItemSecondaryText,
ListItemText,
} from '@monorail/visualComponents/list/List'
const ListItemContainer = styled.li`
display: flex;
flex-direction: row;
align-items: center;
max-width: 100%;
`
const ListItemTextRow = styled(ListItemText)`
margin-left: 4px;
width: 100%;
`
const StyledChoice = styled(Choice)`
${Icon} {
left: 16px;
}
${IconBox} {
height: 80px;
width: 80px;
}
${Banner} {
color: ${getColor(Colors.Black89a)};
${typography(400, FontSizes.Title2, '24px auto')}
}
`
const StyledCustomNoData = styled(CustomNoData)`
height: 100%;
${flexFlow('column')}
place-items: center;
${IconBox} {
height: 56px;
width: 56px;
}
${Banner} {
color: ${getColor(Colors.Black54a)};
${typography(400, FontSizes.Title5)}
margin-top: 12px;
}
`
export type ListItemProps = {
id: string
primaryText: string
secondaryText?: string
}
export type RenderChoiceProps = {
item: A
disabled?: boolean
type: 'checkbox' | 'radio'
onChange: () => void
handleClick?: (item: A) => void
checked: boolean
} & ListItemProps
const RenderChoice = ({
item,
disabled,
type,
onChange,
handleClick = constVoid,
checked,
id,
primaryText,
secondaryText,
children,
}: RenderChoiceProps & {
children: (props: ListItemProps) => JSX.Element
}) => (
handleClick(item)}
onChange={onChange}
>
{children({
id,
primaryText,
secondaryText,
})}
)
export const renderDefaultListItem = (props: ListItemProps) => (
{props.primaryText}
{props.secondaryText}
)
export const renderIconListItem = (
props: ListItemProps & { iconName: IconType },
) => (
{props.primaryText}
{props.secondaryText}
)
export type OptionsListProps = {
noDataHeading?: string
options: ReadonlyArray>
renderListItem?: (props: ListItemProps) => JSX.Element
}
export const OptionsList = ({
noDataHeading = 'No Results Found',
options,
renderListItem = renderDefaultListItem,
}: OptionsListProps) =>
pipe(
options,
RNEA.fromReadonlyArray,
O.fold(
() => ,
nonEmptyOptions => (
<>
{nonEmptyOptions.map(choiceProps => (
{renderListItem}
))}
>
),
),
)