import { gql } from "graphql-request";
import { useQuery } from "@saasquatch/component-boilerplate";
import { useEffect } from "@saasquatch/universal-hooks";
const GET_PAYOUT_DETAILS = gql `
  query getPayoutDetails {
    user: viewer {
      ... on User {
        id
        impactConnection {
          connected
          publisher {
            id
            payoutsAccount {
              hold
              balance
            }
          }
        }
      }
    }
  }
`;
export function usePayoutButton(props) {
  var _a, _b, _c;
  const { data, refetch } = useQuery(GET_PAYOUT_DETAILS, {});
  useEffect(() => {
    const cb = () => refetch();
    window.addEventListener("sqm:tax-form-updated", cb);
    return () => window.removeEventListener("sqm:tax-form-updated", cb);
  }, []);
  return {
    states: {
      payoutSettingsComplete: !!((_c = (_b = (_a = data === null || data === void 0 ? void 0 : data.user) === null || _a === void 0 ? void 0 : _a.impactConnection) === null || _b === void 0 ? void 0 : _b.publisher) === null || _c === void 0 ? void 0 : _c.payoutsAccount),
    },
    text: props.getTextProps(),
  };
}
