import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
import { S as States, A as Actions } from './utils.js';
import { d as defineCustomElement$e } from './mds-avatar2.js';
import { d as defineCustomElement$d } from './mds-button2.js';
import { d as defineCustomElement$c } from './mds-icon2.js';
import { d as defineCustomElement$b } from './mds-img2.js';
import { d as defineCustomElement$a } from './mds-text2.js';
import { d as defineCustomElement$9 } from './sw-action-footer2.js';
import { d as defineCustomElement$8 } from './sw-action-header2.js';
import { d as defineCustomElement$7 } from './sw-badge-error2.js';
import { d as defineCustomElement$6 } from './sw-checklist-item2.js';
import { d as defineCustomElement$5 } from './sw-input-text2.js';
import { d as defineCustomElement$4 } from './sw-input-text-area2.js';
import { d as defineCustomElement$3 } from './sw-inspection-form2.js';
import { d as defineCustomElement$2 } from './sw-options-menu2.js';

const swInspectionCss = "*,::before,::after{box-sizing:border-box;border-width:0;border-style:solid;border-color:currentColor;}::before,::after{--tw-content:''}html{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, \"Noto Sans\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\";font-feature-settings:normal;}body{margin:0;line-height:inherit;}hr{height:0;color:inherit;border-top-width:1px;}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:'Roboto Mono', monospace;font-size:1em;}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-0.25em}sup{top:-0.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse;}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;font-weight:inherit;line-height:inherit;color:inherit;margin:0;padding:0;}button,select{text-transform:none}button,[type='button'],[type='reset'],[type='submit']{-webkit-appearance:button;background-color:transparent;background-image:none;}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type='search']{-webkit-appearance:textfield;outline-offset:-2px;}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit;}summary{display:list-item}blockquote,dl,dd,h1,h2,h3,h4,h5,h6,hr,figure,p,pre{margin:0}fieldset{margin:0;padding:0}legend{padding:0}ol,ul,menu{list-style:none;margin:0;padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af;}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af;}button,[role=\"button\"]{cursor:pointer}:disabled{cursor:default}img,svg,video,canvas,audio,iframe,embed,object{display:block;vertical-align:middle;}img,video{max-width:100%;height:auto}[hidden]{display:none}*,::before,::after{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-scroll-snap-strictness:proximity;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgb(59 130 246 / 0.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;}::backdrop{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-scroll-snap-strictness:proximity;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgb(59 130 246 / 0.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;}.container{width:100%}@media (min-width: 768px){.container{max-width:768px}}@media (min-width: 1024px){.container{max-width:1024px}}@media (min-width: 1280px){.container{max-width:1280px}}@media (min-width: 1440px){.container{max-width:1440px}}@media (min-width: 1600px){.container{max-width:1600px}}@media (min-width: 1920px){.container{max-width:1920px}}.pointer-events-none{pointer-events:none !important}.collapse{visibility:collapse !important}.static{position:static !important}.fixed{position:fixed !important}.absolute{position:absolute !important}.relative{position:relative !important}.sticky{position:sticky !important}.top-4{top:1rem !important}.left-5{left:1.25rem !important}.bottom-0{bottom:0px !important}.right-0{right:0px !important}.my-3{margin-top:0.75rem !important;margin-bottom:0.75rem !important}.mx-6{margin-left:1.5rem !important;margin-right:1.5rem !important}.mb-2{margin-bottom:0.5rem !important}.ml-2{margin-left:0.5rem !important}.mr-10{margin-right:2.5rem !important}.ml-10{margin-left:2.5rem !important}.mr-2{margin-right:0.5rem !important}.mr-4{margin-right:1rem !important}.ml-4{margin-left:1rem !important}.block{display:block !important}.inline{display:inline !important}.flex{display:flex !important}.table{display:table !important}.hidden{display:none !important}.h-screen{height:100vh !important}.h-full{height:100% !important}.h-auto{height:auto !important}.min-h-\\[200px\\]{min-height:200px !important}.min-h-\\[50px\\]{min-height:50px !important}.w-screen{width:100vw !important}.w-\\[200px\\]{width:200px !important}.w-full{width:100% !important}.w-10{width:2.5rem !important}.w-\\[40px\\]{width:40px !important}.w-auto{width:auto !important}.w-24{width:6rem !important}.min-w-\\[200px\\]{min-width:200px !important}.max-w-\\[100px\\]{max-width:100px !important}.flex-none{flex:none !important}.grow{flex-grow:1 !important}.transform{transform:translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y)) !important}.cursor-pointer{cursor:pointer !important}.cursor-grab{cursor:grab !important}.flex-row{flex-direction:row !important}.flex-col{flex-direction:column !important}.items-center{align-items:center !important}.justify-between{justify-content:space-between !important}.whitespace-pre-wrap{white-space:pre-wrap !important}.rounded-md{border-radius:0.375rem !important}.rounded-lg{border-radius:0.5rem !important}.rounded-b-md{border-bottom-right-radius:0.375rem !important;border-bottom-left-radius:0.375rem !important}.rounded-t-md{border-top-left-radius:0.375rem !important;border-top-right-radius:0.375rem !important}.border{border-width:1px !important}.bg-brand-maggioli-05{--tw-bg-opacity:1 !important;background-color:rgba(var(--brand-maggioli-05), var(--tw-bg-opacity)) !important}.bg-brand-synbee-eolo-v1-18{--tw-bg-opacity:1 !important;background-color:rgba(var(--brand-synbee-eolo-v1-18), var(--tw-bg-opacity)) !important}.bg-brand-synbee-eolo-v1-17{--tw-bg-opacity:1 !important;background-color:rgba(var(--brand-synbee-eolo-v1-17), var(--tw-bg-opacity)) !important}.bg-brand-synbee-eolo-04{--tw-bg-opacity:1 !important;background-color:rgba(var(--brand-synbee-eolo-04), var(--tw-bg-opacity)) !important}.bg-brand-synbee-eolo-v1-06{--tw-bg-opacity:1 !important;background-color:rgba(var(--brand-synbee-eolo-v1-06), var(--tw-bg-opacity)) !important}.bg-label-amaranth-05{--tw-bg-opacity:1 !important;background-color:rgba(var(--label-amaranth-05), var(--tw-bg-opacity)) !important}.bg-label-aqua-05{--tw-bg-opacity:1 !important;background-color:rgba(var(--label-aqua-05), var(--tw-bg-opacity)) !important}.bg-label-blue-05{--tw-bg-opacity:1 !important;background-color:rgba(var(--label-blue-05), var(--tw-bg-opacity)) !important}.bg-label-green-05{--tw-bg-opacity:1 !important;background-color:rgba(var(--label-green-05), var(--tw-bg-opacity)) !important}.bg-label-lime-05{--tw-bg-opacity:1 !important;background-color:rgba(var(--label-lime-05), var(--tw-bg-opacity)) !important}.bg-label-orange-05{--tw-bg-opacity:1 !important;background-color:rgba(var(--label-orange-05), var(--tw-bg-opacity)) !important}.bg-label-orchid-05{--tw-bg-opacity:1 !important;background-color:rgba(var(--label-orchid-05), var(--tw-bg-opacity)) !important}.bg-label-sky-05{--tw-bg-opacity:1 !important;background-color:rgba(var(--label-sky-05), var(--tw-bg-opacity)) !important}.bg-label-yellow-05{--tw-bg-opacity:1 !important;background-color:rgba(var(--label-yellow-05), var(--tw-bg-opacity)) !important}.bg-label-violet-05{--tw-bg-opacity:1 !important;background-color:rgba(var(--label-violet-05), var(--tw-bg-opacity)) !important}.bg-status-error-05{--tw-bg-opacity:1 !important;background-color:rgba(var(--status-error-05), var(--tw-bg-opacity)) !important}.bg-status-info-05{--tw-bg-opacity:1 !important;background-color:rgba(var(--status-info-05), var(--tw-bg-opacity)) !important}.bg-status-success-05{--tw-bg-opacity:1 !important;background-color:rgba(var(--status-success-05), var(--tw-bg-opacity)) !important}.bg-status-warning-05{--tw-bg-opacity:1 !important;background-color:rgba(var(--status-warning-05), var(--tw-bg-opacity)) !important}.fill-label-blue-05{fill:rgb(var(--label-blue-05)) !important}.fill-label-green-06{fill:rgb(var(--label-green-06)) !important}.p-4{padding:1rem !important}.py-2{padding-top:0.5rem !important;padding-bottom:0.5rem !important}.py-3{padding-top:0.75rem !important;padding-bottom:0.75rem !important}.pr-6{padding-right:1.5rem !important}.pl-5{padding-left:1.25rem !important}.pr-4{padding-right:1rem !important}.pt-10{padding-top:2.5rem !important}.text-base{font-size:1rem !important;line-height:1.5rem !important}.text-sm{font-size:0.875rem !important;line-height:1.25rem !important}.font-bold{font-weight:700 !important}.font-normal{font-weight:400 !important}.lowercase{text-transform:lowercase !important}.text-brand-synbee-eolo-v1-06{--tw-text-opacity:1 !important;color:rgba(var(--brand-synbee-eolo-v1-06), var(--tw-text-opacity)) !important}.text-brand-synbee-eolo-v1-04{--tw-text-opacity:1 !important;color:rgba(var(--brand-synbee-eolo-v1-04), var(--tw-text-opacity)) !important}.text-adjust-tone-04{--tw-text-opacity:1 !important;color:rgba(var(--adjust-tone-04), var(--tw-text-opacity)) !important}.shadow{--tw-shadow:0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1) !important;--tw-shadow-colored:0 1px 3px 0 var(--tw-shadow-color), 0 1px 2px -1px var(--tw-shadow-color) !important;box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow) !important}.filter{filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow) !important}:host{display:block;background-color:white;border-radius:10px}.error-badge-pos{bottom:40px;left:230px}.active\\:cursor-grabbing:active{cursor:grabbing !important}";

