"use client";

import { authenticateWithPasskey, createPasskey } from "@/lib/passkey";
import PrimaryButton from "../PrimaryButton";
import { SymbolView, SymbolViewProps, SymbolWeight } from "expo-symbols";
import { useState } from "react";
import toast from "react-hot-toast";
import { Platform, StyleProp, ViewStyle } from "react-native";

export function Passkee() {
  const [isLoading, setIsLoading] = useState(false);
  async function handleCreate() {
    //
    const ok = await createPasskey();
    if (!ok) toast.error("Error generating passkey");
    else toast.success("Passkey generated!");
  }
  async function handleCheck() {
    //
    const ok = await authenticateWithPasskey();
    if (!ok) toast.error("Can't login");
    else toast.success("Passkey auth successful");
  }

  return (
    <>
      <PrimaryButton
        label="Create Passkey"
        onPress={handleCreate}
        isLoading={isLoading}
        style={{ marginBottom: 16 }}
      />
      <PrimaryButton
        label="Check Passkey"
        onPress={handleCheck}
        isLoading={isLoading}
        style={{ marginBottom: 16 }}
      />
    </>
  );
}
