import { r as registerInstance, e as createEvent, B as Build, h } from './index-e0adbd54.js';
import { C as ClipboardJS } from './clipboard-dc04d59f.js';
import './_commonjsHelpers-44457d8d.js';

const shareCss = "fireenjin-share ion-item:hover{cursor:pointer}fireenjin-share .share-twitter ion-icon{color:#1da1f3}fireenjin-share .share-twitter ion-icon svg{fill:#1da1f3}fireenjin-share .share-twitter:hover .item{color:#1da1f3}fireenjin-share .share-facebook ion-icon{color:#3b5998}fireenjin-share .share-facebook ion-icon svg{fill:#3b5998}fireenjin-share .share-facebook:hover .item{color:#3b5998}fireenjin-share .share-google ion-icon{color:#dd4b38}fireenjin-share .share-google ion-icon svg{fill:#dd4b38}fireenjin-share .share-google:hover .item{color:#dd4b38}";

const Share = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.fireenjinShareClose = createEvent(this, "fireenjinShareClose", 7);
    this.facebookAppId = undefined;
    this.url = undefined;
    this.text = undefined;
    this.subject = undefined;
    this.lines = undefined;
  }
  // Implementation Example
  // import { SocialSharing } from "@ionic-native/social-sharing";
  //
  // @Listen("fireenjinShare")
  // async share(event) {
  //   try {
  //     if (navigator?.share) {
  //       await navigator.share(event.detail.data);
  //       return;
  //     }
  //     if (!navigator?.share) {
  //       this.sharePopover = await popoverController.create({
  //         event: event.detail.event,
  //         component: "fireenjin-share",
  //         componentProps: event.detail.data,
  //       });
  //       this.sharePopover.present();
  //       return;
  //     }
  //     await SocialSharing.share(
  //       event.detail.data.message,
  //       event.detail.data.subject,
  //       event.detail.data.file,
  //       event.detail.data.url
  //     );
  //   } catch (e) {
  //     console.log("Error using share functionality...", e);
  //   }
  // }
  openPopup(event, type) {
    event.preventDefault();
    let popupUrl;
    if (type === "facebook") {
      popupUrl = `https://www.facebook.com/dialog/share?app_id=${this.facebookAppId}&display=popup&href=${this.url}`;
    }
    else if (type === "google") {
      popupUrl = `https://plus.google.com/share?url=${this.url}`;
    }
    else if (type === "twitter") {
      popupUrl = `https://twitter.com/intent/tweet?url=${this.url}&text=${this.text}`;
    }
    else {
      return false;
    }
    this.fireenjinShareClose.emit({ event, type });
    window.open(popupUrl, "Share", type === "google" ? "height=600,width=400" : "height=400,width=600");
  }
  componentDidLoad() {
    if (!(Build === null || Build === void 0 ? void 0 : Build.isBrowser))
      return;
    {
      new ClipboardJS(this.copyItemEl);
    }
  }
  render() {
    return (h("ion-list", null, h("ion-item", { lines: this.lines, class: "share-twitter", onClick: (event) => this.openPopup(event, "twitter") }, h("ion-icon", { slot: "end", name: "logo-twitter" }), "Share on Twitter"), h("ion-item", { lines: this.lines, class: "share-facebook", onClick: (event) => this.openPopup(event, "facebook") }, h("ion-icon", { slot: "end", name: "logo-facebook" }), "Share on Facebook"), h("ion-item", { lines: this.lines, ref: (el) => (this.copyItemEl = el), class: "share-clipboard", "data-clipboard-text": this.url }, h("ion-icon", { slot: "end", name: "clipboard" }), "Copy to Clipboard")));
  }
};
Share.style = shareCss;

export { Share as fireenjin_share };
