import { HTMLBuilder } from "@sankhyalabs/core";
const LIMIT_TIME_VALUE = 2359;
export const buildDate = () => {
  const dateInput = HTMLBuilder.parseElement(`<ez-date-input
            class="ez-grid grid_editor"
            mode="slim"
            data-is-fixed="true"
        />`);
  dateInput.valueGetter = () => dateInput.getValueAsync();
  dateInput.autoFocus = true;
  return dateInput;
};
export const buildTime = ({ readOnly }) => {
  const timeInputElement = HTMLBuilder.parseElement(`<ez-time-input
        class="ez-grid grid_editor"
        enabled=${!readOnly}
        mode="slim"
    />`);
  timeInputElement.valueGetter = () => {
    const value = timeInputElement.value;
    const isAllowedTime = parseInt(value) <= LIMIT_TIME_VALUE;
    return isAllowedTime ? value : null;
  };
  timeInputElement.valueSetter = (value) => {
    const isAllowedTime = parseInt(value) <= LIMIT_TIME_VALUE;
    if (!isAllowedTime)
      return timeInputElement.value = null;
    return timeInputElement.value = value;
  };
  return timeInputElement;
};
export const buildDateTime = ({ readOnly }) => {
  const dateTimeInput = HTMLBuilder.parseElement(`<ez-date-time-input
        class="ez-grid grid_editor"
        mode="slim"
        enabled=${!readOnly}
        data-is-fixed="true"
    />`);
  dateTimeInput.valueGetter = () => dateTimeInput.getValueAsync();
  return dateTimeInput;
};
