import * as React from "react";
import { View, ViewStyle, StyleSheet, StyleProp } from "react-native";
import { SvgIcon } from "../Icon";

type Props = {
    /**
     * Icon to show.
     */
    icon: React.ReactElement;
    /**
     * Color for the icon.
     */
    color?: string;

    style?: StyleProp<ViewStyle>;
};

const ICON_SIZE = 24;

/**
 * A component to show an icon in a list item.
 *
 * <div class="screenshots">
 *   <figure>
 *     <img class="medium" src="screenshots/list-icon.png" />
 *   </figure>
 * </div>
 *
 * ## Usage
 * ```js
 * import * as React from 'react';
 * import { ListIcon } from 'react-native-simple-elements/components/List';
 * import * as Colors from "react-native-simple-elements/components/theme/colors";
 *
 * const MyComponent = () => (
 *   <>
 *     <List.Icon color={Colors.blue500} icon="folder" />
 *     <List.Icon color={Colors.blue500} icon="equal" />
 *     <List.Icon color={Colors.blue500} icon="calendar" />
 *   </>
 * );
 *
 * export default MyComponent;
 * ```
 */
const ListIcon = ({ icon, color: iconColor, style }: Props) => (
    <View style={[styles.item, style]} pointerEvents="box-none">
        <SvgIcon icon={icon} size={ICON_SIZE} color={iconColor} />
    </View>
);

const styles = StyleSheet.create({
    item: {
        margin: 8,
        height: 40,
        width: 40,
        alignItems: "center",
        justifyContent: "center",
    },
});

ListIcon.displayName = "List.Icon";

export default ListIcon;
