/**
 * Copyright 2018 The Pennsylvania State University
 * @license Apache-2.0, see License.md for full text.
 */
import{LitElement as e,html as t,css as a}from"../../lit/index.js";class BeakerBroker extends e{render(){return t` <style>
        :host {
          display: block;
        }

        :host([hidden]) {
          display: none;
        }
      </style>
      <slot></slot>`}static get haxProperties(){return{}}static get properties(){return{...super.properties,archive:{type:Object},datUrl:{type:String,attribute:"dat-url"}}}static get tag(){return"beaker-broker"}firstUpdated(){"undefined"==typeof DatArchive&&console.warn("Beaker is not available from this site loading methodology")}constructor(){super(),this.datUrl=globalThis.location.host}updated(e){e.forEach(((e,t)=>{"archive"==t&&this.dispatchEvent(new CustomEvent("archive-changed",{detail:{value:this[t]}})),"datUrl"==t&&(this._datUrlChanged(this[t]),this.dispatchEvent(new CustomEvent("dat-url-changed",{detail:{value:this[t]}})))}))}async _datUrlChanged(e){"undefined"!=typeof DatArchive&&e&&(this.archive=new DatArchive(e))}async write(e,t){await this.archive.writeFile(e,t)}async read(e,t){var a,r="utf8";switch(t){case"jpeg":case"jpg":r="binary";var i=await this.archive.readFile(e,r),s=new Blob([i],{type:"image/jpeg"});a=URL.createObjectURL(s);break;case"png":r="binary";i=await this.archive.readFile(e,r),s=new Blob([i],{type:"image/png"});a=URL.createObjectURL(s);break;case"base64":a="data:image/png;base64,"+await this.archive.readFile(e,t);break;default:a=await this.archive.readFile(e,t)}return await a}}customElements.define(BeakerBroker.tag,BeakerBroker);export{BeakerBroker};