/* COPYRIGHT Esri - https://js.arcgis.com/1.2/LICENSE.txt */
import b from"./EZAL5KYF.js";import a from"./HBC3TKGZ.js";import{b as be}from"./W4YXXJAS.js";import{b as xe}from"./S7VQX4XX.js";import"./4Q4PZB7R.js";import{a as me}from"./XN2LWKJE.js";import"./4BPRM7CL.js";import"./NIL6NWG5.js";import"./ED6SUP22.js";import"./E6P6PYNW.js";import"./IKKBLHLZ.js";import"./CUA2IUXX.js";import"./4UZDZNJD.js";import"./KOTG6W5Z.js";import"./6SC7YR5Y.js";import"./Z6NOHRUL.js";import"./GVM4XYEI.js";import"./NGDVSE4Z.js";import"./BTNJZZQQ.js";import"./ZYQ4P2ON.js";import"./5MKH4QDV.js";import"./3GWWHA4S.js";import"./3YYHZQJB.js";import"./JEJ23R3P.js";import"./TONS7KZJ.js";import"./Q62UEPOL.js";import"./44A5XEM4.js";import{b as ke}from"./ODCCVHGI.js";import{G as Z,H as ge,J as fe,L as j,h as le,i as k,k as ce,l as H,m as R,r as he,w as ue,x as pe,y as de}from"./42WFQ3AX.js";import"./3QPJ2JCA.js";export default $arcgis.t(([{n:we},{r:_e}])=>{var A=class extends de{constructor(e){if(super(e),this.it=H,e.type!==ue.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(e){if(e===H||e==null)return this._t=void 0,this.it=e;if(e===ce)return e;if(typeof e!="string")throw Error(this.constructor.directiveName+"() called with a non-string value");if(e===this.it)return this._t;this.it=e;let t=[e];return t.raw=t,this._t={_$litType$:this.constructor.resultType,strings:t,values:[]}}};A.directiveName="unsafeHTML",A.resultType=1;var G=pe(A);var Fe=le`:host {
  display: block;
  height: 100%;
}

.display-flex-row {
  display: flex;
  flex-direction: row;
}

.padding-left-10 {
  padding-left: 10px;
}

.chat-container {
  display: flex;
  flex-direction: column;
  gap: 0px;
  max-width: 600px;
  height: 75%;
  background-color: var(--calcite-color-foreground-3);
  padding: 1px;
}

.chat-container_expanded {
  display: flex;
  flex-direction: column;
  gap: 0px;
  max-width: 100%;
  height: 95%;
  background-color: var(--calcite-color-background);
  border-radius: 10px;
  padding: 10px;
}

.chat-panel {
  --calcite-dialog-header-background-color: var(--calcite-color-brand);
  --calcite-dialog-header-action-background-color: var(--calcite-color-brand);
  --calcite-dialog-heading-text-color: var(--calcite-color-background);
  --calcite-dialog-header-action-text-color: var(--calcite-color-background);
  --calcite-dialog-header-action-text-color-press: var(--calcite-color-background);
  --calcite-dialog-min-size-y: 90vh;
  --calcite-dialog-max-size-y: 90vh;
}

.chat-panel-heading {
  font-size: var(--calcite-font-size-0);
  font-weight: var(--calcite-font-weight-medium);
  color: var(--calcite-color-background, var(--calcite-color-text-1));
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 4px;
  height: 100%;
  overflow-y: auto;
}

.user-message {
  align-self: flex-end;
  background: var(--calcite-color-brand);
  border-radius: 8px;
  max-width: 90%;
  --calcite-card-corner-radius: 8px;
  --calcite-card-background-color: var(--calcite-color-brand);
  --calcite-card-border-color: var(--calcite-color-brand);
  color: var(--calcite-color-background);
  text-align: left;
}

.system-message {
  align-self: flex-start;
  background: var(--calcite-color-foreground-2);
  border-radius: 8px;
  max-width: 90%;
  --calcite-card-corner-radius: 8px;
  --calcite-card-background-color: var(--calcite-color-foreground-3);
  --calcite-card-border-color: var(--calcite-color-foreground-3);
  text-align: left;
}

.loader-message {
  align-self: flex-start;
  background: var(--calcite-color-foreground-3);
  border-radius: 8px;
  --calcite-card-corner-radius: 8px;
  --calcite-card-background-color: var(--calcite-color-foreground-3);
  --calcite-card-border-color: var(--calcite-color-foreground-3);
}

.message-content {
  padding: 0px;
  font-size: 14px;
}

.message-content p:first-child {
  margin-top: 0px;
}

.message-content img {
  max-width: 100%;
  height: auto;
  display: block;
  object-fit: contain;
}

.message-content-pad {
  padding-bottom: 10px;
  font-size: 14px;
}

.message-content-summary {
  padding-bottom: 14px;
}

.message-content-alignment {
  display: flex;
  align-items: center; /* Vertically centers icon and text */
  gap: var(--calcite-spacing-md); /* Uses Calcite spacing token */
  font-size: var(--calcite-font-size--1); /* Matches Calcite text size */
  color: var(--calcite-color-text-1); /* Calcite text color */
}

.padding-top-10 {
  padding-top: 10px;
}

.padding-right-8 {
  padding-right: 8px;
}

.padding-left-right-5 {
  padding-right: 5px;
  padding-left: 5px;
}

.chip-content {
  padding-top: 5px;
  padding-bottom: 5px;
  padding-right: 5px;
  padding-left: 0px;
}

.chat-input {
  display: flex;
  flex-direction: row;
  flex-grow: 1;
}

.table-cell {
  --calcite-table-cell-background: var(--calcite-color-foreground-3);
}

.cursor-pointer {
  cursor: pointer;
}

.notice-border-color {
  --temp-initial-brand: var(--calcite-color-brand);
}

.notice-border-color calcite-notice {
  --calcite-color-brand: #ddd;
  --calcite-icon-color: var(--temp-initial-brand);
}

.notice-border-color calcite-notice * {
  --calcite-color-brand: var(--temp-initial-brand);
}

.solution-card {
  padding: 5px 0px 5px 0px;
  text-decoration: none;
  display: block;
  width: 100%;
  cursor: pointer;
}

.solution-card calcite-card {
  display: flex;
  flex-direction: column;
  max-width: 520px;
  overflow: hidden;  /* Hide overflow content */
  --calcite-card-corner-radius: var(--calcite-corner-radius-round) !important;
  --calcite-card-shadow: var(--calcite-shadow-sm);
  --calcite-card-background-color: var(--calcite-card-background-color)
}

.solution-card div[slot="thumbnail"] {
  max-height: 100%;
  width: 100%;
  position: relative;

  &:after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transition: all 0.15s ease-in-out;
  }
}

.solution-card div[slot="thumbnail"] img {
  max-height: 100%;
  width: 100%;
  object-fit: cover;
}

.solution-card span[slot="description"] {
  padding-top: 10px;
}

.solution-card calcite-chip {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  visibility: hidden;
  pointer-events: none;
  opacity: 0;
  transition: all 0.15s ease-in-out;
  z-index: 9999;
}

.solution-card:hover calcite-chip {
  visibility: visible;
  opacity: 1;
}

.solution-card:hover div[slot="thumbnail"]:after {
  background-color: rgba(0, 0, 0, 0.5);
}

.solution-card:hover h3 {
  text-decoration: underline;
}

.references-container {
  padding-top: 10px;
  display: block;
}

.references-container.collapsed {
  display: none;
}

.width-100 {
  width: 100%;
}

.disclaimer-div {
  display: flex;
  gap: var(--calcite-spacing-sm); /* Uses Calcite spacing token */
  font-size: var(--calcite-font-size--0); /* Matches Calcite text size */
  color: var(--calcite-color-text-1); /* Calcite text color */
}

.display-none {
  display: none;
}

.chat-messages calcite-fab {
  position: absolute;
  bottom: 16px; /* adjust as needed */
  left: 50%;
  transform: translateX(-50%);
  z-index: 999; /* ensures it stays on top of other elements */
}

.icon-color-background {
  --calcite-button-icon-color: var(--calcite-color-background);
}

/* Hide snippet on very small screens */
@media (max-width: 430px) {
  .solution-card .solution-snippet {
    display: none;
  }
}
`,De="https://www.arcgis.com/sharing/rest/content/items/";async function Oe(n){return await He(n)}async function He(n){let e=De+n+"?f=json";try{let t=await fetch(e,{method:"GET"});if(!t.ok)throw new Error(`HTTP error! Status: ${t.status}`);return await t.json()}catch(t){return{error:t.message}}}function V(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var C=V();function Ie(n){C=n}var E={exec:()=>null};function d(n,e=""){let t=typeof n=="string"?n:n.source,i={replace:(s,a)=>{let r=typeof a=="string"?a:a.source;return r=r.replace(b.caret,"$1"),t=t.replace(s,r),i},getRegex:()=>new RegExp(t,e)};return i}var Ze=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),b={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:n=>new RegExp(`^( {0,3}${n})((?:[	 ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:n=>new RegExp(`^ {0,${Math.min(3,n-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ 	][^\\n]*)?(?:\\n|$))`),hrRegex:n=>new RegExp(`^ {0,${Math.min(3,n-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:n=>new RegExp(`^ {0,${Math.min(3,n-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:n=>new RegExp(`^ {0,${Math.min(3,n-1)}}#`),htmlBeginRegex:n=>new RegExp(`^ {0,${Math.min(3,n-1)}}<(?:[a-z].*>|!--)`,"i")},je=/^(?:[ \t]*(?:\n|$))+/,Ge=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Ke=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,P=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,We=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,ee=/(?:[*+-]|\d{1,9}[.)])/,Ce=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Ae=d(Ce).replace(/bull/g,ee).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),Xe=d(Ce).replace(/bull/g,ee).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),te=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Je=/^[^\n]+/,se=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,Ye=d(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",se).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Ve=d(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,ee).getRegex(),D="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",ne=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,et=d("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ 	]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ 	]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ 	]*)+\\n|$))","i").replace("comment",ne).replace("tag",D).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),ze=d(te).replace("hr",P).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",D).getRegex(),tt=d(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",ze).getRegex(),ie={blockquote:tt,code:Ge,def:Ye,fences:Ke,heading:We,hr:P,html:et,lheading:Ae,list:Ve,newline:je,paragraph:ze,table:E,text:Je},ye=d("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",P).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3}	)[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",D).getRegex(),st={...ie,lheading:Xe,table:ye,paragraph:d(te).replace("hr",P).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",ye).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",D).getRegex()},nt={...ie,html:d(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",ne).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:E,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:d(te).replace("hr",P).replace("heading",` *#{1,6} *[^
]`).replace("lheading",Ae).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},it=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,rt=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,Le=/^( {2,}|\\)\n(?!\s*$)/,at=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,O=/[\p{P}\p{S}]/u,re=/[\s\p{P}\p{S}]/u,qe=/[^\s\p{P}\p{S}]/u,ot=d(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,re).getRegex(),Ee=/(?!~)[\p{P}\p{S}]/u,lt=/(?!~)[\s\p{P}\p{S}]/u,ct=/(?:[^\s\p{P}\p{S}]|~)/u,ht=d(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",Ze?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),Pe=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,ut=d(Pe,"u").replace(/punct/g,O).getRegex(),pt=d(Pe,"u").replace(/punct/g,Ee).getRegex(),Be="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",dt=d(Be,"gu").replace(/notPunctSpace/g,qe).replace(/punctSpace/g,re).replace(/punct/g,O).getRegex(),gt=d(Be,"gu").replace(/notPunctSpace/g,ct).replace(/punctSpace/g,lt).replace(/punct/g,Ee).getRegex(),ft=d("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,qe).replace(/punctSpace/g,re).replace(/punct/g,O).getRegex(),kt=d(/\\(punct)/,"gu").replace(/punct/g,O).getRegex(),mt=d(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),xt=d(ne).replace("(?:-->|$)","-->").getRegex(),bt=d("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",xt).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),U=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/,wt=d(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",U).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Me=d(/^!?\[(label)\]\[(ref)\]/).replace("label",U).replace("ref",se).getRegex(),Ne=d(/^!?\[(ref)\](?:\[\])?/).replace("ref",se).getRegex(),_t=d("reflink|nolink(?!\\()","g").replace("reflink",Me).replace("nolink",Ne).getRegex(),ve=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,ae={_backpedal:E,anyPunctuation:kt,autolink:mt,blockSkip:ht,br:Le,code:rt,del:E,emStrongLDelim:ut,emStrongRDelimAst:dt,emStrongRDelimUnd:ft,escape:it,link:wt,nolink:Ne,punctuation:ot,reflink:Me,reflinkSearch:_t,tag:bt,text:at,url:E},yt={...ae,link:d(/^!?\[(label)\]\((.*?)\)/).replace("label",U).getRegex(),reflink:d(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",U).getRegex()},K={...ae,emStrongRDelimAst:gt,emStrongLDelim:pt,url:d(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",ve).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:d(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",ve).getRegex()},vt={...K,br:d(Le).replace("{2,}","*").getRegex(),text:d(K.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},N={normal:ie,gfm:st,pedantic:nt},z={normal:ae,gfm:K,breaks:vt,pedantic:yt},St={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Se=n=>St[n];function T(n,e){if(e){if(b.escapeTest.test(n))return n.replace(b.escapeReplace,Se)}else if(b.escapeTestNoEncode.test(n))return n.replace(b.escapeReplaceNoEncode,Se);return n}function Te(n){try{n=encodeURI(n).replace(b.percentDecode,"%")}catch{return null}return n}function $e(n,e){let t=n.replace(b.findPipe,(a,r,l)=>{let o=!1,h=r;for(;--h>=0&&l[h]==="\\";)o=!o;return o?"|":" |"}),i=t.split(b.splitPipe),s=0;if(i[0].trim()||i.shift(),i.length>0&&!i.at(-1)?.trim()&&i.pop(),e)if(i.length>e)i.splice(e);else for(;i.length<e;)i.push("");for(;s<i.length;s++)i[s]=i[s].trim().replace(b.slashPipe,"|");return i}function L(n,e,t){let i=n.length;if(i===0)return"";let s=0;for(;s<i&&n.charAt(i-s-1)===e;)s++;return n.slice(0,i-s)}function Tt(n,e){if(n.indexOf(e[1])===-1)return-1;let t=0;for(let i=0;i<n.length;i++)if(n[i]==="\\")i++;else if(n[i]===e[0])t++;else if(n[i]===e[1]&&(t--,t<0))return i;return t>0?-2:-1}function Re(n,e,t,i,s){let a=e.href,r=e.title||null,l=n[1].replace(s.other.outputLinkReplace,"$1");i.state.inLink=!0;let o={type:n[0].charAt(0)==="!"?"image":"link",raw:t,href:a,title:r,text:l,tokens:i.inlineTokens(l)};return i.state.inLink=!1,o}function $t(n,e,t){let i=n.match(t.other.indentCodeCompensation);if(i===null)return e;let s=i[1];return e.split(`
`).map(a=>{let r=a.match(t.other.beginningSpace);if(r===null)return a;let[l]=r;return l.length>=s.length?a.slice(s.length):a}).join(`
`)}var Q=class{options;rules;lexer;constructor(n){this.options=n||C}space(n){let e=this.rules.block.newline.exec(n);if(e&&e[0].length>0)return{type:"space",raw:e[0]}}code(n){let e=this.rules.block.code.exec(n);if(e){let t=e[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:e[0],codeBlockStyle:"indented",text:this.options.pedantic?t:L(t,`
`)}}}fences(n){let e=this.rules.block.fences.exec(n);if(e){let t=e[0],i=$t(t,e[3]||"",this.rules);return{type:"code",raw:t,lang:e[2]?e[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):e[2],text:i}}}heading(n){let e=this.rules.block.heading.exec(n);if(e){let t=e[2].trim();if(this.rules.other.endingHash.test(t)){let i=L(t,"#");(this.options.pedantic||!i||this.rules.other.endingSpaceChar.test(i))&&(t=i.trim())}return{type:"heading",raw:e[0],depth:e[1].length,text:t,tokens:this.lexer.inline(t)}}}hr(n){let e=this.rules.block.hr.exec(n);if(e)return{type:"hr",raw:L(e[0],`
`)}}blockquote(n){let e=this.rules.block.blockquote.exec(n);if(e){let t=L(e[0],`
`).split(`
`),i="",s="",a=[];for(;t.length>0;){let r=!1,l=[],o;for(o=0;o<t.length;o++)if(this.rules.other.blockquoteStart.test(t[o]))l.push(t[o]),r=!0;else if(!r)l.push(t[o]);else break;t=t.slice(o);let h=l.join(`
`),c=h.replace(this.rules.other.blockquoteSetextReplace,`
    $1`).replace(this.rules.other.blockquoteSetextReplace2,"");i=i?`${i}
${h}`:h,s=s?`${s}
${c}`:c;let g=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(c,a,!0),this.lexer.state.top=g,t.length===0)break;let p=a.at(-1);if(p?.type==="code")break;if(p?.type==="blockquote"){let m=p,u=m.raw+`
`+t.join(`
`),w=this.blockquote(u);a[a.length-1]=w,i=i.substring(0,i.length-m.raw.length)+w.raw,s=s.substring(0,s.length-m.text.length)+w.text;break}else if(p?.type==="list"){let m=p,u=m.raw+`
`+t.join(`
`),w=this.list(u);a[a.length-1]=w,i=i.substring(0,i.length-p.raw.length)+w.raw,s=s.substring(0,s.length-m.raw.length)+w.raw,t=u.substring(a.at(-1).raw.length).split(`
`);continue}}return{type:"blockquote",raw:i,tokens:a,text:s}}}list(n){let e=this.rules.block.list.exec(n);if(e){let t=e[1].trim(),i=t.length>1,s={type:"list",raw:"",ordered:i,start:i?+t.slice(0,-1):"",loose:!1,items:[]};t=i?`\\d{1,9}\\${t.slice(-1)}`:`\\${t}`,this.options.pedantic&&(t=i?t:"[*+-]");let a=this.rules.other.listItemRegex(t),r=!1;for(;n;){let o=!1,h="",c="";if(!(e=a.exec(n))||this.rules.block.hr.test(n))break;h=e[0],n=n.substring(h.length);let g=e[2].split(`
`,1)[0].replace(this.rules.other.listReplaceTabs,w=>" ".repeat(3*w.length)),p=n.split(`
`,1)[0],m=!g.trim(),u=0;if(this.options.pedantic?(u=2,c=g.trimStart()):m?u=e[1].length+1:(u=e[2].search(this.rules.other.nonSpaceChar),u=u>4?1:u,c=g.slice(u),u+=e[1].length),m&&this.rules.other.blankLine.test(p)&&(h+=p+`
`,n=n.substring(p.length+1),o=!0),!o){let w=this.rules.other.nextBulletRegex(u),$=this.rules.other.hrRegex(u),B=this.rules.other.fencesBeginRegex(u),M=this.rules.other.headingBeginRegex(u),x=this.rules.other.htmlBeginRegex(u);for(;n;){let _=n.split(`
`,1)[0],S;if(p=_,this.options.pedantic?(p=p.replace(this.rules.other.listReplaceNesting,"  "),S=p):S=p.replace(this.rules.other.tabCharGlobal,"    "),B.test(p)||M.test(p)||x.test(p)||w.test(p)||$.test(p))break;if(S.search(this.rules.other.nonSpaceChar)>=u||!p.trim())c+=`
`+S.slice(u);else{if(m||g.replace(this.rules.other.tabCharGlobal,"    ").search(this.rules.other.nonSpaceChar)>=4||B.test(g)||M.test(g)||$.test(g))break;c+=`
`+p}!m&&!p.trim()&&(m=!0),h+=_+`
`,n=n.substring(_.length+1),g=S.slice(u)}}s.loose||(r?s.loose=!0:this.rules.other.doubleBlankLine.test(h)&&(r=!0)),s.items.push({type:"list_item",raw:h,task:!!this.options.gfm&&this.rules.other.listIsTask.test(c),loose:!1,text:c,tokens:[]}),s.raw+=h}let l=s.items.at(-1);if(l)l.raw=l.raw.trimEnd(),l.text=l.text.trimEnd();else return;s.raw=s.raw.trimEnd();for(let o of s.items){if(this.lexer.state.top=!1,o.tokens=this.lexer.blockTokens(o.text,[]),o.task){if(o.text=o.text.replace(this.rules.other.listReplaceTask,""),o.tokens[0]?.type==="text"||o.tokens[0]?.type==="paragraph"){o.tokens[0].raw=o.tokens[0].raw.replace(this.rules.other.listReplaceTask,""),o.tokens[0].text=o.tokens[0].text.replace(this.rules.other.listReplaceTask,"");for(let c=this.lexer.inlineQueue.length-1;c>=0;c--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[c].src)){this.lexer.inlineQueue[c].src=this.lexer.inlineQueue[c].src.replace(this.rules.other.listReplaceTask,"");break}}let h=this.rules.other.listTaskCheckbox.exec(o.raw);if(h){let c={type:"checkbox",raw:h[0]+" ",checked:h[0]!=="[ ]"};o.checked=c.checked,s.loose?o.tokens[0]&&["paragraph","text"].includes(o.tokens[0].type)&&"tokens"in o.tokens[0]&&o.tokens[0].tokens?(o.tokens[0].raw=c.raw+o.tokens[0].raw,o.tokens[0].text=c.raw+o.tokens[0].text,o.tokens[0].tokens.unshift(c)):o.tokens.unshift({type:"paragraph",raw:c.raw,text:c.raw,tokens:[c]}):o.tokens.unshift(c)}}if(!s.loose){let h=o.tokens.filter(g=>g.type==="space"),c=h.length>0&&h.some(g=>this.rules.other.anyLine.test(g.raw));s.loose=c}}if(s.loose)for(let o of s.items){o.loose=!0;for(let h of o.tokens)h.type==="text"&&(h.type="paragraph")}return s}}html(n){let e=this.rules.block.html.exec(n);if(e)return{type:"html",block:!0,raw:e[0],pre:e[1]==="pre"||e[1]==="script"||e[1]==="style",text:e[0]}}def(n){let e=this.rules.block.def.exec(n);if(e){let t=e[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),i=e[2]?e[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",s=e[3]?e[3].substring(1,e[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):e[3];return{type:"def",tag:t,raw:e[0],href:i,title:s}}}table(n){let e=this.rules.block.table.exec(n);if(!e||!this.rules.other.tableDelimiter.test(e[2]))return;let t=$e(e[1]),i=e[2].replace(this.rules.other.tableAlignChars,"").split("|"),s=e[3]?.trim()?e[3].replace(this.rules.other.tableRowBlankLine,"").split(`
`):[],a={type:"table",raw:e[0],header:[],align:[],rows:[]};if(t.length===i.length){for(let r of i)this.rules.other.tableAlignRight.test(r)?a.align.push("right"):this.rules.other.tableAlignCenter.test(r)?a.align.push("center"):this.rules.other.tableAlignLeft.test(r)?a.align.push("left"):a.align.push(null);for(let r=0;r<t.length;r++)a.header.push({text:t[r],tokens:this.lexer.inline(t[r]),header:!0,align:a.align[r]});for(let r of s)a.rows.push($e(r,a.header.length).map((l,o)=>({text:l,tokens:this.lexer.inline(l),header:!1,align:a.align[o]})));return a}}lheading(n){let e=this.rules.block.lheading.exec(n);if(e)return{type:"heading",raw:e[0],depth:e[2].charAt(0)==="="?1:2,text:e[1],tokens:this.lexer.inline(e[1])}}paragraph(n){let e=this.rules.block.paragraph.exec(n);if(e){let t=e[1].charAt(e[1].length-1)===`
`?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:t,tokens:this.lexer.inline(t)}}}text(n){let e=this.rules.block.text.exec(n);if(e)return{type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(n){let e=this.rules.inline.escape.exec(n);if(e)return{type:"escape",raw:e[0],text:e[1]}}tag(n){let e=this.rules.inline.tag.exec(n);if(e)return!this.lexer.state.inLink&&this.rules.other.startATag.test(e[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(e[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(e[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(e[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:e[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:e[0]}}link(n){let e=this.rules.inline.link.exec(n);if(e){let t=e[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(t)){if(!this.rules.other.endAngleBracket.test(t))return;let a=L(t.slice(0,-1),"\\");if((t.length-a.length)%2===0)return}else{let a=Tt(e[2],"()");if(a===-2)return;if(a>-1){let r=(e[0].indexOf("!")===0?5:4)+e[1].length+a;e[2]=e[2].substring(0,a),e[0]=e[0].substring(0,r).trim(),e[3]=""}}let i=e[2],s="";if(this.options.pedantic){let a=this.rules.other.pedanticHrefTitle.exec(i);a&&(i=a[1],s=a[3])}else s=e[3]?e[3].slice(1,-1):"";return i=i.trim(),this.rules.other.startAngleBracket.test(i)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(t)?i=i.slice(1):i=i.slice(1,-1)),Re(e,{href:i&&i.replace(this.rules.inline.anyPunctuation,"$1"),title:s&&s.replace(this.rules.inline.anyPunctuation,"$1")},e[0],this.lexer,this.rules)}}reflink(n,e){let t;if((t=this.rules.inline.reflink.exec(n))||(t=this.rules.inline.nolink.exec(n))){let i=(t[2]||t[1]).replace(this.rules.other.multipleSpaceGlobal," "),s=e[i.toLowerCase()];if(!s){let a=t[0].charAt(0);return{type:"text",raw:a,text:a}}return Re(t,s,t[0],this.lexer,this.rules)}}emStrong(n,e,t=""){let i=this.rules.inline.emStrongLDelim.exec(n);if(!(!i||i[3]&&t.match(this.rules.other.unicodeAlphaNumeric))&&(!(i[1]||i[2])||!t||this.rules.inline.punctuation.exec(t))){let s=[...i[0]].length-1,a,r,l=s,o=0,h=i[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(h.lastIndex=0,e=e.slice(-1*n.length+s);(i=h.exec(e))!=null;){if(a=i[1]||i[2]||i[3]||i[4]||i[5]||i[6],!a)continue;if(r=[...a].length,i[3]||i[4]){l+=r;continue}else if((i[5]||i[6])&&s%3&&!((s+r)%3)){o+=r;continue}if(l-=r,l>0)continue;r=Math.min(r,r+l+o);let c=[...i[0]][0].length,g=n.slice(0,s+i.index+c+r);if(Math.min(s,r)%2){let m=g.slice(1,-1);return{type:"em",raw:g,text:m,tokens:this.lexer.inlineTokens(m)}}let p=g.slice(2,-2);return{type:"strong",raw:g,text:p,tokens:this.lexer.inlineTokens(p)}}}}codespan(n){let e=this.rules.inline.code.exec(n);if(e){let t=e[2].replace(this.rules.other.newLineCharGlobal," "),i=this.rules.other.nonSpaceChar.test(t),s=this.rules.other.startingSpaceChar.test(t)&&this.rules.other.endingSpaceChar.test(t);return i&&s&&(t=t.substring(1,t.length-1)),{type:"codespan",raw:e[0],text:t}}}br(n){let e=this.rules.inline.br.exec(n);if(e)return{type:"br",raw:e[0]}}del(n){let e=this.rules.inline.del.exec(n);if(e)return{type:"del",raw:e[0],text:e[2],tokens:this.lexer.inlineTokens(e[2])}}autolink(n){let e=this.rules.inline.autolink.exec(n);if(e){let t,i;return e[2]==="@"?(t=e[1],i="mailto:"+t):(t=e[1],i=t),{type:"link",raw:e[0],text:t,href:i,tokens:[{type:"text",raw:t,text:t}]}}}url(n){let e;if(e=this.rules.inline.url.exec(n)){let t,i;if(e[2]==="@")t=e[0],i="mailto:"+t;else{let s;do s=e[0],e[0]=this.rules.inline._backpedal.exec(e[0])?.[0]??"";while(s!==e[0]);t=e[0],e[1]==="www."?i="http://"+e[0]:i=e[0]}return{type:"link",raw:e[0],text:t,href:i,tokens:[{type:"text",raw:t,text:t}]}}}inlineText(n){let e=this.rules.inline.text.exec(n);if(e){let t=this.lexer.state.inRawBlock;return{type:"text",raw:e[0],text:e[0],escaped:t}}}},y=class W{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||C,this.options.tokenizer=this.options.tokenizer||new Q,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let t={other:b,block:N.normal,inline:z.normal};this.options.pedantic?(t.block=N.pedantic,t.inline=z.pedantic):this.options.gfm&&(t.block=N.gfm,this.options.breaks?t.inline=z.breaks:t.inline=z.gfm),this.tokenizer.rules=t}static get rules(){return{block:N,inline:z}}static lex(e,t){return new W(t).lex(e)}static lexInline(e,t){return new W(t).inlineTokens(e)}lex(e){e=e.replace(b.carriageReturn,`
`),this.blockTokens(e,this.tokens);for(let t=0;t<this.inlineQueue.length;t++){let i=this.inlineQueue[t];this.inlineTokens(i.src,i.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[],i=!1){for(this.options.pedantic&&(e=e.replace(b.tabCharGlobal,"    ").replace(b.spaceLine,""));e;){let s;if(this.options.extensions?.block?.some(r=>(s=r.call({lexer:this},e,t))?(e=e.substring(s.raw.length),t.push(s),!0):!1))continue;if(s=this.tokenizer.space(e)){e=e.substring(s.raw.length);let r=t.at(-1);s.raw.length===1&&r!==void 0?r.raw+=`
`:t.push(s);continue}if(s=this.tokenizer.code(e)){e=e.substring(s.raw.length);let r=t.at(-1);r?.type==="paragraph"||r?.type==="text"?(r.raw+=(r.raw.endsWith(`
`)?"":`
`)+s.raw,r.text+=`
`+s.text,this.inlineQueue.at(-1).src=r.text):t.push(s);continue}if(s=this.tokenizer.fences(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.heading(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.hr(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.blockquote(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.list(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.html(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.def(e)){e=e.substring(s.raw.length);let r=t.at(-1);r?.type==="paragraph"||r?.type==="text"?(r.raw+=(r.raw.endsWith(`
`)?"":`
`)+s.raw,r.text+=`
`+s.raw,this.inlineQueue.at(-1).src=r.text):this.tokens.links[s.tag]||(this.tokens.links[s.tag]={href:s.href,title:s.title},t.push(s));continue}if(s=this.tokenizer.table(e)){e=e.substring(s.raw.length),t.push(s);continue}if(s=this.tokenizer.lheading(e)){e=e.substring(s.raw.length),t.push(s);continue}let a=e;if(this.options.extensions?.startBlock){let r=1/0,l=e.slice(1),o;this.options.extensions.startBlock.forEach(h=>{o=h.call({lexer:this},l),typeof o=="number"&&o>=0&&(r=Math.min(r,o))}),r<1/0&&r>=0&&(a=e.substring(0,r+1))}if(this.state.top&&(s=this.tokenizer.paragraph(a))){let r=t.at(-1);i&&r?.type==="paragraph"?(r.raw+=(r.raw.endsWith(`
`)?"":`
`)+s.raw,r.text+=`
`+s.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=r.text):t.push(s),i=a.length!==e.length,e=e.substring(s.raw.length);continue}if(s=this.tokenizer.text(e)){e=e.substring(s.raw.length);let r=t.at(-1);r?.type==="text"?(r.raw+=(r.raw.endsWith(`
`)?"":`
`)+s.raw,r.text+=`
`+s.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=r.text):t.push(s);continue}if(e){let r="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(r);break}else throw new Error(r)}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){let i=e,s=null;if(this.tokens.links){let o=Object.keys(this.tokens.links);if(o.length>0)for(;(s=this.tokenizer.rules.inline.reflinkSearch.exec(i))!=null;)o.includes(s[0].slice(s[0].lastIndexOf("[")+1,-1))&&(i=i.slice(0,s.index)+"["+"a".repeat(s[0].length-2)+"]"+i.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(s=this.tokenizer.rules.inline.anyPunctuation.exec(i))!=null;)i=i.slice(0,s.index)+"++"+i.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let a;for(;(s=this.tokenizer.rules.inline.blockSkip.exec(i))!=null;)a=s[2]?s[2].length:0,i=i.slice(0,s.index+a)+"["+"a".repeat(s[0].length-a-2)+"]"+i.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);i=this.options.hooks?.emStrongMask?.call({lexer:this},i)??i;let r=!1,l="";for(;e;){r||(l=""),r=!1;let o;if(this.options.extensions?.inline?.some(c=>(o=c.call({lexer:this},e,t))?(e=e.substring(o.raw.length),t.push(o),!0):!1))continue;if(o=this.tokenizer.escape(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.tag(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.link(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(o.raw.length);let c=t.at(-1);o.type==="text"&&c?.type==="text"?(c.raw+=o.raw,c.text+=o.text):t.push(o);continue}if(o=this.tokenizer.emStrong(e,i,l)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.codespan(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.br(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.del(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.autolink(e)){e=e.substring(o.raw.length),t.push(o);continue}if(!this.state.inLink&&(o=this.tokenizer.url(e))){e=e.substring(o.raw.length),t.push(o);continue}let h=e;if(this.options.extensions?.startInline){let c=1/0,g=e.slice(1),p;this.options.extensions.startInline.forEach(m=>{p=m.call({lexer:this},g),typeof p=="number"&&p>=0&&(c=Math.min(c,p))}),c<1/0&&c>=0&&(h=e.substring(0,c+1))}if(o=this.tokenizer.inlineText(h)){e=e.substring(o.raw.length),o.raw.slice(-1)!=="_"&&(l=o.raw.slice(-1)),r=!0;let c=t.at(-1);c?.type==="text"?(c.raw+=o.raw,c.text+=o.text):t.push(o);continue}if(e){let c="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(c);break}else throw new Error(c)}}return t}},F=class{options;parser;constructor(n){this.options=n||C}space(n){return""}code({text:n,lang:e,escaped:t}){let i=(e||"").match(b.notSpaceStart)?.[0],s=n.replace(b.endingNewline,"")+`
`;return i?'<pre><code class="language-'+T(i)+'">'+(t?s:T(s,!0))+`</code></pre>
`:"<pre><code>"+(t?s:T(s,!0))+`</code></pre>
`}blockquote({tokens:n}){return`<blockquote>
${this.parser.parse(n)}</blockquote>
`}html({text:n}){return n}def(n){return""}heading({tokens:n,depth:e}){return`<h${e}>${this.parser.parseInline(n)}</h${e}>
`}hr(n){return`<hr>
`}list(n){let e=n.ordered,t=n.start,i="";for(let r=0;r<n.items.length;r++){let l=n.items[r];i+=this.listitem(l)}let s=e?"ol":"ul",a=e&&t!==1?' start="'+t+'"':"";return"<"+s+a+`>
`+i+"</"+s+`>
`}listitem(n){return`<li>${this.parser.parse(n.tokens)}</li>
`}checkbox({checked:n}){return"<input "+(n?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:n}){return`<p>${this.parser.parseInline(n)}</p>
`}table(n){let e="",t="";for(let s=0;s<n.header.length;s++)t+=this.tablecell(n.header[s]);e+=this.tablerow({text:t});let i="";for(let s=0;s<n.rows.length;s++){let a=n.rows[s];t="";for(let r=0;r<a.length;r++)t+=this.tablecell(a[r]);i+=this.tablerow({text:t})}return i&&(i=`<tbody>${i}</tbody>`),`<table>
<thead>
`+e+`</thead>
`+i+`</table>
`}tablerow({text:n}){return`<tr>
${n}</tr>
`}tablecell(n){let e=this.parser.parseInline(n.tokens),t=n.header?"th":"td";return(n.align?`<${t} align="${n.align}">`:`<${t}>`)+e+`</${t}>
`}strong({tokens:n}){return`<strong>${this.parser.parseInline(n)}</strong>`}em({tokens:n}){return`<em>${this.parser.parseInline(n)}</em>`}codespan({text:n}){return`<code>${T(n,!0)}</code>`}br(n){return"<br>"}del({tokens:n}){return`<del>${this.parser.parseInline(n)}</del>`}link({href:n,title:e,tokens:t}){let i=this.parser.parseInline(t),s=Te(n);if(s===null)return i;n=s;let a='<a href="'+n+'"';return e&&(a+=' title="'+T(e)+'"'),a+=">"+i+"</a>",a}image({href:n,title:e,text:t,tokens:i}){i&&(t=this.parser.parseInline(i,this.parser.textRenderer));let s=Te(n);if(s===null)return T(t);n=s;let a=`<img src="${n}" alt="${t}"`;return e&&(a+=` title="${T(e)}"`),a+=">",a}text(n){return"tokens"in n&&n.tokens?this.parser.parseInline(n.tokens):"escaped"in n&&n.escaped?n.text:T(n.text)}},oe=class{strong({text:n}){return n}em({text:n}){return n}codespan({text:n}){return n}del({text:n}){return n}html({text:n}){return n}text({text:n}){return n}link({text:n}){return""+n}image({text:n}){return""+n}br(){return""}checkbox({raw:n}){return n}},v=class X{options;renderer;textRenderer;constructor(e){this.options=e||C,this.options.renderer=this.options.renderer||new F,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new oe}static parse(e,t){return new X(t).parse(e)}static parseInline(e,t){return new X(t).parseInline(e)}parse(e){let t="";for(let i=0;i<e.length;i++){let s=e[i];if(this.options.extensions?.renderers?.[s.type]){let r=s,l=this.options.extensions.renderers[r.type].call({parser:this},r);if(l!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(r.type)){t+=l||"";continue}}let a=s;switch(a.type){case"space":{t+=this.renderer.space(a);break}case"hr":{t+=this.renderer.hr(a);break}case"heading":{t+=this.renderer.heading(a);break}case"code":{t+=this.renderer.code(a);break}case"table":{t+=this.renderer.table(a);break}case"blockquote":{t+=this.renderer.blockquote(a);break}case"list":{t+=this.renderer.list(a);break}case"checkbox":{t+=this.renderer.checkbox(a);break}case"html":{t+=this.renderer.html(a);break}case"def":{t+=this.renderer.def(a);break}case"paragraph":{t+=this.renderer.paragraph(a);break}case"text":{t+=this.renderer.text(a);break}default:{let r='Token with "'+a.type+'" type was not found.';if(this.options.silent)return console.error(r),"";throw new Error(r)}}}return t}parseInline(e,t=this.renderer){let i="";for(let s=0;s<e.length;s++){let a=e[s];if(this.options.extensions?.renderers?.[a.type]){let l=this.options.extensions.renderers[a.type].call({parser:this},a);if(l!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(a.type)){i+=l||"";continue}}let r=a;switch(r.type){case"escape":{i+=t.text(r);break}case"html":{i+=t.html(r);break}case"link":{i+=t.link(r);break}case"image":{i+=t.image(r);break}case"checkbox":{i+=t.checkbox(r);break}case"strong":{i+=t.strong(r);break}case"em":{i+=t.em(r);break}case"codespan":{i+=t.codespan(r);break}case"br":{i+=t.br(r);break}case"del":{i+=t.del(r);break}case"text":{i+=t.text(r);break}default:{let l='Token with "'+r.type+'" type was not found.';if(this.options.silent)return console.error(l),"";throw new Error(l)}}}return i}},q=class{options;block;constructor(n){this.options=n||C}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(n){return n}postprocess(n){return n}processAllTokens(n){return n}emStrongMask(n){return n}provideLexer(){return this.block?y.lex:y.lexInline}provideParser(){return this.block?v.parse:v.parseInline}},Rt=class{defaults=V();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=v;Renderer=F;TextRenderer=oe;Lexer=y;Tokenizer=Q;Hooks=q;constructor(...n){this.use(...n)}walkTokens(n,e){let t=[];for(let i of n)switch(t=t.concat(e.call(this,i)),i.type){case"table":{let s=i;for(let a of s.header)t=t.concat(this.walkTokens(a.tokens,e));for(let a of s.rows)for(let r of a)t=t.concat(this.walkTokens(r.tokens,e));break}case"list":{let s=i;t=t.concat(this.walkTokens(s.items,e));break}default:{let s=i;this.defaults.extensions?.childTokens?.[s.type]?this.defaults.extensions.childTokens[s.type].forEach(a=>{let r=s[a].flat(1/0);t=t.concat(this.walkTokens(r,e))}):s.tokens&&(t=t.concat(this.walkTokens(s.tokens,e)))}}return t}use(...n){let e=this.defaults.extensions||{renderers:{},childTokens:{}};return n.forEach(t=>{let i={...t};if(i.async=this.defaults.async||i.async||!1,t.extensions&&(t.extensions.forEach(s=>{if(!s.name)throw new Error("extension name required");if("renderer"in s){let a=e.renderers[s.name];a?e.renderers[s.name]=function(...r){let l=s.renderer.apply(this,r);return l===!1&&(l=a.apply(this,r)),l}:e.renderers[s.name]=s.renderer}if("tokenizer"in s){if(!s.level||s.level!=="block"&&s.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let a=e[s.level];a?a.unshift(s.tokenizer):e[s.level]=[s.tokenizer],s.start&&(s.level==="block"?e.startBlock?e.startBlock.push(s.start):e.startBlock=[s.start]:s.level==="inline"&&(e.startInline?e.startInline.push(s.start):e.startInline=[s.start]))}"childTokens"in s&&s.childTokens&&(e.childTokens[s.name]=s.childTokens)}),i.extensions=e),t.renderer){let s=this.defaults.renderer||new F(this.defaults);for(let a in t.renderer){if(!(a in s))throw new Error(`renderer '${a}' does not exist`);if(["options","parser"].includes(a))continue;let r=a,l=t.renderer[r],o=s[r];s[r]=(...h)=>{let c=l.apply(s,h);return c===!1&&(c=o.apply(s,h)),c||""}}i.renderer=s}if(t.tokenizer){let s=this.defaults.tokenizer||new Q(this.defaults);for(let a in t.tokenizer){if(!(a in s))throw new Error(`tokenizer '${a}' does not exist`);if(["options","rules","lexer"].includes(a))continue;let r=a,l=t.tokenizer[r],o=s[r];s[r]=(...h)=>{let c=l.apply(s,h);return c===!1&&(c=o.apply(s,h)),c}}i.tokenizer=s}if(t.hooks){let s=this.defaults.hooks||new q;for(let a in t.hooks){if(!(a in s))throw new Error(`hook '${a}' does not exist`);if(["options","block"].includes(a))continue;let r=a,l=t.hooks[r],o=s[r];q.passThroughHooks.has(a)?s[r]=h=>{if(this.defaults.async&&q.passThroughHooksRespectAsync.has(a))return(async()=>{let g=await l.call(s,h);return o.call(s,g)})();let c=l.call(s,h);return o.call(s,c)}:s[r]=(...h)=>{if(this.defaults.async)return(async()=>{let g=await l.apply(s,h);return g===!1&&(g=await o.apply(s,h)),g})();let c=l.apply(s,h);return c===!1&&(c=o.apply(s,h)),c}}i.hooks=s}if(t.walkTokens){let s=this.defaults.walkTokens,a=t.walkTokens;i.walkTokens=function(r){let l=[];return l.push(a.call(this,r)),s&&(l=l.concat(s.call(this,r))),l}}this.defaults={...this.defaults,...i}}),this}setOptions(n){return this.defaults={...this.defaults,...n},this}lexer(n,e){return y.lex(n,e??this.defaults)}parser(n,e){return v.parse(n,e??this.defaults)}parseMarkdown(n){return(e,t)=>{let i={...t},s={...this.defaults,...i},a=this.onError(!!s.silent,!!s.async);if(this.defaults.async===!0&&i.async===!1)return a(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof e>"u"||e===null)return a(new Error("marked(): input parameter is undefined or null"));if(typeof e!="string")return a(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(e)+", string expected"));if(s.hooks&&(s.hooks.options=s,s.hooks.block=n),s.async)return(async()=>{let r=s.hooks?await s.hooks.preprocess(e):e,l=await(s.hooks?await s.hooks.provideLexer():n?y.lex:y.lexInline)(r,s),o=s.hooks?await s.hooks.processAllTokens(l):l;s.walkTokens&&await Promise.all(this.walkTokens(o,s.walkTokens));let h=await(s.hooks?await s.hooks.provideParser():n?v.parse:v.parseInline)(o,s);return s.hooks?await s.hooks.postprocess(h):h})().catch(a);try{s.hooks&&(e=s.hooks.preprocess(e));let r=(s.hooks?s.hooks.provideLexer():n?y.lex:y.lexInline)(e,s);s.hooks&&(r=s.hooks.processAllTokens(r)),s.walkTokens&&this.walkTokens(r,s.walkTokens);let l=(s.hooks?s.hooks.provideParser():n?v.parse:v.parseInline)(r,s);return s.hooks&&(l=s.hooks.postprocess(l)),l}catch(r){return a(r)}}}onError(n,e){return t=>{if(t.message+=`
Please report this to https://github.com/markedjs/marked.`,n){let i="<p>An error occurred:</p><pre>"+T(t.message+"",!0)+"</pre>";return e?Promise.resolve(i):i}if(e)return Promise.reject(t);throw t}}},I=new Rt;function f(n,e){return I.parse(n,e)}f.options=f.setOptions=function(n){return I.setOptions(n),f.defaults=I.defaults,Ie(f.defaults),f};f.getDefaults=V;f.defaults=C;f.use=function(...n){return I.use(...n),f.defaults=I.defaults,Ie(f.defaults),f};f.walkTokens=function(n,e){return I.walkTokens(n,e)};f.parseInline=I.parseInline;f.Parser=v;f.parser=v.parse;f.Renderer=F;f.TextRenderer=oe;f.Lexer=y;f.lexer=y.lex;f.Tokenizer=Q;f.Hooks=q;f.parse=f;f.options;f.setOptions;f.use;f.walkTokens;f.parseInline;v.parse;y.lex;var J=class{constructor(e=""){this._text="",this._displayedText="",this._pendingText="",this._text=e,this._pendingText=e}setText(e){this._text=e,this._displayedText&&e.includes(this._displayedText)?this._pendingText=e.substring(this._displayedText.length):(this._pendingText=this._text,this._displayedText="")}getText(){return this._displayedText}clearText(){this._displayedText="",this._text="",this._pendingText=""}updateDisplayText(){if(this._pendingText.length>0){let e=this._pendingText[0];if(e==="["||e==="<"||e==="!"){let t=this._matchMarkdownPattern(this._displayedText+this._pendingText,this._displayedText.length);if(t){let i=t.end-t.start,s=this._pendingText.substring(0,i);this._displayedText+=s,this._pendingText=this._pendingText.substring(i)}else this._displayedText+=e,this._pendingText=this._pendingText.substring(1)}else this._displayedText+=e,this._pendingText=this._pendingText.substring(1)}}_matchMarkdownPattern(e,t){let i=[/<sup>\[\[[^\]]+\]\]\([^)]+\)<\/sup>/,/\[\[[^\]]+\]\]\([^)]+\)/,/\[[^\]]+\]\([^)]+\)/,/!\[[^\]]*\]\([^)]+\)/],s=e.substring(t);for(let a of i){let r=s.match(a);if(r&&r.index===0)return{start:t,end:t+r[0].length}}return null}},It="https://links.esri.com/solutions/agol-organizational-account",Ct="https://links.esri.com/solutions/configure-assistants",Y=class extends ge{constructor(){super(),this.serverRoot="https://aiservices-beta.arcgis.com",this.token=null,this.open=!1,this.userFirstName="",this.conversationStore={conversationId:null,inquiryId:null,ackSequenceNumber:null},this._currentResponse="",this._isAutoScroll=!1,this._isLoading=!1,this._isLoadingText="",this.messages=[],this._orgSettings={aiAssistantsEnabled:!1,blockBetaApps:!0,colocateCompute:!1},this._translations=me({name:"arcgis-solutions-assistant",blocking:!0}),this._isTyping=!1,this._configContextConsumer=xe({context:be,subscribe:!0,callback:e=>{e?.userSession&&!this.userFirstName&&this._loadUserFirstName(),e?.authentication?.PortalSubset?.orgSettings&&(this._orgSettings=e?.authentication?.PortalSubset?.orgSettings,this._getAIServiceUrl())}}),this.closeAssistant=he(),this._resetConversation=()=>{this.conversationStore.conversationId=null,this.conversationStore.inquiryId=null,this.conversationStore.ackSequenceNumber=null},this._setMessageContainerRef=e=>{this._chatContainer=e},this._setInputRef=e=>{this._inputRef=e,this._inputRef.addEventListener("keydown",t=>{t.key==="Enter"&&!t.shiftKey&&!this._isLoading&&!this._isTyping&&(t.preventDefault(),this._inputRef&&(this.handleSendMessage(this._inputRef.value.trim()),this._inputRef.value=""))}),setTimeout(()=>{this._inputRef?.focus()},100)},this._submitQuestion=e=>{this.handleSendMessage(e)},this._handleSignIn=()=>{this._configContextConsumer.value?.authentication?.signIn("aiOpen")},this._checkURLOpenParameter=()=>{this.open=this._configContextConsumer.value?.authentication?.SignInParam==="aiOpen"||this.open},this.listenOn(window,"submitQuestion",e=>{this._submitQuestion(e.detail)})}static{this.properties={serverRoot:1,token:1,open:[5,{},{type:Boolean}],userFirstName:1,conversationStore:[16,{},{state:!0}],_currentResponse:[16,{},{state:!0}],_isAutoScroll:[16,{},{state:!0}],_isLoading:[16,{},{state:!0}],_isLoadingText:[16,{},{state:!0}],messages:[16,{},{state:!0}],_orgSettings:[16,{},{state:!0}],_translations:[16,{},{state:!0}],_isTyping:[16,{},{state:!0}]}}static{this.styles=Fe}get _telemetry(){return this._configContextConsumer.value?.telemetrySession}get solutionAIurl(){return`${this.serverRoot}/skills/solution_deployment/chat`}get docAIurl(){return`${this.serverRoot}/skills/doc_ai_assistant/chat`}async handleSendMessage(e){this._isLoading=!0;let t={message:e,context:{debug:!1,kind:"SolutionRequest"}};if(this.conversationStore.conversationId!==null){if(t.conversationId=this.conversationStore.conversationId,this.token){let i={author:"human",conversationId:this.conversationStore.conversationId?this.conversationStore.conversationId:"",message:e,render:this._renderSimpleTextMessage(e,"human","","Other")};this.messages=[...this.messages,i];let s=await this.requestAIServer(t,this.token,this.solutionAIurl);this.loopRequest(s,this.token,this.solutionAIurl)}}else if(this.token){let i={author:"human",message:e,render:this._renderSimpleTextMessage(e,"human","","Other")};this.messages=[...this.messages,i];let s=await this.requestAIServer(t,this.token,this.solutionAIurl);this.conversationStore.conversationId=s.conversationId,this.conversationStore.inquiryId=s.inquiryId,this.conversationStore.ackSequenceNumber=s.sequenceNumber,this.loopRequest(s,this.token,this.solutionAIurl)}}async loopRequest(e,t,i){let s=Date.now(),a,r=i;this._isLoading=!0;let l=document.createElement("div");l.classList.add("response-message","message-content");let o=document.createElement("div");o.classList.add("display-none");let h=document.createElement("div");h.classList.add("display-none");let c=e.conversationId+Date.now(),g=this._renderResponseBlock(l,o,h,c),p=new J(this._currentResponse),m={author:"ai",conversationId:e.conversationId,message:e.message??"",render:g};for(this.messages.push(m),this.requestUpdate(),this._isAutoScroll=!0;e.hasMore;){await new Promise(_=>setTimeout(_,500));let x={conversationId:e.conversationId,ackSequenceNumber:e.sequenceNumber,inquiryId:e.inquiryId};if(e.context)if(this.conversationStore.context=e.context,e.context.results&&!e.context.intent)for(let _ of e.context.results)this._currentResponse=_.reply,this._currentResponse!==""&&(this._isLoading=!1,this._isTyping=!0,this._showCardById(c),this._startTypeWriter(p,this._currentResponse,l,o,h)),e=await this.requestAIServer(x,t,r);else if(e.context.intent==="Solution question"){a=e.context.intent;let _={message:e.message,conversationId:x.conversationId,context:{kind:"DocAIAssistantRequest",filters:{products:"ArcGIS Solutions"}}};r=this.docAIurl,e=await this.requestAIServer(_,t,r)}else this._currentResponse=e.message??"",e.context.kind&&e.context.kind.toLowerCase()==="ArcGISErrorAsContext".toLowerCase()&&(this._currentResponse=this._translations.genericErrorMessage),this._currentResponse!==""&&(this._isLoading=!1,this._isTyping=!0,this._showCardById(c),this._startTypeWriter(p,this._currentResponse,l,o,h)),e=await this.requestAIServer(x,t,r);else e=await this.requestAIServer(x,t,r)}this._isLoading=!1;let{context:u}=this.conversationStore,w=this.messages.length>=2?this._getMostRecentQuestion():"",$=typeof w=="string"?"":w?.message??"",B=_e(s),M=a||u?.intent||"Unknown";if(this._telemetry?.logEvent({category:we.ASSISTANT,action:"Chat",dimensions:[M],metrics:[B]}),u&&u.intent)switch(u.intent){case"Recommend solution":{if(u.results){let x=u.results,_=x.map(Qe=>`- ${Qe.title}`).join(`
`),S=this._renderSuggestedSolutions(x),Ue=this._renderFeedback(this._currentResponse+`
`+_,$,this.conversationStore.conversationId,u.intent);R(S,o),R(Ue,h)}else o.innerHTML="";this._scrollToBottom();break}default:{let x=this._renderFeedback(this._currentResponse,$,this.conversationStore.conversationId,u.intent);R(x,h),this._scrollToBottom();break}}else{if(u&&u.results&&!u.intent)for(let x of u.results){let _=this._renderSolutionsQuestionTable(x.ref,x.followupQuestions),S=this._renderFeedback(this._currentResponse,$,this.conversationStore.conversationId,"Solution question");R(_,o),R(S,h)}else if(u&&u.kind&&u.kind.toLowerCase()==="ArcGISErrorAsContext".toLowerCase()){let x=this._renderFeedback(this._currentResponse,$,this.conversationStore.conversationId,"Error");R(x,h)}this._scrollToBottom()}}async requestAIServer(e,t,i){try{let a=await(await fetch(i,{method:"POST",headers:{"Content-Type":"application/json",token:t},body:JSON.stringify(e)})).json();if(a)return a;throw new Error("No data returned")}catch(s){throw new Error(`Request failed: ${s}`)}}resetChat(){let e=this.messages[this.messages.length-1];if(e.author!=="system"&&e.conversationId!=="-1"){this._resetConversation();let t={author:"system",conversationId:"-1",message:this._translations.newConversationStarted,render:this._renderSimpleTextMessage(this._translations.newConversationStarted,"system","","Other","speech-bubble-plus")};this.messages=[...this.messages,t],this._inputRef&&(this._inputRef.value="")}}loaded(){this._checkURLOpenParameter();let e=this._chatContainer;e&&e.addEventListener("scroll",()=>{this._isAutoScroll=this._isAtBottom(e)})}firstUpdated(e){this._loadUserFirstName()}willUpdate(e){if(this._configContextConsumer.value?.userSession?.token&&this._configContextConsumer.value?.authentication?.CanUseAI&&this.messages.length===0&&this._translations.defaultStartUpMessage){let t=this._translations.defaultStartUpMessage.replace("{{name}}",this.userFirstName),i=Object.values(this._translations.defaultFollowUpQuestions),s=this._renderSolutionQuestionFollowup(i);this.messages=[{author:"ai",conversationId:"",message:t,render:this._renderSimpleTextMessage(t,"ai","","Other",void 0,s)}]}(e.has("_isLoading")||e.has("_isTyping"))&&this.renderRoot.querySelectorAll(".assistant-followup-chip").forEach(i=>{i.disabled=this._isLoading||this._isTyping})}updated(e){(e.size||this._isLoading)&&this._scrollToBottom()}_renderFeedback(e,t,i,s){let a=Date.now();return k`
      <div>
        <calcite-button
          appearance='transparent'
          class='height-32-flex-auto'
          id='good-${a}'
          icon-start='thumbs-up'
          label='position feedback'
          kind='neutral'
          @click=${()=>{this._sendFeedback(e,t,"Good",i,s)}}
        >
        </calcite-button>
        <calcite-tooltip placement='bottom' reference-element='good-${a}'>
          <span>${this._translations.tooltips.likeButton}</span>
        </calcite-tooltip>

        <calcite-button
          appearance='transparent'
          class='height-32-flex-auto'
          id='bad-${a}'
          icon-start='thumbs-down'
          label='position feedback'
          kind='neutral'
          @click=${()=>{this._sendFeedback(e,t,"Bad",i,s)}}
        >
        </calcite-button>
        <calcite-tooltip placement='bottom' reference-element='bad-${a}'>
          <span>${this._translations.tooltips.dislikeButton}</span>
        </calcite-tooltip>

        <calcite-button
          appearance='transparent'
          class='height-32-flex-auto'
          id='copy-${a}'
          icon-start='copy'
          label='position feedback'
          kind='neutral'
          @click=${r=>{this._copyResponseToClipboard(e,r)}}
        >
        </calcite-button>
        <calcite-tooltip placement='bottom' reference-element='copy-${a}'>
          <span>${this._translations.tooltips.copyButton}</span>
        </calcite-tooltip>
      </div>
    `}_renderSolutionQuestionReferences(e){return k`
      ${e.map(t=>k`
          <div class='message-content-pad'>
            <a href=${t.url} target='_blank'>
              ${t.title}
            </a>
          </div>
        `)}
    `}_renderSolutionQuestionFollowup(e){return k`
      ${e.map(t=>k`
          <calcite-chip
            class='chip-content cursor-pointer assistant-followup-chip'
            kind='brand'
            label=${t}
            @click=${()=>{this._submitFollowupQuestion(t)}}
          >
            ${t}
          </calcite-chip>
        `)}
    `}_renderSolutionsQuestionTable(e,t){let i=this._renderSolutionQuestionReferences(e),s=this._renderSolutionQuestionFollowup(t);return k`
      <div slot='description' class='message-content'>
        <div style='display: flex; justify-content: flex-start;'>
          <calcite-button
            appearance='outline'
            icon-end='chevron-down'
            icon-start='link'
            @click=${a=>{let r=a.currentTarget,l=r.parentElement.nextElementSibling;l.classList.toggle("collapsed"),r.setAttribute("icon-end",l.classList.contains("collapsed")?"chevron-down":"chevron-up")}}
          >
            ${e.length}
            ${e.length===1?this._translations.solutionsDocReference:this._translations.solutionsDocReferences}
          </calcite-button>
        </div>

        <div class='references-container collapsed'>
          ${i}
        </div>
      </div>

      <div class='padding-top-10'>
        ${s}
      </div>
    `}_renderSolutionCard(e,t){return k`
      <a
        class='solution-card'
        id='${t}'
        @click=${()=>this._emitItemIdFromAI(t)}
      >
        <calcite-card thumbnail-position='inline-start'>
          <div slot='thumbnail'>
            <img src='${e.thumbnail}' alt='Thumbnail' />
            <calcite-chip icon='launch' label='View solution'>
              ${this._translations.viewSolutionInApp}
            </calcite-chip>
          </div>

          <h3 slot='heading'><b>${e.title}</b></h3>

          <span slot='description' class='solution-snippet'>${e.snippet}</span>
        </calcite-card>
      </a>
    `}_renderResponseBlock(e,t,i,s){return k`<calcite-card id=${s??j} class="system-message display-none">${e}${t}${i}</calcite-card>`}_renderSimpleTextMessage(e,t,i,s,a,r){let l=this.messages.length>=2?this._getMostRecentQuestion():"",o=typeof l=="string"?"":l?.message??"";return t==="system"?k`<div class="message-content message-content-alignment">${a&&k`<calcite-icon .icon=${a}></calcite-icon>`||""}${e}</div>`:k`<calcite-card class=${fe(t==="human"?"user-message":"system-message")}><div class="message-content">${G(e)}${r}${t==="ai"&&i!==""&&this._renderFeedback(e,o,i,s)||""}</div></calcite-card>`}_renderSuggestedSolutions(e){let t=e.map(i=>{let s=i.thumbnail.match(/\/items\/([a-f0-9]+)\//);return s?this._renderSolutionCard(i,s[1]):null}).filter(i=>i!==null);return k`
      <div class='message-content'>
        ${t}
      </div>
    `}_renderNoSign(){return k`<calcite-notice open scale=m icon=effects kind=info><div slot=message>${this._translations.signInMessage}</div><calcite-link @click=${this._handleSignIn} slot=link title=${this._translations.signInMessage??j} class="padding-top-10">${this._translations.signIn}</calcite-link></calcite-notice>`}_renderNoPermission(){return k`<calcite-notice open scale=m icon=effects kind=info><div slot=title>${this._translations.noPermissionTitle}</div><div slot=message class="padding-top-10">${G(this._translations.noPermissionMessage.replace("{{orgUrl}}",It).replace("{{configAI}}",Ct))}</div></calcite-notice>`}render(){return k`<calcite-dialog class="chat-panel" .open=${this.open} .heading=${this._translations.solutionAssistantTitle} placement=bottom-start @calciteDialogClose=${()=>{this.closeAssistant.emit(!0),this.open=!1}}><span class="chat-panel-heading" slot=header-content><span class="padding-right-8">${this._translations.solutionAssistantTitle}</span><calcite-chip .label=${this._translations.betaTag} .value=${this._translations.betaTag}>${this._translations.betaTag}</calcite-chip></span>${this.messages.length>1?k`<calcite-button appearance=transparent class="icon-color-background" .disabled=${!!this._isLoading||this._isTyping} id=newChatButton icon-end=speech-bubble-plus kind=neutral label="New conversation" @click=${this.resetChat} scale=l slot=header-actions-end></calcite-button><calcite-tooltip placement=bottom reference-element=newChatButton><span>${this._translations.tooltips.newConversation}</span></calcite-tooltip>`:""}<div class="chat-messages" ${Z(this._setMessageContainerRef)}>${this.messages.map(e=>e.render)}${this._isLoading&&k`<calcite-card class="loader-message"><div class="message-content display-flex-row"><calcite-loader .label=${this._isLoadingText} inline scale=s></calcite-loader>${this._isLoadingText!=""&&k`<div class="padding-left-10">${this._isLoadingText}</div>`||""}</div></calcite-card>`||""}${this._chatContainer&&!this._isAtBottom(this._chatContainer)&&!this._isAutoScroll&&k`<calcite-fab icon=arrow-down @click=${()=>{this._isAutoScroll=!0,this._scrollToBottom(),setTimeout(()=>{this.requestUpdate()},100)}} scale=m></calcite-fab>`||""}${this._configContextConsumer.value?.userSession?.token?this._configContextConsumer.value?.authentication?.CanUseAI?"":this._renderNoPermission():this._renderNoSign()}</div><div slot=footer class="width-100"><div class="chat-input"><calcite-text-area .disabled=${!this._configContextConsumer.value?.userSession?.token||!this._configContextConsumer.value?.authentication?.CanUseAI} resize=none rows=3 .placeholder=${this._translations.sendMessage} value ${Z(this._setInputRef)}></calcite-text-area><calcite-button appearance=outline .disabled=${!!this._isLoading||this._isTyping||!this._configContextConsumer.value?.userSession?.token||!this._configContextConsumer.value?.authentication?.CanUseAI} icon-start=send id=sendQuestion kind=neutral @click=${()=>{this._inputRef&&(this.handleSendMessage(this._inputRef.value.trim()),this._inputRef.value="")}}></calcite-button><calcite-tooltip placement=bottom reference-element=sendQuestion><span>${this._translations.tooltips.sendQuestion}</span></calcite-tooltip></div><div class="disclaimer-div padding-top-10" slot=footer><calcite-icon icon=information scale=s></calcite-icon>${this._translations.disclaimerMessage}<a href=https://links.esri.com/solutions/security-concern target=_blank>${this._translations.reportConcern}</a></div></div></calcite-dialog>`}_scrollToBottom(){this._chatContainer&&this._isAutoScroll&&setTimeout(()=>{this._chatContainer&&(this._chatContainer.scrollTop=this._chatContainer.scrollHeight)},100)}_emitItemIdFromAI(e){this._querySolutions(e).then(t=>{let s=t.typeKeywords.filter(r=>r.includes("solutionid")),a=new CustomEvent("solutionIDFromAssistant",{detail:s.length>0?s[0]:e,bubbles:!0,composed:!0});window.dispatchEvent(a)})}_submitFollowupQuestion(e){let t=new CustomEvent("submitQuestion",{detail:e,bubbles:!0,composed:!0});window.dispatchEvent(t)}_getMostRecentQuestion(){return[...this.messages].reverse().find(e=>e.author==="human")||null}async _querySolutions(e){let t=await Oe(e);if("error"in t)throw new Error(t.error);return t}_sendFeedback(e,t,i,s,a){let r=`https://survey123.arcgis.com/share/6e349a50b4504ca6b6107216d568db5f?field:_source=${encodeURIComponent("Solutions Assistant")}&field:user_evaluation=${encodeURIComponent(i)}&field:question=${encodeURIComponent(t)}&field:answer=${encodeURIComponent(e)}&field:context=${encodeURIComponent(JSON.stringify({intent:a}))}&field:conversation_id=${encodeURIComponent(s)}&field:version=${encodeURIComponent("v1")}`;window.open(r,"_blank")}_copyResponseToClipboard(e,t){navigator.clipboard.writeText(e);let i=t.currentTarget;i.iconStart="check",setTimeout(()=>{i.iconStart="copy"},3e3)}_startTypeWriter(e,t,i,s,a){if(t.length>0){e.setText(t);let r=async()=>{e.updateDisplayText();let l=e.getText(),o=await f.parse(l);i.innerHTML=o.replace(/<a\s+/g,'<a target="_blank" '),l.length<this._currentResponse.length?(this._scrollToBottom(),setTimeout(r,5)):(this._isTyping=!1,this._isAutoScroll=!1,s.classList.remove("display-none"),a.classList.remove("display-none"))};r()}}_showCardById(e){let t=this.renderRoot.querySelector(`#${e}`);t&&t.classList.remove("display-none")}_isAtBottom(e){return e.scrollTop+e.clientHeight>=e.scrollHeight-5}async _loadUserFirstName(){try{let e=await this._configContextConsumer.value?.userSession?.getUser();if(e?.fullName){let t=e.fullName.split(" ")[0];this.userFirstName=t}}catch{}}_getAIServiceUrl(){if(this._configContextConsumer.value){let e=this._configContextConsumer.value;e.authentication&&e.authentication?.Portal&&e.authentication?.Portal.helperServices.aiAssistantServices&&(this.serverRoot=e.authentication?.Portal.helperServices.aiAssistantServices.url)}}};ke("arcgis-solutions-assistant",Y);return Y},a,b)