import{__decorate as t}from"tslib";import{html as e}from"lit";import{property as i,query as s,customElement as n}from"lit/decorators.js";import{s as a}from"./nile-date-picker.css.esm.js";import{N as r}from"../internal/nile-element.esm.js";import{p as o,n as l,f as h}from"./nile-date-picker-utils.esm.js";import"../internal/accessibility/a11y.state.enum.esm.js";import"../internal/accessibility/a11y.property.enum.esm.js";import"../internal/accessibility/role.enum.esm.js";let d=class extends r{constructor(){super(...arguments),this.range=!1,this.hideTypes=!1,this.doubleClickUnselect=!1,this.allowClear=!1,this.open=!1,this.hideTimeZone=!1,this.type="absolute",this.showManualInputs=!1,this.hideDurationFields=[],this.allowedDates="{}",this.syncDatePicker=!1,this.dateFormat="DD/MM/YYYY",this.rangeSeparator=" - ",this.showYearDropdown=!1,this.showMonthDropdown=!1,this.portal=!1,this.disabled=!1}static get styles(){return[a]}firstUpdated(){if(super.firstUpdated?.(new Map),!this.syncDatePicker)return;const t=this.querySelector("nile-input");t&&t.addEventListener("nile-input",(t=>{const e=t.detail.value,{first:i,second:s}=o(e,this.dateFormat,this.range,this.rangeSeparator);if(this.range){if(i&&!s&&(this.jumpTo(i),this.syncRangeCalendar(i,null)),i&&s){const[t,e]=l(i,s);e&&this.jumpTo(e),this.syncRangeCalendar(t,e)}}else i&&this.jumpTo(i)}))}updated(t){super.updated(t),t.has("disabled")&&this.updateTriggerDisabledState()}updateTriggerDisabledState(){const t=this.querySelector('[slot="trigger"]');t&&"disabled"in t&&(t.disabled=this.disabled)}jumpTo(t){this.open=!0;const e=this.shadowRoot.querySelector("nile-calendar");e&&(e.currentYear=t.getFullYear(),e.currentMonth=t.getMonth(),e.value=t,e.valueAttribute=t.toISOString())}syncRangeCalendar(t,e){const i=this.shadowRoot.querySelector("nile-calendar");i&&this.range&&(t&&(i.startDate=t),e&&(i.endDate=e))}render(){return e`
      <nile-dropdown ?disabled="${this.disabled}" .open="${this.open}" part="dd-base" .hoist="${!0}" distance="6" exportparts="base" .portal="${this.portal}">
        <slot slot="trigger" part="trigger" name="trigger"></slot>  

        <nile-calendar
          .hideTypes="${this.hideTypes}"
          .type="${this.type}"
          value="${this.value}"
          .range="${this.range}"
          @nile-init="${t=>t.stopPropagation()}"
          @nile-destroy="${t=>t.stopPropagation()}"
          @nile-changed="${t=>t.stopPropagation()}"

          @nile-change="${this.handleChanged}"

          .allowedDates="${this.allowedDates}"

          @nile-type-change="${t=>{t.stopPropagation(),this.emit("nile-type-change",t.detail)}}"
          @nile-clear="${t=>{t.stopPropagation(),this.emit("nile-clear")}}"
          .hideDurationFields="${this.hideDurationFields}"
          .showManualInputs="${this.showManualInputs}"
          .doubleClickUnselect="${this.doubleClickUnselect}"
          .allowClear="${this.allowClear}"
          .startYear="${this.startYear}"
          .endYear="${this.endYear}"
          ?showYearDropdown="${this.showYearDropdown}"
          ?showMonthDropdown="${this.showMonthDropdown}"
          .dateFormat="${this.dateFormat}"
        ></nile-calendar>
      </nile-dropdown>
    `}handleChanged(t){t.stopPropagation();const e=t.detail,i=this.querySelector("nile-input");if(this.disabled)return;if(!this.range){const s=e.value;return s&&i&&(i.value=h(new Date(s),this.dateFormat),i.emit("nile-input",{value:i.value})),this.emit("nile-changed",t.detail),this.emit("nile-change",t.detail),void this.dropdown?.hide()}const s=e.startDate,n=e.endDate;if(i){let t="";s&&(t+=h(new Date(s),this.dateFormat)),s&&n&&(t+=" - "+h(new Date(n),this.dateFormat)),i.value=t,i.emit("nile-input",{value:t})}this.emit("nile-changed",t.detail),this.emit("nile-change",t.detail),this.dropdown&&this.dropdown.hide()}connectedCallback(){super.connectedCallback(),this.emit("nile-init")}disconnectedCallback(){super.disconnectedCallback(),this.emit("nile-destroy")}};t([i({type:Boolean})],d.prototype,"range",void 0),t([i({type:Boolean})],d.prototype,"hideTypes",void 0),t([i({type:Boolean,reflect:!0})],d.prototype,"doubleClickUnselect",void 0),t([i({type:Boolean,reflect:!0})],d.prototype,"allowClear",void 0),t([i({type:Boolean})],d.prototype,"open",void 0),t([i({type:Boolean,attribute:"hide-time-zone"})],d.prototype,"hideTimeZone",void 0),t([i({type:String,reflect:!0})],d.prototype,"type",void 0),t([i({type:Boolean,attribute:"showManualInputs"})],d.prototype,"showManualInputs",void 0),t([i()],d.prototype,"value",void 0),t([i({type:Array,attribute:"hide-duration-fields"})],d.prototype,"hideDurationFields",void 0),t([i({attribute:"allowedDates"})],d.prototype,"allowedDates",void 0),t([i({type:Boolean,attribute:!0,reflect:!0})],d.prototype,"syncDatePicker",void 0),t([i({type:String,attribute:!0,reflect:!0})],d.prototype,"dateFormat",void 0),t([i({type:String,attribute:!0,reflect:!0})],d.prototype,"rangeSeparator",void 0),t([i({type:Number,attribute:!0,reflect:!0})],d.prototype,"startYear",void 0),t([i({type:Number,attribute:!0,reflect:!0})],d.prototype,"endYear",void 0),t([i({type:Boolean,attribute:!0,reflect:!0})],d.prototype,"showYearDropdown",void 0),t([i({type:Boolean,attribute:!0,reflect:!0})],d.prototype,"showMonthDropdown",void 0),t([i({type:Boolean,attribute:!0,reflect:!0})],d.prototype,"portal",void 0),t([i({type:Boolean,attribute:!0,reflect:!0})],d.prototype,"disabled",void 0),t([s("nile-dropdown")],d.prototype,"dropdown",void 0),d=t([n("nile-date-picker")],d);export{d as N};
