// Copyright © 2022 Olo Inc. All rights reserved.
// This software is made available under the Olo Pay SDK License (See LICENSE.md file)
import { useCallback } from 'react';

// Load commands for Fabric
const Commands = require('../components/specs/PaymentCardCvvViewNativeComponent').Commands;

export interface PaymentCardCvvViewNativeMethods {
  blur(ref: any): void;
  clear(ref: any): void;
  createCvvUpdateToken(ref: any): void;
  focus(ref: any): void;
}

export default function usePaymentCardCvvViewManager(): PaymentCardCvvViewNativeMethods {
  const blur = useCallback((ref: any): void => {
    Commands.blur(ref.current);
  }, []);

  const focus = useCallback((ref: any): void => {
    Commands.focus(ref.current);
  }, []);

  const clear = useCallback((ref: any): void => {
    Commands.clear(ref.current);
  }, []);

  const createCvvUpdateToken = useCallback((ref: any): void => {
    // Result comes via onCvvTokenResult event
    Commands.createCvvUpdateToken(ref.current);
  }, []);

  return {
    blur,
    clear,
    createCvvUpdateToken,
    focus,
  };
}