import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState, useEffect } from 'react';
import { styled } from '../styled-components.js';
const INVALID_KEY = 'Invalid license key';
const INVALID_KEY_MISSING = INVALID_KEY + ': missing key';
const EXPIRED = 'Invalid license key: expired';
const TRIAL_EXPIRED = EXPIRED;
const INVALID_HOST = 'Invalid license key: host not allowed';
export const Overlay = ({ licenseInfo }) => {
    const [m, setM] = useState(null); // error message
    const [exp, setExp] = useState(-1); // expires in
    const [local, setLocal] = useState(false); // local preview?
    useEffect(() => {
        if (licenseInfo.local) {
            setLocal(true);
            return;
        }
        if (!licenseInfo.valid) {
            setM(licenseInfo.valid === false
                ? INVALID_KEY + (licenseInfo.cryptoMissing ? ': works only with https' : '')
                : INVALID_KEY_MISSING);
        }
        else if (!licenseInfo.allowed) {
            setM(INVALID_HOST);
        }
        else if (licenseInfo.expired) {
            setM(licenseInfo.t ? EXPIRED : TRIAL_EXPIRED);
        }
        if (licenseInfo.t) {
            setExp(Math.ceil(((licenseInfo?.e ?? 0) - Date.now() / 1000) / 60 / 60 / 24));
        }
    }, [licenseInfo]);
    if (local) {
        return (_jsxs(TrialWrap, { children: [_jsx("a", { href: "https://redoc.ly", children: "Redocly API reference docs" }), " preview"] }));
    }
    if (!m && exp > -1) {
        return _jsxs(TrialWrap, { children: [" Trial version: ", exp, " days remaining "] });
    }
    if (m) {
        return (_jsx(Flash, { children: _jsxs("span", { children: [m, " ", _jsx("br", {}), _jsxs("small", { children: ["Please contact ", _jsx("a", { href: "mailto:team@redoc.ly", children: "team@redoc.ly" }), " to remedy the problem.", ' '] })] }) }));
    }
    return null;
};
const TrialWrap = styled.div `
  padding: 10px 40px;
  position: fixed;
  text-align: right;
  width: 100%;
  box-sizing: border-box;
  color: orange;
  z-index: var(--z-index-surface);
  opacity: 0.6;

  > a,
  a:visited {
    color: orange;
  }
`;
const Flash = styled.div `
  font-size: 1.5em;
  position: fixed;
  z-index: var(--z-index-raised);
  background: rgba(38, 50, 56, 0.93);
  margin: 0;
  padding: 1em;
  width: 100%;
  color: white;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;

  text-align: center;
  box-sizing: border-box;

  > span {
    display: inline-block;
    line-height: 1.5;
  }

  a,
  a:hover,
  a:visited {
    color: white;
  }
`;
//# sourceMappingURL=Overlay.js.map