import { router, Stack, useLocalSearchParams } from "expo-router";
import { Alert } from "react-native";

import { AppBackground } from "@/components/AppBackground";
import { BusinessForm } from "@/components/businesses/BusinessForm";
import { useTabBarScrollPadding } from "@/lib/tab-bar-insets";

export default function EditBusinessScreen() {
  const { id } = useLocalSearchParams<{ id: string }>();
  const scrollPadding = useTabBarScrollPadding();

  return (
    <AppBackground>
      <Stack.Screen options={{ headerBackTitle: "Business" }} />
      <BusinessForm
        mode="edit"
        businessId={id}
        scrollPadding={scrollPadding}
        onSaved={() => {
          Alert.alert("Saved", "Business updated", [
            { text: "OK", onPress: () => router.back() },
          ]);
        }}
        onDeleted={() => {
          Alert.alert("Deleted", "Business removed", [
            { text: "OK", onPress: () => router.replace("/(app)/entities") },
          ]);
        }}
      />
    </AppBackground>
  );
}
