text: "use strict";(self.webpackChunk=self.webpackChunk||[]).push([["resources_js_components_realization_vue"],{"./resources/js/components/realization.vue":
  /*!*************************************************************!*\
    !*** ./resources/js/components/realization.vue + 4 modules ***!
    \*************************************************************/(__unused_webpack_module,__webpack_exports__,__webpack_require__)=>{eval('// ESM COMPAT FLAG\n__webpack_require__.r(__webpack_exports__);\n\n// EXPORTS\n__webpack_require__.d(__webpack_exports__, {\n  "default": () => (/* binding */ realization)\n});\n\n// EXTERNAL MODULE: ./node_modules/vue/dist/vue.esm-bundler.js\nvar vue_esm_bundler = __webpack_require__("./node_modules/vue/dist/vue.esm-bundler.js");\n;// CONCATENATED MODULE: ./node_modules/babel-loader/lib/index.js!./node_modules/vue-loader/dist/templateLoader.js??ruleSet[1].rules[2]!./node_modules/vue-loader/dist/index.js??ruleSet[0]!./resources/js/components/realization.vue?vue&type=template&id=17a74d0b&scoped=true\n\n\nconst _withId = /*#__PURE__*/(0,vue_esm_bundler.withScopeId)("data-v-17a74d0b");\n\n(0,vue_esm_bundler.pushScopeId)("data-v-17a74d0b");\n\nconst _hoisted_1 = {\n  id: "plans"\n};\n\nconst _hoisted_2 = /*#__PURE__*/(0,vue_esm_bundler.createVNode)("h2", null, "Menu", -1\n/* HOISTED */\n);\n\nconst _hoisted_3 = {\n  id: "menu-list"\n};\nconst _hoisted_4 = {\n  id: "ingredients"\n};\n\nconst _hoisted_5 = /*#__PURE__*/(0,vue_esm_bundler.createVNode)("h2", null, "Menu Foods", -1\n/* HOISTED */\n);\n\nconst _hoisted_6 = {\n  key: 0,\n  id: "food-list"\n};\n\nconst _hoisted_7 = /*#__PURE__*/(0,vue_esm_bundler.createTextVNode)("Export Ingredients ");\n\nconst _hoisted_8 = /*#__PURE__*/(0,vue_esm_bundler.createTextVNode)("Export calculator ");\n\nconst _hoisted_9 = /*#__PURE__*/(0,vue_esm_bundler.createTextVNode)("Export menu ");\n\n(0,vue_esm_bundler.popScopeId)();\n\nconst render = /*#__PURE__*/_withId((_ctx, _cache, $props, $setup, $data, $options) => {\n  const _component_dataTable = (0,vue_esm_bundler.resolveComponent)("dataTable");\n\n  const _component_modal = (0,vue_esm_bundler.resolveComponent)("modal");\n\n  const _component_el_button = (0,vue_esm_bundler.resolveComponent)("el-button");\n\n  return (0,vue_esm_bundler.openBlock)(), (0,vue_esm_bundler.createBlock)(vue_esm_bundler.Fragment, null, [(0,vue_esm_bundler.createVNode)("div", _hoisted_1, [_hoisted_2, (0,vue_esm_bundler.createVNode)("div", _hoisted_3, [(0,vue_esm_bundler.createVNode)(_component_dataTable, {\n    onModal: _ctx.toggleModal,\n    onLoading: _ctx.setLoading,\n    loading: _ctx.loading,\n    key: _ctx.menuRows,\n    get: \'getMenus\',\n    add: \'setMenu\',\n    update: \'updateMenu\',\n    onCategory: _ctx.setMenu,\n    onCategories: _ctx.setMenus,\n    onSelecting: _ctx.select,\n    "item-id": _ctx.menu,\n    model: _ctx.modelMenus,\n    rows: _ctx.menuRows\n  }, null, 8\n  /* PROPS */\n  , ["onModal", "onLoading", "loading", "onCategory", "onCategories", "onSelecting", "item-id", "model", "rows"])])]), (0,vue_esm_bundler.createVNode)("div", _hoisted_4, [_hoisted_5, _ctx.menuRows[0].created ? ((0,vue_esm_bundler.openBlock)(), (0,vue_esm_bundler.createBlock)("div", _hoisted_6, [(0,vue_esm_bundler.createVNode)(_component_dataTable, {\n    onModal: _ctx.toggleModal,\n    onLoading: _ctx.setLoading,\n    loading: _ctx.loading,\n    key: _ctx.menuItemRows,\n    get: \'getMenuItems\',\n    add: \'setMenuItem\',\n    update: \'updateMenuItem\',\n    "item-id": _ctx.menu,\n    food: _ctx.item,\n    model: _ctx.modelMenuItems,\n    rows: _ctx.menuItemRows,\n    "no-row": false\n  }, null, 8\n  /* PROPS */\n  , ["onModal", "onLoading", "loading", "item-id", "food", "model", "rows"]), (0,vue_esm_bundler.createVNode)(_component_modal, {\n    onFetchItems: _cache[1] || (_cache[1] = $event => _ctx.fetchItems(_ctx.menu)),\n    onModal: _ctx.toggleModal,\n    itemId: _ctx.menu,\n    type: \'menu\',\n    data: _ctx.modalMenuItems,\n    menu: _ctx.itemName,\n    dialog: _ctx.modal\n  }, null, 8\n  /* PROPS */\n  , ["onModal", "itemId", "data", "menu", "dialog"])])) : (0,vue_esm_bundler.createCommentVNode)("v-if", true)]), (0,vue_esm_bundler.createVNode)(_component_el_button, {\n    class: "export container text-center",\n    size: "large",\n    type: "primary",\n    onClick: _cache[2] || (_cache[2] = $event => _ctx.exportFile(\'ingredients\'))\n  }, {\n    default: _withId(() => [_hoisted_7]),\n    _: 1\n    /* STABLE */\n\n  }), (0,vue_esm_bundler.createVNode)(_component_el_button, {\n    class: "export container text-center",\n    size: "large",\n    type: "primary",\n    onClick: _cache[3] || (_cache[3] = $event => _ctx.exportFile(\'calculation\'))\n  }, {\n    default: _withId(() => [_hoisted_8]),\n    _: 1\n    /* STABLE */\n\n  }), (0,vue_esm_bundler.createVNode)(_component_el_button, {\n    class: "export container text-center",\n    size: "large",\n    type: "primary",\n    onClick: _cache[4] || (_cache[4] = $event => _ctx.exportFile(\'menu\'))\n  }, {\n    default: _withId(() => [_hoisted_9]),\n    _: 1\n    /* STABLE */\n\n  })], 64\n  /* STABLE_FRAGMENT */\n  );\n});\n;// CONCATENATED MODULE: ./resources/js/components/realization.vue?vue&type=template&id=17a74d0b&scoped=true\n\n// EXTERNAL MODULE: ./node_modules/vuex/dist/vuex.esm-bundler.js\nvar vuex_esm_bundler = __webpack_require__("./node_modules/vuex/dist/vuex.esm-bundler.js");\n// EXTERNAL MODULE: ./resources/js/components/dataTable.vue + 6 modules\nvar dataTable = __webpack_require__("./resources/js/components/dataTable.vue");\n// EXTERNAL MODULE: ./resources/js/components/modal.vue + 6 modules\nvar modal = __webpack_require__("./resources/js/components/modal.vue");\n;// CONCATENATED MODULE: ./node_modules/babel-loader/lib/index.js!./node_modules/vue-loader/dist/index.js??ruleSet[0]!./resources/js/components/realization.vue?vue&type=script&lang=js\n\n\n\n\n/* harmony default export */ const realizationvue_type_script_lang_js = ((0,vue_esm_bundler.defineComponent)({\n  components: {\n    dataTable: dataTable.default,\n    modal: modal.default\n  },\n\n  setup() {\n    const store = (0,vuex_esm_bundler.useStore)();\n    const modal = (0,vue_esm_bundler.ref)(false);\n    const loading = (0,vue_esm_bundler.ref)(false);\n    let modelMenus = (0,vue_esm_bundler.ref)({\n      name: \'\',\n      type: \'menu\',\n      date: \'\',\n      edited: false\n    });\n    let menuRows = (0,vue_esm_bundler.ref)([modelMenus.value]);\n    const menus = (0,vue_esm_bundler.computed)(() => store.state.menus);\n    const menu = (0,vue_esm_bundler.ref)(typeof menus.value[0] !== \'undefined\' ? menus.value[0].id : null);\n    const menuList = (0,vue_esm_bundler.ref)([]);\n\n    const fetchMenus = async () => {\n      loading.value = true;\n      await store.dispatch(\'getMenus\').then(() => {\n        loading.value = false;\n\n        if (menus.value.length) {\n          menuRows.value = menus.value.map(item => {\n            return {\n              id: typeof item.id !== \'undefined\' ? item.id : null,\n              name: typeof item.name !== \'undefined\' ? item.name : \'\',\n              type: \'menu\',\n              date: typeof item.date !== \'undefined\' ? item.date : \'\',\n              created: true\n            };\n          });\n        }\n      });\n    };\n\n    (0,vue_esm_bundler.watch)(() => menus.value.length, (n, o) => {\n      if (n !== o) {\n        fetchMenus().then(() => {\n          menu.value = menus.value.length ? menus.value[0].hasOwnProperty(\'id\') ? menus.value[0].id : null : null;\n        });\n      }\n    }, {\n      immediate: true\n    });\n\n    const setMenu = val => {\n      menu.value = val;\n    };\n\n    const setMenus = val => {\n      if (menuList.value.length) {\n        if (menuList.value.find(i => i === val)) menuList.value = menuList.value.filter(i => i !== val);else menuList.value.push(val);\n      } else {\n        menuList.value.push(val);\n      }\n    }; //Items\n\n\n    const foods = (0,vue_esm_bundler.computed)(() => store.state.foods);\n    const groups = (0,vue_esm_bundler.computed)(() => store.state.groups);\n    const items = (0,vue_esm_bundler.computed)(() => store.state.menu_items);\n    store.dispatch(\'getGroups\', {}); // const ingredients = computed(() => store.state.ingredients);\n    // store.dispatch(\'getIngredients\', {category_id: \'all\'})\n\n    const modalMenuItems = (0,vue_esm_bundler.computed)(() => groups.value.map(item => {\n      return {\n        children: item.foods.map(elem => {\n          return {\n            key: elem.id,\n            name: elem.name,\n            menu_id: elem.menu_id,\n            group_id: elem.group_id,\n            price_portion: elem.price_portion,\n            portions: elem.portions\n          };\n        }),\n        disabled: false,\n        key: item.id,\n        name: item.name\n      };\n    }));\n    let modelMenuItems = (0,vue_esm_bundler.ref)({\n      food_id: 0,\n      menu_id: 0,\n      type: \'food\'\n    });\n    let menuItemRows = (0,vue_esm_bundler.ref)([{ ...modelMenuItems.value\n    }]);\n    const item = (0,vue_esm_bundler.computed)(() => typeof foods.value[0] !== \'undefined\' ? foods.value[0].id : null);\n    const itemName = (0,vue_esm_bundler.computed)(() => typeof menus.value[0] !== \'undefined\' ? menus.value[0].name : null);\n\n    const fetchItems = async menu_id => {\n      if (menu_id) {\n        loading.value = true;\n        await store.dispatch(\'getMenuItems\', {\n          menu_id: menu_id\n        }).then(() => {\n          loading.value = false;\n\n          if (items.value.length) {\n            menuItemRows.value = items.value.map(item => {\n              console.log(item);\n              return {\n                id: typeof item.id !== \'undefined\' ? item.id : null,\n                name: typeof item.food.name !== \'undefined\' ? item.food.name : \'\',\n                menu_id: typeof menu_id !== \'undefined\' ? menu_id : null,\n                food_id: typeof item.food_id !== \'undefined\' ? item.food_id : null,\n                group_id: typeof item.food.group_id !== \'undefined\' ? item.food.group_id : null,\n                price_portion: typeof item.food.price_portion !== \'undefined\' ? item.food.price_portion : 0,\n                portions: typeof item.portions !== \'undefined\' ? item.portions : 1,\n                type: \'food\'\n              };\n            });\n          } else {\n            menuItemRows.value = [{ ...modelMenuItems.value\n            }];\n          }\n        });\n      }\n    };\n\n    (0,vue_esm_bundler.watch)(() => menu.value, (n, o) => {\n      if (n !== o) {\n        fetchItems(menu.value);\n      }\n    }, {\n      immediate: true\n    });\n\n    const toggleModal = v => {\n      modal.value = v;\n    };\n\n    const exportFile = type => {\n      let data = {\n        type: type,\n        menu_id: menu.value\n      };\n      if (selecting.value) data = {\n        type: type,\n        menu_id: menuList.value\n      };\n      axios.post(\'/api/export\', data, {\n        responseType: \'arraybuffer\',\n        headers: {\n          \'Content-Type\': \'application/json\',\n          \'Accept\': \'application/pdf\'\n        }\n      }).then(r => {\n        downloadFile(r.data, type);\n      });\n    };\n\n    const setLoading = v => {\n      loading.value = v;\n    };\n\n    const downloadFile = (response, type) => {\n      try {\n        var file = new File([response], filename, {\n          type: "text/plain"\n        });\n      } catch (e) {\n        file = new Blob([response], {\n          type: "text/plain"\n        });\n      }\n\n      let link = document.createElement(\'a\');\n      link.href = window.URL.createObjectURL(file);\n      link.download = type + \'.pdf\';\n      link.click();\n    };\n\n    const selecting = (0,vue_esm_bundler.ref)(false);\n\n    const select = v => {\n      selecting.value = v;\n    };\n\n    return {\n      modelMenus,\n      modalMenuItems,\n      menuRows,\n      menu,\n      menus,\n      groups,\n      foods,\n      modal,\n      menuItemRows,\n      modelMenuItems,\n      menuList,\n      item,\n      itemName,\n      selecting,\n      setMenu,\n      toggleModal,\n      fetchItems,\n      exportFile,\n      setLoading,\n      setMenus,\n      select\n    };\n  }\n\n}));\n;// CONCATENATED MODULE: ./resources/js/components/realization.vue?vue&type=script&lang=js\n \n;// CONCATENATED MODULE: ./resources/js/components/realization.vue\n\n\n\nrealizationvue_type_script_lang_js.render = render\nrealizationvue_type_script_lang_js.__scopeId = "data-v-17a74d0b"\n/* hot reload */\nif (false) {}\n\nrealizationvue_type_script_lang_js.__file = "resources/js/components/realization.vue"\n\n/* harmony default export */ const realization = (realizationvue_type_script_lang_js);\n\n//# sourceURL=webpack:///./resources/js/components/realization.vue_+_4_modules?')}}]);