"use strict";var U=Object.create;var p=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var M=Object.getPrototypeOf;var O=Object.prototype.hasOwnProperty;var w=(r,e)=>p(r,"name",{value:e,configurable:true});var T=(r,e)=>{for(var t in e)p(r,t,{get:e[t],enumerable:true})};var P=(r,e,t,i)=>{if(e&&typeof e==="object"||typeof e==="function"){for(let s of W(e))if(!O.call(r,s)&&s!==t)p(r,s,{get:()=>e[s],enumerable:!(i=v(e,s))||i.enumerable})}return r};var l=(r,e,t)=>(t=r!=null?U(M(r)):{},P(e||!r||!r.__esModule?p(t,"default",{value:r,enumerable:true}):t,r));var j=r=>P(p({},"__esModule",{value:true}),r);var y=(r,e,t,i)=>{var s=i>1?void 0:i?v(e,t):e;for(var a=r.length-1,o;a>=0;a--)if(o=r[a])s=(i?o(e,t,s):o(s))||s;if(i&&s)p(e,t,s);return s};var V={};T(V,{default:()=>J});module.exports=j(V);var f=require("react/jsx-runtime");var S=require("fs-extra");var D=require("mobx");var m=require("mobx-react");var E=require("react");var I=l(require("../../components/settings/recipes/RecipesDashboard"));var C=l(require("../../components/util/ErrorBoundary"));var F=l(require("../../components/util/WithParams"));var d=require("../../config");var L=require("../../environment-remote");var g=require("../../features/communityRecipes");var x=require("../../helpers/asar-helpers");var _=require("../../helpers/url-helpers");var B=l(require("../../models/RecipePreview"));let u=class extends E.Component{autorunDisposer=null;customRecipes=[];constructor(e){super(e);this.customRecipes=(0,S.readJsonSync)((0,x.asarRecipesPath)("all.json"));this.state={needle:null,currentFilter:"featured"}}componentDidMount(){this.autorunDisposer=(0,D.autorun)(()=>{const{filter:e}=this.props.params;const{currentFilter:t}=this.state;if(e==="all"&&t!=="all"){this.setState({currentFilter:"all"})}else if(e==="featured"&&t!=="featured"){this.setState({currentFilter:"featured"})}else if(e==="dev"&&t!=="dev"){this.setState({currentFilter:"dev"})}})}componentWillUnmount(){this.props.stores.services.resetStatus();if(typeof this.autorunDisposer==="function"){this.autorunDisposer()}}searchRecipes(e){if(e===""){this.resetSearch()}else{const{search:t}=this.props.actions.recipePreview;this.setState({needle:e});t({needle:e})}}_sortByName(e,t){if(e.name.toLowerCase()<t.name.toLowerCase()){return-1}if(e.name.toLowerCase()>t.name.toLowerCase()){return 1}return 0}prepareRecipes(e){return e.filter((t,i,s)=>{const a=s.map(o=>o.id);return a.indexOf(t.id)===i}).sort(this._sortByName)}createPreviews(e){return e.map(t=>new B.default(t))}resetSearch(){this.setState({needle:null,currentFilter:"featured"})}render(){const{recipePreviews:e,recipes:t,services:i}=this.props.stores;const{app:s,service:a}=this.props.actions;const o=this.state.currentFilter;let c;if(o==="all"){c=this.prepareRecipes([...e.all,...this.createPreviews(this.customRecipes)])}else if(o==="dev"){c=g.communityRecipesStore.communityRecipes}else{c=e.featured}c=[...c].sort(this._sortByName);const{needle:h}=this.state;const b=h===null?c:this.prepareRecipes([...e.searchResults,...this.createPreviews(this.customRecipes.filter(n=>n.name.toLowerCase().includes(h.toLowerCase())||(n.aliases||[]).some(A=>A.toLowerCase().includes(h.toLowerCase()))))]).sort(this._sortByName);const q=e.all.find(n=>n.id===d.CUSTOM_WEBSITE_RECIPE_ID);const N=e.featuredRecipePreviewsRequest.isExecuting||e.allRecipePreviewsRequest.isExecuting||t.installRecipeRequest.isExecuting||e.searchRecipePreviewsRequest.isExecuting;const R=(0,L.userDataRecipesPath)("dev");return(0,f.jsx)(C.default,{children:(0,f.jsx)(I.default,{recipes:b,customWebsiteRecipe:q,isLoading:N,hasLoadedRecipes:e.featuredRecipePreviewsRequest.wasExecuted,showAddServiceInterface:a.showAddServiceInterface,searchRecipes:n=>this.searchRecipes(n),resetSearch:()=>this.resetSearch(),searchNeedle:this.state.needle,serviceStatus:i.actionStatus,recipeFilter:o,recipeDirectory:R,openRecipeDirectory:()=>(0,_.openPath)(R),openDevDocs:()=>s.openExternalUrl({url:d.FERDIUM_DEV_DOCS})})})}};w(u,"RecipesScreen");u=y([(0,m.inject)("stores","actions"),m.observer],u);var J=(0,F.default)(u);
