import { r as registerInstance, c as createEvent, h, H as Host } from './index-CjTHbolG.js';

const verdocsInitialDialogCss = () => `verdocs-initial-dialog{font-family:"Inter", "Barlow", sans-serif;-webkit-box-sizing:border-box;box-sizing:border-box;position:fixed;z-index:10000;top:0;left:0;right:0;bottom:0;display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;background:rgba(0, 0, 0, 0.4980392157)}verdocs-initial-dialog .dialog{width:100%;max-width:340px;border-radius:4px;overflow:hidden;-webkit-box-shadow:3px 3px 5px 1px rgba(40, 40, 40, 0.4);box-shadow:3px 3px 5px 1px rgba(40, 40, 40, 0.4);background:#f9f9f9}verdocs-initial-dialog .heading{display:-ms-flexbox;display:flex;-ms-flex-direction:row;flex-direction:row;padding:20px 20px 0 20px;line-height:28px;font-size:20px;font-weight:500}verdocs-initial-dialog .content{font-size:14px;padding:20px}verdocs-initial-dialog .buttons{display:-ms-flexbox;display:flex;margin:20px 0 0 0;-ms-flex-direction:row;flex-direction:row;-ms-flex-pack:end;justify-content:flex-end;-ms-flex-align:center;align-items:center}verdocs-initial-dialog .buttons verdocs-button{margin-left:16px}verdocs-initial-dialog canvas{background:#fff;-webkit-box-sizing:border-box;box-sizing:border-box;margin:0 auto;width:300px;height:79px;max-width:100%;-webkit-box-shadow:0 0 6px 0 rgba(0, 0, 0, 0.1215686275);box-shadow:0 0 6px 0 rgba(0, 0, 0, 0.1215686275)}verdocs-initial-dialog .disclaimer{text-align:justify;padding:8px 0;font-size:11px;line-height:14px;color:rgba(0, 0, 0, 0.54)}verdocs-initial-dialog .as-shown{font-size:11px;margin:4px 0 20px 4px;color:rgba(0, 0, 0, 0.54)}verdocs-initial-dialog .tabs{display:-ms-flexbox;display:flex;-ms-flex-direction:row;flex-direction:row}verdocs-initial-dialog .tabs .tab{padding:8px 15px;cursor:pointer}verdocs-initial-dialog .tabs .tab.active{border-bottom:2px solid #cccccc}verdocs-initial-dialog .tabs .tab:hover{color:#55bc81}`;

