import{html as e}from"lit";import{getTemplateWrapper as t,rankWith as r,mapStateToControlProps as l,mapDispatchToControlProps as a,and as d,isObjectControl as s,schemaMatches as n}from"@openremote/or-json-forms";import{INTUITIVE_NOT_APPLICABLE as o}from"@openremote/or-scheduler";let DISABLED_FREQUENCIES=["SECONDLY"],DISABLED_RRULE_PARTS=["bysecond"],schedulerTester=r(6,d(s,n(e=>"simulator-schedule"===e.format))),schedulerRenderer=(r,d)=>{var s,n,i,u;let h;d=Object.assign(Object.assign(Object.assign({},d),l({jsonforms:Object.assign({},r)},d)),a(r.dispatch));let c=Date.now(),m=c-c%864e5,p={start:m,end:m+864e5},f=(null!=(u=null==(i=null==(n=null==(s=r.core)?void 0:s.data)?void 0:n.replayData)?void 0:i.filter(e=>"number"==typeof(null==e?void 0:e.timestamp)))?u:[]).reduce((e,t)=>t.timestamp>e?t.timestamp:e,0);return(f&&(p.end=m+1e3*f),Object.keys(d.data).length)?(!d.required&&d.path&&(h=()=>{d.handleChange(d.path,void 0)}),t(e`
        <or-scheduler
            header="scheduleSimulatorActivity"
            defaultEventTypeLabel="defaultSimulatorSchedule"
            disableNegativeByPartValues
            removable
            .defaultSchedule="${p}"
            .disabledFrequencies="${DISABLED_FREQUENCIES}"
            .disabledRRuleParts="${DISABLED_RRULE_PARTS}"
            .disabledByPartCombinations="${o}"
            .schedule="${d.data}"
            .timezoneOffset="${6e4*new Date().getTimezoneOffset()}"
            @or-scheduler-changed="${e=>{let t=null==e?void 0:e.detail.value;(null==t?void 0:t.start)&&(null==t?void 0:t.end)&&d.handleChange(d.path,t)}}"
            @or-scheduler-removed="${h}"
        >
        </or-scheduler>
    `,h)):d.handleChange(d.path,p)};export const schedulerRendererRegistryEntry={tester:schedulerTester,renderer:schedulerRenderer};