const SwInspection$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  constructor() {
    super();
    this.__registerHost();
    this.__attachShadow();
    this.emitCancel = createEvent(this, "emitCancel", 7);
    this.emitCloseAction = createEvent(this, "emitCloseAction", 7);
    this.filterTodosValue = null;
    this.errorMessage = "Errore! Compilare i campi obbligatori";
    this.creationId = Math.floor(Math.random() * 100);
    this.inspectionGetDTO = {
      id: 1,
      name: "",
      description: "",
      startDate: new Date(),
      inspectionTodos: [],
    };
    this._inspectionGetDTO = undefined;
    this.state = States.create;
    this._state = undefined;
    this.baseUrl = "";
    this.idPluginAction = undefined;
    this.idPlugin = undefined;
    this.idTask = undefined;
    this.creationDate = undefined;
    this.editDate = undefined;
    this.actionCreator = undefined;
    this.badgeErrorOn = false;
  }
  checkBadgeErrorOn(newValue) {
    this.badgeErrorOn = newValue;
  }
  createInspection(inspectionGetDTO) {
    const inspectionCreateDTO = {
      name: inspectionGetDTO.name,
      startDate: inspectionGetDTO.startDate,
      description: inspectionGetDTO.description,
      inspectionTodos: inspectionGetDTO.inspectionTodos,
    };
    if (inspectionCreateDTO.name !== "" &&
      inspectionCreateDTO.startDate !== null) {
      fetch(`${this.baseUrl}/services/eolo-api-gateway/external-api/${this.idTask}/${this.idPluginAction}`, {
        method: "POST",
        body: JSON.stringify(inspectionCreateDTO),
        headers: {
          "Content-Type": "application/json",
        },
      })
        .then((res) => {
        this._state = States.view;
        return res.json();
      })
        .then((res) => {
        this.idPlugin = res.id;
        this._inspectionGetDTO = { ...res };
        this._inspectionGetDTO = { ...this._inspectionGetDTO };
      })
        .catch(() => {
        this.errorMessage = "Errore server!!";
        this.badgeErrorOn = true;
      });
    }
    else {
      this.errorMessage = "Errore! Compilare i campi obbligatori";
      this.badgeErrorOn = true;
    }
    setTimeout(() => {
      this.badgeErrorOn = false;
    }, 4000);
  }
  getInspection() {
    fetch(`${this.baseUrl}/services/eolo-api-gateway/external-api/${this.idPluginAction}/${this.idPlugin}`, {
      method: "GET",
    })
      .then((res) => {
      return res.json();
    })
      .then((res) => {
      this.inspectionGetDTO = { ...res };
      this._inspectionGetDTO = { ...res };
      this._inspectionGetDTO.inspectionTodos =
        this._inspectionGetDTO.inspectionTodos.sort((a, b) => a.orderNumber - b.orderNumber);
      this._inspectionGetDTO.startDate = new Date(this._inspectionGetDTO.startDate);
      this._inspectionGetDTO.startDate = this.addHours(this._inspectionGetDTO.startDate, 1);
      this._inspectionGetDTO = { ...this._inspectionGetDTO };
    })
      .catch((err) => {
      console.log(err);
    });
  }
  editInspection(inspectionGetDTO) {
    delete inspectionGetDTO["id"];
    fetch(`${this.baseUrl}/services/eolo-api-gateway/external-api/${this.idPluginAction}/${this.idPlugin}`, {
      method: "PUT",
      body: JSON.stringify(inspectionGetDTO),
      headers: {
        "Content-Type": "application/json",
      },
    })
      .then((res) => {
      console.log(res.json());
      this._inspectionGetDTO = { ...inspectionGetDTO };
      this._inspectionGetDTO = { ...this._inspectionGetDTO };
      this._state = States.view;
      /* }  else {
      this._inspectionGetDTO = this.inspectionGetDTO;
      } */
      const el = this.element.shadowRoot.querySelector("sw-inspection-form");
      el.disableEditModeItems = true;
    })
      .catch((err) => {
      console.log(err);
      this.errorMessage = "Errore server!";
      this.badgeErrorOn = true;
    });
    setTimeout(() => {
      this.badgeErrorOn = false;
    }, 4000);
  }
  deleteInspection() {
    fetch(`${this.baseUrl}/services/eolo-api-gateway/external-api/${this.idPluginAction}/${this.idPlugin}`, {
      method: "DELETE",
    }).then(() => {
      //if (res.status === 200) {
      this.emitCancel.emit({ html: this.element });
      // }
    });
  }
  changeState(ev) {
    if (ev.detail.state === "edit") {
      this._state = ev.detail.state;
    }
    else if (ev.detail.mode === "delete" &&
      ev.detail.previousState === States.create) {
      this.emitCancel.emit();
    }
    else if (ev.detail.mode === "delete" &&
      ev.detail.previousState === States.view) {
      this.deleteInspection();
    }
    else if (ev.detail.mode === "delete" &&
      ev.detail.previousState === States.edit) {
      this._state = ev.detail.state;
    }
    this.filterTodosValue = null;
  }
  goToEditState() {
    this._state = States.edit;
  }
  padTo2Digits(num) {
    return num.toString().padStart(2, "0");
  }
  formatDate(date) {
    if (!(date instanceof Date)) {
      date = new Date(date);
    }
    return [
      this.padTo2Digits(date.getDate()),
      this.padTo2Digits(date.getMonth() + 1),
      date.getFullYear(),
    ].join("/");
  }
  componentWillLoad() {
    this._state = this.state;
    if (this._state === States.view) {
      this.getInspection();
    }
    this._inspectionGetDTO = { ...this.inspectionGetDTO };
  }
  addHours(date, hours) {
    date.setHours(date.getHours() + hours);
    return date;
  }
  render() {
    return (h(Host, { id: this.creationId }, h("div", { class: "rounded-md relative" }, h("sw-action-header", { status: this._state, creationDate: this.creationDate, editDate: this.editDate, title: this._inspectionGetDTO.name, onEmitTitle: (ev) => {
        this._inspectionGetDTO.name = ev.detail;
        this._inspectionGetDTO = { ...this._inspectionGetDTO };
      }, onEmitChangeState: (ev) => this.changeState(ev), onEmitCloseAction: () => this.emitCloseAction.emit({ html: this.element }), onEmitDeleteAction: () => this.emitCancel.emit({
        html: this.element,
      }), onEmitInternalCloseAction: (ev) => {
        if (ev.detail) {
          this.element.shadowRoot.querySelector("sw-inspection-form").style.display = "none";
          this.element.shadowRoot.querySelector("sw-action-footer").style.display = "none";
        }
        else {
          this.element.shadowRoot.querySelector("sw-inspection-form").style.display = "block";
          this.element.shadowRoot.querySelector("sw-action-footer").style.display = "block";
        }
      } }), h("sw-inspection-form", { status: this._state, inspectionGetDTO: this._inspectionGetDTO, onEmitFilteredTodos: (ev) => (this.filterTodosValue = ev.detail), onUpdateInspection: (ev) => {
        this._inspectionGetDTO.inspectionTodos = [
          ...this._inspectionGetDTO.inspectionTodos,
        ];
        this._inspectionGetDTO = { ...ev.detail };
      }, onUpdateRapidTodoList: (ev) => {
        this._inspectionGetDTO.inspectionTodos = [
          ...this._inspectionGetDTO.inspectionTodos.filter((el) => el.orderNumber !== ev.detail),
        ];
        this.editInspection(this._inspectionGetDTO);
      }, onRapidSaveTodoList: (ev) => {
        this._inspectionGetDTO = { ...ev.detail };
        this.editInspection(this._inspectionGetDTO);
      }, onUpdateStatus: () => {
        this.goToEditState();
      }, filteredTodos: this.filterTodosValue }), h("sw-action-footer", { status: this._state, class: "rounded-b-md", author: this.actionCreator, onEmitSave: () => {
        switch (this._state) {
          case States.create:
            this.createInspection(this._inspectionGetDTO);
            break;
          case States.edit:
            this.editInspection(this._inspectionGetDTO);
            break;
        }
      }, onEmitCancel: (ev) => {
        if (ev.detail === Actions.delete) {
          this.emitCancel.emit({
            html: this.element,
          });
        }
        if (ev.detail === Actions.cancel) {
          this._state = States.view;
        }
      } }), this.badgeErrorOn === true ? (h("div", { class: {
        "badge-error": true,
        hidden: !this.badgeErrorOn,
        block: this.badgeErrorOn,
      } }, h("sw-badge-error", { class: "error-badge-pos" }))) : undefined)));
  }
  get element() { return this; }
  static get watchers() { return {
    "badgeErrorOn": ["checkBadgeErrorOn"]
  }; }
  static get style() { return swInspectionCss; }
}, [1, "sw-inspection", {
    "creationId": [2, "creation-id"],
    "inspectionGetDTO": [1040],
    "state": [1],
    "baseUrl": [1025, "base-url"],
    "idPluginAction": [1026, "id-plugin-action"],
    "idPlugin": [1026, "id-plugin"],
    "idTask": [1026, "id-task"],
    "creationDate": [1025, "creation-date"],
    "editDate": [1025, "edit-date"],
    "actionCreator": [1040],
    "_inspectionGetDTO": [32],
    "_state": [32],
    "badgeErrorOn": [32]
  }]);
