import { Linking, Text, TouchableOpacity, View } from "react-native";

import type { LocationStatus } from "@/lib/use-user-location";

const COPY: Record<string, { title: string; body: string; action: string }> = {
  denied: {
    title: "Location access is off",
    body: "Waseel needs your location to show nearby drivers and set your pickup point.",
    action: "Open Settings",
  },
  "services-off": {
    title: "Location services are off",
    body: "Turn on location on your device, then try again.",
    action: "Try Again",
  },
  unavailable: {
    title: "Couldn't find your location",
    body: "Move somewhere with a clearer signal, or set your pickup point manually.",
    action: "Try Again",
  },
};

/** Fills the map slot when there's no position to draw. */
export const LocationNotice = ({
  status,
  onRetry,
}: {
  status: LocationStatus;
  onRetry: () => void;
}) => {
  const copy = COPY[status];

  if (!copy) return null;

  return (
    <View className="flex-1 items-center justify-center px-6">
      <Text className="text-base font-JakartaBold text-black text-center">
        {copy.title}
      </Text>

      <Text className="text-sm font-Jakarta text-general-200 text-center mt-2">
        {copy.body}
      </Text>

      <TouchableOpacity
        onPress={() =>
          status === "denied" ? void Linking.openSettings() : onRetry()
        }
        activeOpacity={0.8}
        className="mt-5 rounded-full bg-primary-500 px-6 py-3"
      >
        <Text className="text-white font-JakartaBold text-sm">
          {copy.action}
        </Text>
      </TouchableOpacity>
    </View>
  );
};
