{"version":3,"file":"virtual_main.js","sources":["theme-14/virtual:init-settings","theme-14/virtual:theme","theme-14/discourse/components/custom-header-topic-button.gjs","theme-14/discourse/initializers/initialize-header-new-topic-button.gjs","theme-14/virtual:main"],"sourcesContent":["import { registerSettings } from \"discourse/lib/theme-settings-store\";\n\nregisterSettings(14, {\n  \"new_topic_button_icon\": \"\",\n  \"new_topic_button_text\": \"Ask the Community\",\n  \"new_topic_button_title\": \"\",\n  \"hide_default_button\": false,\n  \"show_to_anon\": true\n});\n","import { getObjectForTheme } from \"discourse/lib/theme-settings-store\";\n\nexport const settings = getObjectForTheme(14);\n\nexport function themePrefix(key) {\n  return `theme_translations.14.${key}`;\n}\n","import Component from \"@glimmer/component\";\nimport { getOwner } from \"@ember/application\";\nimport { action } from \"@ember/object\";\nimport { service } from \"@ember/service\";\nimport DButton from \"discourse/components/d-button\";\nimport DButtonTooltip from \"discourse/components/d-button-tooltip\";\nimport routeAction from \"discourse/helpers/route-action\";\nimport Category from \"discourse/models/category\";\nimport i18n from \"discourse-common/helpers/i18n\";\nimport I18n from \"discourse-i18n\";\nimport DTooltip from \"float-kit/components/d-tooltip\";\n\nexport default class CustomHeaderTopicButton extends Component {\n  @service composer;\n  @service currentUser;\n  @service router;\n  @service siteSettings;\n\n  canCreateTopic = this.currentUser?.can_create_topic;\n\n  topic = this.router.currentRouteName.includes(\"topic\")\n    ? getOwner(this).lookup(\"controller:topic\")\n    : null;\n\n  get userHasDraft() {\n    return this.currentUser?.get(\"has_topic_draft\");\n  }\n\n  get currentTag() {\n    if (this.router.currentRoute.attributes?.tag?.id) {\n      return [\n        this.router.currentRoute.attributes?.tag?.id,\n        ...(this.router.currentRoute.attributes?.additionalTags ?? []),\n      ]\n        .filter(Boolean)\n        .filter((t) => ![\"none\", \"all\"].includes(t))\n        .join(\",\");\n    } else {\n      return this.topic?.model?.tags?.join(\",\");\n    }\n  }\n\n  get currentCategory() {\n    return (\n      this.router.currentRoute.attributes?.category ||\n      (this.topic?.model?.category_id\n        ? Category.findById(this.topic?.model?.category_id)\n        : null)\n    );\n  }\n\n  get canCreateTopicWithTag() {\n    return (\n      !this.router.currentRoute.attributes?.tag?.staff ||\n      this.currentUser?.staff\n    );\n  }\n\n  get canCreateTopicWithCategory() {\n    return !this.currentCategory || this.currentCategory?.permission;\n  }\n\n  get createTopicDisabled() {\n    if (this.userHasDraft) {\n      return false;\n    } else {\n      return (\n        !this.canCreateTopic ||\n        !this.canCreateTopicWithCategory ||\n        !this.canCreateTopicWithTag\n      );\n    }\n  }\n\n  get createTopicLabel() {\n    return this.userHasDraft\n      ? I18n.t(\"topic.open_draft\")\n      : settings.new_topic_button_text;\n  }\n\n  get createTopicTitle() {\n    if (!this.userHasDraft && settings.new_topic_button_title.length) {\n      return settings.new_topic_button_title;\n    } else {\n      return this.createTopicLabel;\n    }\n  }\n\n  get showDisabledTooltip() {\n    return this.createTopicDisabled && !this.currentCategory?.read_only_banner;\n  }\n\n  @action\n  createTopic() {\n    this.composer.openNewTopic({\n      preferDraft: true,\n      category: this.currentCategory,\n      tags: this.currentTag,\n    });\n  }\n\n  <template>\n    {{#if this.currentUser}}\n      <DButtonTooltip>\n        <:button>\n          <DButton\n            @action={{this.createTopic}}\n            @translatedLabel={{this.createTopicLabel}}\n            @translatedTitle={{this.createTopicTitle}}\n            @icon={{settings.new_topic_button_icon}}\n            id=\"new-create-topic\"\n            class=\"btn-default header-create-topic\"\n            disabled={{this.createTopicDisabled}}\n          />\n        </:button>\n        <:tooltip>\n          {{#if this.showDisabledTooltip}}\n            <DTooltip\n              @icon=\"info-circle\"\n              @content={{i18n (themePrefix \"button_disabled_tooltip\")}}\n            />\n          {{/if}}\n        </:tooltip>\n      </DButtonTooltip>\n    {{else if settings.show_to_anon}}\n      <DButton\n        @action={{routeAction \"showLogin\"}}\n        @translatedLabel={{this.createTopicLabel}}\n        @translatedTitle={{this.createTopicTitle}}\n        @icon={{settings.new_topic_button_icon}}\n        id=\"new-create-topic\"\n        class=\"btn-default header-create-topic\"\n      />\n    {{/if}}\n  </template>\n}\n","import { apiInitializer } from \"discourse/lib/api\";\nimport CustomHeaderTopicButton from \"../components/custom-header-topic-button\";\n\nexport default apiInitializer(\"1.15.0\", (api) => {\n  api.renderInOutlet(\"before-header-panel\", CustomHeaderTopicButton);\n});\n","import \"virtual:init-settings\";\n\nconst themeCompatModules = {};\nimport * as Mod1 from \"./discourse/components/custom-header-topic-button\";\nthemeCompatModules[\"discourse/components/custom-header-topic-button\"] = Mod1;\n\nimport * as Mod2 from \"./discourse/initializers/initialize-header-new-topic-button\";\nthemeCompatModules[\"discourse/initializers/initialize-header-new-topic-button\"] = Mod2;\n\nexport default themeCompatModules;\n"],"names":["registerSettings","new_topic_button_icon","new_topic_button_text","new_topic_button_title","hide_default_button","show_to_anon","settings","getObjectForTheme","themePrefix","key","CustomHeaderTopicButton","Component","static","dt7948","g","this","prototype","service","composer","i","currentUser","router","siteSettings","canCreateTopic","can_create_topic","topic","currentRouteName","includes","getOwner","lookup","userHasDraft","get","currentTag","currentRoute","attributes","tag","id","additionalTags","filter","Boolean","t","join","model","tags","currentCategory","category","category_id","Category","findById","canCreateTopicWithTag","staff","canCreateTopicWithCategory","permission","createTopicDisabled","createTopicLabel","I18n","createTopicTitle","length","showDisabledTooltip","read_only_banner","createTopic","openNewTopic","preferDraft","n","action","setComponentTemplate","createTemplateFactory","block","moduleName","scope","DButtonTooltip","DButton","DTooltip","i18n","routeAction","isStrictMode","initializeHeaderNewTopicButton","apiInitializer","api","renderInOutlet","themeCompatModules","Mod1","Mod2"],"mappings":";AAEAA,EAAiB,GAAI,CACnBC,sBAAyB,GACzBC,sBAAyB,oBACzBC,uBAA0B,GAC1BC,qBAAuB,EACvBC,cAAgB;ACLX,MAAMC,EAAWC,EAAkB;AAEnC,SAASC,EAAYC,GAC1B,MAAO,yBAAyBA,GAClC,CCMe,MAAMC,UAAgCC,EAAAC,cAAAC,OAAAC,EAAAC,KAAAC,sBAClDC;AAAAC,GAAA,MAAAL,OA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