function defineCustomElement$1() {
  if (typeof customElements === "undefined") {
    return;
  }
  const components = ["sw-inspection", "mds-avatar", "mds-button", "mds-icon", "mds-img", "mds-text", "sw-action-footer", "sw-action-header", "sw-badge-error", "sw-checklist-item", "sw-input-text", "sw-input-text-area", "sw-inspection-form", "sw-options-menu"];
  components.forEach(tagName => { switch (tagName) {
    case "sw-inspection":
      if (!customElements.get(tagName)) {
        customElements.define(tagName, SwInspection$1);
      }
      break;
    case "mds-avatar":
      if (!customElements.get(tagName)) {
        defineCustomElement$e();
      }
      break;
    case "mds-button":
      if (!customElements.get(tagName)) {
        defineCustomElement$d();
      }
      break;
    case "mds-icon":
      if (!customElements.get(tagName)) {
        defineCustomElement$c();
      }
      break;
    case "mds-img":
      if (!customElements.get(tagName)) {
        defineCustomElement$b();
      }
      break;
    case "mds-text":
      if (!customElements.get(tagName)) {
        defineCustomElement$a();
      }
      break;
    case "sw-action-footer":
      if (!customElements.get(tagName)) {
        defineCustomElement$9();
      }
      break;
    case "sw-action-header":
      if (!customElements.get(tagName)) {
        defineCustomElement$8();
      }
      break;
    case "sw-badge-error":
      if (!customElements.get(tagName)) {
        defineCustomElement$7();
      }
      break;
    case "sw-checklist-item":
      if (!customElements.get(tagName)) {
        defineCustomElement$6();
      }
      break;
    case "sw-input-text":
      if (!customElements.get(tagName)) {
        defineCustomElement$5();
      }
      break;
    case "sw-input-text-area":
      if (!customElements.get(tagName)) {
        defineCustomElement$4();
      }
      break;
    case "sw-inspection-form":
      if (!customElements.get(tagName)) {
        defineCustomElement$3();
      }
      break;
    case "sw-options-menu":
      if (!customElements.get(tagName)) {
        defineCustomElement$2();
      }
      break;
  } });
}
defineCustomElement$1();

const SwInspection = SwInspection$1;
const defineCustomElement = defineCustomElement$1;

export { SwInspection, defineCustomElement };
