import {View} from 'react-native'

import {FormError} from '@/components/forms/form-error'
import {Button} from '@/components/ui/button'
import {atoms as a} from '@/sprinkles'

// the standard form submit block: trailing error + full-width primary cta
export const FormSubmit = ({
  label,
  submitting,
  error,
  disabled,
  onPress,
}: {
  label: string
  submitting: boolean
  error: string | null
  disabled: boolean
  onPress: () => void
}) => (
  <View style={[a.pt_md, a.gap_md]}>
    {error && <FormError error={error} />}
    <Button
      label={submitting ? 'Saving…' : label}
      color="primary"
      size="large"
      shape="rectangular"
      onPress={onPress}
      disabled={disabled}
      style={a.w_full}
    />
  </View>
)
