/* eslint-disable react/jsx-props-no-spreading */
/* eslint-disable no-shadow */
/* eslint-disable no-underscore-dangle */
/* eslint-disable no-restricted-syntax */
import * as WebBrowser from "expo-web-browser";
import * as React from "react";
import { View, StyleSheet, TouchableWithoutFeedback } from "react-native";
import {
Layout,
Input,
Button,
Icon,
Text,
SelectItem,
} from "@ui-kitten/components";
import { Cascader, BottomModal } from "beeshell";
import { useCreation } from "@umijs/hooks";
import { useModel } from "flooks";
import moment from "moment";
import OpenTime from "./OpenTime";
import Datepicker from "./Datepicker";
import UpLoadImage from "./UpLoadImage";
import Actionsheet from "./Actionsheet";
const styles = StyleSheet.create({
inputContainer: {
flexDirection: "row",
alignItems: "center",
paddingVertical: 10,
paddingHorizontal: 4,
},
input: {
flex: 1,
},
label: {
width: 80,
marginRight: 19,
flexShrink: 0,
},
labelleft: {
width: 73,
flexShrink: 0,
},
right: {
flexDirection: "row",
},
code: {
paddingHorizontal: 5,
marginLeft: 5,
},
selectContent: {
backgroundColor: "#F0F0F0",
},
titleStyle: {
fontSize: 15,
},
leftLabelTextStyle: {
fontSize: 13,
},
rightLabelTextStyle: {
fontSize: 13,
},
sub: {
color: "#787878",
position: "absolute",
left: 90,
zIndex: 2,
},
upload: {
marginTop: 20,
width: 67,
height: 67,
},
});
function* flattenSelect(array, key) {
for (const item of array) {
const _array = key ? item[key] : item;
if (Array.isArray(_array) && _array.length > 0) {
yield* flattenSelect(_array, key);
} else {
yield item;
}
}
}
function getInputProps(
type,
value,
placeholder,
onChange,
secureTextEntry,
renderIcon
) {
let _props = {
defaultValue: value || "",
placeholder,
};
if (type === "phone") {
_props = {
..._props,
dataDetectorTypes: "phoneNumber",
maxLength: 11,
keyboardType: "phone-pad",
};
} else if (type === "password") {
_props = {
..._props,
accessoryRight: ImageProps => renderIcon(ImageProps),
secureTextEntry,
};
} else if (type === "code") {
_props = {
..._props,
maxLength: 6,
keyboardType: "numeric",
};
} else if (type === "amount" || type === "money") {
_props = {
..._props,
keyboardType: "numeric",
};
}
if (onChange) {
_props = {
..._props,
onChangeText: nextValue => onChange(nextValue),
};
}
return _props;
}
const ForwardIcon = props => ;
const Label = ({ type, labelStyle, label, appearance }) => {
return (
{label}
);
};
const Btn = ({ btnText }) => (
);
const FormInput = React.memo(props => {
const {
placeholder,
appearance,
type,
selectList,
value,
style,
sub,
onChange,
labelStyle,
label,
} = props;
const [secureTextEntry, setSecureTextEntry] = React.useState(true);
const { cancel, confirm } = useModel("wordsModel");
const toggleSecureEntry = () => {
setSecureTextEntry(!secureTextEntry);
};
// eslint-disable-next-line no-shadow
const renderIcon = props => (
);
const inputProps = useCreation(() => {
return getInputProps(
type,
value,
placeholder,
onChange,
secureTextEntry,
renderIcon
);
}, [type, value, placeholder, onChange, secureTextEntry, renderIcon]);
const [bottomModalX, changeBottomModalx] = React.useState("");
const [selectVal, setSelectVal] = React.useState("");
const selectInfo = useCreation(() => {
if (type === "select" && props.value && selectList) {
const childrens = [...flattenSelect(selectList, "children")];
return (
childrens.find(item => {
return item.id === props.value;
}) || { name: " " }
);
}
return { name: " " };
}, [value, type, selectList]);
const [open, ChangeOpen] = React.useState(false);
function getMain(type, props, inputProps) {
if (type === "select") {
return (
<>
{
bottomModalX.open();
}}
/>
{
changeBottomModalx(c);
}}
title={props.selectTitle}
titleStyle={styles.titleStyle}
cancelable
leftLabelText={cancel}
leftLabelTextStyle={styles.leftLabelTextStyle}
rightLabelText={confirm}
rightLabelTextStyle={styles.rightLabelTextStyle}
rightCallback={() => {
props.onChange(selectVal);
}}
>
{
setSelectVal(value[0]);
}}
/>
>
);
}
if (type === "openTime") {
return (
{
props.onChange(week, startTime, endTime);
}}
week={props.week}
startTime={props.startTime}
endTime={props.endTime}
/>
);
}
if (type === "date") {
return ;
}
if (type === "url") {
return (
);
}
if (type === "actionSheet") {
return (
<>
>
);
}
if (type === "img") {
return (
);
}
if (appearance === "inner" && type === "code") {
return (
(
)}
accessoryRight={() => }
size="small"
style={styles.input}
appearance="innerCode"
/>
);
}
if (appearance === "inner") {
return (
(
)}
size="small"
style={styles.input}
appearance="inner"
/>
);
}
if (type === "label") {
return null;
}
return ;
}
return (
{appearance !== "inner" && (
)}
{(!value || value === " ") && (
{sub}
)}
{getMain(type, props, inputProps)}
{appearance !== "inner" && type === "code" && Btn(props)}
);
});
export default FormInput;