import { aL as y, aM as U, aQ as o, aK as D, aJ as e, aO as M, S as x, K as s, n as r, e as k, aq as P, aR as K, V as $ } from "./index-THhC4TET.js";
import { useState as m } from "react";
import { A as q } from "./AppCard-1cD7do0L.js";
import { u as z } from "./useIsAppEnabled-I_8ayZmb.js";
const Y = function({ app: C, eventType: g }) {
  var b;
  const _ = y.usePathname(), { getAppData: c, setAppData: t, disabled: Q } = U(), { enabled: f, updateEnabled: N } = z(C), p = c("roundRobinLeadSkip"), w = c("roundRobinSkipCheckRecordOn") ?? o.CONTACT, E = c("skipContactCreation"), A = c("createLeadIfAccountNull"), T = c("createNewContactUnderAccount"), L = c("createEventOn") ?? o.CONTACT, O = c("onBookingWriteToEventObject") ?? !1, i = c("onBookingWriteToEventObjectMap") ?? {}, R = c("createEventOnLeadCheckForContact") ?? !1, j = c("onBookingChangeRecordOwner") ?? !1, S = c("onBookingChangeRecordOwnerName") ?? [], { t: a } = D(), u = [
    { label: a("contact"), value: o.CONTACT },
    { label: a("salesforce_lead"), value: o.LEAD },
    { label: a("salesforce_contact_under_account"), value: o.ACCOUNT }
  ], [d, B] = m(
    u.find((n) => n.value === L) ?? u[0]
  ), h = [
    { label: a("contact"), value: o.CONTACT },
    { label: a("salesforce_lead"), value: o.LEAD },
    { label: a("account"), value: o.ACCOUNT }
  ], [W, F] = m(
    h.find((n) => n.value === w) ?? h[0]
  ), [l, v] = m({
    field: "",
    value: ""
  });
  return /* @__PURE__ */ e.jsx(
    q,
    {
      returnTo: `${M}${_}?tabName=apps`,
      app: C,
      teamId: ((b = g.team) == null ? void 0 : b.id) || void 0,
      switchOnClick: (n) => {
        N(n);
      },
      switchChecked: f,
      hideSettingsIcon: !0,
      children: /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
        /* @__PURE__ */ e.jsxs("div", { className: "mb-4 ml-2", children: [
          /* @__PURE__ */ e.jsx("label", { className: "text-emphasis mb-2 align-text-top text-sm font-medium", children: a("salesforce_create_record_as") }),
          /* @__PURE__ */ e.jsx(
            x,
            {
              className: "mt-2 w-60",
              options: u,
              value: d,
              onChange: (n) => {
                n && (B(n), t("createEventOn", n.value));
              }
            }
          )
        ] }),
        d.value === o.CONTACT ? /* @__PURE__ */ e.jsx("div", { children: /* @__PURE__ */ e.jsx(
          s,
          {
            label: a("skip_contact_creation", { appName: "Salesforce" }),
            labelOnLeading: !0,
            checked: E,
            onCheckedChange: (n) => {
              t("skipContactCreation", n);
            }
          }
        ) }) : null,
        d.value === o.LEAD ? /* @__PURE__ */ e.jsx("div", { children: /* @__PURE__ */ e.jsx(
          s,
          {
            label: a("salesforce_create_event_on_contact"),
            labelOnLeading: !0,
            checked: R,
            onCheckedChange: (n) => {
              t("createEventOnLeadCheckForContact", n);
            }
          }
        ) }) : null,
        d.value === o.ACCOUNT ? /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
          /* @__PURE__ */ e.jsx("div", { className: "mb-4", children: /* @__PURE__ */ e.jsx(
            s,
            {
              label: a("salesforce_create_new_contact_under_account"),
              labelOnLeading: !0,
              checked: T,
              onCheckedChange: (n) => {
                t("createNewContactUnderAccount", n);
              }
            }
          ) }),
          /* @__PURE__ */ e.jsx("div", { children: /* @__PURE__ */ e.jsx(
            s,
            {
              label: a("salesforce_if_account_does_not_exist"),
              labelOnLeading: !0,
              checked: A,
              onCheckedChange: (n) => {
                t("createLeadIfAccountNull", n);
              }
            }
          ) })
        ] }) : null,
        /* @__PURE__ */ e.jsxs("div", { className: "mt-4", children: [
          /* @__PURE__ */ e.jsx(
            s,
            {
              label: a("on_booking_write_to_event_object"),
              labelOnLeading: !0,
              checked: O,
              onCheckedChange: (n) => {
                t("onBookingWriteToEventObject", n);
              }
            }
          ),
          O ? /* @__PURE__ */ e.jsxs("div", { className: "ml-2 mt-2", children: [
            /* @__PURE__ */ e.jsxs("div", { className: "grid grid-cols-3 gap-4", children: [
              /* @__PURE__ */ e.jsx("div", { children: a("field_name") }),
              /* @__PURE__ */ e.jsx("div", { children: a("value") })
            ] }),
            /* @__PURE__ */ e.jsxs("div", { children: [
              ...Object.keys(i).map((n) => /* @__PURE__ */ e.jsxs("div", { className: "mt-2 grid grid-cols-3 gap-4", children: [
                /* @__PURE__ */ e.jsx("div", { children: /* @__PURE__ */ e.jsx(r, { value: n, readOnly: !0 }) }),
                /* @__PURE__ */ e.jsx("div", { children: /* @__PURE__ */ e.jsx(r, { value: i[n], readOnly: !0 }) }),
                /* @__PURE__ */ e.jsx("div", { children: /* @__PURE__ */ e.jsx(
                  k,
                  {
                    StartIcon: "trash",
                    variant: "icon",
                    color: "destructive",
                    onClick: () => {
                      const I = i;
                      delete i[n], t("onBookingWriteToEventObjectMap", I);
                    }
                  }
                ) })
              ] }, n)),
              /* @__PURE__ */ e.jsxs("div", { className: "mt-2 grid grid-cols-3 gap-4", children: [
                /* @__PURE__ */ e.jsx("div", { children: /* @__PURE__ */ e.jsx(
                  r,
                  {
                    value: l.field,
                    onChange: (n) => v({
                      ...l,
                      field: n.target.value
                    })
                  }
                ) }),
                /* @__PURE__ */ e.jsx("div", { children: /* @__PURE__ */ e.jsx(
                  r,
                  {
                    value: l.value,
                    onChange: (n) => v({
                      ...l,
                      value: n.target.value
                    })
                  }
                ) })
              ] })
            ] }),
            /* @__PURE__ */ e.jsx(
              k,
              {
                className: "mt-2",
                size: "sm",
                disabled: !(l.field && l.value),
                onClick: () => {
                  if (Object.keys(i).includes(
                    l.field.trim()
                  )) {
                    P("Field already exists", "error");
                    return;
                  }
                  t("onBookingWriteToEventObjectMap", {
                    ...i,
                    [l.field.trim()]: l.value.trim()
                  }), v({ field: "", value: "" });
                },
                children: a("add_new_field")
              }
            )
          ] }) : null
        ] }),
        /* @__PURE__ */ e.jsx("div", { className: "mt-4", children: /* @__PURE__ */ e.jsx(
          s,
          {
            label: "Change record owner on booking",
            labelOnLeading: !0,
            checked: j,
            onCheckedChange: (n) => {
              t("onBookingChangeRecordOwner", n);
            }
          }
        ) }),
        j ? /* @__PURE__ */ e.jsxs("div", { className: "ml-2 mt-2", children: [
          /* @__PURE__ */ e.jsx("p", { className: "mb-2", children: a("salesforce_owner_name_to_change") }),
          /* @__PURE__ */ e.jsx(
            r,
            {
              value: S,
              onChange: (n) => t("onBookingChangeRecordOwnerName", n.target.value)
            }
          )
        ] }) : null,
        g.schedulingType === K.ROUND_ROBIN ? /* @__PURE__ */ e.jsxs("div", { className: "mt-4", children: [
          /* @__PURE__ */ e.jsx(
            s,
            {
              label: a("salesforce_book_directly_with_attendee_owner"),
              labelOnLeading: !0,
              checked: p,
              onCheckedChange: (n) => {
                t("roundRobinLeadSkip", n), n && t("enabled", n);
              }
            }
          ),
          p ? /* @__PURE__ */ e.jsxs("div", { className: "my-4 ml-2", children: [
            /* @__PURE__ */ e.jsx("label", { className: "text-emphasis mb-2 align-text-top text-sm font-medium", children: a("salesforce_check_owner_of") }),
            /* @__PURE__ */ e.jsx(
              x,
              {
                className: "mt-2 w-60",
                options: h,
                value: W,
                onChange: (n) => {
                  n && (F(n), t("roundRobinSkipCheckRecordOn", n.value));
                }
              }
            )
          ] }) : null,
          /* @__PURE__ */ e.jsx($, { className: "mt-2", severity: "neutral", title: a("skip_rr_description") })
        ] }) : null
      ] })
    }
  );
};
export {
  Y as default
};
