var __defProp = Object.defineProperty;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
import { c as create_ssr_component, f as createEventDispatcher, o as onDestroy, e as escape, h as each, d as add_attribute, v as validate_component } from "./index-0e008fb3.js";
import get from "lodash/get.js";
import omit from "lodash/omit.js";
import { E as Editor } from "./editor-8f7742a9.js";
const Entity = create_ssr_component(($$result, $$props, $$bindings, slots) => {
  let correlationId;
  createEventDispatcher();
  let { activeConfig } = $$props;
  let { model } = $$props;
  let { entity } = $$props;
  let properties = [];
  const SUPPORTED_TYPES = ["string", "number", "boolean"];
  function getProperties(model2) {
    const properties2 = Object.keys(omit(get(model2, `schema.model.properties`, {}), "v", "type", "version", "json_patch", "created_at", "updated_at", "handler"));
    return properties2.filter((p) => SUPPORTED_TYPES.includes(getProperty(p).type)).sort();
  }
  function getProperty(property) {
    return get(model, `schema.model.properties.${property}`, {});
  }
  const controller = new AbortController();
  onDestroy(() => {
    controller.abort();
  });
  if ($$props.activeConfig === void 0 && $$bindings.activeConfig && activeConfig !== void 0)
    $$bindings.activeConfig(activeConfig);
  if ($$props.model === void 0 && $$bindings.model && model !== void 0)
    $$bindings.model(model);
  if ($$props.entity === void 0 && $$bindings.entity && entity !== void 0)
    $$bindings.entity(entity);
  let $$settled;
  let $$rendered;
  do {
    $$settled = true;
    properties = getProperties(model);
    correlationId = entity[model.correlation_field];
    $$rendered = `<div class="${"p-5 space-y-8 divide-y divide-gray-200 sm:space-y-5"}"><div><div class="${"bg-white px-4 py-5 border-b border-gray-200 sm:px-6"}"><div class="${"-ml-4 -mt-4 flex justify-between items-center flex-wrap sm:flex-nowrap"}"><div class="${"ml-4 mt-4"}"><h3 class="${"text-lg leading-6 font-medium text-gray-900"}">${escape(entity.name || correlationId || activeConfig.name)}

						${entity.version ? `<code>v${escape(entity.version)}</code>` : ``}</h3>
					<p class="${"mt-1 text-sm text-gray-500 break-all"}"><!-- HTML_TAG_START -->${(entity.description || model.description || "").replace(/\n/g, "<br/>")}<!-- HTML_TAG_END --></p></div>
				<div class="${"ml-4 mt-4 flex-shrink-0"}">${correlationId ? `<button type="${"button"}" class="${"relative inline-flex items-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-blue-400 hover:bg-blue-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-300"}">Copy
						</button>

						<button type="${"button"}" class="${"relative inline-flex items-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-blue-400 hover:bg-blue-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-300"}">Raw
						</button>` : `<button type="${"button"}" class="${"relative inline-flex items-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-blue-400 hover:bg-blue-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-300"}">Raw
						</button>`}
					<button type="${"button"}" class="${"relative inline-flex items-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-green-400 hover:bg-green-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-300"}">Save
					</button></div></div></div>

		<div class="${"mt-6 sm:mt-5 space-y-6 sm:space-y-5"}">${each(properties, (property) => {
      return `<div class="${"sm:grid sm:grid-cols-3 sm:gap-4 sm:items-start sm:border-t sm:border-gray-200 sm:pt-5"}"><label${add_attribute("for", `${correlationId}-${property}`, 0)} class="${"block text-m font-medium text-gray-700 sm:mt-px sm:pt-2"}"><code>${escape(property)}</code>
						<p class="${"text-xs text-gray-400"}">${escape(get(model, `schema.model.properties.${property}.description`, ""))}
						</p></label>
					<div class="${"sm:col-span-2"}"><div class="${""}"><div class="${"mt-4 space-y-4"}"><div class="${"flex"}">${getProperty(property).type === "string" && "enum" in getProperty(property) ? `<select${add_attribute("name", property, 0)}${add_attribute("id", `${correlationId}-${property}`, 0)} class="${"mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md"}">${each(getProperty(property).enum, (value) => {
        return `<option${add_attribute("value", value, 0)}>${escape(value)}</option>`;
      })}</select>` : `${getProperty(property).type === "string" ? `<textarea type="${"text"}"${add_attribute("name", property, 0)}${add_attribute("id", `${correlationId}-${property}`, 0)} autocomplete="${"username"}" class="${"flex-1 block w-full focus:ring-indigo-500 focus:border-indigo-500 min-w-0 rounded-md sm:text-sm border-gray-300"}">${entity[property] || ""}</textarea>` : `${getProperty(property).type === "boolean" ? `<button type="${"button"}" class="${[
        "bg-gray-200 relative inline-flex flex-shrink-0 h-6 w-11 border-2 border-transparent rounded-full cursor-pointer transition-colors ease-in-out duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500",
        entity[property] === true ? "bg-green-300" : ""
      ].join(" ").trim()}" role="${"switch"}"${add_attribute("aria-checked", entity[property] === true ? "true" : "false", 0)} aria-labelledby="${"availability-label"}" aria-describedby="${"availability-description"}">
											<span aria-hidden="${"true"}" class="${[
        "translate-x-0 pointer-events-none inline-block h-5 w-5 rounded-full bg-white shadow transform ring-0 transition ease-in-out duration-200",
        entity[property] === true ? "translate-x-full" : ""
      ].join(" ").trim()}"></span>
											
										</button>` : `${validate_component(Editor, "Editor").$$render($$result, {
        language: "json",
        schema: __spreadValues({ type: "object" }, model.schema.model),
        value: entity
      }, {
        value: ($$value) => {
          entity = $$value;
          $$settled = false;
        }
      }, {})}`}`}`}
								</div></div>
						</div></div>
				</div>`;
    })}</div></div></div>`;
  } while (!$$settled);
  return $$rendered;
});
export { Entity as E };
