(function(){
  var i18n = window.CALLIOPE_SP_ADMIN_I18N || {};

  function t(key, fallback){
    return i18n[key] || fallback;
  }

  function getLink(){
    var el = document.getElementById('calliope_sp_link');
    return el ? (el.value || '').trim() : '';
  }
  document.addEventListener('DOMContentLoaded', function(){
    var btn = document.getElementById('calliope-sp-fb-share-group');
    if (!btn) return;
    btn.addEventListener('click', function(e){
      e.preventDefault();
      var href = getLink();
      if (!href) {
        alert(t('pasteLinkFirst', 'Paste a link to share first.'));
        return;
      }
      var u = 'https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(href);
      window.open(u, 'fbshare', 'width=600,height=650');
    });
  });
})();