const VerdocsInitialDialog = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.next = createEvent(this, "next");
        this.exit = createEvent(this, "exit");
        /**
         * Initial signature text
         */
        this.initials = '';
        this.fontLoaded = false;
        this.enteredInitials = '';
        this.mode = 'type';
    }
    componentWillLoad() {
        this.enteredInitials = this.initials.toUpperCase();
        const ds = new FontFace('Dancing Script', 'url(https://fonts.gstatic.com/s/dancingscript/v19/If2cXTr6YS-zF4S-kcSWSVi_sxjsohD9F50Ruu7BMSo3Sup6hNX6plRP.woff)');
        ds.load().then(font => {
            document.fonts.add(font);
            this.fontLoaded = true;
        });
    }
    componentDidLoad() {
        this.redrawSignature();
    }
    componentDidUpdate() {
        this.redrawSignature();
    }
    redrawSignature() {
        if (!this.canvasElement) {
            return;
        }
        const canvasWidth = this.canvasElement.width;
        const context = this.canvasElement.getContext('2d');
        context.clearRect(0, 0, this.canvasElement.width, this.canvasElement.height);
        let fontSize = 100;
        do {
            fontSize -= 2;
            context.font = `${fontSize}px Dancing Script`;
        } while (context.measureText(this.enteredInitials).width > canvasWidth - 32); // 32px padding each side
        context.textAlign = 'center';
        context.textBaseline = 'middle';
        context.font = `${fontSize}px Dancing Script`;
        context.fillText(this.enteredInitials, this.canvasElement.width / 2, this.canvasElement.height / 2);
    }
    handleNameChange(e) {
        this.enteredInitials = e.target.value;
    }
    handleCancel(e) {
        e.stopPropagation();
        e.preventDefault();
        this.exit.emit();
    }
    handleAdopt(e) {
        e.stopPropagation();
        e.preventDefault();
        const data = this.canvasElement.toDataURL('image/png');
        this.next.emit(data);
    }
    /*
    selColor(hex: string) {
      this.color = hex;
      this.animateDraw();
    }
  
    stopDraw() {
      this.paint = false;
      this.adoptedAndSigned = !this.hasSignature();
    }
  
    draw(e) {
      this.paint = true;
      this.addPoints(e, false);
      this.animateDraw();
    }
  
    recordPoints(e) {
      if (this.paint) {
        this.addPoints(e, true);
        this.animateDraw();
      }
    }
  
    animateDraw() {
      this.canvas.clearRect(0, 0, this.canvas.canvas.offsetWidth, this.canvas.canvas.offsetHeight);
  
      this.canvas.strokeStyle = this.color || '#000000';
      this.canvas.lineJoin = 'round';
      this.canvas.lineWidth = 3;
  
      for (let i = 0; i < this.points.length; i++) {
        this.canvas.beginPath();
        if (this.points[i].drag && i) {
          this.canvas.moveTo(this.points[i - 1].x, this.points[i - 1].y);
          // this.canvas.arc(this.points[i - 1].x, this.points[i - 1].y, 2, 0, 2 * Math.PI, false);
        } else {
          this.canvas.moveTo(this.points[i].x - 1, this.points[i].y);
          // this.canvas.arc(this.points[i].x, this.points[i].y, 2, 0, 2 * Math.PI, false);
        }
  
        this.canvas.lineTo(this.points[i].x, this.points[i].y);
        this.canvas.closePath();
        this.canvas.stroke();
      }
    }
  
    drawCurve(color: string, curve: number) {
      this.canvas.beginPath();
    }
  
  
  
    addPoints(e, drag: boolean) {
      if (window) {
        let x;
        let y;
        e.preventDefault();
        if (e.touches && e.touches.length > 0) {
          x = e.touches[0].clientX;
        } else {
          x = e.clientX;
        }
  
        if (e.touches && e.touches.length > 0) {
          y = e.touches[0].clientY;
        } else {
          y = e.clientY;
        }
        const rect = this.signatureCanvas.nativeElement.getBoundingClientRect();
        this.points.push({
          x: x - rect.left,
          y: y - rect.top,
          drag: drag
        });
      }
    }
  
    clearPad() {
      this.canvas.clearRect(0, 0, this.canvas.canvas.offsetWidth, this.canvas.canvas.offsetHeight);
      this.points = [];
      this.adoptedAndSigned = !this.hasSignature();
    }
  
      async adoptAndSign() {
      try {
        this.adoptedAndSigned = true;
        await this.updateFullName();
        await this.captureSignatureFromCanvas();
        const message = this.signatureMode === 'Signature' ? 'Saving Signature' : 'Saving Initial';
        this.snackbarService.open(message, 'OK', this.snackbarService.initConfig(null, 'bottom'));
        this.handleMode();
      } catch (err) {
        this.snackbarService.open('Failed to apply signature', 'OK', this.snackbarService.initConfig(null, 'bottom'));
      }
    }
  
    handleMode() {
      let currentField;
      switch (this.mode) {
        case 'signerview':
          if (this.signatureMode === 'Signature') {
            this.signatureService.postSignatureBlob().then(result => {
              if (result && result.id && result.url) {
                currentField = this.signatureService.currField;
                this.signatureService.updateSigned(currentField.fName, true);
                this.signatureService.toggleSig(false);
                this.signatureService.setSignatureId(result.id);
                this.signatureService.putSignatureField(this.envelopeId, this.fieldName, result.id).then(res => {
                  this.eventTracker.createEvent({
                    category: 'verdoc',
                    action: 'verdoc signed',
                    label: `verdoc id: ${this.envelopeId}`
                  })
                  if (res && res.settings) {
                    this.signatureService.setSignatureData(res.settings.base64);
                    this.signatureService.setSignatureId(res.settings.signature_id);
                  }
                  this.snackbarService.dismiss();
                  this.dialog.close({ status: 'saved', temp_sig: res.settings.base64, sig_id: res.settings.signature_id });
                }).catch(err => {
                  this.snackbarService.open('Failed to save signature. Please try again.', 'DISMISS', {
                    duration: 3000
                  });
                  this.adoptedAndSigned = false;
                  return err;
                });
              }
            });
          } else {
            this.signatureService.postInitialBlob().then(result => {
              if (result && result.id && result.url) {
                currentField = this.signatureService.currField;
                this.signatureService.updateInitialed(currentField.fName, true);
                this.signatureService.setInitialId(result.id);
                this.signatureService.toggleSig(false);
                this.signatureService.putInitialField(this.envelopeId, this.fieldName, result.id).then(res => {
                  if (res && res.settings) {
                    this.signatureService.setInitialData(res.settings.base64);
                    this.signatureService.setInitialId(res.settings.initial_id);
                  }
                  this.snackbarService.dismiss();
                  this.dialog.close({ status: 'saved', temp_int: res.settings.base64, int_id: res.settings.initial_id });
                }).catch(err => {
                  this.snackbarService.open('Failed to save initial. Please try again.', 'DISMISS', {
                    duration: 3000
                  });
                  this.adoptedAndSigned = false;
                  return err;
                });
              }
            });
          }
          break;
      }
    }
     */
    render() {
        return (h(Host, { key: '0b6dd491d0af99d1abe6292f4a6d012a71cd62c7', onClick: e => this.handleCancel(e) }, h("div", { key: '3d2d6486887d049ba2c5f60197aa5f476b922fde', class: "dialog" }, h("div", { key: '186ef3be7f6026cad0bfaa244cd98d8c7183c169', class: "heading" }, "Create Your Initial"), h("div", { key: 'c5e37a3ddbdcac2db94cd56d41db0ecdf58df624', class: "content" }, h("verdocs-text-input", { key: 'ed1c4cc75029610ba03931449e37b7fc3aa437ad', placeholder: "Initials...", label: "Initials", value: this.enteredInitials, onInput: e => this.handleNameChange(e), onClick: e => e.stopPropagation() }), h("div", { key: '1597920974326992c60180a83c63b9ae54280113', class: "as-shown" }, "As shown on driver's license or govt. ID card."), this.fontLoaded ? h("canvas", { ref: el => (this.canvasElement = el) }) : h("div", { style: { display: 'none' } }), h("div", { key: 'd388ed076550e566c711e15a832bd954dd80ba17', class: "disclaimer" }, "By clicking Adopt, I agree that the signature will be the electronic representation of my signature for all purposes when I (or my agent) use them on documents, including legally binding contracts \u2014 just the same as a pen-and-paper signature or initial."), h("div", { key: '1bab8f70eaa8b7bb7eabfd5a64b837ada9879733', class: "buttons" }, h("verdocs-button", { key: '37864544ac1d1b57c67e316cfe1bf524286d5aae', label: "CANCEL", size: "normal", variant: "outline", onClick: e => this.handleCancel(e) }), h("verdocs-button", { key: '586ce5016c2b9b0eaee12c0bfe1757fbffad564f', label: "Adopt & Sign", size: "normal", onClick: e => this.handleAdopt(e) }))))));
    }
};
VerdocsInitialDialog.style = verdocsInitialDialogCss();

export { VerdocsInitialDialog as verdocs_initial_dialog };
//# sourceMappingURL=verdocs-initial-dialog.entry.js.map

//# sourceMappingURL=verdocs-initial-dialog.entry.js.map