import { G as v, N as i, a as y, ah as S, J as x, p as w, j as e, M as j, _ as m, s as t, aA as b, T as d, B as U } from "./index-c65ca4a4.mjs";
import { F as C } from "./Form-f4ced0f0.mjs";
import { I as T } from "./IntegrationHeader-a0a2e0a4.mjs";
const M = v({
  method: "POST",
  path: () => "/slack/test/"
}), N = i.create(() => {
  const { updateRoute: l } = y(), u = i.useModal(), { localSettings: o, updateSetting: r, handleSave: n, validate: k, errors: c, clearError: h } = S({
    onValidate: () => {
      const a = {};
      return s && !x.isURL(s, { require_protocol: !0 }) && (a.slackUrl = "The URL must be in a format like https://hooks.slack.com/services/<your personal key>"), a;
    }
  }), [s, g] = w(o, ["slack_url", "slack_username"]), { mutateAsync: p } = M(), f = async () => {
    m.remove(), await n() ? (await p(null), t({
      message: "Check your Slack channel for the test message",
      type: "neutral"
    })) : t({
      type: "pageError",
      message: "Can't save Slack settings! One or more fields have errors, please doublecheck you filled all mandatory fields"
    });
  };
  return /* @__PURE__ */ e.jsxs(
    j,
    {
      afterClose: () => {
        l("integrations");
      },
      dirty: o.some((a) => a.dirty),
      okColor: "black",
      okLabel: "Save & close",
      testId: "slack-modal",
      title: "",
      onOk: async () => {
        m.remove(), await n() ? (u.remove(), l("integrations")) : t({
          type: "pageError",
          message: "Can't save Slack settings! One or more fields have errors, please doublecheck you filled all mandatory fields"
        });
      },
      children: [
        /* @__PURE__ */ e.jsx(
          T,
          {
            detail: "A messaging app for teams",
            icon: /* @__PURE__ */ e.jsx(b, { className: "h-14 w-14" }),
            title: "Slack"
          }
        ),
        /* @__PURE__ */ e.jsx("div", { className: "mt-7", children: /* @__PURE__ */ e.jsxs(C, { marginBottom: !1, title: "Slack configuration", grouped: !0, children: [
          /* @__PURE__ */ e.jsx(
            d,
            {
              error: !!c.slackUrl,
              hint: c.slackUrl || /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
                "Automatically send newly published posts to a channel in Slack or any Slack-compatible service like Discord or Mattermost. Set up a new incoming webhook ",
                /* @__PURE__ */ e.jsx("a", { href: "https://my.slack.com/apps/new/A0F7XDUAZ-incoming-webhooks", children: "here" }),
                ", and grab the URL."
              ] }),
              placeholder: "https://hooks.slack.com/services/...",
              title: "Webhook URL",
              value: s,
              onBlur: k,
              onChange: (a) => r("slack_url", a.target.value),
              onKeyDown: () => h("slackUrl")
            }
          ),
          /* @__PURE__ */ e.jsxs("div", { className: "flex w-full flex-col gap-2 md:flex-row md:items-center", children: [
            /* @__PURE__ */ e.jsx(
              d,
              {
                containerClassName: "flex-grow",
                hint: "The username to display messages from",
                title: "Username",
                value: g,
                onChange: (a) => r("slack_username", a.target.value)
              }
            ),
            /* @__PURE__ */ e.jsx(U, { color: "outline", label: "Send test notification", onClick: f })
          ] })
        ] }) })
      ]
    }
  );
});
export {
  N as default
};
//# sourceMappingURL=SlackModal-c7b806b1.mjs.map
