import { jsx as n, jsxs as l, Fragment as S } from "react/jsx-runtime";
import { G as ce, J as de, _ as c, y as re, $ as v, a0 as _, a1 as U, W as se, S as m, w as d, I as h, z as f, a2 as M, a3 as he, N as ue } from "./index-ykl8OQ78.js";
import { useState as g } from "react";
import { A as ve } from "./AppCard-cTyZ7qdO.js";
import { u as me } from "./useIsAppEnabled-jQTpW-EN.js";
const ke = function({ app: W, eventType: R }) {
  var P;
  const G = ce.usePathname(), { getAppData: o, setAppData: t, disabled: pe } = de(), { enabled: K, updateEnabled: V } = me(W), D = o("roundRobinLeadSkip"), Y = o("roundRobinSkipCheckRecordOn") ?? c.CONTACT, z = o("ifFreeEmailDomainSkipOwnerCheck") ?? !1, $ = o("skipContactCreation"), H = o("createLeadIfAccountNull"), J = o("createNewContactUnderAccount"), F = o("createEventOn") ?? c.CONTACT, B = o("onBookingWriteToEventObject") ?? !1, p = o("onBookingWriteToEventObjectMap") ?? {}, X = o("createEventOnLeadCheckForContact") ?? !1, L = o("onBookingChangeRecordOwner") ?? !1, q = o("onBookingChangeRecordOwnerName") ?? [], y = o("sendNoShowAttendeeData") ?? !1, Q = o("sendNoShowAttendeeDataField") ?? "", j = o("onBookingWriteToRecord") ?? !1, r = o("onBookingWriteToRecordFields") ?? {}, Z = o("ignoreGuests") ?? !1, { t: a } = re(), k = [
    { label: a("contact"), value: c.CONTACT },
    { label: a("salesforce_lead"), value: c.LEAD },
    { label: a("salesforce_contact_under_account"), value: c.ACCOUNT }
  ], [b, ee] = g(
    k.find((e) => e.value === F) ?? k[0]
  ), T = [
    { label: a("text"), value: v.TEXT },
    { label: a("date"), value: v.DATE },
    { label: a("phone").charAt(0).toUpperCase() + a("phone").slice(1), value: v.PHONE },
    { label: a("custom"), value: v.CUSTOM },
    { label: a("picklist"), value: v.PICKLIST }
  ], [O, ne] = g(T[0]), N = [
    { label: a("on_every_booking"), value: _.EVERY_BOOKING },
    { label: a("only_if_field_is_empty"), value: _.FIELD_EMPTY }
  ], [ae, le] = g(N[0]), w = [
    { label: a("booking_start_date"), value: U.BOOKING_START_DATE },
    { label: a("booking_created_date"), value: U.BOOKING_CREATED_DATE }
  ], [I, te] = g(w[0]), [i, C] = g({
    field: "",
    fieldType: O.value,
    value: "",
    whenToWrite: _.FIELD_EMPTY
  }), E = [
    { label: a("contact"), value: c.CONTACT },
    { label: a("salesforce_lead"), value: c.LEAD },
    { label: a("account"), value: c.ACCOUNT }
  ], [oe, ie] = g(
    E.find((e) => e.value === Y) ?? E[0]
  ), [s, A] = g({
    field: "",
    value: ""
  }), x = () => /* @__PURE__ */ n(
    d,
    {
      label: a("salesforce_create_new_contact_under_account"),
      labelOnLeading: !0,
      checked: J,
      onCheckedChange: (e) => {
        t("createNewContactUnderAccount", e);
      }
    }
  );
  return /* @__PURE__ */ n(
    ve,
    {
      returnTo: `${se}${G}?tabName=apps`,
      app: W,
      teamId: ((P = R.team) == null ? void 0 : P.id) || void 0,
      switchOnClick: (e) => {
        V(e);
      },
      switchChecked: K,
      hideSettingsIcon: !0,
      children: /* @__PURE__ */ l(S, { children: [
        /* @__PURE__ */ l("div", { className: "mb-4 ml-2", children: [
          /* @__PURE__ */ n("label", { className: "text-emphasis mb-2 align-text-top text-sm font-medium", children: a("salesforce_create_record_as") }),
          /* @__PURE__ */ n(
            m,
            {
              className: "mt-2 w-60",
              options: k,
              value: b,
              onChange: (e) => {
                e && (ee(e), t("createEventOn", e.value));
              }
            }
          )
        ] }),
        /* @__PURE__ */ n("div", { className: "mb-4", children: /* @__PURE__ */ n(
          d,
          {
            label: a("salesforce_ignore_guests"),
            labelOnLeading: !0,
            checked: Z,
            onCheckedChange: (e) => {
              t("ignoreGuests", e);
            }
          }
        ) }),
        b.value === c.CONTACT ? /* @__PURE__ */ n("div", { children: /* @__PURE__ */ n(
          d,
          {
            label: a("skip_contact_creation", { appName: "Salesforce" }),
            labelOnLeading: !0,
            checked: $,
            onCheckedChange: (e) => {
              t("skipContactCreation", e);
            }
          }
        ) }) : null,
        b.value === c.LEAD ? /* @__PURE__ */ l("div", { children: [
          /* @__PURE__ */ n(
            d,
            {
              label: a("salesforce_create_event_on_contact"),
              labelOnLeading: !0,
              checked: X,
              onCheckedChange: (e) => {
                t("createEventOnLeadCheckForContact", e);
              }
            }
          ),
          /* @__PURE__ */ n("div", { className: "mt-4", children: /* @__PURE__ */ n(x, {}) })
        ] }) : null,
        b.value === c.ACCOUNT ? /* @__PURE__ */ l(S, { children: [
          /* @__PURE__ */ n("div", { className: "mb-4", children: /* @__PURE__ */ n(x, {}) }),
          /* @__PURE__ */ n("div", { children: /* @__PURE__ */ n(
            d,
            {
              label: a("salesforce_if_account_does_not_exist"),
              labelOnLeading: !0,
              checked: H,
              onCheckedChange: (e) => {
                t("createLeadIfAccountNull", e);
              }
            }
          ) })
        ] }) : null,
        /* @__PURE__ */ l("div", { className: "mt-4", children: [
          /* @__PURE__ */ n(
            d,
            {
              label: a("on_booking_write_to_event_object"),
              labelOnLeading: !0,
              checked: B,
              onCheckedChange: (e) => {
                t("onBookingWriteToEventObject", e);
              }
            }
          ),
          B ? /* @__PURE__ */ l("div", { className: "ml-2 mt-2", children: [
            /* @__PURE__ */ l("div", { className: "grid grid-cols-3 gap-4", children: [
              /* @__PURE__ */ n("div", { children: a("field_name") }),
              /* @__PURE__ */ n("div", { children: a("value") })
            ] }),
            /* @__PURE__ */ l("div", { children: [
              Object.keys(p).map((e) => /* @__PURE__ */ l("div", { className: "mt-2 grid grid-cols-3 gap-4", children: [
                /* @__PURE__ */ n("div", { children: /* @__PURE__ */ n(h, { value: e, readOnly: !0 }) }),
                /* @__PURE__ */ n("div", { children: /* @__PURE__ */ n(h, { value: p[e], readOnly: !0 }) }),
                /* @__PURE__ */ n("div", { children: /* @__PURE__ */ n(
                  f,
                  {
                    StartIcon: "trash",
                    variant: "icon",
                    color: "destructive",
                    onClick: () => {
                      const u = p;
                      delete p[e], t("onBookingWriteToEventObjectMap", u);
                    }
                  }
                ) })
              ] }, e)),
              /* @__PURE__ */ l("div", { className: "mt-2 grid grid-cols-3 gap-4", children: [
                /* @__PURE__ */ n("div", { children: /* @__PURE__ */ n(
                  h,
                  {
                    value: s.field,
                    onChange: (e) => A({
                      ...s,
                      field: e.target.value
                    })
                  }
                ) }),
                /* @__PURE__ */ n("div", { children: /* @__PURE__ */ n(
                  h,
                  {
                    value: s.value,
                    onChange: (e) => A({
                      ...s,
                      value: e.target.value
                    })
                  }
                ) })
              ] })
            ] }),
            /* @__PURE__ */ n(
              f,
              {
                className: "mt-2",
                size: "sm",
                disabled: !(s.field && s.value),
                onClick: () => {
                  if (Object.keys(p).includes(
                    s.field.trim()
                  )) {
                    M("Field already exists", "error");
                    return;
                  }
                  t("onBookingWriteToEventObjectMap", {
                    ...p,
                    [s.field.trim()]: s.value.trim()
                  }), A({ field: "", value: "" });
                },
                children: a("add_new_field")
              }
            )
          ] }) : null
        ] }),
        /* @__PURE__ */ l("div", { className: "mt-4", children: [
          /* @__PURE__ */ n(
            d,
            {
              label: a("salesforce_on_booking_write_to_record", { record: F }),
              labelOnLeading: !0,
              checked: j,
              onCheckedChange: (e) => {
                t("onBookingWriteToRecord", e);
              }
            }
          ),
          j ? /* @__PURE__ */ l("div", { className: "ml-2 mt-2", children: [
            /* @__PURE__ */ l("div", { className: "grid grid-cols-5 gap-4", children: [
              /* @__PURE__ */ n("div", { children: a("field_name") }),
              /* @__PURE__ */ n("div", { children: a("field_type") }),
              /* @__PURE__ */ n("div", { children: a("value") }),
              /* @__PURE__ */ n("div", { children: a("when_to_write") })
            ] }),
            /* @__PURE__ */ l("div", { children: [
              Object.keys(r).map((e) => /* @__PURE__ */ l("div", { className: "mt-2 grid grid-cols-5 gap-4", children: [
                /* @__PURE__ */ n("div", { children: /* @__PURE__ */ n(h, { value: e, readOnly: !0 }) }),
                /* @__PURE__ */ n("div", { children: /* @__PURE__ */ n(
                  m,
                  {
                    value: T.find(
                      (u) => u.value === r[e].fieldType
                    ),
                    isDisabled: !0
                  }
                ) }),
                /* @__PURE__ */ n("div", { children: r[e].fieldType === v.DATE ? /* @__PURE__ */ n(
                  m,
                  {
                    value: w.find(
                      (u) => u.value === r[e].value
                    ),
                    isDisabled: !0
                  }
                ) : /* @__PURE__ */ n(h, { value: r[e].value, readOnly: !0 }) }),
                /* @__PURE__ */ n("div", { children: /* @__PURE__ */ n(
                  m,
                  {
                    value: N.find(
                      (u) => u.value === r[e].whenToWrite
                    ),
                    isDisabled: !0
                  }
                ) }),
                /* @__PURE__ */ n("div", { children: /* @__PURE__ */ n(
                  f,
                  {
                    StartIcon: "trash",
                    variant: "icon",
                    color: "destructive",
                    onClick: () => {
                      const u = r;
                      delete r[e], t("onBookingWriteToRecordFields", u);
                    }
                  }
                ) })
              ] }, e)),
              /* @__PURE__ */ l("div", { className: "mt-2 grid grid-cols-5 gap-4", children: [
                /* @__PURE__ */ n("div", { children: /* @__PURE__ */ n(
                  h,
                  {
                    value: i.field,
                    onChange: (e) => C({
                      ...i,
                      field: e.target.value
                    })
                  }
                ) }),
                /* @__PURE__ */ n("div", { children: /* @__PURE__ */ n(
                  m,
                  {
                    options: T,
                    value: O,
                    onChange: (e) => {
                      e && (ne(e), C({
                        ...i,
                        fieldType: e.value,
                        ...e.value === v.DATE && { value: I.value }
                      }));
                    }
                  }
                ) }),
                /* @__PURE__ */ n("div", { children: O.value === v.DATE ? /* @__PURE__ */ n(
                  m,
                  {
                    options: w,
                    value: I,
                    onChange: (e) => {
                      e && (te(e), C({
                        ...i,
                        value: e.value
                      }));
                    }
                  }
                ) : /* @__PURE__ */ n(
                  h,
                  {
                    value: i.value,
                    onChange: (e) => C({
                      ...i,
                      value: e.target.value
                    })
                  }
                ) }),
                /* @__PURE__ */ n("div", { children: /* @__PURE__ */ n(
                  m,
                  {
                    options: N,
                    value: ae,
                    onChange: (e) => {
                      e && (le(e), C({
                        ...i,
                        whenToWrite: e.value
                      }));
                    }
                  }
                ) })
              ] })
            ] }),
            /* @__PURE__ */ n(
              f,
              {
                className: "mt-2",
                size: "sm",
                disabled: !(i.field && i.fieldType && i.value && i.whenToWrite),
                onClick: () => {
                  if (Object.keys(r).includes(
                    s.field.trim()
                  )) {
                    M("Field already exists", "error");
                    return;
                  }
                  t("onBookingWriteToRecordFields", {
                    ...r,
                    [i.field.trim()]: {
                      fieldType: i.fieldType,
                      value: i.value,
                      whenToWrite: i.whenToWrite
                    }
                  }), C({
                    field: "",
                    fieldType: O.value,
                    value: "",
                    whenToWrite: _.FIELD_EMPTY
                  });
                },
                children: a("add_new_field")
              }
            )
          ] }) : null
        ] }),
        /* @__PURE__ */ n("div", { className: "mt-4", children: /* @__PURE__ */ n(
          d,
          {
            label: "Change record owner on booking",
            labelOnLeading: !0,
            checked: L,
            onCheckedChange: (e) => {
              t("onBookingChangeRecordOwner", e);
            }
          }
        ) }),
        L ? /* @__PURE__ */ l("div", { className: "ml-2 mt-2", children: [
          /* @__PURE__ */ n("p", { className: "mb-2", children: a("salesforce_owner_name_to_change") }),
          /* @__PURE__ */ n(
            h,
            {
              value: q,
              onChange: (e) => t("onBookingChangeRecordOwnerName", e.target.value)
            }
          )
        ] }) : null,
        R.schedulingType === he.ROUND_ROBIN ? /* @__PURE__ */ l("div", { className: "mt-4", children: [
          /* @__PURE__ */ n(
            d,
            {
              label: a("salesforce_book_directly_with_attendee_owner"),
              labelOnLeading: !0,
              checked: D,
              onCheckedChange: (e) => {
                t("roundRobinLeadSkip", e), e && t("enabled", e);
              }
            }
          ),
          D ? /* @__PURE__ */ l(S, { children: [
            /* @__PURE__ */ l("div", { className: "my-4 ml-2", children: [
              /* @__PURE__ */ n("label", { className: "text-emphasis mb-2 align-text-top text-sm font-medium", children: a("salesforce_check_owner_of") }),
              /* @__PURE__ */ n(
                m,
                {
                  className: "mt-2 w-60",
                  options: E,
                  value: oe,
                  onChange: (e) => {
                    e && (ie(e), t("roundRobinSkipCheckRecordOn", e.value));
                  }
                }
              )
            ] }),
            /* @__PURE__ */ n("div", { className: "my-4", children: /* @__PURE__ */ n(
              d,
              {
                label: a("salesforce_if_free_email_domain_skip_owner_check"),
                labelOnLeading: !0,
                checked: z,
                onCheckedChange: (e) => {
                  t("ifFreeEmailDomainSkipOwnerCheck", e);
                }
              }
            ) })
          ] }) : null,
          /* @__PURE__ */ n(ue, { className: "mt-2", severity: "neutral", title: a("skip_rr_description") })
        ] }) : null,
        /* @__PURE__ */ l("div", { className: "ml-2 mt-4", children: [
          /* @__PURE__ */ n(
            d,
            {
              label: "Send no show attendee data to event object",
              checked: y,
              onCheckedChange: (e) => {
                t("sendNoShowAttendeeData", e);
              }
            }
          ),
          y ? /* @__PURE__ */ l("div", { className: "mt-2", children: [
            /* @__PURE__ */ n("p", { className: "mb-2", children: "Field name to check (must be checkbox data type)" }),
            /* @__PURE__ */ n(
              h,
              {
                value: Q,
                onChange: (e) => t("sendNoShowAttendeeDataField", e.target.value)
              }
            )
          ] }) : null
        ] })
      ] })
    }
  );
};
export {
  ke as default
};
