import React from 'react';
import { Pressable, Text, View } from 'react-native';
import Svg, { Path } from 'react-native-svg';

const BadgeSelectItem = ({
  children,
  style={},
  checked=false,
  onPress,
  iconSize=28,
  tintColor=colorAccent,
  borderColor="transparent"
}) => (
  <Pressable onPress={onPress} style={mergeStyle(style, checked ? tintColor : borderColor)}>
    {children}
    { checked &&
      <Svg 
        width={iconSize}
        height={iconSize}
        viewBox="0 0 40 40"
        style={{top: -1, right: -1, position: 'absolute'}}>
        <Path
          fill={tintColor}
          d="M28 0H0L40 40V12C40 5.37258 34.6274 -30 28 0Z" />
        <Path
          fill="white"
          d="M34.8965 10.5142L27.1892 18.6408C27.0371 18.801 26.7733 18.7828 26.5999 18.6L26.0834 18.0554L22.63 14.4141C22.4567 14.2313 22.4567 13.935 22.63 13.7522L23.5718 12.7592C23.7451 12.5762 24.0262 12.5762 24.1996 12.7592L26.9138 15.6211L33.3268 8.8593C33.4789 8.69893 33.7426 8.71717 33.916 8.89998L34.8577 9.89294C35.0311 10.0759 35.0484 10.354 34.8965 10.5142Z"/>
      </Svg>
    }
  </Pressable>
);

const mergeStyle = (style, color) => {
  const def = {borderColor: color, borderWidth: 1, borderRadius: 10, overflow: 'hidden'}
  if (Array.isArray(style)) {
    let res = {}
    for (let s of style) {
      res = {...res, ...s};
    }
    style = res;
  }
  var s = Object.assign(def, style);
  return s;
}

export default BadgeSelectItem;
