/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import{a as y}from"./ONARC6AZ.js";import{a as E}from"./2D6XDWYA.js";import{a as $}from"./BM4VSEDV.js";import{b as f}from"./HVT2WBVC.js";import"./UBPOT5V3.js";import"./ISFTCFSJ.js";import{E as h,F as u,G as m,I as p,h as b,i as o,l as _,q as w}from"./FFF5HUPM.js";import"./EXBEKVP5.js";export default $arcgis.t(([c,S,L])=>{var C=`
  @media print {
    @page {
      size:  Portrait;
      margin: .25in;
    }

    html, body {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }

    body > *:not(.instant-apps-export-print) { display: none; }
  }

  * {
    -webkit-print-color-adjust: exact;
    color-adjust: exact;
  }

  instant-apps-header {
    height: 50px;
    display: block;
  }


  .instant-apps-export-print {
    z-index: -999;
    color: #323232 !important;
    display: grid;
    grid-auto-flow: row;
    --esri-calcite-mode-name: "light";
    position: absolute;
  }

  .instant-apps-export-print__view-header {
    background: #fff;
  }

  .instant-apps-export-print__view-header h1 {
    font-size: 16px;
    font-weight: 500;
    color: #323232;
    margin: 6px;
  }

  .instant-apps-export-print__views-container {
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
  }

  .instant-apps-export-print__view-content:first-child {
    page-break-before: unset;
  } 

  .instant-apps-export-print__view-content {
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 32px;
    page-break-before: always;
  }

  .instant-apps-export-print, .instant-apps-export-print * {
    box-sizing: border-box;
  }

  .instant-apps-export-print__view-section {
    height: 100%;
  }

  .instant-apps-export-print__view-container {
    height: 100%;
    width: 100%;
    break-inside: avoid;
  }

  .instant-apps-export-print__view-wrapper {
    height: fit-content;
    width: min-content;
    position: relative;
    display: flex;
    flex-direction: column;
    border: 2pt solid #323232;
    overflow: hidden;
  }

  .instant-apps-export-print__view {
    max-height: 60vh;
    max-width: calc(100vw - .25in);
    object-fit: contain;
  }

  .instant-apps-export-print__popup-container {
    height: min-content;
    max-width: 350px;
    display: none;
    color: #323232;
    background: #fff;
    border: 1pt solid #323232;
    break-inside: avoid;
  }

  .instant-apps-export-print__popup-title {
    border-bottom: 1pt solid #323232;
  }

  .instant-apps-export-print__popup-content {
    background: #fff;
    padding-top: 8pt;
  }

  .instant-apps-export-print__popup-content .esri-feature-media__chart {
    background: #fff;
  }

  .instant-apps-export-print__legend-container {
    height: min-content;
    background: #fff;
    overflow: unset;
  }

  .esri-legend--card, .esri-legend--card__service-content {
    flex-flow: row wrap;
  }

  .instant-apps-export-print .esri-widget > *:not(.esri-scale-bar.esri-widget > *) {
    background: #fff;
    color: #323232;
  }

  .instant-apps-export-print__popup-content * {
    color: #323232;
  }

  .instant-apps-export-print .esri-widget__heading {
    margin: 2pt 7pt;
    padding: 0;
    color: #323232;
  }

  .instant-apps-export-print .esri-legend__ramp-label:before {
    border-color: rgba(0,0,0,0) rgba(50,50,50,.8) rgba(0,0,0,0) rgba(0,0,0,0);
  }

  .instant-apps-export-print .esri-legend--card__section {
    padding: 4pt 0 4pt;
    min-width: unset;
    border-left: none;
  }

  .instant-apps-export-print .esri-legend--card__section:first-child {
    border-left: none;
  }

  .instant-apps-export-print .esri-legend--card__service {
    border: none;
    flex: 0 1 auto;
    break-inside: avoid;
  }

  .instant-apps-export-print .esri-legend--card {
    border: none;
    gap: 6pt 12pt;
  }

  .instant-apps-export-print .esri-legend--card:not(:first-child),
  .instant-apps-export-print .esri-compass.esri-widget:not(:first-child) {
    display: none;
  }

  .instant-apps-export-print .esri-legend--card__service-caption-container {
    height: unset;
    padding: 0;
    border-bottom: none;
  }

  .instant-apps-export-print .esri-legend--card__service-caption-text {
    padding-bottom: 4px;
  }

  .instant-apps-export-print__compass-container {
    position: absolute;
    top: 65px;
    left: 15px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    --calcite-icon-color: #000;
    border-radius: 50%;
    height: fit-content;
  }

  .instant-apps-export-print__compass-container .esri-compass {
    background: #fff;
  }

  .instant-apps-export-print__compass-container .esri-compass__icon.esri-icon-compass {
    color: #000;
  }

  .instant-apps-export-print__compass-container.esri-compass.esri-widget--button {
    background: #fff;
  }

  .instant-apps-export-print__scale-bar-container {
    width: 100%;
    position: absolute;
    bottom: 15px;
    margin: 0 15px;
  }

  .instant-apps-export-print__scale-bar-container .esri-scale-bar__label {
    color: #323232;
    font-size: 10px;
    padding: 0 4px;
  }

  .instant-apps-export-print__scale-bar-container .esri-scale-bar__label-container--line {
    height: 16px;
    overflow: hidden;
  }

  .instant-apps-export-print__scale-bar-container .esri-scale-bar__label-container--top {
    bottom: 1px;
  }
  
  .instant-apps-export-print__scale-bar-container--position .esri-scale-bar__label {
    height: 10px;
    padding: 0 2px;
    line-height: 11px;
  }

  .instant-apps-export-print__scale-bar-container .esri-scale-bar__bar-container:nth-child(1n+3) {
    display: none;
  }

  .instant-apps-export-print__scale-bar-container--position .esri-scale-bar__bar-container.esri-scale-bar__bar-container--line {
    align-items: center;
  }

  .instant-apps-export-print__scale-bar-container .esri-scale-bar__line {
    background-color: rgba(255, 255, 255, 0.66);
  }

  .instant-apps-export-print__scale-bar-container .esri-scale-bar__line--top {
    width: var(--instant-apps-scale-bar-top) !important;
    border-bottom: 2px solid #323232;
  }

  .instant-apps-export-print__scale-bar-container .esri-scale-bar__line--bottom {
    width: var(--instant-apps-scale-bar-bottom) !important;
    border-top: 2px solid #323232;
  }

  .instant-apps-export-print__scale-bar-container--position .esri-scale-bar__label-container--line {
    position: unset;
    margin: 0 2px;
    background-color: rgba(255, 255, 255, 0.66);
    height: 10px;
    display: flex;
    align-items: center;
  }

  .instant-apps-export-print__scale-bar-container .esri-scale-bar__line--top:before,
  .instant-apps-export-print__scale-bar-container .esri-scale-bar__line--top:after,
  .instant-apps-export-print__scale-bar-container .esri-scale-bar__line--bottom:before,
  .instant-apps-export-print__scale-bar-container .esri-scale-bar__line--bottom:after {
    background-color: #323232;
    border-right: 2px solid #323232;
  }

  .instant-apps-export-print__popup-container .esri-feature-media__item-navigation {
    display: none;
  }

  .instant-apps-export-print__popup-container .esri-feature-media__chart.esri-feature-media__chart--rendered * {
    width: 100%!important;
  }

  .instant-apps-export-print__popup-content .esri-popup__content {
    margin: 0;
  }
    
  .instant-apps-export-print__attribution {
    margin-top: 12px;
    font-size: 10px;
  }`,I=b`:host{display:block;--instant-apps-export-action-background: var(--calcite-color-foreground-1);--instant-apps-export-action-background-hover: var( --calcite-color-foreground-2 );--instant-apps-export-action-background-press: var( --calcite-color-foreground-3 );--instant-apps-export-action-height: 100%;--instant-apps-export-action-width: fit-content;--instant-apps-export-action-icon-color: var(--calcite-color-text-3);--instant-apps-export-action-icon-hover-color: var(--calcite-color-text-1);--instant-apps-export-background: var(--calcite-color-foreground-1);--instant-apps-export-text-color: var(--calcite-color-text-1);--instant-apps-export-popover-width: 250px}.instant-apps-export{height:100%}.instant-apps-export *{box-sizing:border-box}.instant-apps-export__popover-container,.instant-apps-export__inline-container{padding:12px;background:var(--instant-apps-export-background);--calcite-color-text-1: var(--instant-apps-export-text-color)}.instant-apps-export__popover-container{width:var(--instant-apps-export-popover-width)}.instant-apps-export calcite-action{height:var(--instant-apps-export-action-height);width:var(--instant-apps-export-action-width);--calcite-color-foreground-1: var(--instant-apps-export-action-background);--calcite-color-foreground-2: var( --instant-apps-export-action-background-hover );--calcite-color-foreground-3: var( --instant-apps-export-action-background-press );--calcite-color-text-3: var(--instant-apps-export-action-icon-color);--calcite-color-text-1: var(--instant-apps-export-action-icon-hover-color)}.instant-apps-export .instant-apps-export-print{display:none}.instant-apps-export__visually-hidden{position:absolute;top:0;z-index:-1;visibility:hidden}.instant-apps-export calcite-input{--calcite-color-foreground-1: var(--instant-apps-export-background);--calcite-color-text-1: var(--instant-apps-export-text-color)}.instant-apps-export calcite-popover{--calcite-color-foreground-1: var(--instant-apps-export-background)}.instant-apps-export calcite-switch{--calcite-color-foreground-1: #fff;--calcite-color-foreground-2: #f3f3f3}.instant-apps-export calcite-button:last-of-type{margin-top:.5rem}.calcite-mode-dark.instant-apps-export calcite-switch{--calcite-color-foreground-1: #2b2b2b;--calcite-color-foreground-2: #202020}.calcite-mode-dark.instant-apps-export .instant-apps-export__set-map-area{--calcite-color-brand-hover: #fff}.hide{display:none}.screenshotCursor{cursor:crosshair}`,a={baseDark:"instant-apps-export calcite-mode-dark",baseLight:"instant-apps-export calcite-mode-light",inlineContainer:"instant-apps-export__inline-container",popoverContainer:"instant-apps-export__popover-container",print:{base:"instant-apps-export-print",legendContainer:"instant-apps-export-print__legend-container",scaleBarContainer:"instant-apps-export-print__scale-bar-container",popupContainer:"instant-apps-export-print__popup-container",popupContent:"instant-apps-export-print__popup-content",popupTitle:"instant-apps-export-print__popup-title",view:"instant-apps-export-print__view",viewContainer:"instant-apps-export-print__view-container",viewsContainer:"instant-apps-export-print__views-container",viewWrapper:"instant-apps-export-print__view-wrapper",viewContent:"instant-apps-export-print__view-content",viewHeader:"instant-apps-export-print__view-header",attribution:"instant-apps-export-print__attribution"}},x=class extends m{constructor(){super(...arguments),this._messages=$({name:"instant-apps-export-views",blocking:!0}),this.printContainerEl=h(),this.popoverEl=h(),this.printEl=h(),this.legends={},this.baseClass=a.baseLight,this.exportIsLoading=void 0,this.beforeExport=async()=>await Promise.resolve(),this.popoverIcon="export",this.includeLegend=!0,this.includeMap=!0,this.includePopup=!1,this.includeHeader=!1,this.mode="popover",this.popoverPositioning="absolute",this.popoverPlacement="auto",this.scale="m",this.showIncludeLegend=!0,this.showIncludeMap=!1,this.showIncludePopup=!0,this.showIncludeHeader=!0,this.showScaleBar=!1,this.exportOutputUpdated=w()}static{this.properties={baseClass:16,exportIsLoading:16,output:0,beforeExport:0,popoverIcon:1,includeLegend:5,includeMap:5,includePopup:5,includeHeader:5,mode:3,popoverPositioning:1,popoverPlacement:1,scale:1,showIncludeLegend:5,showIncludeMap:5,showIncludePopup:5,showIncludeHeader:5,showScaleBar:5,exportViews:0}}static{this.styles=I}load(){this.baseClass=E(this.el)==="dark"?a.baseDark:a.baseLight,this.initializeModules()}willUpdate(t){t.has("includeMap")&&(this.hasUpdated||this.includeMap!==!0)&&this.exportViews?.forEach(({view:e},i)=>{if(!this.printEl.value)return;let n=this.printEl.value.querySelector(`#legend-${i}`);n!=null&&this.updateLegend(e,i,n)}),t.has("exportViews")&&this.exportViews?.forEach(({view:e},i)=>{this.handleIncludePopup(e,i)})}updated(){this.hasUpdated||this.exportViews?.forEach(({view:t},e)=>{if(!this.printEl.value)return;let i=this.printEl.value.querySelector(`#legend-${e}`);this.updateLegend(t,e,i)})}loaded(){this.printEl.value&&(this.printContainerEl.value?.prepend(this.printEl.value),this.exportViews?.forEach(({view:t},e)=>{this.handleIncludePopup(t,e)}))}initializeModules(){this.handles=new S}optionOnChange(t){let e=t.target,i=e.value;this[i]=e.checked,this.updateExportOutput()}async exportOnClick(){await this.beforeExport(),this.exportViews?.length?(this.addPrintStyling(),this.printEl.value&&document.body.prepend(this.printEl.value),this.exportViews.forEach(({view:t},e)=>{this.handleViewExportOnClick(t,e)}),this.handleImgLoaded()):this.popoverEl.value!=null&&(this.popoverEl.value.open=!1)}async handleViewExportOnClick(t,e){this.includeMap&&(this.updateAttribution(t,e),this.updateScaleBar(t,e),this.updatePopupToPrint(t,e),this.viewScreenshot(t,e),this.handleLegendSetup(e))}addPrintStyling(){this.printStyleEl==null&&(this.printStyleEl=document.createElement("style"),this.printStyleEl.innerHTML=C,document.body.prepend(this.printStyleEl))}handleImgLoaded(){this.exportIsLoading=!0,setTimeout(()=>{this.exportIsLoading=void 0,this.setupViewPrintElements()},1500)}resetPrintContent(){this.printEl.value&&(this.printContainerEl.value?.prepend(this.printEl.value),this.printStyleEl?.remove(),this.printStyleEl=void 0)}async updatePopupToPrint(t,e){if(!this.printEl.value)return;let i=this.printEl.value.querySelector(`#popup-${e}`);if(i!=null&&(i.style.display=this.includePopup&&t?.popup?.visible?"block":"none",this.checkPopupOpen(t,e)),t?.popup?.visible&&t?.popup?.selectedFeature!=null){let n=document.createElement(`h${t?.popup?.headingLevel??2}`);n.innerHTML=t?.popup?.title??"",n.className="esri-widget__heading esri-popup__header-title";let r=this.printEl.value.querySelector(`#popup-title-${e}`);r!=null&&(r.style.display=t?.popup?.title?"block":"none",r.innerHTML="",r.prepend(n))}}updateExportOutput(){this.output={},this.showIncludeLegend&&(this.output.includeLegend=this.includeLegend),this.showIncludeMap&&(this.output.includeMap=this.includeMap),this.showIncludePopup&&(this.output.includePopup=this.includePopup),this.showIncludeHeader&&(this.output.includeHeader=this.includeHeader),this.exportOutputUpdated.emit()}setupViewPrintElements(){let t=document.title;window.print(),document.title=t,setTimeout(()=>{this.resetPrintContent()},1500)}handleLegendSetup(t){if(!this.printEl.value)return;let e=this.printEl.value.querySelector(`#legend-${t}`);if(this.showIncludeLegend&&this.includeMap&&e){let i=this.legends[t],n=i!=null&&i.activeLayerInfos?.length>0;e.style.display=this.includeLegend&&n?"block":"none"}}handleWidgetCreation(){this.includeMap&&this.exportViews?.forEach(({view:t},e)=>{this.handleLegendCreation(t,e)})}handleIncludePopup(t,e){if(!(!this.handles||!t||!this.showIncludePopup)&&this.showIncludePopup){let i=`includePopup-${e}`;this.handles?.remove(i),c.whenOnce(()=>t?.ready).then(()=>{!c||!this.handles||this.handles.add(c.watch(()=>!!t?.popup?.visible,n=>{this.includePopup=n}),i)})}}handleLegendCreation(t,e){if(!this.printEl.value)return;let i=this.printEl.value.querySelector(`#legend-${e}`);if(this.showIncludeLegend&&i!=null){let n=t.map,r=this.legends[e]?.view?.map;n?.portalItem?.id!=null&&n?.portalItem?.id===r?.portalItem?.id||this.updateLegend(t,e,i)}}async updateLegend(t,e,i){t?.when(n=>{if(this.legends[e]==null&&i!=null){i.innerHTML="";let r=document.createElement("div");i.append(r),this.legends[e]=new L({id:`legend-widget-${e}`,container:r,view:n,style:{type:"card",layout:"side-by-side"}})}})}updateScaleBar(t,e){if(!this.printEl.value)return;let i=this.printEl.value.querySelector(`#scale-bar-container-${e}`);if(i&&t!=null&&(i.innerHTML="",this.showScaleBar)){let n=t?.ui?.getComponents()?.find(({container:r})=>r?.className?.includes("esri-scale-bar"));n?.container!=null&&typeof n.container!="string"&&i.append(n.container.cloneNode(!0))}}updateAttribution(t,e){let i=this.printEl.value?.querySelector(`#attribution-${e}`);if(!i||!t?.attributionItems?.length)return;i.innerHTML="";let n=" | ",r=t.attributionItems.map(s=>s.text);i.innerHTML=r.join(n)}async viewScreenshot(t,e){if(!this.printEl.value||!this.includeMap)return;let i=1e3,n=this.printEl.value.querySelector(`#scale-bar-container-${e}`);n?.classList.toggle("instant-apps-export-print__scale-bar-container--position",t.width>i);let r=await t.takeScreenshot({width:t.width*2,height:t.height*2});this.handleScaleBarSize(t,r,n);let s=this.printEl.value.querySelector(`#view-${e}`);r!=null&&s!=null&&(s.src=r.dataUrl)}checkPopupOpen(t,e){if(!this.printEl.value)return;let i=t?.popup?.container?.querySelector(".esri-popup .esri-feature__main-container");if(i!=null){let n=i.querySelectorAll("canvas"),r=this.printEl.value.querySelector(`#popup-content-${e}`);if(r==null)return;r.innerHTML="",r.append(i.cloneNode(!0));let s=r.querySelectorAll("canvas");n.forEach((d,k)=>{let P=d.toDataURL(),l=document.createElement("img");l.src=P;let g=d.getAttribute("style");g&&l.setAttribute("style",g);let v=s[k];v!=null&&(v.replaceWith(l),document.querySelector("link[href*='esri/themes/dark/main.css']")&&l.parentElement?.parentElement!=null&&(l.parentElement.style.background="#242424",l.parentElement.parentElement.style.background="#242424"))})}}handleScaleBarSize(t,e,i){if(this.showScaleBar&&t?.type==="2d"&&i!=null){let n=i.querySelector(".esri-scale-bar__line--top"),r=i.querySelector(".esri-scale-bar__line--bottom");this.setScaleBarWidth(e,i,n,"top"),this.setScaleBarWidth(e,i,r,"bottom")}}setScaleBarWidth(t,e,i,n){if(i!=null&&t!=null){let r=t.data.width/2,s=Number(i.style.width.replace("px",""))/r*100;e?.style.setProperty(`--instant-apps-scale-bar-${n}`,`${s}%`)}}render(){let t=this.mode==="popover"?this.renderPopover():this.renderPanel();return o`<div class=${p(this.baseClass)} @mouseenter=${this.handleWidgetCreation} @focusin=${this.handleWidgetCreation}>${t}</div>`}renderPopover(){let t=this.renderPanel();return[o`<calcite-popover reference-element=export-popover-btn .label=${this._messages.exportPopover} .overlayPositioning=${this.popoverPositioning} .placement=${this.popoverPlacement} auto-close ${u(this.popoverEl)}>${t}</calcite-popover>`,o`<calcite-action id=export-popover-btn alignment=center .icon=${this.popoverIcon} .scale=${this.scale} title=${this._messages.exportBtn??_} .text=${this._messages.exportBtn}></calcite-action>`]}renderPanel(){let t=this.showIncludeMap?this.renderSwitch("includeMap"):null,e=this.includeMap?this.renderMapOptions():null,i=this.renderPrint(),n=this.mode==="inline"?a.inlineContainer:a.popoverContainer;return o`<div class=${p(n)}>${t}${e}<calcite-button width=full @click=${this.exportOnClick} .disabled=${this.exportIsLoading}>${this._messages.export}</calcite-button>${i}</div>`}renderSwitch(t,e){let i=this[t],n=t,r=e??this._messages[n];return o`<calcite-label layout=inline-space-between>${r}<calcite-switch .checked=${i} .value=${t} @calciteSwitchChange=${this.optionOnChange}></calcite-switch></calcite-label>`}renderMapOptions(){let t=this.showIncludeHeader?this.renderSwitch("includeHeader"):null,e=this.showIncludeLegend?this.renderSwitch("includeLegend"):null,i=this.showIncludePopup?this.renderSwitch("includePopup"):null;return o`<div>${t}${e}${i}</div>`}renderPrint(){return o`<div ${u(this.printContainerEl)}><div class=${p(a.print.base)} ${u(this.printEl)}><div class=${p(a.print.viewsContainer)}>${this.exportViews?.map(({title:t,view:e},i)=>{let n=e.map?.portalItem?.id,r=this.includeMap?this.renderPrintMap(t,i):null,s=this.includeMap&&this.showIncludeLegend?this.renderLegend(i):null,d=this.includeMap&&this.showIncludePopup?this.renderPopup(i):null;return y(n??"",o`<div .id=${`print-${i}`} class=${p(a.print.viewContent)}>${r}${s}${d}</div>`)})}</div></div></div>`}renderPrintMap(t,e){return o`<div .id=${`view-container-${e}`} class=${p(a.print.viewContainer)}><div .id=${`view-wrapper-${e}`} class=${p(a.print.viewWrapper)}>${this.includeHeader&&t?o`<div class=${p(a.print.viewHeader)}><h1>${t}</h1></div>`:null}<img .id=${`view-${e}`} class=${p(a.print.view)}><div .id=${`scale-bar-container-${e}`} class=${p(a.print.scaleBarContainer)}></div></div>${this.renderAttribution(e)}</div>`}renderAttribution(t){return o`<div .id=${`attribution-${t}`} class=${p(a.print.attribution)}></div>`}renderLegend(t){return o`<div .id=${`legend-${t}`} class=${p(a.print.legendContainer)}></div>`}renderPopup(t){return o`<div .id=${`popup-${t}`} class=${p(a.print.popupContainer)}><div .id=${`popup-title-${t}`} class=${p(a.print.popupTitle)}></div><div .id=${`popup-content-${t}`} class=${p(a.print.popupContent)}></div></div>`}};f("instant-apps-export-views",x);return x},"core/reactiveUtils","core/Handles","widgets/Legend")