import{html as e}from"lit";import{getTemplateWrapper as r,rankWith as t,mapStateToControlProps as d,mapDispatchToControlProps as a,and as l,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=t(6,l(s,n(e=>"simulator-schedule"===e.format))),schedulerRenderer=(t,l)=>{let s;l=Object.assign(Object.assign(Object.assign({},l),d({jsonforms:Object.assign({},t)},l)),a(t.dispatch));let n=Date.now(),i=n%864e5,u={start:n-i,end:n-i+864e5,recurrence:"FREQ=DAILY"};return Object.keys(l.data).length||l.handleChange(l.path,u),!l.required&&l.path&&(s=()=>{l.handleChange(l.path,void 0)}),r(e`
        <or-scheduler
            header="scheduleSimulatorActivity"
            defaultEventTypeLabel="defaultSimulatorSchedule"
            disableNegativeByPartValues
            removable
            .defaultSchedule="${u}"
            .disabledFrequencies="${DISABLED_FREQUENCIES}"
            .disabledRRuleParts="${DISABLED_RRULE_PARTS}"
            .disabledByPartCombinations="${o}"
            .schedule="${l.data}"
            .timezoneOffset="${6e4*new Date().getTimezoneOffset()}"
            @or-scheduler-changed="${e=>{let r=null==e?void 0:e.detail.value;(null==r?void 0:r.start)&&(null==r?void 0:r.end)&&l.handleChange(l.path,r)}}"
            @or-scheduler-removed="${s}"
        >
        </or-scheduler>
    `,s)};export const schedulerRendererRegistryEntry={tester:schedulerTester,renderer:schedulerRenderer};