import {View} from 'react-native'
import {Trans} from '@lingui/react/macro'

import {useEnableSquareButtons} from '#/state/preferences/enable-square-buttons'
import {atoms as a, useTheme} from '#/alf'
import {Button, type ButtonProps} from '#/components/Button'
import {Text} from '#/components/Typography'

export function EditTextButton({
  children,
  style,
  onPress,
  ...props
}: ButtonProps & {value: string}) {
  const t = useTheme()
  const enableSquareButtons = useEnableSquareButtons()

  return (
    <View style={[a.relative]}>
      <Button
        color="secondary"
        style={[
          a.flex_1,
          a.justify_between,
          enableSquareButtons ? a.rounded_sm : a.rounded_full,
          a.border,
          t.atoms.bg,
          t.atoms.border_contrast_low,
          style,
        ]}
        onPress={onPress}
        {...props}>
        {context => (
          <View
            style={[
              a.flex_1,
              a.flex_row,
              a.align_center,
              a.justify_between,
              a.pl_lg,
              a.pr_sm,
              a.py_sm,
              a.gap_sm,
            ]}>
            {typeof children === 'function' ? children(context) : children}
            <View
              style={[
                enableSquareButtons ? a.rounded_sm : a.rounded_full,
                t.atoms.bg_contrast_50,
                {paddingHorizontal: 10, paddingVertical: 8},
              ]}>
              <Text
                style={[a.text_xs, a.font_medium, t.atoms.text_contrast_high]}>
                <Trans>Edit</Trans>
              </Text>
            </View>
          </View>
        )}
      </Button>
    </View>
  )
}
