import { c as F } from "../../chunks/runtime.js";
import { css as U, html as a } from "lit";
import { ref as v } from "lit/directives/ref.js";
import { keyed as A } from "lit/directives/keyed.js";
import { watch as x } from "@arcgis/core/core/reactiveUtils.js";
import { isHTTPSProtocol as b, isDataProtocol as y } from "@arcgis/core/core/urlUtils.js";
import { formatDate as C, convertDateFormatToIntlOptions as D } from "@arcgis/core/intl.js";
import M from "@arcgis/core/widgets/Bookmarks/BookmarksViewModel.js";
import { LitElement as z, createEvent as B, safeClassMap as c, nothing as E } from "@arcgis/lumina";
import { usePropertyChange as N } from "@arcgis/lumina/controllers";
import { classes as L } from "@arcgis/toolkit/dom";
import { generateGuid as O } from "@arcgis/toolkit/string";
import { u as P } from "../../chunks/useT9n.js";
import { m as V } from "../../chunks/useViewModel.js";
import { H as q } from "../../chunks/heading.js";
import R from "@arcgis/core/core/Accessor.js";
import { property as _, subclass as H } from "@arcgis/core/core/accessorSupport/decorators.js";
/*! All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.34/esri/copyright.txt for details.
v4.34.7 */
const Z = U`.esri-widget__heading{color:var(--calcite-color-text-2);margin:0 0 .5rem;font-weight:var(--calcite-font-weight-semibold)}h1.esri-widget__heading{font-size:var(--calcite-font-size-xl)}h2.esri-widget__heading{font-size:var(--calcite-font-size-md)}h3.esri-widget__heading,h4.esri-widget__heading,h5.esri-widget__heading,h6.esri-widget__heading{font-size:var(--calcite-font-size)}.esri-widget{--esri-widget-padding-x: 15px;--esri-widget-padding-y: var(--calcite-spacing-md);--esri-widget-padding: var(--esri-widget-padding-y) var(--esri-widget-padding-x);box-sizing:border-box;color:var(--calcite-color-text-2);background-color:var(--calcite-color-foreground-1);font-size:var(--calcite-font-size);line-height:var(--calcite-font-line-height-relative-tight)}.esri-widget *,.esri-widget :before,.esri-widget :after{box-sizing:inherit}.esri-widget.esri-widget--disabled>*{opacity:.4;pointer-events:none}.esri-widget.esri-widget--compact{--esri-widget-padding-y: 0;--esri-widget-padding-x: 0}.esri-widget__anchor{color:var(--calcite-color-text-2)}.esri-widget__anchor:hover{color:var(--calcite-color-text-3)}.esri-widget__anchor:hover,.esri-widget__anchor:focus{text-decoration:underline}.esri-widget__anchor--disabled{opacity:.4;pointer-events:none}.esri-widget__header{background-color:var(--calcite-color-foreground-1);flex:1 0 100%;justify-content:space-between;align-items:center;width:100%;min-height:48px;padding:12px 0 12px 15px;display:flex}.esri-widget__header .esri-widget__heading{width:calc(100% - 48px);text-align:initial;color:var(--calcite-color-text-1);align-items:center;margin:0;padding:0;display:flex}.esri-widget__header-button{appearance:none;cursor:pointer;color:var(--calcite-color-text-2);background-color:var(--calcite-color-foreground-1);border:none;flex:0 0 48px;justify-content:center;align-self:stretch;align-items:center;width:48px;padding:0;display:flex}.esri-widget__footer{background-color:var(--calcite-color-foreground-1);justify-content:center;align-items:center;width:100%;min-height:48px;display:flex}.esri-widget__footer-pagination{color:var(--calcite-color-text-2);justify-content:space-between;align-items:center;display:flex}.esri-widget__footer-pagination-previous-button,.esri-widget__footer-pagination-next-button{cursor:pointer;background-color:var(--calcite-color-foreground-1);border:0;margin:0 7px;padding:12px 15px;transition:background-color .125s ease-in-out}.esri-widget__footer-pagination-previous-button:hover,.esri-widget__footer-pagination-previous-button:focus,.esri-widget__footer-pagination-next-button:hover,.esri-widget__footer-pagination-next-button:focus{color:var(--calcite-color-text-1);background-color:var(--calcite-color-foreground-1)}.esri-menu{visibility:hidden;z-index:1;background-clip:padding;background-color:var(--calcite-color-foreground-1);background-clip:padding-box;width:100%;max-height:0;margin:2px 0 0;padding:0;font-size:var(--calcite-font-size);line-height:var(--calcite-spacing-xl);position:absolute;top:100%;left:0;overflow:hidden;box-shadow:0 1px 2px #0000004d}.esri-menu .esri-menu__header{color:var(--calcite-color-text-inverse);background-color:var(--calcite-color-inverse);padding:6px 12px}.esri-menu__list{margin:0;padding:0;list-style:none}.esri-menu__list-item{cursor:pointer;border-top:1px solid #adadad4d;border-left:3px solid #0000;padding:.8em 1em}.esri-menu__list-item [class^=esri-icon-],.esri-menu__list-item [class*=" esri-icon-"]{padding-right:2.8px}.esri-menu__list-item:first-child{border-top:none}.esri-menu__list-item--focus,.esri-menu__list-item:hover,.esri-menu__list-item:focus{background-color:var(--calcite-color-foreground-1)}.esri-menu__list-item:active{background-color:var(--calcite-color-foreground-current)}.esri-menu__list-item--active,.esri-menu__list-item--active:hover,.esri-menu__list-item--active:focus{background-color:var(--calcite-color-foreground-1);border-left-color:var(--calcite-color-brand)}.esri-widget__table{border-collapse:collapse;color:var(--calcite-color-text-1);border:none;width:100%;line-height:var(--calcite-font-line-height-relative-tight)}.esri-widget__table tr:nth-child(odd){background-color:var(--calcite-color-transparent)}.esri-widget__table tr:nth-child(2n){background-color:var(--calcite-color-transparent-press)}.esri-widget__table tr a{color:var(--calcite-color-text-2)}.esri-widget__table tr a:hover,.esri-widget__table tr a:focus{color:var(--calcite-color-text-1)}.esri-widget__table tr td,.esri-widget__table tr th{vertical-align:top;word-break:break-word;padding:.5em .7em;font-size:var(--calcite-font-size-sm);font-weight:var(--calcite-font-weight-regular)}.esri-widget__table tr th{text-align:left;border-right:3px solid #0000000d;width:50%}.esri-widget__table tr td{width:50%}.esri-input{color:var(--calcite-color-text-1);background-color:var(--calcite-color-foreground-1);border:1px solid #959595;font-size:var(--calcite-font-size)}.esri-input::-ms-clear{display:none}.esri-input::placeholder{opacity:1;color:var(--calcite-color-text-2)}.esri-input:placeholder-shown{text-overflow:ellipsis}.esri-input[type=text],.esri-input[type=password],.esri-input[type=number]{height:32px;padding:0 .5em}calcite-combobox.esri-input{border:none}.esri-widget__content--empty{text-align:center;color:var(--calcite-color-border-input);flex-flow:column wrap;align-items:center;padding:18px 22px;display:flex}.esri-widget__content--empty h1.esri-widget__heading,.esri-widget__content--empty h2.esri-widget__heading,.esri-widget__content--empty h3.esri-widget__heading,.esri-widget__content--empty h4.esri-widget__heading,.esri-widget__content--empty h5.esri-widget__heading{font-weight:var(--calcite-font-weight-regular)}.esri-widget__content-illustration--empty{width:128px;padding:1rem 0}.esri-widget__content-icon--empty{width:32px;padding:.5rem 0}.esri-select{appearance:none;cursor:pointer;color:var(--calcite-color-text-2);background:var(--calcite-color-foreground-1) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='-8 -8 32 32' width='32' height='32'%3E%3Cpath d='M8 11.207l-4-4V5.793l4 4 4-4v1.414z' fill='%23adadad' fillrule='nonzero'/%3E%3C/svg%3E") 100% no-repeat;border:1px solid #959595;border-radius:0;width:100%;height:32px;margin:0;padding:0 .5em;font-family:inherit;font-size:.85em;display:block}.esri-select[disabled]{cursor:auto}.esri-select::-ms-expand{display:none}.esri-disabled a,.esri-disabled [role=menu],.esri-disabled [role=checkbox],.esri-disabled [class^=esri-icon-],.esri-disabled [class*=" esri-icon-"]{color:var(--calcite-color-text-3)}.keynav-mode .esri-widget:focus,.keynav-mode .esri-widget :focus{z-index:1;outline-offset:2px;outline:2px solid #adadad}.esri-widget__loader-animation{border:.15em solid #adadad4d;border-top-color:var(--calcite-color-border-input);border-radius:100%;width:1em;height:1em;font-size:var(--calcite-font-size-md);animation:1.25s linear infinite esri-rotate;display:block;transform:translateZ(0)}:dir(rtl) .esri-widget__table th{text-align:right;border-left:3px solid #0000000d;border-right:none}:dir(rtl) .esri-select{background-position:0}:dir(rtl) .esri-menu__list-item{border-left:none;border-right:3px solid #0000}:dir(rtl) .esri-menu__list-item [class^=esri-icon-],:dir(rtl) .esri-menu__list-item [class*=" esri-icon-"]{padding-left:2px;padding-right:0}:dir(rtl) .esri-menu__list-item--active{border-right-color:var(--calcite-color-brand)}.esri-icon-font-fallback-text{clip:rect(0 0 0 0);width:1px;height:1px;position:absolute;overflow:hidden}.esri-rotating{animation:1.25s linear infinite esri-rotate;transform:translateZ(0)}.esri-clearfix:before,.esri-clearfix:after{content:" ";display:table}.esri-clearfix:after{clear:both}.esri-interactive{cursor:pointer}.esri-hidden{display:none!important}.esri-invisible{visibility:hidden!important}.esri-offscreen{position:absolute;top:-999em;left:-999em}.esri-match-height{flex-direction:column;flex:auto;display:flex;overflow:hidden}:host{display:flex}.arcgis-bookmarks{width:100%;overflow:hidden auto;transition:max-height .25s ease-in-out}:host([closed]) .arcgis-bookmarks{display:none}.arcgis-bookmarks__empty{display:flex;flex-flow:column wrap;align-items:center;padding:var(--calcite-spacing-md) var(--calcite-spacing-lg);text-align:center;color:var(--calcite-color-text-1)}.arcgis-bookmarks .arcgis-widget__content--empty{background-color:var(--calcite-color-foreground-2)}.arcgis-bookmarks calcite-flow-item[loading]{min-height:150px}.arcgis-bookmarks__loader{margin-inline-end:0}.arcgis-bookmarks__filter-no-results{padding:var(--calcite-spacing-md) var(--calcite-spacing-lg)}.arcgis-bookmarks__bookmark-image-container{display:flex;position:relative;margin:0;margin-inline-start:var(--calcite-spacing-xs);min-width:16px;min-height:16px}.arcgis-bookmarks__bookmark-image-container .arcgis-bookmarks__image{max-width:64px;overflow:hidden}.arcgis-bookmarks--drag-enabled .arcgis-bookmarks__bookmark-image-container{margin-inline-start:0}.arcgis-bookmarks__no-bookmarks-heading{margin:0;margin-block-start:var(--calcite-spacing-md);font-size:var(--calcite-font-size-md);line-height:var(--calcite-font-line-height-relative-tight);font-weight:var(--calcite-font-weight-regular)}.arcgis-bookmarks__authoring{display:flex;flex-direction:column}.arcgis-bookmarks__authoring-image-container{display:flex;align-items:middle;justify-content:center;margin-block-end:var(--calcite-spacing-md);margin-inline-end:var(--calcite-spacing-lg);background-image:repeating-conic-gradient(#ccc 0% 25%,#fff 0% 50%);background-position:0 0,10px 10px;background-size:20px 20px;background-color:#fff;width:128px;height:128px;text-align:center}.arcgis-bookmarks__authoring-image-container .arcgis-bookmarks__image{max-width:128px;max-height:128px}.arcgis-bookmarks__form{display:flex;height:100%}.arcgis-bookmarks__form-content{padding-block:var(--calcite-spacing-md);padding-inline:var(--calcite-spacing-lg)}.arcgis-bookmarks__authoring-refresh-thumbnail-button{margin-block-end:var(--calcite-spacing-md)}.arcgis-bookmarks__bookmark-content-label{color:var(--calcite-color-text-1);font-size:var(--calcite-font-size-sm);line-height:var(--calcite-font-line-height-relative-normal)}.arcgis-bookmarks__bookmark-content calcite-table{margin-inline-start:-.25rem}.arcgis-bookmarks__bookmark-content calcite-table,.arcgis-bookmarks__bookmark-content calcite-table-row{--calcite-color-border-3: transparent;--calcite-color-text-1: var(--calcite-color-text-3);--calcite-table-row-background-color: transparent;pointer-events:none}`, d = "arcgis-bookmarks", T = `${d}__authoring`, S = `${d}__bookmark`, l = {
  base: d,
  empty: `${d}__empty`,
  noBookmarksHeader: `${d}__no-bookmarks-heading`,
  noBookmarksDescription: `${d}__no-bookmarks-description`,
  form: `${d}__form`,
  list: `${d}__list`,
  loader: `${d}__loader`,
  filterNoResults: `${d}__filter-no-results`,
  formContent: `${d}__form-content`,
  addBookmarkButton: `${d}__add-bookmark-button`,
  editBookmarkInput: `${d}__edit-bookmark-input`,
  addBookmarkInput: `${d}__add-bookmark-input`,
  dragEnabled: `${d}--drag-enabled`,
  bookmarkImage: `${d}__image`,
  bookmarkImageContainer: `${S}-image-container`,
  bookmarkContent: `${S}-content`,
  bookmarkContentLabel: `${S}-content-label`,
  authoring: T,
  authoringImageContainer: `${T}-image-container`,
  authoringRefreshThumbnailButton: `${T}-refresh-thumbnail-button`
};
var j = Object.defineProperty, G = Object.getOwnPropertyDescriptor, g = (n, e, t, i) => {
  for (var r = i > 1 ? void 0 : i ? G(e, t) : e, o = n.length - 1, s; o >= 0; o--)
    (s = n[o]) && (r = (i ? s(e, t, r) : s(r)) || r);
  return i && r && j(e, t, r), r;
};
let m = class extends R {
  constructor(n) {
    super(n);
  }
  get editedBookmark() {
    const { bookmark: n } = this;
    return n ? this._get("editedBookmark") || n.clone() : null;
  }
  get customUrl() {
    if (this._customUrl)
      return this._customUrl;
    const n = this.editedBookmark?.thumbnail?.url ?? "";
    return n ?? (b(n) ? n : null);
  }
  set customUrl(n) {
    this._customUrl = n;
  }
  get screenshotUrl() {
    if (this._screenshotUrl)
      return this._screenshotUrl;
    const n = this.editedBookmark?.thumbnail?.url ?? "";
    return n ?? (y(n) ? n : null);
  }
  set screenshotUrl(n) {
    this._screenshotUrl = n;
  }
  get state() {
    return this._get("state");
  }
  set state(n) {
    this.validationState = void 0, this.creatingBookmark = void 0, this._set("state", n);
  }
  get thumbnailState() {
    if (this._thumbnailState)
      return this._thumbnailState;
    const n = this.editedBookmark?.thumbnail?.url;
    return n ? b(n) ? "url" : "screenshot" : "none";
  }
  set thumbnailState(n) {
    this._thumbnailState = n;
  }
};
g([
  _()
], m.prototype, "bookmark", 2);
g([
  _({ readOnly: !0 })
], m.prototype, "editedBookmark", 1);
g([
  _()
], m.prototype, "_customUrl", 2);
g([
  _()
], m.prototype, "customUrl", 1);
g([
  _()
], m.prototype, "_screenshotUrl", 2);
g([
  _()
], m.prototype, "screenshotUrl", 1);
g([
  _()
], m.prototype, "state", 1);
g([
  _()
], m.prototype, "_thumbnailState", 2);
g([
  _()
], m.prototype, "thumbnailState", 1);
g([
  _()
], m.prototype, "validationState", 2);
g([
  _()
], m.prototype, "creatingBookmark", 2);
m = g([
  H("UserState")
], m);
const J = V(M);
class K extends z {
  constructor() {
    super(...arguments), this._guid = O(), this._addInputNode = null, this._editInputNode = null, this._urlEditInputNode = null, this._lastDragDetail = null, this.messages = P({}), this.viewModel = J(this), this._storeEditFlowItemNode = (e) => {
      this._editFlowItemEl = e;
    }, this._storeRootFlowItem = (e) => {
      this._rootFlowItemEl = e;
    }, this._storeAddFlowItemNode = (e) => {
      this._addFlowItemEl = e;
    }, this._userState = null, this._userCreatingBookmark = !1, this.editIncludeTimeExtent = !1, this.view = this.viewModel.view, this.icon = "bookmark", this.closed = !1, this.defaultCreateOptions = this.viewModel.defaultCreateOptions, this.defaultEditOptions = this.viewModel.defaultEditOptions, this.bookmarks = this.viewModel.bookmarks, this.disabled = !1, this.dragEnabled = !1, this.filterPlaceholder = "", this.filterText = "", this.headingLevel = 2, this.goToOverride = this.viewModel.goToOverride, this.showAddBookmarkButton = !1, this.showCloseButton = !1, this.showCollapseButton = !1, this.showEditBookmarkButton = !1, this.showFilter = !1, this.hideFlow = !1, this.showHeading = !1, this.hideThumbnail = !1, this.hideTime = !1, this.timeDisabled = this.viewModel.capabilities.time, this.autoDestroyDisabled = !1, this.state = this.viewModel.state, this.arcgisBookmarkEdit = B(), this.arcgisBookmarkSelect = B(), this.arcgisPropertyChange = N()("state"), this.arcgisReady = B(), this.arcgisClose = B();
  }
  static {
    this.properties = { _userState: 16, _userStateValue: 16, _userValidationState: 16, _userThumbnailState: 16, _userCreatingBookmark: 16, editIncludeTimeExtent: 16, view: 0, referenceElement: 1, position: 3, icon: 1, closed: 7, defaultCreateOptions: 0, defaultEditOptions: 0, bookmarks: 0, disabled: 5, dragEnabled: 5, filterPlaceholder: 1, filterText: 1, headingLevel: 9, goToOverride: 0, showAddBookmarkButton: 5, showCloseButton: 5, showCollapseButton: 5, showEditBookmarkButton: 5, showFilter: 5, hideFlow: 5, showHeading: 5, hideThumbnail: 5, hideTime: 5, timeDisabled: 5, autoDestroyDisabled: 5, messageOverrides: 0, label: 1, state: 3 };
  }
  static {
    this.styles = Z;
  }
  async destroy() {
    await this.manager.destroy();
  }
  goTo(e) {
    return this.viewModel.goTo(e);
  }
  loaded() {
    this.manager.onLifecycle(() => [
      this.viewModel.on("bookmark-select", this.arcgisBookmarkSelect.emit),
      this.viewModel.on("bookmark-edit", this.arcgisBookmarkEdit.emit),
      x(() => this._userState?.state, (e) => this._userStateValue = e, { initial: !0 }),
      x(() => this._userState?.validationState, (e) => this._userValidationState = e, { initial: !0 }),
      x(() => this._userState?.thumbnailState, (e) => this._userThumbnailState = e, { initial: !0 }),
      x(() => this._userState?.creatingBookmark, (e) => this._userCreatingBookmark = !!e, { initial: !0 })
    ]);
  }
  _handleClose() {
    this.closed = !0, this.arcgisClose.emit();
  }
  startAddBookmark() {
    this._userState = new m({
      state: "add"
    }), requestAnimationFrame(() => {
      this._addFlowItemEl?.setFocus();
    });
  }
  _clearState() {
    this._userState = null;
  }
  _getTimeExtentStrings(e) {
    const { hideTime: t } = this, { timeExtent: i } = e;
    if (!i)
      return {};
    const { start: r, end: o } = i, s = o != null && (r == null || r.getTime() !== o.getTime()), u = r ? this._formatDate(r) : "", h = r && !t ? this._formatTime(r) : "";
    if (!s)
      return { startDate: u, startTime: h };
    const f = this._formatDate(o), k = t ? "" : this._formatTime(o);
    return { startDate: u, startTime: h, endDate: f, endTime: k };
  }
  _handleUrlEditInputChange() {
    const { _userState: e, _urlEditInputNode: t } = this, i = t?.value;
    if (!e?.editedBookmark || !i)
      return;
    e.validationState = void 0, y(e.editedBookmark.thumbnail?.url ?? "") && (e.screenshotUrl = e.editedBookmark.thumbnail?.url);
    const r = { url: i };
    b(r.url) && (e.customUrl = i, e.editedBookmark.thumbnail = r);
  }
  _getBookmarkTitle(e) {
    return (e?.name || this.messages.untitled) ?? "";
  }
  _formatDate(e) {
    if (!e)
      return "";
    const t = this.viewModel.view, i = t && "timeZone" in t ? t.timeZone : "system";
    return C(e, {
      ...D("short-date"),
      timeZone: i
    });
  }
  _formatTime(e) {
    if (!e)
      return "";
    const t = this.viewModel.view, i = t && "timeZone" in t ? t.timeZone : "system";
    return C(e, {
      ...D("long-time"),
      timeZone: i
    });
  }
  _onCalciteListOrderChange(e) {
    const { _lastDragDetail: t, bookmarks: i } = this, { toEl: r, fromEl: o, dragEl: s, newIndex: u } = e;
    if (!i.length)
      return;
    const h = t?.newIndex === u && t?.dragEl === s && t?.toEl === r && t?.fromEl === o;
    if (!o || !r || h)
      return;
    this._lastDragDetail = e;
    const f = Array.from(o.children).filter((k) => k?.matches("calcite-list-item")).map((k) => k.value);
    i.sort((k, I) => {
      const $ = f.indexOf(k.uid), w = f.indexOf(I.uid);
      return $ > w ? 1 : $ < w ? -1 : 0;
    });
  }
  _endAddBookmark() {
    this._clearState(), this._focusRootFlowItem();
  }
  _showEditBookmarkForm(e) {
    e && (this.editIncludeTimeExtent = !!e.timeExtent, this._userState = new m({
      bookmark: e,
      state: "edit"
    }), requestAnimationFrame(() => {
      this._editFlowItemEl?.setFocus();
    }), this.viewModel.goTo(e));
  }
  async _createNewScreenshotUrl() {
    return (await this.viewModel.createBookmark()).thumbnail?.url ?? null;
  }
  _storeCurrentUrl() {
    const { _userState: e } = this, t = e?.editedBookmark?.thumbnail?.url;
    t && (b(t) ? e.customUrl = t : y(t) && (e.screenshotUrl = t));
  }
  async _handleThumbnailTypeSelect(e) {
    const { _userState: t } = this;
    if (!t)
      return;
    const { screenshotUrl: i, customUrl: r, editedBookmark: o } = t, s = e === "screenshot" ? i ?? await this._createNewScreenshotUrl() : e === "url" && r ? r : null;
    this._storeCurrentUrl(), o && s && (o.thumbnail = {
      url: s
    }), t.validationState = void 0, t.thumbnailState = e;
  }
  _focusRootFlowItem() {
    requestAnimationFrame(() => {
      this._rootFlowItemEl?.setFocus();
    });
  }
  _closeEditBookmarkForm() {
    this._clearState(), this._focusRootFlowItem();
  }
  _addBookmarkSubmitClick(e) {
    e.preventDefault(), this._addBookmarkSubmit();
  }
  async _addBookmarkSubmit() {
    const { _addInputNode: e, _userState: t, viewModel: i, viewModel: { bookmarks: r } } = this;
    if (!t)
      return;
    const o = e ? e.value.trim() : null;
    if (!o) {
      t.validationState = "name-required";
      return;
    }
    t.creatingBookmark = !0;
    const s = await i.createBookmark();
    s.name = o, r.add(s), this._endAddBookmark();
  }
  async _editBookmarkAndClose(e, t) {
    const { viewModel: i, viewModel: { defaultEditOptions: r } } = this;
    await i.editBookmark(e, {
      ...r,
      ...t
    }), this._closeEditBookmarkForm();
  }
  _editBookmarkSubmit(e) {
    e.preventDefault();
    const { _userState: t, _editInputNode: i, editIncludeTimeExtent: r, _urlEditInputNode: o } = this;
    if (!t?.bookmark || !t.editedBookmark)
      return;
    t.validationState = void 0, t.customUrl = void 0, t.screenshotUrl = void 0;
    const s = i?.value.trim();
    if (!s) {
      t.validationState = "name-required";
      return;
    }
    if (t.bookmark.name = s, t.bookmark.thumbnail = t.editedBookmark.thumbnail, r || (t.bookmark.timeExtent = null), t.thumbnailState === "url" && o) {
      const h = { url: o.value };
      if (!b(h.url)) {
        t.validationState = "absolute-url-required";
        return;
      }
      t.bookmark.thumbnail = h;
    } else t.thumbnailState === "none" && (t.bookmark.thumbnail = null);
    this._editBookmarkAndClose(t.bookmark, {
      takeScreenshot: !1,
      captureTimeExtent: r
    });
  }
  _storeEditInput(e) {
    this._editInputNode = e;
  }
  _storeAddInput(e) {
    this._addInputNode = e;
  }
  _storeUrlEditInput(e) {
    this._urlEditInputNode = e;
  }
  _deleteBookmark(e) {
    this._closeEditBookmarkForm(), e && (this.viewModel.bookmarks.remove(e), e.destroy());
  }
  _goToBookmark(e) {
    this._clearState(), this.viewModel.goTo(e);
  }
  async _updateThumbnail() {
    const { _userState: e, viewModel: t } = this;
    e && (e.validationState = void 0, await t.editBookmark(e.editedBookmark, {
      takeScreenshot: !0,
      captureViewpoint: !1,
      captureRotation: !1,
      captureScale: !1,
      captureTimeExtent: !1
    }));
  }
  _handleCalciteListDragEnd(e) {
    const { fromEl: t, dragEl: i, oldIndex: r } = e;
    t.insertBefore(i, t.children[r]);
  }
  render() {
    return a`<div class=${c(l.base)}>${this._renderBookmarksContainer()}</div>`;
  }
  _renderNoBookmarksContainer(e) {
    const { messages: t, viewModel: { state: i } } = this;
    return !e.length && i !== "loading" ? a`<div class=${c(l.empty)}><calcite-icon .icon=${this.icon} scale=l></calcite-icon>${q({ class: l.noBookmarksHeader, level: this.headingLevel, children: t.noBookmarksHeading })}<p class=${c(l.noBookmarksDescription)}>${t.noBookmarksDescription}</p></div>` : null;
  }
  _renderEditBookmarkFlowItems() {
    const e = this._userStateValue === "edit", t = this._userState?.editedBookmark;
    return !t || !e ? [] : this._renderEditingBookmark(t);
  }
  _renderBookmarkItems(e) {
    return e ? e.toArray().map((t) => this._renderBookmark(t)) : [];
  }
  _renderBookmarksContainer() {
    const { viewModel: { state: e, bookmarks: t }, dragEnabled: i, messages: r, disabled: o, filterPlaceholder: s, filterText: u, closed: h, headingLevel: f } = this, k = t.filter((p) => p != null), $ = k.length ? a`<calcite-list class=${c(l.list)} display-mode=flat .dragEnabled=${i} .filterEnabled=${this.showFilter} .filterPlaceholder=${s} .filterProps=${["label", "description", "metadata"]} .filterText=${u} .group=${`bookmarks-${this._guid}`} .label=${r.componentLabel ?? ""} selection-appearance=border selection-mode=none @calciteListDragEnd=${(p) => this._handleCalciteListDragEnd(p.detail)} @calciteListFilter=${(p) => this.filterText = p.currentTarget?.filterText ?? ""} @calciteListOrderChange=${(p) => this._onCalciteListOrderChange(p.detail)}>${this._renderBookmarkItems(k)}${this.showFilter ? a`<div class=${c(l.filterNoResults)} slot=filter-no-results><calcite-notice kind=info open width=full><div slot=message>${r.noBookmarksHeading}</div>;</calcite-notice></div>` : null}</calcite-list>` : null, w = [
      a`<calcite-flow-item .closable=${this.showCloseButton} .closed=${h} .collapsible=${this.showCollapseButton} .disabled=${o} .heading=${this.showHeading ? r.componentLabel : void 0} .headingLevel=${f} .loading=${e === "loading"} .selected=${!this._userStateValue} @calciteFlowItemClose=${this._handleClose} ${v(this._storeRootFlowItem)}>${this._renderNoBookmarksContainer(k)}${$}${this._renderAddBookmarkButton()}</calcite-flow-item>`,
      this._renderAddingBookmark(),
      this._renderEditBookmarkFlowItems()
    ];
    return h ? null : this.hideFlow ? w : a`<calcite-flow>${w}</calcite-flow>`;
  }
  _renderAddBookmarkButton() {
    const { messages: e, disabled: t, viewModel: { view: i, state: r } } = this, o = this._userCreatingBookmark;
    return i && r !== "loading" && this.showAddBookmarkButton ? a`<calcite-fab appearance=outline-fill class=${c(l.addBookmarkButton)} .disabled=${t || o} icon=plus kind=neutral .loading=${o} @click=${this.startAddBookmark} slot=fab .text=${e.addBookmark} text-enabled title=${e.addBookmark ?? E}></calcite-fab>` : null;
  }
  _renderEditContainer(e) {
    const { messages: t } = this, i = `${t.edit} ${this._getBookmarkTitle(e)}`;
    return this.showEditBookmarkButton ? a`<calcite-action appearance=transparent icon=pencil @click=${() => this._showEditBookmarkForm(e)} slot=actions-end .text=${i} title=${i ?? E}></calcite-action>` : null;
  }
  _renderBookmarkImage(e, t) {
    return t ? a`<img alt class=${c(l.bookmarkImage)} src=${e.thumbnail?.url ?? E}>` : null;
  }
  _renderBookmarkTimeSwitch(e) {
    const { messages: t, viewModel: { view: i } } = this, { timeExtent: r } = e;
    return i?.timeExtent ?? r ? a`<calcite-label layout=inline-space-between>${t.includeTimeExtent}<calcite-switch .checked=${!!r} @calciteSwitchChange=${(o) => {
      this.editIncludeTimeExtent = !!o.currentTarget.checked;
    }}></calcite-switch></calcite-label>` : null;
  }
  _renderEditBookmarkTimeExtent(e) {
    return this.editIncludeTimeExtent ? this._renderBookmarkTimeExtent(e) : null;
  }
  _renderTimeExtentDescription(e) {
    const { startDate: t, startTime: i, endDate: r, endTime: o } = this._getTimeExtentStrings(e);
    if (!t)
      return "";
    const s = `${t} ${i}`, u = `${r} ${o}`;
    return r ? `${s} - ${u}` : s;
  }
  _renderBookmarkTimeExtent(e, t = !1) {
    const { messages: i } = this, { startDate: r, startTime: o, endDate: s, endTime: u } = this._getTimeExtentStrings(e), h = t ? null : a`<calcite-table-row slot=table-header><calcite-table-header .heading=${i.startDate}></calcite-table-header>${s ? a`<calcite-table-header .heading=${i.endDate}></calcite-table-header>` : null}</calcite-table-row>`;
    return r ? a`<calcite-table .caption=${i.timeExtent ?? ""} scale=s>${h}<calcite-table-row><calcite-table-cell>${r} ${o ? [a`<br>`, o] : null}</calcite-table-cell>${s ? a`<calcite-table-cell>${s}${u ? [a`<br>`, u] : null}</calcite-table-cell>` : null}</calcite-table-row></calcite-table>` : null;
  }
  _renderBookmarkActiveScrim(e, t) {
    return this.viewModel.activeBookmark === e && t ? a`<calcite-scrim loading></calcite-scrim>` : null;
  }
  _renderBookmarkActiveLoader(e, t) {
    return this.viewModel.activeBookmark === e && !t ? a`<calcite-loader class=${c(l.loader)} inline .label=${this.messages.loading ?? ""}></calcite-loader>` : null;
  }
  _renderBookmarkImageIcon(e, t) {
    return this.viewModel.activeBookmark !== e && !t ? a`<calcite-icon icon=bookmark scale=s></calcite-icon>` : null;
  }
  _renderBookmarkThumbnail(e) {
    const t = !this.hideThumbnail && !!e.thumbnail?.url;
    return a`<div class=${c(l.bookmarkImageContainer)} slot=content-start>${this._renderBookmarkActiveScrim(e, t)}${this._renderBookmarkImage(e, t)}${this._renderBookmarkActiveLoader(e, t)}${this._renderBookmarkImageIcon(e, t)}</div>`;
  }
  _renderBookmark(e) {
    return A(e.uid, a`<calcite-list-item class=${c(L({ [l.dragEnabled]: this.dragEnabled }))} .description=${this._renderTimeExtentDescription(e)} .label=${this._getBookmarkTitle(e)} .value=${e.uid} @calciteListItemSelect=${() => this._goToBookmark(e)}>${this._renderBookmarkThumbnail(e)}${this._renderBookmarkContent(e)}${this._renderEditContainer(e)}</calcite-list-item>`);
  }
  _renderBookmarkContent(e) {
    return a`<div class=${c(l.bookmarkContent)} slot=content><span class=${c(l.bookmarkContentLabel)}>${this._getBookmarkTitle(e)}</span>${this._renderBookmarkTimeExtent(e, !0)}</div>`;
  }
  _renderEditingBookmarkName(e) {
    const { messages: t } = this, i = this._userValidationState === "name-required";
    return a`<calcite-label>${t.title}<calcite-input class=${c(l.editBookmarkInput)} name=bookmark-name .placeholder=${t.titlePlaceholder} required type=text .value=${e.name} ${v(this._storeEditInput)}></calcite-input>${i ? a`<calcite-input-message icon=exclamation-mark-triangle status=invalid>${t.invalidTitle}</calcite-input-message>` : null}</calcite-label>`;
  }
  _renderEditingBookmarkActions() {
    const { messages: e, _userState: t } = this, i = t?.bookmark;
    return [
      a`<calcite-button appearance=transparent kind=danger @click=${() => this._deleteBookmark(i)} slot=footer type=button width=full>${e.delete}</calcite-button>`,
      a`<calcite-button appearance=outline @click=${this._closeEditBookmarkForm} slot=footer type=button width=full>${e.cancel}</calcite-button>`,
      a`<calcite-button slot=footer type=submit width=full>${e.save}</calcite-button>`
    ];
  }
  _renderEditingTimeExtent(e) {
    const { capabilities: t, view: i } = this.viewModel, { timeExtent: r } = e;
    return t.time && (i?.timeExtent ?? r) ? a`<div>${this._renderBookmarkTimeSwitch(e)}${this._renderEditBookmarkTimeExtent(e)}</div>` : null;
  }
  _renderEditingBookmarkImage(e) {
    const { _userThumbnailState: t } = this, i = e.thumbnail?.url ?? "", r = b(i) ? t === "url" : y(i) ? t === "screenshot" : null;
    if (r)
      return this._renderBookmarkImage(e, r);
  }
  _renderEditingThumbnail(e) {
    const { _userThumbnailState: t, hideThumbnail: i } = this;
    return !i && t !== "none" ? a`<div class=${c(l.authoringImageContainer)}>${this._renderEditingBookmarkImage(e)}</div>` : null;
  }
  _renderUpdateThumbnailButton() {
    const { hideThumbnail: e, messages: t, _userThumbnailState: i } = this;
    return !e && i === "screenshot" ? a`<calcite-button appearance=outline class=${c(l.authoringRefreshThumbnailButton)} icon-start=refresh kind=neutral @click=${() => void this._updateThumbnail()} width=full>${t.updateThumbnail}</calcite-button>` : null;
  }
  _renderEditingBookmarkUrlInput(e) {
    const { messages: t, _userValidationState: i, _userThumbnailState: r } = this, o = e.thumbnail?.url ?? "", s = b(o) ? o : void 0, u = o && i === "absolute-url-required";
    return r === "url" ? a`<calcite-label><calcite-input name=bookmark-thumbnail-url pattern=https://.* .placeholder=${t ? `https://<${t.imageUrlPlaceholder}>` : void 0} required title=${t.imageUrlTooltip ?? E} type=text .value=${s} @calciteInputChange=${this._handleUrlEditInputChange} @calciteInputInput=${this._handleUrlEditInputChange} ${v(this._storeUrlEditInput)}></calcite-input>${u ? a`<calcite-input-message icon=exclamation-mark-triangle status=invalid>${t.invalidImageUrl}</calcite-input-message>` : null}</calcite-label>` : null;
  }
  _renderThumbnailSelector() {
    const { hideThumbnail: e, messages: t, _userThumbnailState: i } = this;
    return e ? null : a`<calcite-label>${t.thumbnail}<calcite-chip-group .label=${t.thumbnail ?? ""} selection-mode=single-persist @calciteChipGroupSelect=${(r) => this._handleThumbnailTypeSelect(r.currentTarget.selectedItems[0].value)}><calcite-chip .label=${t.screenshot ?? ""} .selected=${i === "screenshot"} value=screenshot>${t.screenshot}</calcite-chip><calcite-chip .label=${t.url ?? ""} .selected=${i === "url"} value=url>${t.url}</calcite-chip><calcite-chip .label=${t.none ?? ""} .selected=${i === "none"} value=none>${t.none}</calcite-chip></calcite-chip-group></calcite-label>`;
  }
  _renderEditingBookmark(e) {
    const { disabled: t, messages: i, headingLevel: r } = this;
    return e ? a`<form class=${c(l.form)} @submit=${this._editBookmarkSubmit}><calcite-flow-item .disabled=${t} .heading=${i.edit ?? ""} .headingLevel=${r} .selected=${this._userStateValue === "edit"} @calciteFlowItemBack=${(o) => {
      o.preventDefault(), this._closeEditBookmarkForm();
    }} ${v(this._storeEditFlowItemNode)}><div class=${c(l.formContent)}><div class=${c(l.authoring)}>${this._renderEditingBookmarkName(e)}${this._renderThumbnailSelector()}${this._renderEditingThumbnail(e)}${this._renderEditingBookmarkUrlInput(e)}${this._renderUpdateThumbnailButton()}${this._renderEditingTimeExtent(e)}</div></div>${this._renderEditingBookmarkActions()}</calcite-flow-item></form>` : null;
  }
  _renderAddingBookmarkName() {
    const { messages: e } = this, t = this._userValidationState === "name-required";
    return a`<calcite-label>${e.title}<calcite-input class=${c(l.addBookmarkInput)} name=bookmark-name .placeholder=${e.titlePlaceholder} required type=text value ${v(this._storeAddInput)}></calcite-input>${t ? a`<calcite-input-message icon=exclamation-mark-triangle status=invalid>${e.invalidTitle}</calcite-input-message>` : null}</calcite-label>`;
  }
  _renderAddingBookmarkActions() {
    const { messages: e } = this;
    return [
      a`<calcite-button appearance=outline @click=${this._endAddBookmark} slot=footer type=button width=full>${e.cancel}</calcite-button>`,
      a`<calcite-button slot=footer type=submit width=full>${e.add}</calcite-button>`
    ];
  }
  _renderAddingBookmark() {
    const { disabled: e, messages: t, headingLevel: i, _userStateValue: r } = this;
    return r === "add" ? a`<form class=${c(l.form)} @submit=${this._addBookmarkSubmitClick}><calcite-flow-item .disabled=${e} .heading=${t.addBookmark} .headingLevel=${i} selected @calciteFlowItemBack=${(o) => {
      o.preventDefault(), this._endAddBookmark();
    }} ${v(this._storeAddFlowItemNode)}><div class=${c(l.formContent)}>${this._renderAddingBookmarkName()}</div>${this._renderAddingBookmarkActions()}</calcite-flow-item></form>` : null;
  }
}
F("arcgis-bookmarks", K);
export {
  K as ArcgisBookmarks
};
