import{html as e}from"lit";import{getTemplateWrapper as t,rankWith as r,mapStateToControlProps as d,mapDispatchToControlProps as a,and as l,isObjectControl as s,schemaMatches as n}from"@openremote/or-json-forms";import"@openremote/or-scheduler";let DISABLED_FREQUENCIES=["SECONDLY"],DISABLED_RRULE_PARTS=["bymonth","byweekno","byyearday","bymonthday","byhour","byminute","bysecond"],schedulerTester=r(6,l(s,n(e=>"simulator-schedule"===e.format))),schedulerRenderer=(r,l)=>{let s;l=Object.assign(Object.assign(Object.assign({},l),d({jsonforms:Object.assign({},r)},l)),a(r.dispatch));let n=Date.now(),o=n%864e5,h={start:n-o,end:n-o+864e5,recurrence:"FREQ=DAILY"};return Object.keys(l.data).length||l.handleChange(l.path,h),!l.required&&l.path&&(s=()=>{l.handleChange(l.path,void 0)}),t(e`
        <or-scheduler
            header="scheduleSimulatorActivity"
            defaultEventTypeLabel="defaultSimulatorSchedule"
            .defaultSchedule="${h}"
            .disabledFrequencies="${DISABLED_FREQUENCIES}"
            .disabledRRuleParts="${DISABLED_RRULE_PARTS}"
            .schedule="${l.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)&&l.handleChange(l.path,t)}}"
        >
        </or-scheduler>
    `,s)};export const schedulerRendererRegistryEntry={tester:schedulerTester,renderer:schedulerRenderer};