import { View, Image, StyleSheet, Button, Text } from "react-native";
import { LoginForm } from "../components/login_form";
import { useLoggin } from "../hooks/useLoggin";
import { LIGHT_THEME } from "../../common/const/theme";
import { router } from "expo-router";
import { LanguageIcon } from "../../lang/components/language_icon";
import { ApiRequestStatus } from "../../common/const/api_request_states";
import { FullPageLoader } from "../../common/components/full_page_loader";
import { useTranslation } from "react-i18next";
import { FullPageMessageModal } from "../../common/components/full_page_message_modal";
import { ServerConnectionErrorModal } from "../../common/components/modals/server_connection_error";
const loginImage = require("../../../assets/login-image.jpg");

export const LoginPage = () => {
  const { control, onSubmit, closeErrorModal, requestStatus, isErrorModalVisible } = useLoggin();
  const LANG = useTranslation();

  if (requestStatus === ApiRequestStatus.LOADING) {
    return <FullPageLoader />;
  }

  return (
    <View style={styles.mainContainer}>
      <View style={styles.imageContainer}>
        <Image
          source={loginImage}
          style={{ width: "100%", height: "100%" }}
          resizeMode="cover"
        />
      </View>
      <View style={styles.loginContainer}>
        <LoginForm control={control} onSubmit={onSubmit} />
      </View>
      <ServerConnectionErrorModal
        isErrorModalVisible={isErrorModalVisible}
        closeErrorModal={closeErrorModal}
      />
    </View>
  );
};

const styles = StyleSheet.create({
  mainContainer: {
    flex: 1,
    backgroundColor: LIGHT_THEME.color.background,
  },
  imageContainer: {
    height: "40%",
    overflow: "hidden",
    borderBottomLeftRadius: 70,
    elevation: 5,
  },
  loginContainer: {
    marginHorizontal: 20,
    marginTop: "-30%",
    marginBottom: 20,
    elevation: 5,
    borderRadius: 10,
    backgroundColor: LIGHT_THEME.color.white,
    height: "70%",
  },
  loginScroll: {
    padding: 20,
    gap: 10,
    justifyContent: "center",
  },
  title: { fontSize: 30, fontWeight: "bold", alignSelf: "center" },
  submitBtn: {
    backgroundColor: "black",
    borderRadius: 5,
    width: "100%",
    padding: 10,
    justifyContent: "center",
    alignItems: "center",
  },
  submitBtnText: {
    color: "white",
    fontSize: 20,
  },
});
