import { r as V, Y as d, Z as I, _ as H, q as e, p as u, I as x, S as m, s as A, $ as Y, t as se, v as te, a0 as r, W as oe, L as K, a1 as ie, y as ce } from "./index-jYYVpIDL.js";
import { useState as p } from "react";
import { S as a, A as de } from "./AppCard-pSUVQRE0.js";
import { u as re } from "./useIsAppEnabled-Tvqt7uu5.js";
var U = /* @__PURE__ */ ((j) => (j.ON_BOOKING = "on_booking", j.ON_CANCEL = "on_cancel", j))(U || {});
const X = ({
  bookingAction: j,
  optionLabel: N,
  optionEnabled: g,
  optionSwitchOnChange: R,
  writeToObjectData: s,
  updateWriteToObjectData: t
}) => {
  const { t: c } = V(), S = [
    { label: c("text"), value: d.TEXT },
    { label: c("date"), value: d.DATE },
    { label: c("phone").charAt(0).toUpperCase() + c("phone").slice(1), value: d.PHONE },
    { label: c("checkbox"), value: d.CHECKBOX },
    { label: c("picklist"), value: d.PICKLIST },
    { label: c("custom"), value: d.CUSTOM }
  ], _ = [
    { label: c("only_if_field_is_empty"), value: I.FIELD_EMPTY },
    ...j === "on_cancel" ? [{ label: c("salesforce_on_every_cancellation"), value: I.EVERY_BOOKING }] : [{ label: c("on_every_booking"), value: I.EVERY_BOOKING }]
  ], C = [
    { label: c("true"), value: !0 },
    { label: c("false"), value: !1 }
  ], k = [
    ...j === "on_cancel" ? [{ label: c("booking_cancel_date"), value: H.BOOKING_CANCEL_DATE }] : [],
    { label: c("booking_start_date"), value: H.BOOKING_START_DATE },
    { label: c("booking_created_date"), value: H.BOOKING_CREATED_DATE }
  ], [w, W] = p(S[0]), [T, z] = p(k[0]), [O, E] = p(
    C[0]
  ), [v, y] = p(_[0]), [i, f] = p({
    field: "",
    fieldType: w.value,
    value: "",
    whenToWrite: v.value
  });
  return /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
    /* @__PURE__ */ e.jsx(a.SubSectionHeader, { icon: "star", labelFor: "write-to-object-settings", title: N, children: /* @__PURE__ */ e.jsx(
      u,
      {
        checked: g,
        onCheckedChange: R,
        id: "write-to-object-settings",
        size: "sm"
      }
    ) }),
    g ? /* @__PURE__ */ e.jsxs(a.SubSectionContent, { children: [
      /* @__PURE__ */ e.jsxs("div", { className: "text-subtle flex gap-3 px-3 py-[6px] text-sm font-medium", children: [
        /* @__PURE__ */ e.jsx("div", { className: "flex-1", children: c("field_name") }),
        /* @__PURE__ */ e.jsx("div", { className: "flex-1", children: c("field_type") }),
        /* @__PURE__ */ e.jsx("div", { className: "flex-1", children: c("value") }),
        /* @__PURE__ */ e.jsx("div", { className: "flex-1", children: c("when_to_write") }),
        /* @__PURE__ */ e.jsx("div", { className: "w-10" })
      ] }),
      /* @__PURE__ */ e.jsxs(a.SubSectionNested, { children: [
        Object.keys(s).map((l) => /* @__PURE__ */ e.jsxs("div", { className: "flex items-center gap-2", children: [
          /* @__PURE__ */ e.jsx("div", { className: "flex-1", children: /* @__PURE__ */ e.jsx(x, { value: l, readOnly: !0, size: "sm", className: "w-full" }) }),
          /* @__PURE__ */ e.jsx("div", { className: "flex-1", children: /* @__PURE__ */ e.jsx(
            m,
            {
              size: "sm",
              className: "w-full",
              value: S.find(
                (h) => h.value === s[l].fieldType
              ),
              isDisabled: !0
            }
          ) }),
          /* @__PURE__ */ e.jsx("div", { className: "flex-1", children: s[l].fieldType === d.DATE ? /* @__PURE__ */ e.jsx(
            m,
            {
              size: "sm",
              className: "w-full",
              value: k.find(
                (h) => h.value === s[l].value
              ),
              isDisabled: !0
            }
          ) : s[l].fieldType === d.CHECKBOX ? /* @__PURE__ */ e.jsx(
            m,
            {
              size: "sm",
              className: "w-full",
              value: C.find(
                (h) => h.value === s[l].value
              ),
              isDisabled: !0
            }
          ) : /* @__PURE__ */ e.jsx(
            x,
            {
              value: s[l].value,
              readOnly: !0,
              size: "sm",
              className: "w-full"
            }
          ) }),
          /* @__PURE__ */ e.jsx("div", { className: "flex-1", children: /* @__PURE__ */ e.jsx(
            m,
            {
              size: "sm",
              className: "w-full",
              value: _.find(
                (h) => h.value === s[l].whenToWrite
              ),
              isDisabled: !0
            }
          ) }),
          /* @__PURE__ */ e.jsx("div", { className: "flex w-10 justify-center", children: /* @__PURE__ */ e.jsx(
            A,
            {
              size: "sm",
              StartIcon: "x",
              variant: "icon",
              color: "minimal",
              onClick: () => {
                const h = s;
                delete s[l], t(h);
              }
            }
          ) })
        ] }, l)),
        /* @__PURE__ */ e.jsxs("div", { className: "flex gap-2", children: [
          /* @__PURE__ */ e.jsx("div", { className: "flex-1", children: /* @__PURE__ */ e.jsx(
            x,
            {
              size: "sm",
              className: "w-full",
              value: i.field,
              onChange: (l) => f({
                ...i,
                field: l.target.value
              })
            }
          ) }),
          /* @__PURE__ */ e.jsx("div", { className: "flex-1", children: /* @__PURE__ */ e.jsx(
            m,
            {
              size: "sm",
              className: "w-full",
              options: S,
              value: w,
              onChange: (l) => {
                l && (W(l), f({
                  ...i,
                  fieldType: l.value,
                  ...l.value === d.DATE && { value: T.value },
                  ...l.value === d.CHECKBOX && {
                    value: O.value
                  }
                }));
              }
            }
          ) }),
          /* @__PURE__ */ e.jsx("div", { className: "flex-1", children: i.fieldType === d.DATE ? /* @__PURE__ */ e.jsx(
            m,
            {
              size: "sm",
              className: "w-full",
              options: k,
              value: T,
              onChange: (l) => {
                l && (z(l), f({
                  ...i,
                  value: l.value
                }));
              }
            }
          ) : i.fieldType === d.CHECKBOX ? /* @__PURE__ */ e.jsx(
            m,
            {
              size: "sm",
              className: "w-full",
              options: C,
              value: O,
              onChange: (l) => {
                l && (E(l), f({
                  ...i,
                  value: l.value
                }));
              }
            }
          ) : /* @__PURE__ */ e.jsx(
            x,
            {
              size: "sm",
              className: "w-full",
              value: i.value,
              onChange: (l) => f({
                ...i,
                value: l.target.value
              })
            }
          ) }),
          /* @__PURE__ */ e.jsx("div", { className: "flex-1", children: /* @__PURE__ */ e.jsx(
            m,
            {
              size: "sm",
              className: "w-full",
              options: _,
              value: v,
              onChange: (l) => {
                l && (y(l), f({
                  ...i,
                  whenToWrite: l.value
                }));
              }
            }
          ) }),
          /* @__PURE__ */ e.jsx("div", { className: "w-10" })
        ] })
      ] }),
      /* @__PURE__ */ e.jsx(
        A,
        {
          className: "text-subtle mt-2 w-fit",
          StartIcon: "plus",
          color: "minimal",
          size: "sm",
          disabled: !(i.field && i.fieldType && i.value !== "" && i.whenToWrite),
          onClick: () => {
            if (Object.keys(s).includes(i.field.trim())) {
              Y("Field already exists", "error");
              return;
            }
            t({
              ...s,
              [i.field.trim()]: {
                fieldType: i.fieldType,
                value: i.value,
                whenToWrite: i.whenToWrite
              }
            }), f({
              field: "",
              fieldType: S[0].value,
              value: "",
              whenToWrite: _[0].value
            });
          },
          children: c("add_new_field")
        }
      )
    ] }) : null
  ] });
}, ve = function({ app: N, eventType: g }) {
  var P;
  const R = se.usePathname(), { getAppData: s, setAppData: t, disabled: c } = te(), { enabled: S, updateEnabled: _ } = re(N), C = s("roundRobinLeadSkip"), k = s("roundRobinSkipCheckRecordOn") ?? r.CONTACT, w = s("ifFreeEmailDomainSkipOwnerCheck") ?? !1, W = s("skipContactCreation"), T = s("createLeadIfAccountNull"), z = s("createNewContactUnderAccount"), O = s("createEventOn") ?? r.CONTACT, E = s("onBookingWriteToEventObject") ?? !1, v = s("onBookingWriteToEventObjectMap") ?? {}, y = s("createEventOnLeadCheckForContact") ?? !1, i = s("onBookingChangeRecordOwner") ?? !1, f = s("onBookingChangeRecordOwnerName") ?? [], l = s("sendNoShowAttendeeData") ?? !1, h = s("sendNoShowAttendeeDataField") ?? "", $ = s("onBookingWriteToRecord") ?? !1, q = s("onBookingWriteToRecordFields") ?? {}, Z = s("ignoreGuests") ?? !1, J = s("roundRobinSkipFallbackToLeadOwner") ?? !1, Q = s("onCancelWriteToEventRecord") ?? !1, ee = s("onCancelWriteToEventRecordFields") ?? {}, { t: o } = V(), B = [
    { label: o("contact"), value: r.CONTACT },
    { label: o("salesforce_lead"), value: r.LEAD },
    { label: o("salesforce_contact_under_account"), value: r.ACCOUNT }
  ], [F, ne] = p(
    B.find((n) => n.value === O) ?? B[0]
  ), L = [
    { label: o("contact"), value: r.CONTACT },
    { label: o("salesforce_lead"), value: r.LEAD },
    { label: o("account"), value: r.ACCOUNT }
  ], [G, le] = p(
    L.find((n) => n.value === k) ?? L[0]
  ), [b, D] = p({
    field: "",
    value: ""
  }), M = () => /* @__PURE__ */ e.jsx(a.SubSection, { children: /* @__PURE__ */ e.jsx(
    a.SubSectionHeader,
    {
      icon: "at-sign",
      title: o("salesforce_create_new_contact_under_account"),
      labelFor: "create-new-contact-under-account",
      children: /* @__PURE__ */ e.jsx(
        u,
        {
          size: "sm",
          labelOnLeading: !0,
          checked: z,
          onCheckedChange: (n) => {
            t("createNewContactUnderAccount", n);
          }
        }
      )
    }
  ) });
  return /* @__PURE__ */ e.jsx(
    de,
    {
      returnTo: `${oe}${R}?tabName=apps`,
      app: N,
      teamId: ((P = g.team) == null ? void 0 : P.id) || void 0,
      switchOnClick: (n) => {
        _(n);
      },
      switchChecked: S,
      hideSettingsIcon: !0,
      children: /* @__PURE__ */ e.jsxs(a.Content, { children: [
        /* @__PURE__ */ e.jsx(a.SubSection, { children: /* @__PURE__ */ e.jsx(
          a.SubSectionHeader,
          {
            icon: "zap",
            title: o("salesforce_add_attendees_as"),
            justify: "start",
            labelFor: "add-attendees-as",
            children: /* @__PURE__ */ e.jsx(
              m,
              {
                size: "sm",
                id: "add-attendees-as",
                className: "w-[200px]",
                options: B,
                value: F,
                onChange: (n) => {
                  n && (ne(n), t("createEventOn", n.value));
                }
              }
            )
          }
        ) }),
        /* @__PURE__ */ e.jsx(a.SubSection, { children: /* @__PURE__ */ e.jsx(
          a.SubSectionHeader,
          {
            icon: "user-plus",
            title: o("salesforce_ignore_guests"),
            labelFor: "ignore-guests",
            children: /* @__PURE__ */ e.jsx(
              u,
              {
                size: "sm",
                labelOnLeading: !0,
                checked: Z,
                onCheckedChange: (n) => {
                  t("ignoreGuests", n);
                }
              }
            )
          }
        ) }),
        F.value === r.CONTACT ? /* @__PURE__ */ e.jsx(a.SubSection, { children: /* @__PURE__ */ e.jsx(
          a.SubSectionHeader,
          {
            icon: "user-plus",
            title: o("skip_contact_creation", { appName: "Salesforce" }),
            labelFor: "skip-contact-creation",
            children: /* @__PURE__ */ e.jsx(
              u,
              {
                size: "sm",
                labelOnLeading: !0,
                checked: W,
                onCheckedChange: (n) => {
                  t("skipContactCreation", n);
                }
              }
            )
          }
        ) }) : null,
        F.value === r.LEAD ? /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
          /* @__PURE__ */ e.jsx(a.SubSection, { children: /* @__PURE__ */ e.jsx(
            a.SubSectionHeader,
            {
              icon: "user-plus",
              title: o("salesforce_create_event_on_contact"),
              labelFor: "create-event-on-contact",
              children: /* @__PURE__ */ e.jsx(
                u,
                {
                  size: "sm",
                  labelOnLeading: !0,
                  checked: y,
                  onCheckedChange: (n) => {
                    t("createEventOnLeadCheckForContact", n);
                  }
                }
              )
            }
          ) }),
          /* @__PURE__ */ e.jsx(M, {})
        ] }) : null,
        F.value === r.ACCOUNT ? /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
          /* @__PURE__ */ e.jsx(M, {}),
          /* @__PURE__ */ e.jsx(a.SubSection, { children: /* @__PURE__ */ e.jsx(
            a.SubSectionHeader,
            {
              icon: "user-plus",
              title: o("salesforce_if_account_does_not_exist"),
              labelFor: "create-lead-if-account-null",
              children: /* @__PURE__ */ e.jsx(
                u,
                {
                  size: "sm",
                  labelOnLeading: !0,
                  checked: T,
                  onCheckedChange: (n) => {
                    t("createLeadIfAccountNull", n);
                  }
                }
              )
            }
          ) })
        ] }) : null,
        /* @__PURE__ */ e.jsxs(a.SubSection, { children: [
          /* @__PURE__ */ e.jsx(a.SubSectionHeader, { icon: "badge-check", title: o("on_booking_write_to_event_object"), children: /* @__PURE__ */ e.jsx(
            u,
            {
              size: "sm",
              labelOnLeading: !0,
              checked: E,
              onCheckedChange: (n) => {
                t("onBookingWriteToEventObject", n);
              }
            }
          ) }),
          E ? /* @__PURE__ */ e.jsxs(a.SubSectionContent, { children: [
            /* @__PURE__ */ e.jsxs("div", { className: "text-subtle flex gap-3 px-3 py-[6px] text-sm font-medium", children: [
              /* @__PURE__ */ e.jsx("div", { className: "flex-1", children: o("field_name") }),
              /* @__PURE__ */ e.jsx("div", { className: "flex-1", children: o("value") }),
              /* @__PURE__ */ e.jsx("div", { className: "w-10" })
            ] }),
            /* @__PURE__ */ e.jsxs(a.SubSectionNested, { children: [
              Object.keys(v).map((n) => /* @__PURE__ */ e.jsxs("div", { className: "flex items-center gap-2", children: [
                /* @__PURE__ */ e.jsx("div", { className: "flex-1", children: /* @__PURE__ */ e.jsx(x, { value: n, readOnly: !0, size: "sm", className: "w-full" }) }),
                /* @__PURE__ */ e.jsx("div", { className: "flex-1", children: /* @__PURE__ */ e.jsx(
                  x,
                  {
                    value: v[n],
                    readOnly: !0,
                    size: "sm",
                    className: "w-full"
                  }
                ) }),
                /* @__PURE__ */ e.jsx("div", { className: "flex w-10 justify-center", children: /* @__PURE__ */ e.jsx(
                  A,
                  {
                    StartIcon: "x",
                    variant: "icon",
                    size: "sm",
                    color: "minimal",
                    onClick: () => {
                      const ae = v;
                      delete v[n], t("onBookingWriteToEventObjectMap", ae);
                    }
                  }
                ) })
              ] }, n)),
              /* @__PURE__ */ e.jsxs("div", { className: "mt-2 flex gap-4", children: [
                /* @__PURE__ */ e.jsx("div", { className: "flex-1", children: /* @__PURE__ */ e.jsx(
                  x,
                  {
                    size: "sm",
                    className: "w-full",
                    value: b.field,
                    onChange: (n) => D({
                      ...b,
                      field: n.target.value
                    })
                  }
                ) }),
                /* @__PURE__ */ e.jsx("div", { className: "flex-1", children: /* @__PURE__ */ e.jsx(
                  x,
                  {
                    size: "sm",
                    className: "w-full",
                    value: b.value,
                    onChange: (n) => D({
                      ...b,
                      value: n.target.value
                    })
                  }
                ) }),
                /* @__PURE__ */ e.jsx("div", { className: "w-10" })
              ] })
            ] }),
            /* @__PURE__ */ e.jsx(
              A,
              {
                className: "text-subtle mt-2 w-fit",
                size: "sm",
                color: "secondary",
                disabled: !(b.field && b.value),
                onClick: () => {
                  if (Object.keys(v).includes(
                    b.field.trim()
                  )) {
                    Y("Field already exists", "error");
                    return;
                  }
                  t("onBookingWriteToEventObjectMap", {
                    ...v,
                    [b.field.trim()]: b.value.trim()
                  }), D({ field: "", value: "" });
                },
                children: o("add_new_field")
              }
            )
          ] }) : null
        ] }),
        /* @__PURE__ */ e.jsx(a.SubSection, { children: /* @__PURE__ */ e.jsx(
          X,
          {
            bookingAction: U.ON_BOOKING,
            optionLabel: o("salesforce_on_booking_write_to_record", { record: O }),
            optionEnabled: $,
            writeToObjectData: q,
            optionSwitchOnChange: (n) => {
              t("onBookingWriteToRecord", n);
            },
            updateWriteToObjectData: (n) => t("onBookingWriteToRecordFields", n)
          }
        ) }),
        /* @__PURE__ */ e.jsxs(a.SubSection, { children: [
          /* @__PURE__ */ e.jsx(
            a.SubSectionHeader,
            {
              icon: "user-plus",
              title: o("salesforce_change_record_owner_on_booking"),
              labelFor: "change-record-owner-on-booking",
              children: /* @__PURE__ */ e.jsx(
                u,
                {
                  size: "sm",
                  labelOnLeading: !0,
                  checked: i,
                  onCheckedChange: (n) => {
                    t("onBookingChangeRecordOwner", n);
                  }
                }
              )
            }
          ),
          i ? /* @__PURE__ */ e.jsx(a.SubSectionContent, { classNames: { container: "p-3" }, children: /* @__PURE__ */ e.jsxs("div", { children: [
            /* @__PURE__ */ e.jsx(
              K,
              {
                htmlFor: "on-booking-change-record-owner-name",
                className: "text-subtle text-sm font-medium",
                children: o("salesforce_owner_name_to_change")
              }
            ),
            /* @__PURE__ */ e.jsx(
              x,
              {
                id: "on-booking-change-record-owner-name",
                size: "sm",
                value: f,
                onChange: (n) => t("onBookingChangeRecordOwnerName", n.target.value)
              }
            )
          ] }) }) : null
        ] }),
        g.schedulingType === ie.ROUND_ROBIN ? /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
          /* @__PURE__ */ e.jsxs(a.SubSection, { children: [
            /* @__PURE__ */ e.jsx(
              a.SubSectionHeader,
              {
                icon: "users",
                title: o("salesforce_book_directly_with_attendee_owner"),
                labelFor: "book-directly-with-attendee-owner",
                children: /* @__PURE__ */ e.jsx(
                  u,
                  {
                    size: "sm",
                    id: "book-directly-witha-attendee-owner",
                    checked: C,
                    onCheckedChange: (n) => {
                      t("roundRobinLeadSkip", n), n && t("enabled", n);
                    }
                  }
                )
              }
            ),
            C ? /* @__PURE__ */ e.jsx(a.SubSectionContent, { classNames: { container: "p-3" }, children: /* @__PURE__ */ e.jsxs("div", { children: [
              /* @__PURE__ */ e.jsx(
                K,
                {
                  htmlFor: "round-robin-skip-check-record-on",
                  className: "text-subtle text-sm font-medium",
                  children: o("salesforce_check_owner_of")
                }
              ),
              /* @__PURE__ */ e.jsx(
                m,
                {
                  size: "sm",
                  className: "w-60",
                  options: L,
                  value: G,
                  onChange: (n) => {
                    n && (le(n), t("roundRobinSkipCheckRecordOn", n.value));
                  }
                }
              )
            ] }) }) : null
          ] }),
          /* @__PURE__ */ e.jsx(e.Fragment, { children: C ? /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
            G.value === r.CONTACT ? /* @__PURE__ */ e.jsx(a.SubSection, { children: /* @__PURE__ */ e.jsx(
              a.SubSectionHeader,
              {
                icon: "users",
                title: o("salesforce_round_robin_skip_fallback_to_lead_owner"),
                labelFor: "round-robin-skip-fallback-to-lead-owner",
                children: /* @__PURE__ */ e.jsx(
                  u,
                  {
                    id: "round-robin-skip-fallback-to-lead-owner",
                    size: "sm",
                    checked: J,
                    onCheckedChange: (n) => {
                      t("roundRobinSkipFallbackToLeadOwner", n);
                    }
                  }
                )
              }
            ) }) : null,
            /* @__PURE__ */ e.jsxs(a.SubSection, { children: [
              /* @__PURE__ */ e.jsx(
                a.SubSectionHeader,
                {
                  icon: "users",
                  title: o("salesforce_if_free_email_domain_skip_owner_check"),
                  labelFor: "if-free-email-domain-skip-owner-check",
                  children: /* @__PURE__ */ e.jsx(
                    u,
                    {
                      id: "if-free-email-domain-skip-owner-check",
                      size: "sm",
                      checked: w,
                      onCheckedChange: (n) => {
                        t("ifFreeEmailDomainSkipOwnerCheck", n);
                      }
                    }
                  )
                }
              ),
              /* @__PURE__ */ e.jsx(ce, { severity: "info", title: o("skip_rr_description") })
            ] })
          ] }) : null })
        ] }) : null,
        /* @__PURE__ */ e.jsx(a.SubSection, { children: /* @__PURE__ */ e.jsx(
          X,
          {
            bookingAction: U.ON_CANCEL,
            optionLabel: o("salesforce_on_cancel_write_to_event"),
            optionEnabled: Q,
            writeToObjectData: ee,
            optionSwitchOnChange: (n) => {
              t("onCancelWriteToEventRecord", n);
            },
            updateWriteToObjectData: (n) => t("onCancelWriteToEventRecordFields", n)
          }
        ) }),
        /* @__PURE__ */ e.jsxs(a.SubSection, { children: [
          /* @__PURE__ */ e.jsx(
            a.SubSectionHeader,
            {
              icon: "calendar",
              title: "Send no show attendee data to event object",
              labelFor: "send-no-show-attendee-data",
              children: /* @__PURE__ */ e.jsx(
                u,
                {
                  id: "send-no-show-attendee-data",
                  size: "sm",
                  checked: l,
                  onCheckedChange: (n) => {
                    t("sendNoShowAttendeeData", n);
                  }
                }
              )
            }
          ),
          l ? /* @__PURE__ */ e.jsxs(a.SubSectionContent, { classNames: { container: "p-3" }, children: [
            /* @__PURE__ */ e.jsx(
              K,
              {
                htmlFor: "send-no-show-attendee-data-field-name",
                className: "text-subtle text-sm font-medium",
                children: "Field name to check (must be checkbox data type)"
              }
            ),
            /* @__PURE__ */ e.jsx(
              x,
              {
                id: "send-no-show-attendee-data-field-name",
                size: "sm",
                value: h,
                onChange: (n) => t("sendNoShowAttendeeDataField", n.target.value)
              }
            )
          ] }) : null
        ] })
      ] })
    }
  );
};
export {
  ve as default
};
