import { ColorsStatus } from "@/constants/ColorsStatus";
import Styles from "@/constants/Styles";
import React from "react";
import { Dimensions, Pressable, Text, View } from "react-native";

type Props = {
   title?: string
   subtitle?: string | React.ReactNode
   icon: React.ReactNode
   desc?: string
   rightTopInfo?: string
   onPress?: () => void
   borderType: 'all' | 'bottom' | 'none'
   leftBottomInfo?: React.ReactNode | string
   rightBottomInfo?: React.ReactNode | string
   titleWeight?: 'normal' | 'bold'
   bgColor?: 'white' | 'transparent'
   width?: number
   descEllipsize?: boolean
}

export default function BorderBottomItem({ title, subtitle, icon, desc, onPress, rightTopInfo, borderType, leftBottomInfo, rightBottomInfo, titleWeight, bgColor, width, descEllipsize }: Props) {
   const lebarDim = Dimensions.get("window").width;
   const lebar = width ? lebarDim * width / 100 : 'auto';

   return (
      <Pressable style={[borderType == 'bottom' ? Styles.wrapItemBorderBottom : borderType == 'all' ? Styles.wrapItemBorderAll : Styles.wrapItemBorderNone, bgColor && bgColor == 'white' && ColorsStatus.white]} onPress={onPress}>
         <View style={[Styles.rowItemsCenter]}>
            {icon}
            <View style={[Styles.rowSpaceBetween, width ? { width: lebar } : { width: '88%' }]}>
               <View style={[Styles.ml10, width ? { width: lebar } : { width: '70%' }]}>
                  <Text style={[titleWeight == 'normal' ? Styles.textDefault : Styles.textDefaultSemiBold]} numberOfLines={1} ellipsizeMode='tail'>{title}</Text>
                  {
                     subtitle &&
                        typeof subtitle == "string"
                        ? <Text style={[Styles.textMediumNormal, { lineHeight: 15 }]}>{subtitle}</Text>
                        : <View style={{ alignItems: 'flex-start' }}>
                           {subtitle}
                        </View>
                  }
               </View>
               {
                  rightTopInfo && <Text style={[Styles.textInformation, Styles.mt05]}>{rightTopInfo}</Text>
               }
            </View>

         </View>
         {desc && <Text style={[Styles.textDefault, Styles.mt05, { textAlign: 'justify' }]} numberOfLines={descEllipsize == false ? 0 : 2} ellipsizeMode='tail'>{desc}</Text>}
         {
            (leftBottomInfo || rightBottomInfo) &&
            (
               <View style={[Styles.rowSpaceBetween, Styles.mt10]}>
                  {
                     typeof leftBottomInfo == 'string' ?
                        <Text style={[Styles.textInformation, Styles.cGray, { textAlign: 'left' }]}>{leftBottomInfo}</Text>
                        :
                        leftBottomInfo
                  }
                  {
                     typeof rightBottomInfo == 'string' ?
                        <Text style={[Styles.textInformation, Styles.mt05, Styles.cGray, { textAlign: 'right' }]}>{rightBottomInfo}</Text>
                        :
                        rightBottomInfo
                  }
               </View>
            )
         }
      </Pressable>
   )
}