"use strict";function _createForOfIteratorHelper(a,b){var c;if("undefined"==typeof Symbol||null==a[Symbol.iterator]){if(Array.isArray(a)||(c=_unsupportedIterableToArray(a))||b&&a&&"number"==typeof a.length){c&&(a=c);var d=0,e=function(){};return{s:e,n:function n(){return d>=a.length?{done:!0}:{done:!1,value:a[d++]}},e:function e(a){throw a},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var f,g=!0,h=!1;return{s:function s(){c=a[Symbol.iterator]()},n:function n(){var a=c.next();return g=a.done,a},e:function e(a){h=!0,f=a},f:function f(){try{g||null==c["return"]||c["return"]()}finally{if(h)throw f}}}}function _unsupportedIterableToArray(a,b){if(a){if("string"==typeof a)return _arrayLikeToArray(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?_arrayLikeToArray(a,b):void 0}}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}request("/ad/my/created-ads","GET").then(function(a){if(0===a.length)return $("#running-ads").empty().append("<p>You have not created any ads.</p>");$("#running-ads").empty();var b,c=[],d=[],e=_createForOfIteratorHelper(a);try{for(e.s();!(b=e.n()).done;){var f=b.value,g=window.subsitutionimageurl;f.imageUrl&&(g=f.imageUrl),f.title&&""!=f.title||(f.title="N/A");var h="",i="";1===f.adType?(h="Catalog",d.push(f.adRedirectId),i="<a href=\"/catalog/"+f.adRedirectId+"\"/<span data-catalogid=\""+f.adRedirectId+"\">Loading...</span></a>"):2===f.adType?(h="Group",c.push(f.adRedirectId),i="<a href=\"/groups/"+f.adRedirectId+"\"/<span data-groupid=\""+f.adRedirectId+"\">Loading...</span></a>"):3===f.adType&&(h="Forum Thread",i="<a href=\"/forum/thread/"+f.adRedirectId+"?page=1\">Forum Thread</a>");var j="<p style=\"font-weight:500;cursor:pointer;\" class=\"onClickRunAd\" data-id=\""+f.adId+"\">Status: <span style=\"color:red;\">Not Running</span> (click me to run)</p>";0!==f.bidAmount&&moment(f.updatedAt).add(24,"hours").isSameOrAfter(moment())&&(j="<p style=\"font-weight:500;\">Status: <span style=\"color:green;\">Running</span> (for "+moment(f.updatedAt).fromNow(!0)+")</p>");var k="<p>Error</p>";1===f.adDisplayType?k="<a href=\"".concat(g,"\" target=\"_blank\"><img src=\"").concat(g,"\" style=\"width:100%;height:auto;display:block;margin:0 auto;max-width:700px;\" /></a>"):2===f.adDisplayType&&(k="<a href=\"".concat(g,"\" target=\"_blank\"><img src=\"").concat(g,"\" style=\"width:80px;height:auto;display:block;margin:0 auto;max-width:160px;\" /></a>")),$("#running-ads").append("\n        \n        <div class=\"row\">\n            <div class=\"col-6 col-md-4 col-lg-3\">\n                ".concat(k,"\n            </div>\n            <div class=\"col-6 col-md-8 col-lg-9\">\n                <h2 style=\"font-size:1.25rem;margin-bottom:0;\">").concat(f.title.escape(),"</h2>\n                <p>").concat(h," advertisement for ").concat(i,"</p>\n                ").concat(j,"\n            </div>\n            <div class=\"col-12\">\n                <p>Stats:</p>\n                <div class=\"row\">\n                    <div class=\"col-6 col-lg-3\">\n                        <p title=\"Clicks: ").concat(f.clicks,"\">CTR: ").concat(0===f.clicks?0:Math.trunc(100*(f.clicks/f.views)),"%</p>\n                    </div>\n                    <div class=\"col-6 col-lg-3\">\n                        <p>Views: ").concat(number_format(f.views),"</p>\n                    </div>\n                    <div class=\"col-6 col-lg-3\">\n                        <p title=\"Total Clicks: ").concat(f.totalClicks,"\">Total CTR: ").concat(0===f.totalClicks?0:Math.trunc(100*(f.totalClicks/f.totalViews)),"%</p>\n                    </div>\n                    <div class=\"col-6 col-lg-3\">\n                        <p>Total Views: ").concat(number_format(f.totalViews),"</p>\n                    </div>\n                </div>\n            </div>\n            <div class=\"col-12\">\n                <hr />\n            </div>\n        </div>\n\n        \n        "))}}catch(a){e.e(a)}finally{e.f()}setGroupNames(c),setCatalogNames(d)})["catch"](function(){$()}),$(document).on("click",".onClickRunAd",function(a){a.preventDefault();var b=$(this).attr("data-id");question("How much primary currency would you like to bid?",function(a){if(a)return a=parseInt(a,10),isNaN(a)||1e5<a||1>a?warning("Please specify a valid number between 1 and 100,000."):void(loading(),request("/ad/"+b+"/bid","POST",{amount:a}).then(function(){return success("Your bid has been placed.",function(){window.location.reload()})})["catch"](function(a){warning(a.responseJSON.message)}))})});