import React from "react";
import { StyleSheet, View, Text, TouchableOpacity } from "react-native";
import { useAuthStore } from "@/stores/auth";
import { Svg, Path } from "react-native-svg";

const AppleIcon = ({ color = "#fff", size = 20 }) => (
  <Svg width={size} height={size} viewBox="0 0 24 24" fill="none">
    <Path
      d="M12.152 6.896c-.948 0-2.415-1.078-3.96-1.04-2.04.027-3.91 1.183-4.961 3.014-2.117 3.675-.546 9.103 1.519 12.09 1.013 1.454 2.208 3.09 3.792 3.039 1.52-.065 2.09-.987 3.935-.987 1.831 0 2.35.987 3.96.948 1.653-.026 2.681-1.507 3.694-2.961 1.169-1.69 1.648-3.327 1.679-3.418-.039-.013-3.182-1.221-3.22-4.857-.026-3.04 2.48-4.494 2.597-4.559-1.429-2.09-3.623-2.324-4.39-2.376-2-.156-3.675 1.09-4.646 1.09z"
      fill={color}
    />
    <Path
      d="M15.53 3.83c.843-1.012 1.4-2.427 1.245-3.83-1.207.052-2.662.805-3.532 1.818-.78.896-1.454 2.338-1.273 3.714 1.338.104 2.715-.688 3.559-1.701z"
      fill={color}
    />
  </Svg>
);

export const AppleLoginButton = ({ onPress }: { onPress: () => void }) => {
  const authLoading = useAuthStore((state) => state.loading);

  return (
    <TouchableOpacity style={styles.button} onPress={onPress} disabled={authLoading}>
      <View style={styles.contentWrapper}>
        <AppleIcon color="#fff" size={20} />
        <Text style={styles.text}>Continuer avec Apple</Text>
      </View>
    </TouchableOpacity>
  );
};

const styles = StyleSheet.create({
  button: {
    backgroundColor: "#000000",
    borderRadius: 8,
    height: 48,
    paddingHorizontal: 12,
    alignItems: "center",
    justifyContent: "center",
    alignSelf: "stretch",
  },
  contentWrapper: {
    flexDirection: "row",
    alignItems: "center",
    justifyContent: "center",
  },
  text: {
    color: "#ffffff",
    fontSize: 14,
    fontWeight: "600",
    textAlign: "center",
    marginLeft: 12,
  },
});
