"use strict";(self.webpackChunkui=self.webpackChunkui||[]).push([[37],{317:function(e,t,n){var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Ingredient=void 0;const r=n(0),i=s(n(499)),{wrapper:c,wrapperName:o,wrapperAmount:a}=i.default;t.Ingredient=({boldText:e,text:t})=>(0,r.jsxs)("li",Object.assign({className:c},{children:[(0,r.jsx)("p",Object.assign({className:o},{children:e})),(0,r.jsx)("p",Object.assign({className:a},{children:t}))]}))},874:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.useCopyToClipboard=t.useCalculatePortion=void 0;const s=n(3);t.useCalculatePortion=({ingredients:e,servingSize:t})=>{const[n,r]=(0,s.useState)(null!=t?t:""),[i,c]=(0,s.useState)(1),[o,a]=(0,s.useState)(e),l=t=>e.map((e=>{try{if(!/\d/.test(e.text))return e;if(e.text.match(/(\d+)?\s*to\s*(\d+)/)){const n=e.text.split("to"),s=n[0].replace(/[^0-9\/]/g,""),r=n[1].replace(/[^0-9\/]/g,""),i=s.includes("/")?u(s,t):Number(s)*t,c=r.includes("/")?u(r,t):Number(r)*t;return Object.assign(Object.assign({},e),{text:e.text.replace(n[0],`${i.toString()} `).replace(n[1],` ${c.toString()}`)})}const n=e.text.replace(/[^0-9.]/g,"");if(!isNaN(Number(n))&&n.includes("."))return Object.assign(Object.assign({},e),{text:e.text.replace(n,(Number(n)*t).toFixed(2))});const s=e.text.replace(/[^0-9\/]/g,"");if(!s)return e;if(!s.includes("/")){const n=Number(s);if(!isNaN(n))return Object.assign(Object.assign({},e),{text:e.text.replace(n.toString(),(n*t).toString())})}if(e.text.includes(s))return Object.assign(Object.assign({},e),{text:e.text.replace(s,u(s,t))});const r=e.text.match(/(\d+)(?:\s+(\d+)\/(\d+))?/);if(r){const n=parseInt(r[1],10)||0,s=parseInt(r[2],10)||0,i=parseInt(r[3],10)||1;return Object.assign(Object.assign({},e),{text:e.text.replace(r[0],p((n*i+s)*t,i))})}return e}catch(t){return e}}));function u(e,t){const[n,s]=e.split("/").map(Number);return p(n*t,s)}function p(e,t){const n=(e,t)=>t<1e-10?e:n(t,Math.floor(e%t)),s=n(e,t),r=e/s,i=t/s;return 1===i?`${r}`:r{const n=e.replace(/[^0-9\/]/g,""),s=Number(n)*t;return e.replace(n,s.toString())};return{portions:i,recipe:o,increasePortions:()=>{const e=i+1;c(e),a(l(e)),t&&r(d(t,e))},decreasePortions:()=>{if(i>1){const e=i-1;c(e),a(l(e)),t&&r(d(t,e))}},servingSizeComputed:n}},t.useCopyToClipboard=({ingredients:e})=>{const[t,n]=(0,s.useState)(!1);return{copyToClipboard:()=>{const t=(e=>e.map((e=>`${e.text} ${e.boldText}`)).join("\n"))(e);navigator.clipboard.writeText(t).then((()=>{n(!0),setTimeout((()=>n(!1)),2e3)})).catch((e=>console.error("Error on file coping: ",e)))},showPopup:t,closePopup:()=>{n(!1)}}}},126:function(e,t,n){var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Ingredients=void 0;const r=n(0),i=n(4),c=n(317),o=n(2),a=n(874),l=s(n(500)),{wrapper:u,wrapperTitle:p,wrapperIngredients:d,wrapperBtns:g,wrapperBtnsBtn:b,wrapperBtnsCopy:j,wrapperBtnsBtnIcon:f,wrapperBtnsBtnIconInactive:x,popup:h,popupActive:m}=l.default;t.Ingredients=({ingredients:e,servingSize:t})=>{const{portions:n,recipe:s,increasePortions:l,decreasePortions:O,servingSizeComputed:v}=(0,a.useCalculatePortion)({ingredients:e,servingSize:t}),{copyToClipboard:I,showPopup:N,closePopup:_}=(0,a.useCopyToClipboard)({ingredients:s});return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",Object.assign({className:u},{children:[(0,r.jsx)("h2",Object.assign({className:p},{children:"INGREDIENTS"})),(0,r.jsx)("div",Object.assign({className:d},{children:s.map((e=>(0,r.jsx)(c.Ingredient,Object.assign({},e))))})),(0,r.jsxs)("div",Object.assign({className:g},{children:[(0,r.jsxs)("div",Object.assign({className:b},{children:[(0,r.jsx)("button",Object.assign({onClick:O,className:(0,o.cx)(f,1===n&&x)},{children:(0,r.jsx)(i.Icons.RecipeMinusIcon,{})})),(0,r.jsx)("p",{children:`${n} serving${n>1?"s":""} ${v}`}),(0,r.jsx)("button",Object.assign({className:f,onClick:l},{children:(0,r.jsx)(i.Icons.RecipePlusIcon,{})}))]})),(0,r.jsx)("button",Object.assign({className:(0,o.cx)(b,j),onClick:I},{children:"copy ingredients"}))]}))]})),(0,r.jsxs)("div",Object.assign({className:(0,o.cx)(h,N&&m)},{children:[(0,r.jsx)(i.Icons.InfoIcon,{}),(0,r.jsx)("p",{children:"Ingredients copied to clipboard"}),(0,r.jsx)("button",Object.assign({onClick:_},{children:(0,r.jsx)(i.Icons.CloseIcon,{})}))]}))]})}},4:function(e,t,n){var s=this&&this.__createBinding||(Object.create?function(e,t,n,s){void 0===s&&(s=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,s,r)}:function(e,t,n,s){void 0===s&&(s=n),e[s]=t[n]}),r=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&s(t,e,n);return r(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.Icons=void 0;const c=i(n(11));t.Icons=c}}]);