"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var ricos_network_conditions_exports = {};
__export(ricos_network_conditions_exports, {
  RicosNetworkConditionsTab: () => RicosNetworkConditionsTab
});
module.exports = __toCommonJS(ricos_network_conditions_exports);
var import_react = __toESM(require("react"));
var import_ricos_context = require("./../../../ricos-context/index.js");
var import_uncreachable = require("./../../../_shared/uncreachable.js");
var import_button = require("../components/button.js");
var import_theme = require("../theme.js");
const errorStatus = {
  Connection: -1,
  Permission: 403,
  NotFound: 404,
  Server: 500,
  Throttle: 429
};
const inputStyles = {
  background: "transparent",
  color: import_theme.jsonTreeTheme.base0B,
  padding: "2px",
  border: `1px solid ${import_theme.jsonTreeTheme.base0B}`
};
const RicosNetworkConditionsTab = () => {
  const devContext = import_react.default.useContext(import_ricos_context.DevContext);
  const { connectionState, setConnectionState } = devContext;
  if (!setConnectionState || !connectionState) {
    return /* @__PURE__ */ import_react.default.createElement("div", null, "Dev context not configured");
  }
  return /* @__PURE__ */ import_react.default.createElement("div", { style: { marginLeft: "0.875em", color: import_theme.jsonTreeTheme.base0D } }, /* @__PURE__ */ import_react.default.createElement("div", { style: { display: "flex", justifyContent: "flex-end" } }, /* @__PURE__ */ import_react.default.createElement(import_button.Button, { onClick: () => setConnectionState({ type: "NO_MODIFICATION" }) }, "Reset to default")), /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("label", { style: { display: "block" } }, /* @__PURE__ */ import_react.default.createElement("span", { style: { minWidth: "60px", display: "inline-block" } }, "CRUD"), /* @__PURE__ */ import_react.default.createElement(
    "select",
    {
      style: {
        marginLeft: "4px",
        width: "120px",
        ...inputStyles
      },
      value: connectionState.type,
      onChange: (e) => {
        const value = e.currentTarget.value;
        switch (value) {
          case "BROKEN": {
            setConnectionState({
              type: "BROKEN",
              delay: 0,
              status: "status" in connectionState ? connectionState.status : errorStatus.Connection
            });
            break;
          }
          case "DELAYED": {
            setConnectionState({ type: "DELAYED", delay: 1 });
            break;
          }
          case "NO_MODIFICATION": {
            setConnectionState({ type: "NO_MODIFICATION" });
            break;
          }
          default:
            throw (0, import_uncreachable.unreachable)(value);
        }
      }
    },
    ["NO_MODIFICATION", "BROKEN", "DELAYED"].map((key) => /* @__PURE__ */ import_react.default.createElement("option", { key, value: key }, key))
  )), connectionState.type === "BROKEN" && /* @__PURE__ */ import_react.default.createElement("label", { style: { display: "block" } }, /* @__PURE__ */ import_react.default.createElement("span", { style: { display: "inline-block", marginTop: "8px", marginLeft: "64px" } }, " ", "with status"), /* @__PURE__ */ import_react.default.createElement(
    "select",
    {
      style: { marginLeft: "4px", width: "120px", ...inputStyles },
      value: connectionState.status,
      onChange: (e) => {
        const value = parseInt(e.currentTarget.value, 10);
        setConnectionState({ ...connectionState, status: value });
      }
    },
    Object.entries(errorStatus).map(([label, status]) => /* @__PURE__ */ import_react.default.createElement("option", { key: status, value: status }, label, " (", status, ")"))
  )), connectionState.type !== "NO_MODIFICATION" && /* @__PURE__ */ import_react.default.createElement("label", { style: { display: "block" } }, /* @__PURE__ */ import_react.default.createElement("span", { style: { display: "inline-block", marginTop: "8px", marginLeft: "64px" } }, " ", "delay by"), /* @__PURE__ */ import_react.default.createElement(
    "input",
    {
      style: { marginLeft: "4px", width: "40px", ...inputStyles },
      type: "number",
      value: connectionState.delay,
      min: 0,
      onChange: (e) => {
        const value = Number(e.currentTarget.value) || 0;
        setConnectionState({ ...connectionState, delay: value });
      }
    }
  ), " ", "seconds")));
};
//# sourceMappingURL=ricos-network-conditions.js.map
