{"version":3,"sources":["discourse/templates//connectors/category-heading/mind-category-subscribe-button.js","discourse/initializers/theme-field-44-common-html-script-1.js"],"names":["window","define","_exports","_templateFactory","Object","defineProperty","value","default","_default","createTemplateFactory","id","block","moduleName","isStrictMode","_pluginApi","require","getObjectForTheme","name","after","false","initialize","withPluginApi","api","ajax","createWidget","tagName","buildClasses","attrs","state","classNames","isSubscribed","this","_is_subscribed","currentCategory","read_restricted","push","defaultState","loading","_get_category","Discourse","__container__","lookup","category","categoryId","user","currentUser","tracked_category_ids","indexOf","watched_category_ids","watched_first_post_category_ids","html","click","_notification_level","type","data","notification_level","then","response","success","setNotification","location","url","alert"],"mappings":"AAAI,WAAYA,QAChBC,OAAO,oGAAqG,CAAC,UAAW,4BAA4B,SAAUC,EAAUC,GACtK;AAEAC,OAAOC,eAAeH,EAAU,aAAc,CAC5CI,OAAO,IAETJ,EAASK,aAAU;AACnB,IAAIC,GAAW,EAAIL,EAAiBM,uBAUpC,CACEC,GAAM,KACNC,MAAS,gOACTC,WAAc,oGACdC,cAAgB;AAElBX,EAASK,QAAUC,CACrB,ICzBI,WAAYR,QAChBC,OAAO,qEAAsE,CAAC,UAAW,6BAA6B,SAAUC,EAAUY,GACxI;AAEAV,OAAOC,eAAeH,EAAU,aAAc,CAC5CI,OAAO,IAETJ,EAASK,aAAU;AACFQ,QAAQ,sCAAsCC,kBAAkB;AAEjF,IAAIR,EAAW,CACbS,KAAM,sCACNC,MAAO,iBACPC,UAAAC,IACE,EAAIN,EAAWO,eAAe,OAAOC,IACnC,MAAMC,EAAOR,QAAQ,sBAAsBQ;AAC3CD,EAAIE,aAAa,iCAAkC,CACjDC,QAAS,SACTN,YAAAO,CAAaC,EAAOC,GAClB,IAAIC,EAAa,CAAC,MAAO,cAAe;AAMxC,OAL2B,OAAvBD,EAAME,cACRC,KAAKC,iBAIHD,KAAKH,MAAMK,gBAAgBC,iBAC7BL,EAAWM,KAAK,UACTN,IAELD,EAAME,cACRD,EAAWM,KAAK,aAEX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ates//connectors/category-heading/mind-category-subscribe-button\", [\"exports\", \"@ember/template-factory\"], function (_exports, _templateFactory) {\n  \"use strict\";\n\n  Object.defineProperty(_exports, \"__esModule\", {\n    value: true\n  });\n  _exports.default = void 0;\n  var _default = (0, _templateFactory.createTemplateFactory)(\n  /*\n    \n      {{#if currentUser}}\n      <div>\n          {{mount-widget widget=\"mind-category-subscribe-button\"}}\n      </div>\n      {{/if}}\n  \n  */\n  {\n    \"id\": null,\n    \"block\": \"[[[1,\\\"\\\\n\\\"],[41,[33,1],[[[1,\\\"    \\\"],[10,0],[12],[1,\\\"\\\\n        \\\"],[1,[28,[35,2],null,[[\\\"widget\\\"],[\\\"mind-category-subscribe-button\\\"]]]],[1,\\\"\\\\n    \\\"],[13],[1,\\\"\\\\n\\\"]],[]],null]],[],false,[\\\"if\\\",\\\"currentUser\\\",\\\"mount-widget\\\"]]\",\n    \"moduleName\": \"discourse/theme-9/discourse/templates//connectors/category-heading/mind-category-subscribe-button\",\n    \"isStrictMode\": false\n  });\n  _exports.default = _default;\n});\n}\n","if ('define' in window) {\ndefine(\"discourse/theme-9/initializers/theme-field-44-common-html-script-1\", [\"exports\", \"discourse/lib/plugin-api\"], function (_exports, _pluginApi) {\n  \"use strict\";\n\n  Object.defineProperty(_exports, \"__esModule\", {\n    value: true\n  });\n  _exports.default = void 0;\n  const settings = require(\"discourse/lib/theme-settings-store\").getObjectForTheme(9);\n  const themePrefix = key => `theme_translations.9.${key}`;\n  var _default = {\n    name: \"theme-field-44-common-html-script-1\",\n    after: \"inject-objects\",\n    initialize() {\n      (0, _pluginApi.withPluginApi)(\"0.8\", api => {\n        const ajax = require(\"discourse/lib/ajax\").ajax;\n        api.createWidget('mind-category-subscribe-button', {\n          tagName: 'button',\n          buildClasses(attrs, state) {\n            let classNames = [\"btn\", \"btn-default\", \"mind-category-subscribe-button\"];\n            if (state.isSubscribed === null) {\n              this._is_subscribed();\n            }\n\n            // Hide this for private categories\n            if (this.state.currentCategory.read_restricted) {\n              classNames.push(\"hidden\");\n              return classNames;\n            }\n            if (state.isSubscribed) {\n              classNames.push(\"btn-leave\");\n            }\n            return classNames;\n          },\n          defaultState() {\n            return {\n              currentCategory: null,\n              isSubscribed: null,\n              loading: false\n            };\n          },\n          _get_category() {\n            if (this.state.currentCategory === null) {\n              this.state.currentCategory = Discourse.__container__.lookup('controller:navigation/category').category;\n            }\n            return this.state.currentCategory;\n          },\n          _is_subscribed() {\n            if (this.state.isSubscribed !== null) {\n              return this.state.isSubscribed;\n            }\n            const categoryId = this._get_category().id;\n            const user = this.currentUser;\n            if (user.tracked_category_ids.indexOf(categoryId) !== -1 || user.watched_category_ids.indexOf(categoryId) !== -1 || user.watched_first_post_category_ids.indexOf(categoryId) !== -1) {\n              this.state.isSubscribed = true;\n            } else {\n              this.state.isSubscribed = false;\n            }\n            return this.state.isSubscribed;\n          },\n          html(attrs, state) {\n            if (state.isSubscribed === null) {\n              this._is_subscribed();\n            }\n            if (this.state.currentCategory.read_restricted) {\n              return \"\";\n            }\n            return state.isSubscribed ? \"Leave this group\" : \"Join this group\";\n          },\n          click() {\n            if (this.state.loading || this.state.currentCategory.read_restricted) {\n              // No need for further processing if already doing something or this is a private category\n              return;\n            }\n            const category = this._get_category();\n            if (category) {\n              // Set notification level to \"Watching\" when joining, and \"Normal\" when leaving\n              // Levels:\n              // 1 - Normal\n              // 2 - Tracking\n              // 3 - Watching\n              const _notification_level = this.state.isSubscribed ? \"1\" : \"3\";\n              this.state.loading = true;\n              ajax(`/category/${category.id}/notifications`, {\n                type: 'POST',\n                data: {\n                  notification_level: _notification_level\n                }\n              }).then(response => {\n                if (response.success) {\n                  category.setNotification(_notification_level);\n                  window.location = category.url;\n                } else {\n                  alert(\"Failed to subscribe. Try again.\");\n                }\n                this.state.loading = false;\n              });\n            }\n          }\n        });\n      });\n    }\n  };\n  _exports.default = _default;\n});\n}\n"]}