{"version":3,"file":"main.C2ra1b.js","sources":["theme-138/virtual:theme","theme-138/discourse/api-initializers/theme-initializer.gjs","theme-138/virtual:entrypoint:main"],"sourcesContent":["import { getObjectForTheme } from \"discourse/lib/theme-settings-store\";\n\nexport const settings = getObjectForTheme(138);\n\nexport function themePrefix(key) {\n  return `theme_translations.138.${key}`;\n}\n","import { apiInitializer } from \"discourse/lib/api\";\nimport { iconHTML } from \"discourse-common/lib/icon-library\";\n\nexport default apiInitializer((api) => {\n  const buttonIcon = iconHTML(\"rocket\");\n  const buttonText = \"Commission\";\n  const buttonClasses = \"btn-primary btn btn-icon-text commission-btn\";\n  \n  const freeSignupsUsers = [\n     // old user prior to moving the email form handling to mothership (dev topic 42110).\n    \"discoursefreesignups\",\n    \"meta_free-signups\"\n  ]\n  // meta_free-signups\n  // the <p> tag that wraps around the desired domain it's the fourth one from the end\n  const subdomainSelector = \"> p:nth-last-child(4)\";\n  \n  const linkGen = (name, subdomain) => {\n    return `https://api.discourse.org/admin/hosted_sites/new?type=free&name=${name}&primary_hostname=${subdomain}.discourse.group`;\n  };\n  \n  const buttonGen = link => {\n    const button = $(\"<a>\", {\n      href: link,\n      class: buttonClasses,\n      target: \"_blank\",\n      html: `${buttonIcon + buttonText}`\n    });\n    return button;\n  };\n  \n  const foobar = ($elem, helper) => {\n    if (!helper) return;\n  \n    const post = helper.getModel();\n    const isPM = post.topic?.archetype === \"private_message\";\n  \n    if (!isPM) return;\n\n    if (!freeSignupsUsers.includes(post.username)) return;\n\n    // div that wraps around desired domain\n    const subdomainDiv = $(subdomainSelector, $elem);\n    \n  \n    if (!subdomainDiv.length) return;\n\n    const subdomain = subdomainDiv\n      .text()\n      .trim()\n     // .split(/\\r?\\n/)[1]\n      .split(\".\", 1)[0];\n\n    // hosted site names should not have \"-\" in them\n    if (subdomain.includes(\"-\")) {\n      var name = subdomain.replaceAll(\"-\", \"_\");\n    }\n    else {\n      var name = subdomain;\n    }\n\n    const link = linkGen(name, subdomain);\n    \n    // append the button\n    subdomainDiv.after(buttonGen(link));\n  };\n  \n  // call a decorator with the function we named above. The onlyStream option\n  // makes the decorator ignore the composer preview\n  api.decorateCooked(foobar, { onlyStream: true });\n});\n","import * as Mod1 from \"./discourse/api-initializers/theme-initializer\";\nconst compatModules = {\n  \"discourse/api-initializers/theme-initializer\": Mod1,\n};\nexport { compatModules };\nexport default compatModules;\n"],"names":["getObjectForTheme","themeInitializer","apiInitializer","api","buttonIcon","iconHTML","freeSignupsUsers","decorateCooked","foobar","$elem","helper","post","getModel","topic","archetype","includes","username","subdomainDiv","$","length","subdomain","text","trim","split","name","replaceAll","link","linkGen","after","href","class","target","html","buttonGen","onlyStream","compatModules"],"mappings":";AAEwBA,EAAkB;;ACC1C,IAAAC;oCAAeC,CAAgBC,IAC7B,MAAMC,EAAaC,EAAS,UAItBC,EAAmB,CAEvB,uBACA;AA0DFH,EAAII,eAtCWC,CAACC,EAAOC,KACrB,IAAKA,EAAQ;AAEb,MAAMC,EAAOD,EAAOE;AAGpB,KAFuC,oBAA1BD,EAAKE,OAAOC,WAEd;AAEX,IAAKR,EAAiBS,SAASJ,EAAKK,UAAW;AAG/C,MAAMC,EAAeC,EA3BG,wBA2BkBT;AAG1C,IAAKQ,EAAaE,OAAQ;AAE1B,MAAMC,EAAYH,EACfI,OACAC,OAEAC,MAAM,IAAK,GAAG;AAGjB,GAAIH,EAAUL,SAAS,KACrB,IAAIS,EAAOJ,EAAUK,WAAW,IAAK;KAGjCD,EAAOJ;AAGb,MAAMM,EA5CQC,EAACH,EAAMJ,IACd,mEAAmEI,sBAAyBJ,oBA2CtFO,CAAQH,EAAMJ;AAG3BH,EAAaW,MA3CGF,IACDR,EAAE,MAAO,CACtBW,KAAMH,EACNI,MAlBkB,+CAmBlBC,OAAQ,SACRC,KAAS5B,EArBM,eA2DE6B,CAAUP,KAKJ,CAAEQ,YAAY;ACpEtC,MAACC,EAAgB,CACpB;"}