import React from 'react';
import { View, Text } from 'react-native';
import { useAppTheme } from '@theme';
import { PrimaryButton } from '@components';
import { useAppDispatch, useAppSelector } from '@store';
import { advanceJobStatus } from '@store/commonReducers/job';
import { useNavigation } from '@react-navigation/native';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
import { AppStackParamList } from '@navigation/navigationTypes';
import { RouteNames, JobStatus } from '@utils/constants';
import { getStyles } from './orderPickedUpScreen.styles';

export const OrderPickedUpScreen: React.FC = () => {
  const { colors } = useAppTheme();
  const styles = getStyles(colors);
  const dispatch = useAppDispatch();
  const navigation = useNavigation<NativeStackNavigationProp<AppStackParamList>>();

  const activeJob = useAppSelector((state) => state.job.activeJob);

  const handleStartDelivery = () => {
    dispatch(advanceJobStatus(JobStatus.EnRoute));
    navigation.navigate(RouteNames.LiveTracking);
  };

  if (!activeJob) return null;

  return (
    <View style={styles.container}>
      {/* Map Background Placeholder */}
      <View style={styles.mapPlaceholder}>
        <Text style={styles.placeholderText}>[ Map Placeholder ]</Text>
      </View>

      {/* Deliver Bottom Card */}
      <View style={styles.bottomCard}>
        <Text style={styles.cardTitle}>Deliver to Customer</Text>
        <Text style={styles.customerName}>{activeJob.dropName}</Text>
        <Text style={styles.customerAddress}>{activeJob.dropAddress}</Text>

        <PrimaryButton
          title="Start Delivery"
          onPress={handleStartDelivery}
          style={styles.startButton}
        />
      </View>
    </View>
  );
};

export default OrderPickedUpScreen;
