import { h, VNode } from "preact";
import { AnastasisClientFrame } from ".";
import {
  ChallengeFeedback,
  ChallengeFeedbackStatus,
} from "../../../../anastasis-core/lib";
import { Notifications } from "../../components/Notifications";
import { useAnastasisContext } from "../../context/anastasis";
import { authMethods, KnownAuthMethods } from "./authMethod";
export function SolveOverviewFeedbackDisplay(props: {
  feedback?: ChallengeFeedback;
}): VNode {
  const { feedback } = props;
  if (!feedback) {
    return 
;
  }
  switch (feedback.state) {
    case ChallengeFeedbackStatus.Message:
      return (
        
      );
    case ChallengeFeedbackStatus.Payment:
      return (
        
                  To pay you can click here
                
              ),
            },
          ]}
        />
      );
    case ChallengeFeedbackStatus.AuthIban:
      return (
        
      );
    case ChallengeFeedbackStatus.ServerFailure:
      return (
        
      );
    case ChallengeFeedbackStatus.RateLimitExceeded:
      return (
        
      );
    case ChallengeFeedbackStatus.Redirect:
      return (
        
                  Please visit this link: {feedback.redirect_url}
                
              ),
            },
          ]}
        />
      );
    case ChallengeFeedbackStatus.Unsupported:
      return (
        
      );
    case ChallengeFeedbackStatus.TruthUnknown:
      return (
        
      );
    default:
      return ;
  }
}
export function SolveScreen(): VNode {
  const reducer = useAnastasisContext();
  if (!reducer) {
    return (
      
        no reducer in context
      
    );
  }
  if (
    !reducer.currentReducerState ||
    reducer.currentReducerState.recovery_state === undefined
  ) {
    return (
      
        invalid state
      
    );
  }
  if (!reducer.currentReducerState.recovery_information) {
    return (
      
        no recovery information found
      
    );
  }
  if (!reducer.currentReducerState.selected_challenge_uuid) {
    return (
      
        invalid state
        
          
        
      
    );
  }
  function SolveNotImplemented(): VNode {
    return (
      
        
          The challenge selected is not supported for this UI. Please update
          this version or try using another policy.
        
        {reducer && (
          
            
          
        )}
      
    );
  }
  const chArr = reducer.currentReducerState.recovery_information.challenges;
  const selectedUuid = reducer.currentReducerState.selected_challenge_uuid;
  const selectedChallenge = chArr.find((ch) => ch.uuid === selectedUuid);
  const SolveDialog =
    !selectedChallenge ||
    !authMethods[selectedChallenge.type as KnownAuthMethods]
      ? SolveNotImplemented
      : authMethods[selectedChallenge.type as KnownAuthMethods].solve ??
        SolveNotImplemented;
  return ;
}