/*!
 * HotPocket by BTHLabs (https://hotpocket.app/)
 * Copyright 2025-present BTHLabs <contact@bthlabs.pl> (https://bthlabs.pl/)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
((HotPocket, htmx) => {
  class InlineCreateSaveForm {
    constructor (app) {
      this.app = app;
      this.element = null;
      this.buttonTrigger = null;
      this.form = null;
    }
    onLoad = (event) => {
      this.element = document.getElementById('InlineCreateSaveForm');
      this.buttonTrigger = this.element.querySelector('.ui-inline-create-save-form-trigger');
      this.buttonClose = this.element.querySelector('.ui-inline-create-save-form-close');
      this.form = this.element.querySelector('.ui-inline-create-save-form');

      this.buttonTrigger.addEventListener('click', this.onTriggerClick);
      this.buttonClose.addEventListener('click', this.onCloseClick);
    };
    onTriggerClick = (event) => {
      event.preventDefault();

      this.form.classList.remove('d-none');
      this.form.classList.add('d-flex');
    };
    onCloseClick = (event) => {
      event.stopPropagation();
      event.preventDefault();

      this.form.classList.add('d-none');
      this.form.classList.remove('d-flex');
    };
  }

  HotPocket.addPlugin('UI.InlineCreateSaveForm', (app) => {
    return new InlineCreateSaveForm(app);
  });
})(window.HotPocket, window.htmx);
