{"version":3,"file":"main.D2m6za.js","sources":["theme-32/virtual:theme","theme-32/discourse/connectors/topic-navigation/custom-blocks.gjs","theme-32/virtual:entrypoint:main"],"sourcesContent":["import { getObjectForTheme } from \"discourse/lib/theme-settings-store\";\n\nexport const settings = getObjectForTheme(32);\n\nexport function themePrefix(key) {\n  return `theme_translations.32.${key}`;\n}\n","import Component from \"@glimmer/component\";\nimport { fn } from \"@ember/helper\";\nimport { on } from \"@ember/modifier\";\nimport { action } from \"@ember/object\";\nimport { service } from \"@ember/service\";\nimport htmlSafe from \"discourse/helpers/html-safe\";\nimport { ajax } from \"discourse/lib/ajax\";\n\nexport default class CustomBlocks extends Component {\n  @service router;\n\n  get blocksToDisplay() {\n    const tags = this.args.outletArgs?.topic?.tags || [];\n    let blocks = [];\n\n    try {\n      if (typeof settings.blocks === \"string\") {\n        blocks = JSON.parse(settings.blocks || \"[]\");\n      } else if (Array.isArray(settings.blocks)) {\n        blocks = settings.blocks;\n      }\n    } catch (e) {\n      console.error(\"Error parsing theme settings for 'blocks':\", e);\n    }\n\n    for (const block of blocks) {\n      if (block.tags?.some((tag) => tags.includes(tag))) {\n        return [{\n          content: htmlSafe(block.html),\n          placementID: block.placementID,\n          campaignID: block.campaignID,\n        }];\n      }\n    }\n\n    return [];\n  }\n\n\n@action\n  handleBlockClick(block, event) {\n\n    const apiEndpoint = settings.api_endpoint;\n\n    if (!apiEndpoint) {\n      console.warn(\"API endpoint is not configured.\");\n      return;\n    }\n\n    const payload = {\n      placementID: block.placementID,\n      campaignID: block.campaignID\n    };\n\n    ajax(apiEndpoint, {\n      method: \"POST\",\n      data: payload,\n      headers: {\n        \"Content-Type\": \"application/json\",\n        \"referrer\": document.referrer\n      },\n    })\n      .then((response) => {\n        const href = event.target.getAttribute('href');\n        if (href) {\n          const url = new URL(href);\n          this.router.transitionTo(url.pathname + url.search);\n        }\n      })\n      .catch((error) => {\n        let errorMessage = \"Unknown error occurred.\";\n      if (error.jqXHR.responseJSON) {\n        errorMessage = error.jqXHR.responseJSON.error || JSON.stringify(error.responseJSON);\n      } else if (error.responseText) {\n        errorMessage = error.responseText;\n      }\n        this.createErrorPost({\n          origin: window.location.origin,\n          placementID: block.placementID ? block.placementID : \"none provided\",\n          campaignID: block.campaignID ? block.campaignID : \"none provided\",\n          message: errorMessage,\n        });\n      }\n    );\n  }\n\n  createErrorPost({ origin, placementID, campaignID, message }) {\n    const apiKey = settings.api_key;\n    const apiUsername = \"system\";\n    const categoryID = settings.category_id;\n\n\n    if (!apiKey || !categoryID) {\n      console.warn(\"API key or category ID is not configured.\");\n      return;\n    }\n\n    const topicTitle = `API Error Report: ${placementID || \"Unknown Placement ID\"}`;\n    const topicBody = `\n      **Error Details**:\n      - **Origin**: ${origin}\n      - **Placement ID**: ${placementID}\n      - **Campaign ID**: ${campaignID}\n      - **Error Message**: ${message}\n    `;\n\n    ajax(\"/posts\", {\n      method: \"POST\",\n      data: {\n        title: topicTitle,\n        raw: topicBody,\n        category: categoryID,\n      },\n      headers: {\n        \"Content-Type\": \"application/x-www-form-urlencoded\",\n        \"Api-Key\": apiKey,\n        \"Api-Username\": apiUsername,\n      },\n    })\n      .then((response) => {\n\n      })\n      .catch((error) => {\n        console.error(\"Failed to create error notification topic:\", error);\n      });\n  }\n\n  <template>\n    <div class=\"custom-topic-banner\">\n      {{#each this.blocksToDisplay as |block|}}\n        <div {{on \"click\" (fn this.handleBlockClick block)}}>\n          {{htmlSafe block.content}}\n        </div>\n      {{/each}}\n    </div>\n  </template>\n}\n","import * as Mod1 from \"./discourse/connectors/topic-navigation/custom-blocks.gjs\";\nconst compatModules = {\n  \"discourse/connectors/topic-navigation/custom-blocks\": Mod1,\n};\nexport { compatModules };\nexport default compatModules;\n"],"names":["settings","getObjectForTheme","CustomBlocks","Component","dt7948","g","this","prototype","service","router","i","blocksToDisplay","tags","args","outletArgs","topic","blocks","JSON","parse","Array","isArray","e","console","error","block","some","tag","includes","content","htmlSafe","html","placementID","campaignID","handleBlockClick","event","apiEndpoint","api_endpoint","warn","payload","ajax","method","data","headers","referrer","document","then","response","href","target","getAttribute","url","URL","transitionTo","pathname","search","catch","errorMessage","jqXHR","responseJSON","stringify","responseText","createErrorPost","origin","window","location","message","n","action","apiKey","api_key","categoryID","category_id","title","raw","category","setComponentTemplate","createTemplateFactory","id","moduleName","scope","on","fn","isStrictMode","compatModules"],"mappings":"yoBAEaA,EAAWC,EAAkB;ACM3B,MAAMC,UAAqBC,SAAAC,OAAAC,EAAAC,KAAAC,oBACvCC,GAAA,CAAAC,QAAAL,OAAAM,EAAAJ,KAAA;AAED,mBAAIK,GACF,MAAMC,EAAON,KAAKO,KAAKC,YAAYC,OAAOH,MAAQ;AAClD,IAAII,EAAS;AAEb,IACiC,iBAApBhB,EAASgB,OAClBA,EAASC,KAAKC,MAAMlB,EAASgB,QAAU,MAC9BG,MAAMC,QAAQpB,EAASgB,UAChCA,EAAShB,EAASgB,OAEtB,CAAE,MAAOK,GACPC,QAAQC,MAAM,6CAA8CF,EAC9D,CAEA,IAAK,MAAMG,KAASR,EAClB,GAAIQ,EAAMZ,MAAMa,KAAMC,GAAQd,EAAKe,SAASD,IAC1C,MAAO,CAAC,CACNE,QAASC,EAASL,EAAMM,MACxBC,YAAaP,EAAMO,YACnBC,WAAYR,EAAMQ;AAKxB,MAAO,EACT,CAIAC,gBAAAA,CAAiBT,EAAOU,GAEtB,MAAMC,EAAcnC,EAASoC;AAE7B,IAAKD,EAEH,YADAb,QAAQe,KAAK;AAIf,MAAMC,EAAU,CACdP,YAAaP,EAAMO,YACnBC,WAAYR,EAAMQ;AAGpBO,EAAKJ,EAAa,CAChBK,OAAQ,OACRC,KAAMH,EACNI,QAAS,CACP,eAAgB,mBAChBC,SAAYC,SAASD,YAGtBE,KAAMC,IACL,MAAMC,EAAOb,EAAMc,OAAOC,aAAa;AACvC,GAAIF,EAAM,CACR,MAAMG,EAAM,IAAIC,IAAIJ;AACpBzC,KAAKG,OAAO2C,aAAaF,EAAIG,SAAWH,EAAII,OA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