@planningcenter/core-automations 1.9.0 → 1.9.1-qa-344.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- import{jsxs as e,jsx as t,Fragment as n}from"react/jsx-runtime";import{Client as a}from"@planningcenter/api-client";import{StackView as i,Heading as o,Text as r,Box as s,Input as l,Select as c,Button as d,DataTable as u,Alert as p,Link as m,Badge as h,Icon as g,ThemeProvider as w,Modal as f,Card as b,Dropdown as v,Tooltip as x,Divider as y,Avatar as k,Summary as C,Spinner as z,TileView as _,HelperDrawer as S,Combobox as O,Highlight as A,Menu as $,Checkbox as L,TextArea as P,DateField as F,NumberField as T,Radio as I}from"@planningcenter/tapestry-react";import D,{createContext as H,useContext as j,useState as W,useEffect as V,useCallback as B,useMemo as R,useRef as N}from"react";import{isBoolean as M,camelCase as E,lowerFirst as Y,truncate as U,compact as q,uniq as Z,upperFirst as X,uniqBy as Q,groupBy as G,isEqual as J,sortBy as K,debounce as ee,cloneDeep as te,set as ne}from"lodash";import ae from"moment";import{standardAlertOptions as ie,successAlertOptions as oe,errorAlertOptions as re,standardConfirmOptions as se,destroyConfirmOptions as le,createConfirmOptions as ce}from"@planningcenter/sweetalert2";import de from"sweetalert2/dist/sweetalert2";import*as ue from"@planningcenter/icons/paths/church-center";import*as pe from"@planningcenter/icons/paths/logomark";import*as me from"@planningcenter/icons/paths/services";import{createPortal as he}from"react-dom";function ge(){return ge=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e},ge.apply(this,arguments)}function we(e,t){if(null==e)return{};var n,a,i={},o=Object.keys(e);for(a=0;a<o.length;a++)t.indexOf(n=o[a])>=0||(i[n]=e[n]);return i}const fe=()=>e("svg",{id:"automations_blank","data-name":"Automations Blank",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 111.112 84.832",className:"symbol",children:[t("title",{children:"people-automations"}),t("g",{opacity:"0.6",children:t("path",{d:"M107.784,46.051A57.416,57.416,0,0,1,85.26,75.058c-9.7,6.247-20.045,7.792-31.912,5.185-11.74-2.638-23.339-8-32.92-13.088-9.51-5.342-17-10.236-18.863-17.925C-.26,41.753,3.737,31.4,13.347,21.194,22.85,11.162,37.968,1.853,55.948.321,73.8-1.476,90.2,4.478,99.608,13.164,109.257,21.9,111.921,33.784,107.784,46.051Z",fill:"#e1f0f9"})}),e("g",{opacity:"0.2",children:[t("path",{d:"M63.086,84.317A43.515,43.515,0,0,1,42.87,79C34.056,74.379,24.712,67.422,14.3,57.728,6.616,50.227.284,43.348.489,35c.13-5.851,3.789-12.312,10.3-18.189l.951,1.054c-6.222,5.613-9.715,11.71-9.837,17.169C1.717,42.811,7.85,49.448,15.278,56.7c10.307,9.6,19.551,16.481,28.248,21.039,9.043,4.684,17.715,6.156,26.513,4.5l.262,1.4A38.914,38.914,0,0,1,63.086,84.317Z",fill:"#bac7d3"}),t("path",{d:"M81.105,80.147l-.587-1.292a56.6,56.6,0,0,0,23.515-19.828l1.183.786A58.03,58.03,0,0,1,81.105,80.147Z",fill:"#bac7d3"}),t("path",{d:"M110.025,49.27l-1.374-.356a28.351,28.351,0,0,0-4.014-22.991C97.189,14.135,82.488,5.177,66.267,2.538A66.6,66.6,0,0,0,25.738,8.55l-.622-1.275a68,68,0,0,1,41.39-6.136c16.6,2.7,31.672,11.905,39.327,24.019A29.732,29.732,0,0,1,110.025,49.27Z",fill:"#bac7d3"})]}),t("path",{d:"M81,27.269v31.8a2.685,2.685,0,0,1-2.685,2.685H44.564a2.685,2.685,0,0,1-2.685-2.685V15.425a2.685,2.685,0,0,1,2.685-2.685h21.91a2.681,2.681,0,0,1,1.9.786L80.217,25.371A2.685,2.685,0,0,1,81,27.269Z",fill:"#fff"}),t("path",{d:"M68.479,13.633v9.8a2.035,2.035,0,0,0,2.035,2.034h9.877Z",fill:"#c9d8e2"}),t("rect",{x:"51.214",y:"41.285",width:"20.221",height:"2.791",rx:"1.395",ry:"1.395",fill:"#dae5ed"}),t("rect",{x:"51.214",y:"48.434",width:"20.221",height:"2.791",rx:"1.395",ry:"1.395",fill:"#dae5ed"}),t("rect",{x:"51.214",y:"34.136",width:"20.221",height:"2.791",rx:"1.395",ry:"1.395",fill:"#dae5ed"}),t("rect",{x:"11.771",y:"44.005",width:"50.915",height:"6.664",transform:"translate(-22.93 44.557) rotate(-49.171)",fill:"#454942"}),t("path",{d:"M56.283,30.38l-7.557,8.745a5.968,5.968,0,0,0-2.005-2.734,6.292,6.292,0,0,0-3.036-1.624l7.555-8.743a6.275,6.275,0,0,1,3.038,1.624A5.959,5.959,0,0,1,56.283,30.38Z",fill:"#fcc846"}),t("path",{d:"M58.088,28.29l-7.556,8.745a5.968,5.968,0,0,0-2-2.734,6.3,6.3,0,0,0-3.036-1.624l7.555-8.743a6.274,6.274,0,0,1,3.037,1.624A5.959,5.959,0,0,1,58.088,28.29Z",fill:"#48a5e5"}),t("path",{d:"M58.724,10.432l1.17,2.7a2.129,2.129,0,0,0,1.4,1.207l2.843.765a.73.73,0,0,1,.1,1.375l-2.7,1.17a2.125,2.125,0,0,0-1.207,1.4L59.56,21.89a.73.73,0,0,1-1.374.1l-1.17-2.7a2.125,2.125,0,0,0-1.4-1.206l-2.843-.766a.73.73,0,0,1-.1-1.374l2.7-1.17a2.121,2.121,0,0,0,1.206-1.4l.766-2.844A.73.73,0,0,1,58.724,10.432Z",fill:"#fcc846"}),t("path",{d:"M44.544,19.294l1.024.868a.968.968,0,0,0,.814.21l1.316-.261a.333.333,0,0,1,.319.541l-.868,1.024a.968.968,0,0,0-.21.814l.261,1.316a.333.333,0,0,1-.541.319l-1.024-.868a.968.968,0,0,0-.814-.21l-1.316.261a.333.333,0,0,1-.319-.541l.868-1.024a.967.967,0,0,0,.21-.814L44,19.613A.333.333,0,0,1,44.544,19.294Z",fill:"#fcc846"}),t("path",{d:"M64.223,25.729l.869,2.005a1.575,1.575,0,0,0,1.036.895l2.109.568a.542.542,0,0,1,.075,1.02l-2,.868a1.576,1.576,0,0,0-.9,1.036l-.568,2.11a.541.541,0,0,1-1.019.074L62.955,32.3a1.572,1.572,0,0,0-1.036-.895l-2.109-.568a.542.542,0,0,1-.075-1.02l2.005-.868a1.572,1.572,0,0,0,.895-1.036L63.2,25.8A.541.541,0,0,1,64.223,25.729Z",fill:"#fcc846"})]}),be=/*#__PURE__*/H({dateFormat:null,olsonTimeZone:null,twentyFourHourTime:null});de.mixin(ie),de.mixin(oe);const ve=de.mixin(re),xe=de.mixin(se),ye=de.mixin(le),ke=de.mixin(ce),Ce={churchCenter:ue,logomark:pe,services:me},ze={givingBrand31:"hsl(36, 100%, 31%)",neutral12:"hsl(0, 0%, 12%)",neutral24:"hsl(0, 0%, 24%)",neutral45:"hsl(0, 0%, 45%)",neutral62:"hsl(0, 0%, 62%)",neutral68:"hsl(0, 0%, 68%)",neutral88:"hsl(0, 0%, 88%)",neutral98:"hsl(0, 0%, 98%)",statusCreate23:"hsl(86, 91%, 23%)",statusCreate27:"hsl(86, 91%, 27%)",statusCreate35:"hsl(86, 91%, 35%)",statusDelete43:"hsl(9, 61%, 43%)",statusDelete47:"hsl(8, 60%, 47%)",statusWarning49:"hsl(42, 84%, 49%)",statusWarning63:"hsl(42, 84%, 63%)",statusWarning94:"hsl(42, 87%, 94%)"};async function _e(e){return Promise.all(e.map(async e=>(function(e){return["AddToWorkflowOperationDefinition","CustomFieldBooleanOperationDefinition","CustomFieldCheckboxesOperationDefinition","CustomFieldDateOperationDefinition","CustomFieldNumberOperationDefinition","CustomFieldSelectOperationDefinition","CustomFieldStringOperationDefinition","CustomFieldTextOperationDefinition"].includes(e.operationDefinitionClassName)}(e)&&(e.description=await async function(e){let t="";if("AddToWorkflowOperationDefinition"===e.operationDefinitionClassName){const n=await async function(e){const{data:t}=await Oe.get({data:{fields:{Workflow:"name"}},url:`workflows/${e}`}).catch(()=>({data:{name:""}}));return t}(e.operationParams.workflowId);n.name&&(t=e.description.replace("[Hidden Workflow]",n.name))}else{const n=e.operationParams.definitionIdentifier.match(/(\d+)_field_definition/)[1],a=await async function(e){const{data:t}=await Oe.get({data:{fields:{FieldDefinition:"name,data_type,field_options",FieldOption:"value"},include:"field_options"},url:`field_definitions/${e}`}).catch(()=>({data:{name:""}}));return t}(n);a.name&&(t=e.description.replace("[Hidden Custom Field]",a.name),t+=e.operationParams.values||"checkboxes"!==a.dataType?` (${function(e,t){var n,a;switch(t.dataType){case"checkboxes":return Object.entries(e.operationParams.values).map(([e,n])=>{var a;const i=(null==(a=t.fieldOptions.find(t=>t.id===parseInt(e,10)))?void 0:a.value)||"[Hidden value]";return`${Se(n)} ${i}`}).join(", ");case"select":return e.operationParams.value?(null==(n=t.fieldOptions.find(t=>t.id===parseInt(e.operationParams.value.toString(),10)))?void 0:n.value)||"[Hidden value]":"Unanswered";case"boolean":switch(e.operationParams.value){case"true":return"Yes";case"false":return"No";default:return"Unanswered"}default:return null!=(a=e.operationParams.value)?a:"Unanswered"}}(e,a)})`:"")}return t||e.description}(e)),e)))}function Se(e){return e.charAt(0).toUpperCase()+e.slice(1)}const Oe=new a({app:"people",version:"2022-07-14"});function Ae(e){return e.listClass?`${e.id}_${e.listClass}`:"PersonSearch"===e.kind?`${e.id}_PersonSearch`:null}function $e(e){if(e.definitionClass.match(/^CustomField\w+OperationDefinition$/))return"Update [Hidden Custom Field]"}function Le(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Pe({field:e,loadedLists:t}){if(e.list)return e.list;if(Ae(e))return t[Ae(e)];throw new Error(`Don't know how to get list for ${JSON.stringify(e)}`)}function Fe(e,t){return e.filter(e=>{if(Object.prototype.hasOwnProperty.call(e,"renderIf")){const n=e.renderIf,a=Object.keys(n)[0];return M(n)?n:n[a]===t[a]}return!0})}function Te({selectedDefinition:e,selectedFieldOptions:t,loadedLists:n}){return function({selectedDefinition:e,selectedFieldOptions:t,loadedLists:n,description:a}){if("AddToWorkflowOperationDefinition"===e.definitionClass){var i;const e=n.workflow_id_WorkflowsList,o=e&&(null==(i=e.find(e=>e.value.toString()===t.workflow_id))?void 0:i.description);return a.replace(o,"[Hidden Workflow]")}return e.definitionClass.match(/^CustomField\w+OperationDefinition$/)?"":a}({description:e.definitionFields.map(e=>{var a;if(!Le(t,e.id))return null;const i=t[e.id];let o;switch(e.kind){case"Select":case"SelectSearch":case"PersonSearch":case"RadioButtons":return o=Pe({field:e,loadedLists:n}),o&&(null==(a=o.find(e=>e.value.toString()===i))?void 0:a.description);case"Checkbox":return i&&e.label;case"Checkboxes":return o=Pe({field:e,loadedLists:n}),o.filter(e=>Le(i,e.value)).map(e=>`${Se(i[e.value])} ${e.description}`).join(", ");case"NumberField":case"TextField":case"TextArea":case"DateField":return i;default:throw new Error(`Don't know how to build value for field with kind ${e.kind}`)}}).filter(e=>e).join(", "),loadedLists:n,selectedDefinition:e,selectedFieldOptions:t})}function Ie(e){return e.replace(/%m/,"MM").replace(/%d/,"DD").replace(/%Y/,"YYYY").replace(/%y/,"YY")}function De(e,t){const n=ae(e,"YYYY-MM-DD");if(!n.isValid())return"";const a=Ie(t);return n.format(a)}function He(e,t){return 1===e?`1 ${t}`:`${e} ${t}s`}function je(e){return e.replace(/s$/,"")}function We(e){const t=e.split("/");return{appName:t[0],resourceId:t[t.length-1],resourcePath:t.slice(2,-1).join("/"),resourceType:t[t.length-2]}}const Ve=new a({app:"webhooks",version:"2022-10-20"}),Be=new a({app:"people",version:"2022-07-14"}),Re={delivered:{label:"Success",value:["delivered"]},failed:{label:"Failed",value:["failed","duplicated"]},ignored:{label:"Ignored",value:["ignored_duplicated","ignored_failed","ignored_skipped"]},pending:{label:"Pending",value:["pending"]},skipped:{label:"Paused",value:["skipped"]}};async function Ne(e){const t=e.data.map(e=>Ee(e));try{const n=await async function(e){const{data:t}=await Be.get({data:{fields:{Person:"id,name"},where:{id:e.join(",")}},url:"people"});return t}(t);return{events:e,people:n}}catch(t){return{events:e,people:[]}}}function Me({events:e,people:t}){const n=e.data.reduce((e,n)=>{const a=Ee(n),i=t.find(e=>a.toString()===e.id.toString());return e.push(ge({},n,i?{person:{id:i.id,name:i.name}}:{person:{id:a,name:"[Hidden]"}})),e},[]);return ge({},e,{data:n})}function Ee(e){return e.personId}function Ye({automation:a,triggerResource:p,filterWhere:h,onEventsStatusChange:g}){var w;const{events:f,loading:b,paginationProps:v,refresh:x,params:y,setParams:k}=function(e,t,n){const[a,i]=W(),[o,r]=W(!1),[s,l]=W({}),[c,d]=W(n?{where:{status:n}}:{}),[u,p]=W(),{offset:m,paginationProps:h,resetOffset:g}=function(e,t){const[n,a]=W(0);return{offset:n,paginationProps:{currentPage:Math.floor(n/50)+1,onPageChange:function(e){a(50*(e-1))},totalPages:Math.ceil(t/50)},resetOffset:B(()=>{a(0)},[])}}(0,null==u?void 0:u.totalCount);V(()=>{o||s[m]||(r(!0),async function(e,t,n){return await Ve.get({data:ge({_e:e,fields:{Delivery:"status,response_body,created_at",Event:"id,created_at,last_delivery,payload,status,uuid,person"},include:"last_delivery",order:"-created_at"},n),url:`automation_subscriptions/${t}/events`})}(t,e,ge({offset:m,per_page:50},c)).then(Ne).then(Me).then(e=>{l(t=>ge({},t,{[m]:e.data})),p(e.meta),r(!1)}).catch(f))},[e,t,o,c,m,s]);const w=B(()=>{l({}),p(void 0),g()},[g]);function f(e){i(()=>{throw e})}return V(()=>{w()},[w,c]),{events:s[m]||[],loading:o,paginationProps:h,params:c,refresh:w,setParams:d}}(a.id,p,h),{dateFormat:C,olsonTimeZone:z,twentyFourHourTime:_}=j(be),S=y.where&&Object.keys(y.where).length>0,O=function(e){const t=ae(e,"YYYY-MM-DD");return ae().diff(t,"days")}(a.createdAt)<=32,A=De(a.createdAt,C),$=O?`Automation history started on ${A}`:"Automation history is saved for 32 days",L=[{cell:e=>t(Ze,{status:e.status}),css:{padding:"8px 12px"},header:"Status"},{cell:e=>ae(e.createdAt).utcOffset(z).format(function({dateFormat:e,twentyFourHourTime:t}){return`${Ie(e)} ${t?"HH:mm":"h:mm A"}`}({dateFormat:C,twentyFourHourTime:_})),header:"Date and time"},{cell:e=>t(m,{to:`/people/AC${e.person.id}`,children:e.person.name}),css:{maxWidth:"33%"},header:"Profile"},{cell:e=>t(Xe,{event:e}),css:{flex:1},header:"Message"},{cell:i=>![...Re.delivered.value,...Re.pending.value].includes(i.status)&&e(n,{children:[t(Ue,{automationId:a.id,event:i,triggerResource:p,onEventsStatusChange:g}),![...Re.ignored.value].includes(i.status)&&t(qe,{automationId:a.id,event:i,triggerResource:p,refreshHistory:x,onEventsStatusChange:g})]}),css:{textAlign:"right"},header:"",minWidth:"84px"}];return e(i,{spacing:4,children:[e(i,{spacing:.5,children:[t(o,{level:3,size:"16px",color:ze.neutral45,weight:500,children:a.description}),t(r,{color:ze.neutral45,size:5,italic:!0,children:$})]}),e(i,{spacing:2,children:[t(s,{minHeight:7,children:!b&&(f.length||S)&&e(i,{alignItems:"end",axis:"horizontal",distribution:"space-between",spacing:1,children:[e(i,{width:"max-content",children:[t(l.InputLabel,{fontWeight:500,color:ze.neutral24,controls:"select-status",children:"Filter by status"}),e(c,{id:"select-status",emptyValue:null,onChange:({selectedValue:e})=>{k({where:e?{status:e}:null})},title:"Status",value:null==(w=y.where)?void 0:w.status,children:[t(c.Option,{value:null,children:"All"}),Object.values(Re).map(e=>t(c.Option,{value:e.value.join(","),children:e.label},e.value))]})]}),t(d,{iconLeft:{name:"general.refresh"},onClick:x,theme:"primary",variant:"outline",width:12,children:"Refresh"})]})}),t(s,{maxHeight:"70vh",minHeight:36,overflow:"auto",children:t(u,ge({columns:L,data:f,empty:e(i,{alignment:"center",distribution:"center",minHeight:20,maxWidth:45,spacing:1,marginTop:S?-4:-8,marginBottom:S?4:void 0,children:[t(s,{css:{svg:{height:15,width:20}},children:t(fe,{})}),t(o,{color:ze.neutral12,fontWeight:500,level:4,size:2,children:"No history found"}),e(r,{fontSize:"16px",textAlign:"center",children:["No events ",S&&"matching your filters"," were triggered for this automation"," ",O?`since ${A}.`:"in the last 32 days."]}),S&&t(d,{marginTop:1,onClick:()=>k({}),theme:"primary",title:"Clear filters",variant:"outline"})]}),loading:b,loadingTitle:"Loading automation history...",variant:{bodyCell:{alignItems:"start",fontSize:"13px",lineHeight:"20px",padding:"10px 12px"},bodyRow:({rowData:e})=>({backgroundColor:[...Re.ignored.value].includes(e.status)?ze.neutral98:void 0,minHeight:"36px"}),headerCell:{padding:"8px 12px"},headerRow:{minHeight:"36px"}}},v))})]})]})}function Ue({automationId:e,event:n,triggerResource:a,onEventsStatusChange:i}){const[o,r]=W(n.status),s=Re.pending.value.includes(o)?"Sending":Re.delivered.value.includes(o)?"Sent":Re.skipped.value.includes(o)?"Run now":"Retry",l=Re.delivered.value.includes(o)?{color:ze.statusCreate27,name:"general.check"}:void 0;return t(d,{title:s,onClick:function(){r(Re.pending.value.join(",")),Ve.post({data:{_e:a,data:{attributes:{}}},url:`/automation_subscriptions/${e}/events/${n.id}/redeliver`}).then(e=>{r(Re.delivered.value.join(",")),i(e.meta.eventsStatus)}).catch(()=>{r(Re.failed.value.join(",")),ve.fire({text:"There was a problem retrying this automation. Please try again in a few moments.",title:"Uh oh!"})})},iconLeft:l,disabled:o!==n.status,variant:"naked",color:Re.delivered.value.includes(o)?ze.statusCreate27:Re.pending.value.includes(o)?ze.neutral68:"linkForeground",theme:"primary",size:"xs"})}function qe({automationId:e,event:n,triggerResource:a,refreshHistory:i,onEventsStatusChange:o}){return t(d,{title:"Ignore",onClick:function(){Ve.post({data:{_e:a,data:{attributes:{}}},url:`/automation_subscriptions/${e}/events/${n.id}/ignore`}).then(e=>{o(e.meta.eventsStatus)}).then(()=>i()).catch(()=>{ve.fire({text:"There was a problem ignoring this event. Please try again in a few moments.",title:"Uh oh!"})})},variant:"naked",color:"linkForeground",theme:"primary",size:"xs"})}function Ze({status:e}){const n=Re.pending.value.includes(e)?{border:ze.neutral62,text:ze.neutral24}:Re.delivered.value.includes(e)?{border:ze.statusCreate35,text:ze.statusCreate23}:Re.skipped.value.includes(e)?{border:ze.statusWarning63,text:ze.givingBrand31}:Re.ignored.value.includes(e)?{border:ze.neutral68,text:ze.neutral45}:{border:ze.statusDelete47,text:ze.statusDelete43},a=Re.pending.value.includes(e)?"general.clock":Re.skipped.value.includes(e)?"services.pause":Re.delivered.value.includes(e)?"general.checkCircle":Re.ignored.value.includes(e)?"general.inactive":"general.exclamationTriangle",i=Re.failed.value.includes(e)?Re.failed.label:Re.ignored.value.includes(e)?Re.ignored.label:Re[e].label;return t(h,{color:{background:"transparent",foreground:n.text},css:{paddingLeft:3.5,paddingRight:1.5},fontSize:"12px",radius:"pill",renderLeft:t(g,{name:a,color:n.border,marginLeft:1}),size:"sm",stroke:n.border,strokeAlign:"inside",strokeWeight:1,title:i})}function Xe({event:e}){const{status:n,lastDelivery:a}=e,o=function(e,n){let a=null;switch(e){case"skipped":case"ignored_skipped":a="Automation was paused and did not run on this profile";break;case"failed":case"duplicated":case"ignored_failed":case"ignored_duplicated":a=function(e,n){const a={403:"Owner doesn't have permission to perform this action.",404:"Owner lacks access to target product or resource doesn't exist.",422:"The automation action failed to run",default:"An error occurred",duplicated_event:"Didn't run because the same action had already been performed less than 60 seconds ago",failed_without_deliveries:"Didn't run because the owner doesn't have permissions in this product."};return t(i,{flex:1,whiteSpace:"normal",children:e?t(Qe,{details:function(e){var t;if(null==e||!e.responseBody)return null;let n;try{n=JSON.parse(e.responseBody)}catch(e){n={errors:["Server Error"]}}return function(e){return null!=e&&e.errors?e.errors.map(e=>"string"==typeof e&&e.match(/Archived profiles/)?e.replace(/Archived profiles/,"Archived profiles."):e):[]}(n).join(", ")||(null==(t=n)?void 0:t.message)}(e),status:e.status,children:a[e.status]||a.default}):["duplicated","ignored_duplicated"].includes(n)?a.duplicated_event:a.failed_without_deliveries})}(n,e)}return a}(n,a);return o?t(s,{fontSize:"13px",fontStyle:"italic",lineHeight:"16px",maxWidth:"100%",paddingTop:"1px",whiteSpace:"normal",children:o}):null}function Qe({children:n,details:a,status:o}){const[l,c]=W(!1);return e(i,{spacing:1,children:[e(s,{children:[n," ",a&&t(d,{inline:!0,onClick:function(){c(e=>!e)},size:"xs",theme:"primary",variant:"naked",fontStyle:"normal",children:"Details"})]}),l?t(s,{padding:1,background:ze.neutral98,children:e(r,{fontFamily:"monospace",fontSize:"11px",lineHeight:"1.2",children:[o&&`${o}: `,a]})}):null]})}class Ge extends D.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?e(p,{type:"error",marginVertical:1,children:["The application hit an unexpected error. If this persists after a few minutes, please let us know so we can get it fixed for you."," ",t("a",{style:{whiteSpace:"nowrap"},onClick:()=>window.Helpdesk.load(),children:"Contact support"})]}):this.props.children}}var Je=e=>t(Ge,{children:t(Ye,ge({},e))});function Ke({onClick:e}){return t(d,{as:"button",height:2,icon:{color:ze.neutral62,name:"general.x"},onClick:e,size:"sm",title:"Close",variant:"naked"})}function et({children:n,onRequestClose:a,open:r,theme:s}){/*#__PURE__*/return he(t(w,{theme:s,children:e(f,{open:r,onRequestClose:a,maxWidth:120,boxShadow:"0 0 20px rgba(0, 0, 0, 0.15)",padding:4,paddingBottom:3,radius:8,children:[e(i,{axis:"horizontal",distribution:"space-between",alignment:"center",children:[t(o,{level:2,color:ze.neutral12,fontWeight:500,fontSize:"25px",lineHeight:"1.4",children:"Automation history"}),t(Ke,{onClick:a})]}),n]})}),document.body)}const tt=["onDelete","theme","openHistoryNow"],nt=["automation","children","theme"],at=new a({app:"webhooks",version:"2022-10-20"}),it=new a({app:"people"}),ot=/*#__PURE__*/H(null);function rt(n){let{onDelete:a,theme:i,openHistoryNow:o=!1}=n,r=we(n,tt);return e(dt,ge({theme:i},r,{children:[e(ut,{children:[t(mt,{}),t(pt,{onDelete:a,openHistoryNow:o})]}),t(wt,{}),t(gt,{})]}))}function st(n){return e(dt,{automation:n.automation,children:[e(ut,{children:[t(mt,{}),t(ct,{})]}),t(lt,{}),t(ht,{})]})}function lt(){const{automation:n}=j(ot),a=n.triggerEventDescription,{name:s,description:l}=bt(n.description);return e(i,{paddingVertical:2,flex:1,opacity:n.active?void 0:.5,children:[t(o,{level:3,size:"21px",weight:600,marginBottom:.5,truncate:!0,children:s}),e(i,{spacing:.75,children:[e(r,{size:4,color:ze.neutral24,lineHeight:"1.2",children:[a,", then ",Y(s)," ",ft(n)]}),t(r,{size:5,color:ze.neutral45,lineHeight:"1.2",children:U(l,{length:160,separator:" "})})]})]})}function ct(){const{automation:e}=j(ot);return t(d,{external:!0,iconLeft:{name:"general.newWindow"},variant:"naked",size:"sm",to:e.triggerAdminUrl,disabled:!e.canManage,tooltip:e.canManage?void 0:"You do not have access to this resource",color:ze.neutral45,hover:{backgroundColor:"highlight",color:ze.neutral45},children:"Manage"})}function dt(e){let{automation:n,children:a,theme:i}=e,o=we(e,nt);const[r,s]=W(n);return t(ot.Provider,{value:ge({automation:r,theme:i,updateAutomation:s},o),children:t(b,{radius:4,padding:2,children:a})})}function ut({children:e}){const{automation:n}=j(ot);return t(i,{axis:"horizontal",alignment:"center",padding:0,distribution:"space-between",opacity:n.active?void 0:.5,children:e})}function pt({onDelete:a,openHistoryNow:o=!1}){const{automation:l,currentPersonCanCreate:c,currentPersonId:u,trigger:p,theme:m,updateAutomation:h}=j(ot),[g,w]=W(o),f=l.active,{name:b}=bt(l.description);return e(n,{children:[e(i,{axis:"horizontal",alignment:"center",spacing:.75,children:[e(v,{icon:{color:ze.neutral24,name:"churchCenter.threeDots"},iconRight:!1,title:"Actions",variant:"naked",size:"md",children:[t(v.Item,{onSelect:()=>{w(!0)},children:"History"}),c&&t(v.Item,l.createdById===u?{disabled:!0,children:t(x,{placement:"left",openDelay:250,title:"This automation is already assigned to you.",children:t(r,{children:"Reassign to me..."})})}:{onSelect:function(){xe.fire({text:"This automation will run with your permission levels. Other administrators who can see this automation can grant it their permissions by reassigning it to themselves.",title:"Reassign automation?"}).then(({isConfirmed:e})=>{e&&at.post({data:{_e:p.resource,data:{attributes:{}}},url:`/automation_subscriptions/${l.id}/self_assign`}).then(({data:e})=>async function(e){const{data:{avatar:t}}=await it.get({data:{fields:{Person:"avatar"}},url:"me"});return{avatar:t,subscription:e}}(e)).then(({subscription:e,avatar:t})=>{h(n=>ge({},n,{createdBy:ge({},n.createdBy,{avatarUrl:t}),createdById:e.createdById,createdByName:e.createdByName}))}).catch(()=>ve.fire({text:"There was a problem updating this automation. Please try again in a few moments.",title:"Uh oh!"}))})},children:"Reassign to me..."}),t(v.Item,{onSelect:function(){ye.fire({confirmButtonText:"Yes, delete automation",text:`Are you sure you want to delete the "${b}" automation? This cannot be undone.`,title:"Delete this automation?"}).then(({isConfirmed:e})=>{e&&a(l.id)})},children:"Delete..."})]}),t(d,{as:"button",theme:!1,position:"relative",backgroundColor:f?ze.statusCreate35:ze.neutral62,radius:"pill",width:3.5,height:2,onClick:function(){at.patch({data:{_e:p.resource,data:{attributes:{active:!f}}},url:`/automation_subscriptions/${l.id}`}).then(e=>{h(t=>ge({},t,{active:e.data.active}))}).catch(()=>ve.fire({text:`There was a problem ${f?"pausing":"unpausing"} this automation. Please try again in a few moments.`,title:"Uh oh!"}))},tooltip:f?"Pause automation":"Enable automation",children:t(s,{position:"absolute",pointerEvents:"none",top:.25,left:.25,width:1.5,height:1.5,background:"#fff",radius:"circle",transition:"0.1s",transform:`translateX(${f?"100%":"0%"})`})})]}),t(et,{open:g,onRequestClose:()=>w(!1),theme:m,children:t(Je,{automation:l,triggerResource:p.resource,onEventsStatusChange:function(e){h(t=>ge({},t,{eventsStatus:e}))}})})]})}function mt(){const{automation:n}=j(ot),a=n.name.split(".")[0];return e(i,{axis:"horizontal",alignment:"center",spacing:.5,children:[t(g,{name:`logomark.${E(a)}`,size:2,color:a.toLowerCase()}),t(g,{name:"general.rightArrow",size:1.5}),t(g,{name:`logomark.${E(n.operationAppName)}`,size:2,color:n.operationAppName.toLowerCase()})]})}function ht(){var a,o;const{automation:s}=j(ot),{dateFormat:l}=j(be),c=null!=(a=s.createdBy)&&a.id?"":"(deleted profile)",d=`${s.createdByName} ${c}`,u=s.active?void 0:.5;return e(n,{children:[t(y,{marginHorizontal:-2}),e(i,{axis:"horizontal",alignment:"center",distribution:"space-between",paddingTop:1.75,spacing:1,opacity:u,children:[e(r,{size:6,color:ze.neutral62,whiteSpace:"nowrap",children:["Updated ",De(s.createdAt,l)]}),e(i,{axis:"horizontal",alignment:"center",spacing:.5,maxWidth:"calc(100% - 136px)",children:[(null==(o=s.createdBy)?void 0:o.avatarUrl)&&t(k,{width:2,height:2,basis:2,source:s.createdBy.avatarUrl},d),t(r,{size:5,truncate:!0,children:d})]})]})]})}function gt(){var a,o,l,c,u,p,m,h;const{dateFormat:w}=j(be),{automation:f,trigger:b,theme:v,updateAutomation:x}=j(ot),C=null!=(a=f.createdBy)&&a.id?"":"(deleted profile)",z=`${f.createdByName} ${C}`,_=f.active?void 0:.5,S={color:ze.neutral45,fontSize:6,fontWeight:400,paddingHorizontal:1,radius:"pill",size:"xs",variant:"naked"},[O,A]=W({filter:null,historyVisible:!1});return e(n,{children:[t(y,{marginHorizontal:-2}),e(i,{axis:"horizontal",alignment:"center",distribution:"space-between",paddingTop:1.75,spacing:1,opacity:_,children:[e(r,{size:6,color:ze.neutral62,whiteSpace:"nowrap",children:["Updated ",De(f.createdAt,w)]}),e(i,{axis:"horizontal",alignment:"center",spacing:.25,children:[!(null==(o=f.eventsStatus)||!o.skipped)&&e(d,ge({},S,{"aria-label":`${f.eventsStatus.skipped} skipped`,onClick:function(){A({filter:"skipped",historyVisible:!0})},tooltip:`${null==(l=f.eventsStatus.skipped)?void 0:l.toLocaleString()} skipped events`,children:[t(s,{backgroundColor:ze.statusWarning63,marginRight:.5,radius:"circle",height:"10px",width:"10px",padding:"2px",children:t(g,{name:"services.pause",size:"6px",title:"Skipped",color:"white"})}),`${null==(c=f.eventsStatus.skipped)?void 0:c.toLocaleString()}`]})),!(null==(u=f.eventsStatus)||!u.failed)&&t(d,ge({},S,{"aria-label":`${f.eventsStatus.failed} failed`,iconLeft:{color:ze.statusDelete43,marginRight:.5,name:"general.exclamationTriangle",size:"10px",title:"Failed"},onClick:function(){A({filter:"failed,duplicated",historyVisible:!0})},title:`${null==(p=f.eventsStatus.failed)?void 0:p.toLocaleString()}`,tooltip:`${null==(m=f.eventsStatus.failed)?void 0:m.toLocaleString()} failed events`}))]}),e(i,{axis:"horizontal",alignment:"center",distribution:"end",flex:1,spacing:.5,marginLeft:"auto",children:[(null==(h=f.createdBy)?void 0:h.avatarUrl)&&t(k,{width:2,height:2,basis:2,source:f.createdBy.avatarUrl},z),t(r,{size:5,truncate:!0,children:z})]})]}),t(et,{open:O.historyVisible,onRequestClose:()=>A({filter:null,historyVisible:!1}),theme:v,children:t(Je,{automation:f,triggerResource:b.resource,filterWhere:O.filter,onEventsStatusChange:function(e){x(t=>ge({},t,{eventsStatus:e}))}})})]})}function wt(){const{automation:n,trigger:a}=j(ot),{name:s,description:l}=bt(n.description),c=n.active?void 0:.5,d=["When a person",Y(a.event.description)+",","then",Y(s),ft(n)].join(" ");return e(i,{paddingVertical:2,flex:1,opacity:c,children:[t(o,{level:3,size:"21px",weight:600,marginBottom:.5,truncate:!0,children:s}),e(i,{spacing:.75,children:[t(r,{size:4,color:ze.neutral24,lineHeight:"1.2",children:d}),t(r,{size:5,color:ze.neutral45,lineHeight:"1.2",children:U(l,{length:160,separator:" "})})]})]})}function ft(e){var t;return null!=e&&null!=(t=e.triggerParams)&&t.useTriggerPersonOverride?"(also applies to joint donor)":""}function bt(e){const t=/^(.+?)\(([^()]*?)\)$/.exec(e);return t?{description:t[2],name:t[1].trim()}:{name:e}}const vt=new a({app:"webhooks",version:"2022-10-20"}),xt=new a({app:"people"});async function yt(e){const t=q(Z(e.map(e=>e.createdById)));try{const{data:n}=await xt.get({data:{fields:{Person:"avatar"},where:{id:t.join(",")}},url:"people"});return{profiles:n,subscriptions:e}}catch(t){return{profiles:[],subscriptions:e}}}function kt({profiles:e,subscriptions:t}){return t.map(t=>{const n=e.find(e=>e.id===t.createdById);return ge({},t,{createdBy:ge({},t.createdBy,{avatarUrl:null==n?void 0:n.avatar})})})}const Ct=new a({app:"webhooks",version:"2022-10-20"});async function zt(e){const t={people:["forms","lists"],registrations:["events"],services:["teams"]},n=["giving"],a=e.reduce((e,t)=>{const n=t.triggerResource.replace(/signup/,"event"),{appName:a,resourceType:i,resourcePath:o,resourceId:r}=We(n);return e[a]||(e[a]={}),e[a][i]||(e[a][i]={}),e[a][i].resoucePath||(e[a][i].resourcePath=o),e[a][i].ids||(e[a][i].ids=[]),e[a][i].ids.push(r),e},{}),i=Object.keys(a).flatMap(e=>Object.entries(a[e]).flatMap(([a,i])=>{var o;return(n.includes(e)?Ot:null!=(o=t[e])&&o.includes(a)?_t:St)({appName:e,ids:i.ids,resourcePath:i.resourcePath,resourceType:a})}));return{automations:e,triggerResources:(o=await Promise.allSettled(i),o.reduce((e,t)=>("fulfilled"===t.status&&(e=e.concat(t.value)),e),[]).flatMap(e=>e.data))};var o}function _t({appName:e,resourcePath:t,resourceType:n,ids:a}){return At({appName:e,params:{where:{id:a.join(",")}},path:t,resourceType:n})}function St({appName:e,resourcePath:t,resourceType:n,ids:a}){return a.map(a=>At({appName:e,path:`${t}/${a}`,resourceType:n}))}function Ot(e){return new Promise((e,t)=>{t()})}function At({appName:e,path:t,resourceType:n,params:i={}}){const o=new a({app:e}),r=X(je(n));return o.get({data:ge({fields:{[r]:["name","name_or_description"]}},i),url:t})}function $t({encryptedParam:a,trigger:i}){const[l,c]=W(!0),[d,u]=W();V(()=>{(async function(){return xt.get({data:{fields:{App:["name"],PersonApp:["app","allow_pco_login"]},include:["app"]},url:"/me/person_apps"}).then(({data:e})=>e.filter(e=>e.allowPcoLogin).map(e=>e.app.name.toLowerCase()))})().then(e=>{(async function(e){const{data:t}=await Ct.get({data:{_e:e,fields:{AutomationSubscription:"id,description,created_at,created_by,operation_app_name,operation_definition_class_name,operation_params,active,created_by_name,name,trigger_admin_url,trigger_resource,trigger_params",Person:"name"},include:"created_by"},url:"incoming_automation_subscriptions"});return t})(a).then(yt).then(kt).then(_e).then(zt).then(({automations:t,triggerResources:n})=>function({automations:e,triggerResources:t,operationApps:n}){return e.map(e=>{const{appName:a,resourceType:i,resourceId:o}=We(e.triggerResource);if("giving"===a)return e.triggerEventDescription=function(e){switch(e.name.replace("giving.v2.events.","")){case"donation.payment_successful":return"When a person gives";case"profile.first_donated_automation":return"When a person gives for the first time";case"recurring_donation.setup_successful":return"When a person sets up a recurring donation";default:return null}}(e),e.canManage=n.find(e=>"giving"===e),e;const r=t.find(e=>e.id.toString()==o.toString()),s=r?r.name||r.nameOrDescription:`[Hidden ${X(je(i))}]`;return e.triggerEventDescription=function(e,t){const n=function(e){switch(e.replace("v2.events.","")){case"groups.membership.created":return"joins";case"groups.membership.destroyed":return"leaves";case"people.list_result.created":case"services.team_person.created":return"is added to";case"people.list_result.destroyed":case"services.team_person.destroyed":return"is removed from";case"people.form_submission.created":return"submits";case"registrations.attendee.created":return"is registered as a new attendee for";case"registrations.attendee.cancelled":return"is canceled as an attendee for";case"registrations.registration.created":return"is the registration contact on a new registration for";case"registrations.registration.cancelled":return"is the registration contact on a canceled registration for";default:return null}}(e.name),{resourceType:a}=We(e.triggerResource);if(!n){const e=U(t,{length:160,separator:" "});return`When the automation is triggered from ${je(a)} "${e}"`}return`When a person ${n} ${je(a)} "${t}"`}(e,s),e.canManage=!!r,e})}({automations:t,operationApps:e,triggerResources:n})).then(u).then(()=>c(!1))})},[a]);const p=!l&&0===d.length;return e(n,{children:[t(s,{borderBottom:`1px solid ${ze.neutral88}`,marginBottom:2,marginHorizontal:-3,marginTop:i?12:0,paddingHorizontal:3,paddingVertical:2,children:t(o,{color:ze.neutral12,level:2,size:"18px",children:l?"Incoming automations":He(d.length,"incoming automation")})}),p?t(r,{color:ze.neutral45,marginVertical:3,children:"Automations that perform actions on this resource will be listed here."}):l?t(C,{image:t(z,{size:"xl"}),paddingVertical:10,title:"Loading incoming automations..."}):t(_,{spacing:3,marginVertical:3,minCellWidth:45,children:d.map(e=>t(st,{automation:e},e.id))})]})}function Lt(e){return`OPERATION_${e.definitionClass}${e.definitionIdentifier||""}`}function Pt(e){return`SECTION_${e}`}function Ft(e){return e.map(({label:e,value:n})=>t(c.Option,{value:n,children:e},n))}function Tt(e){const n=G(e,"group");return Object.keys(n).sort().map(e=>"null"===e?Ft(n[e]):t(c.OptionGroup,{title:e,children:Ft(n[e])},e))}const It=({selectedOperation:n,onOperationDefinitionChange:a,operationDefinitions:o})=>{const r=null==n?void 0:n.section,s=o.map(e=>ge({},e,{id:Lt(e)})),l=s.filter(e=>null===e.section),d=Q(o,"section").filter(e=>!!e.section).map(e=>({group:e.sectionGroup,label:e.section,value:Pt(e.section)})),u=r?s.filter(e=>e.section===r):[];function p({selectedValue:e}){switch(function(e){if(e.startsWith("SECTION"))return"section";if(e.startsWith("OPERATION"))return"operation";if(e)throw new Error(`Unexpected value: ${e}`);return null}(e)){case"section":a(o.find(t=>Pt(t.section)===e));break;case"operation":a(o.find(t=>Lt(t)===e));break;case null:a(null)}}function m(e){return Tt(e.map(e=>({group:e.group,label:e.description,value:e.id})))}return e(i,{spacing:1,children:[e(c,{emptyValue:"Select an action",id:"select-action",onChange:p,size:"lg","data-testid":"operation-select",children:[m(l),Tt(d)]}),u.length>0&&t(c,{defaultValue:u[0].id,onChange:p,size:"lg",children:m(u)})]})},Dt=({canAccessPeople:n,field:a,onChange:o,value:r,selectedFieldOptions:c,loadListForField:d,loadedLists:u,loadingLists:p})=>{const m=function(e){const[t,n]=W(e);return V(()=>{const a=e();J(a,t)||n(a)},[e,t]),t}(()=>function({field:e,selectedFieldOptions:t}){return(e.dependsOn||[]).reduce((e,n)=>(Object.prototype.hasOwnProperty.call(t,n)&&(e[E(n)]=t[n]),e),{})}({field:a,selectedFieldOptions:c}));V(()=>{a.listClass&&d({dependencies:m,field:a})},[a,m,d]);const h=a.list||u[Ae(a)]||[],g=h.filter(e=>!e.automationNotAllowed),w=a.listClass&&p[Ae(a)];return e(i,{marginBottom:2,spacing:.5,children:[e(l.InputLabel,{color:ze.neutral12,fontSize:"14px",fontWeight:500,controls:a.id,children:[a.description,a.info&&t(S.Toggle,{drawerId:`${a.id}_help`,marginLeft:1})]}),t(s,{children:w?t(Ut,{}):function(){switch(a.kind){case"Select":return t(Ht,{fieldId:a.id,listOptions:g,onChange:o,value:r});case"SelectSearch":return t(jt,{fieldId:a.id,listOptions:g,onChange:o,value:r});case"Checkbox":return t(Vt,{field:a,value:r,onChange:o});case"TextArea":return t(Bt,{field:a,onChange:o,value:r});case"DateField":return t(Rt,{field:a,onChange:o,value:r});case"Checkboxes":return t(Nt,{fieldId:a.id,options:g,onChange:o});case"NumberField":return t(Mt,{field:a,onChange:o,value:r});case"PersonSearch":return t(Wt,{canAccessPeople:n,field:a,onChange:o,listOptions:h,isLoading:p[Ae(a)],loadListForField:d,value:r});case"TextField":return t(Et,{field:a,onChange:o,value:r});case"RadioButtons":return t(Yt,{field:a,options:h,onChange:o,value:r});default:return console.warn(`Unknown field kind "${a.kind}"`),null}}()}),a.info&&t(S,{id:`${a.id}_help`,marginTop:.5,children:t(s,{dangerouslySetInnerHTML:{__html:a.info}})})]})},Ht=({fieldId:e,listOptions:n,onChange:a,value:i})=>{const o=null==n?void 0:n.find(e=>"no-option"===e.value),r=G(n,"group"),s=Object.keys(r).sort(),l=()=>s.map(e=>"null"===e||"undefined"===e?d(r[e]):t(c.OptionGroup,{title:e,children:d(r[e])},e)),d=e=>e.map(e=>t(c.Option,{value:e.value.toString(),disabled:e.disabled,children:e.description},e.value));return t(c,{id:e,onChange:({selectedValue:t})=>{a({fieldId:e,value:t})},disabled:l().length<1,emptyValue:0===l().length?"No options available":(null==o?void 0:o.description)||"Select a value",size:"lg",value:i||(null==o?void 0:o.value)||null,placement:"bottom-start",children:l()})},jt=({fieldId:a,listOptions:i,onChange:o,value:s})=>{const l=i.find(e=>{var t;return(null==(t=e.value)?void 0:t.toString())===s}),c=(null==l?void 0:l.description)||"",[d,u]=W(""),[p,m]=W(c),[w,f]=W(!1),[b,v]=W(!1);c!==d&&(u(c),m(c),f(!1));let x=K(Q(i,"value"),"group");if(w){const e=p.toLowerCase();x=x.filter(t=>`${t.description} ${t.group}`.toLowerCase().includes(e))}return t(O.Popover,{closeOnSelect:!0,closeButton:{icon:{size:"md"}},css:{"[role='combobox']":{cursor:i.length>0?"pointer":"not-allowed"}},cursor:"pointer",disabled:0===i.length,onBlur:()=>{v(!1),m(c)},onChange:e=>{m(e.target.value),f(!0),v(!0)},onClear:b?()=>{m(""),f(!1)}:void 0,onFocus:e=>e.target.select(),onSelect:e=>{(e=>{o({fieldId:a,value:e})})(e.value),m(e.description),f(!1),v(!1)},openOnFocus:!0,paddingLeft:4.5,placeholder:i.length>0?"Select an option":"No options available",placement:"bottom-start",popoverProps:{matchWidths:"minimum"},renderLeft:t(g,{name:"general.search",size:"md"}),renderRight:t(g,{name:"general.downCaret"}),size:"lg",value:p,children:i.length>0&&t(n,{children:x.length>0?x.map((n,a)=>{const i=n.value.toString()===s;return e(O.Item,{"aria-label":n.description,disabled:n.disabled,index:a,paddingLeft:4.25,renderLeft:t(g,{marginLeft:-.5,name:i?"general.check":"",size:"sm"}),role:"option",spacing:1,value:{description:n.description,value:n.value.toString()},children:[t(r,{truncate:!0,children:t(A,{text:n.description,query:p})}),n.group&&t(h,{title:t(A,{text:n.group,query:p}),size:"sm",marginLeft:"auto"})]},n.value)}):t($.Item,{children:e(r,{children:['No results for "',p,'"']})})})})},Wt=({canAccessPeople:e,field:n,isLoading:a,listOptions:i,loadListForField:o,onChange:s,value:l})=>{var c;const d=B(e=>{o({dependencies:{query:e},field:n})},[o]),u=R(()=>ee(d,300),[d]),p=B(t=>{e&&(t.trim().length>0?u(t):u.cancel())},[u]),m=R(()=>({description:"Myself",value:"self"}),[]),h=R(()=>e?i:[m],[m,i]).find(e=>e.value===l),w=(null==h?void 0:h.description)||"",[f,b]=W(w),[v,x]=W(!1);function y(e){b(e),p(e),0===e.trim().length&&C(null)}const C=e=>{s({fieldId:n.id,value:e})};return t(O.Popover,{closeOnSelect:!0,closeButton:{icon:{size:"md"}},cursor:"pointer",onBlur:()=>{x(!1),y(w)},onChange:e=>{y(e.target.value),x(!0)},onClear:v?()=>{y("")}:void 0,onFocus:e=>e.target.select(),onSelect:e=>{C(e.value),y(e.description),x(!1)},openOnFocus:!0,paddingLeft:4.5,placeholder:"Search",placement:"bottom-start",popoverProps:{matchWidths:"minimum"},renderLeft:h&&null!=(c=h.meta)&&c.avatar?t(k,{size:"sm",source:h.meta.avatar}):t(g,{name:"general.search",size:"md"}),renderRight:t(g,{name:"general.downCaret"}),size:"lg",value:f,children:e?f.trim().length>0?i.length>0?i.map((e,n)=>t(O.Item,{"aria-label":e.description,index:n,paddingLeft:4.25,renderLeft:t(k,{marginLeft:-.5,source:e.meta.avatar,size:"sm"}),role:"option",spacing:1,value:e,children:t(r,{truncate:!0,children:t(A,{text:e.description,query:f})})},e.value)):t(O.Item,a?{children:t(r,{children:"Loading..."})}:{children:t(r,{children:"No results"})}):t(O.Item,{children:t(r,{children:"Type to search"})}):t(O.Item,{value:m,index:0,role:"option",children:t(r,{children:m.description})})})},Vt=({field:e,value:n,onChange:a})=>t(L,{disabled:e.disabled,label:e.label,checked:n||!1,onChange:t=>{a({fieldId:e.id,value:t.target.checked})}}),Bt=({field:e,value:n,onChange:a})=>t(s,{children:t(P,{value:n,placeholder:e.placeholder,onChange:t=>{a({fieldId:e.id,value:t.target.value})},size:"lg"})}),Rt=({field:n,value:a,onChange:o})=>{const{dateFormat:r}=j(be),[l,d]=W(!1),u=n.customValue||"Date automation runs",p=r.replace(/%m/,"M").replace(/%d/,"d").replace(/%Y/,"y").replace(/%y/,"yy"),[m,h]=W(ae(a).toDate());return e(i,{axis:"horizontal",children:[e(c,{onChange:({selectedValue:e})=>{e===u?(d(!1),o({fieldId:n.id,value:u})):"specific-date"===e?(o({fieldId:n.id,value:null}),d(!0)):(d(!1),o({fieldId:n.id,value:null}))},size:"lg",placement:"bottom-start",children:[t(c.Option,{value:u,children:u}),t(c.Option,{value:"specific-date",children:"A specific date"}),t(c.Option,{value:"unanswered",children:"Unanswered"})]}),l&&t(s,{children:t(F,{defaultOpen:!0,formatValue:p,marginLeft:1,onChange:e=>{o({fieldId:n.id,value:De(e,r)}),h(e)},size:"lg",value:m})})]})},Nt=({fieldId:n,options:a,onChange:o})=>{const[r,d]=W({});return t(i,{spacing:1,children:a.map(a=>e(s,{children:[t(l.InputLabel,{controls:`checkboxes_${n}_${a.value}`,children:a.description||a.value}),e(c,{id:`checkboxes_${n}_${a.value}`,onChange:({selectedValue:e})=>((e,t)=>{const a=ge({},r);a[t]=e,d(a),o({fieldId:n,value:a})})(e,a.value),size:"lg",emptyValue:"Don't change",children:[t(c.Option,{value:"check",children:"Check"}),t(c.Option,{value:"uncheck",children:"Uncheck"})]})]},a.value))})},Mt=({field:n,onChange:a,value:o})=>{const s=n.minValue>=0?n.minValue:1,c=n.maxValue>=1&&n.maxValue<=365?n.maxValue:365,[d,u]=W(Number(n.defaultValue)||1);return V(()=>{a({fieldId:n.id,value:n.defaultValue||1})},[n]),e(i,{children:[t(l.InputBox,{children:t(T,{onChange:e=>{const t=Number(e)||0;u(t),a({fieldId:n.id,value:Math.min(Math.max(t,s),c)})},placeholder:n.placeholder,size:"lg",value:o,min:s,max:c,hasControls:!0})}),d>c&&t(p,{type:"error",paddingHorizontal:1,paddingVertical:.5,display:"inline-block",marginTop:1.5,children:e(i,{axis:"horizontal",alignment:"center",spacing:.75,children:[t(g,{name:"general.exclamationTriangle",size:"sm",color:"delete45"}),e(r,{size:4,children:["Value cannot exceed ",c,"."]})]})})]})},Et=({field:e,value:n,onChange:a})=>t(s,{children:t(l,{size:"lg",value:n,id:e.id,placeholder:e.placeholder,onChange:t=>{a({fieldId:e.id,value:t.target.value})}})}),Yt=({field:e,options:n,onChange:a,value:o})=>{const r=t=>{a({fieldId:e.id,value:t.target.value})};return t(i,{marginTop:1,spacing:.5,children:n.map(e=>t(I,{checked:o===e.value,label:e.description||e.value,onChange:r,size:"md",value:e.value},e.value))})},Ut=()=>e(i,{axis:"horizontal",alignment:"center",spacing:1,paddingHorizontal:1.75,paddingVertical:1,radius:4,border:`1px solid ${ze.neutral88}`,children:[t(z,{size:"xs"}),t(r,{fontSize:16,lineHeight:2.75,children:"Loading"})]}),qt=({canAccessPeople:e,definitionFields:n,onChange:a,selectedFieldOptions:i,loadListForField:o,loadedLists:r,loadingLists:s})=>{V(()=>{const e=n.reduce((e,t)=>(Object.prototype.hasOwnProperty.call(t,"defaultValue")?e[t.id]=t.defaultValue:"DateField"===t.kind&&(e[t.id]=t.customValue||"Date automation runs"),e),{});a(e)},[n,a]);const l=Fe(n,i),c=({fieldId:e,value:t})=>{const o=ge({},i),r=n.filter(e=>e.dependsOn);r.map(t=>{if(t.dependsOn.includes(e)){const e=r.find(e=>e.dependsOn.includes(t.id));e&&delete o[e.id],delete o[t.id],void 0!==t.defaultValue&&void 0===o[t.id]&&(o[t.id]=t.defaultValue)}}),"no-option"===t?delete o[e]:o[e]=t,a(ge({},o))};return n.length?t("div",{children:l.map(n=>t(Dt,{canAccessPeople:e,field:n,onChange:c,value:i[n.id],selectedFieldOptions:i,loadListForField:o,loadedLists:r,loadingLists:s},n.id))}):null},Zt=new a({app:"people",env:window.railsEnv,version:"LATEST"}),Xt=new a({app:"webhooks",env:window.railsEnv,version:"LATEST"}),Qt={css:{borderRadius:4},paddingHorizontal:1.75,paddingVertical:1.25,type:"error"};async function Gt(){return Zt.get({data:{fields:{Topbar:"apps"}},url:"/me/topbar"}).then(({data:e})=>e.apps.map(e=>e.name))}async function Jt(){return Xt.get({data:{fields:{OperationApp:"name"}},url:"/operation_apps"}).then(({data:e})=>e.map(e=>e.name))}async function Kt(e){return Xt.get({data:{fields:{OperationDefinition:"definition_class,definition_fields,definition_identifier,description,group,section,section_group,footer_message"},filter:"automation_allowed"},url:`/operation_apps/${e}/operation_definitions`}).then(({data:e})=>e)}const en=({afterCreateOptions:a,blankStateLink:o,debugMode:u=!1,defaultApp:h,description:w,onRequestClose:f,trigger:b})=>{var v,x,y;const[k,C]=W(b.events[0]),[_,S]=W({}),[O,A]=W(h),[$,P]=W([]),[F,T]=W([]),[I,D]=W(!0),[H,j]=W(),[M,E]=W({}),[Y,U]=W({}),[q,Z]=W({}),[X,Q]=W(!1),[G,J]=W({}),[K,ee]=W(!1),[ae,ie]=W({}),oe=N(null),re=R(()=>$.map(e=>e.id).includes("people"),[$]),se=null==H?void 0:H.definitionIdentifier,le="danger"===(null==H||null==(v=H.footerMessage)?void 0:v.kind),ce=B(({field:e,dependencies:t})=>{Z(t=>ge({},t,{[Ae(e)]:!0})),async function({app:e,field:t,definitionIdentifier:n,dependencies:a}){if("PersonSearch"===t.kind){const{data:e}=await Zt.get({data:{fields:{Person:"avatar,name"},where:{search_name_or_email:a.query,status:"active"}},url:"/people"});return e.map(e=>({description:e.name,meta:{avatar:e.avatar},value:e.id.toString()}))}{const{data:i}=await Xt.get({data:ge({},a,{definitionIdentifier:n,fields:{OperationDefinitionList:"values"}}),url:`/operation_apps/${e}/operation_definition_lists/${t.listClass}`});return i.values}}({app:O,definitionIdentifier:se,dependencies:t,field:e}).then(t=>{U(n=>ge({},n,{[Ae(e)]:t})),Z(t=>ge({},t,{[Ae(e)]:!1}))}).catch(e=>J({selected_definition:e}))},[O,se]);V(()=>{J({}),async function(){const[e,t]=await Promise.all([Gt(),Jt()]);return e.filter(e=>t.includes(e)).sort().map(e=>({id:e.toLowerCase(),name:e}))}().then(e=>{P(e);const t=e.find(e=>e.id===h)?h:e[0].id;A(t),Kt(t).then(e=>{oe.current||(T(e),D(!1))}).catch(e=>J({definitions:e}))})},[h]),V(()=>{J({})},[M]);const de=te("conditions"in k?k.conditions:b.conditions);for(const e in _)ne(de,e,_[e]);const ue="dynamicConditions"in k?k.dynamicConditions:b.dynamicConditions;function pe(){const e=function({selectedDefinition:e,selectedFieldOptions:t,loadedLists:n}){return{description:Te({loadedLists:n||{},selectedDefinition:e,selectedFieldOptions:t}),name:(a=e,$e(a)||a.description)};var a}({loadedLists:Y,selectedDefinition:H,selectedFieldOptions:M});let t=e.name;return e.description&&(t+=` (${e.description})`),t}function me(e){Q(!0),Xt.post({data:e,url:"/me/automation_subscriptions"}).then(()=>{null!=a&&a.onConfirm&&K?(f(),a.onConfirm(ge({},e))):window.location.reload()}).catch(e=>{Q(!1),e.errors?J({automation:e.errors}):alert("something even worse happened!")})}return e(i,{paddingTop:4,spacing:2,children:[w&&t(s,{children:e(r,{style:{color:ze.neutral24,fontSize:16,lineHeight:1.65,marginBottom:16},children:[w," ",t(m,{external:!0,to:o,children:"Learn more"})]})}),G.automation&&t(p,ge({},Qt,{children:t(r,{children:"There was an error creating your automation. Please change your selections and try again or contact support if the problem persists."})})),e(i,{spacing:1,children:[t(l.InputLabel,{color:ze.neutral12,controls:"select-trigger-event",fontSize:"16px",fontWeight:600,children:"When a person..."}),t(c,{id:"select-trigger-event",onChange:({selectedValue:e})=>(e=>{C(e),S({})})(e),size:"lg",value:k,children:b.events.map((e,n)=>t(c.Option,{value:e,children:e.description},`${e.name}_${n}`))}),(null==ue?void 0:ue.length)>0&&t(qt,{canAccessPeople:re,definitionFields:ue,selectedFieldOptions:_,onChange:S,loadedLists:{},loadingLists:{},loadListForField:()=>null})]}),e(i,{spacing:1,children:[$.length>0?t(rn,{selectedApp:O,operationApps:$,onOperationAppChange:e=>{A(e),D(!0),T([]),oe.current=e,j(null),E({}),J({}),Kt(e).then(T).then(()=>D(!1)).catch(e=>J({definitions:e}))}}):e(i,{spacing:1,children:[t(r,{color:ze.neutral12,fontSize:"16px",fontWeight:600,children:"Then perform an action in..."}),e(i,{axis:"horizontal",alignment:"center",spacing:1,paddingHorizontal:1.75,paddingVertical:1,radius:4,border:`1px solid ${ze.neutral88}`,children:[t(z,{size:"xs"}),t(r,{fontSize:16,lineHeight:2.75,children:"Loading"})]})]}),G.definitions?t(p,ge({marginTop:1},Qt,{children:t(r,{children:"There was a problem looking up automations. Please contact support if the problem persists."})})):I?t(sn,{}):t(It,{selectedOperation:H,operationDefinitions:F,onOperationDefinitionChange:e=>{j(e),J({}),E({})}})]}),H&&(G.selected_definition?t(p,ge({},Qt,{children:t(r,{children:"There was a problem looking up automation options. Please contact support if the problem persists."})})):e(n,{children:[t(qt,{canAccessPeople:re,definitionFields:H.definitionFields||[],onChange:E,selectedFieldOptions:M,loadedLists:Y,loadListForField:ce,loadingLists:q}),(null==a?void 0:a.label)&&t(L,{disabled:X||tn(H,M),label:a.label,checked:K,onChange:()=>ee(!K)}),null==k||null==(x=k.triggerParams)?void 0:x.map((e,n)=>t(L,{label:e.description,checked:ae&&ae[e.key]||e.defaultValue,onChange:t=>{ie(n=>ge({},n,{[`${e.key}`]:t.target.checked}))}},`${e.key}_${n}`)),le&&t(p,ge({},Qt,{children:e(i,{axis:"horizontal",spacing:1.5,children:[t(g,{size:3,name:"general.exclamationTriangle",color:"error"}),t(r,{dangerouslySetInnerHTML:{__html:null==(y=H.footerMessage)?void 0:y.html}})]})}))]})),u&&t("pre",{children:JSON.stringify({description:H&&pe(),loadedLists:Y,selectedDefinition:H,selectedFieldOptions:M,triggerConditions:de},null,4)}),e(i,{alignment:"center",axis:"horizontal",borderTop:`1px solid ${ze.neutral88}`,distribution:"end",marginTop:2,marginHorizontal:-4,paddingHorizontal:4,paddingTop:3,spacing:2,children:[t(d,{color:ze.neutral12,"data-modal-close":!0,fontWeight:400,onClick:f,size:"md",title:"Cancel",variant:"naked"}),t(d,{disabled:X||le||tn(H,M),onClick:function(){if(X)return;const e=ge({},M);H.definitionIdentifier&&(e.definition_identifier=H.definitionIdentifier);const t={_e:b.resource,data:{attributes:{description:pe(),name:k.name,operation_app_name:O,operation_definition_class_name:H.definitionClass,operation_params:e,trigger_conditions:de,trigger_params:ae},type:"AutomationSubscription"}};K?ke.fire({cancelButtonText:"Cancel",confirmButtonText:"Yes, perform action",text:"This will happen immediately after creating your new automation. Are you sure?",title:`${a.label}?`}).then(e=>{e.value?me(t):(Q(!1),ee(!1))}):me(t)},size:"md",theme:"primary",title:on(H,M),variant:"fill","data-testid":"create-automation"})]})]})};function tn(e,t){if(e){const n=Fe(e.definitionFields,t),a=n.filter(e=>e.required),i=n.filter(e=>nn(e));return!a.every(e=>an(e,t))||!i.every(e=>an(e,t))}return!0}function nn(e){return"Select"===e.kind||"SelectSearch"===e.kind}function an(e,t){return nn(e)?t.hasOwnProperty(e.id):t.hasOwnProperty(e.id)&&t[e.id]&&""!==t[e.id].toString().trim()}function on(e,t){const n=function(e,t){if(null==e||!e.definitionFields)return;const n=Fe(e.definitionFields,t);for(const e of n)if(e.required&&!an(e,t))return e.description}(e,t);return e?n?`Select a${n.charAt(0).match(/[aeiou]/i)?"n":""} ${n.toLowerCase()}`:"Create automation":"Select an action"}const rn=({onOperationAppChange:n,operationApps:a,selectedApp:o})=>e(i,{spacing:1,children:[t(l.InputLabel,{color:ze.neutral12,controls:"select-product",fontSize:"16px",fontWeight:600,children:"Then perform an action in..."}),t(c,{autoFocus:!0,id:"select-product",onChange:({selectedValue:e})=>{n(e)},size:"lg",value:o,children:a.map(e=>t(c.Option,{value:e.id,children:e.name},e.id))})]}),sn=()=>e(i,{axis:"horizontal",alignment:"center",spacing:1,paddingHorizontal:1.75,paddingVertical:1,radius:4,border:`1px solid ${ze.neutral88}`,children:[t(z,{size:"xs"}),t(r,{fontSize:16,lineHeight:2.75,children:"Loading"})]});function ln({onClick:e}){return t(d,{as:"button",height:2,icon:{color:ze.neutral62,name:"general.x"},onClick:e,size:"sm",title:"Close",variant:"naked"})}function cn({children:n,onRequestClose:a,open:r,theme:s}){/*#__PURE__*/return he(e(w,{theme:s,children:[e(f,{open:r,onRequestClose:a,maxWidth:75,boxShadow:"0 0 20px rgba(0, 0, 0, 0.15)",padding:4,paddingBottom:3,radius:8,zIndex:10009,children:[e(i,{axis:"horizontal",distribution:"space-between",alignment:"center",children:[t(o,{level:2,color:ze.neutral12,fontWeight:500,fontSize:"25px",lineHeight:"1.4",children:"Create automation"}),t(ln,{onClick:a})]}),n]}),t("style",{children:"\n .swal2-container.swal2-backdrop-show { z-index: 10001 }\n "})]}),document.body)}var dn='.swal2-popup.swal2-toast{align-items:stretch;background:#fff;box-shadow:0 0 .625em #d9d9d9;flex-direction:column;overflow-y:hidden;padding:1.25em;width:auto}.swal2-popup.swal2-toast .swal2-header{flex-direction:row;padding:0}.swal2-popup.swal2-toast .swal2-title{flex-grow:1;font-size:1em;justify-content:flex-start;margin:0 .625em}.swal2-popup.swal2-toast .swal2-loading{justify-content:center}.swal2-popup.swal2-toast .swal2-input{font-size:1em;height:2em;margin:.3125em auto}.swal2-popup.swal2-toast .swal2-validation-message{font-size:1em}.swal2-popup.swal2-toast .swal2-footer{font-size:.8em;margin:.5em 0 0;padding:.5em 0 0}.swal2-popup.swal2-toast .swal2-close{height:.8em;line-height:.8;position:static;width:.8em}.swal2-popup.swal2-toast .swal2-content{font-size:1em;justify-content:flex-start;margin:0 .625em;padding:0;text-align:initial}.swal2-popup.swal2-toast .swal2-html-container{padding:.625em 0 0}.swal2-popup.swal2-toast .swal2-html-container:empty{padding:0}.swal2-popup.swal2-toast .swal2-icon{height:2em;margin:0 .5em 0 0;min-width:2em;width:2em}.swal2-popup.swal2-toast .swal2-icon .swal2-icon-content{align-items:center;display:flex;font-size:1.8em;font-weight:700}@media (-ms-high-contrast:active),(-ms-high-contrast:none){.swal2-popup.swal2-toast .swal2-icon .swal2-icon-content{font-size:.25em}}.swal2-popup.swal2-toast .swal2-icon.swal2-success .swal2-success-ring{height:2em;width:2em}.swal2-popup.swal2-toast .swal2-icon.swal2-error [class^=swal2-x-mark-line]{top:.875em;width:1.375em}.swal2-popup.swal2-toast .swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=left]{left:.3125em}.swal2-popup.swal2-toast .swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=right]{right:.3125em}.swal2-popup.swal2-toast .swal2-actions{align-self:stretch;flex:1;flex-basis:auto!important;height:2.2em;height:auto;margin:.3125em .3125em 0;padding:0;width:auto}.swal2-popup.swal2-toast .swal2-styled{font-size:1em;margin:.125em .3125em;padding:.3125em .625em}.swal2-popup.swal2-toast .swal2-styled:focus{box-shadow:0 0 0 1px #fff,0 0 0 3px rgba(100,150,200,.5)}.swal2-popup.swal2-toast .swal2-success{border-color:#a5dc86}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-circular-line]{border-radius:50%;height:3em;position:absolute;transform:rotate(45deg);width:1.6em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-circular-line][class$=left]{border-radius:4em 0 0 4em;left:-.5em;top:-.8em;transform:rotate(-45deg);transform-origin:2em 2em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-circular-line][class$=right]{border-radius:0 4em 4em 0;left:.9375em;top:-.25em;transform-origin:0 1.5em}.swal2-popup.swal2-toast .swal2-success .swal2-success-ring{height:2em;width:2em}.swal2-popup.swal2-toast .swal2-success .swal2-success-fix{height:2.6875em;left:.4375em;top:0;width:.4375em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-line]{height:.3125em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-line][class$=tip]{left:.1875em;top:1.125em;width:.75em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-line][class$=long]{right:.1875em;top:.9375em;width:1.375em}.swal2-popup.swal2-toast .swal2-success.swal2-icon-show .swal2-success-line-tip{animation:swal2-toast-animate-success-line-tip .75s}.swal2-popup.swal2-toast .swal2-success.swal2-icon-show .swal2-success-line-long{animation:swal2-toast-animate-success-line-long .75s}.swal2-popup.swal2-toast.swal2-show{animation:swal2-toast-show .5s}.swal2-popup.swal2-toast.swal2-hide{animation:swal2-toast-hide .1s forwards}.swal2-container{-webkit-overflow-scrolling:touch;align-items:center;bottom:0;display:flex;flex-direction:row;justify-content:center;left:0;overflow-x:hidden;padding:16px;position:fixed;right:0;top:0;transition:background-color .1s;z-index:1060}.swal2-container.swal2-backdrop-show,.swal2-container.swal2-noanimation{background:rgba(0,0,0,.4)}.swal2-container.swal2-backdrop-hide{background:transparent!important}.swal2-container.swal2-top{align-items:flex-start}.swal2-container.swal2-top-left,.swal2-container.swal2-top-start{align-items:flex-start;justify-content:flex-start}.swal2-container.swal2-top-end,.swal2-container.swal2-top-right{align-items:flex-start;justify-content:flex-end}.swal2-container.swal2-center{align-items:center}.swal2-container.swal2-center-left,.swal2-container.swal2-center-start{align-items:center;justify-content:flex-start}.swal2-container.swal2-center-end,.swal2-container.swal2-center-right{align-items:center;justify-content:flex-end}.swal2-container.swal2-bottom{align-items:flex-end}.swal2-container.swal2-bottom-left,.swal2-container.swal2-bottom-start{align-items:flex-end;justify-content:flex-start}.swal2-container.swal2-bottom-end,.swal2-container.swal2-bottom-right{align-items:flex-end;justify-content:flex-end}.swal2-container.swal2-bottom-end>:first-child,.swal2-container.swal2-bottom-left>:first-child,.swal2-container.swal2-bottom-right>:first-child,.swal2-container.swal2-bottom-start>:first-child,.swal2-container.swal2-bottom>:first-child{margin-top:auto}.swal2-container.swal2-grow-fullscreen>.swal2-modal{align-self:stretch;display:flex!important;flex:1;justify-content:center}.swal2-container.swal2-grow-row>.swal2-modal{align-content:center;display:flex!important;flex:1;justify-content:center}.swal2-container.swal2-grow-column{flex:1;flex-direction:column}.swal2-container.swal2-grow-column.swal2-bottom,.swal2-container.swal2-grow-column.swal2-center,.swal2-container.swal2-grow-column.swal2-top{align-items:center}.swal2-container.swal2-grow-column.swal2-bottom-left,.swal2-container.swal2-grow-column.swal2-bottom-start,.swal2-container.swal2-grow-column.swal2-center-left,.swal2-container.swal2-grow-column.swal2-center-start,.swal2-container.swal2-grow-column.swal2-top-left,.swal2-container.swal2-grow-column.swal2-top-start{align-items:flex-start}.swal2-container.swal2-grow-column.swal2-bottom-end,.swal2-container.swal2-grow-column.swal2-bottom-right,.swal2-container.swal2-grow-column.swal2-center-end,.swal2-container.swal2-grow-column.swal2-center-right,.swal2-container.swal2-grow-column.swal2-top-end,.swal2-container.swal2-grow-column.swal2-top-right{align-items:flex-end}.swal2-container.swal2-grow-column>.swal2-modal{align-content:center;display:flex!important;flex:1;justify-content:center}.swal2-container.swal2-no-transition{transition:none!important}.swal2-container:not(.swal2-top):not(.swal2-top-start):not(.swal2-top-end):not(.swal2-top-left):not(.swal2-top-right):not(.swal2-center-start):not(.swal2-center-end):not(.swal2-center-left):not(.swal2-center-right):not(.swal2-bottom):not(.swal2-bottom-start):not(.swal2-bottom-end):not(.swal2-bottom-left):not(.swal2-bottom-right):not(.swal2-grow-fullscreen)>.swal2-modal{margin:auto}@media (-ms-high-contrast:active),(-ms-high-contrast:none){.swal2-container .swal2-modal{margin:0!important}}.swal2-popup{background:#fff;border:none;border-radius:5px;box-sizing:border-box;display:none;flex-direction:column;font-family:inherit;font-size:1rem;justify-content:center;max-width:100%;padding:24px 24px 20px;position:relative;width:512px}.swal2-popup:focus{outline:none}.swal2-popup.swal2-loading{overflow-y:hidden}.swal2-header{align-items:center;display:flex;flex-direction:column;padding:0 1.8em}.swal2-title{word-wrap:break-word;color:#595959;font-size:25px;font-weight:600;margin:0 0 18px;max-width:100%;padding:0;position:relative;text-align:center;text-transform:none}.swal2-actions{align-items:center;box-sizing:border-box;display:flex;flex-wrap:wrap;justify-content:center;margin:40px auto 0;padding:12px 0 0;width:100%;z-index:1}.swal2-actions:not(.swal2-loading) .swal2-styled[disabled]{opacity:.4}.swal2-actions:not(.swal2-loading) .swal2-styled:hover{background-image:linear-gradient(rgba(0,0,0,.1),rgba(0,0,0,.1))}.swal2-actions:not(.swal2-loading) .swal2-styled:active{background-image:linear-gradient(rgba(0,0,0,.2),rgba(0,0,0,.2))}.swal2-loader{align-items:center;animation:swal2-rotate-loading 1.5s linear 0s infinite normal;border-color:#2778c4 transparent;border-radius:100%;border-style:solid;border-width:.25em;display:none;height:2.2em;justify-content:center;margin:0 1.875em;width:2.2em}.swal2-styled{box-shadow:none;font-weight:400;margin:4px;padding:8px 24px}.swal2-styled:not([disabled]){cursor:pointer}.swal2-styled.swal2-confirm{background:initial;background-color:#1f93ff;border:0;border-radius:3px;color:#fff;font-size:16px}.swal2-styled.swal2-deny{background:initial;background-color:#e75146;border:0;border-radius:3px;color:#fff;font-size:16px}.swal2-styled.swal2-cancel{background:initial;background-color:transparent;border:0;border-radius:3px;color:#848484;font-size:16px}.swal2-styled:focus{box-shadow:0 0 0 3px rgba(100,150,200,.5);outline:none}.swal2-styled::-moz-focus-inner{border:0}.swal2-footer{border-top:1px solid #eee;color:#545454;font-size:1em;justify-content:center;margin:1.25em 0 0;padding:1em 0 0}.swal2-timer-progress-bar-container{border-bottom-left-radius:5px;border-bottom-right-radius:5px;bottom:0;height:.25em;left:0;overflow:hidden;position:absolute;right:0}.swal2-timer-progress-bar{background:rgba(0,0,0,.2);height:.25em;width:100%}.swal2-image{margin:24px auto 26px;max-width:100%}.swal2-close{align-items:center;background:transparent;border:none;border-radius:5px;color:#ccc;cursor:pointer;font-family:serif;font-size:2.5em;height:1.2em;justify-content:center;line-height:1.2;overflow:hidden;padding:0;position:absolute;right:0;top:0;transition:color .1s ease-out;width:1.2em;z-index:2}.swal2-close:hover{background:transparent;color:#f27474;transform:none}.swal2-close:focus{box-shadow:inset 0 0 0 3px rgba(100,150,200,.5);outline:none}.swal2-close::-moz-focus-inner{border:0}.swal2-content{word-wrap:break-word;color:#848484;font-size:16px;font-weight:400;justify-content:center;line-height:1.4em;margin:-5px 0;padding:0 1.6em;text-align:center;z-index:1}.swal2-checkbox,.swal2-file,.swal2-input,.swal2-radio,.swal2-select,.swal2-textarea{margin:1em auto}.swal2-file,.swal2-input,.swal2-textarea{background:inherit;border:1px solid #d9d9d9;border-radius:.1875em;box-shadow:inset 0 1px 1px rgba(0,0,0,.06);box-sizing:border-box;color:inherit;font-size:1.125em;transition:border-color .3s,box-shadow .3s;width:100%}.swal2-file.swal2-inputerror,.swal2-input.swal2-inputerror,.swal2-textarea.swal2-inputerror{border-color:#f27474!important;box-shadow:0 0 2px #f27474!important}.swal2-file:focus,.swal2-input:focus,.swal2-textarea:focus{border:1px solid #b4dbed;box-shadow:0 0 0 3px rgba(100,150,200,.5);outline:none}.swal2-file::-moz-placeholder,.swal2-input::-moz-placeholder,.swal2-textarea::-moz-placeholder{color:#ccc}.swal2-file::placeholder,.swal2-input::placeholder,.swal2-textarea::placeholder{color:#ccc}.swal2-range{background:#fff;margin:1em auto}.swal2-range input{width:80%}.swal2-range output{color:inherit;font-weight:600;text-align:center;width:20%}.swal2-range input,.swal2-range output{font-size:1.125em;height:2.625em;line-height:2.625em;padding:0}.swal2-input{height:2.625em;padding:0 .75em}.swal2-input[type=number]{max-width:10em}.swal2-file{background:inherit;font-size:1.125em}.swal2-textarea{height:6.75em;padding:.75em}.swal2-select{background:inherit;color:inherit;font-size:1.125em;max-width:100%;min-width:50%;padding:.375em .625em}.swal2-checkbox,.swal2-radio{align-items:center;background:#fff;color:inherit;justify-content:center}.swal2-checkbox label,.swal2-radio label{font-size:1.125em;margin:0 .6em}.swal2-checkbox input,.swal2-radio input{flex-shrink:0;margin:0 .4em}.swal2-input-label{display:flex;justify-content:center;margin:1em auto}.swal2-validation-message{align-items:center;background:#f0f0f0;color:#666;font-size:1em;font-weight:300;justify-content:center;margin:0 -2.7em;overflow:hidden;padding:.625em}.swal2-validation-message:before{background-color:#f27474;border-radius:50%;color:#fff;content:"!";display:inline-block;font-weight:600;height:1.5em;line-height:1.5em;margin:0 .625em;min-width:1.5em;text-align:center;width:1.5em}.swal2-icon{border:.25em solid #000;border-radius:50%;box-sizing:content-box;cursor:default;font-family:inherit;height:5em;justify-content:center;line-height:5em;margin:24px auto 32px;position:relative;-webkit-user-select:none;-moz-user-select:none;user-select:none;width:5em}.swal2-icon .swal2-icon-content{align-items:center;display:flex;font-size:3.75em}.swal2-icon.swal2-error{border-color:#f27474;color:#f27474}.swal2-icon.swal2-error .swal2-x-mark{flex-grow:1;position:relative}.swal2-icon.swal2-error [class^=swal2-x-mark-line]{background-color:#f27474;border-radius:.125em;display:block;height:.3125em;position:absolute;top:2.3125em;width:2.9375em}.swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=left]{left:1.0625em;transform:rotate(45deg)}.swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=right]{right:1em;transform:rotate(-45deg)}.swal2-icon.swal2-error.swal2-icon-show{animation:swal2-animate-error-icon .5s}.swal2-icon.swal2-error.swal2-icon-show .swal2-x-mark{animation:swal2-animate-error-x-mark .5s}.swal2-icon.swal2-warning{border-color:#facea8;color:#f8bb86}.swal2-icon.swal2-info{border-color:#9de0f6;color:#3fc3ee}.swal2-icon.swal2-question{border-color:#c9dae1;color:#87adbd}.swal2-icon.swal2-success{border-color:#a5dc86;color:#a5dc86}.swal2-icon.swal2-success [class^=swal2-success-circular-line]{border-radius:50%;height:7.5em;position:absolute;transform:rotate(45deg);width:3.75em}.swal2-icon.swal2-success [class^=swal2-success-circular-line][class$=left]{border-radius:7.5em 0 0 7.5em;left:-2.0635em;top:-.4375em;transform:rotate(-45deg);transform-origin:3.75em 3.75em}.swal2-icon.swal2-success [class^=swal2-success-circular-line][class$=right]{border-radius:0 7.5em 7.5em 0;left:1.875em;top:-.6875em;transform:rotate(-45deg);transform-origin:0 3.75em}.swal2-icon.swal2-success .swal2-success-ring{border:.25em solid hsla(98,55%,69%,.3);border-radius:50%;box-sizing:content-box;height:100%;left:-.25em;position:absolute;top:-.25em;width:100%;z-index:2}.swal2-icon.swal2-success .swal2-success-fix{height:5.625em;left:1.625em;position:absolute;top:.5em;transform:rotate(-45deg);width:.4375em;z-index:1}.swal2-icon.swal2-success [class^=swal2-success-line]{background-color:#a5dc86;border-radius:.125em;display:block;height:.3125em;position:absolute;z-index:2}.swal2-icon.swal2-success [class^=swal2-success-line][class$=tip]{left:.8125em;top:2.875em;transform:rotate(45deg);width:1.5625em}.swal2-icon.swal2-success [class^=swal2-success-line][class$=long]{right:.5em;top:2.375em;transform:rotate(-45deg);width:2.9375em}.swal2-icon.swal2-success.swal2-icon-show .swal2-success-line-tip{animation:swal2-animate-success-line-tip .75s}.swal2-icon.swal2-success.swal2-icon-show .swal2-success-line-long{animation:swal2-animate-success-line-long .75s}.swal2-icon.swal2-success.swal2-icon-show .swal2-success-circular-line-right{animation:swal2-rotate-success-circular-line 4.25s ease-in}.swal2-progress-steps{align-items:center;background:inherit;flex-wrap:wrap;font-weight:600;margin:0 0 1.25em;max-width:100%;padding:0}.swal2-progress-steps li{display:inline-block;position:relative}.swal2-progress-steps .swal2-progress-step{background:#2778c4;border-radius:2em;color:#fff;flex-shrink:0;height:2em;line-height:2em;text-align:center;width:2em;z-index:20}.swal2-progress-steps .swal2-progress-step.swal2-active-progress-step{background:#2778c4}.swal2-progress-steps .swal2-progress-step.swal2-active-progress-step~.swal2-progress-step{background:#add8e6;color:#fff}.swal2-progress-steps .swal2-progress-step.swal2-active-progress-step~.swal2-progress-step-line{background:#add8e6}.swal2-progress-steps .swal2-progress-step-line{background:#2778c4;flex-shrink:0;height:.4em;margin:0 -1px;width:2.5em;z-index:10}[class^=swal2]{-webkit-tap-highlight-color:transparent}.swal2-hide,.swal2-show{animation:none}.swal2-noanimation{transition:none}.swal2-scrollbar-measure{height:50px;overflow:scroll;position:absolute;top:-9999px;width:50px}.swal2-rtl .swal2-close{left:0;right:auto}.swal2-rtl .swal2-timer-progress-bar{left:auto;right:0}@supports (-ms-accelerator:true){.swal2-range input{width:100%!important}.swal2-range output{display:none}}@media (-ms-high-contrast:active),(-ms-high-contrast:none){.swal2-range input{width:100%!important}.swal2-range output{display:none}}@keyframes swal2-toast-show{0%{transform:translateY(-.625em) rotate(2deg)}33%{transform:translateY(0) rotate(-2deg)}66%{transform:translateY(.3125em) rotate(2deg)}to{transform:translateY(0) rotate(0deg)}}@keyframes swal2-toast-hide{to{opacity:0;transform:rotate(1deg)}}@keyframes swal2-toast-animate-success-line-tip{0%{left:.0625em;top:.5625em;width:0}54%{left:.125em;top:.125em;width:0}70%{left:-.25em;top:.625em;width:1.625em}84%{left:.75em;top:1.0625em;width:.5em}to{left:.1875em;top:1.125em;width:.75em}}@keyframes swal2-toast-animate-success-line-long{0%{right:1.375em;top:1.625em;width:0}65%{right:.9375em;top:1.25em;width:0}84%{right:0;top:.9375em;width:1.125em}to{right:.1875em;top:.9375em;width:1.375em}}@keyframes swal2-show{0%{transform:scale(.7)}45%{transform:scale(1.05)}80%{transform:scale(.95)}to{transform:scale(1)}}@keyframes swal2-hide{0%{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.5)}}@keyframes swal2-animate-success-line-tip{0%{left:.0625em;top:1.1875em;width:0}54%{left:.125em;top:1.0625em;width:0}70%{left:-.375em;top:2.1875em;width:3.125em}84%{left:1.3125em;top:3em;width:1.0625em}to{left:.8125em;top:2.8125em;width:1.5625em}}@keyframes swal2-animate-success-line-long{0%{right:2.875em;top:3.375em;width:0}65%{right:2.875em;top:3.375em;width:0}84%{right:0;top:2.1875em;width:3.4375em}to{right:.5em;top:2.375em;width:2.9375em}}@keyframes swal2-rotate-success-circular-line{0%{transform:rotate(-45deg)}5%{transform:rotate(-45deg)}12%{transform:rotate(-405deg)}to{transform:rotate(-405deg)}}@keyframes swal2-animate-error-x-mark{0%{margin-top:1.625em;opacity:0;transform:scale(.4)}50%{margin-top:1.625em;opacity:0;transform:scale(.4)}80%{margin-top:-.375em;transform:scale(1.15)}to{margin-top:0;opacity:1;transform:scale(1)}}@keyframes swal2-animate-error-icon{0%{opacity:0;transform:rotateX(100deg)}to{opacity:1;transform:rotateX(0deg)}}@keyframes swal2-rotate-loading{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}}body.swal2-shown:not(.swal2-no-backdrop):not(.swal2-toast-shown){overflow:hidden}body.swal2-height-auto{height:auto!important}body.swal2-no-backdrop .swal2-container{background-color:transparent!important;bottom:auto;left:auto;max-width:calc(100% - 32px);right:auto;top:auto}body.swal2-no-backdrop .swal2-container>.swal2-modal{box-shadow:0 0 10px rgba(0,0,0,.4)}body.swal2-no-backdrop .swal2-container.swal2-top{left:50%;top:0;transform:translateX(-50%)}body.swal2-no-backdrop .swal2-container.swal2-top-left,body.swal2-no-backdrop .swal2-container.swal2-top-start{left:0;top:0}body.swal2-no-backdrop .swal2-container.swal2-top-end,body.swal2-no-backdrop .swal2-container.swal2-top-right{right:0;top:0}body.swal2-no-backdrop .swal2-container.swal2-center{left:50%;top:50%;transform:translate(-50%,-50%)}body.swal2-no-backdrop .swal2-container.swal2-center-left,body.swal2-no-backdrop .swal2-container.swal2-center-start{left:0;top:50%;transform:translateY(-50%)}body.swal2-no-backdrop .swal2-container.swal2-center-end,body.swal2-no-backdrop .swal2-container.swal2-center-right{right:0;top:50%;transform:translateY(-50%)}body.swal2-no-backdrop .swal2-container.swal2-bottom{bottom:0;left:50%;transform:translateX(-50%)}body.swal2-no-backdrop .swal2-container.swal2-bottom-left,body.swal2-no-backdrop .swal2-container.swal2-bottom-start{bottom:0;left:0}body.swal2-no-backdrop .swal2-container.swal2-bottom-end,body.swal2-no-backdrop .swal2-container.swal2-bottom-right{bottom:0;right:0}@media print{body.swal2-shown:not(.swal2-no-backdrop):not(.swal2-toast-shown){overflow-y:scroll!important}body.swal2-shown:not(.swal2-no-backdrop):not(.swal2-toast-shown)>[aria-hidden=true]{display:none}body.swal2-shown:not(.swal2-no-backdrop):not(.swal2-toast-shown) .swal2-container{position:static!important}}body.swal2-toast-shown .swal2-container{background-color:transparent}body.swal2-toast-shown .swal2-container.swal2-top{bottom:auto;left:50%;right:auto;top:0;transform:translateX(-50%)}body.swal2-toast-shown .swal2-container.swal2-top-end,body.swal2-toast-shown .swal2-container.swal2-top-right{bottom:auto;left:auto;right:0;top:0}body.swal2-toast-shown .swal2-container.swal2-top-left,body.swal2-toast-shown .swal2-container.swal2-top-start{bottom:auto;left:0;right:auto;top:0}body.swal2-toast-shown .swal2-container.swal2-center-left,body.swal2-toast-shown .swal2-container.swal2-center-start{bottom:auto;left:0;right:auto;top:50%;transform:translateY(-50%)}body.swal2-toast-shown .swal2-container.swal2-center{bottom:auto;left:50%;right:auto;top:50%;transform:translate(-50%,-50%)}body.swal2-toast-shown .swal2-container.swal2-center-end,body.swal2-toast-shown .swal2-container.swal2-center-right{bottom:auto;left:auto;right:0;top:50%;transform:translateY(-50%)}body.swal2-toast-shown .swal2-container.swal2-bottom-left,body.swal2-toast-shown .swal2-container.swal2-bottom-start{bottom:0;left:0;right:auto;top:auto}body.swal2-toast-shown .swal2-container.swal2-bottom{bottom:0;left:50%;right:auto;top:auto;transform:translateX(-50%)}body.swal2-toast-shown .swal2-container.swal2-bottom-end,body.swal2-toast-shown .swal2-container.swal2-bottom-right{bottom:0;left:auto;right:0;top:auto}.swal2-actions{border-top:1px solid #e0e0e0}';const un=new a({app:"webhooks",version:"2022-10-20"});function pn({afterCreateOptions:n,automations:a,blankStateLink:r,canCreate:l,defaultApp:c,description:u,hasActiveAutomations:p,loading:m,onPauseAutomations:h,theme:w,trigger:f}){const[b,v]=W(!1),x={size:"md",theme:"primary"},y=l&&!p;return e(i,{axis:"horizontal",alignment:"center",backgroundColor:y?ze.statusWarning94:void 0,borderBottom:y?void 0:`1px solid ${ze.neutral88}`,"data-testid":"automations-header",distribution:"space-between",marginHorizontal:-3,marginBottom:2,marginTop:-3,paddingHorizontal:3,paddingVertical:2,spacing:2,wrap:!0,zIndex:2,children:[l&&!p?e(i,{axis:"horizontal",alignment:"center",marginHorizontal:1,spacing:1,children:[t(g,{size:2,color:ze.statusWarning49,name:"general.exclamationTriangle"}),t(o,{color:ze.neutral12,level:2,size:"18px",children:"Automations are currently paused"})]}):t(o,{color:ze.neutral12,level:2,size:"18px",children:m?"Active automations":He(a.length,"active automation")}),l&&(p?e(i,{axis:"horizontal",alignment:"center",spacing:1,children:[a.length>0&&t(d,ge({onClick:h},x,{variant:"outline",children:"Pause automations"})),t(d,ge({},x,{variant:"fill",onClick:()=>v(!0),children:"Create automation"})),t(cn,{open:b,onRequestClose:()=>v(!1),theme:w,children:t(en,{description:u,blankStateLink:r,defaultApp:c,trigger:f,onRequestClose:()=>v(!1),afterCreateOptions:n})})]}):t(s,{children:e(i,{axis:"horizontal",alignment:"center",spacing:1,children:[t(d,ge({},x,{backgroundColor:"success",hover:{backgroundColor:"success-dark"},active:{backgroundColor:"success-darker"},onClick:h,children:"Enable automations"})),t(d,ge({},x,{disabled:!0,tooltip:{title:"Automations must be enabled to create new ones"},children:"Create automation"}))]})}))]})}function mn({afterCreateOptions:a,blankStateDescription:l,blankStateLink:c="https://pcopeople.zendesk.com/hc/en-us/articles/217582148-Automations",currentPersonId:u,currentPersonCanCreate:p,defaultApp:h,incomingAutomationsParam:g,theme:f,trigger:b,currentOrganization:v,permissionDeniedReason:x="You need permissions of Editor or above to add an automation."}){V(()=>{if(!b)return O(!1);(async function(e){const{data:t}=await vt.get({data:{_e:e,fields:{AutomationSubscription:"id,description,created_at,created_by,operation_app_name,operation_definition_class_name,operation_params,active,created_by_name,name,trigger_admin_url,events_status,trigger_params",Person:"name"},include:"created_by"},url:"automation_subscriptions"});return t})(b.resource).then(yt).then(kt).then(_e).then(k).then(()=>O(!1))},[null==b?void 0:b.resource]);const[y,k]=W([]),[S,O]=W(!0),[A,$]=W(!1),{dateFormat:L,twentyFourHourTime:P,olsonTimeZone:F}=v,T=new URLSearchParams(window.location.search).get("automation_id"),I=ge({},f,{icons:ge({},Ce)});V(()=>{document.body.toggleAttribute("data-loading-automations",S)},[S]);const D=!y.length||y.some(e=>e.active);function H(e){un.delete({data:{_e:b.resource},url:`/automation_subscriptions/${e}`}).then(()=>k(y.filter(t=>t.id!==e))).catch(()=>ve.fire({text:"There was a problem deleting this automation. Please try again in a few moments.",title:"Uh oh!"}))}const j={color:ze.neutral24,level:2,size:"25px",weight:700},B={color:ze.neutral45,lineHeight:3,size:3};return e(w,{theme:I,children:[e(be.Provider,{value:{dateFormat:L,olsonTimeZone:F,twentyFourHourTime:P},children:[b&&t(pn,{automations:y,blankStateLink:c,canCreate:p,loading:S,defaultApp:h,description:l,theme:I,trigger:b,hasActiveAutomations:D,onPauseAutomations:function(){un.post({data:{data:{attributes:{_e:b.resource,active:!D}}},url:"/pause_automations"}).then(()=>{window.location.reload()})},afterCreateOptions:a}),S?t(C,{image:t(z,{size:"xl"}),paddingVertical:10,title:"Loading automations..."}):b?t(s,{"data-testid":"automations-section",children:(null==y?void 0:y.length)>0?t(_,{spacing:3,marginVertical:3,minCellWidth:45,children:y.map(e=>{return t(rt,{automation:e,onDelete:H,theme:I,openHistoryNow:e.id===Number(T),trigger:{event:(n=e,b.events.find(e=>e.name===n.name)),resource:b.resource},currentPersonId:u,currentPersonCanCreate:p},e.id);var n})}):e(i,{margin:6,spacing:2,alignment:"center",mediaQueries:{lg:{axis:"horizontal",distribution:"center",spacing:6}},children:[t(s,{css:{".symbol":{height:"100%",width:"100%"}},maxWidth:24,mediaQueries:{lg:{maxWidth:40}},children:t(fe,{})}),t(i,{alignment:"center",spacing:1,maxWidth:45,mediaQueries:{lg:{alignment:"start",textAlign:"left"}},textAlign:"center",children:e(n,p?{children:[t(o,ge({},j,{children:"Add an automation"})),t(i,{alignment:"center",marginBottom:1,mediaQueries:{lg:{alignment:"start"}},spacing:1,children:e(r,ge({},B,{children:[l," ",t(m,{inline:!0,external:!0,to:c,children:"Learn more"}),"."]}))}),t(d,{as:"button",theme:"primary",variant:"fill",onClick:()=>$(!0),children:"Create automation"}),t(cn,{open:A,onRequestClose:()=>$(!1),theme:I,children:t(en,{defaultApp:h,description:l,blankStateLink:c,onRequestClose:()=>$(!1),trigger:b,afterCreateOptions:a})})]}:{children:[t(o,ge({},j,{children:"Automations"})),t(r,ge({},B,{children:x}))]})})]})}):t(n,{}),g&&t($t,{encryptedParam:g,trigger:b})]}),t("style",{children:dn})]})}export{mn as Automations};
1
+ import{jsxs as e,jsx as t,Fragment as n}from"react/jsx-runtime";import{Client as a}from"@planningcenter/api-client";import{StackView as i,Heading as o,Text as r,Box as s,Input as l,Select as c,Button as d,DataTable as u,Alert as p,Link as m,Badge as h,Icon as g,ThemeProvider as w,Modal as f,Card as b,Dropdown as v,Tooltip as x,Divider as y,Avatar as k,Summary as C,Spinner as z,TileView as _,HelperDrawer as S,Combobox as O,Highlight as A,Menu as $,Checkbox as L,TextArea as P,DateField as F,NumberField as T,Radio as I}from"@planningcenter/tapestry-react";import D,{createContext as H,useContext as j,useState as W,useEffect as V,useCallback as B,useMemo as R,useRef as N}from"react";import{isBoolean as M,camelCase as E,lowerFirst as Y,truncate as U,compact as q,uniq as Z,upperFirst as X,uniqBy as Q,groupBy as G,isEqual as J,sortBy as K,debounce as ee,cloneDeep as te,set as ne}from"lodash";import ae from"moment";import{standardAlertOptions as ie,successAlertOptions as oe,errorAlertOptions as re,standardConfirmOptions as se,destroyConfirmOptions as le,createConfirmOptions as ce}from"@planningcenter/sweetalert2";import de from"sweetalert2/dist/sweetalert2";import*as ue from"@planningcenter/icons/paths/church-center";import*as pe from"@planningcenter/icons/paths/logomark";import*as me from"@planningcenter/icons/paths/services";import{createPortal as he}from"react-dom";function ge(){return ge=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)({}).hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e},ge.apply(null,arguments)}function we(e,t){if(null==e)return{};var n={};for(var a in e)if({}.hasOwnProperty.call(e,a)){if(-1!==t.indexOf(a))continue;n[a]=e[a]}return n}const fe=()=>e("svg",{id:"automations_blank","data-name":"Automations Blank",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 111.112 84.832",className:"symbol",children:[t("title",{children:"people-automations"}),t("g",{opacity:"0.6",children:t("path",{d:"M107.784,46.051A57.416,57.416,0,0,1,85.26,75.058c-9.7,6.247-20.045,7.792-31.912,5.185-11.74-2.638-23.339-8-32.92-13.088-9.51-5.342-17-10.236-18.863-17.925C-.26,41.753,3.737,31.4,13.347,21.194,22.85,11.162,37.968,1.853,55.948.321,73.8-1.476,90.2,4.478,99.608,13.164,109.257,21.9,111.921,33.784,107.784,46.051Z",fill:"#e1f0f9"})}),e("g",{opacity:"0.2",children:[t("path",{d:"M63.086,84.317A43.515,43.515,0,0,1,42.87,79C34.056,74.379,24.712,67.422,14.3,57.728,6.616,50.227.284,43.348.489,35c.13-5.851,3.789-12.312,10.3-18.189l.951,1.054c-6.222,5.613-9.715,11.71-9.837,17.169C1.717,42.811,7.85,49.448,15.278,56.7c10.307,9.6,19.551,16.481,28.248,21.039,9.043,4.684,17.715,6.156,26.513,4.5l.262,1.4A38.914,38.914,0,0,1,63.086,84.317Z",fill:"#bac7d3"}),t("path",{d:"M81.105,80.147l-.587-1.292a56.6,56.6,0,0,0,23.515-19.828l1.183.786A58.03,58.03,0,0,1,81.105,80.147Z",fill:"#bac7d3"}),t("path",{d:"M110.025,49.27l-1.374-.356a28.351,28.351,0,0,0-4.014-22.991C97.189,14.135,82.488,5.177,66.267,2.538A66.6,66.6,0,0,0,25.738,8.55l-.622-1.275a68,68,0,0,1,41.39-6.136c16.6,2.7,31.672,11.905,39.327,24.019A29.732,29.732,0,0,1,110.025,49.27Z",fill:"#bac7d3"})]}),t("path",{d:"M81,27.269v31.8a2.685,2.685,0,0,1-2.685,2.685H44.564a2.685,2.685,0,0,1-2.685-2.685V15.425a2.685,2.685,0,0,1,2.685-2.685h21.91a2.681,2.681,0,0,1,1.9.786L80.217,25.371A2.685,2.685,0,0,1,81,27.269Z",fill:"#fff"}),t("path",{d:"M68.479,13.633v9.8a2.035,2.035,0,0,0,2.035,2.034h9.877Z",fill:"#c9d8e2"}),t("rect",{x:"51.214",y:"41.285",width:"20.221",height:"2.791",rx:"1.395",ry:"1.395",fill:"#dae5ed"}),t("rect",{x:"51.214",y:"48.434",width:"20.221",height:"2.791",rx:"1.395",ry:"1.395",fill:"#dae5ed"}),t("rect",{x:"51.214",y:"34.136",width:"20.221",height:"2.791",rx:"1.395",ry:"1.395",fill:"#dae5ed"}),t("rect",{x:"11.771",y:"44.005",width:"50.915",height:"6.664",transform:"translate(-22.93 44.557) rotate(-49.171)",fill:"#454942"}),t("path",{d:"M56.283,30.38l-7.557,8.745a5.968,5.968,0,0,0-2.005-2.734,6.292,6.292,0,0,0-3.036-1.624l7.555-8.743a6.275,6.275,0,0,1,3.038,1.624A5.959,5.959,0,0,1,56.283,30.38Z",fill:"#fcc846"}),t("path",{d:"M58.088,28.29l-7.556,8.745a5.968,5.968,0,0,0-2-2.734,6.3,6.3,0,0,0-3.036-1.624l7.555-8.743a6.274,6.274,0,0,1,3.037,1.624A5.959,5.959,0,0,1,58.088,28.29Z",fill:"#48a5e5"}),t("path",{d:"M58.724,10.432l1.17,2.7a2.129,2.129,0,0,0,1.4,1.207l2.843.765a.73.73,0,0,1,.1,1.375l-2.7,1.17a2.125,2.125,0,0,0-1.207,1.4L59.56,21.89a.73.73,0,0,1-1.374.1l-1.17-2.7a2.125,2.125,0,0,0-1.4-1.206l-2.843-.766a.73.73,0,0,1-.1-1.374l2.7-1.17a2.121,2.121,0,0,0,1.206-1.4l.766-2.844A.73.73,0,0,1,58.724,10.432Z",fill:"#fcc846"}),t("path",{d:"M44.544,19.294l1.024.868a.968.968,0,0,0,.814.21l1.316-.261a.333.333,0,0,1,.319.541l-.868,1.024a.968.968,0,0,0-.21.814l.261,1.316a.333.333,0,0,1-.541.319l-1.024-.868a.968.968,0,0,0-.814-.21l-1.316.261a.333.333,0,0,1-.319-.541l.868-1.024a.967.967,0,0,0,.21-.814L44,19.613A.333.333,0,0,1,44.544,19.294Z",fill:"#fcc846"}),t("path",{d:"M64.223,25.729l.869,2.005a1.575,1.575,0,0,0,1.036.895l2.109.568a.542.542,0,0,1,.075,1.02l-2,.868a1.576,1.576,0,0,0-.9,1.036l-.568,2.11a.541.541,0,0,1-1.019.074L62.955,32.3a1.572,1.572,0,0,0-1.036-.895l-2.109-.568a.542.542,0,0,1-.075-1.02l2.005-.868a1.572,1.572,0,0,0,.895-1.036L63.2,25.8A.541.541,0,0,1,64.223,25.729Z",fill:"#fcc846"})]}),be=/*#__PURE__*/H({dateFormat:null,olsonTimeZone:null,twentyFourHourTime:null});de.mixin(ie),de.mixin(oe);const ve=de.mixin(re),xe=de.mixin(se),ye=de.mixin(le),ke=de.mixin(ce),Ce={churchCenter:ue,logomark:pe,services:me},ze={givingBrand31:"hsl(36, 100%, 31%)",neutral12:"hsl(0, 0%, 12%)",neutral24:"hsl(0, 0%, 24%)",neutral45:"hsl(0, 0%, 45%)",neutral62:"hsl(0, 0%, 62%)",neutral68:"hsl(0, 0%, 68%)",neutral88:"hsl(0, 0%, 88%)",neutral98:"hsl(0, 0%, 98%)",statusCreate23:"hsl(86, 91%, 23%)",statusCreate27:"hsl(86, 91%, 27%)",statusCreate35:"hsl(86, 91%, 35%)",statusDelete43:"hsl(9, 61%, 43%)",statusDelete47:"hsl(8, 60%, 47%)",statusWarning49:"hsl(42, 84%, 49%)",statusWarning63:"hsl(42, 84%, 63%)",statusWarning94:"hsl(42, 87%, 94%)"};async function _e(e){return Promise.all(e.map(async e=>(function(e){return["AddToWorkflowOperationDefinition","CustomFieldBooleanOperationDefinition","CustomFieldCheckboxesOperationDefinition","CustomFieldDateOperationDefinition","CustomFieldNumberOperationDefinition","CustomFieldSelectOperationDefinition","CustomFieldStringOperationDefinition","CustomFieldTextOperationDefinition"].includes(e.operationDefinitionClassName)}(e)&&(e.description=await async function(e){let t="";if("AddToWorkflowOperationDefinition"===e.operationDefinitionClassName){const n=(await async function(e){const{data:t}=await Oe.get({data:{fields:{Workflow:"name,archived_at"},filter:"not_archived,archived",where:{id:e}},url:"workflows"}).catch(()=>[{data:{name:""}}]);return t}(e.operationParams.workflowId))[0];if(null!=n&&n.name){let a;a=n.archivedAt?`[archived] ${n.name}`:n.name,t=e.description.replace("[Hidden Workflow]",a)}}else{const n=e.operationParams.definitionIdentifier.match(/(\d+)_field_definition/)[1],a=await async function(e){const{data:t}=await Oe.get({data:{fields:{FieldDefinition:"name,data_type,field_options",FieldOption:"value"},include:"field_options"},url:`field_definitions/${e}`}).catch(()=>({data:{name:""}}));return t}(n);a.name&&(t=e.description.replace("[Hidden Custom Field]",a.name),t+=e.operationParams.values||"checkboxes"!==a.dataType?` (${function(e,t){var n,a;switch(t.dataType){case"checkboxes":return Object.entries(e.operationParams.values).map(([e,n])=>{var a;const i=(null==(a=t.fieldOptions.find(t=>t.id===parseInt(e,10)))?void 0:a.value)||"[Hidden value]";return`${Se(n)} ${i}`}).join(", ");case"select":return e.operationParams.value?(null==(n=t.fieldOptions.find(t=>t.id===parseInt(e.operationParams.value.toString(),10)))?void 0:n.value)||"[Hidden value]":"Unanswered";case"boolean":switch(e.operationParams.value){case"true":return"Yes";case"false":return"No";default:return"Unanswered"}default:return null!=(a=e.operationParams.value)?a:"Unanswered"}}(e,a)})`:"")}return t||e.description}(e)),e)))}function Se(e){return e.charAt(0).toUpperCase()+e.slice(1)}const Oe=new a({app:"people",version:"2022-07-14"});function Ae(e){return e.listClass?`${e.id}_${e.listClass}`:"PersonSearch"===e.kind?`${e.id}_PersonSearch`:null}function $e(e){if(e.definitionClass.match(/^CustomField\w+OperationDefinition$/))return"Update [Hidden Custom Field]"}function Le(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Pe({field:e,loadedLists:t}){if(e.list)return e.list;if(Ae(e))return t[Ae(e)];throw new Error(`Don't know how to get list for ${JSON.stringify(e)}`)}function Fe(e,t){return e.filter(e=>{if(Object.prototype.hasOwnProperty.call(e,"renderIf")){const n=e.renderIf,a=Object.keys(n)[0];return M(n)?n:n[a]===t[a]}return!0})}function Te({selectedDefinition:e,selectedFieldOptions:t,loadedLists:n}){return function({selectedDefinition:e,selectedFieldOptions:t,loadedLists:n,description:a}){if("AddToWorkflowOperationDefinition"===e.definitionClass){var i;const e=n.workflow_id_WorkflowsList,o=e&&(null==(i=e.find(e=>e.value.toString()===t.workflow_id))?void 0:i.description);return a.replace(o,"[Hidden Workflow]")}return e.definitionClass.match(/^CustomField\w+OperationDefinition$/)?"":a}({description:e.definitionFields.map(e=>{var a;if(!Le(t,e.id))return null;const i=t[e.id];let o;switch(e.kind){case"Select":case"SelectSearch":case"PersonSearch":case"RadioButtons":return o=Pe({field:e,loadedLists:n}),o&&(null==(a=o.find(e=>e.value.toString()===i))?void 0:a.description);case"Checkbox":return i&&e.label;case"Checkboxes":return o=Pe({field:e,loadedLists:n}),o.filter(e=>Le(i,e.value)).map(e=>`${Se(i[e.value])} ${e.description}`).join(", ");case"NumberField":case"TextField":case"TextArea":case"DateField":return i;default:throw new Error(`Don't know how to build value for field with kind ${e.kind}`)}}).filter(e=>e).join(", "),loadedLists:n,selectedDefinition:e,selectedFieldOptions:t})}function Ie(e){return e.replace(/%m/,"MM").replace(/%d/,"DD").replace(/%Y/,"YYYY").replace(/%y/,"YY")}function De(e,t){const n=ae(e,"YYYY-MM-DD");if(!n.isValid())return"";const a=Ie(t);return n.format(a)}function He(e,t){return 1===e?`1 ${t}`:`${e} ${t}s`}function je(e){return e.replace(/s$/,"")}function We(e){const t=e.split("/");return{appName:t[0],resourceId:t[t.length-1],resourcePath:t.slice(2,-1).join("/"),resourceType:t[t.length-2]}}const Ve=new a({app:"webhooks",version:"2022-10-20"}),Be=new a({app:"people",version:"2022-07-14"}),Re={delivered:{label:"Success",value:["delivered"]},failed:{label:"Failed",value:["failed","duplicated"]},ignored:{label:"Ignored",value:["ignored_duplicated","ignored_failed","ignored_skipped"]},pending:{label:"Pending",value:["pending"]},skipped:{label:"Paused",value:["skipped"]}};async function Ne(e){const t=e.data.map(e=>Ee(e));try{const n=await async function(e){const{data:t}=await Be.get({data:{fields:{Person:"id,name"},where:{id:e.join(",")}},url:"people"});return t}(t);return{events:e,people:n}}catch(t){return{events:e,people:[]}}}function Me({events:e,people:t}){const n=e.data.reduce((e,n)=>{const a=Ee(n),i=t.find(e=>a.toString()===e.id.toString());return e.push(ge({},n,i?{person:{id:i.id,name:i.name}}:{person:{id:a,name:"[Hidden]"}})),e},[]);return ge({},e,{data:n})}function Ee(e){return e.personId}function Ye({automation:a,triggerResource:p,filterWhere:h,onEventsStatusChange:g}){var w;const{events:f,loading:b,paginationProps:v,refresh:x,params:y,setParams:k}=function(e,t,n){const[a,i]=W(),[o,r]=W(!1),[s,l]=W({}),[c,d]=W(n?{where:{status:n}}:{}),[u,p]=W(),{offset:m,paginationProps:h,resetOffset:g}=function(e,t){const[n,a]=W(0);return{offset:n,paginationProps:{currentPage:Math.floor(n/50)+1,onPageChange:function(e){a(50*(e-1))},totalPages:Math.ceil(t/50)},resetOffset:B(()=>{a(0)},[])}}(0,null==u?void 0:u.totalCount);V(()=>{o||s[m]||(r(!0),async function(e,t,n){return await Ve.get({data:ge({_e:e,fields:{Delivery:"status,response_body,created_at",Event:"id,created_at,last_delivery,payload,status,uuid,person"},include:"last_delivery",order:"-created_at"},n),url:`automation_subscriptions/${t}/events`})}(t,e,ge({offset:m,per_page:50},c)).then(Ne).then(Me).then(e=>{l(t=>ge({},t,{[m]:e.data})),p(e.meta),r(!1)}).catch(f))},[e,t,o,c,m,s]);const w=B(()=>{l({}),p(void 0),g()},[g]);function f(e){i(()=>{throw e})}return V(()=>{w()},[w,c]),{events:s[m]||[],loading:o,paginationProps:h,params:c,refresh:w,setParams:d}}(a.id,p,h),{dateFormat:C,olsonTimeZone:z,twentyFourHourTime:_}=j(be),S=y.where&&Object.keys(y.where).length>0,O=function(e){const t=ae(e,"YYYY-MM-DD");return ae().diff(t,"days")}(a.createdAt)<=32,A=De(a.createdAt,C),$=O?`Automation history started on ${A}`:"Automation history is saved for 32 days",L=[{cell:e=>t(Ze,{status:e.status}),css:{padding:"8px 12px"},header:"Status"},{cell:e=>ae(e.createdAt).utcOffset(z).format(function({dateFormat:e,twentyFourHourTime:t}){return`${Ie(e)} ${t?"HH:mm":"h:mm A"}`}({dateFormat:C,twentyFourHourTime:_})),header:"Date and time"},{cell:e=>t(m,{to:`/people/AC${e.person.id}`,children:e.person.name}),css:{maxWidth:"33%"},header:"Profile"},{cell:e=>t(Xe,{event:e}),css:{flex:1},header:"Message"},{cell:i=>![...Re.delivered.value,...Re.pending.value].includes(i.status)&&e(n,{children:[t(Ue,{automationId:a.id,event:i,triggerResource:p,onEventsStatusChange:g}),![...Re.ignored.value].includes(i.status)&&t(qe,{automationId:a.id,event:i,triggerResource:p,refreshHistory:x,onEventsStatusChange:g})]}),css:{textAlign:"right"},header:"",minWidth:"84px"}];return e(i,{spacing:4,children:[e(i,{spacing:.5,children:[t(o,{level:3,size:"16px",color:ze.neutral45,weight:500,children:a.description}),t(r,{color:ze.neutral45,size:5,italic:!0,children:$})]}),e(i,{spacing:2,children:[t(s,{minHeight:7,children:!b&&(f.length||S)&&e(i,{alignItems:"end",axis:"horizontal",distribution:"space-between",spacing:1,children:[e(i,{width:"max-content",children:[t(l.InputLabel,{fontWeight:500,color:ze.neutral24,controls:"select-status",children:"Filter by status"}),e(c,{id:"select-status",emptyValue:null,onChange:({selectedValue:e})=>{k({where:e?{status:e}:null})},title:"Status",value:null==(w=y.where)?void 0:w.status,children:[t(c.Option,{value:null,children:"All"}),Object.values(Re).map(e=>t(c.Option,{value:e.value.join(","),children:e.label},e.value))]})]}),t(d,{iconLeft:{name:"general.refresh"},onClick:x,theme:"primary",variant:"outline",width:12,children:"Refresh"})]})}),t(s,{maxHeight:"70vh",minHeight:36,overflow:"auto",children:t(u,ge({columns:L,data:f,empty:e(i,{alignment:"center",distribution:"center",minHeight:20,maxWidth:45,spacing:1,marginTop:S?-4:-8,marginBottom:S?4:void 0,children:[t(s,{css:{svg:{height:15,width:20}},children:t(fe,{})}),t(o,{color:ze.neutral12,fontWeight:500,level:4,size:2,children:"No history found"}),e(r,{fontSize:"16px",textAlign:"center",children:["No events ",S&&"matching your filters"," were triggered for this automation"," ",O?`since ${A}.`:"in the last 32 days."]}),S&&t(d,{marginTop:1,onClick:()=>k({}),theme:"primary",title:"Clear filters",variant:"outline"})]}),loading:b,loadingTitle:"Loading automation history...",variant:{bodyCell:{alignItems:"start",fontSize:"13px",lineHeight:"20px",padding:"10px 12px"},bodyRow:({rowData:e})=>({backgroundColor:[...Re.ignored.value].includes(e.status)?ze.neutral98:void 0,minHeight:"36px"}),headerCell:{padding:"8px 12px"},headerRow:{minHeight:"36px"}}},v))})]})]})}function Ue({automationId:e,event:n,triggerResource:a,onEventsStatusChange:i}){const[o,r]=W(n.status),s=Re.pending.value.includes(o)?"Sending":Re.delivered.value.includes(o)?"Sent":Re.skipped.value.includes(o)?"Run now":"Retry",l=Re.delivered.value.includes(o)?{color:ze.statusCreate27,name:"general.check"}:void 0;return t(d,{title:s,onClick:function(){r(Re.pending.value.join(",")),Ve.post({data:{_e:a,data:{attributes:{}}},url:`/automation_subscriptions/${e}/events/${n.id}/redeliver`}).then(e=>{r(Re.delivered.value.join(",")),i(e.meta.eventsStatus)}).catch(()=>{r(Re.failed.value.join(",")),ve.fire({text:"There was a problem retrying this automation. Please try again in a few moments.",title:"Uh oh!"})})},iconLeft:l,disabled:o!==n.status,variant:"naked",color:Re.delivered.value.includes(o)?ze.statusCreate27:Re.pending.value.includes(o)?ze.neutral68:"linkForeground",theme:"primary",size:"xs"})}function qe({automationId:e,event:n,triggerResource:a,refreshHistory:i,onEventsStatusChange:o}){return t(d,{title:"Ignore",onClick:function(){Ve.post({data:{_e:a,data:{attributes:{}}},url:`/automation_subscriptions/${e}/events/${n.id}/ignore`}).then(e=>{o(e.meta.eventsStatus)}).then(()=>i()).catch(()=>{ve.fire({text:"There was a problem ignoring this event. Please try again in a few moments.",title:"Uh oh!"})})},variant:"naked",color:"linkForeground",theme:"primary",size:"xs"})}function Ze({status:e}){const n=Re.pending.value.includes(e)?{border:ze.neutral62,text:ze.neutral24}:Re.delivered.value.includes(e)?{border:ze.statusCreate35,text:ze.statusCreate23}:Re.skipped.value.includes(e)?{border:ze.statusWarning63,text:ze.givingBrand31}:Re.ignored.value.includes(e)?{border:ze.neutral68,text:ze.neutral45}:{border:ze.statusDelete47,text:ze.statusDelete43},a=Re.pending.value.includes(e)?"general.clock":Re.skipped.value.includes(e)?"services.pause":Re.delivered.value.includes(e)?"general.checkCircle":Re.ignored.value.includes(e)?"general.inactive":"general.exclamationTriangle",i=Re.failed.value.includes(e)?Re.failed.label:Re.ignored.value.includes(e)?Re.ignored.label:Re[e].label;return t(h,{color:{background:"transparent",foreground:n.text},css:{paddingLeft:3.5,paddingRight:1.5},fontSize:"12px",radius:"pill",renderLeft:t(g,{name:a,color:n.border,marginLeft:1}),size:"sm",stroke:n.border,strokeAlign:"inside",strokeWeight:1,title:i})}function Xe({event:e}){const{status:n,lastDelivery:a}=e,o=function(e,n){let a=null;switch(e){case"skipped":case"ignored_skipped":a="Automation was paused and did not run on this profile";break;case"failed":case"duplicated":case"ignored_failed":case"ignored_duplicated":a=function(e,n){const a={403:"Owner doesn't have permission to perform this action.",404:"Owner lacks access to target product or resource doesn't exist.",422:"The automation action failed to run",default:"An error occurred",duplicated_event:"Didn't run because the same action had already been performed less than 60 seconds ago",failed_without_deliveries:"Didn't run because the owner doesn't have permissions in this product."};return t(i,{flex:1,whiteSpace:"normal",children:e?t(Qe,{details:function(e){var t;if(null==e||!e.responseBody)return null;let n;try{n=JSON.parse(e.responseBody)}catch(e){n={errors:["Server Error"]}}return function(e){return null!=e&&e.errors?e.errors.map(e=>"string"==typeof e&&e.match(/Archived profiles/)?e.replace(/Archived profiles/,"Archived profiles."):e):[]}(n).join(", ")||(null==(t=n)?void 0:t.message)}(e),status:e.status,children:a[e.status]||a.default}):["duplicated","ignored_duplicated"].includes(n)?a.duplicated_event:a.failed_without_deliveries})}(n,e)}return a}(n,a);return o?t(s,{fontSize:"13px",fontStyle:"italic",lineHeight:"16px",maxWidth:"100%",paddingTop:"1px",whiteSpace:"normal",children:o}):null}function Qe({children:n,details:a,status:o}){const[l,c]=W(!1);return e(i,{spacing:1,children:[e(s,{children:[n," ",a&&t(d,{inline:!0,onClick:function(){c(e=>!e)},size:"xs",theme:"primary",variant:"naked",fontStyle:"normal",children:"Details"})]}),l?t(s,{padding:1,background:ze.neutral98,children:e(r,{fontFamily:"monospace",fontSize:"11px",lineHeight:"1.2",children:[o&&`${o}: `,a]})}):null]})}class Ge extends D.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?e(p,{type:"error",marginVertical:1,children:["The application hit an unexpected error. If this persists after a few minutes, please let us know so we can get it fixed for you."," ",t("a",{style:{whiteSpace:"nowrap"},onClick:()=>window.Helpdesk.load(),children:"Contact support"})]}):this.props.children}}var Je=e=>t(Ge,{children:t(Ye,ge({},e))});function Ke({onClick:e}){return t(d,{as:"button",height:2,icon:{color:ze.neutral62,name:"general.x"},onClick:e,size:"sm",title:"Close",variant:"naked"})}function et({children:n,onRequestClose:a,open:r,theme:s}){/*#__PURE__*/return he(t(w,{theme:s,children:e(f,{open:r,onRequestClose:a,maxWidth:120,boxShadow:"0 0 20px rgba(0, 0, 0, 0.15)",padding:4,paddingBottom:3,radius:8,children:[e(i,{axis:"horizontal",distribution:"space-between",alignment:"center",children:[t(o,{level:2,color:ze.neutral12,fontWeight:500,fontSize:"25px",lineHeight:"1.4",children:"Automation history"}),t(Ke,{onClick:a})]}),n]})}),document.body)}const tt=["onDelete","theme","openHistoryNow"],nt=["automation","children","theme"],at=new a({app:"webhooks",version:"2022-10-20"}),it=new a({app:"people"}),ot=/*#__PURE__*/H(null);function rt(n){let{onDelete:a,theme:i,openHistoryNow:o=!1}=n,r=we(n,tt);return e(dt,ge({theme:i},r,{children:[e(ut,{children:[t(mt,{}),t(pt,{onDelete:a,openHistoryNow:o})]}),t(wt,{}),t(gt,{})]}))}function st(n){return e(dt,{automation:n.automation,children:[e(ut,{children:[t(mt,{}),t(ct,{})]}),t(lt,{}),t(ht,{})]})}function lt(){const{automation:n}=j(ot),a=n.triggerEventDescription,{name:s,description:l}=bt(n.description);return e(i,{paddingVertical:2,flex:1,opacity:n.active?void 0:.5,children:[t(o,{level:3,size:"21px",weight:600,marginBottom:.5,truncate:!0,children:s}),e(i,{spacing:.75,children:[e(r,{size:4,color:ze.neutral24,lineHeight:"1.2",children:[a,", then ",Y(s)," ",ft(n)]}),t(r,{size:5,color:ze.neutral45,lineHeight:"1.2",children:U(vt(l),{length:160,separator:" "})})]})]})}function ct(){const{automation:e}=j(ot);return t(d,{external:!0,iconLeft:{name:"general.newWindow"},variant:"naked",size:"sm",to:e.triggerAdminUrl,disabled:!e.canManage,tooltip:e.canManage?void 0:"You do not have access to this resource",color:ze.neutral45,hover:{backgroundColor:"highlight",color:ze.neutral45},children:"Manage"})}function dt(e){let{automation:n,children:a,theme:i}=e,o=we(e,nt);const[r,s]=W(n);return t(ot.Provider,{value:ge({automation:r,theme:i,updateAutomation:s},o),children:t(b,{radius:4,padding:2,children:a})})}function ut({children:e}){const{automation:n}=j(ot);return t(i,{axis:"horizontal",alignment:"center",padding:0,distribution:"space-between",opacity:n.active?void 0:.5,children:e})}function pt({onDelete:a,openHistoryNow:o=!1}){const{automation:l,currentPersonCanCreate:c,currentPersonId:u,trigger:p,theme:m,updateAutomation:h}=j(ot),[g,w]=W(o),f=l.active,{name:b}=bt(l.description);return e(n,{children:[e(i,{axis:"horizontal",alignment:"center",spacing:.75,children:[e(v,{icon:{color:ze.neutral24,name:"churchCenter.threeDots"},iconRight:!1,title:"Actions",variant:"naked",size:"md",children:[t(v.Item,{onSelect:()=>{w(!0)},children:"History"}),c&&t(v.Item,l.createdById===u?{disabled:!0,children:t(x,{placement:"left",openDelay:250,title:"This automation is already assigned to you.",children:t(r,{children:"Reassign to me..."})})}:{onSelect:function(){xe.fire({text:"This automation will run with your permission levels. Other administrators who can see this automation can grant it their permissions by reassigning it to themselves.",title:"Reassign automation?"}).then(({isConfirmed:e})=>{e&&at.post({data:{_e:p.resource,data:{attributes:{}}},url:`/automation_subscriptions/${l.id}/self_assign`}).then(({data:e})=>async function(e){const{data:{avatar:t}}=await it.get({data:{fields:{Person:"avatar"}},url:"me"});return{avatar:t,subscription:e}}(e)).then(({subscription:e,avatar:t})=>{h(n=>ge({},n,{createdBy:ge({},n.createdBy,{avatarUrl:t}),createdById:e.createdById,createdByName:e.createdByName}))}).catch(()=>ve.fire({text:"There was a problem updating this automation. Please try again in a few moments.",title:"Uh oh!"}))})},children:"Reassign to me..."}),t(v.Item,{onSelect:function(){ye.fire({confirmButtonText:"Yes, delete automation",text:`Are you sure you want to delete the "${b}" automation? This cannot be undone.`,title:"Delete this automation?"}).then(({isConfirmed:e})=>{e&&a(l.id)})},children:"Delete..."})]}),t(d,{as:"button",theme:!1,position:"relative",backgroundColor:f?ze.statusCreate35:ze.neutral62,radius:"pill",width:3.5,height:2,onClick:function(){at.patch({data:{_e:p.resource,data:{attributes:{active:!f}}},url:`/automation_subscriptions/${l.id}`}).then(e=>{h(t=>ge({},t,{active:e.data.active}))}).catch(()=>ve.fire({text:`There was a problem ${f?"pausing":"unpausing"} this automation. Please try again in a few moments.`,title:"Uh oh!"}))},tooltip:f?"Pause automation":"Enable automation",children:t(s,{position:"absolute",pointerEvents:"none",top:.25,left:.25,width:1.5,height:1.5,background:"#fff",radius:"circle",transition:"0.1s",transform:`translateX(${f?"100%":"0%"})`})})]}),t(et,{open:g,onRequestClose:()=>w(!1),theme:m,children:t(Je,{automation:l,triggerResource:p.resource,onEventsStatusChange:function(e){h(t=>ge({},t,{eventsStatus:e}))}})})]})}function mt(){const{automation:n}=j(ot),a=n.name.split(".")[0];return e(i,{axis:"horizontal",alignment:"center",spacing:.5,children:[t(g,{name:`logomark.${E(a)}`,size:2,color:a.toLowerCase()}),t(g,{name:"general.rightArrow",size:1.5}),t(g,{name:`logomark.${E(n.operationAppName)}`,size:2,color:n.operationAppName.toLowerCase()})]})}function ht(){var a,o;const{automation:s}=j(ot),{dateFormat:l}=j(be),c=null!=(a=s.createdBy)&&a.id?"":"(deleted profile)",d=`${s.createdByName} ${c}`,u=s.active?void 0:.5;return e(n,{children:[t(y,{marginHorizontal:-2}),e(i,{axis:"horizontal",alignment:"center",distribution:"space-between",paddingTop:1.75,spacing:1,opacity:u,children:[e(r,{size:6,color:ze.neutral62,whiteSpace:"nowrap",children:["Updated ",De(s.createdAt,l)]}),e(i,{axis:"horizontal",alignment:"center",spacing:.5,maxWidth:"calc(100% - 136px)",children:[(null==(o=s.createdBy)?void 0:o.avatarUrl)&&t(k,{width:2,height:2,basis:2,source:s.createdBy.avatarUrl},d),t(r,{size:5,truncate:!0,children:d})]})]})]})}function gt(){var a,o,l,c,u,p,m,h;const{dateFormat:w}=j(be),{automation:f,trigger:b,theme:v,updateAutomation:x}=j(ot),C=null!=(a=f.createdBy)&&a.id?"":"(deleted profile)",z=`${f.createdByName} ${C}`,_=f.active?void 0:.5,S={color:ze.neutral45,fontSize:6,fontWeight:400,paddingHorizontal:1,radius:"pill",size:"xs",variant:"naked"},[O,A]=W({filter:null,historyVisible:!1});return e(n,{children:[t(y,{marginHorizontal:-2}),e(i,{axis:"horizontal",alignment:"center",distribution:"space-between",paddingTop:1.75,spacing:1,opacity:_,children:[e(r,{size:6,color:ze.neutral62,whiteSpace:"nowrap",children:["Updated ",De(f.createdAt,w)]}),e(i,{axis:"horizontal",alignment:"center",spacing:.25,children:[!(null==(o=f.eventsStatus)||!o.skipped)&&e(d,ge({},S,{"aria-label":`${f.eventsStatus.skipped} skipped`,onClick:function(){A({filter:"skipped",historyVisible:!0})},tooltip:`${null==(l=f.eventsStatus.skipped)?void 0:l.toLocaleString()} skipped events`,children:[t(s,{backgroundColor:ze.statusWarning63,marginRight:.5,radius:"circle",height:"10px",width:"10px",padding:"2px",children:t(g,{name:"services.pause",size:"6px",title:"Skipped",color:"white"})}),`${null==(c=f.eventsStatus.skipped)?void 0:c.toLocaleString()}`]})),!(null==(u=f.eventsStatus)||!u.failed)&&t(d,ge({},S,{"aria-label":`${f.eventsStatus.failed} failed`,iconLeft:{color:ze.statusDelete43,marginRight:.5,name:"general.exclamationTriangle",size:"10px",title:"Failed"},onClick:function(){A({filter:"failed,duplicated",historyVisible:!0})},title:`${null==(p=f.eventsStatus.failed)?void 0:p.toLocaleString()}`,tooltip:`${null==(m=f.eventsStatus.failed)?void 0:m.toLocaleString()} failed events`}))]}),e(i,{axis:"horizontal",alignment:"center",distribution:"end",flex:1,spacing:.5,marginLeft:"auto",children:[(null==(h=f.createdBy)?void 0:h.avatarUrl)&&t(k,{width:2,height:2,basis:2,source:f.createdBy.avatarUrl},z),t(r,{size:5,truncate:!0,children:z})]})]}),t(et,{open:O.historyVisible,onRequestClose:()=>A({filter:null,historyVisible:!1}),theme:v,children:t(Je,{automation:f,triggerResource:b.resource,filterWhere:O.filter,onEventsStatusChange:function(e){x(t=>ge({},t,{eventsStatus:e}))}})})]})}function wt(){const{automation:n,trigger:a}=j(ot),{name:s,description:l}=bt(n.description),c=n.active?void 0:.5,d=["When a person",Y(a.event.description)+",","then",Y(s),ft(n)].join(" ");return e(i,{paddingVertical:2,flex:1,opacity:c,children:[t(o,{level:3,size:"21px",weight:600,marginBottom:.5,truncate:!0,children:s}),e(i,{spacing:.75,children:[t(r,{size:4,color:ze.neutral24,lineHeight:"1.2",children:d}),t(r,{size:5,color:ze.neutral45,lineHeight:"1.2",children:U(vt(l),{length:160,separator:" "})})]})]})}function ft(e){var t;return null!=e&&null!=(t=e.triggerParams)&&t.useTriggerPersonOverride?"(also applies to joint donor)":""}function bt(e){const t=/^(.+?)\(([^()]*?)\)$/.exec(e);return t?{description:t[2],name:t[1].trim()}:{name:e}}function vt(e){return null!=e&&e.startsWith("[archived]")?e.replace("[archived]","(Archived)"):e}const xt=new a({app:"webhooks",version:"2022-10-20"}),yt=new a({app:"people"});async function kt(e){const t=q(Z(e.map(e=>e.createdById)));try{const{data:n}=await yt.get({data:{fields:{Person:"avatar"},where:{id:t.join(",")}},url:"people"});return{profiles:n,subscriptions:e}}catch(t){return{profiles:[],subscriptions:e}}}function Ct({profiles:e,subscriptions:t}){return t.map(t=>{const n=e.find(e=>e.id===t.createdById);return ge({},t,{createdBy:ge({},t.createdBy,{avatarUrl:null==n?void 0:n.avatar})})})}const zt=new a({app:"webhooks",version:"2022-10-20"});async function _t(e){const t={people:["forms","lists"],registrations:["events"],services:["teams"]},n=["giving"],a=e.reduce((e,t)=>{const n=t.triggerResource.replace(/signup/,"event"),{appName:a,resourceType:i,resourcePath:o,resourceId:r}=We(n);return e[a]||(e[a]={}),e[a][i]||(e[a][i]={}),e[a][i].resoucePath||(e[a][i].resourcePath=o),e[a][i].ids||(e[a][i].ids=[]),e[a][i].ids.push(r),e},{}),i=Object.keys(a).flatMap(e=>Object.entries(a[e]).flatMap(([a,i])=>{var o;return(n.includes(e)?At:null!=(o=t[e])&&o.includes(a)?St:Ot)({appName:e,ids:i.ids,resourcePath:i.resourcePath,resourceType:a})}));return{automations:e,triggerResources:(o=await Promise.allSettled(i),o.reduce((e,t)=>("fulfilled"===t.status&&(e=e.concat(t.value)),e),[]).flatMap(e=>e.data))};var o}function St({appName:e,resourcePath:t,resourceType:n,ids:a}){return $t({appName:e,params:{where:{id:a.join(",")}},path:t,resourceType:n})}function Ot({appName:e,resourcePath:t,resourceType:n,ids:a}){return a.map(a=>$t({appName:e,path:`${t}/${a}`,resourceType:n}))}function At(e){return new Promise((e,t)=>{t()})}function $t({appName:e,path:t,resourceType:n,params:i={}}){const o=new a({app:e}),r=X(je(n));return o.get({data:ge({fields:{[r]:["name","name_or_description"]}},i),url:t})}function Lt({encryptedParam:a,trigger:i}){const[l,c]=W(!0),[d,u]=W();V(()=>{(async function(){return yt.get({data:{fields:{App:["name"],PersonApp:["app","allow_pco_login"]},include:["app"]},url:"/me/person_apps"}).then(({data:e})=>e.filter(e=>e.allowPcoLogin).map(e=>e.app.name.toLowerCase()))})().then(e=>{(async function(e){const{data:t}=await zt.get({data:{_e:e,fields:{AutomationSubscription:"id,description,created_at,created_by,operation_app_name,operation_definition_class_name,operation_params,active,created_by_name,name,trigger_admin_url,trigger_resource,trigger_params",Person:"name"},include:"created_by"},url:"incoming_automation_subscriptions"});return t})(a).then(kt).then(Ct).then(_e).then(_t).then(({automations:t,triggerResources:n})=>function({automations:e,triggerResources:t,operationApps:n}){return e.map(e=>{const{appName:a,resourceType:i,resourceId:o}=We(e.triggerResource);if("giving"===a)return e.triggerEventDescription=function(e){switch(e.name.replace("giving.v2.events.","")){case"donation.payment_successful":return"When a person gives";case"profile.first_donated_automation":return"When a person gives for the first time";case"recurring_donation.setup_successful":return"When a person sets up a recurring donation";default:return null}}(e),e.canManage=n.find(e=>"giving"===e),e;const r=t.find(e=>e.id.toString()==o.toString()),s=r?r.name||r.nameOrDescription:`[Hidden ${X(je(i))}]`;return e.triggerEventDescription=function(e,t){const n=function(e){switch(e.replace("v2.events.","")){case"groups.membership.created":return"joins";case"groups.membership.destroyed":return"leaves";case"people.list_result.created":case"services.team_person.created":return"is added to";case"people.list_result.destroyed":case"services.team_person.destroyed":return"is removed from";case"people.form_submission.created":return"submits";case"registrations.attendee.created":return"is registered as a new attendee for";case"registrations.attendee.cancelled":return"is canceled as an attendee for";case"registrations.registration.created":return"is the registration contact on a new registration for";case"registrations.registration.cancelled":return"is the registration contact on a canceled registration for";default:return null}}(e.name),{resourceType:a}=We(e.triggerResource);if(!n){const e=U(t,{length:160,separator:" "});return`When the automation is triggered from ${je(a)} "${e}"`}return`When a person ${n} ${je(a)} "${t}"`}(e,s),e.canManage=!!r,e})}({automations:t,operationApps:e,triggerResources:n})).then(u).then(()=>c(!1))})},[a]);const p=!l&&0===d.length;return e(n,{children:[t(s,{borderBottom:`1px solid ${ze.neutral88}`,marginBottom:2,marginHorizontal:-3,marginTop:i?12:0,paddingHorizontal:3,paddingVertical:2,children:t(o,{color:ze.neutral12,level:2,size:"18px",children:l?"Incoming automations":He(d.length,"incoming automation")})}),p?t(r,{color:ze.neutral45,marginVertical:3,children:"Automations that perform actions on this resource will be listed here."}):l?t(C,{image:t(z,{size:"xl"}),paddingVertical:10,title:"Loading incoming automations..."}):t(_,{spacing:3,marginVertical:3,minCellWidth:45,children:d.map(e=>t(st,{automation:e},e.id))})]})}function Pt(e){return`OPERATION_${e.definitionClass}${e.definitionIdentifier||""}`}function Ft(e){return`SECTION_${e}`}function Tt(e){return e.map(({label:e,value:n})=>t(c.Option,{value:n,children:e},n))}function It(e){const n=G(e,"group");return Object.keys(n).sort().map(e=>"null"===e?Tt(n[e]):t(c.OptionGroup,{title:e,children:Tt(n[e])},e))}const Dt=({selectedOperation:n,onOperationDefinitionChange:a,operationDefinitions:o})=>{const r=null==n?void 0:n.section,s=o.map(e=>ge({},e,{id:Pt(e)})),l=s.filter(e=>null===e.section),d=Q(o,"section").filter(e=>!!e.section).map(e=>({group:e.sectionGroup,label:e.section,value:Ft(e.section)})),u=r?s.filter(e=>e.section===r):[];function p({selectedValue:e}){switch(function(e){if(e.startsWith("SECTION"))return"section";if(e.startsWith("OPERATION"))return"operation";if(e)throw new Error(`Unexpected value: ${e}`);return null}(e)){case"section":a(o.find(t=>Ft(t.section)===e));break;case"operation":a(o.find(t=>Pt(t)===e));break;case null:a(null)}}function m(e){return It(e.map(e=>({group:e.group,label:e.description,value:e.id})))}return e(i,{spacing:1,children:[e(c,{emptyValue:"Select an action",id:"select-action",onChange:p,size:"lg","data-testid":"operation-select",children:[m(l),It(d)]}),u.length>0&&t(c,{defaultValue:u[0].id,onChange:p,size:"lg",children:m(u)})]})},Ht=({canAccessPeople:n,field:a,onChange:o,value:r,selectedFieldOptions:c,loadListForField:d,loadedLists:u,loadingLists:p})=>{const m=function(e){const[t,n]=W(e);return V(()=>{const a=e();J(a,t)||n(a)},[e,t]),t}(()=>function({field:e,selectedFieldOptions:t}){return(e.dependsOn||[]).reduce((e,n)=>(Object.prototype.hasOwnProperty.call(t,n)&&(e[E(n)]=t[n]),e),{})}({field:a,selectedFieldOptions:c}));V(()=>{a.listClass&&d({dependencies:m,field:a})},[a,m,d]);const h=a.list||u[Ae(a)]||[],g=h.filter(e=>!e.automationNotAllowed),w=a.listClass&&p[Ae(a)];return e(i,{marginBottom:2,spacing:.5,children:[e(l.InputLabel,{color:ze.neutral12,fontSize:"14px",fontWeight:500,controls:a.id,children:[a.description,a.info&&t(S.Toggle,{drawerId:`${a.id}_help`,marginLeft:1})]}),t(s,{children:w?t(qt,{}):function(){switch(a.kind){case"Select":return t(jt,{fieldId:a.id,listOptions:g,onChange:o,value:r});case"SelectSearch":return t(Wt,{fieldId:a.id,listOptions:g,onChange:o,value:r});case"Checkbox":return t(Bt,{field:a,value:r,onChange:o});case"TextArea":return t(Rt,{field:a,onChange:o,value:r});case"DateField":return t(Nt,{field:a,onChange:o,value:r});case"Checkboxes":return t(Mt,{fieldId:a.id,options:g,onChange:o});case"NumberField":return t(Et,{field:a,onChange:o,value:r});case"PersonSearch":return t(Vt,{canAccessPeople:n,field:a,onChange:o,listOptions:h,isLoading:p[Ae(a)],loadListForField:d,value:r});case"TextField":return t(Yt,{field:a,onChange:o,value:r});case"RadioButtons":return t(Ut,{field:a,options:h,onChange:o,value:r});default:return console.warn(`Unknown field kind "${a.kind}"`),null}}()}),a.info&&t(S,{id:`${a.id}_help`,marginTop:.5,children:t(s,{dangerouslySetInnerHTML:{__html:a.info}})})]})},jt=({fieldId:e,listOptions:n,onChange:a,value:i})=>{const o=null==n?void 0:n.find(e=>"no-option"===e.value),r=G(n,"group"),s=Object.keys(r).sort(),l=()=>s.map(e=>"null"===e||"undefined"===e?d(r[e]):t(c.OptionGroup,{title:e,children:d(r[e])},e)),d=e=>e.map(e=>t(c.Option,{value:e.value.toString(),disabled:e.disabled,children:e.description},e.value));return t(c,{id:e,onChange:({selectedValue:t})=>{a({fieldId:e,value:t})},disabled:l().length<1,emptyValue:0===l().length?"No options available":(null==o?void 0:o.description)||"Select a value",size:"lg",value:i||(null==o?void 0:o.value)||null,placement:"bottom-start",children:l()})},Wt=({fieldId:a,listOptions:i,onChange:o,value:s})=>{const l=i.find(e=>{var t;return(null==(t=e.value)?void 0:t.toString())===s}),c=(null==l?void 0:l.description)||"",[d,u]=W(""),[p,m]=W(c),[w,f]=W(!1),[b,v]=W(!1);c!==d&&(u(c),m(c),f(!1));let x=K(Q(i,"value"),"group");if(w){const e=p.toLowerCase();x=x.filter(t=>`${t.description} ${t.group}`.toLowerCase().includes(e))}return t(O.Popover,{closeOnSelect:!0,closeButton:{icon:{size:"md"}},css:{"[role='combobox']":{cursor:i.length>0?"pointer":"not-allowed"}},cursor:"pointer",disabled:0===i.length,onBlur:()=>{v(!1),m(c)},onChange:e=>{m(e.target.value),f(!0),v(!0)},onClear:b?()=>{m(""),f(!1)}:void 0,onFocus:e=>e.target.select(),onSelect:e=>{(e=>{o({fieldId:a,value:e})})(e.value),m(e.description),f(!1),v(!1)},openOnFocus:!0,paddingLeft:4.5,placeholder:i.length>0?"Select an option":"No options available",placement:"bottom-start",popoverProps:{matchWidths:"minimum"},renderLeft:t(g,{name:"general.search",size:"md"}),renderRight:t(g,{name:"general.downCaret"}),size:"lg",value:p,children:i.length>0&&t(n,{children:x.length>0?x.map((n,a)=>{const i=n.value.toString()===s;return e(O.Item,{"aria-label":n.description,disabled:n.disabled,index:a,paddingLeft:4.25,renderLeft:t(g,{marginLeft:-.5,name:i?"general.check":"",size:"sm"}),role:"option",spacing:1,value:{description:n.description,value:n.value.toString()},children:[t(r,{truncate:!0,children:t(A,{text:n.description,query:p})}),n.group&&t(h,{title:t(A,{text:n.group,query:p}),size:"sm",marginLeft:"auto"})]},n.value)}):t($.Item,{children:e(r,{children:['No results for "',p,'"']})})})})},Vt=({canAccessPeople:e,field:n,isLoading:a,listOptions:i,loadListForField:o,onChange:s,value:l})=>{var c;const d=B(e=>{o({dependencies:{query:e},field:n})},[o]),u=R(()=>ee(d,300),[d]),p=B(t=>{e&&(t.trim().length>0?u(t):u.cancel())},[u]),m=R(()=>({description:"Myself",value:"self"}),[]),h=R(()=>e?i:[m],[m,i]).find(e=>e.value===l),w=(null==h?void 0:h.description)||"",[f,b]=W(w),[v,x]=W(!1);function y(e){b(e),p(e),0===e.trim().length&&C(null)}const C=e=>{s({fieldId:n.id,value:e})};return t(O.Popover,{closeOnSelect:!0,closeButton:{icon:{size:"md"}},cursor:"pointer",onBlur:()=>{x(!1),y(w)},onChange:e=>{y(e.target.value),x(!0)},onClear:v?()=>{y("")}:void 0,onFocus:e=>e.target.select(),onSelect:e=>{C(e.value),y(e.description),x(!1)},openOnFocus:!0,paddingLeft:4.5,placeholder:"Search",placement:"bottom-start",popoverProps:{matchWidths:"minimum"},renderLeft:h&&null!=(c=h.meta)&&c.avatar?t(k,{size:"sm",source:h.meta.avatar}):t(g,{name:"general.search",size:"md"}),renderRight:t(g,{name:"general.downCaret"}),size:"lg",value:f,children:e?f.trim().length>0?i.length>0?i.map((e,n)=>t(O.Item,{"aria-label":e.description,index:n,paddingLeft:4.25,renderLeft:t(k,{marginLeft:-.5,source:e.meta.avatar,size:"sm"}),role:"option",spacing:1,value:e,children:t(r,{truncate:!0,children:t(A,{text:e.description,query:f})})},e.value)):t(O.Item,a?{children:t(r,{children:"Loading..."})}:{children:t(r,{children:"No results"})}):t(O.Item,{children:t(r,{children:"Type to search"})}):t(O.Item,{value:m,index:0,role:"option",children:t(r,{children:m.description})})})},Bt=({field:e,value:n,onChange:a})=>t(L,{disabled:e.disabled,label:e.label,checked:n||!1,onChange:t=>{a({fieldId:e.id,value:t.target.checked})}}),Rt=({field:e,value:n,onChange:a})=>t(s,{children:t(P,{value:n,placeholder:e.placeholder,onChange:t=>{a({fieldId:e.id,value:t.target.value})},size:"lg"})}),Nt=({field:n,value:a,onChange:o})=>{const{dateFormat:r}=j(be),[l,d]=W(!1),u=n.customValue||"Date automation runs",p=r.replace(/%m/,"M").replace(/%d/,"d").replace(/%Y/,"y").replace(/%y/,"yy"),[m,h]=W(ae(a).toDate());return e(i,{axis:"horizontal",children:[e(c,{onChange:({selectedValue:e})=>{e===u?(d(!1),o({fieldId:n.id,value:u})):"specific-date"===e?(o({fieldId:n.id,value:null}),d(!0)):(d(!1),o({fieldId:n.id,value:null}))},size:"lg",placement:"bottom-start",children:[t(c.Option,{value:u,children:u}),t(c.Option,{value:"specific-date",children:"A specific date"}),t(c.Option,{value:"unanswered",children:"Unanswered"})]}),l&&t(s,{children:t(F,{defaultOpen:!0,formatValue:p,marginLeft:1,onChange:e=>{o({fieldId:n.id,value:De(e,r)}),h(e)},size:"lg",value:m})})]})},Mt=({fieldId:n,options:a,onChange:o})=>{const[r,d]=W({});return t(i,{spacing:1,children:a.map(a=>e(s,{children:[t(l.InputLabel,{controls:`checkboxes_${n}_${a.value}`,children:a.description||a.value}),e(c,{id:`checkboxes_${n}_${a.value}`,onChange:({selectedValue:e})=>((e,t)=>{const a=ge({},r);a[t]=e,d(a),o({fieldId:n,value:a})})(e,a.value),size:"lg",emptyValue:"Don't change",children:[t(c.Option,{value:"check",children:"Check"}),t(c.Option,{value:"uncheck",children:"Uncheck"})]})]},a.value))})},Et=({field:n,onChange:a,value:o})=>{const s=n.minValue>=0?n.minValue:1,c=n.maxValue>=1&&n.maxValue<=365?n.maxValue:365,[d,u]=W(Number(n.defaultValue)||1);return V(()=>{a({fieldId:n.id,value:n.defaultValue||1})},[n]),e(i,{children:[t(l.InputBox,{children:t(T,{onChange:e=>{const t=Number(e)||0;u(t),a({fieldId:n.id,value:Math.min(Math.max(t,s),c)})},placeholder:n.placeholder,size:"lg",value:o,min:s,max:c,hasControls:!0})}),d>c&&t(p,{type:"error",paddingHorizontal:1,paddingVertical:.5,display:"inline-block",marginTop:1.5,children:e(i,{axis:"horizontal",alignment:"center",spacing:.75,children:[t(g,{name:"general.exclamationTriangle",size:"sm",color:"delete45"}),e(r,{size:4,children:["Value cannot exceed ",c,"."]})]})})]})},Yt=({field:e,value:n,onChange:a})=>t(s,{children:t(l,{size:"lg",value:n,id:e.id,placeholder:e.placeholder,onChange:t=>{a({fieldId:e.id,value:t.target.value})}})}),Ut=({field:e,options:n,onChange:a,value:o})=>{const r=t=>{a({fieldId:e.id,value:t.target.value})};return t(i,{marginTop:1,spacing:.5,children:n.map(e=>t(I,{checked:o===e.value,label:e.description||e.value,onChange:r,size:"md",value:e.value},e.value))})},qt=()=>e(i,{axis:"horizontal",alignment:"center",spacing:1,paddingHorizontal:1.75,paddingVertical:1,radius:4,border:`1px solid ${ze.neutral88}`,children:[t(z,{size:"xs"}),t(r,{fontSize:16,lineHeight:2.75,children:"Loading"})]}),Zt=({canAccessPeople:e,definitionFields:n,onChange:a,selectedFieldOptions:i,loadListForField:o,loadedLists:r,loadingLists:s})=>{V(()=>{const e=n.reduce((e,t)=>(Object.prototype.hasOwnProperty.call(t,"defaultValue")?e[t.id]=t.defaultValue:"DateField"===t.kind&&(e[t.id]=t.customValue||"Date automation runs"),e),{});a(e)},[n,a]);const l=Fe(n,i),c=({fieldId:e,value:t})=>{const o=ge({},i),r=n.filter(e=>e.dependsOn);r.map(t=>{if(t.dependsOn.includes(e)){const e=r.find(e=>e.dependsOn.includes(t.id));e&&delete o[e.id],delete o[t.id],void 0!==t.defaultValue&&void 0===o[t.id]&&(o[t.id]=t.defaultValue)}}),"no-option"===t?delete o[e]:o[e]=t,a(ge({},o))};return n.length?t("div",{children:l.map(n=>t(Ht,{canAccessPeople:e,field:n,onChange:c,value:i[n.id],selectedFieldOptions:i,loadListForField:o,loadedLists:r,loadingLists:s},n.id))}):null},Xt=new a({app:"people",env:window.railsEnv,version:"LATEST"}),Qt=new a({app:"webhooks",env:window.railsEnv,version:"LATEST"}),Gt={css:{borderRadius:4},paddingHorizontal:1.75,paddingVertical:1.25,type:"error"};async function Jt(){return Xt.get({data:{fields:{Topbar:"apps"}},url:"/me/topbar"}).then(({data:e})=>e.apps.map(e=>e.name))}async function Kt(){return Qt.get({data:{fields:{OperationApp:"name"}},url:"/operation_apps"}).then(({data:e})=>e.map(e=>e.name))}async function en(e){return Qt.get({data:{fields:{OperationDefinition:"definition_class,definition_fields,definition_identifier,description,group,section,section_group,footer_message"},filter:"automation_allowed"},url:`/operation_apps/${e}/operation_definitions`}).then(({data:e})=>e)}const tn=({afterCreateOptions:a,blankStateLink:o,debugMode:u=!1,defaultApp:h,description:w,onRequestClose:f,trigger:b})=>{var v,x,y;const[k,C]=W(b.events[0]),[_,S]=W({}),[O,A]=W(h),[$,P]=W([]),[F,T]=W([]),[I,D]=W(!0),[H,j]=W(),[M,E]=W({}),[Y,U]=W({}),[q,Z]=W({}),[X,Q]=W(!1),[G,J]=W({}),[K,ee]=W(!1),[ae,ie]=W({}),oe=N(null),re=R(()=>$.map(e=>e.id).includes("people"),[$]),se=null==H?void 0:H.definitionIdentifier,le="danger"===(null==H||null==(v=H.footerMessage)?void 0:v.kind),ce=B(({field:e,dependencies:t})=>{Z(t=>ge({},t,{[Ae(e)]:!0})),async function({app:e,field:t,definitionIdentifier:n,dependencies:a}){if("PersonSearch"===t.kind){const{data:e}=await Xt.get({data:{fields:{Person:"avatar,name"},where:{search_name_or_email:a.query,status:"active"}},url:"/people"});return e.map(e=>({description:e.name,meta:{avatar:e.avatar},value:e.id.toString()}))}{const{data:i}=await Qt.get({data:ge({},a,{definitionIdentifier:n,fields:{OperationDefinitionList:"values"}}),url:`/operation_apps/${e}/operation_definition_lists/${t.listClass}`});return i.values}}({app:O,definitionIdentifier:se,dependencies:t,field:e}).then(t=>{U(n=>ge({},n,{[Ae(e)]:t})),Z(t=>ge({},t,{[Ae(e)]:!1}))}).catch(e=>J({selected_definition:e}))},[O,se]);V(()=>{J({}),async function(){const[e,t]=await Promise.all([Jt(),Kt()]);return e.filter(e=>t.includes(e)).sort().map(e=>({id:e.toLowerCase(),name:e}))}().then(e=>{P(e);const t=e.find(e=>e.id===h)?h:e[0].id;A(t),en(t).then(e=>{oe.current||(T(e),D(!1))}).catch(e=>J({definitions:e}))})},[h]),V(()=>{J({})},[M]);const de=te("conditions"in k?k.conditions:b.conditions);for(const e in _)ne(de,e,_[e]);const ue="dynamicConditions"in k?k.dynamicConditions:b.dynamicConditions;function pe(){const e=function({selectedDefinition:e,selectedFieldOptions:t,loadedLists:n}){return{description:Te({loadedLists:n||{},selectedDefinition:e,selectedFieldOptions:t}),name:(a=e,$e(a)||a.description)};var a}({loadedLists:Y,selectedDefinition:H,selectedFieldOptions:M});let t=e.name;return e.description&&(t+=` (${e.description})`),t}function me(e){Q(!0),Qt.post({data:e,url:"/me/automation_subscriptions"}).then(()=>{null!=a&&a.onConfirm&&K?(f(),a.onConfirm(ge({},e))):window.location.reload()}).catch(e=>{Q(!1),e.errors?J({automation:e.errors}):alert("something even worse happened!")})}return e(i,{paddingTop:4,spacing:2,children:[w&&t(s,{children:e(r,{style:{color:ze.neutral24,fontSize:16,lineHeight:1.65,marginBottom:16},children:[w," ",t(m,{external:!0,to:o,children:"Learn more"})]})}),G.automation&&t(p,ge({},Gt,{children:t(r,{children:"There was an error creating your automation. Please change your selections and try again or contact support if the problem persists."})})),e(i,{spacing:1,children:[t(l.InputLabel,{color:ze.neutral12,controls:"select-trigger-event",fontSize:"16px",fontWeight:600,children:"When a person..."}),t(c,{id:"select-trigger-event",onChange:({selectedValue:e})=>(e=>{C(e),S({})})(e),size:"lg",value:k,children:b.events.map((e,n)=>t(c.Option,{value:e,children:e.description},`${e.name}_${n}`))}),(null==ue?void 0:ue.length)>0&&t(Zt,{canAccessPeople:re,definitionFields:ue,selectedFieldOptions:_,onChange:S,loadedLists:{},loadingLists:{},loadListForField:()=>null})]}),e(i,{spacing:1,children:[$.length>0?t(sn,{selectedApp:O,operationApps:$,onOperationAppChange:e=>{A(e),D(!0),T([]),oe.current=e,j(null),E({}),J({}),en(e).then(T).then(()=>D(!1)).catch(e=>J({definitions:e}))}}):e(i,{spacing:1,children:[t(r,{color:ze.neutral12,fontSize:"16px",fontWeight:600,children:"Then perform an action in..."}),e(i,{axis:"horizontal",alignment:"center",spacing:1,paddingHorizontal:1.75,paddingVertical:1,radius:4,border:`1px solid ${ze.neutral88}`,children:[t(z,{size:"xs"}),t(r,{fontSize:16,lineHeight:2.75,children:"Loading"})]})]}),G.definitions?t(p,ge({marginTop:1},Gt,{children:t(r,{children:"There was a problem looking up automations. Please contact support if the problem persists."})})):I?t(ln,{}):t(Dt,{selectedOperation:H,operationDefinitions:F,onOperationDefinitionChange:e=>{j(e),J({}),E({})}})]}),H&&(G.selected_definition?t(p,ge({},Gt,{children:t(r,{children:"There was a problem looking up automation options. Please contact support if the problem persists."})})):e(n,{children:[t(Zt,{canAccessPeople:re,definitionFields:H.definitionFields||[],onChange:E,selectedFieldOptions:M,loadedLists:Y,loadListForField:ce,loadingLists:q}),(null==a?void 0:a.label)&&t(L,{disabled:X||nn(H,M),label:a.label,checked:K,onChange:()=>ee(!K)}),null==k||null==(x=k.triggerParams)?void 0:x.map((e,n)=>t(L,{label:e.description,checked:ae&&ae[e.key]||e.defaultValue,onChange:t=>{ie(n=>ge({},n,{[`${e.key}`]:t.target.checked}))}},`${e.key}_${n}`)),le&&t(p,ge({},Gt,{children:e(i,{axis:"horizontal",spacing:1.5,children:[t(g,{size:3,name:"general.exclamationTriangle",color:"error"}),t(r,{dangerouslySetInnerHTML:{__html:null==(y=H.footerMessage)?void 0:y.html}})]})}))]})),u&&t("pre",{children:JSON.stringify({description:H&&pe(),loadedLists:Y,selectedDefinition:H,selectedFieldOptions:M,triggerConditions:de},null,4)}),e(i,{alignment:"center",axis:"horizontal",borderTop:`1px solid ${ze.neutral88}`,distribution:"end",marginTop:2,marginHorizontal:-4,paddingHorizontal:4,paddingTop:3,spacing:2,children:[t(d,{color:ze.neutral12,"data-modal-close":!0,fontWeight:400,onClick:f,size:"md",title:"Cancel",variant:"naked"}),t(d,{disabled:X||le||nn(H,M),onClick:function(){if(X)return;const e=ge({},M);H.definitionIdentifier&&(e.definition_identifier=H.definitionIdentifier);const t={_e:b.resource,data:{attributes:{description:pe(),name:k.name,operation_app_name:O,operation_definition_class_name:H.definitionClass,operation_params:e,trigger_conditions:de,trigger_params:ae},type:"AutomationSubscription"}};K?ke.fire({cancelButtonText:"Cancel",confirmButtonText:"Yes, perform action",text:"This will happen immediately after creating your new automation. Are you sure?",title:`${a.label}?`}).then(e=>{e.value?me(t):(Q(!1),ee(!1))}):me(t)},size:"md",theme:"primary",title:rn(H,M),variant:"fill","data-testid":"create-automation"})]})]})};function nn(e,t){if(e){const n=Fe(e.definitionFields,t),a=n.filter(e=>e.required),i=n.filter(e=>an(e));return!a.every(e=>on(e,t))||!i.every(e=>on(e,t))}return!0}function an(e){return"Select"===e.kind||"SelectSearch"===e.kind}function on(e,t){return an(e)?t.hasOwnProperty(e.id):t.hasOwnProperty(e.id)&&t[e.id]&&""!==t[e.id].toString().trim()}function rn(e,t){const n=function(e,t){if(null==e||!e.definitionFields)return;const n=Fe(e.definitionFields,t);for(const e of n)if(e.required&&!on(e,t))return e.description}(e,t);return e?n?`Select a${n.charAt(0).match(/[aeiou]/i)?"n":""} ${n.toLowerCase()}`:"Create automation":"Select an action"}const sn=({onOperationAppChange:n,operationApps:a,selectedApp:o})=>e(i,{spacing:1,children:[t(l.InputLabel,{color:ze.neutral12,controls:"select-product",fontSize:"16px",fontWeight:600,children:"Then perform an action in..."}),t(c,{autoFocus:!0,id:"select-product",onChange:({selectedValue:e})=>{n(e)},size:"lg",value:o,children:a.map(e=>t(c.Option,{value:e.id,children:e.name},e.id))})]}),ln=()=>e(i,{axis:"horizontal",alignment:"center",spacing:1,paddingHorizontal:1.75,paddingVertical:1,radius:4,border:`1px solid ${ze.neutral88}`,children:[t(z,{size:"xs"}),t(r,{fontSize:16,lineHeight:2.75,children:"Loading"})]});function cn({onClick:e}){return t(d,{as:"button",height:2,icon:{color:ze.neutral62,name:"general.x"},onClick:e,size:"sm",title:"Close",variant:"naked"})}function dn({children:n,onRequestClose:a,open:r,theme:s}){/*#__PURE__*/return he(e(w,{theme:s,children:[e(f,{open:r,onRequestClose:a,maxWidth:75,boxShadow:"0 0 20px rgba(0, 0, 0, 0.15)",padding:4,paddingBottom:3,radius:8,zIndex:10009,children:[e(i,{axis:"horizontal",distribution:"space-between",alignment:"center",children:[t(o,{level:2,color:ze.neutral12,fontWeight:500,fontSize:"25px",lineHeight:"1.4",children:"Create automation"}),t(cn,{onClick:a})]}),n]}),t("style",{children:"\n .swal2-container.swal2-backdrop-show { z-index: 10001 }\n "})]}),document.body)}var un='.swal2-popup.swal2-toast{align-items:stretch;background:#fff;box-shadow:0 0 .625em #d9d9d9;flex-direction:column;overflow-y:hidden;padding:1.25em;width:auto}.swal2-popup.swal2-toast .swal2-header{flex-direction:row;padding:0}.swal2-popup.swal2-toast .swal2-title{flex-grow:1;font-size:1em;justify-content:flex-start;margin:0 .625em}.swal2-popup.swal2-toast .swal2-loading{justify-content:center}.swal2-popup.swal2-toast .swal2-input{font-size:1em;height:2em;margin:.3125em auto}.swal2-popup.swal2-toast .swal2-validation-message{font-size:1em}.swal2-popup.swal2-toast .swal2-footer{font-size:.8em;margin:.5em 0 0;padding:.5em 0 0}.swal2-popup.swal2-toast .swal2-close{height:.8em;line-height:.8;position:static;width:.8em}.swal2-popup.swal2-toast .swal2-content{font-size:1em;justify-content:flex-start;margin:0 .625em;padding:0;text-align:initial}.swal2-popup.swal2-toast .swal2-html-container{padding:.625em 0 0}.swal2-popup.swal2-toast .swal2-html-container:empty{padding:0}.swal2-popup.swal2-toast .swal2-icon{height:2em;margin:0 .5em 0 0;min-width:2em;width:2em}.swal2-popup.swal2-toast .swal2-icon .swal2-icon-content{align-items:center;display:flex;font-size:1.8em;font-weight:700}@media (-ms-high-contrast:active),(-ms-high-contrast:none){.swal2-popup.swal2-toast .swal2-icon .swal2-icon-content{font-size:.25em}}.swal2-popup.swal2-toast .swal2-icon.swal2-success .swal2-success-ring{height:2em;width:2em}.swal2-popup.swal2-toast .swal2-icon.swal2-error [class^=swal2-x-mark-line]{top:.875em;width:1.375em}.swal2-popup.swal2-toast .swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=left]{left:.3125em}.swal2-popup.swal2-toast .swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=right]{right:.3125em}.swal2-popup.swal2-toast .swal2-actions{align-self:stretch;flex:1;flex-basis:auto!important;height:2.2em;height:auto;margin:.3125em .3125em 0;padding:0;width:auto}.swal2-popup.swal2-toast .swal2-styled{font-size:1em;margin:.125em .3125em;padding:.3125em .625em}.swal2-popup.swal2-toast .swal2-styled:focus{box-shadow:0 0 0 1px #fff,0 0 0 3px rgba(100,150,200,.5)}.swal2-popup.swal2-toast .swal2-success{border-color:#a5dc86}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-circular-line]{border-radius:50%;height:3em;position:absolute;transform:rotate(45deg);width:1.6em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-circular-line][class$=left]{border-radius:4em 0 0 4em;left:-.5em;top:-.8em;transform:rotate(-45deg);transform-origin:2em 2em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-circular-line][class$=right]{border-radius:0 4em 4em 0;left:.9375em;top:-.25em;transform-origin:0 1.5em}.swal2-popup.swal2-toast .swal2-success .swal2-success-ring{height:2em;width:2em}.swal2-popup.swal2-toast .swal2-success .swal2-success-fix{height:2.6875em;left:.4375em;top:0;width:.4375em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-line]{height:.3125em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-line][class$=tip]{left:.1875em;top:1.125em;width:.75em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-line][class$=long]{right:.1875em;top:.9375em;width:1.375em}.swal2-popup.swal2-toast .swal2-success.swal2-icon-show .swal2-success-line-tip{animation:swal2-toast-animate-success-line-tip .75s}.swal2-popup.swal2-toast .swal2-success.swal2-icon-show .swal2-success-line-long{animation:swal2-toast-animate-success-line-long .75s}.swal2-popup.swal2-toast.swal2-show{animation:swal2-toast-show .5s}.swal2-popup.swal2-toast.swal2-hide{animation:swal2-toast-hide .1s forwards}.swal2-container{-webkit-overflow-scrolling:touch;align-items:center;bottom:0;display:flex;flex-direction:row;justify-content:center;left:0;overflow-x:hidden;padding:16px;position:fixed;right:0;top:0;transition:background-color .1s;z-index:1060}.swal2-container.swal2-backdrop-show,.swal2-container.swal2-noanimation{background:rgba(0,0,0,.4)}.swal2-container.swal2-backdrop-hide{background:transparent!important}.swal2-container.swal2-top{align-items:flex-start}.swal2-container.swal2-top-left,.swal2-container.swal2-top-start{align-items:flex-start;justify-content:flex-start}.swal2-container.swal2-top-end,.swal2-container.swal2-top-right{align-items:flex-start;justify-content:flex-end}.swal2-container.swal2-center{align-items:center}.swal2-container.swal2-center-left,.swal2-container.swal2-center-start{align-items:center;justify-content:flex-start}.swal2-container.swal2-center-end,.swal2-container.swal2-center-right{align-items:center;justify-content:flex-end}.swal2-container.swal2-bottom{align-items:flex-end}.swal2-container.swal2-bottom-left,.swal2-container.swal2-bottom-start{align-items:flex-end;justify-content:flex-start}.swal2-container.swal2-bottom-end,.swal2-container.swal2-bottom-right{align-items:flex-end;justify-content:flex-end}.swal2-container.swal2-bottom-end>:first-child,.swal2-container.swal2-bottom-left>:first-child,.swal2-container.swal2-bottom-right>:first-child,.swal2-container.swal2-bottom-start>:first-child,.swal2-container.swal2-bottom>:first-child{margin-top:auto}.swal2-container.swal2-grow-fullscreen>.swal2-modal{align-self:stretch;display:flex!important;flex:1;justify-content:center}.swal2-container.swal2-grow-row>.swal2-modal{align-content:center;display:flex!important;flex:1;justify-content:center}.swal2-container.swal2-grow-column{flex:1;flex-direction:column}.swal2-container.swal2-grow-column.swal2-bottom,.swal2-container.swal2-grow-column.swal2-center,.swal2-container.swal2-grow-column.swal2-top{align-items:center}.swal2-container.swal2-grow-column.swal2-bottom-left,.swal2-container.swal2-grow-column.swal2-bottom-start,.swal2-container.swal2-grow-column.swal2-center-left,.swal2-container.swal2-grow-column.swal2-center-start,.swal2-container.swal2-grow-column.swal2-top-left,.swal2-container.swal2-grow-column.swal2-top-start{align-items:flex-start}.swal2-container.swal2-grow-column.swal2-bottom-end,.swal2-container.swal2-grow-column.swal2-bottom-right,.swal2-container.swal2-grow-column.swal2-center-end,.swal2-container.swal2-grow-column.swal2-center-right,.swal2-container.swal2-grow-column.swal2-top-end,.swal2-container.swal2-grow-column.swal2-top-right{align-items:flex-end}.swal2-container.swal2-grow-column>.swal2-modal{align-content:center;display:flex!important;flex:1;justify-content:center}.swal2-container.swal2-no-transition{transition:none!important}.swal2-container:not(.swal2-top):not(.swal2-top-start):not(.swal2-top-end):not(.swal2-top-left):not(.swal2-top-right):not(.swal2-center-start):not(.swal2-center-end):not(.swal2-center-left):not(.swal2-center-right):not(.swal2-bottom):not(.swal2-bottom-start):not(.swal2-bottom-end):not(.swal2-bottom-left):not(.swal2-bottom-right):not(.swal2-grow-fullscreen)>.swal2-modal{margin:auto}@media (-ms-high-contrast:active),(-ms-high-contrast:none){.swal2-container .swal2-modal{margin:0!important}}.swal2-popup{background:#fff;border:none;border-radius:5px;box-sizing:border-box;display:none;flex-direction:column;font-family:inherit;font-size:1rem;justify-content:center;max-width:100%;padding:24px 24px 20px;position:relative;width:512px}.swal2-popup:focus{outline:none}.swal2-popup.swal2-loading{overflow-y:hidden}.swal2-header{align-items:center;display:flex;flex-direction:column;padding:0 1.8em}.swal2-title{word-wrap:break-word;color:#595959;font-size:25px;font-weight:600;margin:0 0 18px;max-width:100%;padding:0;position:relative;text-align:center;text-transform:none}.swal2-actions{align-items:center;box-sizing:border-box;display:flex;flex-wrap:wrap;justify-content:center;margin:40px auto 0;padding:12px 0 0;width:100%;z-index:1}.swal2-actions:not(.swal2-loading) .swal2-styled[disabled]{opacity:.4}.swal2-actions:not(.swal2-loading) .swal2-styled:hover{background-image:linear-gradient(rgba(0,0,0,.1),rgba(0,0,0,.1))}.swal2-actions:not(.swal2-loading) .swal2-styled:active{background-image:linear-gradient(rgba(0,0,0,.2),rgba(0,0,0,.2))}.swal2-loader{align-items:center;animation:swal2-rotate-loading 1.5s linear 0s infinite normal;border-color:#2778c4 transparent;border-radius:100%;border-style:solid;border-width:.25em;display:none;height:2.2em;justify-content:center;margin:0 1.875em;width:2.2em}.swal2-styled{box-shadow:none;font-weight:400;margin:4px;padding:8px 24px}.swal2-styled:not([disabled]){cursor:pointer}.swal2-styled.swal2-confirm{background:initial;background-color:#1f93ff;border:0;border-radius:3px;color:#fff;font-size:16px}.swal2-styled.swal2-deny{background:initial;background-color:#e75146;border:0;border-radius:3px;color:#fff;font-size:16px}.swal2-styled.swal2-cancel{background:initial;background-color:transparent;border:0;border-radius:3px;color:#848484;font-size:16px}.swal2-styled:focus{box-shadow:0 0 0 3px rgba(100,150,200,.5);outline:none}.swal2-styled::-moz-focus-inner{border:0}.swal2-footer{border-top:1px solid #eee;color:#545454;font-size:1em;justify-content:center;margin:1.25em 0 0;padding:1em 0 0}.swal2-timer-progress-bar-container{border-bottom-left-radius:5px;border-bottom-right-radius:5px;bottom:0;height:.25em;left:0;overflow:hidden;position:absolute;right:0}.swal2-timer-progress-bar{background:rgba(0,0,0,.2);height:.25em;width:100%}.swal2-image{margin:24px auto 26px;max-width:100%}.swal2-close{align-items:center;background:transparent;border:none;border-radius:5px;color:#ccc;cursor:pointer;font-family:serif;font-size:2.5em;height:1.2em;justify-content:center;line-height:1.2;overflow:hidden;padding:0;position:absolute;right:0;top:0;transition:color .1s ease-out;width:1.2em;z-index:2}.swal2-close:hover{background:transparent;color:#f27474;transform:none}.swal2-close:focus{box-shadow:inset 0 0 0 3px rgba(100,150,200,.5);outline:none}.swal2-close::-moz-focus-inner{border:0}.swal2-content{word-wrap:break-word;color:#848484;font-size:16px;font-weight:400;justify-content:center;line-height:1.4em;margin:-5px 0;padding:0 1.6em;text-align:center;z-index:1}.swal2-checkbox,.swal2-file,.swal2-input,.swal2-radio,.swal2-select,.swal2-textarea{margin:1em auto}.swal2-file,.swal2-input,.swal2-textarea{background:inherit;border:1px solid #d9d9d9;border-radius:.1875em;box-shadow:inset 0 1px 1px rgba(0,0,0,.06);box-sizing:border-box;color:inherit;font-size:1.125em;transition:border-color .3s,box-shadow .3s;width:100%}.swal2-file.swal2-inputerror,.swal2-input.swal2-inputerror,.swal2-textarea.swal2-inputerror{border-color:#f27474!important;box-shadow:0 0 2px #f27474!important}.swal2-file:focus,.swal2-input:focus,.swal2-textarea:focus{border:1px solid #b4dbed;box-shadow:0 0 0 3px rgba(100,150,200,.5);outline:none}.swal2-file::-moz-placeholder,.swal2-input::-moz-placeholder,.swal2-textarea::-moz-placeholder{color:#ccc}.swal2-file::placeholder,.swal2-input::placeholder,.swal2-textarea::placeholder{color:#ccc}.swal2-range{background:#fff;margin:1em auto}.swal2-range input{width:80%}.swal2-range output{color:inherit;font-weight:600;text-align:center;width:20%}.swal2-range input,.swal2-range output{font-size:1.125em;height:2.625em;line-height:2.625em;padding:0}.swal2-input{height:2.625em;padding:0 .75em}.swal2-input[type=number]{max-width:10em}.swal2-file{background:inherit;font-size:1.125em}.swal2-textarea{height:6.75em;padding:.75em}.swal2-select{background:inherit;color:inherit;font-size:1.125em;max-width:100%;min-width:50%;padding:.375em .625em}.swal2-checkbox,.swal2-radio{align-items:center;background:#fff;color:inherit;justify-content:center}.swal2-checkbox label,.swal2-radio label{font-size:1.125em;margin:0 .6em}.swal2-checkbox input,.swal2-radio input{flex-shrink:0;margin:0 .4em}.swal2-input-label{display:flex;justify-content:center;margin:1em auto}.swal2-validation-message{align-items:center;background:#f0f0f0;color:#666;font-size:1em;font-weight:300;justify-content:center;margin:0 -2.7em;overflow:hidden;padding:.625em}.swal2-validation-message:before{background-color:#f27474;border-radius:50%;color:#fff;content:"!";display:inline-block;font-weight:600;height:1.5em;line-height:1.5em;margin:0 .625em;min-width:1.5em;text-align:center;width:1.5em}.swal2-icon{border:.25em solid #000;border-radius:50%;box-sizing:content-box;cursor:default;font-family:inherit;height:5em;justify-content:center;line-height:5em;margin:24px auto 32px;position:relative;-webkit-user-select:none;-moz-user-select:none;user-select:none;width:5em}.swal2-icon .swal2-icon-content{align-items:center;display:flex;font-size:3.75em}.swal2-icon.swal2-error{border-color:#f27474;color:#f27474}.swal2-icon.swal2-error .swal2-x-mark{flex-grow:1;position:relative}.swal2-icon.swal2-error [class^=swal2-x-mark-line]{background-color:#f27474;border-radius:.125em;display:block;height:.3125em;position:absolute;top:2.3125em;width:2.9375em}.swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=left]{left:1.0625em;transform:rotate(45deg)}.swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=right]{right:1em;transform:rotate(-45deg)}.swal2-icon.swal2-error.swal2-icon-show{animation:swal2-animate-error-icon .5s}.swal2-icon.swal2-error.swal2-icon-show .swal2-x-mark{animation:swal2-animate-error-x-mark .5s}.swal2-icon.swal2-warning{border-color:#facea8;color:#f8bb86}.swal2-icon.swal2-info{border-color:#9de0f6;color:#3fc3ee}.swal2-icon.swal2-question{border-color:#c9dae1;color:#87adbd}.swal2-icon.swal2-success{border-color:#a5dc86;color:#a5dc86}.swal2-icon.swal2-success [class^=swal2-success-circular-line]{border-radius:50%;height:7.5em;position:absolute;transform:rotate(45deg);width:3.75em}.swal2-icon.swal2-success [class^=swal2-success-circular-line][class$=left]{border-radius:7.5em 0 0 7.5em;left:-2.0635em;top:-.4375em;transform:rotate(-45deg);transform-origin:3.75em 3.75em}.swal2-icon.swal2-success [class^=swal2-success-circular-line][class$=right]{border-radius:0 7.5em 7.5em 0;left:1.875em;top:-.6875em;transform:rotate(-45deg);transform-origin:0 3.75em}.swal2-icon.swal2-success .swal2-success-ring{border:.25em solid hsla(98,55%,69%,.3);border-radius:50%;box-sizing:content-box;height:100%;left:-.25em;position:absolute;top:-.25em;width:100%;z-index:2}.swal2-icon.swal2-success .swal2-success-fix{height:5.625em;left:1.625em;position:absolute;top:.5em;transform:rotate(-45deg);width:.4375em;z-index:1}.swal2-icon.swal2-success [class^=swal2-success-line]{background-color:#a5dc86;border-radius:.125em;display:block;height:.3125em;position:absolute;z-index:2}.swal2-icon.swal2-success [class^=swal2-success-line][class$=tip]{left:.8125em;top:2.875em;transform:rotate(45deg);width:1.5625em}.swal2-icon.swal2-success [class^=swal2-success-line][class$=long]{right:.5em;top:2.375em;transform:rotate(-45deg);width:2.9375em}.swal2-icon.swal2-success.swal2-icon-show .swal2-success-line-tip{animation:swal2-animate-success-line-tip .75s}.swal2-icon.swal2-success.swal2-icon-show .swal2-success-line-long{animation:swal2-animate-success-line-long .75s}.swal2-icon.swal2-success.swal2-icon-show .swal2-success-circular-line-right{animation:swal2-rotate-success-circular-line 4.25s ease-in}.swal2-progress-steps{align-items:center;background:inherit;flex-wrap:wrap;font-weight:600;margin:0 0 1.25em;max-width:100%;padding:0}.swal2-progress-steps li{display:inline-block;position:relative}.swal2-progress-steps .swal2-progress-step{background:#2778c4;border-radius:2em;color:#fff;flex-shrink:0;height:2em;line-height:2em;text-align:center;width:2em;z-index:20}.swal2-progress-steps .swal2-progress-step.swal2-active-progress-step{background:#2778c4}.swal2-progress-steps .swal2-progress-step.swal2-active-progress-step~.swal2-progress-step{background:#add8e6;color:#fff}.swal2-progress-steps .swal2-progress-step.swal2-active-progress-step~.swal2-progress-step-line{background:#add8e6}.swal2-progress-steps .swal2-progress-step-line{background:#2778c4;flex-shrink:0;height:.4em;margin:0 -1px;width:2.5em;z-index:10}[class^=swal2]{-webkit-tap-highlight-color:transparent}.swal2-hide,.swal2-show{animation:none}.swal2-noanimation{transition:none}.swal2-scrollbar-measure{height:50px;overflow:scroll;position:absolute;top:-9999px;width:50px}.swal2-rtl .swal2-close{left:0;right:auto}.swal2-rtl .swal2-timer-progress-bar{left:auto;right:0}@supports (-ms-accelerator:true){.swal2-range input{width:100%!important}.swal2-range output{display:none}}@media (-ms-high-contrast:active),(-ms-high-contrast:none){.swal2-range input{width:100%!important}.swal2-range output{display:none}}@keyframes swal2-toast-show{0%{transform:translateY(-.625em) rotate(2deg)}33%{transform:translateY(0) rotate(-2deg)}66%{transform:translateY(.3125em) rotate(2deg)}to{transform:translateY(0) rotate(0deg)}}@keyframes swal2-toast-hide{to{opacity:0;transform:rotate(1deg)}}@keyframes swal2-toast-animate-success-line-tip{0%{left:.0625em;top:.5625em;width:0}54%{left:.125em;top:.125em;width:0}70%{left:-.25em;top:.625em;width:1.625em}84%{left:.75em;top:1.0625em;width:.5em}to{left:.1875em;top:1.125em;width:.75em}}@keyframes swal2-toast-animate-success-line-long{0%{right:1.375em;top:1.625em;width:0}65%{right:.9375em;top:1.25em;width:0}84%{right:0;top:.9375em;width:1.125em}to{right:.1875em;top:.9375em;width:1.375em}}@keyframes swal2-show{0%{transform:scale(.7)}45%{transform:scale(1.05)}80%{transform:scale(.95)}to{transform:scale(1)}}@keyframes swal2-hide{0%{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.5)}}@keyframes swal2-animate-success-line-tip{0%{left:.0625em;top:1.1875em;width:0}54%{left:.125em;top:1.0625em;width:0}70%{left:-.375em;top:2.1875em;width:3.125em}84%{left:1.3125em;top:3em;width:1.0625em}to{left:.8125em;top:2.8125em;width:1.5625em}}@keyframes swal2-animate-success-line-long{0%{right:2.875em;top:3.375em;width:0}65%{right:2.875em;top:3.375em;width:0}84%{right:0;top:2.1875em;width:3.4375em}to{right:.5em;top:2.375em;width:2.9375em}}@keyframes swal2-rotate-success-circular-line{0%{transform:rotate(-45deg)}5%{transform:rotate(-45deg)}12%{transform:rotate(-405deg)}to{transform:rotate(-405deg)}}@keyframes swal2-animate-error-x-mark{0%{margin-top:1.625em;opacity:0;transform:scale(.4)}50%{margin-top:1.625em;opacity:0;transform:scale(.4)}80%{margin-top:-.375em;transform:scale(1.15)}to{margin-top:0;opacity:1;transform:scale(1)}}@keyframes swal2-animate-error-icon{0%{opacity:0;transform:rotateX(100deg)}to{opacity:1;transform:rotateX(0deg)}}@keyframes swal2-rotate-loading{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}}body.swal2-shown:not(.swal2-no-backdrop):not(.swal2-toast-shown){overflow:hidden}body.swal2-height-auto{height:auto!important}body.swal2-no-backdrop .swal2-container{background-color:transparent!important;bottom:auto;left:auto;max-width:calc(100% - 32px);right:auto;top:auto}body.swal2-no-backdrop .swal2-container>.swal2-modal{box-shadow:0 0 10px rgba(0,0,0,.4)}body.swal2-no-backdrop .swal2-container.swal2-top{left:50%;top:0;transform:translateX(-50%)}body.swal2-no-backdrop .swal2-container.swal2-top-left,body.swal2-no-backdrop .swal2-container.swal2-top-start{left:0;top:0}body.swal2-no-backdrop .swal2-container.swal2-top-end,body.swal2-no-backdrop .swal2-container.swal2-top-right{right:0;top:0}body.swal2-no-backdrop .swal2-container.swal2-center{left:50%;top:50%;transform:translate(-50%,-50%)}body.swal2-no-backdrop .swal2-container.swal2-center-left,body.swal2-no-backdrop .swal2-container.swal2-center-start{left:0;top:50%;transform:translateY(-50%)}body.swal2-no-backdrop .swal2-container.swal2-center-end,body.swal2-no-backdrop .swal2-container.swal2-center-right{right:0;top:50%;transform:translateY(-50%)}body.swal2-no-backdrop .swal2-container.swal2-bottom{bottom:0;left:50%;transform:translateX(-50%)}body.swal2-no-backdrop .swal2-container.swal2-bottom-left,body.swal2-no-backdrop .swal2-container.swal2-bottom-start{bottom:0;left:0}body.swal2-no-backdrop .swal2-container.swal2-bottom-end,body.swal2-no-backdrop .swal2-container.swal2-bottom-right{bottom:0;right:0}@media print{body.swal2-shown:not(.swal2-no-backdrop):not(.swal2-toast-shown){overflow-y:scroll!important}body.swal2-shown:not(.swal2-no-backdrop):not(.swal2-toast-shown)>[aria-hidden=true]{display:none}body.swal2-shown:not(.swal2-no-backdrop):not(.swal2-toast-shown) .swal2-container{position:static!important}}body.swal2-toast-shown .swal2-container{background-color:transparent}body.swal2-toast-shown .swal2-container.swal2-top{bottom:auto;left:50%;right:auto;top:0;transform:translateX(-50%)}body.swal2-toast-shown .swal2-container.swal2-top-end,body.swal2-toast-shown .swal2-container.swal2-top-right{bottom:auto;left:auto;right:0;top:0}body.swal2-toast-shown .swal2-container.swal2-top-left,body.swal2-toast-shown .swal2-container.swal2-top-start{bottom:auto;left:0;right:auto;top:0}body.swal2-toast-shown .swal2-container.swal2-center-left,body.swal2-toast-shown .swal2-container.swal2-center-start{bottom:auto;left:0;right:auto;top:50%;transform:translateY(-50%)}body.swal2-toast-shown .swal2-container.swal2-center{bottom:auto;left:50%;right:auto;top:50%;transform:translate(-50%,-50%)}body.swal2-toast-shown .swal2-container.swal2-center-end,body.swal2-toast-shown .swal2-container.swal2-center-right{bottom:auto;left:auto;right:0;top:50%;transform:translateY(-50%)}body.swal2-toast-shown .swal2-container.swal2-bottom-left,body.swal2-toast-shown .swal2-container.swal2-bottom-start{bottom:0;left:0;right:auto;top:auto}body.swal2-toast-shown .swal2-container.swal2-bottom{bottom:0;left:50%;right:auto;top:auto;transform:translateX(-50%)}body.swal2-toast-shown .swal2-container.swal2-bottom-end,body.swal2-toast-shown .swal2-container.swal2-bottom-right{bottom:0;left:auto;right:0;top:auto}.swal2-actions{border-top:1px solid #e0e0e0}';const pn=new a({app:"webhooks",version:"2022-10-20"});function mn({afterCreateOptions:n,automations:a,blankStateLink:r,canCreate:l,defaultApp:c,description:u,hasActiveAutomations:p,loading:m,onPauseAutomations:h,theme:w,trigger:f}){const[b,v]=W(!1),x={size:"md",theme:"primary"},y=l&&!p;return e(i,{axis:"horizontal",alignment:"center",backgroundColor:y?ze.statusWarning94:void 0,borderBottom:y?void 0:`1px solid ${ze.neutral88}`,"data-testid":"automations-header",distribution:"space-between",marginHorizontal:-3,marginBottom:2,marginTop:-3,paddingHorizontal:3,paddingVertical:2,spacing:2,wrap:!0,zIndex:2,children:[l&&!p?e(i,{axis:"horizontal",alignment:"center",marginHorizontal:1,spacing:1,children:[t(g,{size:2,color:ze.statusWarning49,name:"general.exclamationTriangle"}),t(o,{color:ze.neutral12,level:2,size:"18px",children:"Automations are currently paused"})]}):t(o,{color:ze.neutral12,level:2,size:"18px",children:m?"Active automations":He(a.length,"active automation")}),l&&(p?e(i,{axis:"horizontal",alignment:"center",spacing:1,children:[a.length>0&&t(d,ge({onClick:h},x,{variant:"outline",children:"Pause automations"})),t(d,ge({},x,{variant:"fill",onClick:()=>v(!0),children:"Create automation"})),t(dn,{open:b,onRequestClose:()=>v(!1),theme:w,children:t(tn,{description:u,blankStateLink:r,defaultApp:c,trigger:f,onRequestClose:()=>v(!1),afterCreateOptions:n})})]}):t(s,{children:e(i,{axis:"horizontal",alignment:"center",spacing:1,children:[t(d,ge({},x,{backgroundColor:"success",hover:{backgroundColor:"success-dark"},active:{backgroundColor:"success-darker"},onClick:h,children:"Enable automations"})),t(d,ge({},x,{disabled:!0,tooltip:{title:"Automations must be enabled to create new ones"},children:"Create automation"}))]})}))]})}function hn({afterCreateOptions:a,blankStateDescription:l,blankStateLink:c="https://pcopeople.zendesk.com/hc/en-us/articles/217582148-Automations",currentPersonId:u,currentPersonCanCreate:p,defaultApp:h,incomingAutomationsParam:g,theme:f,trigger:b,currentOrganization:v,permissionDeniedReason:x="You need permissions of Editor or above to add an automation."}){V(()=>{if(!b)return O(!1);(async function(e){const{data:t}=await xt.get({data:{_e:e,fields:{AutomationSubscription:"id,description,created_at,created_by,operation_app_name,operation_definition_class_name,operation_params,active,created_by_name,name,trigger_admin_url,events_status,trigger_params",Person:"name"},include:"created_by"},url:"automation_subscriptions"});return t})(b.resource).then(kt).then(Ct).then(_e).then(k).then(()=>O(!1))},[null==b?void 0:b.resource]);const[y,k]=W([]),[S,O]=W(!0),[A,$]=W(!1),{dateFormat:L,twentyFourHourTime:P,olsonTimeZone:F}=v,T=new URLSearchParams(window.location.search).get("automation_id"),I=ge({},f,{icons:ge({},Ce)});V(()=>{document.body.toggleAttribute("data-loading-automations",S)},[S]);const D=!y.length||y.some(e=>e.active);function H(e){pn.delete({data:{_e:b.resource},url:`/automation_subscriptions/${e}`}).then(()=>k(y.filter(t=>t.id!==e))).catch(()=>ve.fire({text:"There was a problem deleting this automation. Please try again in a few moments.",title:"Uh oh!"}))}const j={color:ze.neutral24,level:2,size:"25px",weight:700},B={color:ze.neutral45,lineHeight:3,size:3};return e(w,{theme:I,children:[e(be.Provider,{value:{dateFormat:L,olsonTimeZone:F,twentyFourHourTime:P},children:[b&&t(mn,{automations:y,blankStateLink:c,canCreate:p,loading:S,defaultApp:h,description:l,theme:I,trigger:b,hasActiveAutomations:D,onPauseAutomations:function(){pn.post({data:{data:{attributes:{_e:b.resource,active:!D}}},url:"/pause_automations"}).then(()=>{window.location.reload()})},afterCreateOptions:a}),S?t(C,{image:t(z,{size:"xl"}),paddingVertical:10,title:"Loading automations..."}):b?t(s,{"data-testid":"automations-section",children:(null==y?void 0:y.length)>0?t(_,{spacing:3,marginVertical:3,minCellWidth:45,children:y.map(e=>{return t(rt,{automation:e,onDelete:H,theme:I,openHistoryNow:e.id===Number(T),trigger:{event:(n=e,b.events.find(e=>e.name===n.name)),resource:b.resource},currentPersonId:u,currentPersonCanCreate:p},e.id);var n})}):e(i,{margin:6,spacing:2,alignment:"center",mediaQueries:{lg:{axis:"horizontal",distribution:"center",spacing:6}},children:[t(s,{css:{".symbol":{height:"100%",width:"100%"}},maxWidth:24,mediaQueries:{lg:{maxWidth:40}},children:t(fe,{})}),t(i,{alignment:"center",spacing:1,maxWidth:45,mediaQueries:{lg:{alignment:"start",textAlign:"left"}},textAlign:"center",children:e(n,p?{children:[t(o,ge({},j,{children:"Add an automation"})),t(i,{alignment:"center",marginBottom:1,mediaQueries:{lg:{alignment:"start"}},spacing:1,children:e(r,ge({},B,{children:[l," ",t(m,{inline:!0,external:!0,to:c,children:"Learn more"}),"."]}))}),t(d,{as:"button",theme:"primary",variant:"fill",onClick:()=>$(!0),children:"Create automation"}),t(dn,{open:A,onRequestClose:()=>$(!1),theme:I,children:t(tn,{defaultApp:h,description:l,blankStateLink:c,onRequestClose:()=>$(!1),trigger:b,afterCreateOptions:a})})]}:{children:[t(o,ge({},j,{children:"Automations"})),t(r,ge({},B,{children:x}))]})})]})}):t(n,{}),g&&t(Lt,{encryptedParam:g,trigger:b})]}),t("style",{children:un})]})}export{hn as Automations};
2
2
  //# sourceMappingURL=core-automations.modern.mjs.map