PageSourceSearch

https://www.fotowalser.com/theme/a5af882ef61d94f44d7f90cacbc83791/…nage-line-items-history.plugin.ts.47d3e8.js

js fotowalser.com collected 2026-10-09 22:42:50 UTC 76,862 bytes, 251 lines download raw bytes

1"use strict";(self.webpackChunkquote_management=self.webpackChunkquote_management||[]).push([[46722],{722(t,e,i){i.r(e),i.d(e,{default:()=>o});var s=i(220),r=i(194);class o extends s.A{static #t=this.options={events:{historyReadCollectRequested:"b2b-quote-history-read-collect-requested",historyReadSucceeded:"b2b-quote-history-read-succeeded",historyEntryRemoveConfirmed:"b2b-quote-manage-line-items-history-entry-remove-confirmed",lineItemsReloaded:"b2b-quote-manage-line-items-reloaded",updateTotalLineItems:"b2b-quote-manage-line-items-update-total-line-items",lineItemsReloadRequested:"b2b-quote-manage-line-items-reload-requested",openHistory:"b2b-quote-manage-line-items-history-open",historyReload:"b2b-quote-manage-line-items-history-reload"},selectors:{actionDetail:".quote-manage-line-items-modal__action-detail",apiHistoryDetail:"[data-b2b-quote-manage-line-items-api-history-detail]",backButton:"[data-b2b-quote-manage-line-items-back]",deletedHistoryErrorState:"[data-b2b-quote-manage-line-items-deleted-history-error]",deletedHistoryItems:"[data-b2b-quote-manage-line-items-deleted-history-items]",deletedHistoryLoadTrigger:"[data-b2b-quote-manage-line-items-deleted-history-load-trigger]",deletedHistorySection:"[data-b2b-quote-manage-line-items-deleted-history]",deletedHistoryLoadingState:"[data-b2b-quote-manage-line-items-deleted-history-loading]",historyCancelButton:"[data-b2b-quote-manage-line-items-history-cancel]",historyCommentInput:"[data-b2b-quote-manage-line-items-history-comment]",historyEntry:"[data-b2b-quote-manage-line-items-history-entry]",historyEntryDeleteButton:".quote-manage-line-items-modal__history-entry-action.is-delete",historyEntryEdit:"[data-b2b-quote-manage-line-items-history-entry-edit]",historyEntryEditButton:".quote-manage-line-items-modal__history-entry-action.is-edit",historyEntryEditCancelButton:"[data-b2b-quote-manage-line-items-history-entry-edit-cancel]",historyEntryEditInput:"[data-b2b-quote-manage-line-items-history-entry-edit-input]",historyEntryEditSendButton:"[data-b2b-quote-manage-line-items-history-entry-edit-send]",historyEntryReply:"[data-b2b-quote-manage-line-items-history-entry-reply]",historyEntryReplyButton:".quote-manage-line-items-modal__history-entry-action.is-reply",historyEntryReplyCancelButton:"[data-b2b-quote-manage-line-items-history-entry-reply-cancel]",historyEntryReplyInput:"[data-b2b-quote-manage-line-items-history-entry-reply-input]",historyEntryReplySendButton:"[data-b2b-quote-manage-line-items-history-entry-reply-send]",historyEmptyState:"[data-b2b-quote-manage-line-items-history-empty]",historyErrorState:"[data-b2b-quote-manage-line-items-history-error]",historyList:"[data-b2b-quote-manage-line-items-history-list]",historyListItems:"[data-b2b-quote-manage-line-items-history-list-items]",historyLoadingState:"[data-b2b-quote-manage-line-items-history-loading]",historyLoadTrigger:"[data-b2b-quote-manage-line-items-history-load-trigger]",historyOverview:"[data-b2b-quote-manage-line-items-history-overview]",historyScrollLoadingState:"[data-b2b-quote-manage-line-items-history-scroll-loading]",historyPanel:"[data-b2b-quote-manage-line-items-history-panel]",historySendButton:"[data-b2b-quote-manage-line-items-history-send]",closeTriggers:'.quote-manage-line-items-modal__cancel, .quote-manage-line-items-modal__save, .btn-close[data-bs-dismiss="modal"]',modalRoot:".quote-manage-line-items-modal__root",root:".quote-manage-line-items-modal__content",row:"[data-b2b-quote-manage-line-items-row]",searchContainer:".quote-manage-line-items-modal__topbar",sidebar:".quote-manage-line-items-modal__sidebar",sidebarChevron:".quote-manage-line-items-modal__sidebar-chevron",sidebarItem:"[data-b2b-quote-manage-line-items-sidebar-item]",sortSelect:'.quote-manage-line-items-modal__sort select[name="order"]',totalLineItemsCount:".quote-manage-line-items-modal__sidebar-count"},deletedLineItemsUrl:"",draftVersionId:"",editMessageUrlTemplate:"",focusHistoryComment:!1,shortcutCurrentCustomer:"",historyLimit:10,historyOrder:"created-at-desc",historyScrollThreshold:160,historySnippets:{},historyUrl:"",isEditable:!0,currentCustomerId:"",removeMessageUrlTemplate:"",replyMessageUrl:"",selectedLineItemId:"",sendMessageUrl:""};
1init(){this._historyById=new Map,this._apiDetailOpenKey=null,this._apiDetailOpenPromise=null,this._detailHistoryById=new Map,this._detailHistoryCurrentPage=0,this._detailHistoryIsFullyLoaded=!1,this._detailHistoryItems=[],this._detailHistoryLineItems=new Map,this._detailHistoryLoadPromise=null,this._detailHistoryTotal=0,this._deletedHistoryById=new Map,this._deletedHistoryCurrentPage=0,this._deletedHistoryHasError=!1,this._deletedHistoryIsFullyLoaded=!1,this._deletedHistoryIsLoading=!1,this._deletedHistoryItems=[],this._deletedHistoryLastScrollTop=0,this._deletedHistoryLoadPromise=null,this._deletedHistoryShouldReloadOnModalOpen=!1,this._deletedHistoryRenderedIds=new Set,this._historyCurrentPage=0,this._historyCurrencySymbol="",this._historyHasError=!1,this._historyIsFullyLoaded=!1,this._historyIsLoading=!1,this._historyItems=[],this._historyLoadPromise=null,this._historyLineItems=new Map,this._historyTotal=0,this._isSyncing=!1,this._boundHandleChange=this._handleChange.bind(this),this._boundHandleClick=this._handleClick.bind(this),this._boundHandleHistoryReadSucceeded=this._handleHistoryReadSucceeded.bind(this),this._boundHandleHistoryEntryRemoveConfirmed=this._handleHistoryEntryRemoveConfirmed.bind(this),this._boundHandleHistoryScroll=this._handleHistoryScroll.bind(this),this._boundHandleInput=this._handleInput.bind(this),this._boundHandleKeypress=this._handleKeypress.bind(this),this._boundHandleModalShown=this._handleModalShown.bind(this),this._historyScrollElement=null,this._historyScrollLoadFrame=null,this._lineItemsReloadedHandler=this._handleLineItemsReloaded.bind(this),this._updateTotalLineItemsHandler=this._handleUpdateTotalLineItems.bind(this),this._openHistoryHandler=this._handleOpenHistory.bind(this),this._loadHistoryHandler=this._loadHistory.bind(this),this._selectedRowId=(this.options.selectedLineItemId||"").trim()||null,this._selectedHistoryId=null,this._selectedDetailSource=null,this._shouldFocusHistoryComment=!0===this.options.focusHistoryComment,this._syncState(),this._registerModalEvents(),document.addEventListener(this.options.events.historyReadSucceeded,this._boundHandleHistoryReadSucceeded)}_hydrateState(){this._rootElement=this._resolveRootElement(),this._modalElement=this._resolveModalElement(),this._rows=this._readRows(),this._historyPanels=this._readHistoryPanels(),this._apiHistoryDetail=this._modalElement?.querySelector(this.options.selectors.apiHistoryDetail),this._deletedHistoryErrorState=this._modalElement?.querySelector(this.options.selectors.deletedHistoryErrorState),this._deletedHistoryItemsElement=this._modalElement?.querySelector(this.options.selectors.deletedHistoryItems),this._deletedHistoryLoadTrigger=this._modalElement?.querySelector(this.options.selectors.deletedHistoryLoadTrigger),this._deletedHistoryLoadingState=this._modalElement?.querySelector(this.options.selectors.deletedHistoryLoadingState),this._deletedHistorySection=this._modalElement?.querySelector(this.options.selectors.deletedHistorySection),this._historyEmptyState=this._modalElement?.querySelector(this.options.selectors.historyEmptyState),this._historyErrorState=this._modalElement?.querySelector(this.options.selectors.historyErrorState),this._historyList=this._modalElement?.querySelector(this.options.selectors.historyList),this._historyListItems=this._modalElement?.querySelector(this.options.selectors.historyListItems),this._historyLoadTrigger=this._modalElement?.querySelector(this.options.selectors.historyLoadTrigger),this._historyLoadingState=this._modalElement?.querySelector(this.options.selectors.historyLoadingState),this._historyOverview=this._modalElement?.querySelector(this.options.selectors.historyOverview),this._historyScrollLoadingState=this._modalElement?.querySelector(this.options.selectors.historyScrollLoadingState),this._sidebarElement=this._modalElement?.querySelector(this.options.selectors.sidebar),this._totalLineItemsCountElement=this._modalElement?.querySelector(this.options.selectors.totalLineItemsCount),this._bindHistoryListScroll()}_readRows(){return Array.from(this._modalElement?.querySelectorAll(this.options.selectors.row)||[]).map(t=>({element:t,editUrl:(t.dataset.editUrl||"").trim(),id:(t.dataset.lineItemId||"").trim(),removeUrl:(t.dataset.removeUrl||"").trim(),versionId:(t.dataset.versionId||"").trim()})).filter(t=>""!==t.id)}_hasRow(t){return this._rows.some(e=>e.id===t)}_readHistoryPanels(){return Array.from(this._modalElement?.querySelectorAll(this.options.selectors.historyPanel)||[]).map(t=>({element:t,id:(t.dataset.lineItemId||"").trim(),source:(t.dataset.historySource||"api").trim()||"api"})).filter(t=>""!==t.id)}_registerModalEvents(){this._modalElement?.addEventListener("click",this._boundHandleClick),this._modalElement?.addEventListener("change",this._boundHandleChange),this._modalElement?.addEventListener("input",this._boundHandleInput),this._modalElement?.addEventListener(this.options.events.historyEntryRemoveConfirmed,this._boundHandleHistoryEntryRemoveConfirmed),this._modalElement?.addEventListener(this.options.events.historyReload,this._loadHistoryHandler),this._modalElement?.addEventListener(this.options.events.openHistory,this._openHistoryHandler),this._modalElement?.addEventListener(this.options.events.lineItemsReloaded,this._lineItemsReloadedHandler),this._modalElement?.addEventListener(this.options.events.updateTotalLineItems,this._updateTotalLineItemsHandler),this._modalElement?.addEventListener("shown.bs.modal",this._boundHandleModalShown),this._modalElement?.addEventListener("keypress",this._boundHandleKeypress)}_resolveRootElement(){return this.el||document.querySelector(this.options.selectors.root)}_resolveModalElement(){return this._rootElement.closest(".modal")}
1_isActiveInstance(){return!!this.el.isConnected&&(this._rootElement.isConnected||(this._rootElement=this._resolveRootElement()),this._modalElement?.isConnected&&this._rootElement.isConnected)}_bindHistoryListScroll(){this._historyScrollElement!==this._historyList&&(this._unbindHistoryListScroll(),this._historyScrollElement=this._historyList||null,this._historyScrollElement?.addEventListener("scroll",this._boundHandleHistoryScroll,{passive:!0}))}_unbindHistoryListScroll(){this._historyScrollElement?.removeEventListener("scroll",this._boundHandleHistoryScroll),this._historyScrollElement=null}destroy(){document.removeEventListener(this.options.events.historyReadSucceeded,this._boundHandleHistoryReadSucceeded),this._unbindHistoryListScroll()}_handleHistoryScroll(t){let e=t.currentTarget;e instanceof HTMLElement&&(this._loadMoreHistoryFromScroll(e),this._loadMoreDeletedHistoryFromScroll(e))}_scheduleHistoryScrollCheck(){null===this._historyScrollLoadFrame&&(this._historyScrollLoadFrame=window.requestAnimationFrame(()=>{this._historyScrollLoadFrame=null,this._loadMoreHistoryFromScroll(this._historyList||null,!0)}))}_loadMoreHistoryFromScroll(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!t||this._historyIsLoading||this._historyIsFullyLoaded||this._historyHasError||!this._isActiveInstance()||t.classList.contains("d-none")||"api"===this._selectedDetailSource||!this._historyLoadTrigger||this._historyLoadTrigger.classList.contains("d-none"))return;let i=t.getBoundingClientRect(),s=this._historyLoadTrigger.getBoundingClientRect(),o=Number(this.options.historyScrollThreshold||160),n=s.top-i.bottom,a=t.scrollHeight>t.clientHeight;!e&&n>o||e&&a&&n>o||this._loadNextHistoryPage().catch(t=>{(0,r.F)(t)})}_loadMoreDeletedHistoryFromScroll(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!t||this._deletedHistoryIsLoading||this._deletedHistoryIsFullyLoaded||this._deletedHistoryHasError||!this._isActiveInstance()||t.classList.contains("d-none")||"api"===this._selectedDetailSource||!this._deletedHistoryLoadTrigger||this._deletedHistoryLoadTrigger.classList.contains("d-none"))return;if(!e&&t.scrollTop<=this._deletedHistoryLastScrollTop){this._deletedHistoryLastScrollTop=t.scrollTop;return}this._deletedHistoryLastScrollTop=t.scrollTop;let i=t.getBoundingClientRect(),s=this._deletedHistoryLoadTrigger.getBoundingClientRect(),o=Number(this.options.historyScrollThreshold||160),n=s.top-i.bottom,a=t.scrollHeight>t.clientHeight;!e&&n>o||e&&a&&n>o||this._loadNextDeletedHistoryPage().catch(t=>{(0,r.F)(t)})}_handleKeypress(t){if(!this._isActiveInstance())return;let e=t.target;e instanceof HTMLElement&&e.closest(this.options.selectors.searchContainer)&&"Enter"===t.key&&t.preventDefault()}_handleClick(t){if(!this._isActiveInstance())return;let e=t.target;if(!(e instanceof Element))return;let i=e.closest(this.options.selectors.closeTriggers);if(i&&this._modalElement?.contains(i)&&!i.disabled&&this._clearDetail(),e.closest(this.options.selectors.backButton)){t.preventDefault(),this._clearDetail();return}let s=e.closest(this.options.selectors.sidebarChevron);if(s){t.preventDefault(),t.stopImmediatePropagation();let e=s.closest(this.options.selectors.sidebarItem),i=(e?.dataset.lineItemId||"").trim(),o=(e?.dataset.lineItemHistoryId||"").trim();if(!i||this._openVisibleLineItemHistory(i))return;this._openApiDetail(i,o||null).catch(t=>{(0,r.F)(t)});return}let o=e.closest(this.options.selectors.historyEntryEditButton);if(o){t.preventDefault();let e=o.closest(this.options.selectors.historyEntry);if(!e)return;this._openHistoryEntryEdit(e);return}let n=e.closest(this.options.selectors.historyEntryEditCancelButton);if(n){t.preventDefault();let e=n.closest(this.options.selectors.historyEntry);if(!e)return;this._closeHistoryEntryEdit(e,!0);return}let a=e.closest(this.options.selectors.historyEntryEditSendButton);if(a){t.preventDefault();let e=a.closest(this.options.selectors.historyEntry);if(!e)return;this._submitHistoryEntryEdit(e);return}let l=e.closest(this.options.selectors.historyEntryReplyCancelButton);if(l){t.preventDefault();let e=l.closest(this.options.selectors.historyEntryReply);if(!e)return;this._closeHistoryEntryReply(e,!0);return}let d=e.closest(this.options.selectors.historyEntryReplySendButton);if(d){t.preventDefault();let e=d.closest(this.options.selectors.historyEntryReply),i=e?this._getHistoryEntryForReplyPanel
1(e):null;if(!i)return;this._submitHistoryEntryReply(i);return}let h=e.closest(this.options.selectors.historyEntryReplyButton);if(h){t.preventDefault();let e=h.closest(this.options.selectors.historyEntry);if(!e)return;this._openHistoryEntryReply(e);return}let y=e.closest(this.options.selectors.historyCancelButton);if(y){t.preventDefault();let e=y.closest(this.options.selectors.historyPanel);if(!e)return;this._cancelHistoryComposer(e);return}let m=e.closest(this.options.selectors.historySendButton);if(m){t.preventDefault();let e=m.closest(this.options.selectors.historyPanel);if(!e)return;this._sendHistoryMessage(e)}}_openVisibleLineItemHistory(t){let e=this._rows.find(e=>e.id===t);if(!e)return!1;let i=e.element.querySelector(this.options.selectors.actionDetail);return!!i&&(i instanceof HTMLButtonElement&&!!i.disabled||"true"===i.getAttribute("aria-disabled")||(i.click(),!0))}_handleChange(t){if(!this._isActiveInstance())return;let e=t.target;e instanceof HTMLSelectElement&&e.matches(this.options.selectors.sortSelect)&&this._handleHistorySortChange()}_handleHistoryEntryRemoveConfirmed(t){t.preventDefault(),t.stopPropagation();let e=t.detail||{};this._submitHistoryEntryRemove(e).catch(t=>{(0,r.F)(t)})}_handleHistorySortChange(){this._clearDetail(),this._refreshSidebarHistory().catch(t=>{(0,r.F)(t)})}_handleInput(t){if(!this._isActiveInstance())return;let e=t.target;if(e instanceof HTMLTextAreaElement){if(e.matches(this.options.selectors.historyCommentInput)){this._syncHistoryComposerActions(e);return}if(e.matches(this.options.selectors.historyEntryReplyInput)){let t=e.closest(this.options.selectors.historyEntryReply);t&&this._syncHistoryEntryReplySendButton(t);return}if(e.matches(this.options.selectors.historyEntryEditInput)){let t=e.closest(this.options.selectors.historyEntry);t&&this._syncHistoryEntryEditSendButton(t)}}}_openHistoryEntryEdit(t){if(!this._isHistoryEditable())return;this._closeHistoryEntryReplies(),this._closeHistoryEntryEdits(t);let e=t.querySelector(this.options.selectors.historyEntryEdit),i=t.querySelector(this.options.selectors.historyEntryEditInput),s=t.querySelector(this.options.selectors.historyEntryEditButton);e&&i&&(t.classList.add("quote-manage-line-items-modal__history-entry--editing"),e.hidden=!1,s?.setAttribute("aria-expanded","true"),this._syncHistoryEntryEditSendButton(t),window.requestAnimationFrame(()=>{i.focus(),i.setSelectionRange(i.value.length,i.value.length)}))}_closeHistoryEntryEdit(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];e&&this._resetHistoryEntryEditInput(t),t.classList.remove("quote-manage-line-items-modal__history-entry--editing"),t.querySelector(this.options.selectors.historyEntryEdit)?.setAttribute("hidden","hidden"),t.querySelector(this.options.selectors.historyEntryEditButton)?.setAttribute("aria-expanded","false"),this._syncHistoryEntryEditSendButton(t)}_closeHistoryEntryEdits(t){this._modalElement?.querySelectorAll(this.options.selectors.historyEntry).forEach(e=>{t&&e===t||this._closeHistoryEntryEdit(e,!0)})}_resetHistoryEntryEditInput(t){let e=t.querySelector(this.options.selectors.historyEntryEditInput),i=t.querySelector(".quote-manage-line-items-modal__history-entry-body");e&&i&&(e.value=i.textContent||"")}_openHistoryEntryReply(t){if(!this._isHistoryEditable())return;this._closeHistoryEntryEdits(),this._closeHistoryEntryReplies();let e=this._getHistoryEntryReplyPanel(t),i=e?.querySelector(this.options.selectors.historyEntryReplyInput),s=t.querySelector(this.options.selectors.historyEntryReplyButton);e&&i&&(t.classList.add("quote-manage-line-items-modal__history-entry--replying"),e.hidden=!1,s?.setAttribute("aria-expanded","true"),this._syncHistoryEntryReplySendButton(e),window.requestAnimationFrame(()=>{i.focus()}))}_getHistoryEntryReplyPanel(t){let e=t.nextElementSibling;for(;e instanceof HTMLElement;){if(e.matches(this.options.selectors.historyEntryReply))return e;e=e.nextElementSibling}return t.querySelector(this.options.selectors.historyEntryReply)}_closeHistoryEntryReply(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=this._getHistoryEntryForReplyPanel
1(t),s=t.querySelector(this.options.selectors.historyEntryReplyInput);e&&s&&(s.value=""),i?.classList.remove("quote-manage-line-items-modal__history-entry--replying"),i?.querySelector(this.options.selectors.historyEntryReplyButton)?.setAttribute("aria-expanded","false"),t.setAttribute("hidden","hidden"),this._syncHistoryEntryReplySendButton(t)}_getHistoryEntryForReplyPanel(t){let e=t.previousElementSibling;for(;e instanceof HTMLElement;){if(e.matches(this.options.selectors.historyEntry)&&!e.classList.contains("quote-manage-line-items-modal__history-entry--reply"))return e;e=e.previousElementSibling}return t.closest(this.options.selectors.historyEntry)}_closeHistoryEntryReplies(t){let e=t?this._getHistoryEntryReplyPanel(t):null;this._modalElement?.querySelectorAll(this.options.selectors.historyEntry).forEach(e=>{t&&e===t||(e.classList.remove("quote-manage-line-items-modal__history-entry--replying"),e.querySelector(this.options.selectors.historyEntryReplyButton)?.setAttribute("aria-expanded","false"))}),this._modalElement?.querySelectorAll(this.options.selectors.historyEntryReply).forEach(t=>{e&&t===e||this._closeHistoryEntryReply(t,!0)})}async _submitHistoryEntryReply(t){if(!this._isHistoryEditable())return;let e=this._getHistoryEntryReplyPanel(t),i=e?.querySelector(this.options.selectors.historyEntryReplyInput),s=t.closest(this.options.selectors.historyPanel),o=i?.value.trim()||"",n=(this.options.replyMessageUrl||"").trim(),a=(t.dataset.lineItemHistoryId||"").trim(),l=(s?.dataset.lineItemId||"").trim(),d=this._getDraftVersionId();if(e&&o&&n&&a&&d){this._toggleHistoryEntryReplyPending(e,!0);try{let t=await fetch(n,{method:"POST",body:this._buildHistoryActionPayload({comment:o,lineItemHistoryId:a,versionId:d}).toString(),credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8","X-Requested-With":"XMLHttpRequest"}});if(!t.ok)throw Error(this._snippet("messageReplyFailed",{status:t.status}));i&&(i.value=""),await this._refreshAfterHistoryAction(s,l||null,a,!0)}catch(t){this._toggleHistoryEntryReplyPending(e,!1),(0,r.F)(t)}}}async _submitHistoryEntryEdit(t){if(!this._isHistoryEditable())return;let e=t.querySelector(this.options.selectors.historyEntryEditInput),i=t.closest(this.options.selectors.historyPanel),s=e?.value.trim()||"",o=(t.dataset.editUrl||"").trim(),n=(t.dataset.lineItemHistoryId||"").trim(),a=(i?.dataset.lineItemId||"").trim(),l=this._getDraftVersionId();if(s&&o&&n&&l){this._toggleHistoryEntryEditPending(t,!0);try{let t=await fetch(o,{method:"POST",body:this._buildHistoryActionPayload({comment:s,lineItemHistoryId:n,versionId:l}).toString(),credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8","X-Requested-With":"XMLHttpRequest"}});if(!t.ok)throw Error(this._snippet("messageEditFailed",{status:t.status}));await this._refreshAfterHistoryAction(i,a||null,n)}catch(e){this._toggleHistoryEntryEditPending(t,!1),(0,r.F)(e)}}}async _submitHistoryEntryRemove(t){if(!this._isHistoryEditable()){t.close?.();return}let e=t.trigger instanceof HTMLElement?t.trigger:null,i=e?.closest(this.options.selectors.historyEntry)||null,s=i?.closest(this.options.selectors.historyPanel)||null,o=this._getStringFromUnknown(t.context?.removeUrl)||(i?.dataset.removeUrl||"").trim(),n=this._getStringFromUnknown(t.context?.lineItemHistoryId)||(i?.dataset.lineItemHistoryId||"").trim(),a=this._getStringFromUnknown(t.context?.lineItemId)||(s?.dataset.lineItemId||"").trim(),l=this._getStringFromUnknown(t.context?.versionId)||this._getDraftVersionId();if(!i||!o||!n||!l){t.close?.();return}this._closeHistoryEntryEdits(),this._closeHistoryEntryReplies(),this._toggleHistoryEntryRemovePending(i,!0),this._toggleConfirmModalPending(t,!0);try{let e=await fetch(o,{method:"POST",body:this._buildHistoryActionPayload({lineItemHistoryId:n,versionId:l}).toString(),credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8","X-Requested-With":"XMLHttpRequest"}});if(!e.ok)throw Error(this._snippet("messageRemoveFailed",{status:e.status}));
1t.close?.(),await this._refreshAfterHistoryAction(s,a||null,null,!0)}catch(e){this._toggleHistoryEntryRemovePending(i,!1),this._toggleConfirmModalPending(t,!1),(0,r.F)(e)}}_handleOpenHistory(t){if(!this._isActiveInstance())return;let e=t.detail,i=e?.lineItemId?.trim()||"";if(!i)return;let s=e?.focusComment!==!1;this._openApiDetail(i).then(()=>{this._shouldFocusHistoryComment=s&&this._isHistoryEditable(),this._focusHistoryCommentIfRequested(this._apiHistoryDetail||null)})}_handleLineItemsReloaded(t){let e=this._selectedRowId,i=t.detail?.reason||"",s="add"===i||"comment"===i||"delete"===i;if(this._syncState({renderHistory:s}),!s)return;let o="delete"!==i||null===e||this._hasRow(e);this._refreshSidebarHistory({keepDetailOpen:o}).catch(t=>{(0,r.F)(t)})}_handleUpdateTotalLineItems(t){let e=t.detail?.totalLineItems||0;this._totalLineItemsCountElement&&(this._totalLineItemsCountElement.textContent=this._snippet(e>1?"historyPluralLabel":"historySingularLabel",{count:e}))}_handleHistoryReadSucceeded(t){if(!this._isActiveInstance()){this.destroy();return}(t.detail?.payloads||[]).some(t=>this._isDeletedHistoryReadPayload(t))&&(this._deletedHistoryShouldReloadOnModalOpen=!0)}_isDeletedHistoryReadPayload(t){return(t.quoteLineItemIds||[]).length>0&&0===(t.lineItemHistoryIds||[]).length}_handleModalShown(){this._deletedHistoryShouldReloadOnModalOpen&&this._isActiveInstance()&&(this._deletedHistoryShouldReloadOnModalOpen=!1,this._reloadDeletedHistory().catch(t=>{(0,r.F)(t)}))}_syncState(){let{renderHistory:t=!0}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!this._isSyncing&&(this._isSyncing=!0,this._hydrateState(),t&&this._renderHistoryState(),this._isSyncing=!1,t&&(this._requestHistoryReadCollection(),this._selectedRowId||this._clearDetail()))}async _sendHistoryMessage(t){if(!this._isHistoryEditable())return;let e=t.querySelector(this.options.selectors.historyCommentInput),i=(this.options.sendMessageUrl||"").trim(),s=e?.value.trim()||"",o=(t.dataset.lineItemId||"").trim(),n=this._getDraftVersionId();if(s&&o&&n&&i){this._toggleHistoryComposerPending(t,!0);try{let r=await fetch(i,{method:"POST",body:this._buildHistoryActionPayload({comment:s,lineItemId:o,versionId:n}).toString(),credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8","X-Requested-With":"XMLHttpRequest"}});if(!r.ok)throw Error(this._snippet("messageSendFailed",{status:r.status}));e&&(e.value=""),await this._refreshAfterHistoryAction(t,o,null,!0)}catch(e){this._toggleHistoryComposerPending(t,!1),(0,r.F)(e)}}}_getDraftVersionId(){return(this.options.draftVersionId||"").trim()}_buildHistoryActionPayload(t){let e=new URLSearchParams;return Object.entries(t).forEach(t=>{let[i,s]=t;e.set(i,s)}),e}_cancelHistoryComposer(t){let e=t.querySelector(this.options.selectors.historyCommentInput);e&&!e.disabled&&(e.value="",this._syncHistoryComposerActions(e),e.focus())}_syncHistoryComposerActions(t){let e=t.closest(this.options.selectors.historyPanel),i=e?.querySelector(this.options.selectors.historyCancelButton),s=e?.querySelector(this.options.selectors.historySendButton),r=""!==t.value.trim();if(i||s){if(i?.classList.toggle("d-none",!r),!this._isHistoryEditable()){i&&(i.disabled=!0),s&&(s.disabled=!0);return}i&&(i.disabled=!1),s&&(s.disabled=!r)}}_syncHistoryEntryEditSendButton(t){let e=t.querySelector(this.options.selectors.historyEntryEditInput),i=t.querySelector(this.options.selectors.historyEntryEditSendButton);if(i){if(!this._isHistoryEditable()){i.disabled=!0;return}i.disabled=""===(e?.value.trim()||"")}}_syncHistoryEntryReplySendButton(t){let e=t.querySelector(this.options.selectors.historyEntryReplyInput),i=t.querySelector(this.options.selectors.historyEntryReplySendButton);if(i){if(!this._isHistoryEditable()){i.disabled=!0;return}i.disabled=""===(e?.value.trim()||"")}}_toggleHistoryComposerPending(t,e){let i=t.querySelector(this.options.selectors.historyCommentInput),s=t.querySelector(this.options.selectors.historyCancelButton),r=t.querySelector(this.options.selectors.historySendButton),o=e||!this._isHistoryEditable();i&&(i.disabled=o),s&&(s.disabled=o),r&&(r.disabled=o||""===(i?.value.trim()||""),r.toggleAttribute("aria-busy",e))}_toggleHistoryEntryReplyPending(t,e){let i=t.querySelector(this.options.selectors.historyEntryReplyInput),s=t.querySelector(this.options.selectors.historyEntryReplyCancelButton),r=t.querySelector(this.options.selectors.historyEntryReplySendButton),o=e||!this._isHistoryEditable();i&&(i.disabled=o),s&&(s.disabled=o),r&&(r.disabled=o||""===(i?.value.trim()||""),r.toggleAttribute("aria-busy",e))}_toggleHistoryEntryEditPending(t,e){let i=t.querySelector(this.options.selectors.historyEntryEditInput),s=t.querySelector(this.options.selectors.historyEntryEditCancelButton),r=t.querySelector(this.options.selectors.historyEntryDeleteButton),o=t.querySelector(this.options.selectors.historyEntryEditSendButton),n=e||!this._isHistoryEditable();i&&(i.disabled=n),s&&(s.disabled=n),o&&(o.disabled=n||""===(i?.value.trim()||""),o.toggleAttribute("aria-busy",e)),r&&(r.disabled=n,r.toggleAttribute("aria-busy",e))}_toggleHistoryEntryRemovePending(t,e){let i=t.querySelector(this.options.selectors.historyEntryDeleteButton);i&&(i.disabled=e,i.toggleAttribute("aria-busy",e))}_toggleConfirmModalPending(t,e){let i=t.modal instanceof HTMLElement?t.modal:null,s=i?.querySelector("[data-b2b-confirm-modal-cancel]"),r=i?.querySelector('[data-bs-dismiss="modal"]'),o=i?.querySelector("[data-b2b-confirm-modal-confirm]");i?.classList.toggle("is-loading",e),s&&(s.disabled=e),r&&(r.disabled=e),o&&(o.disabled=e,o.toggleAttribute("aria-busy",e))}_getStringFromUnknown(t){return"string"==typeof t?t.trim():""}async _loadHistory(t){let e=t.detail.reason||"",i=(t.detail.lineItemId||"").trim();if(this.options.draftVersionId=t.detail.versionId||"",!(this.options.historyUrl||"").trim()){this._renderHistoryState();return}if(this._resetHistoryCache(),await Promise.all([this._loadHistoryPage(1),this._loadInitialDeletedHistory()]),"delete"===e){this._syncState({renderHistory:!1});let t=this._selectedRowId;if(null!==t&&(i===t||!this._hasRow(t))){this._clearDetail();return}}this._openSelectedHistoryDetail()}async _loadNextHistoryPage(){this._historyIsFullyLoaded||await this._loadHistoryPage(this._historyCurrentPage+1)}async _refreshHistory(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(this._resetHistoryCache(),await this._loadHistoryPage(),t){await this._openApiDetail(t,e);return}this._renderHistoryState()}async _refreshSidebarHistory(){let{keepDetailOpen:t=!0}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}
1,e=t?this._selectedRowId:null,i=t?this._selectedHistoryId:null,s=t?this._selectedDetailSource:null;if(this._resetHistoryCache(),await this._loadHistoryPage(),this._isActiveInstance()){if("api"===s&&e&&this._hasRow(e)){await this._openApiDetail(e,i);return}this._clearDetail()}}_resetHistoryCache(){this._historyById.clear(),this._historyCurrentPage=0,this._historyHasError=!1,this._historyIsFullyLoaded=!1,this._historyItems=[],this._historyLineItems.clear(),this._historyLoadPromise=null,this._historyTotal=0,this._resetDetailHistoryCache(),this._renderHistoryState()}_resetDetailHistoryCache(){this._detailHistoryById.clear(),this._detailHistoryCurrentPage=0,this._detailHistoryIsFullyLoaded=!1,this._detailHistoryItems=[],this._detailHistoryLineItems.clear(),this._detailHistoryLoadPromise=null,this._detailHistoryTotal=0}_resetDeletedHistoryCache(){this._deletedHistoryById.clear(),this._deletedHistoryCurrentPage=0,this._deletedHistoryHasError=!1,this._deletedHistoryIsFullyLoaded=!1,this._deletedHistoryIsLoading=!1,this._deletedHistoryItems=[],this._deletedHistoryLastScrollTop=0,this._deletedHistoryLoadPromise=null,this._deletedHistoryRenderedIds.clear(),this._deletedHistoryItemsElement&&(this._deletedHistoryItemsElement.innerHTML=""),this._renderHistoryState()}async _reloadDeletedHistory(){this._resetDeletedHistoryCache(),await this._loadInitialDeletedHistory()}async _loadHistoryPage(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;if(this._historyLoadPromise&&await this._historyLoadPromise,this._historyIsFullyLoaded||this._historyCurrentPage>=t){this._renderHistoryState();return}if(!this._shouldLoadHistory()||!(this.options.historyUrl||"").trim()){this._historyIsFullyLoaded=!0,this._renderHistoryState();return}this._historyIsLoading=!0,this._historyHasError=!1,this._renderHistoryState();let e=this._fetchHistoryPage(t).then(e=>{this._applyHistoryResponse(e,t)}).catch(t=>{throw this._historyHasError=!0,t}).finally(()=>{this._historyIsLoading=!1,this._historyLoadPromise=null,this._renderHistoryState()});this._historyLoadPromise=e,await e}async _loadInitialDeletedHistory(){this._deletedHistoryCurrentPage>0||this._deletedHistoryIsLoading||this._deletedHistoryIsFullyLoaded||this._deletedHistoryHasError||await this._loadDeletedHistoryPage(1)}async _loadNextDeletedHistoryPage(){this._deletedHistoryIsFullyLoaded||await this._loadDeletedHistoryPage(this._deletedHistoryCurrentPage+1)}async _loadDeletedHistoryPage(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;if(this._deletedHistoryLoadPromise&&await this._deletedHistoryLoadPromise,this._deletedHistoryIsFullyLoaded||this._deletedHistoryCurrentPage>=t){this._renderHistoryState();return}if(!(this.options.deletedLineItemsUrl||"").trim()){this._deletedHistoryIsFullyLoaded=!0,this._renderHistoryState();return}this._deletedHistoryIsLoading=!0,this._deletedHistoryHasError=!1,this._renderHistoryState();let e=this._fetchDeletedHistoryPage(t).then(e=>{this._applyDeletedHistoryResponse(e,t)}).catch(t=>{throw this._deletedHistoryHasError=!0,t}).finally(()=>{this._deletedHistoryIsLoading=!1,this._deletedHistoryLoadPromise=null,this._renderHistoryState()});this._deletedHistoryLoadPromise=e,await e}async _fetchDeletedHistoryPage(t){let e=new URL(this.options.deletedLineItemsUrl,window.location.origin),i=Number(this.options.historyLimit||10);e.searchParams.delete("versionId"),e.searchParams.delete("draftVersionId"),e.searchParams.set("p",`${t}`),e.searchParams.set("limit",`${i>0?i:10}`);let s=await fetch(`${e.pathname}${e.search}${e.hash}`,{method:"GET",credentials:"same-origin",headers:{Accept:"application/json","X-Requested-With":"XMLHttpRequest"}});if(!s.ok)throw Error(this._snippet("lineItemHistoryFailed",{status:s.status}));return await s.json()}_applyDeletedHistoryResponse(t,e){let i=this._normalizeCollectionElements(t.elements),s=i.filter(t=>""!==this._stringValue(t.deletedAt)),r=[];this._deletedHistoryCurrentPage=e,s.forEach(t=>{let e=this._stringValue(t.id);if(e){if(this._deletedHistoryById.has(e)){let i=this._deletedHistoryItems.findIndex(t=>this._stringValue(t.id)===e);i>=0&&(this._deletedHistoryItems[i]=t)}else this._deletedHistoryItems.push(t),r.push(t);this._deletedHistoryById.set(e,t)}}),this._deletedHistoryIsFullyLoaded=this._isLineItemHistoryResponseFullyLoaded(t,e,i.length),this._appendDeletedHistoryLineItems(r)}_appendDeletedHistoryLineItems(t){if(!this._deletedHistoryItemsElement||0===t.length)return;let e=t.filter(t=>{let e=this._stringValue(t.id);return!(!e||this._deletedHistoryRenderedIds.has(e))&&(this._deletedHistoryRenderedIds.add(e),
1!0)}).map(t=>this._renderDeletedHistoryLineItem(t)).join("");e&&this._deletedHistoryItemsElement.insertAdjacentHTML("beforeend",e)}_applyHistoryResponse(t,e){let i=this._normalizeHistoryResponse(t),s=i.records;if(this._historyCurrentPage=e,this._storeHistoryRecords(s),i.isLineItemResponse){this._historyTotal=this._historyItems.length,this._historyIsFullyLoaded=this._isLineItemHistoryResponseFullyLoaded(t,e,i.sourceCount);return}this._historyTotal=Number(t.total||s.length||this._historyTotal||0),this._historyIsFullyLoaded=0===s.length||this._historyItems.length>=this._historyTotal}async _loadDetailHistoryPage(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this._detailHistoryLoadPromise&&await this._detailHistoryLoadPromise,this._detailHistoryIsFullyLoaded||this._detailHistoryCurrentPage>=t)return;if(!this._shouldLoadHistory()||!(this.options.historyUrl||"").trim()){this._detailHistoryIsFullyLoaded=!0;return}let i=this._fetchHistoryPage(t,e).then(e=>{let i=this._normalizeHistoryResponse(e),s=i.records;if(this._detailHistoryCurrentPage=t,this._storeDetailHistoryRecords(s),i.isLineItemResponse){this._detailHistoryTotal=this._detailHistoryItems.length,this._detailHistoryIsFullyLoaded=this._isLineItemHistoryResponseFullyLoaded(e,t,i.sourceCount);return}this._detailHistoryTotal=Number(e.total||s.length||this._detailHistoryTotal||0),this._detailHistoryIsFullyLoaded=0===s.length||this._detailHistoryItems.length>=this._detailHistoryTotal}).finally(()=>{this._detailHistoryLoadPromise=null});this._detailHistoryLoadPromise=i,await i}_shouldLoadHistory(){return!this._isHistoryEditable()||""!==this._getDraftVersionId()}_isHistoryEditable(){return!1!==this.options.isEditable&&"false"!==this.options.isEditable&&"0"!==this.options.isEditable}async _ensureAllDetailHistoryLoaded(){for(;!this._detailHistoryIsFullyLoaded&&this._isActiveInstance();){let t=this._detailHistoryCurrentPage+1;if(await this._loadDetailHistoryPage(t,!0),this._detailHistoryCurrentPage<t)break}}async _fetchHistoryPage(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=new URL(this.options.historyUrl,window.location.origin),s=Number(this.options.historyLimit||10),r=this._readHistoryOrder(),o=this._getDraftVersionId();i.searchParams.set("p",`${t}`),i.searchParams.set("limit",`${s>0?s:10}`),i.searchParams.set("order",r),o&&i.searchParams.set("versionId",o),this._selectedRowId&&e&&i.searchParams.set("lineItemId",this._selectedRowId);let n=await fetch(`${i.pathname}${i.search}${i.hash}`,{method:"GET",credentials:"same-origin",headers:{Accept:"application/json","X-Requested-With":"XMLHttpRequest"}});if(!n.ok)throw Error(this._snippet("lineItemHistoryFailed",{status:n.status}));let a=await n.json();return this._assignHistoryCurrencySymbol(a),a}_assignHistoryCurrencySymbol(t){if(this._historyCurrencySymbol)return;let e=this._stringValue(t.currency?.symbol);e&&(this._historyCurrencySymbol=e)}_normalizeHistoryResponse(t){let e=this._normalizeCollectionElements(t.elements);return{isLineItemResponse:"quote_line_item"===t.entity||e.some(t=>this._isHistoryLineItemResponseElement(t)),records:e.flatMap(t=>this._isHistoryLineItemResponseElement(t)?this._normalizeHistoryRecordsFromLineItem(t):[t]),sourceCount:e.length}}_normalizeHistoryRecordsFromLineItem(t){return this._normalizeCollectionElements(t.histories).map(e=>this._attachLineItemToHistory(e,t))}_attachLineItemToHistory(t,e){let i=this._stringValue(t.quoteLineItemId||e.id),s=this._createHistoryLineItemSnapshot(e),r=t.quoteLineItem?{...s,...t.quoteLineItem}:s;return{...t,quoteLineItem:r,quoteLineItemId:i}}_createHistoryLineItemSnapshot(t){let e={...t};return delete e.histories,e}_isHistoryLineItemResponseElement(t){return this._isRecord(t)&&"histories"in t}_normalizeCollectionElements(t){return t?Array.isArray(t)?t:this._isRecord(t)?"elements"in t?this._normalizeCollectionElements(t.elements):Object.keys(t).map(e=>t[e]).filter(t=>this._isRecord(t)&&""!==this._stringValue(t.id)):[]:[]}_isLineItemHistoryResponseFullyLoaded(t,e,i){let s=Number(t.limit||this.options.historyLimit||10),r=Number(t.total||0);return 0===i||(r<=0?i<s:e*s>=r)}
1_storeHistoryRecords(t){t.forEach(t=>{let e=(t.id||"").trim(),i=this._getHistoryLineItemId(t);if(e&&i){if(this._rememberHistoryLineItem(t),this._historyById.has(e)){let i=this._historyItems.findIndex(t=>t.id===e);this._historyById.set(e,t),i>=0&&(this._historyItems[i]=t);return}this._historyById.set(e,t),this._historyItems.push(t)}}),this._sortHistoryItems(this._historyItems)}_storeDetailHistoryRecords(t){t.forEach(t=>{let e=(t.id||"").trim(),i=this._getHistoryLineItemId(t);if(e&&i){if(this._rememberDetailHistoryLineItem(t),this._detailHistoryById.has(e)){let i=this._detailHistoryItems.findIndex(t=>t.id===e);this._detailHistoryById.set(e,t),i>=0&&(this._detailHistoryItems[i]=t);return}this._detailHistoryById.set(e,t),this._detailHistoryItems.push(t)}}),this._sortHistoryItems(this._detailHistoryItems)}_sortHistoryItems(t){let e=this._readHistoryOrder(),i=this._isAlphabetHistoryOrder(e),s="updated-at-asc"===e||"created-at-asc"===e||"label-asc"===e?1:-1;t.sort((t,e)=>{let r=Date.parse(t.createdAt||"")||0,o=Date.parse(e.createdAt||"")||0;if(i){let i=this._getLineItemLabel(t.quoteLineItem||this._getHistoryLineItem(this._getHistoryLineItemId(t))),n=this._getLineItemLabel(e.quoteLineItem||this._getHistoryLineItem(this._getHistoryLineItemId(e))),a=i.localeCompare(n,void 0,{numeric:!0,sensitivity:"base"});return 0!==a?a*s:o-r}return(r-o)*s})}_readHistoryOrder(){return this._modalElement?.querySelector(this.options.selectors.sortSelect)?.value?.trim()||`${this.options.historyOrder||"updated-at-desc"}`}_isAlphabetHistoryOrder(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this._readHistoryOrder();return"label-asc"===t||"label-desc"===t}_rememberHistoryLineItem(t){let e=this._getHistoryLineItemId(t);e&&t.quoteLineItem&&this._historyLineItems.set(e,t.quoteLineItem)}_rememberDetailHistoryLineItem(t){let e=this._getHistoryLineItemId(t);e&&t.quoteLineItem&&this._detailHistoryLineItems.set(e,t.quoteLineItem)}_getHistoryLineItemId(t){return(t.quoteLineItemId||t.quoteLineItem?.id||"").trim()}_getHistoriesForLineItem(t){return this._historyItems.filter(e=>this._getHistoryLineItemId(e)===t)}_getDetailHistoriesForLineItem(t){return this._detailHistoryItems.filter(e=>this._getHistoryLineItemId(e)===t)}_getHistoryLineItem(t){return this._historyLineItems.get(t)||{id:t,label:this._getRowLabel(t)}}_getDetailHistoryLineItem(t){return this._detailHistoryLineItems.get(t)||this._historyLineItems.get(t)||{id:t,label:this._getRowLabel(t)}}_getRowLabel(t){let e=this._rows.find(e=>e.id===t);return e?.element.querySelector(".line-item-label, .quote-manage-line-items-modal__product-name")?.textContent?.trim()||""}async _refreshAfterHistoryAction(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,s=arguments.length>3&&void 0!==arguments[3]&&arguments[3];s&&this._syncState(),await this._refreshHistory(e,i)}async _requestManageLineItemsReload(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"reload";await new Promise((e,i)=>{let s=new CustomEvent(this.options.events.lineItemsReloadRequested,{bubbles:!0,cancelable:!0,detail:{reason:t,reject:i,resolve:e}});this._modalElement?.dispatchEvent(s),s.defaultPrevented||e()})}_hideRenderedHistoryPanels(){this._historyPanels.forEach(t=>{t.element.classList.add("d-none")})}_renderHistoryState(){let t=this._getVisibleSidebarHistoryItems(),e=this._historyItems.length>0,i=t.length>0,s=this._deletedHistoryItems.length>0,r=s||this._deletedHistoryIsLoading||this._deletedHistoryHasError,o=i||r,n=!this._historyIsLoading&&!this._historyHasError&&this._historyIsFullyLoaded&&!i&&!s&&!this._deletedHistoryIsLoading&&!this._deletedHistoryHasError&&this._deletedHistoryIsFullyLoaded,a="api"===this._selectedDetailSource;this._updateHistoryMarkup(()=>{let e=this._getGroupedSidebarItems(t);this._historyLoadingState?.classList.toggle("d-none",a||!this._historyIsLoading||i),this._historyScrollLoadingState?.classList.toggle("d-none",a||!this._historyIsLoading||!i),this._historyErrorState?.classList.toggle("d-none",a||!this._historyHasError),this._historyEmptyState?.classList.toggle("d-none",a||!n),this._historyLoadTrigger?.classList.toggle("d-none",a||!i||this._historyIsLoading||this._historyHasError||this._historyIsFullyLoaded),this._historyOverview?.classList.toggle("d-none",a||!o),this._historyList&&this._historyList.classList.toggle("d-none",!o&&!a),this._historyListItems&&(this._historyListItems.classList.toggle("d-none",!i||a),this._historyListItems.innerHTML=i?this._renderSidebarItems(e,t):""),this._deletedHistorySection?.classList.toggle("d-none",a||!r),this._deletedHistoryItemsElement?.classList.toggle("d-none",!s||a),this._deletedHistoryLoadingState?.classList.toggle("d-none",a||!this._deletedHistoryIsLoading),this._deletedHistoryErrorState?.classList.toggle("d-none",a||!this._deletedHistoryHasError),this._deletedHistoryLoadTrigger?.classList.toggle("d-none",a||!s||this._deletedHistoryIsLoading||this._deletedHistoryHasError||this._deletedHistoryIsFullyLoaded)}),!e||a||this._historyIsLoading||this._historyIsFullyLoaded||this._scheduleHistoryScrollCheck(),this._requestHistoryReadCollection()}_renderDeletedHistoryLineItem(t){let e=this._getLineItemLabel(t),i=this._getLineItemSpecification(t),s=this._getDeletedLineItemHistory(t),r=this._stringValue(t.id),o=s?this._getActorName(s):this._snippet("merchant"),n=this._formatDate(s?.createdAt||this._stringValue(t.deletedAt)),a=this._getLineItemImage(t,e,"quote-manage-line-items-modal__deleted-attachment-thumb"),l=!!s&&this._isUnreadHistoryRecord(s);return`
2            <article
3                class="quote-manage-line-items-modal__deleted-attachment position-relative"
4                data-b2b-quote-manage-line-items-deleted-attachment
5                data-b2b-quote-manage-line-items-history-entry
6                data-line-item-id="${this._escapeAttribute(r)}"
7                ${s?.id?`data-line-item-history-id="${this._escapeAttribute(s.id)}"`:""}
8                ${s?`data-comment-id="${this._escapeAttribute(this._getHistoryCommentId(s))}"`:""}
9                ${l?"data-unread":""}
10            >
11                ${l?'<span class="position-absolute top-0 end-0 translate-middle p-1 bg-danger border border-light rounded-circle quote-manage-line-items-modal__deleted-attachment-unread-badge" aria-hidden="true"></span>':""}
12                <div class="quote-manage-line-items-modal__deleted-attachment-header">
13                    ${a}
14                    <div class="quote-manage-line-items-modal__deleted-attachment-copy">
15                        <div class="quote-manage-line-items-modal__deleted-attachment-title">${this._escapeHtml(e)}</div>
16                        ${i?`<div class="quote-manage-line-items-modal__deleted-attachment-specification">${this._escapeHtml(i)}</div>`:""}
17                    </div>
18                </div>
19                <div class="quote-manage-line-items-modal__deleted-attachment-meta">
20                    <span class="quote-manage-line-items-modal__sidebar-actor" data-actor-initials="${this._escapeAttribute(this._getInitials(o))}">${this._escapeHtml(o)}</span>
21                    ${n?`<span class="quote-manage-line-items-modal__sidebar-timestamp">${this._escapeHtml(n)}</span>`:""}
22                </div>
23                ${this._renderBadge("quote-manage-line-items-modal__sidebar-badge",{label:this._snippet("removedFromQuote"),value:""})}
24            </article>
25        `}_renderSidebarItem(t){let e=this._getHistoryLineItemId(t),i=this._getHistoryLineItem(e),s=this._getLineItemLabel(i),r=this._getLineItemSpecification(i),o=this._getSidebarActorName(t),n=this._getHistoryBadges(t,i,!1),a=this._shouldRenderHistoryComment(t)?this._getHistoryCommentText(t):"",l=this._getHistoryCommentId(t),d=this._getLineItemImage(i,s,"quote-manage-line-items-modal__sidebar-thumb"),h=this._formatDate(t.createdAt||""),y=t.id&&t.id===this._selectedHistoryId?" quote-manage-line-items-modal__sidebar-item--active":"",m=this._isUnreadHistoryRecord(t)?'<span class="position-absolute top-0 end-0 translate-middle p-1 bg-danger border border-light rounded-circle quote-manage-line-items-modal__sidebar-item-unread-badge" aria-hidden="true"></span>':"";return n.map(i=>`
26            <article
27                class="quote-manage-line-items-modal__sidebar-item${y}"
28                data-b2b-quote-manage-line-items-sidebar-item
29                data-line-item-id="${this._escapeAttribute(e)}"
30                data-line-item-history-id="${this._escapeAttribute(t.id||"")}"
31                ${l?`data-comment-id="${this._escapeAttribute(l)}"`:""}
32            >
33                <div class="quote-manage-line-items-modal__sidebar-item-header position-relative">
34                    ${m}
35                    ${d}
36                    <div class="quote-manage-line-items-modal__sidebar-copy">
37                        <div class="quote-manage-line-items-modal__sidebar-title">${this._escapeHtml(s)}</div>
38                        ${r?`<div class="quote-manage-line-items-modal__sidebar-specification">${this._escapeHtml(r)}</div>`:""}
39                    </div>
40                    <button
41                        type="button"
42                        class="quote-manage-line-items-modal__sidebar-chevron"
43                        aria-label="${this._escapeAttribute(this._snippet("openLabel"))}"
44                    >&rsaquo;</button>
45                </div>
46                <div class="quote-manage-line-items-modal__sidebar-item-body">
47                    ${this._renderSidebarItemChange(o,h,a,i,t)}
48                </div>
49            </article>
50        `).join("")}_renderSidebarItems(t,e){return this._isAlphabetHistoryOrder()?t.map(t=>this._renderGroupedSidebarItem(t)).join(""):e.map(t=>this._renderSidebarItem(t)).join("")}_getVisibleSidebarHistoryItems(){return this._historyItems.filter(t=>!(t.quoteLineItem||this._getHistoryLineItem(this._getHistoryLineItemId(t))).deletedAt)}_getGroupedSidebarItems(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this._getVisibleSidebarHistoryItems(),e=new Map;return t.forEach(t=>{let i=this._getHistoryLineItemId(t);i&&(e.has(i)||e.set(i,[]),e.get(i)?.push(t))}),Array.from(e.values())}_renderGroupedSidebarItem(t){let e=t[0];if(!e)return"";let i=this._getHistoryLineItemId(e),s=this._getHistoryLineItem(i),r=this._getLineItemLabel(s),o=this._getLineItemSpecification(s),n=this._getLineItemImage(s,r,"quote-manage-line-items-modal__sidebar-thumb"),a=t.some(t=>t.id&&t.id===this._selectedHistoryId)?" quote-manage-line-items-modal__sidebar-item--active":"",l=t.some(t=>this._isUnreadHistoryRecord(t))?'<span class="position-absolute top-0 end-0 translate-middle p-1 bg-danger border border-light rounded-circle quote-manage-line-items-modal__sidebar-item-unread-badge" aria-hidden="true"></span>':"";return`
51            <article
52                class="quote-manage-line-items-modal__sidebar-item${a}"
53                data-b2b-quote-manage-line-items-sidebar-item
54                data-line-item-id="${this._escapeAttribute(i)}"
55                data-line-item-history-id="${this._escapeAttribute(e.id||"")}"
56            >
57                <div class="quote-manage-line-items-modal__sidebar-item-header position-relative">
58                    ${l}
59                    ${n}
60                    <div class="quote-manage-line-items-modal__sidebar-copy">
61                        <div class="quote-manage-line-items-modal__sidebar-title">${this._escapeHtml(r)}</div>
62                        ${o?`<div class="quote-manage-line-items-modal__sidebar-specification">${this._escapeHtml(o)}</div>`:""}
63                    </div>
64                    <button
65                        type="button"
66                        class="quote-manage-line-items-modal__sidebar-chevron"
67                        aria-label="${this._escapeAttribute(this._snippet("openLabel"))}"
68                    >&rsaquo;</button>
69                </div>
70                <div class="quote-manage-line-items-modal__sidebar-item-body">
71                    ${t.map(t=>{let e=this._getSidebarActorName(t),i=this._getHistoryBadges(t,s,!1),r=this._shouldRenderHistoryComment(t)?this._getHistoryCommentText(t):"",o=this._formatDate(t.createdAt||"");return i.map(i=>this._renderSidebarItemChange(e,o,r,i,t)).join("")}).join("")}
72                </div>
73            </article>
74        `}
74_renderSidebarItemChange(t,e,i,s,r){return`
75            <div
76                class="quote-manage-line-items-modal__sidebar-item-change"
77                data-b2b-quote-manage-line-items-history-entry
78                ${r?.id?`data-line-item-history-id="${this._escapeAttribute(r.id)}"`:""}
79                ${r?`data-line-item-id="${this._escapeAttribute(this._getHistoryLineItemId(r))}"`:""}
80                ${r?`data-comment-id="${this._escapeAttribute(this._getHistoryCommentId(r))}"`:""}
81                ${r&&this._isUnreadHistoryRecord(r)?"data-unread":""}
82            >
83                <div class="quote-manage-line-items-modal__sidebar-meta">
84                    <span class="quote-manage-line-items-modal__sidebar-actor" data-actor-initials="${this._escapeAttribute(this._getInitials(t))}">${this._escapeHtml(t)}</span>
85                    ${e?`<span class="quote-manage-line-items-modal__sidebar-timestamp">${this._escapeHtml(e)}</span>`:""}
86                </div>
87                ${i?this._renderSidebarComment(i):this._renderBadge("quote-manage-line-items-modal__sidebar-badge",s)}
88            </div>
89        `}_renderHistoryDetail(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(!this._apiHistoryDetail)return;let i=this._getDetailHistoryLineItem(t),s=this._getLineItemLabel(i),r=this._getLineItemSpecification(i),o=this._getDetailHistoriesForLineItem(t),n=o.length>0?o:this._getHistoriesForLineItem(t),a=this._getLineItemImage(i,s,"quote-manage-line-items-modal__history-panel-thumb"),l=n.length>0?`<div class="quote-manage-line-items-modal__history-list">${n.map(t=>this._renderHistoryEntryThread(t,i,e)).join("")}</div>`:`<div class="quote-manage-line-items-modal__sidebar-state">${this._escapeHtml(this._snippet("empty"))}</div>`;this._updateHistoryMarkup(()=>{this._apiHistoryDetail&&(this._apiHistoryDetail.innerHTML=`
90                <section
91                    class="quote-manage-line-items-modal__history-panel"
92                    data-b2b-quote-manage-line-items-history-panel
93                    data-history-source="api"
94                    data-line-item-id="${this._escapeAttribute(t)}"
95                >
96                    <div class="quote-manage-line-items-modal__history-panel-header">
97                        <button
98                            type="button"
99                            class="btn btn-light quote-manage-line-items-modal__history-back"
100                            data-b2b-quote-manage-line-items-back
101                            aria-label="${this._escapeAttribute(this._snippet("backLabel"))}"
102                        >&lsaquo;</button>
103                        ${a}
104                        <div class="quote-manage-line-items-modal__history-panel-copy">
105                            <div class="quote-manage-line-items-modal__history-panel-title">${this._escapeHtml(s)}</div>
106                            ${r?`<div class="quote-manage-line-items-modal__history-panel-specification">${this._escapeHtml(r)}</div>`:""}
107                        </div>
108                    </div>
109                    ${this._renderComposer()}
110                    ${l}
111                </section>
112            `)}),this._syncRenderedHistoryControls(),this._scrollHistoryEntryIntoView(e),this._requestHistoryReadCollection()}
112_renderDetailLoading(){this._updateHistoryMarkup(()=>{this._apiHistoryDetail&&(this._apiHistoryDetail.innerHTML=`
113                <div class="quote-manage-line-items-modal__sidebar-state">
114                    <span class="spinner-border spinner-border-sm" aria-hidden="true"></span>
115                    <span>${this._escapeHtml(this._snippet("loading"))}</span>
116                </div>
117            `)})}_renderComposer(){let t=this._isHistoryEditable();return`
118            <div class="quote-manage-line-items-modal__history-composer">
119                <span class="quote-manage-line-items-modal__history-composer-avatar" aria-hidden="true">${this._escapeHtml(this._getComposerInitials())}</span>
120                <div class="quote-manage-line-items-modal__history-composer-field">
121                    <textarea
122                        class="form-control"
123                        rows="3"
124                        placeholder="${this._escapeAttribute(this._snippet("placeholder"))}"
125                        data-b2b-quote-manage-line-items-history-comment
126                        ${t?"":"disabled"}
127                    ></textarea>
128                    ${t?this._renderMessageActions("quote-manage-line-items-modal__history-cancel","data-b2b-quote-manage-line-items-history-cancel","quote-manage-line-items-modal__history-send","data-b2b-quote-manage-line-items-history-send",!0):""}
129                </div>
130            </div>
131        `}_renderHistoryEntryThread(t,e,i){let s=this._renderHistoryEntry(t,e,i,!1),r=this._normalizeHistoryChildren(t.children).filter(t=>""!==this._getHistoryCommentText(t)).map(t=>this._renderReplyEntry(t,e,i)).join("");return`${s}${r}${this._renderReplyComposer()}`}_renderHistoryEntry(t,e,i,s,r){let o=r?this._getCommentText(r):this._getHistoryCommentText(t),n=r?.id||this._getHistoryCommentId(t),a=this._getHistoryEntryActorName(t,r),l=r?.createdAt||t.createdAt||"",d=this._formatDate(l),h=this._isHistoryEditable(),y=h&&n?this._buildMessageUrl(this.options.editMessageUrlTemplate,n):"",m=h&&n?this._buildMessageUrl(this.options.removeMessageUrlTemplate,n):"",_=o?[this._getHistoryBadge(t,e,!1)]:this._getHistoryBadges(t,e,!1),c=!s&&t.id&&t.id===i?" quote-manage-line-items-modal__history-entry--highlighted":"",u=s?" quote-manage-line-items-modal__history-entry--reply":"",p=this._isCurrentCustomerComment(t,r),g=t.createdById,H=h&&p&&""!==o&&!t.sentAt&&""!==n,b=h&&!s&&!g,I=H&&""!==m,E=this._isUnreadHistoryRecord(t),L=E?'<span class="position-absolute top-0 start-100 translate-middle p-1 bg-danger border border-light rounded-circle quote-manage-line-items-modal__history-entry-unread-badge" aria-hidden="true"></span>':"";return _.map(e=>`
132            <article
133                class="quote-manage-line-items-modal__history-entry position-relative${u}${c}"
134                data-b2b-quote-manage-line-items-history-entry
135                data-line-item-history-id="${this._escapeAttribute(t.id||"")}"
136                ${n?`data-comment-id="${this._escapeAttribute(n)}"`:""}
137                ${y?`data-edit-url="${this._escapeAttribute(y)}"`:""}
138                ${m?`data-remove-url="${this._escapeAttribute(m)}"`:""}
139                ${E?"data-unread":""}
140            >
141                ${L}
142                <div class="quote-manage-line-items-modal__history-entry-meta">
143                    <div class="quote-manage-line-items-modal__history-entry-author">
144                        <span class="quote-manage-line-items-modal__history-entry-avatar" aria-hidden="true">${this._escapeHtml(this._getInitials(a))}</span>
145                        <span class="quote-manage-line-items-modal__history-entry-actor">${this._escapeHtml(a)}</span>
146                    </div>
147                    ${d?`<span class="quote-manage-line-items-modal__history-entry-timestamp">${this._escapeHtml(d)}</span>`:""}
148                </div>
149                ${o?this._renderCommentBody(o,H):this._renderBadge("quote-manage-line-items-modal__history-entry-badge",e)}
150                ${o||!g?this._renderHistoryEntryActions(H,b,I,{lineItemHistoryId:t.id||"",lineItemId:this._getHistoryLineItemId(t),removeUrl:m,versionId:this._getDraftVersionId()}):""}
151            </article>
152        `).join("")}_renderReplyEntry(t,e,i){return`
153            <div class="quote-manage-line-items-modal__history-entry-reply-item">
154                ${this._renderReplyMarker()}
155                ${this._renderHistoryEntry(t,e,i,!0)}
156            </div>
157        `}_renderCommentBody(t,e){return`
158            <div class="quote-manage-line-items-modal__history-entry-body">${this._escapeHtml(t)}
158</div>
159            ${e?`
160                <div class="quote-manage-line-items-modal__history-entry-edit" data-b2b-quote-manage-line-items-history-entry-edit hidden>
161                    <div class="quote-manage-line-items-modal__history-entry-edit-field">
162                        <textarea
163                            class="form-control"
164                            rows="4"
165                            data-b2b-quote-manage-line-items-history-entry-edit-input
166                        >${this._escapeHtml(t)}</textarea>
167                        ${this._renderMessageActions("quote-manage-line-items-modal__history-entry-edit-cancel","data-b2b-quote-manage-line-items-history-entry-edit-cancel","quote-manage-line-items-modal__history-entry-edit-send","data-b2b-quote-manage-line-items-history-entry-edit-send",!1,"save")}
168                    </div>
169                </div>
170            `:""}
171        `}_renderHistoryEntryActions(t,e){let i=arguments.length>2&&void 0!==arguments[2]&&arguments[2],s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;return this._isHistoryEditable()&&(t||e||i)?`
172            <div class="quote-manage-line-items-modal__history-entry-actions">
173                ${t?`<button type="button" class="btn btn-link quote-manage-line-items-modal__history-entry-action is-edit" aria-expanded="false">${this._escapeHtml(this._snippet("editLabel"))}</button>`:""}
174                ${e?`<button type="button" class="btn btn-link quote-manage-line-items-modal__history-entry-action is-reply" aria-expanded="false">${this._escapeHtml(this._snippet("replyLabel"))}</button>`:""}
175                ${i?`
176                    <button
177                        type="button"
178                        class="btn btn-link quote-manage-line-items-modal__history-entry-action is-delete"
179                        data-b2b-quote-trigger-confirm-modal
180                        data-b2b-quote-trigger-confirm-modal-options="${this._escapeAttribute(this._getHistoryEntryRemoveConfirmOptions(s))}"
181                        aria-label="${this._escapeAttribute(this._snippet("deleteLabel"))}"
182                        title="${this._escapeAttribute(this._snippet("deleteLabel"))}"
183                    >${this._renderTrashIcon()}</button>
184                `:""}
185            </div>
186        `:""}_getHistoryEntryRemoveConfirmOptions(t){return JSON.stringify({actions:{confirm:this.options.events.historyEntryRemoveConfirmed},cancelLabel:this._snippet("cancelLabel"),closeLabel:this._snippet("closeLabel"),confirmButtonClass:"btn-danger",confirmLabel:this._snippet("deleteLabel"),context:t||{},message:this._snippet("deleteCommentConfirm"),modalClass:"quote-confirm-modal",title:this._snippet("deleteCommentTitle")})}_renderTrashIcon(){return`
187            <span class="icon icon-trash-s" aria-hidden="true">
188                <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
189                    <path fill-rule="evenodd" clip-rule="evenodd" d="M9 15V16C9 16.5523 9.44772 17 10 17C10.5523 17 11 16.5523 11 16V15C11 14.4477 10.5523 14 10 14C9.44772 14 9 14.4477 9 15ZM13 15V16C13 16.5523 13.4477 17 14 17C14.5523 17 15 16.5523 15 16V15C15 14.4477 14.5523 14 14 14C13.4477 14 13 14.4477 13 15ZM8 7V6C8 4.89543 8.89543 4 10 4H14C15.1046 4 16 4.89543 16 6V7H17C18.1046 7 19 7.89543 19 9C19 9.55228 18.5523 10 18 10H6C5.44772 10 5 9.55228 5 9C5 7.89543 5.89543 7 7 7H8ZM6 11H18V18C18 19.1046 17.1046 20 16 20H8C6.89543 20 6 19.1046 6 18V11ZM10 7H14V6H10V7Z" fill="currentColor"/>
190                </svg>
191            </span>
192        `}_renderReplyMarker(){return`
193            <span class="quote-manage-line-items-modal__history-entry-reply-marker" aria-hidden="true">
194                <span class="icon icon-reply" aria-hidden="true">
195                    <svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
196                        <path fill-rule="evenodd" clip-rule="evenodd" d="M7.91912 8.66667H4.33333C1.9401 8.66667 0 6.72657 0 4.33333V1C0 0.447715 0.447715 0 1 0C1.55228 0 2 0.447715 2 1V4.33333C2 5.622 3.04467 6.66667 4.33333 6.66667H7.91912L6.95956 5.70711C6.56904 5.31658 6.56904 4.68342 6.95956 4.29289C7.35008 3.90237 7.98325 3.90237 8.37377 4.29289L11.0404 6.95956C11.431 7.35008 11.431 7.98325 11.0404 8.37377L8.37377 11.0404C7.98325 11.431 7.35008 11.431 6.95956 11.0404C6.56904 10.6499 6.56904 10.0168 6.95956 9.62623L7.91912 8.66667V8.66667Z" fill="currentColor"/>
197                    </svg>
198                </span>
199            </span>
200        `}_renderReplyComposer(){return this._isHistoryEditable()?`
201            <div class="quote-manage-line-items-modal__history-entry-reply" data-b2b-quote-manage-line-items-history-entry-reply hidden>
202                ${this._renderReplyMarker()}
203                <span class="quote-manage-line-items-modal__history-composer-avatar" aria-hidden="true">${this._escapeHtml(this._getComposerInitials())}</span>
204                <div class="quote-manage-line-items-modal__history-entry-reply-field">
205                    <textarea
206                        class="form-control"
207                        rows="3"
208                        placeholder="${this._escapeAttribute(this._snippet("placeholder"))}"
209                        data-b2b-quote-manage-line-items-history-entry-reply-input
210                    ></textarea>
211                    ${this._renderMessageActions("quote-manage-line-items-modal__history-entry-reply-cancel","data-b2b-quote-manage-line-items-history-entry-reply-cancel","quote-manage-line-items-modal__history-entry-reply-send","data-b2b-quote-manage-line-items-history-entry-reply-send",!0)}
212                </div>
213            </div>
214        `:""}_renderMessageActions(t,e,i,s){let r=arguments.length>4&&void 0!==arguments[4]&&arguments[4],o=arguments.length>5&&void 0!==arguments[5]?arguments[5]:"send";return`
215            <div class="quote-manage-line-items-modal__history-message-actions">
216                <button
217                    type="button"
218                    class="btn btn-link ${t}"
219                    ${e}
220                >${this._escapeHtml(this._snippet("cancelLabel"))}</button>
221                <button
222                    type="button"
223                    class="btn d-inline-flex align-items-center justify-content-center gap-2 ${i}"
224                    ${s}
225                    ${r?"disabled":""}
226                >${this._renderSendButtonContent(o)}</button>
227            </div>
228        `}_renderSendButtonContent(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"send";return"save"===t?this._escapeHtml("Save"):`
229            <span class="quote-manage-line-items-modal__history-send-icon" aria-hidden="true"></span>
230            <span class="quote-manage-line-items-modal__history-send-label">${this._escapeHtml(this._snippet("sendLabel"))}</span>
231            <span class="spinner-border spinner-border-sm quote-manage-line-items-modal__history-send-spinner" aria-hidden="true"></span>
232        `}_renderBadge(t,e){let i=this._hasHistoryBadgeValue(e);return`
233            <div class="${t}">
234                <span class="${e.label&&!i?"fw-bold":"fw-normal"}">${this._escapeHtml(e.label)}${i?":":""}</span>
235                ${this._renderBadgeValue(e)}
236            </div>
237        `}_renderBadgeValue(t){return t.oldValue&&t.newValue?`
238                <strong>${this._escapeHtml(t.oldValue)}</strong>
239                <span aria-hidden="true">&rarr;</span>
240                <strong>${this._escapeHtml(t.newValue)}</strong>
241            `:t.value?`<strong>${this._escapeHtml(t.value)}</strong>`:""}_hasHistoryBadgeValue(t){return""!==t.value||""!==this._stringValue(t.oldValue)&&""!==this._stringValue(t.newValue)}_renderSidebarComment(t){return`
242            <div class="quote-manage-line-items-modal__sidebar-comment">${this._escapeHtml(t)}</div>
243        `}_shouldRenderHistoryComment(t){return null==t.changes&&""!==this._getHistoryCommentText(t)}_getDeletedLineItemHistory(t){let e=this._normalizeHistoryRecordsFromLineItem(t).filter(t=>"delete"===t.action||""!==this._stringValue(t.changes?.new?.deletedAt));return 0===e.length?null:e.reduce((t,e)=>{let i=this._getHistoryTimestamp(t)||0;return(this._getHistoryTimestamp(e)||0)>i?e:t},e[0])}_getHistoryBadge(t,e,i){return this._getHistoryBadges(t,e,i)[0]}_getHistoryBadges(t,e,i){let s=t.changes?.new?.priceDefinition||null,r=t.changes?.old?.priceDefinition||null,o=this._stringValue(s?.quantity),n=this._stringValue(r?.quantity),a=this._stringValue(t.changes?.new?.requestedPrice),l=this._stringValue(t.changes?.old?.requestedPrice),d=this._stringValue(s?.price),h=this._stringValue(r?.price),y=this._stringValue(s?.taxRules?.[0]?.taxRate),m=this._stringValue(r?.taxRules?.[0]?.taxRate),_=this._hasHistoryValueChanged(o,n,!0),c=this._hasHistoryValueChanged(a,l,!0),u=this._hasHistoryValueChanged(d,h),p=this._hasHistoryValueChanged(y,m);if("delete"===t.action||e.deletedAt)return[{label:this._snippet("deleted"),value:""}];if("add"===t.action||i)return[{label:this._snippet("addedToQuote"),value:""}];let g=[];if(_){let t=""!==n&&_&&this._snippet("amount")||this._snippet("requestedAmount");g.push(this._createHistoryBadge(t,o,n))}return(c&&g.push(this._createHistoryBadge(this._getHistoryPriceLabel(t),this._formatHistoryPrice(a),""!==l?this._formatHistoryPrice(l):"")),u&&g.push(this._createHistoryBadge(this._snippet("quotedPrice"),this._formatHistoryPrice(d),""!==h?this._formatHistoryPrice(h):"")),p&&g.push(this._createHistoryBadge(this._snippet("requestedTax"),this._formatHistoryTax(y),""!==m?this._formatHistoryTax(m):"")),g.length>0)?g:[{label:this._snippet("changed"),value:this._snippet("notAvailable")}]}_hasHistoryValueChanged(t,e){let i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return""!==t&&(""===e?i:e!==t)}_getHistoryPriceLabel(t){return this._isMerchantHistoryRecord(t)&&this._snippet("quotedPrice")||this._snippet("requestedPrice")}_isMerchantHistoryRecord(t){return!!this._stringValue(t.createdById)||!t.customer&&!t.employee&&""===this._stringValue(t.customerId)&&""===this._stringValue(t.employeeId)}_createHistoryBadge(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"";return""!==e&&""!==i&&i!==e?{label:t,oldValue:i,newValue:e,value:""}:{label:t,value:e}}_formatHistoryPrice(t){let e=this._stringValue(t),i=this._historyCurrencySymbol;return!e||!i||e.startsWith(i)?e:`${i}${e}`}_formatHistoryTax(t){let e=this._stringValue(t);return e?`${e} %`:""}_isOldestHistoryForLineItem(t){let e=this._getHistoryLineItemId(t),i=(t.id||"").trim();if(!e||!i)return!1;let s=this._getDetailHistoriesForLineItem(e),r=s.length>0?s:this._getHistoriesForLineItem(e);return r.length<=1||(r.reduce((t,e)=>{let i=this._getHistoryTimestamp(t),s=this._getHistoryTimestamp(e);return null===s?t:null===i||s<i?e:t},r[r.length-1]).id||"").trim()===i}_getHistoryTimestamp(t){if(!t.createdAt)return null;let e=new Date(t.createdAt).getTime();return Number.isNaN(e)?null:e}_getLineItemLabel(t){return this._stringValue(t.label)||this._stringValue(t.payload?.productNumber)||this._snippet("notAvailable")}_getLineItemSpecification(t){let e=t.payload||{},i=[],s=this._stringValue(e.productNumber),r=this._normalizeUnknownList(e.options).map(t=>{if(!this._isRecord(t))return"";let e=this._stringValue(t.group),i=this._stringValue(t.option||t.name);return e&&i?`${e}: ${i}`:i}).filter(t=>""!==t);if(s&&i.push(s),r.length>0&&i.push(r.join(", ")),i.length>0)return i.join(" | ");
243let o=this._stringValue(t.description);return o!==this._getLineItemLabel(t)?o:""}_getLineItemImage(t,e,i){let s=this._stringValue(t.cover?.url);return s?`
244            <div class="${i}">
245                <img src="${this._escapeAttribute(s)}" alt="${this._escapeAttribute(e)}" loading="lazy">
246            </div>
247        `:`
248                <div class="${i}">
249                    <span class="${i}-placeholder" aria-hidden="true"></span>
250                </div>
251            `}_getActorName(t){return this._getPreferredActorName(t)||this._snippet("merchant")}_getHistoryEntryActorName(t,e){if(e)return this._getActorName(e);let i=t.comment;if(this._shouldRenderHistoryComment(t)&&i){let t=this._getPreferredActorName(i);if(t)return t}return this._getActorName(t)}_getSidebarActorName(t){let e=t.comment;if(this._shouldRenderHistoryComment(t)&&e){let t=this._getPreferredActorName(e);if(t)return t}return this._getActorName(t)}_getPreferredActorName(t){return t.employee?this._getPersonName(t.employee)||this._snippet("merchant"):t.customer?this._getPersonName(t.customer)||this._snippet("merchant"):""}_getPersonName(t){return`${this._stringValue(t.firstName)} ${this._stringValue(t.lastName)}`.trim()}_getInitials(t){return t.trim().split(/\s+/).filter(t=>""!==t).slice(0,2).map(t=>t[0]).join("").toUpperCase()||t.trim().slice(0,2).toUpperCase()}_getComposerInitials(){return this._stringValue(this.options.shortcutCurrentCustomer)||this._getInitials(this._snippet("customer"))}_getHistoryCommentText(t){return this._getCommentText(t.comment||void 0)}_getCommentText(t){return this._stringValue(t?.comment).trim()}_getHistoryCommentId(t){return(t.comment?.id||t.commentId||"").trim()}_isCurrentCustomerComment(t,e){let i=this._stringValue(this.options.currentCustomerId);if(!i)return!1;let s=e||t.comment,r=this._stringValue(s?.customerId||(e?"":t.customerId));return(this._stringValue(s?.employeeId||(e?"":t.employeeId))||r)===i}_isUnreadHistoryRecord(t){return null===t.seenAt&&null!==t.createdById}_normalizeHistoryChildren(t){return this._normalizeCollectionElements(t)}_buildMessageUrl(t,e){return(t||"").replace("__commentId__",encodeURIComponent(e))}_formatDate(t){if(!t)return"";let e=new Date(t);return Number.isNaN(e.getTime())?"":new Intl.DateTimeFormat(document.documentElement.lang||navigator.language,{dateStyle:"short",timeStyle:"short"}).format(e)}_snippet(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=this.options.historySnippets,s=this._stringValue(i?.[t]);return Object.entries(e).forEach(t=>{let[e,i]=t;s=s.split(`%${e}%`).join(`${i}`)}),s}_normalizeUnknownList(t){return t?Array.isArray(t)?t:this._isRecord(t)?Object.keys(t).map(e=>t[e]):[]:[]}_isRecord(t){return"object"==typeof t&&null!==t}_stringValue(t){return null==t?"":`${t}`.trim()}_escapeHtml(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}_escapeAttribute(t){return this._escapeHtml(t)}_updateHistoryMarkup(t){t()}_openSelectedHistoryDetail(){this._selectedRowId&&this._openApiDetail(this._selectedRowId,this._selectedHistoryId)}async _openApiDetail(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,i=`${t}:${e||""}`;if(this._apiDetailOpenPromise&&this._apiDetailOpenKey===i){await this._apiDetailOpenPromise;return}let s=this._openApiDetailInternal(t,e);this._apiDetailOpenKey=i,this._apiDetailOpenPromise=s;try{await s}finally{this._apiDetailOpenPromise===s&&(this._apiDetailOpenKey=null,this._apiDetailOpenPromise=null)}}async _openApiDetailInternal(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;this._selectedRowId=t,this._selectedHistoryId=e,this._selectedDetailSource="api",this._rows.forEach(e=>{e.element.classList.toggle("quote-manage-line-items-modal__row--selected",e.id===t)}),this._sidebarElement?.classList.add("quote-manage-line-items-modal__sidebar--detail-open"),this._updateHistoryMarkup(()=>{this._apiHistoryDetail?.classList.remove("d-none"),this._historyOverview?.classList.add("d-none"),this._historyListItems?.classList.add("d-none"),this._hideRenderedHistoryPanels()}
251),this._renderDetailLoading(),this._resetDetailHistoryCache(),await this._ensureAllDetailHistoryLoaded(),this._isActiveInstance()&&this._selectedRowId===t&&"api"===this._selectedDetailSource&&(this._selectedHistoryId=e,this._renderHistoryState(),this._requestHistoryReadCollection(),this._renderHistoryDetail(t,e),this._focusHistoryCommentIfRequested(this._apiHistoryDetail||null))}_focusHistoryCommentIfRequested(t){if(!this._shouldFocusHistoryComment||!t)return;this._shouldFocusHistoryComment=!1;let e=()=>{let e=t.querySelector(this.options.selectors.historyCommentInput);e&&!e.disabled&&(e.focus(),e.scrollIntoView({block:"center",behavior:"smooth"}))};window.requestAnimationFrame(()=>{e(),window.setTimeout(e,150)})}_hasOpenDetail(){return null!==this._selectedRowId||null!==this._selectedHistoryId||null!==this._selectedDetailSource||this._sidebarElement?.classList.contains("quote-manage-line-items-modal__sidebar--detail-open")===!0||this._apiHistoryDetail?.classList.contains("d-none")===!1}_clearDetail(){this._hasOpenDetail()&&(this._selectedRowId=null,this._selectedHistoryId=null,this._selectedDetailSource=null,this._rows.forEach(t=>{t.element.classList.remove("quote-manage-line-items-modal__row--selected")}),this._updateHistoryMarkup(()=>{this._sidebarElement?.classList.remove("quote-manage-line-items-modal__sidebar--detail-open"),this._apiHistoryDetail?.classList.add("d-none"),this._historyOverview?.classList.remove("d-none"),this._historyListItems?.classList.remove("d-none"),this._apiHistoryDetail&&(this._apiHistoryDetail.innerHTML=""),this._hideRenderedHistoryPanels()}),this._renderHistoryState())}_syncRenderedHistoryControls(){let t=this._isHistoryEditable();this._modalElement?.querySelectorAll(".quote-manage-line-items-modal__history-message-actions, .quote-manage-line-items-modal__history-entry-actions").forEach(e=>{e.classList.toggle("d-none",!t)}),this._modalElement?.querySelectorAll([this.options.selectors.historyCommentInput,this.options.selectors.historyEntryReplyInput,this.options.selectors.historyEntryEditInput].join(", ")).forEac
251h(e=>{e.disabled=!t}),t&&(this._modalElement?.querySelectorAll(this.options.selectors.historyCommentInput).forEach(t=>this._syncHistoryComposerActions(t)),this._modalElement?.querySelectorAll(this.options.selectors.historyEntryReply).forEach(t=>this._syncHistoryEntryReplySendButton(t)),this._modalElement?.querySelectorAll(this.options.selectors.historyEntry).forEach(t=>this._syncHistoryEntryEditSendButton(t)),this._initializeRenderedHistoryPlugins())}_initializeRenderedHistoryPlugins(){this._apiHistoryDetail&&void 0!==window.PluginManager&&window.PluginManager.initializePluginsInParentElement(this._apiHistoryDetail)}_scrollHistoryEntryIntoView(t){t&&this._apiHistoryDetail&&window.requestAnimationFrame(()=>{let e=window.CSS?.escape?CSS.escape(t):t.replace(/"/g,'\\"'),i=this._apiHistoryDetail?.querySelector(`[data-b2b-quote-manage-line-items-history-entry][data-line-item-history-id="${e}"]`);i?.scrollIntoView({block:"center",behavior:"smooth"}),this._requestHistoryReadCollection()})}_requestHistoryReadCollection(){this.el.dispatchEvent(new CustomEvent(this.options.events.historyReadCollectRequested,{bubbles:!0}))}}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.