"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useTrialStatus = useTrialStatus; var _ioTs = require("io-ts"); var _i18n = require("@kbn/i18n"); var _react = require("react"); var _public = require("@kbn/kibana-react-plugin/public"); var _constants = require("@kbn/license-management-plugin/common/constants"); var _use_tracked_promise = require("../utils/use_tracked_promise"); var _runtime_types = require("../../common/runtime_types"); /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ function useTrialStatus() { const { services } = (0, _public.useKibana)(); const [isTrialAvailable, setIsTrialAvailable] = (0, _react.useState)(false); const [loadState, checkTrialAvailability] = (0, _use_tracked_promise.useTrackedPromise)({ createPromise: async () => { const response = await services.http.get(`${_constants.API_BASE_PATH}/start_trial`); return (0, _runtime_types.decodeOrThrow)(_ioTs.boolean)(response); }, onResolve: response => { setIsTrialAvailable(response); }, onReject: error => { services.notifications.toasts.addDanger(_i18n.i18n.translate('xpack.infra.trialStatus.trialStatusNetworkErrorMessage', { defaultMessage: 'We could not determine if the trial license is available' })); } }, [services]); return { loadState: loadState.state, isTrialAvailable, checkTrialAvailability }; }