const BaseExtractor = require('./base');

class AskGamblers extends BaseExtractor {
  constructor() { super(); this.patterns = [/askgamblers\.com/]; }
  getExtractCode() {
    return (
      "(function(){var R=[],S={};for(var c of document.querySelectorAll('.ag-search-hottest-item__img,.card__media--overlay')){" +
      "if(R.length>=25)break;var im=c.querySelector('img[alt]');if(!im||!im.alt)continue;" +
      "var a=(im.alt||'').trim();if(!/casino/i.test(a))continue;" +
      "var nm=a.replace(/\\s*Casino$/i,'').trim();if(nm.length<2||S[nm])continue;" +
      "// Walk up to get affiliate link from containing <a>" +
      "var ct=c.parentElement,lnk='';while(ct&&ct!==document.body){try{if(ct.tagName.toLowerCase()==='a'&&ct.href){var u=new URL(ct.href,document.baseURI);if(u.hostname.replace('www.','')!==location.hostname.replace('www','')){lnk=u.origin;break;}}}catch(e){}ct=ct.parentElement;}" +
      "S[nm]=true;R.push({name:nm,link:lnk,bonus:''});}" +
      "return R.slice(0,25);})()"
    );
  }
}

module.exports = AskGamblers;
