"use strict";var e=require("@babel/runtime/helpers/toConsumableArray"),t=require("@babel/runtime/helpers/defineProperty"),r=require("react"),a=require("prop-types"),n=require("slate-react"),i=require("slate"),l=require("lodash"),s=require("./RenderElements.js"),o=require("./utils.js"),u=require("react/jsx-runtime");function d(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var c=d(e),f=d(t),p=d(a);function x(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function O(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?x(Object(r),!0).forEach((function(t){f.default(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):x(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var m=function(e){var t,a=e.text,d=e.textsList,f=e.defaultText,p=e.defaultRenderingTextNode,x=e.locator,m="".concat(x,"_slateText"),S=r.useMemo((function(){return n.withReact(i.createEditor())}),[]),g=r.useCallback((function(e){return u.jsx(s.Element,O({},e))}),[]),y=r.useCallback((function(e){return u.jsx(s.Leaf,O({},e))}),[]),b=r.useMemo((function(){var e=o.slateFormattingTextUtils.getValidSlateJSON(a),t=e.isTextValidSlateJSON,r=e.parsedJSON;if(d.length){var n=d.map((function(e){return o.slateFormattingTextUtils.getValidSlateJSON(e)}));t=l.every(n,(function(e){return e.isTextValidSlateJSON})),r=o.slateFormattingTextUtils.getDefaultParagraphObjectEmpty(),t&&n.forEach((function(e){var t,a=e.parsedJSON;o.slateFormattingTextUtils.isSlateTextEmpty(a)||(r[0].children=(t=r[0].children).concat.apply(t,c.default(a.map((function(e){return e.children})))));r[0].children=r[0].children.concat({text:"\n"})}))}var i=t&&o.slateFormattingTextUtils.isSlateTextEmpty(r);return{isValidSlateJSON:t,parsedSlateJSON:r,isEmptySlateJSON:i}}),[a,String(d)]),T=b.isValidSlateJSON,j=b.parsedSlateJSON,h=b.isEmptySlateJSON,v=o.slateFormattingTextUtils.getFormattedText({isValid:T,isEmpty:h,text:a,parsedText:j,defaultText:f});return t=d.length>0?d.map((function(e){return u.jsxs("span",{"data-testid":"".concat(m,"_listItem"),children:[e,u.jsx("br",{})]},e)})):T&&h||!p?v:p,T&&!h?u.jsx(n.Slate,{editor:S,value:v,children:u.jsx(n.Editable,{"data-testid":"".concat(m,"_editable"),renderElement:g,renderLeaf:y,readOnly:!0})}):t};m.propTypes={text:p.default.string,textsList:p.default.arrayOf(p.default.string),defaultText:p.default.oneOfType([p.default.string,p.default.node]),defaultRenderingTextNode:p.default.node,locator:p.default.string},m.defaultProps={text:"",textsList:[],defaultText:"",defaultRenderingTextNode:void 0,locator:"SlateFormattedText"},module.exports=m;
