import { c as create_ssr_component, d as add_attribute, e as escape, h as each, b as subscribe, g as getContext, v as validate_component } from "./index-0e008fb3.js";
import { p as page } from "./stores-9eb273d1.js";
function guard(name) {
  return () => {
    throw new Error(`Cannot call ${name}(...) on the server`);
  };
}
const goto = guard("goto");
const Search = create_ssr_component(($$result, $$props, $$bindings, slots) => {
  let { value } = $$props;
  let { name = "search" } = $$props;
  let { id = name } = $$props;
  let { placeholder = "" } = $$props;
  let { count } = $$props;
  let { pattern = "" } = $$props;
  let { fragments = [] } = $$props;
  if ($$props.value === void 0 && $$bindings.value && value !== void 0)
    $$bindings.value(value);
  if ($$props.name === void 0 && $$bindings.name && name !== void 0)
    $$bindings.name(name);
  if ($$props.id === void 0 && $$bindings.id && id !== void 0)
    $$bindings.id(id);
  if ($$props.placeholder === void 0 && $$bindings.placeholder && placeholder !== void 0)
    $$bindings.placeholder(placeholder);
  if ($$props.count === void 0 && $$bindings.count && count !== void 0)
    $$bindings.count(count);
  if ($$props.pattern === void 0 && $$bindings.pattern && pattern !== void 0)
    $$bindings.pattern(pattern);
  if ($$props.fragments === void 0 && $$bindings.fragments && fragments !== void 0)
    $$bindings.fragments(fragments);
  return `<div class="${"mt-1"}"><input type="${"search"}"${add_attribute("name", name, 0)}${add_attribute("id", id, 0)} class="${"shadow-sm focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 rounded-md"}"${add_attribute("placeholder", placeholder, 0)}${add_attribute("value", value, 0)}></div>

${typeof count === "number" ? `<p class="${"mt-2 text-sm text-gray-500"}"><span class="${"inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-green-100 text-green-800"}"><code>count=${escape(count)}</code></span>

		${!!pattern ? `<span class="${"inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-green-100 text-blue-800"}"><code>pattern=${escape(pattern)}</code></span>` : ``}

		${each(fragments, (fragment) => {
    return `<span class="${"inline-flex items-center mr-2 px-2 py-0.5 rounded text-xs font-medium bg-gray-100 text-gray-800"}"><code>${escape(fragment[0])}=${escape(fragment[1])}</code>
			</span>`;
  })}</p>` : ``}`;
});
const Page = create_ssr_component(($$result, $$props, $$bindings, slots) => {
  let path;
  let names;
  let $filterModels, $$unsubscribe_filterModels;
  let $models, $$unsubscribe_models;
  let $page, $$unsubscribe_page;
  $$unsubscribe_page = subscribe(page, (value) => $page = value);
  getContext("stores").activeConfig;
  const models = getContext("stores").models;
  $$unsubscribe_models = subscribe(models, (value) => $models = value);
  const filterModels = getContext("stores").filterModels;
  $$unsubscribe_filterModels = subscribe(filterModels, (value) => $filterModels = value);
  function getFilteredModels(models2, filter) {
    const names2 = /* @__PURE__ */ new Set();
    Object.values(models2).forEach((model) => {
      if (new RegExp(filter, "i").test(model.name)) {
        names2.add(model.name);
      }
      if (new RegExp(filter, "i").test(model.description)) {
        names2.add(model.name);
      }
    });
    return Array.from(names2.values()).sort();
  }
  function redirect(path2, names2) {
    if (typeof window === "undefined") {
      return;
    }
    if (path2 !== `/datastore`.toLowerCase()) {
      return;
    }
    if (names2.length === 0) {
      return;
    }
    goto(`/datastore/${names2[0]}`.toLowerCase());
  }
  let $$settled;
  let $$rendered;
  do {
    $$settled = true;
    path = $page.url.pathname;
    names = getFilteredModels($models, $filterModels);
    {
      redirect(path, names);
    }
    $$rendered = `
<div class="${"h-screen flex overflow-hidden bg-white"}">
	<div class="${"hidden lg:flex lg:flex-shrink-0"}"><div class="${"flex flex-col w-64"}">
			<div class="${"flex-1 flex flex-col min-h-0 border-r border-gray-200 bg-gray-100"}"><div class="${"flex-1 flex flex-col pb-4 overflow-y-auto"}"><div class="${"flex items-center flex-shrink-0 px-2"}"><div class="${"px-2 py-2 space-y-1"}"><div class="${"mt-1 relative flex items-center"}">${validate_component(Search, "Search").$$render($$result, { value: $filterModels }, {
      value: ($$value) => {
        $filterModels = $$value;
        $$settled = false;
      }
    }, {})}</div></div></div>

					<div class="${"hidden sm:block"}" aria-hidden="${"true"}"><div class="${"pt-1"}"><div class="${"border-t border-gray-200"}"></div></div></div>

					<nav class="${"flex-1"}" aria-label="${"Sidebar"}"><div class="${"px-2 space-y-1"}">${each(names, (name, i) => {
      return `<a${add_attribute("href", `/datastore/${name}`.toLocaleLowerCase(), 0)} class="${"text-gray-600 hover:bg-gray-50 hover:text-gray-900 group flex items-center px-2 py-2 text-sm font-medium rounded-md"}"><p><code>${escape(name)}</code> <br>
										<span class="${"mx-2 text-gray-400 text-xs"}">${escape($models[name].description || "")}</span></p>
								</a>`;
    })}</div></nav></div>
				</div></div></div>
	<div class="${"flex flex-col min-w-0 flex-1 overflow-hidden"}"><div class="${"lg:hidden"}"><div class="${"flex items-center justify-between bg-gray-50 border-b border-gray-200 px-4 py-1.5"}">
				<div><button type="${"button"}" class="${"-mr-3 h-12 w-12 inline-flex items-center justify-center rounded-md text-gray-500 hover:text-gray-900"}"><span class="${"sr-only"}">Open sidebar</span>
						
						<svg class="${"h-6 w-6"}" xmlns="${"http://www.w3.org/2000/svg"}" fill="${"none"}" viewBox="${"0 0 24 24"}" stroke="${"currentColor"}" aria-hidden="${"true"}"><path stroke-linecap="${"round"}" stroke-linejoin="${"round"}" stroke-width="${"2"}" d="${"M4 6h16M4 12h16M4 18h16"}"></path></svg></button></div></div></div>
		<div class="${"flex-1 relative z-0 flex overflow-hidden"}"><main class="${"flex-1 relative z-0 overflow-y-auto focus:outline-none"}">
				<div class="${"absolute inset-0 py-6 px-4 sm:px-6 lg:px-8"}">${slots.main ? slots.main({}) : `
						<div class="${"h-full border-2 border-gray-200 border-dashed rounded-lg"}"></div>
					`}</div>
				</main>
			<aside class="${"hidden relative xl:flex xl:flex-col flex-shrink-0 w-96 border-l border-gray-200"}">
				<div class="${"absolute inset-0 py-6 px-4 sm:px-6 lg:px-8"}">${slots.secondary ? slots.secondary({}) : `
						<div class="${"h-full border-2 border-gray-200 border-dashed rounded-lg"}"></div>
					`}</div>
				</aside></div></div></div>`;
  } while (!$$settled);
  $$unsubscribe_filterModels();
  $$unsubscribe_models();
  $$unsubscribe_page();
  return $$rendered;
});
export { Page as P, Search as S, goto as g };
