// src/components/integrations/molecules/IntegrationCard.tsx
import { PlugZap, ToggleRight } from "lucide-react";
import { Button } from "@contractspec/lib.design-system";
import { jsx, jsxs } from "react/jsx-runtime";
function IntegrationCard({
  id,
  provider,
  name,
  category,
  enabled = true,
  lastSyncAt,
  status = "connected",
  onToggle,
  onConfigure
}) {
  const tone = status === "connected" ? "text-emerald-500 bg-emerald-500/10 border-emerald-500/30" : status === "error" ? "text-red-500 bg-red-500/10 border-red-500/30" : "text-gray-500 bg-gray-500/10 border-gray-500/30";
  return /* @__PURE__ */ jsxs("div", {
    className: "border-border bg-card flex flex-col gap-4 rounded-2xl border p-4 shadow-sm",
    children: [
      /* @__PURE__ */ jsxs("header", {
        className: "flex items-center justify-between",
        children: [
          /* @__PURE__ */ jsxs("div", {
            children: [
              /* @__PURE__ */ jsx("p", {
                className: "text-xl font-semibold",
                children: name
              }),
              /* @__PURE__ */ jsx("p", {
                className: "text-muted-foreground text-sm",
                children: provider
              })
            ]
          }),
          /* @__PURE__ */ jsxs(Button, {
            variant: "outline",
            size: "sm",
            className: `inline-flex items-center gap-2 rounded-full border px-3 py-1 text-xs font-semibold tracking-wide uppercase ${tone}`,
            onPress: () => onToggle?.(id, !enabled),
            children: [
              /* @__PURE__ */ jsx(ToggleRight, {
                className: "h-3.5 w-3.5"
              }),
              enabled ? "Enabled" : "Disabled"
            ]
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "text-muted-foreground text-sm",
        children: [
          category && /* @__PURE__ */ jsx("span", {
            className: "font-medium",
            children: category
          }),
          /* @__PURE__ */ jsxs("div", {
            className: "mt-2 flex flex-wrap items-center gap-3 text-xs tracking-wide uppercase",
            children: [
              /* @__PURE__ */ jsxs("span", {
                className: "inline-flex items-center gap-1",
                children: [
                  /* @__PURE__ */ jsx(PlugZap, {
                    className: "h-3 w-3"
                  }),
                  status
                ]
              }),
              /* @__PURE__ */ jsxs("span", {
                children: [
                  "Last sync:",
                  " ",
                  lastSyncAt ? new Date(lastSyncAt).toLocaleString() : "Not synced yet"
                ]
              })
            ]
          })
        ]
      }),
      /* @__PURE__ */ jsxs("footer", {
        className: "flex items-center gap-2",
        children: [
          /* @__PURE__ */ jsx(Button, {
            className: "flex-1",
            onPress: () => onConfigure?.(id),
            children: "Configure"
          }),
          /* @__PURE__ */ jsx(Button, {
            variant: "ghost",
            className: "flex-1",
            onPress: () => onToggle?.(id, !enabled),
            children: enabled ? "Disconnect" : "Connect"
          })
        ]
      })
    ]
  });
}

// src/components/integrations/organisms/IntegrationMarketplace.tsx
import * as React from "react";
import { Boxes, Search } from "lucide-react";
import { Input } from "@contractspec/lib.design-system";
import {
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue
} from "@contractspec/lib.ui-kit-web/ui/select";
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
function IntegrationMarketplace({
  integrations,
  onToggle,
  onConfigure
}) {
  const [search, setSearch] = React.useState("");
  const [category, setCategory] = React.useState("all");
  const categories = React.useMemo(() => Array.from(new Set(integrations.map((integration) => integration.category))), [integrations]);
  const filtered = integrations.filter((integration) => {
    const matchesSearch = integration.name.toLowerCase().includes(search.toLowerCase()) || integration.provider.toLowerCase().includes(search.toLowerCase());
    const matchesCategory = category === "all" ? true : integration.category === category;
    return matchesSearch && matchesCategory;
  });
  return /* @__PURE__ */ jsxs2("div", {
    className: "border-border bg-card space-y-4 rounded-2xl border p-4",
    children: [
      /* @__PURE__ */ jsxs2("header", {
        className: "flex flex-wrap items-center justify-between gap-3",
        children: [
          /* @__PURE__ */ jsxs2("div", {
            children: [
              /* @__PURE__ */ jsx2("p", {
                className: "text-sm font-semibold tracking-wide uppercase",
                children: "Integration marketplace"
              }),
              /* @__PURE__ */ jsx2("p", {
                className: "text-muted-foreground text-sm",
                children: "Connect AI providers, payments, analytics, and internal tools with BYOK controls."
              })
            ]
          }),
          /* @__PURE__ */ jsx2(Boxes, {
            className: "text-muted-foreground h-5 w-5"
          })
        ]
      }),
      /* @__PURE__ */ jsxs2("div", {
        className: "flex flex-wrap gap-3",
        children: [
          /* @__PURE__ */ jsxs2("div", {
            className: "relative min-w-[200px] flex-1",
            children: [
              /* @__PURE__ */ jsx2(Search, {
                className: "text-muted-foreground pointer-events-none absolute top-1/2 left-3 h-4 w-4 -translate-y-1/2"
              }),
              /* @__PURE__ */ jsx2(Input, {
                type: "search",
                "aria-label": "Search providers",
                className: "w-full py-2 pr-3 pl-9 text-sm",
                value: search,
                onChange: (event) => setSearch(event.target.value),
                placeholder: "Search providers"
              })
            ]
          }),
          /* @__PURE__ */ jsxs2(Select, {
            value: category,
            onValueChange: setCategory,
            children: [
              /* @__PURE__ */ jsx2(SelectTrigger, {
                className: "w-[200px]",
                children: /* @__PURE__ */ jsx2(SelectValue, {
                  placeholder: "All categories"
                })
              }),
              /* @__PURE__ */ jsxs2(SelectContent, {
                children: [
                  /* @__PURE__ */ jsx2(SelectItem, {
                    value: "all",
                    children: "All categories"
                  }),
                  categories.map((item) => /* @__PURE__ */ jsx2(SelectItem, {
                    value: item,
                    children: item
                  }, item))
                ]
              })
            ]
          })
        ]
      }),
      /* @__PURE__ */ jsx2("div", {
        className: "grid gap-4 md:grid-cols-2",
        children: filtered.length ? filtered.map((integration) => /* @__PURE__ */ jsx2(IntegrationCard, {
          id: integration.id,
          provider: integration.provider,
          name: integration.name,
          category: integration.category,
          enabled: integration.enabled,
          status: integration.status,
          lastSyncAt: integration.lastSyncAt,
          onToggle,
          onConfigure
        }, integration.id)) : /* @__PURE__ */ jsx2("div", {
          className: "text-muted-foreground border-border rounded-xl border border-dashed p-6 text-center text-sm md:col-span-2",
          children: "No integrations match your filters."
        })
      })
    ]
  });
}

// src/components/integrations/organisms/IntegrationSettings.tsx
import * as React2 from "react";
import { ShieldCheck, Key, TestTube2 } from "lucide-react";
import { Button as Button2, Input as Input2, Textarea } from "@contractspec/lib.design-system";
import { Checkbox } from "@contractspec/lib.ui-kit-web/ui/checkbox";
import { Label } from "@contractspec/lib.ui-kit-web/ui/label";
import {
  Select as Select2,
  SelectContent as SelectContent2,
  SelectItem as SelectItem2,
  SelectTrigger as SelectTrigger2,
  SelectValue as SelectValue2
} from "@contractspec/lib.ui-kit-web/ui/select";
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
function IntegrationSettings({
  provider,
  initialValues,
  onTestConnection,
  onSave,
  isSaving,
  isTesting
}) {
  const [values, setValues] = React2.useState({
    apiKey: initialValues?.apiKey ?? "",
    secret: initialValues?.secret ?? "",
    ownershipMode: initialValues?.ownershipMode ?? "managed",
    secretProvider: initialValues?.secretProvider ?? "env",
    secretRef: initialValues?.secretRef ?? "",
    config: initialValues?.config ?? `{
  "region": "eu-west-1"
}`
  });
  const handleChange = (event) => {
    const target = event.target;
    const { name, value } = target;
    setValues((prev) => ({
      ...prev,
      [name]: value
    }));
  };
  return /* @__PURE__ */ jsxs3("div", {
    className: "border-border bg-card space-y-4 rounded-2xl border p-4",
    children: [
      /* @__PURE__ */ jsxs3("header", {
        className: "flex flex-wrap items-center justify-between gap-3",
        children: [
          /* @__PURE__ */ jsxs3("div", {
            children: [
              /* @__PURE__ */ jsxs3("p", {
                className: "text-sm font-semibold tracking-wide uppercase",
                children: [
                  provider,
                  " credentials"
                ]
              }),
              /* @__PURE__ */ jsx3("p", {
                className: "text-muted-foreground text-sm",
                children: "Store encrypted keys with BYOK and run safe connection tests."
              })
            ]
          }),
          /* @__PURE__ */ jsx3(ShieldCheck, {
            className: "text-muted-foreground h-5 w-5"
          })
        ]
      }),
      /* @__PURE__ */ jsx3("div", {
        className: "grid gap-4 md:grid-cols-2",
        children: /* @__PURE__ */ jsxs3("div", {
          className: "space-y-2",
          children: [
            /* @__PURE__ */ jsx3(Label, {
              htmlFor: "ownershipMode",
              children: "Ownership"
            }),
            /* @__PURE__ */ jsxs3(Select2, {
              value: values.ownershipMode ?? "managed",
              onValueChange: (next) => setValues((prev) => ({
                ...prev,
                ownershipMode: next
              })),
              children: [
                /* @__PURE__ */ jsx3(SelectTrigger2, {
                  id: "ownershipMode",
                  className: "w-full",
                  children: /* @__PURE__ */ jsx3(SelectValue2, {})
                }),
                /* @__PURE__ */ jsxs3(SelectContent2, {
                  children: [
                    /* @__PURE__ */ jsx3(SelectItem2, {
                      value: "managed",
                      children: "Managed (store encrypted)"
                    }),
                    /* @__PURE__ */ jsx3(SelectItem2, {
                      value: "byok",
                      children: "BYOK (store secret reference)"
                    })
                  ]
                })
              ]
            })
          ]
        })
      }),
      /* @__PURE__ */ jsxs3("div", {
        className: "grid gap-4 md:grid-cols-2",
        children: [
          /* @__PURE__ */ jsxs3("div", {
            className: "space-y-1 text-sm",
            children: [
              /* @__PURE__ */ jsx3(Label, {
                htmlFor: "apiKey",
                className: "font-semibold",
                children: "API key"
              }),
              /* @__PURE__ */ jsxs3("div", {
                className: "relative",
                children: [
                  /* @__PURE__ */ jsx3(Key, {
                    className: "text-muted-foreground pointer-events-none absolute top-1/2 left-3 h-4 w-4 -translate-y-1/2"
                  }),
                  /* @__PURE__ */ jsx3(Input2, {
                    type: "text",
                    name: "apiKey",
                    id: "apiKey",
                    className: "w-full py-2 pr-3 pl-9",
                    value: values.apiKey,
                    onChange: handleChange,
                    required: true
                  })
                ]
              })
            ]
          }),
          /* @__PURE__ */ jsxs3("div", {
            className: "space-y-1 text-sm",
            children: [
              /* @__PURE__ */ jsx3(Label, {
                htmlFor: "secret",
                className: "font-semibold",
                children: "Secret"
              }),
              /* @__PURE__ */ jsx3(Input2, {
                type: "password",
                id: "secret",
                name: "secret",
                className: "w-full px-3 py-2",
                value: values.secret,
                onChange: handleChange
              })
            ]
          })
        ]
      }),
      values.ownershipMode === "byok" ? /* @__PURE__ */ jsxs3("div", {
        className: "space-y-4 rounded-xl border border-blue-500/20 bg-blue-500/5 p-4",
        children: [
          /* @__PURE__ */ jsx3("p", {
            className: "text-sm font-semibold",
            children: "BYOK secret reference"
          }),
          /* @__PURE__ */ jsxs3("div", {
            className: "grid gap-4 md:grid-cols-2",
            children: [
              /* @__PURE__ */ jsxs3("div", {
                className: "space-y-2",
                children: [
                  /* @__PURE__ */ jsx3(Label, {
                    htmlFor: "secretProvider",
                    children: "Secret provider"
                  }),
                  /* @__PURE__ */ jsxs3(Select2, {
                    value: values.secretProvider ?? "env",
                    onValueChange: (next) => setValues((prev) => ({
                      ...prev,
                      secretProvider: next
                    })),
                    children: [
                      /* @__PURE__ */ jsx3(SelectTrigger2, {
                        id: "secretProvider",
                        className: "w-full",
                        children: /* @__PURE__ */ jsx3(SelectValue2, {})
                      }),
                      /* @__PURE__ */ jsxs3(SelectContent2, {
                        children: [
                          /* @__PURE__ */ jsx3(SelectItem2, {
                            value: "env",
                            children: "Environment"
                          }),
                          /* @__PURE__ */ jsx3(SelectItem2, {
                            value: "gcp",
                            children: "GCP Secret Manager"
                          })
                        ]
                      })
                    ]
                  })
                ]
              }),
              /* @__PURE__ */ jsxs3("div", {
                className: "space-y-2",
                children: [
                  /* @__PURE__ */ jsx3(Label, {
                    htmlFor: "secretRef",
                    children: "Secret reference"
                  }),
                  /* @__PURE__ */ jsx3(Input2, {
                    id: "secretRef",
                    name: "secretRef",
                    placeholder: values.secretProvider === "gcp" ? "gcp://projects/.../secrets/..." : "env://MY_TOKEN_ENV_VAR",
                    value: values.secretRef ?? "",
                    onChange: handleChange
                  })
                ]
              })
            ]
          })
        ]
      }) : /* @__PURE__ */ jsxs3("div", {
        className: "flex items-center gap-3 rounded-xl border border-emerald-500/20 bg-emerald-500/5 p-4 text-sm",
        children: [
          /* @__PURE__ */ jsx3(Checkbox, {
            checked: true,
            onCheckedChange: () => {},
            "aria-label": "Managed"
          }),
          /* @__PURE__ */ jsxs3("div", {
            children: [
              /* @__PURE__ */ jsx3("p", {
                className: "font-semibold",
                children: "Managed encryption enabled"
              }),
              /* @__PURE__ */ jsx3("p", {
                className: "text-muted-foreground",
                children: "Secrets are encrypted server-side for this tenant."
              })
            ]
          })
        ]
      }),
      /* @__PURE__ */ jsxs3("div", {
        className: "space-y-1 text-sm",
        children: [
          /* @__PURE__ */ jsx3(Label, {
            htmlFor: "config",
            className: "font-semibold",
            children: "Configuration (JSON)"
          }),
          /* @__PURE__ */ jsx3(Textarea, {
            id: "config",
            name: "config",
            className: "min-h-[140px] w-full font-mono text-sm",
            value: values.config,
            onChange: handleChange
          })
        ]
      }),
      /* @__PURE__ */ jsxs3("div", {
        className: "flex flex-wrap items-center gap-3",
        children: [
          /* @__PURE__ */ jsxs3(Button2, {
            variant: "ghost",
            onPress: () => onTestConnection?.(values),
            disabled: isTesting,
            children: [
              /* @__PURE__ */ jsx3(TestTube2, {
                className: "h-4 w-4"
              }),
              "Test connection"
            ]
          }),
          /* @__PURE__ */ jsx3(Button2, {
            variant: "default",
            onPress: () => onSave?.(values),
            disabled: isSaving,
            children: "Save settings"
          })
        ]
      })
    ]
  });
}

// src/components/integrations/organisms/KnowledgeSourceList.tsx
import { BookCopy, Plus, RefreshCcw } from "lucide-react";
import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
function KnowledgeSourceList({
  sources,
  onRefresh,
  onDelete,
  onAdd
}) {
  return /* @__PURE__ */ jsxs4("div", {
    className: "border-border bg-card space-y-4 rounded-2xl border p-4",
    children: [
      /* @__PURE__ */ jsxs4("header", {
        className: "flex flex-wrap items-center justify-between gap-3",
        children: [
          /* @__PURE__ */ jsxs4("div", {
            children: [
              /* @__PURE__ */ jsx4("p", {
                className: "text-sm font-semibold tracking-wide uppercase",
                children: "Knowledge sources"
              }),
              /* @__PURE__ */ jsx4("p", {
                className: "text-muted-foreground text-sm",
                children: "Manage documentation, specs, and repos powering Studio RAG flows."
              })
            ]
          }),
          /* @__PURE__ */ jsxs4("button", {
            type: "button",
            className: "btn-primary inline-flex items-center gap-2",
            onClick: onAdd,
            children: [
              /* @__PURE__ */ jsx4(Plus, {
                className: "h-4 w-4"
              }),
              "Add source"
            ]
          })
        ]
      }),
      /* @__PURE__ */ jsx4("div", {
        className: "space-y-3",
        children: sources.length ? sources.map((source) => /* @__PURE__ */ jsxs4("div", {
          className: "border-border bg-background flex flex-wrap items-center justify-between gap-3 rounded-xl border p-4",
          children: [
            /* @__PURE__ */ jsxs4("div", {
              className: "flex items-center gap-3",
              children: [
                /* @__PURE__ */ jsx4(BookCopy, {
                  className: "text-muted-foreground h-8 w-8"
                }),
                /* @__PURE__ */ jsxs4("div", {
                  children: [
                    /* @__PURE__ */ jsx4("p", {
                      className: "text-base font-semibold",
                      children: source.name
                    }),
                    /* @__PURE__ */ jsx4("p", {
                      className: "text-muted-foreground text-sm",
                      children: source.type
                    }),
                    /* @__PURE__ */ jsx4("p", {
                      className: "text-muted-foreground text-xs",
                      children: source.indexed ? `Indexed ${source.lastIndexed ? new Date(source.lastIndexed).toLocaleString() : ""}` : "Pending indexing"
                    })
                  ]
                })
              ]
            }),
            /* @__PURE__ */ jsxs4("div", {
              className: "flex items-center gap-2",
              children: [
                /* @__PURE__ */ jsxs4("button", {
                  type: "button",
                  className: "btn-ghost inline-flex items-center gap-1 text-sm",
                  onClick: () => onRefresh?.(source.id),
                  children: [
                    /* @__PURE__ */ jsx4(RefreshCcw, {
                      className: "h-3.5 w-3.5"
                    }),
                    "Reindex"
                  ]
                }),
                /* @__PURE__ */ jsx4("button", {
                  type: "button",
                  className: "btn-ghost text-destructive text-sm",
                  onClick: () => onDelete?.(source.id),
                  children: "Remove"
                })
              ]
            })
          ]
        }, source.id)) : /* @__PURE__ */ jsx4("div", {
          className: "text-muted-foreground border-border rounded-xl border border-dashed p-6 text-center text-sm",
          children: "No knowledge sources added yet."
        })
      })
    ]
  });
}
export {
  KnowledgeSourceList,
  IntegrationSettings,
  IntegrationMarketplace,
  IntegrationCard
};
