Liferay.Loader.define("layout-seo-web@2.0.43/js/seo/PreviewSeo.es",["module","exports","require","@liferay/frontend-js-react-web","frontend-js-web","liferay!frontend-js-react-web$prop-types","liferay!frontend-js-react-web$react","./PreviewSeoEvents.es"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){return i.default.createElement(d,e)};var n=r("@liferay/frontend-js-react-web"),a=r("frontend-js-web"),i=(r("liferay!frontend-js-react-web$prop-types"),function(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=o();if(t&&t.has(e))return t.get(e);var r={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var a in e)if(Object.prototype.hasOwnProperty.call(e,a)){var i=n?Object.getOwnPropertyDescriptor(e,a):null;i&&(i.get||i.set)?Object.defineProperty(r,a,i):r[a]=e[a]}r.default=e,t&&t.set(e,r);return r}(r("liferay!frontend-js-react-web$react"))),c=r("./PreviewSeoEvents.es");function o(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return o=function(){return e},e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function u(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?l(Object(r),!0).forEach((function(t){s(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):l(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function s(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function f(e,t){if(null==e)return{};var r,n,a=function(e,t){if(null==e)return{};var r,n,a={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}const e=160,p=({description:t="",direction:r="ltr",displayType:n="serp",imgUrl:a="",title:c="",titleSuffix:o="",url:l=""})=>{const u=[i.default.createElement("div",{className:"preview-seo-title text-truncate",key:"title"},c,o&&" - ".concat(o)),i.default.createElement("div",{className:"preview-seo-url text-truncate",key:"url"},l)];return i.default.createElement("div",{className:"preview-seo preview-seo-".concat(n),dir:r},a&&i.default.createElement("div",{className:"aspect-ratio aspect-ratio-191-to-100 preview-seo-image"},i.default.createElement("img",{alt:"",className:"aspect-ratio-item aspect-ratio-item-center-middle aspect-ratio-item-flush",src:a})),"og"===n?u.reverse():u,i.default.createElement("div",{className:"preview-seo-description"},t.length<e?t:"".concat(t.slice(0,e),"…")))},d=({displayType:e,portletNamespace:t,targets:r,titleSuffix:o})=>{const l=Liferay.ThemeDisplay.getLanguageId(),[s,d]=(0,i.useState)(l),[y,b]=(0,i.useState)({}),v=(0,n.useIsMounted)(),[m,O]=(0,i.useState)({}),g=(0,i.useCallback)((e=>{let t=r[e]&&r[e].defaultValue;return(0,a.isObject)(t)&&(t=t[s]||t[l]),t}),[l,r,s]);(0,i.useEffect)((()=>{const e=Liferay.on("inputLocalized:localeChanged",(e=>{const t=e.item&&e.item.getAttribute("data-value");t&&v()&&d(t)}));return()=>{Liferay.detach(e)}}),[v]),(0,i.useEffect)((()=>{const e=e=>{let{type:t}=e,r=f(e,["type"]);v()&&b((e=>u(u({},e),{},{[t]:u({},r)})))},n=Object.entries(r).reduce(((r,[n,{id:a,value:i}])=>{if(a){const e=document.getElementById("".concat(t).concat(a)),i=document.getElementById("".concat(t).concat(a,"_").concat(l));r[n]={defaultLanguageInput:i,input:e,type:n}}else i&&e({type:n,value:i});return r}),{});O(n);const a=Object.values(n).reduce(((t,{input:r,type:n})=>{const a=t=>{(({event:t,type:r})=>{const n=t.target;if(!n)return;const{disabled:a,value:i}=n;e({disabled:a,type:r,value:i})})({event:t,type:n})};return r.addEventListener("input",a),t.push({input:r,listener:a}),t}),[]),i=(0,c.previewSeoOnChange)(t,e);return()=>{a.forEach((({input:e,listener:t})=>e.removeEventListener("input",t))),Liferay.detach(i)}}),[l,v,t,r]),(0,i.useEffect)((()=>{if(!v())return;const e=Object.values(m).reduce(((e,{input:t,type:r})=>{const{disabled:n,value:a}=t;return e[r]={disabled:n,value:a},e}),{});b((t=>u(u({},t),e)))}),[m,v,s]);const j=e=>{const t=y[e]&&y[e].disabled;let r=y[e]&&y[e].value;if(t||!r){const t=m[e]&&m[e].defaultLanguageInput,n=t&&!t.disabled&&t.value;r=s!==l&&n?n:g(e)}return r||""};return i.default.createElement(p,{description:j("description"),direction:Liferay.Language.direction[s],displayType:e,imgUrl:j("imgUrl"),title:j("title"),titleSuffix:o,url:j("url")})}}}));
//# sourceMappingURL=PreviewSeo.es.js.map