import { Channel } from "@dashboard/channels/utils"; import { ControlledCheckbox } from "@dashboard/components/ControlledCheckbox"; import Hr from "@dashboard/components/Hr"; import { TextField, Typography } from "@material-ui/core"; import { filter } from "fuzzaldrin"; import React from "react"; import { FormattedMessage, useIntl } from "react-intl"; import { useStyles } from "./styles"; export interface ChannelsAvailabilityContentProps { isSelected: (option: Channel) => boolean; channels: Channel[]; contentType?: string; disabled: boolean; onChange: (option: Channel) => void; selected?: number; toggleAllText?: string; toggleAll?: (items: Channel[], selected: number) => void; } export const ChannelsAvailabilityContent: React.FC = ({ isSelected, channels, contentType = "", onChange, selected = 0, toggleAll, toggleAllText, }) => { const classes = useStyles({}); const intl = useIntl(); const searchText = intl.formatMessage({ id: "ybaLoZ", defaultMessage: "Search through channels", }); const [query, onQueryChange] = React.useState(""); const filteredChannels = filter(channels, query, { key: "name" }); return (
{!!contentType && ( )} onQueryChange(e.target.value)} label={searchText} placeholder={searchText} fullWidth />
{!!toggleAll && ( <> ) } onChange={() => toggleAll(channels, selected)} />
)}
{filteredChannels?.length ? ( filteredChannels.map(option => (
{option.name} } onChange={() => onChange(option)} />
)) ) : (
)}
); }; ChannelsAvailabilityContent.displayName = "ChannelsAvailabilityContent"; export default ChannelsAvailabilityContent;