@erpsquad/common 1.10.8-test → 1.10.9-test

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/chunks/{ai-summary-D9QajB4_.js → ai-summary-4NVNEHfi.js} +2 -2
  2. package/dist/chunks/{ai-summary-D9QajB4_.js.map → ai-summary-4NVNEHfi.js.map} +1 -1
  3. package/dist/chunks/{ai-summary-FqAUpafL.esm.js → ai-summary-f8clWLbW.esm.js} +65 -44
  4. package/dist/chunks/{ai-summary-FqAUpafL.esm.js.map → ai-summary-f8clWLbW.esm.js.map} +1 -1
  5. package/dist/chunks/{android-12-switch-BVabRCje.esm.js → android-12-switch-BUbQYnRQ.esm.js} +53 -35
  6. package/dist/chunks/{android-12-switch-BVabRCje.esm.js.map → android-12-switch-BUbQYnRQ.esm.js.map} +1 -1
  7. package/dist/chunks/android-12-switch-CphTHRb8.js +2 -0
  8. package/dist/chunks/{android-12-switch-DMaoWQwq.js.map → android-12-switch-CphTHRb8.js.map} +1 -1
  9. package/dist/chunks/{appbar-6Ucw59ku.js → appbar-C6Es9HGk.js} +2 -2
  10. package/dist/chunks/{appbar-6Ucw59ku.js.map → appbar-C6Es9HGk.js.map} +1 -1
  11. package/dist/chunks/{appbar-mDf1LZ0u.esm.js → appbar-CKrHdx9n.esm.js} +2 -2
  12. package/dist/chunks/{appbar-mDf1LZ0u.esm.js.map → appbar-CKrHdx9n.esm.js.map} +1 -1
  13. package/dist/chunks/{default-data-CwLgBvlI.esm.js → default-data-BsZWgQGR.esm.js} +3 -3
  14. package/dist/chunks/{default-data-CwLgBvlI.esm.js.map → default-data-BsZWgQGR.esm.js.map} +1 -1
  15. package/dist/chunks/{default-data-D2cqOmp4.js → default-data-Dsjlvwev.js} +2 -2
  16. package/dist/chunks/{default-data-D2cqOmp4.js.map → default-data-Dsjlvwev.js.map} +1 -1
  17. package/dist/chunks/{fullScreen-VlXxoepU.js → fullScreen-BBpaDn-A.js} +2 -2
  18. package/dist/chunks/{fullScreen-VlXxoepU.js.map → fullScreen-BBpaDn-A.js.map} +1 -1
  19. package/dist/chunks/{fullScreen-B9d2_kak.esm.js → fullScreen-Dn-3Tkwm.esm.js} +2 -2
  20. package/dist/chunks/{fullScreen-B9d2_kak.esm.js.map → fullScreen-Dn-3Tkwm.esm.js.map} +1 -1
  21. package/dist/chunks/index-B9CFxEZ9.js +2 -0
  22. package/dist/chunks/index-B9CFxEZ9.js.map +1 -0
  23. package/dist/chunks/{index-iPYNYnNP.esm.js → index-wf5q5BST.esm.js} +73 -66
  24. package/dist/chunks/{index-iPYNYnNP.esm.js.map → index-wf5q5BST.esm.js.map} +1 -1
  25. package/dist/chunks/{migration-utils-TYitNMC7.js → migration-utils-9IXhe_fj.js} +2 -2
  26. package/dist/chunks/{migration-utils-TYitNMC7.js.map → migration-utils-9IXhe_fj.js.map} +1 -1
  27. package/dist/chunks/{migration-utils-BRjncD-b.esm.js → migration-utils-DGoEzQUj.esm.js} +2 -2
  28. package/dist/chunks/{migration-utils-BRjncD-b.esm.js.map → migration-utils-DGoEzQUj.esm.js.map} +1 -1
  29. package/dist/chunks/{sidebar-DJREtRnK.js → sidebar-B3SExDRU.js} +2 -2
  30. package/dist/chunks/{sidebar-DJREtRnK.js.map → sidebar-B3SExDRU.js.map} +1 -1
  31. package/dist/chunks/{sidebar-D_3INLNa.esm.js → sidebar-n9Y25HU-.esm.js} +2 -2
  32. package/dist/chunks/{sidebar-D_3INLNa.esm.js.map → sidebar-n9Y25HU-.esm.js.map} +1 -1
  33. package/dist/chunks/{sidebarScreen-CUf5Onkp.js → sidebarScreen-Dxb_e58p.js} +2 -2
  34. package/dist/chunks/{sidebarScreen-CUf5Onkp.js.map → sidebarScreen-Dxb_e58p.js.map} +1 -1
  35. package/dist/chunks/{sidebarScreen-CLjYZOzQ.esm.js → sidebarScreen-_Zt2pSOx.esm.js} +3 -3
  36. package/dist/chunks/{sidebarScreen-CLjYZOzQ.esm.js.map → sidebarScreen-_Zt2pSOx.esm.js.map} +1 -1
  37. package/dist/components/index.esm.js +121 -103
  38. package/dist/components/index.js +1 -1
  39. package/dist/index.esm.js +218 -200
  40. package/dist/index.js +1 -1
  41. package/dist/index.js.map +1 -1
  42. package/dist/layout/index.esm.js +2 -2
  43. package/dist/layout/index.js +1 -1
  44. package/dist/src/components/index.d.ts +18 -1
  45. package/dist/utils/index.esm.js +1 -1
  46. package/dist/utils/index.js +1 -1
  47. package/dist/views/index.esm.js +5 -5
  48. package/dist/views/index.js +1 -1
  49. package/package.json +1 -1
  50. package/dist/chunks/android-12-switch-DMaoWQwq.js +0 -2
  51. package/dist/chunks/index-BQ2NBHDS.js +0 -2
  52. package/dist/chunks/index-BQ2NBHDS.js.map +0 -1
@@ -1,2 +1,2 @@
1
- "use strict";const e=require("react/jsx-runtime"),t=require("react"),l=require("react-router-dom"),a=require("./pathname.rental-Br768eN2.js"),o=require("./useAuth-C1y8BBuX.js"),n=require("./android-12-switch-DMaoWQwq.js"),r=require("./hooks-BdfwliGF.js"),i=require("@reduxjs/toolkit"),s=require("./form-builder-deconversion-BbeAseMU.js"),d=require("@mui/material"),c=require("./appbar-6Ucw59ku.js"),u=require("./images-DrJQoSCu.js"),m=require("react-hook-form"),p=require("yup"),h=require("./api-config-CkfRrKRY.js"),g=require("./tick-ChY3vEPD.js"),x=require("@glideapps/glide-data-grid"),b=require("@mui/material/styles");;/* empty css */const f=require("@mui/icons-material"),y=require("react-dnd"),v=require("react-dnd-html5-backend"),j=require("react-i18next"),S=require("notistack"),C=require("./form-builder-conversion-CfUcZgLV.js"),w=require("./common-wRWMk0Fs.js"),_=require("./page-context-qa1FKO9A.js"),k=require("./reducer-BfnLOnkL.js"),T=require("./trash-lbX6jsCI.js"),I=require("./toggle-switch-tXRsnOmX.js"),E=require("@mui/icons-material/Close"),B=require("./pathname.hrms-DGxdM-k7.js"),A=require("@mui/icons-material/CodeOutlined"),M=require("./route-page-map-CDdU1EAs.js"),F=require("@dnd-kit/core"),$=require("@mui/icons-material/DragIndicator"),D=require("@mui/icons-material/CallSplit"),P=require("@mui/icons-material/FormatBold"),z=require("@mui/icons-material/FormatItalic"),R=require("@mui/icons-material/FormatUnderlined"),N=require("@mui/icons-material/ColorLens"),L=require("lodash"),O=require("@mui/icons-material/FormatAlignLeft"),q=require("@mui/icons-material/FormatAlignCenter"),W=require("@mui/icons-material/FormatAlignRight"),H=require("@mui/icons-material/FormatAlignJustify"),V=require("@mui/icons-material/ExpandMore"),G=require("@mui/icons-material/Add"),U=require("@mui/icons-material/Refresh"),K=require("@mui/icons-material/MergeType"),J=require("react-dropzone"),Y=require("lucide-react"),Z=require("./api-DG3x2G1d.js"),X=require("@mui/icons-material/Check"),Q=require("uuid"),ee=require("./action-bar-BmEN5Ob9.js"),te=require("./useAccountSetting-DZvJOGz7.js");function le(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const l in e)if("default"!==l){const a=Object.getOwnPropertyDescriptor(e,l);Object.defineProperty(t,l,a.get?a:{enumerable:!0,get:()=>e[l]})}return t.default=e,Object.freeze(t)}const ae=le(p),oe=[{label:"Average",value:"avg"},{label:"Sum",value:"sum"},{label:"Min",value:"min"},{label:"Max",value:"max"},{label:"Count Empty",value:"count_empty"},{label:"Count Full",value:"count_full"},{label:"Percentage Full",value:"percentage_full"},{label:"Percentage Empty",value:"percentage_empty"},{label:"None",value:"none"}],ne=[{label:"Count Empty",value:"count_empty"},{label:"Count Full",value:"count_full"},{label:"Percentage Full",value:"percentage_full"},{label:"Percentage Empty",value:"percentage_empty"},{label:"None",value:"none"}],re={avg:s.aggregationFns.average,sum:s.aggregationFns.sum,max:s.aggregationFns.max,count_empty:s.aggregationFns.countEmpty,count_full:s.aggregationFns.countFull,percentage_empty:s.aggregationFns.percentageEmpty,percentage_full:s.aggregationFns.percentageFull,min:s.aggregationFns.min,none:s.aggregationFns.none},ie=({data:l,column:a,type:n})=>{const[r,i]=t.useState("none"),[c,u]=t.useState(null),[m,p]=t.useState(),h=Boolean(c),g=()=>{u(null)};t.useEffect(()=>{p((0,re[r])(l,a))},[r,a,l]);const x="number"===n?oe:ne;return e.jsxs(e.Fragment,{children:[e.jsx(o.Typography,{onClick:e=>{u(e.currentTarget)},sx:{cursor:"pointer"},type:"s4",weight:"normal",color:m?"theme.secondary.1000":"theme.secondary.500",children:m||"+ Add Calculation"}),e.jsx(s.Menu,{id:"basic-menu",anchorEl:c,open:h,onClose:g,children:null==x?void 0:x.map(t=>e.jsx(d.MenuItem,{selected:r==(null==t?void 0:t.value),onClick:()=>{return e=null==t?void 0:t.value,i(e),void g();var e},children:e.jsx(o.Typography,{color:"theme.secondary.1000",type:"s4",children:null==t?void 0:t.label})},t.value))})]})};class se extends t.Component{componentDidMount(){setTimeout(()=>{},2e3)}render(){return e.jsxs("div",{style:{textAlign:"center",position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)"},children:[e.jsx("strong",{children:e.jsx("p",{children:"404"})}),e.jsx("hr",{}),e.jsx("p",{children:"Not Found"})]})}}const de=i.createAsyncThunk("pageView/fetchPage",(e,{getState:t})=>{const{pages:l}=t(),{data:a}=l.pages.find(t=>(null==t?void 0:t.value)===e);return a}),ce={rows:[{name:"John",age:30,gender:"Male",company:"NASA",location:"USA",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4}],columns:[{header:"Name",type:"string",accessorKey:"name"},{type:"number",header:"Age",accessorKey:"age"},{header:"Gender",type:"string",accessorKey:"gender"},{header:"Company",type:"string",accessorKey:"company"},{header:"Location",type:"string",accessorKey:"location"},{header:"Price",type:"number",accessorKey:"price"}],columnOrder:["name","age","gender","company","location","price"]},ue={rows:[{name:"John",age:30,gender:"Male",company:"NASA",location:"USA",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4}],columns:[{type:"number",header:"Age",accessorKey:"age"},{header:"Gender",type:"string",accessorKey:"gender"},{header:"Company",type:"string",accessorKey:"company"},{header:"Name",type:"string",accessorKey:"name"},{header:"Location",type:"string",accessorKey:"location"},{header:"Price",type:"number",accessorKey:"price"}],columnOrder:["age","gender","company","name","location","price"]},me={currentPage:1,rows:[],columns:[],columnOrder:[],loading:!0,error:"",pages:[{name:"Default",_id:1,data:ce},{name:"Local",_id:2,data:ue}],paginationModel:{pageNo:1,limit:10}},pe=i.createSlice({name:"pageView",initialState:me,reducers:{changeCurrentPage(e,t){e.currentPage=t.payload},setPages(e,t){e.pages=t.payload},setPaginationModel(e,t){e.paginationModel=t.payload},setColumnOrder(e,t){e.columnOrder=t.payload},setRowData(e,{payload:t}){const l=JSON.parse(JSON.stringify(e.rows));l[t.rowId][t.columnId]=t.value,e.rows=l}},extraReducers:e=>{e.addCase(de.pending,e=>{e.loading=!0}),e.addCase(de.fulfilled,(e,t)=>{e.loading=!1,e.error="",e.rows=t.payload.rows,e.columns=t.payload.columns,e.columnOrder=t.payload.columnOrder}),e.addCase(de.rejected,e=>{e.loading=!1,e.rows=[],e.columns=[],e.error="Unable to get data"})}}),{changeCurrentPage:he,setPages:ge,setPaginationModel:xe,setColumnOrder:be,setRowData:fe}=pe.actions,ye=pe.reducer,ve=d.styled(d.Grid)(()=>({height:"100vh"})),je=d.styled(d.Grid)(({theme:e})=>({[e.breakpoints.down("sm")]:{display:"none"},backgroundImage:`url(${u.images.login.LoginLeftBg})`,backgroundRepeat:"no-repeat",backgroundSize:"cover",display:"flex",justifyContent:"center",alignItems:"center",[e.breakpoints.down("lg")]:{"& img":{width:350,height:350}},[e.breakpoints.down("md")]:{"& img":{width:300,height:300}}})),Se=d.styled(d.Grid)(()=>({display:"flex",justifyContent:"center",alignItems:"center",padding:"1rem"})),Ce=d.styled(d.Box)(()=>({display:"flex",flexDirection:"column"})),we=ae.object({login:ae.object({password:ae.string().required("Please enter password").min(8,"Password must be at least 8 characters").matches(/[A-Z]/,"Password must contain at least one uppercase letter").matches(/[!@#$%^&*(),.?":{}|<>]/,"Password must contain at least one special character"),confirm_password:ae.string().required("Please enter confirm password").oneOf([ae.ref("password")],"Passwords must match")})}),_e={events:[{title:"All Day Event",start:ke("YEAR-MONTH-01")},{title:"Long Event",start:ke("YEAR-MONTH-07"),end:ke("YEAR-MONTH-10")},{groupId:"999",title:"Repeating Event",start:ke("YEAR-MONTH-09T16:00:00+00:00")},{groupId:"999",title:"Repeating Event",start:ke("YEAR-MONTH-16T16:00:00+00:00")},{title:"Conference",start:"YEAR-MONTH-17",end:ke("YEAR-MONTH-19")},{title:"Meeting",start:ke("YEAR-MONTH-18T10:30:00+00:00"),end:ke("YEAR-MONTH-18T12:30:00+00:00")},{title:"Lunch",start:ke("YEAR-MONTH-18T12:00:00+00:00")},{title:"Birthday Party",start:ke("YEAR-MONTH-19T07:00:00+00:00")},{title:"Meeting",start:ke("YEAR-MONTH-18T14:30:00+00:00")},{title:"Happy Hour",start:ke("YEAR-MONTH-18T17:30:00+00:00")},{title:"Dinner",start:ke("YEAR-MONTH-18T20:00:00+00:00")}]};function ke(e){const t=new Date,l=t.getFullYear().toString();let a=(t.getMonth()+1).toString();return 1===a.length&&(a="0"+a),e.replace("YEAR",l).replace("MONTH",a)}const Te=[{title:"Name",id:"name",hasMenu:!0,icon:x.GridColumnIcon.HeaderString},{title:"Company",id:"company",hasMenu:!0,dataType:"Bubble"},{title:"Age",id:"age",hasMenu:!0,dataType:"Number"},{title:"Image dd",id:"image",key:"image",dataType:"Image"},{title:"Email",id:"email",hasMenu:!0},{title:"Date",id:"date",hasMenu:!0,dataType:"DatePicker"},{title:"Phone",id:"phone"},{title:"Address",id:"address"},{title:"about",id:"about"}],Ie={text:{field_type:"text",label:"label",placeholder:"Enter text",default_value:"",min_length:2,max_length:30,is_multiline:!1,is_required:!0,is_unique:!1},number:{field_type:"number",label:"label",placeholder:"Enter number",default_value:"",float_step:"0.001",min_length:0,max_length:1e3,is_negative:!1,is_required:!0,is_unique:!1},email:{field_type:"email",label:"label",placeholder:"Enter email",default_value:"",is_required:!1,is_unique:!1},phone:{field_type:"phone",label:"label",placeholder:"Enter phone",default_value:"",is_required:!1,is_unique:!1},select:{field_type:"select",label:"Select",placeholder:"Choose option",default_value:"",options:[],is_multiselect:!1,is_required:!0,is_unique:!1},date:{field_type:"date",label:"label",placeholder:"Select Date",default_value:"",is_future_dates_allowed:!1,is_past_dates_allowed:!1,is_required:!1,is_unique:!1},time:{field_type:"time",label:"label",placeholder:"Select Time",default_value:"",is_required:!1,is_unique:!1,option:"12hr"},url:{field_type:"url",label:"label",placeholder:"Enter URL",default_value:"",is_required:!1,is_unique:!1},currency:{field_type:"currency",label:"label",placeholder:"Enter Currency",default_value:"",is_required:!1,is_unique:!1,option:"inr"},file:{field_type:"file",label:"label",placeholder:"Upload File or Media",is_required:!1,is_unique:!1,max_size:20,default_value:""},geoLocation:{field_type:"geoLocation",label:"label",placeholder:"Enter geo location",default_value:"",is_required:!1,is_unique:!1},image:{field_type:"image",label:"label",placeholder:"Upload Image",is_required:!1,is_unique:!1,max_size:20,default_value:""},section:{field_type:"section",label:"section",section_type:"Default",form_switcher_label:"Form section",form_switcher_name:"",switcher_forms:[{value:"",name:"Form 1",id:null}],is_accordion:!1,members:[]},info:{field_type:"info",label:"label",placeholder:"Add Label Text",default_value:""},relation:{field_type:"relation",label:"label",placeholder:"Add Label Text",is_required:!1,is_unique:!1,module:"",field:"",default_value:""},checkbox:{field_type:"checkbox",label:"label",placeholder:"Add Label Text",is_required:!1,is_checked:!1,title_position:"end",title:"Checkbox"},toggleButton:{field_type:"toggleButton",label:"label",placeholder:"Add Label Text",is_required:!1,is_checked:!1,title_position:"end",title:"Toggle"},radioButton:{field_type:"radioButton",placeholder:"",label:"label",title:"",is_required:!1,title_position:"end",options:[],display:"row",default_value:""},table:{field_type:"table",label:"label",placeholder:"Add Label Text",is_required:!1,table_columns:[],table:"custom"},tagsInput:{field_type:"tagsInput",label:"label",placeholder:"Enter tagsInput",default_value:"",min_length:2,max_length:30,is_multiline:!1,is_required:!0,is_unique:!1}},Ee=[{label:"Text",value:"text",icon:T.Paragraph},{label:"Number",value:"number",icon:T.Hashtag},{label:"Select",value:"select",icon:T.ArrowCircleDown},{label:"Date",value:"date",icon:T.Calendar},{label:"Files & Media",value:"file",icon:T.PaperClip},{label:"URL",value:"url",icon:T.Link},{label:"Email",value:"email",icon:T.Email},{label:"Phone",value:"phone",icon:T.Phone},{label:"Currency",value:"currency",icon:T.DollarCircle},{label:"Time",value:"time",icon:T.Clock},{label:"Table",value:"table",icon:T.Grid},{label:"Geolocation",value:"geoLocation",icon:T.Location},{label:"Check Box",value:"checkbox",icon:T.CheckboxSquare},{label:"Image Upload",value:"image",icon:T.Image},{label:"Relation Field",value:"relation",icon:T.LinkHorizontal},{label:"Info Card",value:"info",icon:T.InfoCircle},{label:"Toggle Button",value:"toggleButton",icon:I.ToggleSwitch},{label:"Radio Button",value:"radioButton",icon:T.RadioButton},{label:"tagsInput",value:"tagsInput",icon:T.Paragraph}],Be=l=>{const[a,n]=t.useState(Ee),[r,i]=t.useState(""),s=e=>{i(e.target.value)};return t.useEffect(()=>{var e;n((e=r)?[...Ee.filter(t=>t.value.includes(e))]:Ee)},[r]),e.jsx(c.Select,{fullWidth:!0,placeholder:"Select Field",size:"small",labelName:"Field Type",renderValue:e=>{var t;return null==(t=Ee.find(t=>t.value===e))?void 0:t.label},handleSearch:()=>s,searchPlaceholder:"Search Attributes",searchValue:r,...l,children:a.map(t=>e.jsx(d.MenuItem,{value:t.value,onKeyDown:e=>e.stopPropagation(),children:e.jsxs(d.Stack,{direction:"row",spacing:1,alignItems:"center",children:[t.icon&&e.jsx(t.icon,{fontSize:"small"}),e.jsx(o.Typography,{type:"s3",color:"theme.secondary.1000",children:t.label})]})}))})},Ae=[1,2,3,4,5,6],Me=[{text:"12 Hour",value:"12hr"},{text:"24 Hour",value:"24hr"}],Fe=[{text:"INR (India)",value:"inr"},{text:"USD (US)",value:"usd"}],$e=new Set(["time","file","geoLocation","image","info","relation"]),De=new Set(["text","number"]),Pe=({option:t,index:l,prefix:a})=>e.jsx(d.MenuItem,{value:t.value,children:t.text||t.label},`${a}-${l}`),ze=({option:t,index:l,prefix:a})=>e.jsx(d.MenuItem,{value:t.value,children:e.jsx(o.Typography,{type:"s3",color:"theme.secondary.1000",children:t.label})},`${a}-${l}`);function Re(l){const{handlePropertyValueUpdate:a,handleColumnSelect:r,handleWidthChange:i,fields:s,element:u}=l,[m,p]=t.useState(u),[h,g]=t.useState(!1),[x,b]=t.useState([]),[y,v]=t.useState(""),j=t.useRef(u),S=t.useRef(s),C=t.useMemo(()=>s&&s!==S.current||!S.current||!s?(S.current=s,s?Object.keys(s).map(e=>({label:w.formatText(e),value:e})):[]):S.current,[s]),_=t.useCallback(e=>{if(!s||!e)return void b(e=>e.length>0?[]:e);const t=s[e];if(null==t?void 0:t.length){const e=t.map(e=>({label:e.field,value:e.field}));b(t=>t.length!==e.length||t.some((t,l)=>{var a,o;return t.value!==(null==(a=e[l])?void 0:a.value)||t.label!==(null==(o=e[l])?void 0:o.label)})?e:t)}else b(e=>e.length>0?[]:e)},[s]),k=t.useCallback(e=>{if(m){if(m.default_value!==e){const t={...m,default_value:e};p(t),a(null,null,e)}e&&(v(""),g(!1))}},[m,a]),T=t.useCallback(e=>{if(!m)return;const t=e.target.value;if(m.field_type!==t){const l={...m,field_type:t};p(l),a(null,null,null,e.target.value)}},[m,a]),I=t.useCallback(e=>{if(!m)return;const t=e.target.value;if(m.option!==t){const e={...m,option:t};p(e),a(null,null,t)}},[m,a]),E=t.useCallback(e=>{const t=e.target.value;(null==m?void 0:m.module)!==t&&(_(t),a(e))},[null==m?void 0:m.module,_,a]),B=t.useCallback((e,t)=>{if(!m)return;const l=Array.isArray(t)?t[0]:t;if(m.custom_width!==l){const e={...m,custom_width:l};p(e),i(l)}},[m,i]),A=t.useCallback(e=>{if(!m)return;const t=e.target.checked;if(m.is_fullwidth!==t){const l={...m,is_fullwidth:t};p(l),a(e)}},[m,a]),M=t.useCallback(e=>{const t=Number(e.target.value);r(t)},[r]),F=t.useCallback(e=>{var t;return["number","currency","geoLocation"].includes(e.field_type)?(null==(t=e.default_value)?void 0:t.toString().replace(/[^0-9]/g,""))||"":e.default_value||""},[]),$=t.useCallback(e=>"text"===e?{min:"Min character count (with spaces)",max:"Max character count (with spaces)"}:{min:"Min number",max:"Max number"},[]),D=t.useCallback(()=>g(!0),[]),P=t.useCallback(()=>{g(!1),v("")},[]),z=t.useCallback(e=>{v(e.target.value)},[]);t.useEffect(()=>{u!==j.current&&(p(u),j.current=u,(null==u?void 0:u.module)&&_(u.module))},[u,_]);const R=t.useMemo(()=>"currency"!==(null==m?void 0:m.field_type)?null:e.jsx(d.Box,{children:e.jsx(d.FormControl,{fullWidth:!0,children:e.jsx(c.Select,{fullWidth:!0,placeholder:"Select Currency",size:"small",onChange:I,defaultValue:m.option,label:"Currency",name:"option",variant:"outlined",children:Fe.map((t,l)=>e.jsx(Pe,{option:t,index:l,prefix:"currency"},`currency-${l}`))})})}),[null==m?void 0:m.field_type,null==m?void 0:m.option,I]),N=t.useMemo(()=>"time"!==(null==m?void 0:m.field_type)?null:e.jsx(d.Box,{children:e.jsx(d.FormControl,{fullWidth:!0,children:e.jsx(c.Select,{fullWidth:!0,placeholder:"Select Time Format",size:"small",onChange:I,defaultValue:m.option,label:"Time Format",name:"option",variant:"outlined",children:Me.map((t,l)=>e.jsx(Pe,{option:t,index:l,prefix:"time"},`time-${l}`))})})}),[null==m?void 0:m.field_type,null==m?void 0:m.option,I]),L=t.useMemo(()=>"relation"!==(null==m?void 0:m.field_type)?null:e.jsxs(e.Fragment,{children:[e.jsx(d.Box,{children:e.jsx(d.FormControl,{fullWidth:!0,children:e.jsx(c.Select,{fullWidth:!0,placeholder:C.length?"Select Relation Module":"No data available",size:"small",onChange:E,value:m.module||"",label:"Relation Module",name:"module",children:C.length?C.map((t,l)=>e.jsx(ze,{option:t,index:l,prefix:"module"},`module-${l}`)):e.jsx(d.MenuItem,{disabled:!0,children:e.jsx(o.Typography,{type:"s3",color:"theme.secondary.1000",children:e.jsx("em",{children:"No data available"})})})})})}),e.jsx(d.Box,{children:e.jsx(d.FormControl,{fullWidth:!0,children:e.jsx(c.Select,{fullWidth:!0,placeholder:m.module?x.length?"Select Relation Field":"No data available":"Select Module First",size:"small",onChange:a,value:m.field||"",label:"Relation Field",disabled:!m.module,name:"field",children:x.length?x.map((t,l)=>e.jsx(ze,{option:t,index:l,prefix:"field"},`field-${l}`)):e.jsx(d.MenuItem,{disabled:!0,children:e.jsx(o.Typography,{type:"s3",color:"theme.secondary.1000",children:e.jsx("em",{children:"No data available"})})})})})})]}),[null==m?void 0:m.field_type,null==m?void 0:m.module,null==m?void 0:m.field,C,x,E,a]);if(!m)return null;const{field_type:O}=m,q=$(O);return e.jsxs(d.Box,{className:"formSection--FieldContainer",children:[e.jsx(d.Box,{children:e.jsx(Be,{variant:"outlined",onChange:T,defaultValue:O,label:"Field Type",disabled:"system"===m.type||!m.is_new})}),e.jsx(d.Box,{children:e.jsx(c.TextField,{fullWidth:!0,label:"Label",is_required:!0,name:"label",type:"text",onChange:a,defaultValue:m.label})}),("file"===O||"image"===O)&&e.jsx(d.Box,{children:e.jsx(c.TextField,{fullWidth:!0,label:"Max File Size (in MB)",name:"max_size",type:"number",onChange:a,defaultValue:m.max_size})}),R,!$e.has(O)&&e.jsxs(e.Fragment,{children:[e.jsx(d.Box,{children:e.jsx(c.TextField,{fullWidth:!0,label:"Placeholder",name:"placeholder",type:"text",onChange:a,defaultValue:m.placeholder})}),e.jsx(d.Box,{children:e.jsx(c.TextField,{fullWidth:!0,label:"Default Value",placeholder:"Default Value",name:"default_value",type:"phone"===O?"tel":"number"===O?"number":"text",onChange:a,defaultValue:F(m)})})]}),N,L,De.has(O)&&e.jsxs(e.Fragment,{children:[e.jsx(d.Box,{children:e.jsx(c.TextField,{fullWidth:!0,label:q.min,name:"min_length",type:"number",onChange:e=>a(e,Number(e.target.value)),defaultValue:m.min_length||m.min||1})}),e.jsx(d.Box,{children:e.jsx(c.TextField,{fullWidth:!0,label:q.max,name:"max_length",type:"number",onChange:e=>a(e,Number(e.target.value)),defaultValue:m.max_length||m.max||("number"===O?1e4:255)})})]}),e.jsx(d.Box,{children:e.jsx(d.FormControl,{fullWidth:!0,children:e.jsx(c.Select,{fullWidth:!0,placeholder:"Select Column Per Row",size:"small",onChange:M,value:m.columns_per_row||1,label:"Select Column Per Row",name:"columns_per_row",variant:"outlined",children:Ae.map((t,l)=>e.jsx(d.MenuItem,{value:t,children:t},`column-${l}`))})})}),e.jsxs(d.Box,{children:[e.jsx(o.Typography,{sx:{color:"black",mb:1},children:"Adjust Width:"}),e.jsx(d.Slider,{value:m.custom_width||12,name:"custom_width",min:1,max:12,step:1,onChange:B,"aria-labelledby":"width-slider",sx:{color:"#4AC08C"},disabled:m.is_fullwidth,marks:!0,valueLabelDisplay:"auto"})]}),"number"===O&&e.jsxs(e.Fragment,{children:[e.jsx(d.Box,{children:e.jsx(c.TextField,{fullWidth:!0,label:"Float Step",name:"float_step",type:"number",step:"0.01",onChange:a,defaultValue:m.float_step})}),e.jsx(d.Box,{children:e.jsx(d.FormControlLabel,{name:"is_negative",control:e.jsx(n.Checkbox,{}),onChange:a,checked:m.is_negative||!1,label:"Allow Negative Numbers"})})]}),"date"===O&&e.jsxs(e.Fragment,{children:[e.jsx(d.Box,{children:e.jsx(d.FormControlLabel,{name:"is_future_dates_allowed",control:e.jsx(n.Checkbox,{}),onChange:a,checked:m.is_future_dates_allowed||!1,label:"Allow Future Dates"})}),e.jsx(d.Box,{children:e.jsx(d.FormControlLabel,{name:"is_past_dates_allowed",control:e.jsx(n.Checkbox,{}),onChange:a,checked:m.is_past_dates_allowed||!1,label:"Allow Past Dates"})})]}),"info"!==O&&e.jsx(d.Box,{children:e.jsx(d.FormControlLabel,{name:"is_required",control:e.jsx(n.Checkbox,{}),onChange:a,checked:m.is_required||!1,label:"This field is required"})}),"email"===O&&e.jsx(d.Box,{children:e.jsx(d.FormControlLabel,{name:"is_unique",control:e.jsx(n.Checkbox,{}),onChange:a,checked:m.is_unique||!1,label:"Is Unique"})}),"text"===O&&e.jsx(d.Box,{children:e.jsx(d.FormControlLabel,{name:"is_multiline",control:e.jsx(n.Checkbox,{}),onChange:a,checked:m.is_multiline||!1,label:"Is Multiline"})}),e.jsx(d.Box,{children:e.jsx(d.FormControlLabel,{name:"is_fullwidth",control:e.jsx(n.Checkbox,{}),onChange:A,checked:m.is_fullwidth||!1,label:"Full Width"})}),"info"===O&&e.jsx(d.Box,{children:e.jsx(c.Button,{variant:"outlined",startIcon:e.jsx(f.Add,{}),onClick:D,className:"formSection--PreviewButton",children:"Add Function"})}),e.jsxs(c.Modal,{fullWidth:!0,onClose:P,open:h,children:[e.jsxs(d.DialogTitle,{children:[e.jsx(o.Typography,{type:"s3",weight:"medium",color:"theme.secondary.1000",children:"Add Function"}),e.jsx(d.IconButton,{edge:"end",onClick:P,size:"small",children:e.jsx(f.Close,{fontSize:"inherit"})})]}),e.jsxs(d.DialogContent,{dividers:!0,children:[e.jsxs(o.Typography,{weight:"medium",type:"s3",color:"theme.secondary.700",sx:{mb:2},children:["Label: ",e.jsx("span",{style:{color:"#1F2125"},children:m.label})]}),e.jsx(c.TextField,{name:"default_value",fullWidth:!0,placeholder:"Add a function",multiline:!0,minRows:4,defaultValue:m.default_value,onChange:z,value:y})]}),e.jsxs(d.DialogActions,{children:[e.jsx(c.Button,{variant:"outlined",onClick:P,style:{color:"black"},children:"Cancel"}),e.jsx(c.Button,{onClick:()=>k(y),children:"Save"})]})]})]})}const Ne=[1,2,3,4,5,6],Le=t.memo(({element:l,handlePropertyValueUpdate:a,handleSelectOptionValueUpdate:r,handleColumnSelect:i,handleWidthChange:s})=>{const[u,m]=t.useState(l.options||[]),[p,h]=t.useState({label:"",value:""}),[g,x]=t.useState(!1);t.useEffect(()=>{JSON.stringify(u)!==JSON.stringify(l.options||[])&&m(l.options||[])},[l.options,u]);const b=t.useMemo(()=>"system"===l.type||!l.is_new,[l.type,l.is_new]),y=t.useMemo(()=>{const e=u.find(e=>e.value===l.default_value);return(null==e?void 0:e.label)||"Select Default"},[u,l.default_value]),v=t.useCallback(e=>{a(null,null,null,e.target.value)},[a]),j=t.useCallback(e=>{a(null,null,e.target.value)},[a]),C=t.useCallback(e=>{const t=e.target.checked;a({target:{name:"is_multiselect",checked:t,value:t}}),t&&l.default_value&&a(null,"default_value",null)},[a,l.default_value]),w=t.useCallback(e=>{const{name:t,value:l}=e.target;h(e=>({...e,[t]:l}))},[]),_=t.useCallback(()=>{if(!p.label.trim()||!p.value.trim())return;if(u.some(e=>e.value===p.value||e.label===p.label))return void S.enqueueSnackbar("Option with this value or label already exists.",{variant:"error"});const e=[...u,{...p}];m(e),r(e),h({label:"",value:""}),x(!1)},[p,u,r]),k=t.useCallback(e=>{const t=u.filter((t,l)=>l!==e);m(t),r(t);const o=u[e];l.default_value===(null==o?void 0:o.value)&&a(null,"default_value",null)},[u,r,l.default_value,a]),I=t.useCallback((e,t)=>{s(t)},[s]);return e.jsxs(d.Box,{className:"formSection--FieldContainer",children:[e.jsx(d.Box,{children:e.jsx(Be,{variant:"outlined",onChange:v,defaultValue:l.field_type,label:"Field Type",disabled:b})}),e.jsx(d.Box,{children:e.jsx(c.TextField,{fullWidth:!0,label:"Label",is_required:!0,name:"label",type:"text",onChange:a,defaultValue:l.label})}),e.jsx(d.Box,{children:e.jsx(c.TextField,{fullWidth:!0,label:"Placeholder",is_required:!0,name:"placeholder",type:"text",onChange:a,defaultValue:l.placeholder})}),e.jsx(d.Box,{children:e.jsx(c.Select,{fullWidth:!0,placeholder:"Select Default",size:"small",name:"default_value",onChange:j,value:l.default_value||"",label:"Default",variant:"outlined",disabled:l.is_multiselect,renderValue:()=>y,children:u.map((t,l)=>e.jsx(d.MenuItem,{value:t.value,children:t.label},`${t.value}-${l}`))})}),e.jsx(d.Box,{children:e.jsx(d.FormControl,{fullWidth:!0,children:e.jsx(c.Select,{fullWidth:!0,placeholder:"Select Column Per Row",size:"small",onChange:i,label:"Select Column Per Row",name:"columnPerRow",variant:"outlined",children:Ne.map(t=>e.jsx(d.MenuItem,{value:t,children:t},t))})})}),e.jsxs(d.Box,{children:[e.jsx(o.Typography,{sx:{color:"black",mb:1},children:"Adjust Width:"}),e.jsx(d.Box,{pr:2,children:e.jsx(d.Slider,{value:l.custom_width||6,min:1,max:12,step:1,onChange:I,"aria-labelledby":"width-slider",sx:{color:"#4AC08C"},marks:!0,valueLabelDisplay:"auto"})})]}),e.jsxs(d.Box,{className:"formSection--SelectOption",children:[e.jsx(o.Typography,{type:"s5",weight:"medium",color:"theme.secondary.800",sx:{mb:.5},children:"Options"}),u.map((t,l)=>e.jsxs(d.Box,{sx:{mb:1,display:"flex",gap:1},children:[e.jsx(c.TextField,{fullWidth:!0,value:`${t.label} (${t.value})`,InputProps:{readOnly:!0}}),e.jsx(d.IconButton,{color:"error",size:"small",onClick:()=>k(l),children:e.jsx(T.Trash,{})})]},`option-${l}`)),g&&e.jsxs(d.Box,{className:"formSection--SelectOption",sx:{mt:.5,p:2,border:"1px solid #ddd",borderRadius:1},children:[e.jsx(d.Box,{sx:{mb:2},children:e.jsx(c.TextField,{fullWidth:!0,label:"Option Label",is_required:!0,name:"label",type:"text",placeholder:"Enter option label",value:p.label,onChange:w})}),e.jsx(d.Box,{sx:{mb:2},children:e.jsx(c.TextField,{fullWidth:!0,label:"Option Value",placeholder:"Enter option value",is_required:!0,name:"value",type:"text",value:p.value,onChange:w})}),e.jsxs(d.Box,{sx:{display:"flex",gap:1},children:[e.jsx(c.Button,{onClick:_,startIcon:e.jsx(f.Add,{}),disabled:!p.label.trim()||!p.value.trim(),children:"Add Option"}),e.jsx(c.Button,{onClick:()=>{x(!1),h({label:"",value:""})},variant:"outlined",children:"Cancel"})]})]}),!g&&e.jsx(c.Button,{onClick:()=>x(!0),variant:"outlined",className:"formSection--Button",startIcon:e.jsx(f.Add,{}),sx:{mt:1},children:"Add Option"})]}),e.jsxs(d.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:[e.jsx(d.FormControlLabel,{name:"is_multiselect",control:e.jsx(n.Checkbox,{}),onChange:C,checked:l.is_multiselect,label:"Enable Multi Select"}),e.jsx(d.FormControlLabel,{name:"is_required",control:e.jsx(n.Checkbox,{}),onChange:a,checked:l.is_required,label:"This field is required"}),e.jsx(d.FormControlLabel,{name:"is_unique",control:e.jsx(n.Checkbox,{}),onChange:a,checked:l.is_unique,label:"Is Unique"}),e.jsx(d.FormControlLabel,{name:"is_fullwidth",control:e.jsx(n.Checkbox,{}),onChange:a,checked:l.is_fullwidth,label:"Full Width"})]})]})});Le.displayName="SelectEditForm";const Oe=l=>{var a;const{handlePropertyValueUpdate:r}=l,[i,s]=t.useState(l.element),[u,m]=t.useState(!1),[p,h]=t.useState(""),g=["section"],x=t.useMemo(()=>{var e;return null==(e=i.switcher_forms)?void 0:e.map(e=>e.name).includes(p)},[i.switcher_forms,p]);return t.useEffect(()=>{s(l.element)},[l.element]),e.jsxs(d.Box,{className:"formSection--FieldContainer",children:[e.jsx("div",{children:e.jsx(c.Select,{fullWidth:!0,placeholder:"Select Field",size:"small",disabled:!0,defaultValue:i.field_type,label:"Field Type",variant:"outlined",children:null==g?void 0:g.map(t=>e.jsx(d.MenuItem,{value:t,children:t}))},i.id)}),e.jsx("div",{children:e.jsx(c.Select,{fullWidth:!0,placeholder:"Select Field",size:"small",name:"section_type",defaultValue:i.section_type,label:"Section Type",variant:"outlined",onChange:e=>r(e),children:Object.values(w.SECTION_TYPES).map(t=>e.jsx(d.MenuItem,{value:t,children:t},t))},i.id)}),e.jsx("div",{children:e.jsx(c.TextField,{fullWidth:!0,label:"Label",is_required:!0,name:"label",type:"text",onChange:r,defaultValue:i.label},i.id)}),e.jsx(d.FormControlLabel,{name:"is_accordion",control:e.jsx(n.Checkbox,{}),onChange:r,checked:i.is_accordion,label:"Is Accordion"},i.id),i.section_type===w.SECTION_TYPES.FORM_SWITCH_SECTION?e.jsxs("div",{className:"formSection--SubFieldContainer",children:[e.jsx("div",{children:e.jsx(c.TextField,{fullWidth:!0,label:"Form label",is_required:!0,name:"form_switcher_label",type:"text",onChange:r,defaultValue:i.form_switcher_label},i.id)}),e.jsxs("div",{children:[e.jsx(o.Typography,{type:"s5",weight:"medium",color:"theme.secondary.800",children:"Forms"}),null==(a=null==i?void 0:i.switcher_forms)?void 0:a.map(t=>e.jsxs("div",{className:"formSection--MultiOptions",children:[e.jsx(c.TextField,{fullWidth:!0,value:t.name,style:{marginBottom:"10px"},name:"switcher_forms",onChange:e=>{var l;const a=null==(l=i.switcher_forms)?void 0:l.map(l=>t.id===l.id?{...l,name:e.target.value}:{...l});r(e,a)}},t.id),e.jsx(E,{style:{fontSize:"1rem",color:"#656669"},onClick:e=>{const l=[...i.switcher_forms].filter(e=>e.id!==t.id);e.target.name="switcher_forms",r(e,l)}})]},i.id))]}),u?e.jsxs("div",{children:[e.jsxs("div",{className:"formSection--MultiOptions formSection--FullWidth",children:[e.jsx("div",{className:"formSection--FullWidth",children:e.jsx(c.TextField,{fullWidth:!0,label:"Form section name",placeholder:"Form section name",is_required:!0,type:"text",value:p,error:x,helperText:x?"Form section name can not duplicate":"",onChange:e=>h(e.target.value)},i.id)}),e.jsx(E,{style:{fontSize:"1rem",color:"#656669"},onClick:()=>{m(!1),h("")}})]},i.id),e.jsx(c.Button,{onClick:e=>{const{uniqueStringId:t}=w.generateRandomId(),l=[...i.switcher_forms,{name:p,id:t}];r(e,l),h(""),m(!1)},name:"switcher_forms",variant:"text",className:"formSection--Button",disabled:x||!p,startIcon:e.jsx(f.Add,{}),children:"Add"})]}):null,u?null:e.jsx(c.Button,{onClick:()=>m(!0),variant:"text",className:"formSection--Button",startIcon:e.jsx(f.Add,{}),children:"Add forms"})]}):null]},i.id)};function qe(l){const[a,r]=t.useState(!1),{handlePropertyValueUpdate:i,handleSelectOptionValueUpdate:s,handleColumnSelect:u,handleWidthChange:m}=l,p=[1,2,3,4,5,6],[h,g]=t.useState(l.element.options||[]),[x,b]=t.useState(l.element),y="radioButton"!==x.field_type,[v,j]=t.useState({label:"",value:"",is_checked:!1}),S=e=>{const t=e.target.name,l=e.target.value,a={...v};a[t]=l,j(a)},C=e=>{x.default_value=e.target.value,i(null,null,e.target.value)};return t.useEffect(()=>{b(l.element),g(l.element.options||[])},[l.element]),t.useEffect(()=>{j({label:"",value:"",is_checked:!1}),r(!1),s(h)},[h]),e.jsxs(d.Box,{className:"formSection--FieldContainer",children:[e.jsx("div",{children:e.jsx(Be,{variant:"outlined",onChange:e=>{x.field_type=e.target.value,i(null,null,null,e.target.value)},defaultValue:x.field_type,label:"Field Type",disabled:"system"===x.type||!x.is_new},x.id)},x.id),e.jsx("div",{children:e.jsx(c.TextField,{fullWidth:!0,label:"Label",is_required:!0,name:"label",type:"text",onChange:i,defaultValue:x.label},x.id)},x.id),e.jsx("div",{children:e.jsx(d.Select,{variant:"outlined",fullWidth:!0,placeholder:"Select Default",size:"small",name:"options",onChange:()=>C,defaultValue:x.default_value,label:"Default",disabled:!h.length,children:null==h?void 0:h.map((t,l)=>e.jsx(d.MenuItem,{value:t.value,children:t.label},l))},x.id)},x.id),e.jsx(d.FormControl,{children:e.jsx(d.Select,{fullWidth:!0,placeholder:"Select Column Per Row",size:"small",onChange:u,label:"Select Column Per Row",name:"option",variant:"outlined",children:null==p?void 0:p.map((t,l)=>e.jsx(d.MenuItem,{value:t,children:t},l))},x.id)}),e.jsxs(d.Box,{children:[e.jsx(o.Typography,{sx:{color:"black"},children:"Adjust Width:"}),e.jsx(d.Slider,{value:null==x?void 0:x.custom_width,name:"custom_width",min:1,max:12,step:1,onChange:(e,t)=>m(t),"aria-labelledby":"width-slider",sx:{color:"#4AC08C"}})]}),e.jsxs("div",{className:"formSection--SelectOption",children:[e.jsx(o.Typography,{type:"s5",weight:"medium",color:"theme.secondary.800",children:"Options"}),h.map((t,l)=>e.jsxs("div",{className:"formSection--MultiOptions",children:[e.jsx(c.TextField,{fullWidth:!0,value:`${t.label} (${t.value})`,InputProps:{readOnly:!0}},l),e.jsx(E,{style:{fontSize:"1rem",color:"#656669"},onClick:()=>{g([...h.filter((e,t)=>t!==l)])}})]}))]}),a?e.jsxs("div",{className:"formSection--SelectOption",children:[e.jsx("div",{children:e.jsx(c.TextField,{fullWidth:!0,label:"Label",is_required:!0,name:"label",type:"text",placeholder:"Label",defaultValue:v.label,onChange:S})}),e.jsx("div",{children:e.jsx(c.TextField,{fullWidth:!0,label:"Value",placeholder:"Value",is_required:!0,name:"value",type:"text",defaultValue:v.value,onChange:S})}),e.jsx(d.Button,{onClick:()=>g([...h,{...v}]),disabled:!!h.find(e=>e.value===v.value),variant:"text",className:"formSection--Button",startIcon:e.jsx(f.Add,{}),children:"Add"})]}):e.jsx(d.Button,{onClick:()=>r(!0),variant:"text",className:"formSection--Button",startIcon:e.jsx(f.Add,{}),children:"Add Option"}),e.jsxs(d.FormControl,{children:[e.jsx(o.Typography,{type:"s4",color:"theme.secondary.800",children:"Display style"}),e.jsxs(d.RadioGroup,{row:!0,"aria-labelledby":"demo-radio-buttons-group-label",name:"display",onChange:i,defaultValue:x.display,children:[e.jsx(d.FormControlLabel,{value:"row",control:e.jsx(n.Radio,{size:"small"}),label:"Row",slotProps:{typography:{variant:"body2"}}}),e.jsx(d.FormControlLabel,{value:"column",control:e.jsx(n.Radio,{size:"small"}),label:"Column",slotProps:{typography:{variant:"body2"}}})]},x.id)]}),e.jsx("div",{children:e.jsx(c.TextField,{fullWidth:!0,label:"Title",is_required:!0,name:"title",type:"text",onChange:i,defaultValue:x.title},x.id)},x.id),e.jsxs(d.FormControl,{disabled:!y,children:[e.jsx(o.Typography,{type:"s4",color:"theme.secondary.800",children:"Title Position"}),e.jsxs(d.RadioGroup,{row:!0,"aria-labelledby":"demo-radio-buttons-group-label",name:"title_position",onChange:i,defaultValue:y?"end":"",children:[e.jsx(d.FormControlLabel,{value:"start",control:e.jsx(n.Radio,{size:"small"}),label:"Start",slotProps:{typography:{variant:"body2"}}}),e.jsx(d.FormControlLabel,{value:"end",control:e.jsx(n.Radio,{size:"small"}),label:"End",slotProps:{typography:{variant:"body2"}}})]},x.id)]}),e.jsx(d.FormControlLabel,{name:"is_required",control:e.jsx(n.Checkbox,{}),onChange:i,checked:x.is_required,label:"This field is required"},x.id),e.jsx(d.FormControlLabel,{name:"is_unique",control:e.jsx(n.Checkbox,{}),onChange:i,checked:x.is_unique,label:"Is Unique"},x.id),e.jsx(d.FormControlLabel,{name:"is_fullwidth",control:e.jsx(n.Checkbox,{}),onChange:i,checked:null==x?void 0:x.is_fullwidth,label:"Full Width "},x.id)]},x.id)}const We=({handlePropertyValueUpdate:l,element:a,handleColumnsUpdate:o,fields:n})=>{const[r,i]=t.useState(a),[s,u]=t.useState([]);return t.useEffect(()=>{i(a)},[a]),t.useEffect(()=>{if(r&&r.table&&n){const e=n[r.table];let t=[];t=e&&(null==e?void 0:e.length)?e.map((e,t)=>({header:w.formatText(e.field),accessorKey:e.field,visible:!(t>3),type:e.type})):[{header:"Column 1",accessorKey:"column_1",visible:!0},{header:"Column 2",accessorKey:"column_1",visible:!0}],t&&o(t)}},[null==r?void 0:r.table]),t.useEffect(()=>{if(n){const e=Object.keys(n).map(e=>({label:w.formatText(e),value:e}));u(e)}},[n]),r?e.jsxs(d.Box,{className:"formSection--FieldContainer",children:[e.jsx("div",{children:e.jsx(Be,{variant:"outlined",onChange:e=>{r&&(r.field_type=e.target.value,l(null,null,null,e.target.value))},defaultValue:r.field_type,disabled:"system"===r.type||!r.is_new},r.id)},r.id),e.jsx("div",{children:e.jsx(c.TextField,{fullWidth:!0,label:"Label",is_required:!0,name:"label",type:"text",onChange:l,defaultValue:r.label},r.id)},r.id),e.jsx("div",{children:e.jsx(c.Select,{variant:"outlined",label:"Table",fullWidth:!0,placeholder:"Select Table",size:"small",name:"table",defaultValue:r.table,disabled:"system"===r.type,onChange:e=>{l(e)},renderValue:e=>{var t;return null==(t=s.find(t=>t.value===e))?void 0:t.label},children:null==s?void 0:s.map(t=>e.jsx(d.MenuItem,{value:t.value,children:t.label}))},r.id)},r.id)]},r.id):null},He=t.memo(({field:l,index:a,gridItemSize:o,activeMember:r,control:i,t:s,element:u,images:m,elementJSON:p,remove:h,move:g,handleElementSelection:x,setElementSwap:b,handleDuplicateElement:f,setSelectedHoc:y,setActiveMember:v})=>{const j=t.useMemo(()=>({activeIndex:r===a,removeElement:h,index:a,onClick:x,swap:g,elementSwap:()=>b(!0),handleDuplicate:f,setElementHoc:()=>{y(""),v(void 0)}}),[r,a,h,x,g,b,f,y,v]),S=t.useMemo(()=>({key:l.id,position:a,placeholder:s(l.placeholder||""),label:s(l.label),formControl:i,name:"message",fieldArrayName:"members",required:l.is_required,formType:"builder",typeOfField:l.type,disabled:!0}),[l.id,l.placeholder,l.label,l.is_required,l.type,a,s,i]),C=t.useCallback(()=>{const{field_type:t}=l;switch(t){case u.text.field_type:return e.jsx(c.DynamicInput,{...S,type:t,defaultValue:l.default_value,is_multiline:l.is_multiline,min:l.min_length,max:l.max_length});case u.email.field_type:return e.jsx(c.DynamicInput,{...S,type:t,defaultValue:l.default_value,endIcon:e.jsx("img",{src:m.sms,alt:"email"})});case u.number.field_type:return e.jsx(c.DynamicInput,{...S,type:t,defaultValue:l.default_value,min:l.min_length,max:l.max_length,float_step:l.float_step});case u.phone.field_type:return e.jsx(n.DynamicPhone,{...S,type:t,default_value:l.default_value});case u.select.field_type:return e.jsx(n.DynamicSelect,{...S,options:l.options,defaultValue:l.default_value,is_multiselect:l.is_multiselect});case u.date.field_type:return e.jsx(n.DynamicDate,{...S,defaultValue:l.default_value,is_future_dates_allowed:l.is_future_dates_allowed,is_past_dates_allowed:l.is_past_dates_allowed,disable:!0});case u.time.field_type:return e.jsx(n.DynamicTime,{...S,option:l.option});case u.url.field_type:return e.jsx(c.DynamicInput,{...S,type:t,defaultValue:l.default_value,endIcon:e.jsx("img",{src:m.url,alt:"url"})});case u.currency.field_type:return e.jsx(c.DynamicInput,{...S,type:t,defaultValue:l.default_value,endIcon:e.jsx("img",{src:m.dollar,alt:"currency"})});case u.file.field_type:case u.image.field_type:return e.jsx(n.DynamicMedia,{...S,type:t,max_size:l.max_size});case u.geoLocation.field_type:return e.jsx(c.DynamicInput,{...S,type:t,defaultValue:l.default_value,endIcon:e.jsx("img",{src:m.location,alt:"location"})});case u.relation.field_type:return e.jsx(c.DynamicInput,{...S,type:t,defaultValue:l.default_value,is_multiline:l.is_multiline,min:l.min_length,max:l.max_length,label:e.jsxs("span",{className:"formSection--Relation","data-position":a,"data-name":`members.${a}.message`,children:[s(l.label),e.jsx("img",{src:m.relation,alt:"relation"})]})});case u.info.field_type:return e.jsx(n.DynamicInfo,{...S,defaultValue:l.default_value});case u.toggleButton.field_type:return e.jsx(n.DynamicToggleButton,{...S,title:s(l.title||""),titlePosition:null==p?void 0:p.title_position});case u.radioButton.field_type:return e.jsx(n.DynamicRadioButton,{...S,options:l.options,display:l.display,titlePosition:null==p?void 0:p.title_position});case u.tagsInput.field_type:return e.jsx(c.DynamicInput,{...S,type:t,defaultValue:l.default_value,is_multiline:l.is_multiline,min:l.min_length,max:l.max_length});case u.checkbox.field_type:return e.jsx(n.DynamicCheckBox,{...S,title:s(l.title||""),titlePosition:l.title_position});case u.table.field_type:return e.jsx(n.DynamicTable,{...S,columns:l.table_columns||(null==p?void 0:p.table_columns)||[]});default:return console.warn(`Unknown field type: ${t}`),null}},[l,S,u,m,p,s,a]);return e.jsx(d.Grid,{item:!0,xs:o,children:e.jsx(n.DynamicElementHOC,{...j,element:l.field_type,children:C()})})});He.displayName="FormField";const Ve=t.memo(({sectionMembers:l,members:a,activeMember:o,control:n,t:r,element:i,images:s,elementJSON:d,remove:c,move:u,handleElementSelection:m,setElementSwap:p,handleDuplicateElement:h,setSelectedHoc:g,setActiveMember:x})=>{const b=t.useCallback(e=>e.is_fullwidth||"table"===e.field_type?12:e.custom_width?e.custom_width:6,[]),f=t.useMemo(()=>l.map(t=>{const l=a.findIndex(e=>e===t),f=b(t);return e.jsx(He,{field:t,index:l,gridItemSize:f,activeMember:o,control:n,t:r,element:i,images:s,elementJSON:d,remove:c,move:u,handleElementSelection:m,setElementSwap:p,handleDuplicateElement:h,setSelectedHoc:g,setActiveMember:x},`${t.id}-${l}`)}),[l,a,o,n,r,i,s,d,c,u,m,p,h,g,x,b,null==d?void 0:d.field_type]);return e.jsx(e.Fragment,{children:f})});Ve.displayName="FormFields";const Ge={accounting:a.PathnameAccounting.FORMS,inventory:a.PathnameInventory.FORMS,manufacturing:a.PathnameManufacturing.FORMS,procurement:a.PathnamePurchase.FORMS,crm:a.PathnameCrm.FORMS,rental:a.PathnameRental.FORMS,user:B.PathnameUsers.FORMS,hrms:B.PathnameHrms.FORMS},Ue=e=>e.split("_").map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(" "),Ke=(e,t)=>{var l,a;if(null==(l=e.table_columns)?void 0:l.length)return e.table_columns;if(!e.table||!(null==(a=t.fields)?void 0:a[e.table]))return[{header:"Column 1",accessorKey:"column_1",visible:!0},{header:"Column 2",accessorKey:"column_2",visible:!0}];const o=t.fields[e.table];return Array.isArray(o)&&0!==o.length?o.map((e,t)=>({header:Ue(e.field),accessorKey:e.field,visible:t<=3})):[{header:"Column 1",accessorKey:"column_1",visible:!0},{header:"Column 2",accessorKey:"column_2",visible:!0}]},Je=(e,t)=>e.flatMap(e=>e.members.map(e=>"table"===e.field_type?{...e,table_columns:Ke(e,t)}:{...e})),Ye=e=>e.map(({field_type:e,label:t,is_accordion:l,id:a,remove_section:o,form_switcher_label:n,form_switcher_name:r,is_section_field:i,section_type:s,switcher_forms:d})=>({field_type:e,label:t,is_accordion:l,id:a,remove_section:o,form_switcher_label:n,form_switcher_name:r,is_section_field:i,section_type:s,switcher_forms:d})),Ze=(e,t=0,l,a,o)=>{const{removeSection:n,remove:r}=o;try{if(n(),r(),e.tab)Xe(e.tab,t,l,o);else if(e.section)Qe(e.section,l,o);else{if(!e.tabsData||!a)throw new Error("Invalid data format: Missing required properties (tab, section, or tabsData)");et(a,t,o)}}catch(i){console.error("Error processing data:",i),alert(i instanceof Error?i.message:"An error occurred while processing data")}},Xe=(e,t,l,a)=>{const{setTabsData:o,append:n,appendSection:r}=a;o(e);const i=e.find(e=>e.tab_order===t+1);if(!(null==i?void 0:i.data))return void console.warn(`No active tab found for tab order: ${t+1}`);const s=Ye(i.data);n(Je(i.data,l)),r(s)},Qe=(e,t,l)=>{const{append:a,appendSection:o}=l,n=Ye(e);a(Je(e,t)),o(n)},et=(e,t,l)=>{const{append:a,appendSection:o}=l,n=e.find(e=>e.tab_order===t+1);if(!(null==n?void 0:n.data))return void console.warn(`No active tab found for tab order: ${t+1}`);const r=Ye(n.data),i=n.data.flatMap(e=>e.members.map(e=>({...e})));i.length>0&&a(i),r.length>0&&o(r)},tt=(e,l,a=0,o)=>{const{removeSection:n,remove:r,append:i}=o;t.useEffect(()=>{var t;let d=null;if(null==(t=null==e?void 0:e.formData)?void 0:t.length)try{d=s.formBuilderDeConversion(e.formData)}catch(c){console.error("Error converting form data:",c)}if(!d)return n(),r(),void i([]);try{l.length>0?Ze({tabsData:l},a,e,l,o):d.tab?Ze(d,a,e,l,o):d.section?Ze(d,0,e,l,o):(console.warn("Invalid data structure in initialData"),n(),r(),i([]))}catch(c){console.error("Error processing form data:",c),n(),r(),i([])}},[a,JSON.stringify(null==e?void 0:e.formData),l.length])},lt=e=>{try{const t=(e=>{if(!(e in Ge))throw new Error(`Invalid module: ${e}`);return Ge[e]})(e);return`/dashboard/${e}${t}`}catch(t){throw console.error("Error generating module path:",t),t}},at=e=>!isNaN(Number(e))&&isFinite(Number(e)),ot=e=>JSON.parse(JSON.stringify(e)),nt=(e="")=>({uniqueStringId:`${Date.now()}${e}${Math.random().toString(36).substr(2,9)}`}),rt=new class{generateScopeId(){return`email-tpl-${Date.now()}-${Math.random().toString(36).substring(2,11)}`}scopeCSS(e,t){return e&&t?this.parseCSS(e).map(e=>this.scopeRule(e,t)).join("\n"):e}parseCSS(e){const t=[];let l="",a=0,o=!1;for(let n=0;n<e.length;n++){const r=e[n],i=e[n+1];"/"!==r||"*"!==i?o&&"*"===r&&"/"===i?(o=!1,l+=r):(l+=r,o||("{"===r?a++:"}"===r&&(a--,0===a&&l.trim()&&(t.push(l.trim()),l="")))):(o=!0,l+=r)}return l.trim()&&t.push(l.trim()),t}scopeRule(e,t){const l=e.indexOf("{");if(-1===l)return e;const a=e.substring(0,l).trim(),o=e.substring(l);return`${a.split(",").map(e=>e.trim()).map(e=>this.scopeSelector(e,t)).join(", ")} ${o}`}scopeSelector(e,t){return e.startsWith(":root")||e.startsWith(":host")||e.startsWith("@")?e:`.${t} ${e}`}wrapHTMLWithScope(e,t){return e&&t?`<div class="${t}">\n${e}\n</div>`:e}extractInlineStyles(e){const t=new Map;return(new DOMParser).parseFromString(e,"text/html").querySelectorAll("[style]").forEach((e,l)=>{const a=e.getAttribute("style");if(a){const o=this.parseInlineStyles(a),n=`${e.tagName.toLowerCase()}-${l}`;t.set(n,o)}}),t}parseInlineStyles(e){const t={};return e.split(";").filter(e=>e.trim()).forEach(e=>{const l=e.indexOf(":");if(l>-1){const a=e.substring(0,l).trim(),o=e.substring(l+1).trim();t[a]=o}}),t}mergeStyles(e,t){return{...e,...t}}scopeTemplate(e,t=""){const l=this.generateScopeId();return{scopeId:l,scopedCSS:t?this.scopeCSS(t,l):"",wrappedHTML:this.wrapHTMLWithScope(e,l)}}},it=(e,t)=>{const l=`${e}${M.TEMPLATE_EDITOR_PATHS.TEMPLATES_LIST(t)}`,a=`${e}${M.TEMPLATE_EDITOR_PATHS.TEMPLATES_ADD(t)}`,o=`${e}${M.TEMPLATE_EDITOR_PATHS.TEMPLATES_EDIT(t)}`;return{LIST:l,ADD_TEMPLATE:e=>a.replace(":id",e),EDIT_TEMPLATE:(e,t)=>o.replace(":id",e).replace(":template_id",t)}},st=(e,t=[],l=[],a=!1,o)=>{const n=t&&(null==t?void 0:t.length)?dt(t,"header"):"",r=l&&(null==l?void 0:l.length)?dt(l,"footer"):"";let i=`\n <html>\n <head>\n <style>\n .email-container {\n margin: 0 auto;\n margin-bottom: 20px;\n background-color: #fff;\n border-radius: 8px;\n max-width: ${a?"65%":"800px"};\n width: 100%;\n }\n a {\n color: #007bff !important;\n text-decoration: none !important;\n }\n a:hover {\n text-decoration: underline;\n }\n * {\n margin: 0;\n padding: 0;\n box-sizing: border-box;\n }\n\n body {\n font-family: "Inter", sans-serif !important;\n font-size: 16px;\n font-weight: 400;\n color: #00011c;\n font-style: normal;\n }\n\n img {\n display: block;\n height: auto;\n }\n\n table,\n tr,\n td {\n border-collapse: collapse;\n }\n\n a {\n text-decoration: none;\n }\n\n table.our-details,\n .our-details td,\n .our-details th {\n border: 1px solid #d3d3d4;\n }\n\n table.amount-word-table,\n table.amount-word-table td,\n table.amount-word-table th {\n border: 1px solid #d6d6d6;\n }\n\n .amount-word-table thead th {\n background-color: #f5f6f5;\n }\n\n .amount-word-table thead td {\n background-color: #f5f6f5;\n }\n\n .amount-word-table tbody tr:nth-child(even) {\n background-color: #f5f6f5;\n }\n\n .amount-word-table tbody tr td {\n border-top: 0;\n border-bottom: 0;\n }\n\n .deliver-table thead th {\n background-color: transparent;\n }\n </style>\n </head>\n <body>\n <div class="email-container ${o||rt.generateScopeId()}">\n ${n}\n ${n?"<hr/>":""}\n `;const s=[];let d=[],c=null;for(const u of e)u.isSplitPair&&0!==u.splitGroupId?(c!==u.splitGroupId&&d.length>0&&(s.push(d),d=[]),d.push(u),c=u.splitGroupId):(d.length>0&&(s.push(d),d=[],c=null),s.push([u]));d.length>0&&s.push(d);for(const u of s)if(1!==u.length||u[0].isSplitPair){i+='<table style="width: 100%; border-collapse: collapse;"><tr>';for(const e of u)i+=`<td style="width: ${e.splitWidth}%; vertical-align: top; padding: 10px;">\n ${e.content}\n </td>`;i+="</tr></table>"}else i+=`<div style="padding: 10px;">${u[0].content}</div>`;return i+=`\n ${r?"<hr/>":""}\n ${r}\n </div></body></html>`,i},dt=(e,t="header",l)=>{let a=`<${t} class="${t}${l?` ${l}`:""}">`;const o=[];let n=[],r=null;for(const i of e)i.isSplitPair&&0!==i.splitGroupId?(r!==i.splitGroupId&&n.length>0&&(o.push(n),n=[]),n.push(i),r=i.splitGroupId):(n.length>0&&(o.push(n),n=[],r=null),o.push([i]));n.length>0&&o.push(n);for(const i of o)if(1!==i.length||i[0].isSplitPair){a+='<table style="width: 100%; border-collapse: collapse;"><tr>';for(const e of i)a+=`<td style="width: ${e.splitWidth}%; vertical-align: top; padding: 10px;">\n ${e.content}\n </td>`;a+="</tr></table>"}else a+=`<div style="padding: 10px;">${i[0].content}</div>`;return a+=`</${t}>`,a},ct=(e,t)=>{const l=document.createElement("div");l.innerHTML=e;const a=l.firstChild;if(!a)return{};if((null==a?void 0:a.getAttribute)instanceof Function==0)return{};const o=null==a?void 0:a.getAttribute("style"),n=(null==a?void 0:a.attributes)||[],r=Array.from(n).reduce((e,t)=>(e[t.name]=t.value,e),{});if(!o)return{};const i={};return o.split(";").filter(e=>""!==e.trim()).forEach(e=>{const[t,l]=e.split(":").map(e=>e.trim());if(t&&l){const e=t.replace(/-([a-z])/g,e=>e[1].toUpperCase());i[e]=l}}),r.styles=i,r},ut=new Set(["background","background-color","border","border-style","border-collapse","border-top","border-right","border-bottom","border-left","border-color","border-radius","color","display","font","font-family","font-size","font-style","font-weight","height","line-height","margin","margin-top","margin-right","margin-bottom","margin-left","padding","padding-top","padding-right","padding-bottom","padding-left","text-align","text-decoration","vertical-align","width","max-width","min-width","max-height","min-height"]),mt=(e,t="")=>e&&"object"==typeof e?Object.entries(e).reduce((e,[l,a])=>{if(null==a)return e;const o=t?`${t}-${l}`:l;if("object"==typeof a&&!Array.isArray(a))return e.push(mt(a,o)),e;const n=o.replace(/([A-Z])/g,"-$1").toLowerCase();if(!ut.has(n)&&"fullWidth"!==l&&"alignment"!==l)return e;if("fullWidth"===l&&!0===a)return e.push("width: 100%"),e;if("alignment"===l&&"string"==typeof a)return e.push(`text-align: ${a}`),e;if("boolean"==typeof a)return e;const r="number"!=typeof a||["z-index","opacity","line-height"].includes(l)?a:`${a}px`;return e.push(`${n}: ${r}`),e},[]).filter(Boolean).join("; "):"",pt=(e,t={})=>{let l="";const a=M.initialStyles[e]||{},o=mt(a);switch(e){case"heading":l=`<h1 style="${o}">Heading 1</h1>`;break;case"heading-2":l=`<h2 style="${o}">Heading 2</h2>`;break;case"heading-3":l=`<h3 style="${o}">Heading 3</h3>`;break;case"heading-4":l=`<h4 style="${o}">Heading 4</h4>`;break;case"text":l=`<p style="${o}">Hello, enter your text here...</p>`;break;case"image":l=`<img src="${(null==t?void 0:t.src)||""}" alt="${(null==t?void 0:t.alt)||""}" style="${o};" />`;break;case"buttons":t.text=(null==t?void 0:t.text)||"Button text",l=`<button style="${o}">${t.text}</button>`;break;case"divider":l=`<hr style="${o}" />`;break;case"table":{const{border:e,borderStyle:t,borderColor:o,...n}=a,r=mt(a.is_bordered?a:n),i=mt(a.tHead),s=mt(a.tBody),d=mt({...a.thCells,border:e,borderStyle:t,borderColor:o}),c=mt({...a.tbCells,border:e,borderStyle:t,borderColor:o});l=`\n <table style="${r}">\n <thead style="${i}">\n <tr style="background-color: #f5f5f5;">\n <th style="${d}"></th>\n <th style="${d}"></th>\n <th style="${d}"></th>\n </tr>\n </thead>\n <tbody style="${s}">\n <tr>\n <td style="${c}"></td>\n <td style="${c}"></td>\n <td style="${c}"></td>\n </tr>\n </tbody>\n </table>\n `;break}case"signature":l=`<div style="${o}">Signature: <input type='text' style="border:0; border-bottom:1px solid black" class='signature-input'/></div>`;break;case"qr-code":t.placeholder=(null==t?void 0:t.placeholder)||"{{qr_data}}",l=`<div style="background-color: #f5f5f5; padding: 16px; text-align: center; color: #666666;">${t.placeholder}</div>`;break;case"bar-code":t.placeholder=(null==t?void 0:t.placeholder)||"{{barcode_data}}",l=`<div style="background-color: #f5f5f5; padding: 16px; text-align: center; color: #666666;">${t.placeholder}</div>`;break;default:l='<p style="font-size: 16px; color: #333333; line-height: 1.5;">New section</p>'}return ct(l),{content:l,type:e,attributes:{...t||{},styles:a}}},ht=({onSave:t,onPreview:a,preview:n,editHtml:r,onEditHtml:i,sections:s,isEditingHeaderFooter:u,onEditModeChange:m,setIsEditingHeaderFooter:p,onSaveHeaderFooter:h,modulePath:x,type:b,mode:y="add",templateData:v,isSaving:j=!1,editMode:S,fromPreview:C=!1,zoom:w,onZoomIn:_,onZoomOut:k,onResetZoom:I})=>{const E=it(x,b);return e.jsx(d.AppBar,{position:"static",color:"default",elevation:0,sx:{borderColor:"divider",bgcolor:"background.paper"},children:e.jsxs(d.Toolbar,{variant:"dense",sx:{justifyContent:"space-between",p:3},children:[e.jsxs(d.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(d.Link,{component:l.Link,to:E.LIST,underline:"hover",color:"text.secondary",sx:{fontSize:"0.875rem"},children:e.jsx(o.Typography,{type:"s5",color:"theme.secondary.800",children:"email"===b?"Emails":"PDF"})}),e.jsx(o.Typography,{type:"s5",weight:"medium",color:"theme.secondary.1000",children:"/"}),e.jsxs(o.Typography,{type:"s5",weight:"medium",color:"theme.secondary.1000",children:["add"===y?"Add New":S?"Edit":"Preview"," Template"]}),v&&(null==v?void 0:v.name)&&e.jsxs(e.Fragment,{children:[e.jsx(o.Typography,{type:"s5",weight:"medium",color:"theme.secondary.1000",children:"/"}),e.jsx(o.Typography,{type:"s5",weight:"medium",color:"theme.secondary.1000",children:null==v?void 0:v.name})]})]}),e.jsxs(d.Stack,{direction:"row",spacing:1,alignItems:"center",children:[n&&e.jsxs(e.Fragment,{children:[e.jsxs(d.Box,{sx:{display:"flex",alignItems:"center",gap:1,borderRadius:1,bgcolor:"rgba(74, 192, 140, 0.08)",border:"1px solid rgba(74, 192, 140, 0.2)"},children:[e.jsx(d.IconButton,{size:"small",onClick:k,disabled:w<=50,color:"#4AC08C",sx:{color:"#4AC08C","&:hover":{bgcolor:"rgba(74, 192, 140, 0.15)"},"&.Mui-disabled":{opacity:.3,color:"#4AC08C"}},children:e.jsx(f.ZoomOut,{fontSize:"small"})}),e.jsxs(o.Typography,{type:"s5",weight:"medium",sx:{minWidth:"50px",textAlign:"center",color:"#4AC08C"},children:[w,"%"]}),e.jsx(d.IconButton,{size:"small",onClick:_,disabled:w>=150,sx:{color:"#4AC08C","&:hover":{bgcolor:"rgba(74, 192, 140, 0.15)"},"&.Mui-disabled":{opacity:.3,color:"#4AC08C"}},children:e.jsx(f.ZoomIn,{fontSize:"small"})}),e.jsx(d.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5,bgcolor:"rgba(74, 192, 140, 0.3)"}}),e.jsx(d.IconButton,{size:"small",onClick:I,disabled:100===w,title:"Reset Zoom",sx:{color:"#4AC08C","&:hover":{bgcolor:"rgba(74, 192, 140, 0.15)"},"&.Mui-disabled":{opacity:.3,color:"#4AC08C"}},children:e.jsx(f.ZoomOutMap,{fontSize:"small"})})]}),e.jsx(d.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:1}})]}),C?S?e.jsx(e.Fragment,{children:u?e.jsxs(e.Fragment,{children:[e.jsx(c.Button,{onClick:()=>p(!1),size:"small",variant:"outlined",sx:e=>({color:`${e.palette.theme.secondary[1e3]} !important`}),children:"Cancel Editing"}),e.jsx(c.Button,{variant:"contained",onClick:h,size:"small",sx:{boxShadow:"none"},children:"Save Changes"})]}):e.jsxs(e.Fragment,{children:[e.jsx(c.Button,{onClick:()=>p(!0),size:"small",variant:"outlined",sx:e=>({color:`${e.palette.theme.secondary[1e3]} !important`}),startIcon:e.jsx(T.Edit,{fontSize:"small"}),disabled:n,children:"Edit Header/Footer"}),e.jsx(c.Button,{onClick:a,size:"small",variant:"outlined",sx:e=>({color:`${e.palette.theme.secondary[1e3]} !important`}),startIcon:n?e.jsx(g.EyeOff,{fontSize:"small"}):e.jsx(g.Eye,{fontSize:"small"}),disabled:!(null==s?void 0:s.length),children:"Preview"}),e.jsx(c.Button,{variant:"contained",onClick:t,size:"small",sx:{boxShadow:"none"},disabled:!(null==s?void 0:s.length),children:"Save"}),e.jsx(c.Button,{onClick:()=>m&&m(),size:"small",variant:"outlined",sx:e=>({color:`${e.palette.theme.secondary[1e3]} !important`}),children:"Cancel"})]})}):e.jsx(c.Button,{variant:"contained",onClick:()=>m&&m(),size:"small",sx:{boxShadow:"none"},startIcon:e.jsx(T.Edit,{fontSize:"small"}),disabled:!(null==s?void 0:s.length),children:"Edit"}):e.jsxs(e.Fragment,{children:[e.jsx(c.Button,{onClick:()=>p(!0),size:"small",variant:"outlined",sx:e=>({color:`${e.palette.theme.secondary[1e3]} !important`}),startIcon:e.jsx(T.Edit,{fontSize:"small"}),disabled:n,children:"Edit Header/Footer"}),e.jsx(c.Button,{onClick:a,size:"small",variant:"outlined",sx:e=>({color:`${e.palette.theme.secondary[1e3]} !important`}),startIcon:n?e.jsx(g.EyeOff,{fontSize:"small"}):e.jsx(g.Eye,{fontSize:"small"}),disabled:!(null==s?void 0:s.length),children:"Preview"}),e.jsx(c.Button,{onClick:i,size:"small",variant:r?"contained":"outlined",color:r?"primary":"inherit",sx:e=>({color:r?void 0:`${e.palette.theme.secondary[1e3]} !important`}),startIcon:e.jsx(A,{fontSize:"small"}),disabled:!(null==s?void 0:s.length)||n,children:r?"Exit HTML Edit":"Edit HTML"}),e.jsx(c.Button,{variant:"contained",onClick:t,size:"small",sx:{boxShadow:"none"},disabled:!(null==s?void 0:s.length)||j,children:j?"Saving...":"Save"})]})]})]})})},gt=t.lazy(()=>Promise.resolve().then(()=>require("./custom-editor-CqKvR1Cc.js"))),xt=({isOpen:l,setIsOpen:a,modalProps:n,section:r,placeholders:i,handleSave:s,handleAddPlaceholder:u,handleEditorReady:m})=>{const p=()=>{a(null)};return e.jsxs(c.Modal,{open:l,onClose:p,maxWidth:"lg",maxHeight:"md",fullWidth:!0,...n,children:[e.jsxs(d.DialogTitle,{className:"editSectionModal--DialogTitle",children:[e.jsx(o.Typography,{type:"s3",color:"inherit",weight:"medium",children:"Edit Content"}),e.jsxs(d.Box,{display:"flex",alignItems:"center",gap:1,position:"absolute",right:"1%",top:"4px",children:[e.jsx(c.Select,{displayEmpty:!0,value:"",size:"small",renderValue:()=>"Add placeholder",fullWidth:!0,sx:{bgcolor:"white",borderRadius:1,"& .MuiSelect-select":{py:.75}},onChange:e=>{e.target.value&&(u(e.target.value),e.target.value="")},children:i.map(t=>e.jsx(d.MenuItem,{value:t.value,children:e.jsx(o.Typography,{type:"s4",color:"theme.secondary.1000",children:t.label})},t.value))}),e.jsx(d.IconButton,{onClick:p,children:e.jsx(E,{fontSize:"small"})})]})]}),e.jsx(d.DialogContent,{className:"editSectionModal--DialogContents",children:e.jsx(t.Suspense,{children:e.jsx(gt,{handleEditorReady:m,data:r.content})})}),e.jsx(d.DialogActions,{className:"editSectionModal--DialogAction",children:e.jsxs(d.Box,{display:"flex",gap:1.5,children:[e.jsx(c.Button,{className:"editSectionModal--DialogAction--WhiteBtn",onClick:p,children:"Cancel"}),e.jsx(c.Button,{onClick:e=>(e=>{s(e)})(e),children:"Save"})]})})]})},bt=()=>{const e=t.useMemo(()=>({i:{fontStyle:"italic"},em:{fontStyle:"italic"},b:{fontWeight:"bold"},strong:{fontWeight:"bold"},u:{textDecoration:"underline"},s:{textDecoration:"line-through"},strike:{textDecoration:"line-through"},del:{textDecoration:"line-through"},sup:{verticalAlign:"super",fontSize:"smaller"},sub:{verticalAlign:"sub",fontSize:"smaller"},small:{fontSize:"smaller"},big:{fontSize:"larger"},mark:{backgroundColor:"yellow"},code:{fontFamily:"monospace"},kbd:{fontFamily:"monospace",backgroundColor:"#f1f1f1",padding:"2px 4px",borderRadius:"3px"},samp:{fontFamily:"monospace"},var:{fontStyle:"italic",fontFamily:"monospace"}}),[]),l=t.useMemo(()=>{const e={};return Object.entries({"fontStyle-italic":"i","fontWeight-bold":"b","textDecoration-underline":"u","textDecoration-line-through":"s","verticalAlign-super":"sup","verticalAlign-sub":"sub","fontSize-smaller":"small","fontSize-larger":"big","backgroundColor-yellow":"mark"}).forEach(([t,l])=>{e[t]=l}),e},[]),a=t.useMemo(()=>({"font-family":"fontFamily","font-size":"fontSize","font-weight":"fontWeight","font-style":"fontStyle","text-align":"textAlign","text-decoration":"textDecoration","text-transform":"textTransform","line-height":"lineHeight","letter-spacing":"letterSpacing","word-spacing":"wordSpacing",color:"color","background-color":"backgroundColor","background-image":"backgroundImage","background-size":"backgroundSize","background-position":"backgroundPosition","background-repeat":"backgroundRepeat",border:"border","border-color":"borderColor","border-width":"borderWidth","border-style":"borderStyle","border-radius":"borderRadius",margin:"margin","margin-top":"marginTop","margin-right":"marginRight","margin-bottom":"marginBottom","margin-left":"marginLeft",padding:"padding","padding-top":"paddingTop","padding-right":"paddingRight","padding-bottom":"paddingBottom","padding-left":"paddingLeft",width:"width",height:"height","max-width":"maxWidth","max-height":"maxHeight","min-width":"minWidth","min-height":"minHeight",display:"display",position:"position",top:"top",right:"right",bottom:"bottom",left:"left",float:"float",clear:"clear",overflow:"overflow",opacity:"opacity","z-index":"zIndex","box-shadow":"boxShadow","text-shadow":"textShadow","vertical-align":"verticalAlign"}),[]),o=t.useCallback(e=>a[e]||e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase()),[a]),n=t.useCallback(e=>e.replace(/([A-Z])/g,"-$1").toLowerCase(),[]),r=t.useCallback(e=>{const t={};for(let l=0;l<e.length;l++){const a=e[l],n=e.getPropertyValue(a);n&&(t[o(a)]=n.trim())}return t},[o]),i=t.useCallback(t=>{const l=t.tagName.toLowerCase();return e[l]||{}},[e]),s=t.useCallback(t=>{const l={};let a=t.parentElement;for(;a&&"BODY"!==a.tagName;){const t=a.tagName.toLowerCase();if(e[t]&&Object.entries(e[t]).forEach(([e,t])=>{l[e]||(l[e]=t)}),a.style.length>0){const e=["color","fontFamily","fontSize","lineHeight","textAlign"],t=r(a.style);e.forEach(e=>{t[e]&&!l[e]&&(l[e]=t[e])})}a=a.parentElement}return l},[e,r]),d=t.useCallback((e,t)=>{const l={};e.width&&(l.width=`${e.width}px`),e.height&&(l.height=`${e.height}px`),e.getAttribute("align")&&(l.textAlign=e.getAttribute("align")),Object.assign(t.styles,l),t.src=e.src,t.alt=e.alt},[]),c=t.useCallback((e,t={})=>{const{includeInlineStyles:l=!0,includeTagStyles:a=!0,filterEmptyStyles:o=!0,mergeNestedStyles:n=!0}=t,c=document.createElement("div");c.innerHTML=e;const u=[];return c.querySelectorAll("*").forEach((e,t)=>{var c;const m={elementType:e.tagName.toLowerCase(),elementIndex:t,className:e.className||null,id:e.id||null,styles:{},textContent:(null==(c=e.textContent)?void 0:c.trim())||null};if(l&&e.style.length>0&&(m.styles={...m.styles,...r(e.style)}),a){const t=i(e);m.styles={...m.styles,...t}}if(n){const t=s(e);m.styles={...m.styles,...t},m.inheritedStyles=t}"img"===e.tagName.toLowerCase()&&d(e,m),o&&0===Object.keys(m.styles).length&&!m.textContent||u.push(m)}),u},[r,i,s,d]),u=t.useCallback(t=>{const l=document.createElement("div");l.innerHTML=t;const a={};return["i","em","b","strong","u","s","strike","del","sup","sub"].forEach(t=>{l.querySelectorAll(t).forEach((l,o)=>{a[`${t}_${o}`]={...e[t],textContent:l.textContent}})}),a},[e]),m=t.useCallback((e,t={},a={})=>{const{preferSemanticTags:o=!0,wrapInParagraph:r=!0}=a;if(!e||"string"!=typeof e)return"";let i=e;const s={};if(Object.entries(t).forEach(([e,t])=>{const a=`${e}-${t}`;if(o&&l[a]){const e=l[a];i=`<${e}>${i}</${e}>`}else s[e]=t}),Object.keys(s).length>0){const e=Object.entries(s).map(([e,t])=>`${n(e)}: ${t}`).join("; ");i=`<span style="${e}">${i}</span>`}return r&&(i=`<p>${i}</p>`),i},[l,n]),p=t.useCallback((e,t={})=>{const{wrapInContainer:l=!0,containerTag:a="div",separateElements:o=!1}=t;if(!Array.isArray(e))return"";const n=e.map(e=>{const{text:l,styles:a={},wrapInParagraph:o=!1}=e;return m(l,a,{...t,wrapInParagraph:o})});let r=o?n.join("\n"):n.join(" ");return l&&(r=`<${a}>${r}</${a}>`),r},[m]),h=t.useCallback((e,t={},a="*")=>{const o=document.createElement("div");return o.innerHTML=e,("*"===a?o.querySelectorAll("*"):o.querySelectorAll(a)).forEach(e=>{Object.entries(t).forEach(([t,a])=>{const o=`${t}-${a}`;if(l[o]){const t=l[o],a=document.createElement(t);for(;e.firstChild;)a.appendChild(e.firstChild);e.appendChild(a)}else{const l=n(t);e.style[l]=a}})}),o.innerHTML},[l,n]),g=t.useCallback((e,t={})=>{const l=c(e),a={};return l.forEach(e=>{const l=e.className||e.id||`${e.elementType}_${e.elementIndex}`,o={...e.styles,...t};e.textContent&&(a[l]=m(e.textContent,o,{wrapInParagraph:!1}))}),a},[c,m]),x=t.useCallback(e=>{let t="";return e.forEach((e,l)=>{const a=e.className?`.${e.className}`:e.id?`#${e.id}`:`${e.elementType}-${l}`,o=Object.entries(e.styles).map(([e,t])=>` ${n(e)}: ${t};`).join("\n");o&&(t+=`${a} {\n${o}\n}\n\n`)}),t},[n]),b=t.useCallback(e=>{const t={};return e.forEach((e,l)=>{const a=e.className||e.id||`${e.elementType}_${l}`;Object.entries(e.styles).forEach(([e,l])=>{t[`${a}_${e}`]=l})}),t},[]),f=t.useCallback(e=>{const t={};return e.forEach((e,l)=>{Object.entries(e.styles).forEach(([e,l])=>{t[e]=l})}),t},[]);return{extractStyles:c,extractFormattingStyles:u,generateCSS:x,getFlattenedStyles:b,getSingleStyles:f,stylesToHtml:m,multipleStylesToHtml:p,applyStylesToHtml:h,extractAndConvert:g}},ft=(e,l=300)=>{const a=t.useRef(null);return t.useCallback((...t)=>{a.current&&clearTimeout(a.current),a.current=setTimeout(()=>{e(...t)},l)},[e,l])},yt=t.lazy(()=>Promise.resolve().then(()=>require("./custom-editor-CqKvR1Cc.js"))),vt=["text","text-block","heading","heading-1","heading-2","heading-3","heading-4"],jt=t.memo(({section:l,isSelected:a,isDragging:r,isOver:i,onSelect:u,onUpdate:m,onSplit:p,onDelete:h,placeholders:g,setIsSectionEditing:x})=>{const{extractStyles:b,getSingleStyles:f}=bt(),{attributes:y,listeners:v,setNodeRef:j,transform:S}=F.useDraggable({id:l.id}),{setNodeRef:C}=F.useDroppable({id:l.id}),[w,_]=t.useState(!1),[k,I]=t.useState(!1),[B,A]=t.useState(!1),[M,P]=t.useState(Boolean(null==l?void 0:l.is_edited_from_source)),[z,R]=t.useState(l.content),[N,L]=t.useState(!1),O=t.useRef(null),q=t.useRef(null),W=t.useRef(null),H=t.useRef(!1),V=t.useRef(l.content),G=t.useRef(l.content),U=ft(m,300),K=t.useMemo(()=>S?{transform:`translate3d(${S.x}px, ${S.y}px, 0)`,transition:"none"}:{transition:"all 0.2s ease"},[S]),J=t.useMemo(()=>({position:"relative",border:"1px dashed",borderColor:a||i?"primary.main":"grey.400",borderRadius:1,bgcolor:"white",opacity:r?.7:1,boxShadow:"none",transition:"all 0.2s ease","&:hover":{boxShadow:"none"},...i&&{borderColor:"primary.main",boxShadow:"none"}}),[a,i,r]),Y=t.useCallback(e=>{j(e),C(e)},[j,C]),Z=t.useCallback(()=>{vt.includes(l.type)&&X()},[l.type]),X=t.useCallback(()=>{G.current=l.content,L(!1),(null==l?void 0:l.isSplitPair)?A(!0):(_(!0),x(!0))},[null==l?void 0:l.isSplitPair,l.content,x]),Q=t.useCallback(e=>{O.current=e,(null==e?void 0:e._tiptap)&&(e._tiptap.on("selectionUpdate",()=>{if(!H.current&&e._tiptap){const{from:t,to:l}=e._tiptap.state.selection;W.current={from:t,to:l}}}),e._tiptap.on("update",({transaction:e})=>{e.docChanged&&L(!0)}))},[]),ee=t.useCallback(e=>{var t;if(e.stopPropagation(),O.current){if(O.current._tiptap){const{from:e,to:t}=O.current._tiptap.state.selection;W.current={from:e,to:t}}const e=O.current.getData();V.current=e,R(e);const a=b(l.content,{includeTagStyles:!0,includeInlineStyles:!0,mergeNestedStyles:!0,filterEmptyStyles:!0}),o=f(a),n={...(null==(t=l.attributes)?void 0:t.styles)||{},...o},r={...l.attributes||{},styles:n};U(e,{is_edited_from_source:M,attributes:r})}_(!1),x(!1),A(!1),L(!1)},[U,M,b,f,l.content,l.attributes,x,N]),te=t.useCallback(()=>{const e=l.content||"";p(e,"")},[l.content,p]),le=t.useCallback(e=>{if(O.current){const t=O.current.data.processor.toView(`{{${e}}}`),l=O.current.data.toModel(t);O.current.model.insertContent(l)}},[]),ae=t.useCallback(()=>{null!==q.current&&window.clearTimeout(q.current),q.current=window.setTimeout(()=>{I(!0)},50)},[]),oe=t.useCallback(()=>{null!==q.current&&window.clearTimeout(q.current),q.current=window.setTimeout(()=>{I(!1)},50)},[]),ne=t.useCallback(e=>{e.stopPropagation(),u()},[u]),re=t.useCallback(e=>{e.stopPropagation(),h()},[h]),ie=t.useCallback(()=>{_(!1),x(!1)},[x]),se=t.useCallback(e=>{P(e.target.checked)},[]),de=t.useCallback(e=>{e.target.value&&(le(e.target.value),e.target.value="")},[le]);t.useEffect(()=>()=>{null!==q.current&&window.clearTimeout(q.current)},[]),t.useEffect(()=>{var e;if(V.current!==l.content&&(V.current=l.content,R(l.content),w&&(null==(e=O.current)?void 0:e._tiptap)&&W.current&&!H.current)){const e=O.current._tiptap,{from:t,to:l}=W.current;requestAnimationFrame(()=>{try{H.current=!0;const a=e.state.doc.content.size,o=Math.min(t,a),n=Math.min(l,a);e.commands.setTextSelection({from:o,to:n}),e.isFocused||e.commands.focus()}catch(a){console.warn("Failed to restore cursor position:",a)}finally{H.current=!1}})}},[l.content,w]);const ce=t.useMemo(()=>w?e.jsx(t.Suspense,{fallback:e.jsx(d.Skeleton,{}),children:e.jsx(yt,{editorRef:O,handleEditorReady:Q,data:z,onError:e=>console.error("Editor error:",e)},`editor-${l.id}`)}):e.jsx(d.Box,{dangerouslySetInnerHTML:{__html:z},sx:{position:"relative",py:"divider"===l.type?1:0,lineHeight:1.6,"& p":{margin:0}}}),[w,z,l.type,l.id]),ue=t.useMemo(()=>g.map(t=>e.jsx(d.MenuItem,{value:t.value,children:e.jsx(o.Typography,{type:"s4",color:"theme.secondary.1000",children:t.label})},t.value)),[g]);return e.jsxs(d.Paper,{ref:Y,style:K,elevation:k||a?3:1,sx:J,onClick:ne,onDoubleClick:Z,onMouseEnter:ae,onMouseLeave:oe,children:[i&&!r&&e.jsx(d.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,border:"2px dashed",borderColor:"primary.main",borderRadius:1,bgcolor:"rgba(25, 118, 210, 0.04)",zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"none"},children:e.jsx(o.Typography,{type:"s2",color:"primary",weight:"medium",children:"Drop here"})}),e.jsxs(d.Box,{sx:{bgcolor:"grey.50",p:1,display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid",borderColor:"grey.200"},children:[e.jsxs(d.Box,{...v,...y,sx:{display:"flex",alignItems:"center",cursor:"grab",px:1,py:.5,borderRadius:1,transition:"background-color 0.2s ease","&:hover":{bgcolor:"grey.100"},"&:active":{cursor:"grabbing"}},children:[e.jsx($,{sx:{color:"grey.600",fontSize:"1.2rem",mr:.5}}),e.jsx(o.Typography,{type:"s3",color:"theme.secondary.600",weight:"medium",children:"Move"})]}),e.jsx(d.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:w?e.jsxs(e.Fragment,{children:[e.jsx(d.FormControlLabel,{control:e.jsx(n.Checkbox,{onChange:se,defaultChecked:M}),label:e.jsx(o.Typography,{type:"s2",color:"theme.secondary.1000",children:"Edited from source"})}),e.jsx(d.FormControl,{size:"small",sx:{minWidth:160},children:e.jsx(c.Select,{displayEmpty:!0,value:"",size:"small",renderValue:()=>"Add placeholder...",sx:{bgcolor:"white",borderRadius:1,"& .MuiSelect-select":{py:.75}},onChange:de,children:ue})}),e.jsxs(d.Box,{children:[e.jsx(d.IconButton,{size:"small",onClick:ee,children:e.jsx(T.Save,{fontSize:"small",color:"inherit"})}),e.jsx(d.IconButton,{size:"small",onClick:ie,color:"error",children:e.jsx(E,{fontSize:"small",color:"inherit"})})]})]}):e.jsx(d.Fade,{in:k||a,timeout:200,children:e.jsxs(d.Box,{sx:{display:"flex",gap:.5},children:[(null==l?void 0:l.is_edited_from_source)&&e.jsx(s.Chip,{label:"Edited From Source",size:"small",sx:e=>{var t,l,a,o;return{textTransform:"capitalize",backgroundColor:null==(l=null==(t=e.palette.theme)?void 0:t.tertiary1)?void 0:l[200],color:null==(o=null==(a=e.palette.theme)?void 0:a.tertiary1)?void 0:o[900]}}}),vt.includes(l.type)&&e.jsx(d.IconButton,{size:"small",onClick:X,sx:{bgcolor:"grey.100","&:hover":{bgcolor:"grey.200"}},children:e.jsx(T.Edit,{fontSize:"small",sx:{color:"theme.secondary.1000"}})}),e.jsx(d.IconButton,{size:"small",onClick:te,sx:{bgcolor:"grey.100","&:hover":{bgcolor:"grey.200"},opacity:25===(null==l?void 0:l.splitWidth)?.5:1},disabled:25===(null==l?void 0:l.splitWidth),children:e.jsx(D,{fontSize:"small",color:"primary"})}),e.jsx(d.IconButton,{size:"small",onClick:re,sx:{bgcolor:"grey.100","&:hover":{bgcolor:"grey.200"}},children:e.jsx(T.Trash,{fontSize:"small",sx:{color:"theme.error.500"}})})]})})})]}),e.jsxs(d.Box,{sx:{p:3,bgcolor:"white"},children:[e.jsx("style",{children:"\n\t\t\t\t\t\ta {\n\t\t\t\t\t\t\tcolor: #007bff !important;\n\t\t\t\t\t\t\ttext-decoration: none !important;\n\t\t\t\t\t\t}\n\t\t\t\t\t\ta:hover {\n\t\t\t\t\t\t\ttext-decoration: underline;\n\t\t\t\t\t\t}\n "}),ce]}),B&&e.jsx(xt,{isOpen:B,setIsOpen:A,modalProps:{open:B},placeholders:g,handleSave:ee,handleAddPlaceholder:le,handleEditorReady:Q,section:l})]})},(e,t)=>e.section.id===t.section.id&&(e.section.content===t.section.content&&(e.section.type===t.section.type&&(e.section.is_edited_from_source===t.section.is_edited_from_source&&(e.section.isSplitPair===t.section.isSplitPair&&(e.section.splitWidth===t.section.splitWidth&&(e.isSelected===t.isSelected&&(e.isDragging===t.isDragging&&(e.isOver===t.isOver&&(e.placeholders===t.placeholders&&JSON.stringify(e.section.attributes)===JSON.stringify(t.section.attributes)))))))))));jt.displayName="EditorSection";const St=d.styled(d.ToggleButtonGroup)(({theme:e,item:t})=>({display:"grid",borderRadius:4,border:"1px solid #e3e3e3",width:"100%",gridTemplateColumns:`repeat(${t||4}, 1fr)`,[`& .${d.toggleButtonGroupClasses.grouped}`]:{margin:e.spacing(.5),border:0,borderRadius:e.shape.borderRadius,[`&.${d.toggleButtonGroupClasses.disabled}`]:{border:0}},[`& .${d.toggleButtonGroupClasses.middleButton},& .${d.toggleButtonGroupClasses.lastButton}`]:{marginLeft:-1,borderLeft:"1px solid transparent"},[`& .${d.toggleButtonGroupClasses.selected}`]:{backgroundColor:`${e.palette.theme.primary[800]}!important`,color:"#fff !important"}})),Ct=({alignment:t,onAlignmentChange:l,displayLabel:a=!1})=>e.jsxs(d.Box,{sx:{display:"flex",flexWrap:"wrap",gap:1,mb:2},children:[a&&e.jsx(o.Typography,{type:"s5",weight:"medium",color:"theme.secondary.800",children:"Alignment"}),e.jsxs(St,{value:t,exclusive:!0,onChange:l,"aria-label":"text alignment",size:"small",children:[e.jsx(d.Tooltip,{title:"Align Left",children:e.jsx(d.ToggleButton,{value:"left","aria-label":"left aligned",children:e.jsx(O,{fontSize:"small"})})}),e.jsx(d.Tooltip,{title:"Align Center",children:e.jsx(d.ToggleButton,{value:"center","aria-label":"centered",children:e.jsx(q,{fontSize:"small"})})}),e.jsx(d.Tooltip,{title:"Align Right",children:e.jsx(d.ToggleButton,{value:"right","aria-label":"right aligned",children:e.jsx(W,{fontSize:"small"})})}),e.jsx(d.Tooltip,{title:"Justify",children:e.jsx(d.ToggleButton,{value:"justify","aria-label":"justified",children:e.jsx(H,{fontSize:"small"})})})]})]}),wt=d.styled(d.ToggleButtonGroup)(({theme:e,item:t=4})=>({display:"grid",borderRadius:4,border:"1px solid #e3e3e3",width:"100%",gridTemplateColumns:`repeat(${t}, 1fr)`,[`& .${d.toggleButtonGroupClasses.grouped}`]:{margin:e.spacing(.5),border:0,borderRadius:e.shape.borderRadius,[`&.${d.toggleButtonGroupClasses.disabled}`]:{border:0}},[`& .${d.toggleButtonGroupClasses.middleButton}, & .${d.toggleButtonGroupClasses.lastButton}`]:{marginLeft:-1,borderLeft:"1px solid transparent"},[`& .${d.toggleButtonGroupClasses.selected}`]:{backgroundColor:`${e.palette.theme.primary[800]} !important`,color:"#fff !important"}})),_t=[10,12,14,16,20,24,28,32],kt=[1,1.2,1.5,2],Tt=["Arial","Times New Roman","Roboto","Helvetica","Georgia","Courier New"],It=t.memo(({attrs:l,updateAttrs:a})=>{const o=t.useMemo(()=>l.styles||{},[JSON.stringify(l.styles)]),n=t.useMemo(()=>{const e=[];return"bold"===o.fontWeight&&e.push("bold"),"italic"===o.fontStyle&&e.push("italic"),"underline"===o.textDecoration&&e.push("underline"),e},[o.fontWeight,o.fontStyle,o.textDecoration]),r=t.useCallback(e=>{a({styles:{...o,...e}})},[o,a]),i=t.useCallback(L.debounce(e=>{r({color:e})},300),[r]),s=t.useCallback(e=>{const t=n.includes(e);r({bold:{fontWeight:t?"normal":"bold"},italic:{fontStyle:t?"normal":"italic"},underline:{textDecoration:t?"none":"underline"}}[e])},[n,r]),u=t.useCallback((e,t)=>{null!==t&&r({textAlign:t})},[r]),m=t.useCallback(e=>{i(e.target.value)},[i]),p=t.useCallback(e=>r({fontFamily:e.target.value}),[r]),h=t.useCallback(e=>r({fontSize:Number(e.target.value)}),[r]),g=t.useCallback(e=>r({lineHeight:String(e.target.value)}),[r]);return e.jsxs(e.Fragment,{children:[e.jsx(d.Box,{sx:{mb:2},children:e.jsx(d.FormControl,{size:"small",fullWidth:!0,children:e.jsx(c.Select,{value:o.fontFamily||"",onChange:p,displayEmpty:!0,label:"Select Font",children:Tt.map(t=>e.jsx(d.MenuItem,{value:t,children:t},t))})})}),e.jsxs(d.Box,{sx:{mb:2,display:"flex",gap:1},children:[e.jsx(d.FormControl,{size:"small",fullWidth:!0,children:e.jsx(c.Select,{value:o.fontSize||"",onChange:h,renderValue:e=>`${e}px`,label:"Size",displayEmpty:!0,children:_t.map(t=>e.jsxs(d.MenuItem,{value:t,children:[t,"px"]},t))})}),e.jsx(d.FormControl,{size:"small",fullWidth:!0,children:e.jsx(c.Select,{value:o.lineHeight||"",onChange:g,renderValue:e=>`${e}x`,label:"Line Height",displayEmpty:!0,children:kt.map(t=>e.jsxs(d.MenuItem,{value:t,children:[t,"x"]},t))})})]}),e.jsx(Ct,{alignment:o.textAlign,onAlignmentChange:u}),e.jsx(d.Box,{sx:{display:"flex",flexWrap:"wrap",gap:1,mb:2},children:e.jsxs(wt,{item:3,children:[e.jsx(d.Tooltip,{title:"Bold",children:e.jsx(d.ToggleButton,{value:"bold",selected:n.includes("bold"),onClick:()=>s("bold"),"aria-label":"bold",size:"small",sx:{borderRadius:1},children:e.jsx(P,{fontSize:"small"})})}),e.jsx(d.Tooltip,{title:"Italic",children:e.jsx(d.ToggleButton,{value:"italic",selected:n.includes("italic"),onClick:()=>s("italic"),"aria-label":"italic",size:"small",sx:{borderRadius:1},children:e.jsx(z,{fontSize:"small"})})}),e.jsx(d.Tooltip,{title:"Underline",children:e.jsx(d.ToggleButton,{value:"underline",selected:n.includes("underline"),onClick:()=>s("underline"),"aria-label":"underline",size:"small",sx:{borderRadius:1},children:e.jsx(R,{fontSize:"small"})})})]})}),e.jsx(d.Box,{sx:{mb:2,width:"100%"},children:e.jsx(d.TextField,{label:"Text Color",variant:"outlined",type:"color",value:o.color||"#000000",onChange:m,size:"small",fullWidth:!0,InputProps:{startAdornment:e.jsx(d.InputAdornment,{position:"start",children:e.jsx(N,{fontSize:"small"})})}})})]})}),Et=[{label:"None",value:"none"},{value:"1px solid #e0e0e0",label:"Solid"},{value:"1px dashed #e0e0e0",label:"Dashed"},{value:"1px dotted #e0e0e0",label:"Dotted"}],Bt=({attrs:t,updateAttrs:l})=>{const{text:a,styles:r}=t;return e.jsxs(e.Fragment,{children:[e.jsx(c.TextField,{label:"Button Text",fullWidth:!0,value:a,onChange:e=>l({text:e.target.value}),size:"small",sx:{mb:2}}),e.jsx(d.Box,{sx:{mb:2},children:e.jsx(n.ColorPickerInput,{value:(null==r?void 0:r.backgroundColor)||"#333333",onChange:e=>l({styles:{backgroundColor:e}}),label:"Background Color"})}),e.jsx(d.Box,{sx:{mb:2},children:e.jsx(n.ColorPickerInput,{value:(null==r?void 0:r.color)||"#333333",onChange:e=>l({styles:{color:e}}),label:"Text Color"})}),e.jsx(d.FormControl,{fullWidth:!0,size:"small",sx:{mb:2},children:e.jsxs(c.Select,{value:null==r?void 0:r.border,renderValue:e=>{var t;return(null==(t=Et.find(t=>t.value===e))?void 0:t.label)||"None"},onChange:e=>l({styles:{border:e.target.value}}),label:"Border",children:[e.jsx(d.MenuItem,{value:"none",children:"None"}),e.jsx(d.MenuItem,{value:"1px solid #e0e0e0",children:"Solid"}),e.jsx(d.MenuItem,{value:"1px dashed #e0e0e0",children:"Dashed"})]})}),e.jsxs(d.Box,{sx:{mb:2},children:[e.jsx(o.Typography,{type:"s3",color:"theme.neutral.800",children:"Border Radius"}),e.jsx(d.Slider,{value:null==r?void 0:r.borderRadius,onChange:(e,t)=>l({styles:{borderRadius:t}}),min:0,max:20,step:1,valueLabelDisplay:"auto",size:"small",marks:!0,sx:e=>({"& .MuiSlider-rail":{color:e.palette.theme.primary[500]},"& .MuiSlider-thumb":{color:e.palette.theme.primary[800]},"& .MuiSlider-track":{color:e.palette.theme.primary[600]}})})]}),e.jsxs(d.Box,{sx:{mb:2},children:[e.jsx(o.Typography,{type:"s3",color:"theme.neutral.800",children:"Font Size"}),e.jsx(d.Slider,{value:null==r?void 0:r.fontSize,onChange:(e,t)=>l({styles:{fontSize:t}}),min:10,max:20,step:1,valueLabelDisplay:"auto",size:"small",marks:!0,sx:e=>({"& .MuiSlider-rail":{color:e.palette.theme.primary[500]},"& .MuiSlider-thumb":{color:e.palette.theme.primary[800]},"& .MuiSlider-track":{color:e.palette.theme.primary[600]}})})]}),e.jsx(Ct,{alignment:"0 auto"===(null==r?void 0:r.margin)?"center":"0 0 0 auto"===(null==r?void 0:r.margin)?"right":"auto 0 0 0"===(null==r?void 0:r.margin)?"left":"justify",onAlignmentChange:(e,t)=>{if(t){let e="0";switch(t){case"justify":case"center":default:e="0 auto";break;case"right":e="0 0 0 auto";break;case"left":e="auto 0 0 0"}l({styles:{margin:e}})}}})]})},At=d.styled(d.Switch)(({theme:e})=>({padding:8,"& .MuiSwitch-track":{borderRadius:11,"&::before, &::after":{content:'""',position:"absolute",top:"50%",transform:"translateY(-50%)",width:16,height:16},"&::before":{backgroundImage:`url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" viewBox="0 0 24 24"><path fill="${encodeURIComponent(e.palette.getContrastText(e.palette.primary.main))}" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"/></svg>')`,left:12},"&::after":{backgroundImage:`url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" viewBox="0 0 24 24"><path fill="${encodeURIComponent(e.palette.getContrastText(e.palette.primary.main))}" d="M19,13H5V11H19V13Z" /></svg>')`,right:12}},"& .MuiSwitch-thumb":{boxShadow:"none",width:16,height:16,margin:2},"& .Mui-checked":{color:`${e.palette.theme.primary[800]} !important`},"& .Mui-checked+.MuiSwitch-track":{backgroundColor:`${e.palette.theme.primary[800]} !important`}})),Mt=["none","solid","dashed","dotted","double","groove","ridge","inset","outset"],Ft=({styles:l,onChange:a,isBordered:r,disableWidth:i=!1,disableStyle:s=!1,disableColor:u=!1,disableCollapse:m=!1,disableRadius:p=!1,initiateStyles:h})=>(t.useEffect(()=>{h instanceof Function&&h(r?{border:1,borderStyle:"solid",borderColor:"#000000",borderCollapse:"collapse",borderRadius:0}:{border:0,borderStyle:"none",borderColor:"#000000",borderCollapse:"separate",borderRadius:0})},[r]),e.jsxs(d.Grid,{container:!0,spacing:2,children:[e.jsx(d.Grid,{item:!0,xs:12,children:e.jsx(d.FormControlLabel,{control:e.jsx(At,{checked:r,onChange:e=>a("is_bordered",e.target.checked)}),label:e.jsx(o.Typography,{type:"s5",weight:"medium",color:"theme.secondary.800",children:"Bordered Table"}),labelPlacement:"start",sx:{display:"flex",alignItems:"center",justifyContent:"space-between",margin:"auto"}})}),r&&e.jsxs(e.Fragment,{children:[!i&&e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(c.Select,{value:l.border||1,onChange:e=>a("border",e.target.value),label:"Border Width",fullWidth:!0,size:"small",children:[1,2,3,4,5,6,7,8,9,10].map(t=>e.jsx(d.MenuItem,{value:t,children:e.jsx(o.Typography,{type:"s5",color:"theme.secondary.1000",children:t})},t))})}),!s&&e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(d.FormControl,{fullWidth:!0,size:"small",children:e.jsx(c.Select,{value:l.borderStyle||"solid",onChange:e=>a("borderStyle",e.target.value),renderValue:e=>w.formatText(e),label:"Border Style",children:Mt.map(t=>e.jsx(d.MenuItem,{value:t,children:e.jsx(o.Typography,{type:"s5",color:"theme.secondary.1000",children:w.formatText(t)})},t))})})}),!u&&e.jsxs(d.Grid,{item:!0,xs:6,children:[e.jsx(o.Typography,{type:"s5",weight:"medium",color:"theme.secondary.800",mb:.5,children:"Border Color"}),e.jsx(n.ColorPickerInput,{value:l.borderColor||"#e0e0e0",onChange:e=>a("borderColor",e),fullWidth:!0})]}),!m&&e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(d.FormControl,{fullWidth:!0,size:"small",children:e.jsxs(c.Select,{value:l.borderCollapse||"collapse",onChange:e=>a("borderCollapse",e.target.value),label:"Border Collapse",renderValue:e=>w.formatText(e),children:[e.jsx(d.MenuItem,{value:"collapse",children:e.jsx(o.Typography,{type:"s5",color:"theme.secondary.1000",children:"Collapse"})}),e.jsx(d.MenuItem,{value:"separate",children:e.jsx(o.Typography,{type:"s5",color:"theme.secondary.1000",children:"Separate"})})]})})}),!p&&e.jsxs(d.Grid,{item:!0,xs:12,children:[e.jsx(o.Typography,{type:"s5",weight:"medium",color:"theme.secondary.800",variant:"caption",children:"Border Radius"}),e.jsx(d.Slider,{value:"number"==typeof l.borderRadius?l.borderRadius:1,min:0,max:20,step:1,marks:!0,onChange:(e,t)=>a("borderRadius",t),valueLabelDisplay:"auto",sx:e=>({"& .MuiSlider-rail":{color:e.palette.theme.primary[500]},"& .MuiSlider-thumb":{color:e.palette.theme.primary[800]},"& .MuiSlider-track":{color:e.palette.theme.primary[600]}})})]})]})]})),$t=d.styled(d.Switch)(({theme:e})=>({padding:8,"& .MuiSwitch-track":{borderRadius:11,"&::before, &::after":{content:'""',position:"absolute",top:"50%",transform:"translateY(-50%)",width:16,height:16},"&::before":{backgroundImage:`url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" viewBox="0 0 24 24"><path fill="${encodeURIComponent(e.palette.getContrastText(e.palette.primary.main))}" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"/></svg>')`,left:12},"&::after":{backgroundImage:`url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" viewBox="0 0 24 24"><path fill="${encodeURIComponent(e.palette.getContrastText(e.palette.primary.main))}" d="M19,13H5V11H19V13Z" /></svg>')`,right:12}},"& .MuiSwitch-thumb":{boxShadow:"none",width:16,height:16,margin:2},"& .Mui-checked":{color:e.palette.theme.primary[800]},"& .Mui-checked+.MuiSwitch-track":{backgroundColor:`${e.palette.theme.primary[700]}`}})),Dt=({attrs:t,updateAttrs:l})=>{const{src:a,alt:n,styles:r}=t||{};return e.jsxs(e.Fragment,{children:[e.jsx(c.TextField,{label:"Image URL",fullWidth:!0,value:a,onChange:e=>l({src:e.target.value}),size:"small",sx:{mb:2}}),e.jsx(c.TextField,{label:"Alt Text",fullWidth:!0,value:n,onChange:e=>l({alt:e.target.value}),size:"small",sx:{mb:2}}),e.jsx(d.FormControlLabel,{control:e.jsx($t,{defaultChecked:!0,checked:Boolean(null==r?void 0:r.fullWidth)}),label:e.jsx(o.Typography,{type:"s5",color:"theme.secondary.800",weight:"medium",children:"Full Width"}),labelPlacement:"start",value:Boolean(null==r?void 0:r.fullWidth),onClick:e=>{const t=e.target.checked;l({styles:{fullWidth:t,width:t?100:150,height:t?"auto":150}})},sx:{display:"flex",alignItems:"center",justifyContent:"space-between",margin:"auto",mb:2}}),e.jsxs(d.Grid,{container:!0,spacing:2,children:[e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(c.TextField,{label:"Width (px)",type:"number",fullWidth:!0,value:(null==r?void 0:r.fullWidth)?"":null==r?void 0:r.width,onChange:e=>l({styles:{width:Number(e.target.value)}}),size:"small",sx:{mb:2},inputProps:{min:1},disabled:null==r?void 0:r.fullWidth})}),e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(c.TextField,{label:"Height (px)",type:"number",fullWidth:!0,value:(null==r?void 0:r.fullWidth)?"":null==r?void 0:r.height,onChange:e=>l({styles:{height:Number(e.target.value)}}),size:"small",sx:{mb:2},inputProps:{min:1},disabled:null==r?void 0:r.fullWidth})})]}),e.jsx(d.Box,{sx:{mb:2},children:e.jsx(d.FormControl,{size:"small",fullWidth:!0,children:e.jsxs(c.Select,{label:"Object Fit",value:null==r?void 0:r.objectFit,onChange:e=>l({styles:{objectFit:e.target.value}}),displayEmpty:!0,children:[e.jsx(d.MenuItem,{value:"contain",children:"Contain"}),e.jsx(d.MenuItem,{value:"cover",children:"Cover"}),e.jsx(d.MenuItem,{value:"fill",children:"Fill"}),e.jsx(d.MenuItem,{value:"none",children:"None"}),e.jsx(d.MenuItem,{value:"scale-down",children:"Scale Down"})]})})}),e.jsx(Ct,{alignment:"0 auto"===(null==r?void 0:r.margin)||"center"===(null==r?void 0:r.alignment)?"center":"0 0 0 auto"===(null==r?void 0:r.margin)||"right"===(null==r?void 0:r.alignment)?"right":"auto 0 0 0"===(null==r?void 0:r.margin)||"left"===(null==r?void 0:r.alignment)?"left":"justify",onAlignmentChange:(e,t)=>{if(t){let e="0";switch(t){case"justify":case"center":default:e="0 auto";break;case"right":e="0 0 0 auto";break;case"left":e="auto 0 0 0"}l({styles:{margin:e,alignment:t}})}},displayLabel:!0}),e.jsx(Ft,{styles:r,onChange:(e,t)=>l({styles:{[e]:t}}),isBordered:null==r?void 0:r.is_bordered,disableCollapse:!0,initiateStyles:e=>l({styles:e})})]})},Pt=({attrs:t,updateAttrs:l})=>{const{styles:a}=t;return e.jsxs(e.Fragment,{children:[e.jsx(d.FormControl,{fullWidth:!0,size:"small",sx:{mb:2},children:e.jsxs(c.Select,{label:"Style",value:null==a?void 0:a.borderStyle,onChange:e=>l({styles:{borderStyle:e.target.value}}),renderValue:e=>w.formatText(e),children:[e.jsx(d.MenuItem,{value:"solid",children:"Solid"}),e.jsx(d.MenuItem,{value:"dashed",children:"Dashed"}),e.jsx(d.MenuItem,{value:"dotted",children:"Dotted"})]})}),e.jsxs(d.Box,{sx:{mb:1},children:[e.jsx(o.Typography,{type:"s5",color:"theme.secondary.800",weight:"medium",children:"Thickness (px)"}),e.jsx(d.Slider,{value:null==a?void 0:a.borderWidth,onChange:(e,t)=>l({styles:{borderWidth:t}}),min:1,max:10,step:1,valueLabelDisplay:"auto",size:"small",sx:e=>({"& .MuiSlider-rail":{color:e.palette.theme.primary[500]},"& .MuiSlider-thumb":{color:e.palette.theme.primary[800]},"& .MuiSlider-track":{color:e.palette.theme.primary[600]}})})]}),e.jsx(d.Box,{sx:{mb:2},children:e.jsx(c.TextField,{label:"Divider Color",type:"color",value:null==a?void 0:a.borderColor,onChange:e=>l({styles:{borderColor:e.target.value}}),size:"small",fullWidth:!0,InputProps:{startAdornment:e.jsx(d.InputAdornment,{position:"start",children:e.jsx(N,{fontSize:"small"})})}})})]})},zt=d.styled(t=>e.jsx(d.Accordion,{disableGutters:!0,elevation:0,square:!0,...t}))(({theme:e})=>({border:`1px solid ${e.palette.divider}`,borderRadius:0,"&:not(:last-child)":{borderBottom:0},"&::before":{display:"none"}})),Rt=["left","center","right","justify"],Nt=["normal","bold","100","200","300","400","500","600","700","800","900"],Lt=["Arial, sans-serif","Helvetica, sans-serif","Times New Roman, serif","Georgia, serif","Courier New, monospace","Verdana, sans-serif","Tahoma, sans-serif","Trebuchet MS, sans-serif"],Ot=({tableData:l,setTableData:a,attrs:r,updateAttrs:i,placeholders:s,handleSave:u,setParentRowLevel:m,levelType:p,relation_table:h})=>{var g,x,b,f,y,v,j,S,C,_,k,I,E,B,A,M,F,$,P,z;const[R,N]=t.useState(0),[L,O]=t.useState("tableBasic"),[q,W]=t.useState(!0),[H,J]=t.useState(!1),[Y,Z]=t.useState([]),[X,Q]=t.useState(""),[ee,te]=t.useState(!1),{placeholders:le}=r,[ae,oe]=t.useState(null),[ne,re]=t.useState({}),[ie,se]=t.useState({}),de=l.mergedCells||[],[ce,ue]=t.useState(!1),me=t.useMemo(()=>ae?(e=>{if(!h||!Array.isArray(h))return[];const t=h.find(t=>(null==t?void 0:t.dataKey)==e);return t&&t.fields&&Array.isArray(t.fields)?t.fields:[]})(ae):s,[s,ae,h]),[pe,he]=t.useState((null==r?void 0:r.styles)||{is_bordered:!0,border:1,borderStyle:"solid",borderColor:"#e0e0e0",borderCollapse:"collapse",width:"100%",thCells:{padding:8},tbCells:{padding:8},tHead:{backgroundColor:"#f5f5f5",color:"#333333",fontSize:14,fontWeight:"bold",fontFamily:"Arial, sans-serif",textAlign:"left",margin:"0.5em 0"},tBody:{backgroundColor:"#ffffff",color:"#333333",fontSize:14,fontWeight:"normal",fontFamily:"Arial, sans-serif",textAlign:"left"}});t.useEffect(()=>{i({styles:pe})},[JSON.stringify(pe)]),t.useEffect(()=>{q&&(le||ee)&&xe()},[le,q,ee,ie]);const ge=e=>{const t=me.find(t=>t.value===e);if(!t)return"";if(ee)return`{{${t.value}}}`;if(void 0!==t.actualValue)return String(t.actualValue);switch(t.type){case"date":return(new Date).toLocaleDateString();case"datetime":return(new Date).toLocaleString();case"number":return"123";case"currency":return"$1,234.56";case"email":return"example@domain.com";case"phone":return"+1 (555) 123-4567";case"url":return"https://example.com";default:return`{{${t.value}}}`||t.label}},xe=()=>{(le||ee)&&(a(e=>({...e,name:ae||"",rows:e.rows.map((t,l)=>{const a={...t};return e.columns.forEach(e=>{var t,o;let n;if(ee&&(null==(t=ie[l])?void 0:t[e.id])?n=ie[l][e.id]:(null==le?void 0:le[e.id])&&(n=le[e.id]),n){a[e.id]=ge(n);const t=(null==(o=ne[l])?void 0:o[e.id])||"";t&&(a[`${e.id}_static`]=`${t} ${a[e.id]}`)}}),a})})),ue(!1))},be=(e,t,l)=>{const a=null==de?void 0:de.find(a=>a.section===e&&t>=a.rowStart&&t<=a.rowEnd&&l>=a.colStart&&l<=a.colEnd);return a?{merge:a,isTopLeft:t===a.rowStart&&l===a.colStart,isCovered:!(t===a.rowStart&&l===a.colStart)}:null},fe=(e,t,l)=>Y.some(a=>a.section===e&&a.row===t&&a.col===l),ye=(e,t,l)=>{const a={section:e,row:t,col:l};if(fe(e,t,l))Z(a=>a.filter(a=>!(a.section===e&&a.row===t&&a.col===l)));else{if(Y.some(t=>t.section!==e))return void alert("Cannot select cells from both header and body for the same merge");Z(e=>[...e,a])}},ve=e=>{const t=s.find(t=>t.value===e);return t?{label:t.label,type:t.type||"text",description:t.description||""}:null},je=e=>(t,l)=>{O(l?e:"")},Se=(e,t)=>{he(l=>({...l,tHead:{...l.tHead,[e]:t}}))},Ce=(e,t)=>{he(l=>({...l,tBody:{...l.tBody,[e]:t}}))},we=()=>{a(e=>({...e,name:ae||"",rows:e.rows.map(t=>({...Object.fromEntries(e.columns.map(e=>[null==e?void 0:e.id,""]))}))}))},_e=le?Object.keys(le).length:0;return t.useEffect(()=>{te(p),oe((null==l?void 0:l.name)||null),re(e=>{const t={};return l.rows.forEach((e,l)=>{Object.keys(e).forEach(a=>{if(a.endsWith("_static")){const o=a.replace("_static","");t[l]||(t[l]={});const n=e[o]||"";let r=e[a]||"";n&&r.includes(n)&&(r=r.replace(n,"").trim()),r=r.replace(/\{\{\s*value\s*\}\}/g,"").trim(),t[l][o]=r}})}),t})},[l]),t.useEffect(()=>{ae||we()},[ae]),e.jsxs(e.Fragment,{children:[e.jsx(d.Box,{sx:{mb:2,borderBottom:1,paddingBottom:5,borderColor:"divider"},children:e.jsxs(d.Tabs,{value:R,onChange:(e,t)=>{N(t)},variant:"fullWidth",sx:e=>{var t,l;return{"& .MuiTabs-indicator":{backgroundColor:null==(t=e.palette.theme)?void 0:t.primary[700]},"& .MuiTab-root.Mui-selected":{color:null==(l=e.palette.theme)?void 0:l.primary[700]},"& .MuiTab-root":{textTransform:"none"}}},children:[e.jsx(d.Tab,{label:"Content"}),e.jsx(d.Tab,{label:"Styles"}),e.jsx(d.Tab,{label:"Cell Merging"})]})}),0===R&&e.jsxs(e.Fragment,{children:[e.jsxs(d.Box,{sx:{mb:2,p:2,bgcolor:"grey.50",borderRadius:1,border:"1px solid",borderColor:"divider"},children:[e.jsxs(d.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1},children:[e.jsx(o.Typography,{type:"s4",weight:"medium",color:"theme.primary.700",children:"Dynamic Data Settings"}),e.jsx(d.Chip,{label:`${_e} columns linked`,size:"small",color:"primary",variant:"outlined",sx:e=>{var t,l;return{color:null==(t=e.palette.theme)?void 0:t.primary[700],borderColor:null==(l=e.palette.theme)?void 0:l.primary[700]}}})]}),e.jsx(d.FormControlLabel,{control:e.jsx(n.Android12Switch,{checked:q,onChange:e=>W(e.target.checked)}),label:e.jsx(o.Typography,{type:"s5",color:"theme.secondary.800",children:"Auto-populate rows with placeholder data"})}),e.jsx(d.FormControlLabel,{control:e.jsx(n.Android12Switch,{checked:ee,onChange:e=>{te(e.target.checked),oe(null),m(e.target.checked),we()}}),label:e.jsx(o.Typography,{type:"s5",color:"theme.secondary.800",children:"Row Level Management"})}),q&&e.jsx(d.Box,{sx:{mt:1},children:e.jsx(c.Button,{variant:"outlined",size:"small",onClick:()=>{xe()},startIcon:e.jsx(U,{}),className:"black-outlined-btn",children:"Refresh Data"})})]}),e.jsxs(d.Box,{sx:{mb:2},children:[e.jsx(o.Typography,{type:"s3",weight:"medium",color:"theme.secondary.1000",sx:{mb:1},children:"Columns"}),null==(g=l.columns)?void 0:g.map((t,o)=>e.jsxs(d.Box,{sx:{mb:1,display:"flex",alignItems:"center",gap:1},children:[e.jsx(c.TextField,{label:`Column ${o+1} Header`,value:t.header,onChange:e=>{return l=t.id,o=e.target.value,void a(e=>({...e,columns:e.columns.map(e=>e.id===l?{...e,header:o}:e)}));var l,o},size:"small",sx:{flex:1}}),e.jsx(d.IconButton,{size:"small",onClick:()=>(e=>{const t=l.columns.findIndex(t=>t.id===e);if(a(l=>{var a;return{...l,name:ae||"",columns:l.columns.filter(t=>t.id!==e),rows:l.rows.map(t=>{const{[e]:l,...a}=t;return a}),mergedCells:(null==(a=l.mergedCells)?void 0:a.filter(e=>!(e.colStart<=t&&e.colEnd>=t)).map(e=>({...e,colStart:e.colStart>t?e.colStart-1:e.colStart,colEnd:e.colEnd>t?e.colEnd-1:e.colEnd})))||[]}}),le&&le[e]){const t={...le};delete t[e],i({placeholders:t})}})(t.id),disabled:l.columns.length<=1,color:"error",children:e.jsx(T.Trash,{})})]},t.id)),e.jsx(c.Button,{variant:"outlined",size:"small",onClick:()=>{const e=(()=>{const e=l.columns.map(e=>e.id);let t=1;for(;e.includes(`col${t}`);)t++;return`col${t}`})(),t={id:e,header:`Column ${l.columns.length+1}`};a(l=>{var a;return{...l,name:ae||"",columns:[...l.columns,t],rows:l.rows.map(t=>({...t,[e]:""})),mergedCells:(null==(a=l.mergedCells)?void 0:a.map(e=>({...e})))||[]}})},startIcon:e.jsx(G,{}),sx:{mt:1},className:"black-outlined-btn",children:"Add Column"})]}),e.jsx(d.Divider,{sx:{my:2}}),e.jsxs(d.Box,{sx:{mb:2},children:[e.jsxs(d.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1},children:[e.jsxs(o.Typography,{type:"s3",weight:"medium",color:"theme.secondary.1000",children:["Rows (",l.rows.length,")"]}),e.jsx(c.Button,{variant:"outlined",size:"small",disabled:ae,onClick:()=>(()=>{const e={};l.columns.forEach(t=>{if(null==le?void 0:le[t.id]){const l=le[t.id];e[t.id]=`{{${l}}}`,ee&&(e[`${t.id}_static`]=e[t.id])}else l.rows.length>0?(e[t.id]=l.rows[0][t.id]||"",ee&&(e[`${t.id}_static`]=l.rows[0][`${t.id}_static`]||"")):(ee&&(e[`${t.id}_static`]=""),e[t.id]="")}),a(t=>{var l;const a=[...t.rows,e];return{...t,rows:a,name:ae||"",mergedCells:(null==(l=t.mergedCells)?void 0:l.map(e=>({...e})))||[]}}),u()})(),startIcon:e.jsx(G,{}),className:"black-outlined-btn",children:"Add Row"})]}),!ee&&e.jsx(d.Box,{sx:{mb:2},children:e.jsx(n.SearchableSelect,{value:ae||"",label:"Select Table",options:(null==h?void 0:h.map(e=>({value:null==e?void 0:e.dataKey,label:(e.name.charAt(0).toUpperCase()+e.name.slice(1)).replaceAll("_"," ")})))||[],onChange:e=>{oe(e.target.value)}})}),l.rows.map((t,r)=>e.jsxs(d.Box,{sx:{mb:2,p:2,border:1,borderColor:"divider",borderRadius:1},children:[e.jsxs(d.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1},children:[e.jsxs(o.Typography,{type:"s4",weight:"medium",color:"theme.secondary.800",children:["Row ",r+1]}),e.jsx(d.IconButton,{size:"small",onClick:()=>(e=>{a(t=>{var l;return{...t,name:ae||"",rows:t.rows.filter((t,l)=>l!==e),mergedCells:(null==(l=t.mergedCells)?void 0:l.filter(t=>!("tbody"===t.section&&t.rowStart<=e&&t.rowEnd>=e)).map(t=>({...t,rowStart:"tbody"===t.section&&t.rowStart>e?t.rowStart-1:t.rowStart,rowEnd:"tbody"===t.section&&t.rowEnd>e?t.rowEnd-1:t.rowEnd})))||[]}}),se(t=>{const l={...t};return delete l[e],l}),re(t=>{const l={...t};return delete l[e],l})})(r),disabled:l.rows.length<=1,color:"error",children:e.jsx(T.Trash,{})})]}),e.jsx(d.Grid,{container:!0,spacing:1,children:l.columns.map((i,u)=>{var m,p,h,g;const x=ee?null==(m=ie[r])?void 0:m[i.id]:null==le?void 0:le[i.id],b=x?ve((null==le?void 0:le[i.id])||(null==(p=ie[r])?void 0:p[i.id])):null,f=be("tbody",r,u);return e.jsx(d.Grid,{item:!0,xs:12,children:ee?e.jsxs(e.Fragment,{children:[e.jsxs(o.Typography,{type:"s4",weight:"medium",color:"theme.secondary.800",children:[" ",i.header," "]}),e.jsxs(d.Box,{sx:{display:"flex",flexDirection:"row",gap:1,alignItems:"center",justifyContent:"space-between"},children:[e.jsx(c.TextField,{value:(null==(h=ne[r])?void 0:h[i.id])||"",onChange:e=>{const t=e.target.value;re(e=>{const l={...e};return l[r]||(l[r]={}),l[r][i.id]=t,l}),a(e=>({...e,rows:e.rows.map((e,l)=>l===r?{...e,[`${i.id}_static`]:t?`${t} ${e[i.id]||""}`.trim():""}:e)}))},size:"small",placeholder:"Enter custom text...",sx:{flex:1,minWidth:150}}),e.jsx(d.Box,{sx:{flex:1,minWidth:150},children:e.jsx(n.SearchableSelect,{value:f?f.merge.value:(null==(g=ie[r])?void 0:g[i.id])||t[i.id]||"",onChange:e=>((e,t,o)=>{var n;ue(!0);const r=l.columns.findIndex(e=>e.id===t),i=be("tbody",e,r),s=ee&&(null==(n=ne[e])?void 0:n[t])||"";i?a(e=>{var t;return{...e,name:ae||"",mergedCells:(null==(t=e.mergedCells)?void 0:t.map(e=>e===i.merge?{...e,value:o}:e))||[]}}):(ee&&o?se(l=>{const a={...l};return a[e]||(a[e]={}),a[e][t]=o,a}):ee&&!o&&se(l=>{var a;const o={...l};return(null==(a=o[e])?void 0:a[t])&&(delete o[e][t],0===Object.keys(o[e]).length&&delete o[e]),o}),a(l=>({...l,name:ae||"",rows:l.rows.map((l,a)=>a===e?{...l,[t]:ee?o?`{{${o}}}`:"":o?ge(o):"",[`${t}_static`]:s?`${s} ${o?ge(o):""}`.trim():o?ge(o):""}:l)})),xe())})(r,i.id,e.target.value),size:"small",options:s||[],sx:{flex:1,maxWidth:150,minWidth:150,"& .MuiInputBase-input":{bgcolor:x&&q?"grey.100":f?"blue.50":"transparent",width:150}}})})]})]}):e.jsx(c.TextField,{label:i.header,value:f?f.merge.value:t[i.id]||"",onChange:e=>((e,t,o)=>{var n;ue(!0);const r=l.columns.findIndex(e=>e.id===t),i=be("tbody",e,r),s=(null==(n=ne[e])?void 0:n[t])||"";i?a(e=>{var t;return{...e,name:ae||"",mergedCells:(null==(t=e.mergedCells)?void 0:t.map(e=>e===i.merge?{...e,value:o}:e))||[]}}):(ee&&se(l=>{const a={...l};return a[e]||(a[e]={}),o?a[e][t]=o:(delete a[e][t],0===Object.keys(a[e]).length&&delete a[e]),a}),a(l=>({...l,name:ae||"",rows:l.rows.map((l,a)=>a===e?{...l,[t]:ee?o?`{{${o}}}`:"":o,[`${t}_static`]:s?`${s} ${o||""}`.trim():o||""}:l)})),(ee||q&&(null==le?void 0:le[t]))&&xe(),ue(!1))})(r,i.id,e.target.value),size:"small",fullWidth:!0,disabled:q||x,helperText:f?`Merged cell (${f.merge.rowEnd-f.merge.rowStart+1}×${f.merge.colEnd-f.merge.colStart+1})`:x&&b?`Linked to: ${b.label}`:void 0,sx:{"& .MuiInputBase-input":{bgcolor:x&&q?"grey.100":f?"blue.50":"transparent"}}})},i.id)})})]},r))]}),e.jsx(d.Divider,{sx:{my:2}}),e.jsx(o.Typography,{type:"s3",weight:"medium",color:"theme.secondary.1000",sx:{mb:1},children:"Column Data Sources"}),0===s.length&&e.jsx(d.Alert,{severity:"info",sx:{mb:2},children:"No placeholders available. Add placeholders to dynamically populate table data."}),e.jsx(d.Grid,{container:!0,spacing:1,alignItems:"center",children:l.columns.map(r=>{var s,c;const u=(null==le?void 0:le[r.id])||(null==(c=null==(s=l.rows)?void 0:s[0])?void 0:c[r.id]),m=u?ve(u):null;return e.jsxs(t.Fragment,{children:[e.jsxs(d.Grid,{item:!0,xs:4,children:[e.jsx(o.Typography,{type:"s5",weight:"medium",color:"theme.secondary.800",children:r.header}),m&&e.jsx(o.Typography,{type:"s6",color:"theme.secondary.600",sx:{fontStyle:"italic"},children:m.type})]}),e.jsx(d.Grid,{item:!0,xs:8,children:e.jsx(n.SearchableSelect,{value:ee?"":u||"",onChange:e=>{((e,t)=>{ue(!0);const l={...le,[e]:t};if(t||delete l[e],i({placeholders:l}),q){const l=t?ge(t):"";a(t=>({...t,name:ae||"",rows:t.rows.map(t=>({...t,[e]:l}))}))}ue(!1)})(r.id,e.target.value)},size:"small",options:me.map(e=>({value:e.value,label:e.label,description:e.description})),disabled:ce||ee,sx:{flex:1,maxWidth:150,minWidth:150,"& .MuiInputBase-input":{bgcolor:"transparent",width:150}},renderOption:(l,a)=>t.createElement(d.MenuItem,{...l,key:a.value},e.jsxs(d.Box,{children:[e.jsx(o.Typography,{type:"s5",color:"theme.secondary.1000",children:a.label}),a.description&&e.jsx(o.Typography,{type:"s6",color:"theme.secondary.600",sx:{fontStyle:"italic"},children:a.description})]})),noOptionsText:e.jsx(d.MenuItem,{disabled:!0,children:e.jsx(o.Typography,{type:"s5",color:"theme.secondary.600",children:"No Data Source"})})})})]},r.id)})})]}),1===R&&e.jsxs(d.Box,{sx:{"& >:first-child":{borderTopLeftRadius:8,borderTopRightRadius:8},"& >:last-child":{borderBottomLeftRadius:8,borderBottomRightRadius:8}},children:[e.jsxs(zt,{expanded:"tableBasic"===L,onChange:je("tableBasic"),disableGutters:!0,children:[e.jsx(d.AccordionSummary,{expandIcon:e.jsx(V,{}),children:e.jsx(o.Typography,{type:"s3",color:"theme.secondary.1000",children:"Table Basic Properties"})}),e.jsx(d.AccordionDetails,{children:e.jsx(Ft,{styles:pe,onChange:(e,t)=>((e,t)=>{he(l=>({...l,[e]:t}))})(e,t),isBordered:pe.is_bordered,disableRadius:!0})})]}),e.jsxs(zt,{expanded:"tableHeader"===L,onChange:je("tableHeader"),disableGutters:!0,children:[e.jsx(d.AccordionSummary,{expandIcon:e.jsx(V,{}),children:e.jsx(o.Typography,{type:"s3",color:"theme.secondary.1000",children:"Table Header Styles"})}),e.jsx(d.AccordionDetails,{children:e.jsxs(d.Grid,{container:!0,spacing:2,children:[e.jsx(d.Grid,{item:!0,xs:12,children:e.jsx(n.ColorPickerInput,{value:(null==(x=pe.tHead)?void 0:x.backgroundColor)||"#f5f5f5",onChange:e=>Se("backgroundColor",e),fullWidth:!0,label:"Background Color"})}),e.jsx(d.Grid,{item:!0,xs:12,children:e.jsx(n.ColorPickerInput,{value:(null==(b=pe.tHead)?void 0:b.color)||"#333333",onChange:e=>Se("color",e),fullWidth:!0,label:"Text Color"})}),e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(c.TextField,{label:"Font Size",type:"number",value:(null==(f=pe.tHead)?void 0:f.fontSize)||14,onChange:e=>Se("fontSize",parseInt(e.target.value)||14),size:"small",fullWidth:!0})}),e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(c.Select,{value:(null==(y=pe.tHead)?void 0:y.fontWeight)||"bold",onChange:e=>Se("fontWeight",e.target.value),fullWidth:!0,size:"small",label:"Font Weight",children:Nt.map(t=>e.jsx(d.MenuItem,{value:t,children:w.formatText(t)},t))})}),e.jsx(d.Grid,{item:!0,xs:12,children:e.jsx(c.Select,{value:(null==(v=pe.tHead)?void 0:v.fontFamily)||"Arial, sans-serif",onChange:e=>Se("fontFamily",e.target.value),fullWidth:!0,size:"small",label:"Font Family",children:Lt.map(t=>e.jsx(d.MenuItem,{value:t,children:t.split(",")[0]},t))})}),e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(c.Select,{value:(null==(j=pe.tHead)?void 0:j.textAlign)||"left",onChange:e=>Se("textAlign",e.target.value),fullWidth:!0,size:"small",label:"Text Align",children:Rt.map(t=>e.jsx(d.MenuItem,{value:t,children:w.formatText(t)},t))})}),e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(c.TextField,{label:"Cell Padding",type:"number",value:(null==(S=pe.thCells)?void 0:S.padding)||8,onChange:e=>{return t="padding",l=parseInt(e.target.value)||8,void he(e=>({...e,thCells:{...e.thCells,[t]:l}}));var t,l},size:"small",fullWidth:!0})}),e.jsx(d.Grid,{item:!0,xs:12,children:e.jsx(d.FormControlLabel,{control:e.jsx(n.Android12Switch,{checked:!!(null==(C=pe.tBody)?void 0:C.zebraStriping),onChange:e=>Ce("zebraStriping",e.target.checked)}),label:"Zebra Striping"})}),(null==(_=pe.tBody)?void 0:_.zebraStriping)&&e.jsxs(d.Grid,{item:!0,xs:12,children:[e.jsx(o.Typography,{type:"s5",weight:"medium",color:"theme.secondary.1000",variant:"caption",children:"Alternating Row Color"}),e.jsx(n.ColorPickerInput,{value:(null==(k=pe.tBody)?void 0:k.alternateRowColor)||"#f9f9f9",onChange:e=>Ce("alternateRowColor",e),fullWidth:!0})]})]})})]}),e.jsxs(zt,{expanded:"tableBody"===L,onChange:je("tableBody"),disableGutters:!0,children:[e.jsx(d.AccordionSummary,{expandIcon:e.jsx(V,{}),children:e.jsx(o.Typography,{type:"s3",color:"theme.secondary.1000",children:"Table Body Styles"})}),e.jsx(d.AccordionDetails,{children:e.jsxs(d.Grid,{container:!0,spacing:2,children:[e.jsx(d.Grid,{item:!0,xs:12,children:e.jsx(n.ColorPickerInput,{value:(null==(I=pe.tBody)?void 0:I.backgroundColor)||"#ffffff",onChange:e=>Ce("backgroundColor",e),fullWidth:!0,label:"Background Color"})}),e.jsx(d.Grid,{item:!0,xs:12,children:e.jsx(n.ColorPickerInput,{value:(null==(E=pe.tBody)?void 0:E.color)||"#333333",onChange:e=>Ce("color",e),fullWidth:!0,label:"Text Color"})}),e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(c.TextField,{label:"Font Size",type:"number",value:(null==(B=pe.tBody)?void 0:B.fontSize)||14,onChange:e=>Ce("fontSize",parseInt(e.target.value)||14),size:"small",fullWidth:!0})}),e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(c.Select,{value:(null==(A=pe.tBody)?void 0:A.fontWeight)||"normal",onChange:e=>Ce("fontWeight",e.target.value),fullWidth:!0,size:"small",label:"Font Weight",children:Nt.map(t=>e.jsx(d.MenuItem,{value:t,children:w.formatText(t)},t))})}),e.jsx(d.Grid,{item:!0,xs:12,children:e.jsx(c.Select,{value:(null==(M=pe.tBody)?void 0:M.fontFamily)||"Arial, sans-serif",onChange:e=>Ce("fontFamily",e.target.value),fullWidth:!0,size:"small",label:"Font Family",children:Lt.map(t=>e.jsx(d.MenuItem,{value:t,children:t.split(",")[0]},t))})}),e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(c.Select,{value:(null==(F=pe.tBody)?void 0:F.textAlign)||"left",onChange:e=>Ce("textAlign",e.target.value),fullWidth:!0,size:"small",label:"Text Align",children:Rt.map(t=>e.jsx(d.MenuItem,{value:t,children:w.formatText(t)},t))})}),e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(c.TextField,{label:"Cell Padding",type:"number",value:(null==($=pe.tbCells)?void 0:$.padding)||8,onChange:e=>{return t="padding",l=parseInt(e.target.value)||8,void he(e=>({...e,tbCells:{...e.tbCells,[t]:l}}));var t,l},size:"small",fullWidth:!0})})]})})]})]}),2===R&&e.jsxs(d.Box,{children:[e.jsxs(d.Box,{sx:{mb:3},children:[e.jsx(o.Typography,{type:"s3",weight:"medium",color:"theme.secondary.1000",sx:{mb:2},children:"Cell Selection & Merging"}),e.jsx(d.Alert,{severity:"info",sx:{mb:2},children:"Click on cells in the table below to select them for merging. Selected cells will be highlighted. You can merge cells within the header or body, but not across both."}),e.jsxs(d.Box,{sx:{display:"flex",gap:1,mb:2,flexWrap:"wrap"},children:[e.jsxs(c.Button,{variant:"contained",size:"small",onClick:()=>{var e,t,a,o;if(Y.length<2)return void alert("Please select at least 2 cells to merge");const n=Y[0];let r="",i="";if("tbody"===n.section){const o=null==(e=l.columns[n.col])?void 0:e.id;r=(null==(t=l.rows[n.row])?void 0:t[o])||"",ee&&(i=(null==(a=ne[n.row])?void 0:a[o])||"")}else r=(null==(o=l.columns[n.col])?void 0:o.header)||"";const s=ee&&i?`${i} ${r}`.trim():r;Q(s),J(!0)},startIcon:e.jsx(K,{}),disabled:Y.length<2,color:"primary",children:["Merge Selected (",Y.length,")"]}),e.jsx(c.Button,{variant:"outlined",size:"small",onClick:()=>Z([]),disabled:0===Y.length,className:"black-outlined-btn",children:"Clear Selection"})]}),e.jsx(d.Box,{sx:{border:1,borderColor:"divider",borderRadius:1,overflow:"auto",maxHeight:400},children:e.jsxs(d.Table,{size:"small",sx:{minWidth:300},children:[e.jsx(d.TableHead,{children:e.jsx(d.TableRow,{children:l.columns.map((t,l)=>{const a=be("thead",0,l),o=fe("thead",0,l);if(null==a?void 0:a.isCovered)return null;const r=a?a.merge.value:t.header,i=a?a.merge.rowEnd-a.merge.rowStart+1:1,s=a?a.merge.colEnd-a.merge.colStart+1:1;return e.jsxs(d.TableCell,{rowSpan:i,colSpan:s,onClick:()=>!a&&ye("thead",0,l),sx:e=>({fontWeight:"bold",bgcolor:a?"blue.50":o?"primary.100":"grey.100",position:"sticky",top:0,zIndex:1,cursor:a?"default":"pointer",border:o?2:1,borderColor:o?e.palette.theme.primary[800]:"divider","&:hover":a?{}:{bgcolor:o?"primary.200":"grey.50"}}),children:[r,a&&e.jsx(d.Chip,{label:`${i}×${s}`,size:"small",color:"primary",variant:"outlined",sx:e=>({position:"absolute",top:2,right:2,fontSize:"0.6rem",height:16,color:e.palette.theme.primary[800],borderColor:e.palette.theme.primary[800]})}),o&&e.jsx(n.Checkbox,{checked:!0,size:"small",sx:{position:"absolute",top:2,left:2,padding:0}})]},t.id)})})}),e.jsx(d.TableBody,{children:l.rows.map((t,a)=>e.jsx(d.TableRow,{children:l.columns.map((l,o)=>{var r;const i=be("tbody",a,o),s=fe("tbody",a,o);if(null==i?void 0:i.isCovered)return null;const c=(null==(r=ne[a])?void 0:r[l.id])||"",u=i?i.merge.value:c?`${c} ${t[l.id]||""}`.trim():t[l.id]||"",m=i?i.merge.rowEnd-i.merge.rowStart+1:1,p=i?i.merge.colEnd-i.merge.colStart+1:1;return e.jsxs(d.TableCell,{rowSpan:m,colSpan:p,onClick:()=>!i&&ye("tbody",a,o),sx:e=>{var t;return{cursor:i?"default":"pointer",bgcolor:i?"blue.50":s?"primary.100":"transparent",border:s?2:1,borderColor:s?null==(t=e.palette.theme)?void 0:t.primary[800]:"divider","&:hover":i?{}:{bgcolor:s?"primary.200":"grey.50"},position:"relative"}},children:[u,i&&e.jsx(d.Chip,{label:`${m}×${p}`,size:"small",color:"primary",variant:"outlined",sx:e=>{var t,l;return{position:"absolute",top:2,right:2,fontSize:"0.6rem",height:16,color:null==(t=e.palette.theme)?void 0:t.primary[800],borderColor:null==(l=e.palette.theme)?void 0:l.primary[800]}}}),s&&e.jsx(n.Checkbox,{checked:!0,size:"small",sx:{position:"absolute",top:2,left:2,padding:0}})]},l.id)})},a))})]})})]}),de.length>0&&e.jsxs(d.Box,{sx:{mt:3},children:[e.jsxs(o.Typography,{type:"s3",weight:"medium",color:"theme.secondary.1000",sx:{mb:2},children:["Merged Cells (",de.length,")"]}),de.map((t,l)=>e.jsxs(d.Box,{sx:{p:2,mb:1,border:1,borderColor:"divider",borderRadius:1,bgcolor:"blue.25"},children:[e.jsxs(d.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",mb:1},children:[e.jsxs(d.Box,{children:[e.jsxs(o.Typography,{type:"s4",weight:"medium",color:"theme.secondary.900",children:["Merge ",l+1,": ",t.rowEnd-t.rowStart+1,"×",t.colEnd-t.colStart+1," cells (",t.section,")"]}),e.jsxs(o.Typography,{type:"s5",color:"theme.secondary.700",children:["Rows ",t.rowStart+1,"-",t.rowEnd+1,", Columns ",t.colStart+1,"-",t.colEnd+1]})]}),e.jsx(c.Button,{variant:"outlined",size:"small",onClick:()=>(e=>{const t=de[e];a(l=>{var a,o;const n=[...l.rows],r=[...l.columns];if("tbody"===t.section)for(let e=t.rowStart;e<=t.rowEnd;e++)for(let o=t.colStart;o<=t.colEnd;o++){const r=null==(a=l.columns[o])?void 0:a.id;r&&n[e]&&(n[e][r]=t.value)}else r[t.colStart]&&(r[t.colStart].header=t.value);return{...l,rows:n,name:ae||"",columns:r,mergedCells:(null==(o=l.mergedCells)?void 0:o.filter((t,l)=>l!==e))||[]}})})(l),startIcon:e.jsx(D,{}),className:"black-outlined-btn",children:"Split"})]}),e.jsx(c.TextField,{label:"Merged Cell Value",value:t.value,onChange:e=>{a(t=>{var a;return{...t,mergedCells:(null==(a=t.mergedCells)?void 0:a.map((t,a)=>a===l?{...t,value:e.target.value}:t))||[]}})},size:"small",fullWidth:!0,multiline:!0,rows:2})]},l))]})]}),e.jsxs(d.Dialog,{open:H,onClose:()=>J(!1),maxWidth:"sm",fullWidth:!0,children:[e.jsx(d.DialogTitle,{children:e.jsx(o.Typography,{type:"s2",weight:"medium",children:"Merge Selected Cells"})}),e.jsxs(d.DialogContent,{children:[e.jsxs(o.Typography,{type:"s4",color:"theme.secondary.700",sx:{mb:2},children:["You are about to merge ",Y.length," selected cells in ",null==(P=Y[0])?void 0:P.section,". Enter the value for the merged cell:"]}),e.jsx(c.TextField,{label:"Merged Cell Value",value:X,onChange:e=>Q(e.target.value),fullWidth:!0,multiline:!0,rows:3,sx:{mt:1}}),e.jsxs(d.Alert,{severity:"info",sx:{mt:2},children:["The merged cell will span from row ",Math.min(...Y.map(e=>e.row))+1," to ",Math.max(...Y.map(e=>e.row))+1,"and column ",Math.min(...Y.map(e=>e.col))+1," to ",Math.max(...Y.map(e=>e.col))+1," in ",null==(z=Y[0])?void 0:z.section,"."]})]}),e.jsxs(d.DialogActions,{children:[e.jsx(c.Button,{onClick:()=>J(!1),children:"Cancel"}),e.jsx(c.Button,{onClick:()=>{if(Y.length<2)return;const e=Y[0].section,t=Y.map(e=>e.row),l=Y.map(e=>e.col),o=Math.min(...t),n=Math.max(...t),r=Math.min(...l),i=Math.max(...l),s=(n-o+1)*(i-r+1);if(Y.length!==s)return void alert("Please select a rectangular area of cells to merge");if(de.some(t=>t.section===e&&!(n<t.rowStart||o>t.rowEnd||i<t.colStart||r>t.colEnd)))return void alert("Cannot merge cells that overlap with existing merged cells");const d={section:e,rowStart:o,rowEnd:n,colStart:r,colEnd:i,value:X};a(t=>({...t,name:ae||"",mergedCells:[...t.mergedCells||[],d],columns:"thead"===e?t.columns.map((e,t)=>t===r?{...e,header:X}:e):t.columns})),Z([]),Q(""),J(!1)},variant:"contained",color:"primary",children:"Merge Cells"})]})]})]})},qt=({attrs:t,updateAttrs:l})=>{const{styles:a}=t;return e.jsxs(e.Fragment,{children:[e.jsxs(d.Box,{sx:{mb:1},children:[e.jsx(o.Typography,{type:"s5",color:"theme.secondary.800",weight:"medium",children:"Font Size"}),e.jsx(d.Slider,{value:null==a?void 0:a.fontSize,onChange:(e,t)=>l({styles:{fontSize:t}}),min:10,max:20,step:1,valueLabelDisplay:"auto",size:"small",sx:e=>({"& .MuiSlider-rail":{color:e.palette.theme.primary[500]},"& .MuiSlider-thumb":{color:e.palette.theme.primary[800]},"& .MuiSlider-track":{color:e.palette.theme.primary[600]}})})]}),e.jsx(d.Box,{sx:{mb:2},children:e.jsx(c.TextField,{label:"Text Color",type:"color",value:null==a?void 0:a.color,onChange:e=>l({styles:{color:e.target.value}}),fullWidth:!0,InputProps:{startAdornment:e.jsx(d.InputAdornment,{position:"start",children:e.jsx(N,{fontSize:"small"})})}})})]})},Wt=({attrs:t,updateAttrs:l})=>{const{styles:a}=t,n=e=>{l({styles:e})};return e.jsxs(e.Fragment,{children:[e.jsxs(d.Box,{sx:{mb:2},children:[e.jsx(o.Typography,{type:"s3",color:"theme.neutral.800",children:"Size (px)"}),e.jsx(d.Slider,{value:a.fontSize,onChange:(e,t)=>n({fontSize:t}),min:10,max:25,step:5,valueLabelDisplay:"auto",size:"small",sx:e=>({"& .MuiSlider-rail":{color:e.palette.theme.primary[500]},"& .MuiSlider-thumb":{color:e.palette.theme.primary[800]},"& .MuiSlider-track":{color:e.palette.theme.primary[600]}})})]}),e.jsx(Ct,{alignment:null==a?void 0:a.textAlign,onAlignmentChange:(e,t)=>{null!==t&&n({textAlign:t})},displayLabel:!0})]})},Ht=["text","text-block","heading","heading-2","heading-3","heading-4","buttons","image","divider","table","signature","qr-code","bar-code"],Vt=({section:l,onClose:a,onUpdate:n,placeholders:r,relation_table:i,handleSave:s})=>{var u,m;const p=t.useMemo(()=>(null==l?void 0:l.type)||"text",[null==l?void 0:l.type]),h=t.useMemo(()=>(null==l?void 0:l.content)||"text",[null==l?void 0:l.content]);t.useState([]);const[g,x]=t.useState((null==(u=null==l?void 0:l.attributes)?void 0:u.rowLevel)||!1),[b,f]=t.useState({name:"",columns:[{id:"col1",header:"Column 1"},{id:"col2",header:"Column 2"},{id:"col3",header:"Column 3"}],rows:[{col1:"",col2:"",col3:""}],border:!0,mergedCells:[]}),[y,v]=t.useState(!0),[j,S]=t.useState(ct(h));t.useEffect(()=>{var e,t;if(l&&"table"===l.type)if(null==(e=l.attributes)?void 0:e.tableData)f(l.attributes.tableData);else{const e=C(l.content);e&&(f(e),x((null==(t=null==l?void 0:l.attributes)?void 0:t.rowLevel)||!1))}},[]),t.useEffect(()=>{var e;l&&!y&&(document.createElement("div").innerHTML=l.content,S(null==(e=ct(l.content))?void 0:e.styles),v(!1))},[l]);const C=e=>{try{const t=(new DOMParser).parseFromString(e,"text/html").querySelector("table");if(!t)return null;const l=t.querySelectorAll("thead tr"),a=t.querySelectorAll("tbody tr");if(0===l.length)return null;const o=l[0].querySelectorAll("th"),n=Array.from(o).map((e,t)=>{var l;return{id:`col${t+1}`,header:(null==(l=e.textContent)?void 0:l.trim())||`Column ${t+1}`}}),r=[];Array.from(l).forEach((e,t)=>{e.querySelectorAll("th").forEach((e,l)=>{var a;const o=parseInt(e.getAttribute("rowspan")||"1"),n=parseInt(e.getAttribute("colspan")||"1");(o>1||n>1)&&r.push({section:"thead",rowStart:t,rowEnd:t+o-1,colStart:l,colEnd:l+n-1,value:(null==(a=e.textContent)?void 0:a.trim())||""})})});const i=Array.from(a).map(e=>{const t=e.querySelectorAll("td"),l={};return t.forEach((e,t)=>{var a;t<n.length&&(l[n[t].id]=(null==(a=e.textContent)?void 0:a.trim())||"")}),l});return Array.from(a).forEach((e,t)=>{e.querySelectorAll("td").forEach((e,l)=>{var a;const o=parseInt(e.getAttribute("rowspan")||"1"),n=parseInt(e.getAttribute("colspan")||"1");(o>1||n>1)&&r.push({section:"tbody",rowStart:t,rowEnd:t+o-1,colStart:l,colEnd:l+n-1,value:(null==(a=e.textContent)?void 0:a.trim())||""})})}),{name:"",columns:n,rows:i.length>0?i:[{}],border:!0,mergedCells:r}}catch(t){return null}},w=t.useCallback(e=>{var t;const{src:a,alt:o,styles:n,text:i,placeholder:s,placeholders:d}=e||(null==l?void 0:l.attributes)||j||{},c={...M.initialStyles[p],...n,...null==j?void 0:j.styles,...null==e?void 0:e.styles},u=mt(c);if("buttons"===p)return`<button style="${u}">${i||"Button Text"}</button>`;if("image"===p){let e=u;return(null==c?void 0:c.is_bordered)?(c.padding="10px",e=mt(c)):(c.padding="0",e=mt(c)),`<img src="${a||""}" alt="${o||""}" style="${e}" />`}if("divider"===p)return`<hr style="${u}" />`;if("table"===p){const{border:e,borderStyle:l,borderColor:a,...o}=c,n=mt(c.is_bordered?c:o),i=mt(c.tHead||{}),s=mt(c.tBody||{}),u=mt({...c.thCells||{},...c.is_bordered?{border:e,borderStyle:l,borderColor:a}:{}}),m=mt({...c.tbCells||{},...c.is_bordered?{border:e,borderStyle:l,borderColor:a}:{}}),p=(e,t,l)=>{var a;return null==(a=b.mergedCells)?void 0:a.find(a=>a.section===e&&t>=a.rowStart&&t<=a.rowEnd&&l>=a.colStart&&l<=a.colEnd)},h=b.columns.map((e,t)=>{const l=p("thead",0,t);if(l&&t!==l.colStart)return"";const a=l?` rowspan="${l.rowEnd-l.rowStart+1}" colspan="${l.colEnd-l.colStart+1}"`:"",o=l?l.value:e.header;return`<th style="${u}"${a}>${o}</th>`}).filter(e=>""!==e).join("");let g="";if(b.name){const e=b.columns.map((e,t)=>{var l,a;const o=p("tbody",0,t);if(o&&t!==o.colStart)return"";const n=o?` rowspan="${o.rowEnd-o.rowStart+1}" colspan="${o.colEnd-o.colStart+1}"`:"";let r="";if("index"===e.id||"incrementIndex"===e.id)r="{{incrementIndex @index}}";else if(e.id.includes(".")){const t=null==(l=null==b?void 0:b.rows)?void 0:l[0][e.id];r="string"==typeof t?t.replace(b.name+".",""):String(t||"")}else{const t=null==(a=null==b?void 0:b.rows)?void 0:a[0][e.id];r="string"==typeof t?t.replace(b.name+".",""):String(t||"")}return`<td style="${m}"${n}>${r}</td>`}).filter(e=>""!==e).join(""),l=(null==(t=c.tBody)?void 0:t.zebraStriping)?`{{#if (isOdd @index)}}${s}; background-color: ${c.tBody.alternateRowColor||"#f9f9f9"}{{else}}${s}{{/if}}`:s;g=`{{#each ${b.name}}}\n <tr style="${l}">\n ${e}\n </tr>\n {{/each}}`}else g=b.rows.map((e,t)=>{var l;const a=(null==(l=c.tBody)?void 0:l.zebraStriping)&&t%2==1?`; background-color: ${c.tBody.alternateRowColor||"#f9f9f9"}`:"",o=b.columns.map((l,a)=>{const o=p("tbody",t,a);if(o&&(t!==o.rowStart||a!==o.colStart))return"";let n=e[l.id]||"";Object.keys(e).includes(`${l.id}_static`)&&(n=e[`${l.id}_static`]||""),!n&&(null==d?void 0:d[l.id])&&(n=(e=>{const t=r.find(t=>t.value===e);if(!t)return"";if(void 0!==t.actualValue)return String(t.actualValue);switch(t.type){case"date":return(new Date).toLocaleDateString();case"datetime":return(new Date).toLocaleString();case"number":return"123";case"currency":return"$1,234.56";case"email":return"example@domain.com";case"phone":return"+1 (555) 123-4567";case"url":return"https://example.com";default:return t.label||t.value}})(d[l.id]));const i=o?` rowspan="${o.rowEnd-o.rowStart+1}" colspan="${o.colEnd-o.colStart+1}"`:"",s=o?o.value:n;return`<td style="${m}"${i}>${s}</td>`}).filter(e=>""!==e).join("");return`<tr style="${s}${a}">${o}</tr>`}).join("");return`\n <table style="${n}">\n <thead>\n <tr style="${i}">\n ${h}\n </tr>\n </thead>\n <tbody>\n ${g}\n </tbody>\n </table>\n `}if("qr-code"===p||"bar-code"===p)return`<div style="${u}">${s}</div>`;if(/<\/?[a-z][\s\S]*>/i.test(h)){const e=(new DOMParser).parseFromString(`<div>${h}</div>`,"text/html").body.firstChild;return e&&e.nodeType===Node.ELEMENT_NODE?(e.querySelectorAll("*").forEach(e=>{if("SCRIPT"===e.tagName||"STYLE"===e.tagName)return;const t=e.getAttribute("style")||"",l={};t.split(";").forEach(e=>{const[t,a]=e.split(":").map(e=>e.trim());t&&a&&(l[t]=a)});const a={};u.split(";").forEach(e=>{const[t,l]=e.split(":").map(e=>e.trim());t&&l&&(a[t]=l)}),"P"===e.tagName||"DIV"===e.tagName?a["line-height"]="1.5":["H1","H2","H3","H4","H5","H6"].includes(e.tagName)&&(a["line-height"]="1.2",a.margin="0.5em 0");const o={...l,...a},n=Object.entries(o).filter(([e,t])=>e&&t).map(([e,t])=>`${e}: ${t}`).join("; ");e.setAttribute("style",n)}),e.innerHTML):h}switch(p){case"text":case"text-block":default:return`<p style="${u}">${h}</p>`;case"heading":return`<h1 style="${u}">${h}</h1>`;case"heading-2":return`<h2 style="${u}">${h}</h2>`;case"heading-3":return`<h3 style="${u}">${h}</h3>`;case"heading-4":return`<h4 style="${u}">${h}</h4>`;case"signature":return`<div style="${u}">${h}</div>`}},[JSON.stringify(l)]),_=()=>{const e={content:w(),type:p,rowLevel:g,name:b.name||"",attributes:{...(null==l?void 0:l.attributes)||{},..."table"===p?{tableData:b}:{}},is_edited_from_source:(null==l?void 0:l.is_edited_from_source)||!1};n(e)};t.useEffect(()=>{_()},[b]);const k=e=>{var t;if(!l)return;const a={...(null==(t=l.attributes)?void 0:t.styles)||{},...e.styles||{}},o={...l.attributes||{},...e,styles:a,..."table"===p?{tableData:b}:{}},{id:r,...i}=l,s=w(o);S(o),n({...i,content:s,attributes:o})};return e.jsxs(d.Paper,{elevation:3,sx:{width:{xs:"100%",sm:320,lg:390},height:"100%",overflow:"auto",borderLeft:"1px solid",borderColor:"divider",display:"flex",flexDirection:"column",bgcolor:"background.paper",boxShadow:"none"},children:[e.jsxs(d.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",p:2,borderBottom:"1px solid",borderColor:"divider",bgcolor:"grey.50"},children:[e.jsxs(o.Typography,{type:"s1",weight:"bold",color:"theme.neutral.1000",children:["Format ",p?(null==(m=null==p?void 0:p.charAt(0))?void 0:m.toUpperCase())+(null==p?void 0:p.slice(1).replace(/-/g," ")):""]}),e.jsx(d.Tooltip,{title:"Save and Close",children:e.jsxs(d.Box,{children:[e.jsx(d.IconButton,{size:"small",onClick:()=>{_(),null==s||s(),a()},"aria-label":"Save",children:e.jsx(T.Save,{fontSize:"small"})}),e.jsx(d.IconButton,{size:"small",onClick:a,"aria-label":"Close",children:e.jsx(E,{fontSize:"small"})})]})})]}),e.jsxs(d.Box,{sx:{p:2,flex:1,pb:10,overflowY:"auto"},children:[e.jsx(d.Box,{sx:{mb:2},children:e.jsx(d.FormControl,{size:"small",fullWidth:!0,children:e.jsx(c.Select,{value:null==l?void 0:l.type,onChange:e=>(e=>{const t=pt(e);n({...l,...t}),"table"===e&&f({name:"",columns:[{id:"col1",header:"Column 1"},{id:"col2",header:"Column 2"},{id:"col3",header:"Column 3"}],rows:[{col1:"",col2:"",col3:""}],border:!0,mergedCells:[]})})(e.target.value),renderValue:e=>e?e.charAt(0).toUpperCase()+e.slice(1).replace(/-/g," "):"",label:"Select Preset",displayEmpty:!0,children:Ht.map(t=>e.jsx(d.MenuItem,{value:t,children:e.jsx(o.Typography,{type:"s4",color:"theme.secondary.1000",children:t.charAt(0).toUpperCase()+t.slice(1).replace(/-/g," ")})},t))})})}),l&&("text"===p||"heading"===p||"heading-2"===p||"heading-3"===p||"heading-4"===p)&&e.jsx(It,{attrs:(null==l?void 0:l.attributes)||{},updateAttrs:k}),"buttons"===p&&e.jsx(Bt,{attrs:(null==l?void 0:l.attributes)||{},updateAttrs:k}),"image"===p&&e.jsx(Dt,{attrs:(null==l?void 0:l.attributes)||{},updateAttrs:k}),"divider"===p&&e.jsx(Pt,{attrs:(null==l?void 0:l.attributes)||{},updateAttrs:k}),"table"===p&&e.jsx(Ot,{tableData:{...b,rows:b.rows.map(e=>{const t={};return Object.keys(e).forEach(l=>{t[l]=String(e[l]??"")}),t})},setTableData:e=>{var t;t={...e,border:b.border,name:b.name||""},f(t),_()},attrs:(null==l?void 0:l.attributes)||{},updateAttrs:k,placeholders:r,handleSave:s,setParentRowLevel:x,levelType:g,relation_table:i}),"signature"===p&&e.jsx(qt,{attrs:(null==l?void 0:l.attributes)||{},updateAttrs:k}),l&&("qr-code"===p||"bar-code"===p)&&e.jsx(Wt,{attrs:(null==l?void 0:l.attributes)||{},updateAttrs:k})]})]})},Gt=b.styled(d.ListItem)(({theme:e})=>({padding:e.spacing(1.5),cursor:"grab",borderRadius:e.shape.borderRadius,"&:hover":{backgroundColor:e.palette.grey[100]},"&.dragging":{opacity:.5}})),Ut=b.styled(d.Box)(({theme:e})=>({border:`2px dashed ${e.palette.grey[400]}`,borderRadius:e.shape.borderRadius,padding:e.spacing(2),textAlign:"center",backgroundColor:e.palette.grey[50],cursor:"pointer","&:hover":{backgroundColor:e.palette.grey[100]}})),Kt=({id:t,icon:l,label:a,imageUrl:o})=>{const n="string"==typeof t?t.replace("sidebar-",""):t,{attributes:r,listeners:i,setNodeRef:s,isDragging:c}=F.useDraggable({id:t,data:{type:o?"image":n,imageUrl:o,label:a}});return e.jsx(Gt,{ref:s,...i,...r,className:c?"dragging":"",sx:{border:"1px solid",borderColor:"grey.200",p:.75},children:o?e.jsx("img",{src:o,alt:a,style:{width:"100%",height:140,objectFit:"cover",marginRight:8}}):e.jsxs(e.Fragment,{children:[e.jsx(d.ListItemIcon,{sx:{minWidth:40},children:l}),e.jsx(d.ListItemText,{primary:a,primaryTypographyProps:{variant:"body2"}})]})})},Jt=({onHtmlUpload:l})=>{const[a,o]=t.useState("text"),[n,r]=t.useState([]),[i,s]=t.useState(!1),[u,m]=t.useState(!1),[p,g]=t.useState(null),x=t.useCallback(async e=>{s(!0),g(null);try{for(const t of e){const e=await w.uploadFiles([t],"document"),l=w.getToken(),a={...l,"x-timezone":String(l["x-timezone"]||""),title:null==t?void 0:t.name.split(".")[0],path:"/",is_private:!0,is_directory:!1,file_size:t.size,is_child:!1,file_extension:null==t?void 0:t.name.split(".")[1],type:"image",mime_type:t.type,url:`${h.getApiConfig().s3BucketUrl}${e[0]}`};await Z.postV1Drive(a),r(l=>[...l,{id:`uploaded-image-${Date.now()}-${Math.random()}`,url:`${h.getApiConfig().s3BucketUrl}${e[0]}`,name:t.name}])}}catch(t){g("Failed to upload image. Please try again.")}finally{s(!1)}},[]),{getRootProps:b,getInputProps:f,isDragActive:y}=J.useDropzone({onDrop:x,accept:{"image/*":[".jpeg",".png",".jpg",".gif"]},multiple:!0}),v=t.useCallback(async e=>{if(l){m(!0),g(null);try{const t=e[0];if(!t)return;const a=new FileReader;a.onload=e=>{var t;const a=null==(t=e.target)?void 0:t.result;a&&(l(a),m(!1))},a.onerror=()=>{g("Failed to read HTML file. Please try again."),m(!1)},a.readAsText(t)}catch(t){g("Failed to process HTML file. Please try again."),m(!1)}}},[l]),{getRootProps:j,getInputProps:S,isDragActive:C}=J.useDropzone({onDrop:v,accept:{"text/html":[".html",".htm"]},multiple:!1,maxFiles:1}),_=[{id:"html-upload",icon:e.jsx(Y.FileCode,{size:18}),label:"Upload HTML",content:e.jsxs(d.Box,{sx:{mt:2},children:[e.jsxs(Ut,{...j(),children:[e.jsx("input",{...S()}),C?e.jsx(d.Typography,{variant:"body2",color:"text.secondary",children:"Drop the HTML file here..."}):e.jsx(d.Typography,{variant:"body2",color:"text.secondary",children:"Drag and drop HTML file here, or click to select"}),u&&e.jsx(d.Box,{sx:{mt:1},children:e.jsx(d.CircularProgress,{size:20})})]}),e.jsx(d.Typography,{variant:"caption",color:"text.secondary",sx:{mt:1,display:"block"},children:"Upload an HTML file to replace current sections with the file content"})]})},{id:"text",icon:e.jsx(Y.Text,{size:18}),label:"Text",content:e.jsxs(d.Box,{sx:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:1},children:[e.jsx(Kt,{id:"sidebar-heading",icon:e.jsx(Y.Heading,{size:20}),label:"Heading 1"}),e.jsx(Kt,{id:"sidebar-heading-2",icon:e.jsx(Y.Heading,{size:18}),label:"Heading 2"}),e.jsx(Kt,{id:"sidebar-heading-3",icon:e.jsx(Y.Heading,{size:16}),label:"Heading 3"}),e.jsx(Kt,{id:"sidebar-heading-4",icon:e.jsx(Y.Heading,{size:14}),label:"Heading 4"}),e.jsx(Kt,{id:"sidebar-text",icon:e.jsx(Y.Text,{size:20}),label:"Body"}),e.jsx(Kt,{id:"sidebar-text-block",icon:e.jsx(Y.Text,{size:20}),label:"Text Block"})]})},{id:"images",icon:e.jsx(Y.Image,{size:18}),label:"Images",content:e.jsx(d.Box,{sx:{mt:2},children:e.jsxs(d.Box,{sx:{mt:2},children:[e.jsxs(Ut,{...b(),children:[e.jsx("input",{...f()}),y?e.jsx(d.Typography,{variant:"body2",color:"text.secondary",children:"Drop the images here..."}):e.jsx(d.Typography,{variant:"body2",color:"text.secondary",children:"Drag and drop images here, or click to select"}),i&&e.jsx(d.Box,{sx:{mt:1},children:e.jsx(d.CircularProgress,{size:20})})]}),p&&e.jsx(d.Alert,{severity:"error",sx:{mt:2},children:p}),n.length>0&&e.jsxs(d.Box,{sx:{mt:2},children:[e.jsx(d.Typography,{variant:"body2",sx:{mb:1,color:"grey.500"},children:"Uploaded Images"}),e.jsx(d.Grid,{container:!0,spacing:1,children:n.map(t=>e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(Kt,{id:t.id,label:t.name,imageUrl:t.url})},t.id))})]})]})})},{id:"buttons",icon:e.jsx(d.Box,{sx:{width:16,height:16,bgcolor:"grey.400",borderRadius:1,color:"white",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"8px"},children:"BTN"}),label:"Buttons",content:e.jsx(d.Box,{sx:{mt:2},children:e.jsx(Kt,{id:"sidebar-buttons",icon:e.jsx(d.Box,{sx:{width:20,height:20,bgcolor:"success.main",borderRadius:1,color:"white",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px"},children:"BTN"}),label:"Buttons"})})},{id:"divider",icon:e.jsx(d.Divider,{sx:{width:18}}),label:"Divider",content:e.jsx(d.Box,{sx:{mt:2},children:e.jsx(Kt,{id:"sidebar-divider",icon:e.jsx(d.Divider,{sx:{width:20}}),label:"Divider"})})},{id:"table",icon:e.jsx(Y.Table,{size:18}),label:"Table",content:e.jsx(d.Box,{sx:{mt:2},children:e.jsx(Kt,{id:"sidebar-table",icon:e.jsx(Y.Table,{size:20}),label:"Table"})})},{id:"signature",icon:e.jsx(Y.Blocks,{size:18}),label:"Signature",content:e.jsx(d.Box,{sx:{mt:2},children:e.jsx(Kt,{id:"sidebar-signature",icon:e.jsx(Y.Blocks,{size:20}),label:"Signature"})})},{id:"qr-code",icon:e.jsx(Y.QrCode,{size:18}),label:"QR Code",content:e.jsx(d.Box,{sx:{mt:2},children:e.jsx(Kt,{id:"sidebar-qr-code",icon:e.jsx(Y.QrCode,{size:20}),label:"QR Code"})})},{id:"bar-code",icon:e.jsx(Y.Barcode,{size:18}),label:"Bar Code",content:e.jsx(d.Box,{sx:{mt:2},children:e.jsx(Kt,{id:"sidebar-bar-code",icon:e.jsx(Y.Barcode,{size:20}),label:"Bar Code"})})}];return t.useEffect(()=>{(async()=>{try{const e=w.getToken(),t=await Z.getV1Drive({...e,"x-timezone":String(e["x-timezone"]||""),skip:0,limit:10,filters:"(is_directory.eq=0)"});if("data"in t&&t.data&&"object"==typeof t.data&&"drive"in t.data){const e=t.data.drive||[];r(e)}}catch(e){console.log(e)}})()},[]),e.jsxs(d.Box,{sx:{bgcolor:"background.paper",borderRight:1,borderColor:"grey.200",width:390,display:"flex",flexDirection:"column",height:"calc(100vh - 104px)",boxShadow:"0 2px 8px rgba(0,0,0,0.05)",fontFamily:"Inter, system-ui, Avenir, Helvetica, Arial, sans-serif"},children:[e.jsx(d.Box,{sx:{p:2,borderBottom:1,borderColor:"grey.200"},children:e.jsx(c.SearchBar,{handleSearch:e=>console.log("Search:",e),sx:{backgroundColor:"#fff !important",border:"1px solid grey"}})}),e.jsx(d.Box,{sx:{flexGrow:1,overflowY:"auto",p:1},children:_.map(t=>{return e.jsxs(d.Accordion,{expanded:a===t.id,onChange:(l=t.id,(e,t)=>{o(!!t&&l)}),sx:{border:"none",boxShadow:"none",backgroundColor:"transparent","&:before":{display:"none"},marginBottom:1},children:[e.jsx(d.AccordionSummary,{expandIcon:e.jsx(V,{sx:{color:"grey.600"}}),sx:{borderRadius:"8px",padding:"0 12px",backgroundColor:a===t.id?"grey.200":"grey.50","&:hover":{backgroundColor:"grey.50"},transition:"background-color 0.2s ease",minHeight:42,"& .MuiAccordionSummary-content":{alignItems:"center",margin:"8px 0"},"&.Mui-expanded":{minHeight:42}},children:e.jsxs(d.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[t.icon,e.jsx(d.Typography,{variant:"body2",sx:{fontWeight:500,color:"text.primary"},children:t.label})]})}),e.jsx(d.AccordionDetails,{sx:{padding:"8px 16px"},children:t.content})]},t.id);var l})})]})},Yt="header",Zt="main",Xt="footer",Qt=({sections:l,headerSections:a,footerSections:n,activeId:r,selectedSection:i,onSelectSection:s,onUpdateSection:u,onSplitSection:m,onDeleteSection:p,preview:h,editHtml:g,onApplyHtmlEdit:x,onCancelHtmlEdit:b,editMode:f,isFromPreview:y,placeholders:v,isEditingHeaderFooter:j,handleSave:S,relation_table:C,zoom:w=100})=>{const _=t.useMemo(()=>v.map(e=>({value:e.value||e.key||"",label:e.label||e.name||String(e.value||e.key||"")})),[v]),{setNodeRef:k}=F.useDroppable({id:"main-canvas"}),{setNodeRef:T}=F.useDroppable({id:"header-canvas"}),{setNodeRef:I}=F.useDroppable({id:"footer-canvas"}),B=t.useMemo(()=>[...l,...a,...n].find(e=>e.id===i),[l,i]),[A,M]=t.useState({id:null,type:"inside",canvasType:Zt}),[$,D]=t.useState(!1),[P,z]=t.useState(!1),[R,N]=t.useState("");t.useEffect(()=>{g&&N(st(l,a,n))},[g]);const L=t.useRef(0),O=t.useRef({x:0,y:0}),q=t.useRef(null),W=t.useRef(null),H=t.useRef(null),V=t.useRef(null),G=e=>{switch(e){case Yt:return a;case Xt:return n;default:return l}};t.useEffect(()=>{q.current=r,r&&String(r).includes("sidebar-")?(D(!0),(null==l?void 0:l.length)>0?U(l[0].id,"before",Zt):(null==a?void 0:a.length)>0&&j?U(a[0].id,"before",Yt):(null==n?void 0:n.length)>0&&j?U(n[0].id,"before",Xt):U(null,"inside",Zt)):r||(D(!1),M({id:null,type:"inside",canvasType:Zt}))},[r,l,a,n,j]);const U=t.useCallback((e,t,l)=>{const a=Date.now();a-L.current<50||M(o=>o.id===e&&o.type===t&&o.canvasType===l?o:(L.current=a,{id:e,type:t,canvasType:l}))},[]),K=t.useCallback((e,t)=>{if(!q.current)return;if(t!==Zt&&!j)return;const l=e.clientX-O.current.x,a=e.clientY-O.current.y;if(Math.sqrt(l*l+a*a)<5)return;O.current={x:e.clientX,y:e.clientY};const o=document.elementsFromPoint(e.clientX,e.clientY).find(e=>e.hasAttribute("data-section-id")),n=G(t);if(!o)return void(0===n.length?U(null,"inside",t):$&&U(n[n.length-1].id,"after",t));const r=o.getAttribute("data-section-id");if(!r)return;const i=o.hasAttribute("data-canvas-type")?o.getAttribute("data-canvas-type"):t,s=o.getBoundingClientRect(),d=e.clientY-s.top,c=e.clientX-s.left,u=s.height,m=s.width,p=G(i).find(e=>e.id===r);if(r.startsWith("split-group-")||p&&p.isSplitPair)U(r,c<.4*m?"left":c>.6*m?"right":"inside",i);else{let e="inside";e=d<.19999999999999998*u?"before":d>.7999999999999999*u?"after":"inside",U(r,e,i)}},[j,$,U]),J=t.useCallback((e,t)=>{if(!q.current||!$)return;if(t!==Zt&&!j)return;const l=G(t);l.length>0?U(l[0].id,"before",t):U(null,"inside",t),O.current={x:e.clientX,y:e.clientY}},[$,j,U]),Y=t.useCallback((l,a)=>{const n=[],c=new Set;let h=0;const g=(t,l=!1)=>e.jsx(d.Box,{sx:{[l?"width":"height"]:"50px",border:"2px dashed",borderColor:"primary.main",borderRadius:1,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"rgba(25, 118, 210, 0.04)",[l?"mx":"mb"]:2,opacity:0,animation:"fadeIn 0.3s ease-in-out forwards","@keyframes fadeIn":{"0%":{opacity:0,transform:l?"translateX(-10px)":"translateY(-10px)"},"100%":{opacity:1,transform:"translate(0)"}}},children:e.jsx(o.Typography,{type:"s2",color:"primary",weight:"medium",children:"Drop here"})},t);for($&&(null==l?void 0:l.length)>0&&"before"===A.type&&A.id===l[0].id&&A.canvasType===a&&n.push(g(`drop-before-first-${a}`));h<(null==l?void 0:l.length);){const o=l[h],x=o.id;if(A.id!==x||"before"!==A.type||A.canvasType!==a||$&&0===h||n.push(g(`drop-before-${x}-${a}`)),o.isSplitPair){const x=o.splitGroupId;if(x&&c.has(x)){h++;continue}const b=l.filter(e=>e.splitGroupId===x);if(b.length>0){x&&c.add(x);const l=e.jsx(d.Box,{sx:{display:"flex",gap:2,mb:2,bgcolor:"rgba(0, 0, 0, 0.02)",p:1,borderRadius:1},"data-section-id":`split-group-${x}`,"data-canvas-type":a,children:b.map((l,o)=>e.jsxs(t.Fragment,{children:[A.id===l.id&&"left"===A.type&&A.canvasType===a&&g(`drop-left-${l.id}-${a}`,!0),e.jsx(d.Box,{sx:{width:l.splitWidth?`${l.splitWidth}%`:100/b.length+"%",transition:"width 0.3s ease-in-out"},"data-section-id":l.id,"data-canvas-type":a,children:e.jsx(jt,{section:l,isSelected:i===l.id,isDragging:r===l.id,isOver:A.id===l.id&&"inside"===A.type&&A.canvasType===a,onSelect:()=>s(l.id),onUpdate:(e,t)=>{u(l.id,{content:e,...t},a),s(null)},onSplit:(e,t)=>m(l.id,e,t,a),onDelete:()=>p(l.id,a),placeholders:_,setIsSectionEditing:z})}),A.id===l.id&&"right"===A.type&&A.canvasType===a&&g(`drop-right-${l.id}-${a}`,!0)]},l.id))},`split-row-${x}`);n.push(l),h+=b.length}else h++}else n.push(e.jsx(d.Box,{"data-section-id":o.id,"data-canvas-type":a,children:e.jsx(jt,{section:o,isSelected:i===o.id,isDragging:r===o.id,isOver:A.id===o.id&&"inside"===A.type&&A.canvasType===a,onSelect:()=>s(o.id),onUpdate:(e,t)=>{u(o.id,{content:e,...t},a),s(null)},onSplit:(e,t)=>m(o.id,e,t,a),onDelete:()=>p(o.id,a),placeholders:_,setIsSectionEditing:z})},o.id)),h++;A.id===x&&"after"===A.type&&A.canvasType===a&&n.push(g(`drop-after-${x}-${a}`))}return(0===(null==l?void 0:l.length)&&r&&A.canvasType===a||0===(null==l?void 0:l.length)&&$&&A.canvasType===a)&&n.push(g(`drop-empty-canvas-${a}`)),n},[$,A,r,i,s,u,m,p,_]),Z=t.useMemo(()=>Y(l,Zt),[l,A,r,$,i]),Q=t.useMemo(()=>Y(a,Yt),[a,A,r,$,i,j]),ee=t.useMemo(()=>Y(n,Xt),[n,A,r,$,i,j]),te=(t,l,i,c,u,m=!0)=>{var p;return m?e.jsxs(d.Box,{sx:{mb:3},children:[Zt===l&&m&&a.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(o.Typography,{type:"h4",weight:"bold",color:"theme.secondary.800",children:"Header"}),e.jsx(d.Paper,{sx:{mb:1,boxShadow:"none",opacity:.5},dangerouslySetInnerHTML:{__html:dt(a)}})]}),e.jsx(o.Typography,{type:"h4",weight:"bold",color:"theme.secondary.800",sx:{mb:1},children:t}),e.jsx(d.Paper,{ref:e=>{c(e),u.current=e},elevation:0,sx:{p:4,border:"1px dashed",borderColor:$&&A.canvasType===l?"primary.main":"primary.light",borderRadius:1,bgcolor:"background.paper",position:"relative",minHeight:"Header"===t||"Footer"===t?"100px":"200px",transition:"border-color 0.3s ease, background-color 0.3s ease","&:hover":{bgcolor:$&&A.canvasType===l?"rgba(25, 118, 210, 0.04)":"background.paper"},pointerEvents:l!==Yt&&l!==Xt||j?"auto":"none",opacity:l!==Yt&&l!==Xt||j?1:.5},onClick:()=>{(l!==Yt&&l!==Xt||j)&&s(null)},onMouseMove:e=>K(e,l),onMouseEnter:e=>J(e,l),children:e.jsxs(d.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:[i,0===(null==(p=G(l))?void 0:p.length)&&!r&&!$&&e.jsx(d.Box,{sx:{borderRadius:1,p:2,textAlign:"center",color:"text.secondary"},children:e.jsxs(o.Typography,{type:"s2",color:"theme.secondary.600",weight:"medium",children:["Drag Sections from side panel to start building the ",t.toLowerCase()]})})]})}),Zt===l&&m&&n.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(o.Typography,{type:"h4",weight:"bold",color:"theme.secondary.800",sx:{mt:1},children:"Footer"}),e.jsx(d.Paper,{sx:{mb:1,boxShadow:"none",opacity:.5},dangerouslySetInnerHTML:{__html:dt(n)}})]})]}):null};return e.jsxs(d.Box,{sx:{display:"flex",flex:1,overflow:"hidden"},children:[e.jsx(d.Box,{sx:{flex:1,overflow:"auto",height:"calc(100vh - 104px)"},children:e.jsx(d.Container,{maxWidth:!g&&"lg",sx:{py:g?0:4,height:g?"100%":void 0},children:g?e.jsxs(d.Box,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:[e.jsxs(d.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,bgcolor:"#1e1e1e",borderBottom:"1px solid #333",borderRadius:"4px 4px 0 0"},children:[e.jsx(o.Typography,{type:"s3",sx:{color:"#ccc",fontFamily:"monospace"},children:"HTML Source Editor — changes will replace current sections"}),e.jsxs(d.Box,{sx:{display:"flex",gap:1},children:[e.jsx(c.Button,{size:"small",variant:"contained",color:"primary",startIcon:e.jsx(X,{fontSize:"small"}),onClick:()=>x(R),sx:{boxShadow:"none"},children:"Apply"}),e.jsx(c.Button,{size:"small",variant:"outlined",startIcon:e.jsx(E,{fontSize:"small"}),onClick:()=>b(),sx:e=>({color:`${e.palette.theme.secondary[1e3]} !important`,borderColor:"#555 !important"}),children:"Cancel"})]})]}),e.jsx("textarea",{value:R,onChange:e=>N(e.target.value),spellCheck:!1,style:{flex:1,width:"100%",minHeight:"calc(100vh - 220px)",padding:"16px",fontFamily:'"Fira Code", "Cascadia Code", "Consolas", monospace',fontSize:"13px",lineHeight:"1.6",color:"#d4d4d4",backgroundColor:"#1e1e1e",border:"none",outline:"none",resize:"none",boxSizing:"border-box",borderRadius:"0 0 4px 4px",tabSize:2}})]}):h?e.jsx(d.Box,{sx:{transform:`scale(${w/100})`,transformOrigin:"top center",transition:"transform 0.2s ease-in-out",bgcolor:"white",p:2,borderRadius:1,boxShadow:1},children:e.jsx(d.Box,{dangerouslySetInnerHTML:{__html:st(l,a,n)}})}):e.jsxs(e.Fragment,{children:[te("Header",Yt,Q,T,H,j),te("Content",Zt,Z,k,W,!j),te("Footer",Xt,ee,I,V,j)]})})}),!g&&e.jsx(d.Box,{sx:{width:y?f?400:0:400,flexShrink:0,position:"sticky",top:0,alignSelf:"flex-start",height:"calc(100vh - 104px)",overflowY:"auto",borderLeft:"1px solid",borderColor:"divider",bgcolor:"background.paper",zIndex:1},children:!i||(null==B?void 0:B.is_edited_from_source)||P?y?f&&e.jsx(Jt,{}):e.jsx(Jt,{}):e.jsx(Vt,{section:B,onClose:()=>s(null),onUpdate:e=>{if(i){const t=a.some(e=>e.id===i)?Yt:n.some(e=>e.id===i)?Xt:Zt;u(i,e,t)}},placeholders:v,handleSave:S,relation_table:C})})]})},el=({isOpen:a,setIsOpen:n,modalProps:r,templateRoutes:i,payload:s,mode:u="add",templateData:p,onSaveSuccess:h,onSaveError:g,isSaving:x=!1})=>{console.log("is saving...........",x);const{handleSubmit:b,control:f,setValue:y}=m.useForm({mode:"all",resolver:c.o(ae.object().shape({template_name:ae.object().shape({name:ae.string().trim().required("Template name is required")})}))}),v=l.useNavigate(),[j,C]=t.useState(!1);console.log("isSubmitting............",j);const w=()=>{j||x||n(null)};return t.useEffect(()=>{p&&(null==p?void 0:p.name)&&y("template_name.name",null==p?void 0:p.name)},[y,p]),e.jsxs(c.Modal,{open:a,onClose:w,maxWidth:"xs",fullWidth:!0,...r,children:[e.jsxs(d.DialogTitle,{className:"companySelectionModal--DialogTitle",children:[e.jsx(o.Typography,{type:"s3",color:"inherit",weight:"medium",children:x?"Saving Template...":"Template Name"}),e.jsx(d.IconButton,{onClick:w,disabled:j||x,children:e.jsx(E,{fontSize:"small"})})]}),e.jsx(d.DialogContent,{className:"companySelectionModal--DialogContents",children:e.jsx("form",{onSubmit:b(async e=>{C(!0);try{const{name:t=""}=(null==e?void 0:e.template_name)||{};s.name=t,200===(await("edit"===u?Z.patchV1TemplatesId(s):Z.postV1Templates(s))).status_code&&(S.enqueueSnackbar("Template saved successfully",{variant:"success"}),null==h||h(),v(i.LIST)),C(!1)}catch(t){const e=(null==t?void 0:t.message)||"Something went wrong";C(!1),S.enqueueSnackbar(e,{variant:"error"}),null==g||g()}}),id:"template_name",children:e.jsx(c.DynamicInput,{label:"Name",name:"name",placeholder:"Enter Name",fieldArrayName:"template_name",formControl:f,required:!0})})}),e.jsx(d.DialogActions,{className:"companySelectionModal--DialogAction",children:e.jsxs(d.Box,{display:"flex",gap:1.5,children:[e.jsx(c.Button,{className:"companySelectionModal--DialogAction--WhiteBtn",onClick:w,disabled:j||x,children:"Cancel"}),e.jsx(c.Button,{type:"submit",form:"template_name",disabled:j||x,endIcon:(j||x)&&e.jsx(d.CircularProgress,{size:15}),children:x?"Saving...":"Save"})]})})]})},tl=({modulePath:a,module:o,type:n})=>{const{id:r,template_id:i}=l.useParams(),{state:s}=l.useLocation(),[c,u]=t.useState([]),[m,p]=t.useState([]),[h,g]=t.useState([]),[x,b]=t.useState(null),[f,y]=t.useState(!1),[v,j]=t.useState(!1),[C,_]=t.useState(null),[k,T]=t.useState(null),[I,E]=t.useState(!!(null==s?void 0:s.fromPreview)),[B,A]=t.useState(!1),[$,D]=t.useState([]),[P,z]=t.useState("main"),[R,N]=t.useState(!1),[O,q]=t.useState(null),[W,H]=t.useState(""),V=it(a,n),[G,U]=t.useState([]),[K,J]=t.useState(null),[Y,X]=t.useState(!1),[ee,te]=t.useState(null),[le,ae]=t.useState(100),[oe,ne]=t.useState({past:[],future:[]}),re=t.useMemo(()=>$,[JSON.stringify($)]),ie=t.useCallback(()=>{ne(e=>({past:[...e.past,{sections:[...c],headerSections:[...m],footerSections:[...h]}].slice(-50),future:[]}))},[c,m,h]),se=t.useCallback(()=>{if(0===oe.past.length)return;const e=oe.past[oe.past.length-1],t=oe.past.slice(0,-1);ne({past:t,future:[{sections:[...c],headerSections:[...m],footerSections:[...h]},...oe.future].slice(0,50)}),u(e.sections),p(e.headerSections),g(e.footerSections)},[oe,c,m,h]),de=t.useCallback(()=>{if(0===oe.future.length)return;const e=oe.future[0],t=oe.future.slice(1);ne({past:[...oe.past,{sections:[...c],headerSections:[...m],footerSections:[...h]}].slice(-50),future:t}),u(e.sections),p(e.headerSections),g(e.footerSections)},[oe,c,m,h]);t.useEffect(()=>{const e=e=>{!e.ctrlKey&&!e.metaKey||"z"!==e.key||e.shiftKey?((e.ctrlKey||e.metaKey)&&"y"===e.key||(e.ctrlKey||e.metaKey)&&e.shiftKey&&"z"===e.key)&&(e.preventDefault(),de()):(e.preventDefault(),se())};return window.addEventListener("keydown",e),()=>{window.removeEventListener("keydown",e)}},[se,de]);const ce=t.useCallback((e,t={})=>{let l="";const a=M.initialStyles[e]||{},o=mt(a),n="header"===P&&R?"header-":"footer"===P&&R?"footer-":"";switch(e){case"heading":l=`<h1 style="${o}">Heading 1</h1>`;break;case"heading-2":l=`<h2 style="${o}">Heading 2</h2>`;break;case"heading-3":l=`<h3 style="${o}">Heading 3</h3>`;break;case"heading-4":l=`<h4 style="${o}">Heading 4</h4>`;break;case"text":l=`<p style="${o}">Hello, enter your text here...</p>`;break;case"image":l=`<img src="${t.src}" alt="${t.alt}" style="${o};" />`;break;case"buttons":t.text=(null==t?void 0:t.text)||"Button text",l=`<button style="${o}">${t.text}</button>`;break;case"divider":l=`<hr style="${o}" />`;break;case"table":const e=a,{border:n,borderStyle:r,borderColor:i,...s}=e,d=mt(e.is_bordered?e:s),c=mt(e.tHead),u=mt(e.tBody),m=mt({...e.thCells,border:n,borderStyle:r,borderColor:i}),p=mt({...e.tbCells,border:n,borderStyle:r,borderColor:i});l=`\n <table style="${d}">\n <thead style="${c}">\n <tr style="background-color: #f5f5f5;">\n <th style="${m}"></th>\n <th style="${m}"></th>\n <th style="${m}"></th>\n </tr>\n </thead>\n <tbody style="${u}">\n <tr>\n <td style="${p}"></td>\n <td style="${p}"></td>\n <td style="${p}"></td>\n </tr>\n </tbody>\n </table>\n `;break;case"signature":l=`<div style="${o}">Signature: <input type='text' style="border:0; border-bottom:1px solid black" class='signature-input'/></div>`;break;case"qr-code":t.placeholder=(null==t?void 0:t.placeholder)||"{{qr_data}}",l=`<div style="background-color: #f5f5f5; padding: 16px; text-align: center; color: #666666;">${t.placeholder}</div>`;break;case"bar-code":t.placeholder=(null==t?void 0:t.placeholder)||"{{barcode_data}}",l=`<div style="background-color: #f5f5f5; padding: 16px; text-align: center; color: #666666;">${t.placeholder}</div>`;break;default:l='<p style="font-size: 16px; color: #333333; line-height: 1.5;">New section</p>'}return ct(l),{id:`${n}section-${Q.v4()}`,content:l,type:e,attributes:{...t||{},styles:a},is_edited_from_source:!1}},[P,R]),ue=t.useCallback(e=>{const{active:t}=e;b(t.id)},[]),me=t.useCallback(e=>{const{over:t}=e;t?("header-canvas"===t.id&&R?z("header"):"footer-canvas"===t.id&&R?z("footer"):"main-canvas"===t.id&&z("main"),"header-canvas"!==t.id&&"main-canvas"!==t.id&&"footer-canvas"!==t.id&&T(t.id)):T(null)},[R]),pe=t.useCallback(e=>{var t;const{active:l,over:a}=e;if(b(null),T(null),!a)return;let o=c,n=u;if(("header-canvas"===a.id||(null==k?void 0:k.startsWith("header-")))&&R?(o=m,n=p,z("header")):("footer-canvas"===a.id||(null==k?void 0:k.startsWith("footer-")))&&R?(o=h,n=g,z("footer")):z("main"),"image"===(null==(t=l.data.current)?void 0:t.type)){ie();const e=l.data.current.imageUrl,t=ce("image",{src:e,alt:"Image"}),r=o.findIndex(e=>e.id===a.id),i=[...o];return"header-canvas"===a.id||"main-canvas"===a.id||"footer-canvas"===a.id||-1===r?n([...o,t]):(i.splice(r,0,t),n(i)),void S.enqueueSnackbar("Added uploaded image section")}if("string"==typeof l.id&&l.id.startsWith("sidebar-")){ie();const e=l.id.replace("sidebar-",""),t=ce(e),r=o.findIndex(e=>e.id===a.id);if(-1!==r&&"header-canvas"!==a.id&&"main-canvas"!==a.id&&"footer-canvas"!==a.id){const l=o[r];if(!l.content||l.content.includes("Click to add")||l.content.includes("enter your text")){const a=[...o];a[r]={...l,type:e,content:t.content},n(a)}else{const e=[...o];e.splice(r,0,t),n(e)}}else n([...o,t]);return}if(l.id!==a.id&&"string"==typeof l.id&&"string"==typeof a.id){ie();let e=[],t=null;l.id.startsWith("header-")&&R?(e=m,t=p):l.id.startsWith("footer-")&&R?(e=h,t=g):(e=c,t=u);const r=l.id.replace(/^(header-|footer-)/,""),i=e.findIndex(e=>e.id===r||e.id===l.id);let s=o.findIndex(e=>e.id===String(a.id).replace(/^(header-|footer-)/,""));if("header-canvas"!==a.id&&"main-canvas"!==a.id&&"footer-canvas"!==a.id||(s=o.length),-1!==i&&-1!==s)if(e===o){const l=[...e],[a]=l.splice(i,1);if(a.isSplitPair&&a.splitGroupId){const o=a.splitGroupId,n=[a,...e.filter(e=>e.splitGroupId===o&&e.id!==a.id)],r=l.filter(e=>e.splitGroupId!==o);r.splice(s,0,...n),t(r)}else l.splice(s,0,a),t(l)}else{const l=e[i],r=[...e];r.splice(i,1),t(r);const d=[...o],c={...l};("header-canvas"===a.id||a.id.startsWith("header-"))&&R?c.id.startsWith("header-")||(c.id=`header-${c.id}`):("footer-canvas"===a.id||a.id.startsWith("footer-"))&&R?c.id.startsWith("footer-")||(c.id=`footer-${c.id}`):c.id=c.id.replace(/^(header-|footer-)/,""),d.splice(s,0,c),n(d)}}},[c,m,h,k,R,P,ce,ie]),he=t.useCallback(e=>"header"===e&&R?m:"footer"===e&&R?h:c,[c,m,h,R]),ge=t.useCallback(e=>"header"===e&&R?p:"footer"===e&&R?g:u,[R]),xe=t.useCallback((e,t,l)=>{const a=he(l),o=ge(l),n=e.replace(/^(header-|footer-)/,"");o(a.map(l=>l.id===n||l.id===e?{...l,...t}:l))},[he,ge]),be=ft(xe,300),fe=t.useCallback((e,t,l)=>{void 0!==t.content&&1===Object.keys(t).length?be(e,t,l):xe(e,t,l)},[xe,be]),ye=t.useCallback((e,t,l,a)=>{ie();const o=he(a),n=ge(a),r=e.replace(/^(header-|footer-)/,""),i=o.findIndex(t=>t.id===r||t.id===e);if(-1===i)return;const s=o[i],d=[...o],c="header"===a?"header-":"footer"===a?"footer-":"";if(s.isSplitPair&&s.splitGroupId){const e=s.splitGroupId,a=100/(d.filter(t=>t.splitGroupId===e).length+1);d[i]={...s,content:t,splitWidth:a};const o={id:`${c}section-${Q.v4()}`,content:l,type:s.type,isSplitPair:!0,splitGroupId:e,splitWidth:a,attributes:s.attributes,is_edited_from_source:!1};d.splice(i+1,0,o);for(let t=0;t<d.length;t++)d[t].splitGroupId===e&&(d[t].splitWidth=a)}else{const e=Q.v4(),a=50;d[i]={...s,content:t,isSplitPair:!0,splitGroupId:e,splitWidth:a};const o={id:`${c}section-${Q.v4()}`,content:l,type:s.type,isSplitPair:!0,splitGroupId:e,splitWidth:a,attributes:s.attributes,is_edited_from_source:!1};d.splice(i+1,0,o)}n(d)},[he,ge,P,R,ie]),ve=t.useCallback((e,t)=>{ie();const l=he(t),a=ge(t),o=e.replace(/^(header-|footer-)/,""),n=l.find(t=>t.id===o||t.id===e);if(n){if(n.isSplitPair&&n.splitGroupId){const t=l.filter(e=>e.splitGroupId===n.splitGroupId);if(t.length<=2){const n=t.find(t=>t.id!==o&&t.id!==e);n&&(n.isSplitPair=!1,n.splitGroupId=void 0,n.splitWidth=void 0),a(l.filter(t=>t.id!==o&&t.id!==e))}else{const r=100/t.filter(t=>t.id!==o&&t.id!==e).length;a(l.filter(t=>t.id!==o&&t.id!==e).map(e=>e.splitGroupId===n.splitGroupId?{...e,splitWidth:r}:e))}}else a(l.filter(t=>t.id!==o&&t.id!==e));C===e&&_(null)}},[he,ge,C,ie]);t.useEffect(()=>{var e;(null==s?void 0:s.fromPreview)&&(y(!(null==s?void 0:s.isViewOnly)),j(!0)),document.body.style.overflow="hidden";const t=null==(e=document.getElementsByTagName("main"))?void 0:e[0];return t&&(t.style.marginTop="4.125rem"),()=>{document.body.removeAttribute("style")}},[]),t.useEffect(()=>{(async()=>{var e,t,l,a;if(r){const l=w.getToken(),a=await Z.getV1SubjectsId({...l,"x-timezone":(null==(e=l["x-timezone"])?void 0:e.toString())||"",id:r});if("data"in a&&a.data&&"object"==typeof a.data&&"resource"in a.data){const e=a.data.resource,l=w.getToken(),o=await Z.getV1FormBuilderRelationalSchemaFieldsName({...l,"x-timezone":(null==(t=l["x-timezone"])?void 0:t.toString())||"",name:e}),n="data"in o&&o.data&&"object"==typeof o.data&&"fields"in o.data&&o.data.fields||[],r="data"in o&&o.data&&"object"==typeof o.data&&"relational_fields"in o.data&&o.data.relational_fields||[],i=n.map(e=>({...e,key:e.key.replace("__replaceKey","")})).filter(e=>{var t;return!e.is_inner_join&&"id"!==e.alias&&!(null==(t=null==e?void 0:e.alias)?void 0:t.includes("_id"))}),s=[],d=[];r.forEach(e=>{if(!e)return;const t=(e.fields||[]).map(t=>{const l={...t,key:t.key.replace("__replaceKey",""),alias:(null==t?void 0:t.templateKey)?null==t?void 0:t.templateKey:t.alias};return"object"===e.type&&e.dataKey&&(l.key=`${e.dataKey}.${l.key}`),l}).filter(e=>!e.is_inner_join&&"id"!==e.alias&&!e.alias.includes("_id")),l=L.differenceWith(t,t,(e,t)=>e.key===(null==t?void 0:t.joinKey)).map(t=>({label:w.formatText(t.alias.replace(/_data$/,"").replace(/_/g," ")),value:"object"===e.type&&e.dataKey?`${e.dataKey}.${t.alias.replace(/ /g,"_").toLowerCase()}`:t.alias.replace(/ /g,"_").toLowerCase()}));"object"===e.type?d.push(...l):s.push({...e,fields:l})});const c=[...i.map(e=>{const t=(null==e?void 0:e.alias)||(null==e?void 0:e.key),l=w.formatText(t.replace(/_data$/,"").replace(/_/g," "));return{label:l,value:l.replace(/ /g,"_").toLowerCase()}}),...d],u=L.uniqBy(c,"value");D(u),U(s)}}if(i){const e=w.getToken(),t=await Z.getV1TemplatesId({...e,"x-timezone":(null==(l=e["x-timezone"])?void 0:l.toString())||"",id:i}),a=("data"in t&&t.data&&"object"==typeof t.data&&"sections"in t.data&&t.data.sections||[]).map(e=>{var t;return{...e,id:e.id||`section-${Q.v4()}`,attributes:{...e.attributes,styles:(null==(t=e.attributes)?void 0:t.styles)||M.initialStyles[e.type]||{}}}});J("data"in t&&t.data?t.data:null),u(a)}if(null==s?void 0:s.company_id){const e=w.getToken(),t=await Z.getV1TemplateHeaderFooterCompanyIdHeaderFooter({...e,"x-timezone":(null==(a=e["x-timezone"])?void 0:a.toString())||"",company_id:s.company_id}),l="data"in t&&t.data&&"object"==typeof t.data?t.data:null;H((null==l?void 0:l._id)||"");const o=(null==l?void 0:l.header_sections)||[],n=(null==l?void 0:l.footer_sections)||[],r=o.map(e=>{var t;return{...e,id:e.id||`header-section-${Q.v4()}`,attributes:{...e.attributes,styles:(null==(t=e.attributes)?void 0:t.styles)||M.initialStyles[e.type]||{}}}}),i=n.map(e=>{var t;return{...e,id:e.id||`footer-section-${Q.v4()}`,attributes:{...e.attributes,styles:(null==(t=e.attributes)?void 0:t.styles)||M.initialStyles[e.type]||{}}}});p(r),g(i)}})()},[i,r,null==s?void 0:s.company_id]);const je=t.useCallback(e=>{ie();const t={id:`section-${Q.v4()}`,content:e,type:"text",is_edited_from_source:!0};u([t]),A(!1)},[ie]),Se=t.useCallback(()=>{A(!1)},[]),Ce=t.useCallback(async()=>{if(0===c.length&&0===m.length&&0===h.length)return void S.enqueueSnackbar("Please add at least one section");te({sections:[...c],headerSections:[...m],footerSections:[...h]});const e=st(c,m,h,!0);try{const t={...w.getToken(),...i?{id:i}:{subject_id:r,is_default:!1,company_id:s.company_id},sections:c.map(e=>({...e,attributes:e.attributes})),contents:e};q(t)}catch(t){const e=w.getErrorMessage(null==t?void 0:t.message);S.enqueueSnackbar(e,{variant:"error"}),te(null)}},[c,m,h,i,r,s]),we=t.useCallback(async()=>{var e,t;if(0===c.length&&0===m.length&&0===h.length)return void S.enqueueSnackbar("Please add at least one section",{variant:"error"});if(!(null==s?void 0:s.company_id))return void S.enqueueSnackbar("Company has not been selected",{variant:"error"});te({sections:[...c],headerSections:[...m],footerSections:[...h]}),X(!0);const l=`${dt(m,"header")}${dt(h,"footer")}`,a=e=>({id:e.id,content:e.content,type:e.type,isSplitPair:e.isSplitPair,splitGroupId:e.splitGroupId,splitWidth:void 0!==e.splitWidth?String(e.splitWidth):void 0,attributes:e.attributes}),o=m.map(a),n=h.map(a);try{if(W){const t=w.getToken();200===(await Z.patchV1TemplateHeaderFooterId({...t,"x-timezone":(null==(e=t["x-timezone"])?void 0:e.toString())||"",id:W,header_sections:o,footer_sections:n,contents:l})).status_code&&(S.enqueueSnackbar("Header/Footer saved successfully",{variant:"success"}),N(!1),te(null))}else{const e=w.getToken();200===(await Z.postV1TemplateHeaderFooter({...e,"x-timezone":(null==(t=e["x-timezone"])?void 0:t.toString())||"",header_sections:o,footer_sections:n,contents:l,company_id:s.company_id})).status_code&&(S.enqueueSnackbar("Header/Footer saved successfully",{variant:"success"}),N(!1),te(null))}}catch(r){const e=w.getErrorMessage(null==r?void 0:r.message);S.enqueueSnackbar(e,{variant:"error"}),ee&&(u(ee.sections),p(ee.headerSections),g(ee.footerSections),S.enqueueSnackbar("Changes reverted due to save error",{variant:"warning"}))}finally{X(!1),te(null)}},[c,m,h,W,s,ee]),_e=t.useCallback(()=>{N(!R),R&&z("main")},[R]),ke=t.useCallback(()=>{te(null),q(null)},[]),Te=t.useCallback(()=>{ee&&(u(ee.sections),p(ee.headerSections),g(ee.footerSections),S.enqueueSnackbar("Changes reverted due to save error",{variant:"warning"})),te(null),q(null)},[ee]);return e.jsxs(d.Box,{sx:{display:"flex",flexDirection:"column",height:"100vh"},children:[e.jsx(ht,{fromPreview:v,onPreview:()=>E(!I),onSave:Ce,onEditModeChange:()=>{y(!f),E(!!f)},zoom:le,onZoomIn:()=>{ae(e=>Math.min(e+10,150))},onZoomOut:()=>{ae(e=>Math.max(e-10,50))},onResetZoom:()=>{ae(100)},editMode:f,preview:I,editHtml:B,onEditHtml:()=>A(!B),sections:c,isEditingHeaderFooter:R,setIsEditingHeaderFooter:_e,onSaveHeaderFooter:we,modulePath:a,type:n,mode:i?"edit":"add",templateData:K,isSaving:Y}),e.jsx(d.Box,{sx:{display:"flex",flex:1,overflow:"hidden"},children:e.jsx(F.DndContext,{onDragStart:ue,onDragOver:me,onDragEnd:pe,collisionDetection:F.pointerWithin,children:e.jsx(Qt,{sections:c,headerSections:m,footerSections:h,activeId:x,overSection:k,selectedSection:C,onSelectSection:_,onUpdateSection:fe,onSplitSection:ye,onDeleteSection:ve,preview:I,editHtml:B,onApplyHtmlEdit:je,onCancelHtmlEdit:Se,zoom:le,editMode:f,isFromPreview:v,handleSave:Ce,placeholders:re,isEditingHeaderFooter:R,relation_table:G})})}),null!==O&&e.jsx(el,{isOpen:null!==O,setIsOpen:()=>q(null),payload:O,templateRoutes:V,mode:i?"edit":"add",templateData:K,onSaveSuccess:ke,onSaveError:Te,isSaving:Y})]})},ll=({modulePath:t,module:l,type:a})=>e.jsx(d.Box,{sx:{minHeight:"100vh",bgcolor:"grey.50"},children:e.jsx(tl,{modulePath:t,module:l,type:a})}),al=({template:l,width:a=300,height:n=200,scale:r=.25,showControls:i=!1,onClick:s=null,selectedTemplateId:c="",isFetching:u=!1,onDelete:m,minScale:p=.1,maxScale:h=1,scaleStep:g=1.2,loadingDelay:x=500,refreshDelay:b=300,normalView:y=!1})=>{const[v,j]=t.useState(u||!0),[S,C]=t.useState(r),[w,_]=t.useState(null),[k,I]=t.useState(!1),E=t.useRef(null),B=t.useRef(null),A=t.useRef(null),M=t.useRef(null),F=a/S,$=n/S;t.useEffect(()=>()=>{A.current&&clearTimeout(A.current),M.current&&clearTimeout(M.current)},[]),t.useEffect(()=>(A.current&&clearTimeout(A.current),A.current=setTimeout(()=>{j(!1)},x),()=>{A.current&&clearTimeout(A.current)}),[l.contents,x]),t.useEffect(()=>{j(u)},[u]);const D=t.useCallback(()=>{C(e=>Math.min(e*g,h))},[g,h]),P=t.useCallback(()=>{C(e=>Math.max(e/g,p))},[g,p]),z=t.useCallback(()=>{j(!0),_(null),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{j(!1)},b)},[b]),R=t.useCallback(()=>{s&&!v&&s(l)},[s,l,v]),N=t.useCallback(e=>{e.stopPropagation(),m&&!(null==l?void 0:l.is_default)&&m(l)},[m,l]),L=t.useCallback(()=>{I(!0)},[]),O=t.useCallback(()=>{I(!1)},[]);if(v)return e.jsx(d.Box,{sx:{width:a,height:n,borderRadius:1,overflow:"hidden",border:"1px solid",borderColor:"divider"},children:e.jsx(d.Skeleton,{variant:"rectangular",width:"100%",height:"100%",animation:"wave"})});if(w)return e.jsx(d.Box,{sx:{width:a,height:n,borderRadius:1,overflow:"hidden",border:"1px solid",borderColor:"error.main",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"error.light",color:"error.contrastText"},children:"Failed to load template"});const q=c===l._id,W=S<h,H=S>p,V=!(null==l?void 0:l.is_default);return e.jsxs(d.Box,{sx:{position:"relative",display:"inline-block"},onMouseEnter:L,onMouseLeave:O,children:[e.jsxs(d.Box,{ref:E,onClick:R,sx:e=>({width:a,height:n,border:"1px solid",borderRadius:1,overflow:"hidden",position:"relative",cursor:s?"pointer":"default",backgroundColor:"#fff",transition:"all 0.2s ease-in-out","&:hover":s?{boxShadow:"0 4px 16px rgba(0,0,0,0.15)",transform:"translateY(-1px)"}:{},borderColor:y&&q?e.palette.theme.primary[800]:"grey.300",borderWidth:q?2:1}),children:[e.jsx(d.Box,{sx:{width:F,height:$,transform:`scale(${S})`,transformOrigin:"top left",position:"absolute",top:0,left:0,overflow:"hidden"},children:e.jsx(d.Box,{ref:B,sx:{width:"100%",height:"100%",userSelect:"none",pointerEvents:"none",pt:2,"& *":{maxWidth:"100% !important",boxSizing:"border-box !important"},"& body":{margin:"0 !important",padding:"0 !important",overflow:"hidden !important"},"& img":{maxWidth:"100% !important",height:"auto !important"},"& table":{width:"100% !important",tableLayout:"fixed !important"},'& *[style*="position: absolute"]':{position:"relative !important"},"& .email-container":{width:"85% !important"}},dangerouslySetInnerHTML:{__html:l.contents}})}),v&&e.jsx(d.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(255,255,255,0.8)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:2},children:e.jsx(d.Skeleton,{variant:"rectangular",width:"90%",height:"90%"})}),(null==l?void 0:l.is_default)&&e.jsx(d.Box,{sx:e=>{var t;return{position:"absolute",top:8,left:8,width:12,height:12,borderRadius:"50%",backgroundColor:null==(t=e.palette.theme)?void 0:t.primary[800],zIndex:3}}})]}),(null==l?void 0:l.name)&&e.jsx(o.Typography,{type:"s3",weight:"medium",color:"theme.secondary.1000",align:"center",sx:{width:a,mt:.5},children:null==l?void 0:l.name}),i&&e.jsx(d.Fade,{in:k,timeout:200,children:e.jsxs(d.Box,{sx:{position:"absolute",top:-8,right:-8,display:"flex",gap:.5,zIndex:4,backgroundColor:"rgba(255,255,255,0.95)",border:"1px solid",borderColor:"grey.300",borderRadius:2,padding:.5,boxShadow:"0 4px 12px rgba(0,0,0,0.15)",backdropFilter:"blur(4px)"},children:[e.jsx(d.Tooltip,{title:`Zoom In (${Math.round(100*S)}%)`,arrow:!0,children:e.jsx("span",{children:e.jsx(d.IconButton,{size:"small",onClick:D,disabled:!W,sx:{backgroundColor:"transparent","&:hover":{backgroundColor:"primary.light",color:"primary.contrastText"},"&:disabled":{opacity:.5}},children:e.jsx(f.ZoomIn,{fontSize:"small"})})})}),e.jsx(d.Divider,{orientation:"vertical",variant:"middle",flexItem:!0}),e.jsx(d.Tooltip,{title:`Zoom Out (${Math.round(100*S)}%)`,arrow:!0,children:e.jsx("span",{children:e.jsx(d.IconButton,{size:"small",onClick:P,disabled:!H,sx:{backgroundColor:"transparent","&:hover":{backgroundColor:"primary.light",color:"primary.contrastText"},"&:disabled":{opacity:.5}},children:e.jsx(f.ZoomOut,{fontSize:"small"})})})}),e.jsx(d.Divider,{orientation:"vertical",variant:"middle",flexItem:!0}),e.jsx(d.Tooltip,{title:"Refresh Preview",arrow:!0,children:e.jsx(d.IconButton,{size:"small",onClick:z,sx:{backgroundColor:"transparent","&:hover":{backgroundColor:"primary.light",color:"primary.contrastText"}},children:e.jsx(f.Refresh,{fontSize:"small"})})}),m&&e.jsxs(e.Fragment,{children:[e.jsx(d.Divider,{orientation:"vertical",variant:"middle",flexItem:!0}),e.jsx(d.Tooltip,{title:V?"Delete Template":"Cannot delete default template",arrow:!0,children:e.jsx("span",{children:e.jsx(d.IconButton,{size:"small",onClick:N,disabled:!V,sx:{backgroundColor:"transparent","&:hover":V?{backgroundColor:"error.light",color:"error.contrastText"}:{},"&:disabled":{opacity:.5}},children:e.jsx(T.Trash,{fontSize:"small"})})})})]})]})})]})},ol=({template:l,width:a="100%",height:n=800,scale:r=.25,showControls:i=!1,onClick:s=null,selectedTemplateId:c="",isFetching:u=!1,onDelete:m,normalView:p=!1,minScale:h=.1,maxScale:g=1,scaleStep:x=1.2,loadingDelay:b=500,refreshDelay:y=300})=>{const[v,j]=t.useState(u||!0),[S,C]=t.useState(r),[w,_]=t.useState(null),[k,I]=t.useState(!1),E=t.useRef(null),B=t.useRef(null),A=t.useRef(null),M=t.useRef(null),[F,$]=t.useState("number"==typeof a?a:800);t.useEffect(()=>{const e=()=>{if(E.current){const e=E.current.offsetWidth;$(e)}};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),t.useEffect(()=>()=>{clearTimeout(A.current),clearTimeout(M.current)},[]),t.useEffect(()=>(clearTimeout(A.current),A.current=setTimeout(()=>j(!1),b),()=>clearTimeout(A.current)),[l.contents,b]),t.useEffect(()=>j(u),[u]);const D=t.useCallback(()=>C(e=>Math.min(e*x,g)),[x,g]),P=t.useCallback(()=>C(e=>Math.max(e/x,h)),[x,h]),z=t.useCallback(()=>{j(!0),_(null),clearTimeout(M.current),M.current=setTimeout(()=>j(!1),y)},[y]),R=t.useCallback(()=>{s&&!v&&s(l)},[s,l,v]),N=t.useCallback(e=>{e.stopPropagation(),m&&!(null==l?void 0:l.is_default)&&m(l)},[m,l]),L=t.useCallback(()=>I(!0),[]),O=t.useCallback(()=>I(!1),[]);if(v)return e.jsx(d.Box,{sx:{width:a,height:n,borderRadius:1,overflow:"hidden",border:"1px solid",borderColor:"divider"},children:e.jsx(d.Skeleton,{variant:"rectangular",width:"100%",height:"100%",animation:"wave"})});if(w)return e.jsx(d.Box,{sx:{width:a,height:n,borderRadius:1,overflow:"hidden",border:"1px solid",borderColor:"error.main",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"error.light",color:"error.contrastText"},children:"Failed to load template"});const q=S<g,W=S>h,H=!(null==l?void 0:l.is_default);return e.jsxs(d.Box,{ref:E,sx:{position:"relative",width:a,marginInline:"auto",display:"inline-block"},onMouseEnter:L,onMouseLeave:O,children:[e.jsxs(d.Box,{onClick:R,sx:e=>({width:"100%",height:n,marginBlock:0,overflow:"hidden",position:"relative",backgroundColor:"#fff",transition:"all 0.2s ease-in-out","&:hover":s?{boxShadow:"0 4px 16px rgba(0,0,0,0.15)",transform:"translateY(-1px)"}:{}}),children:[e.jsx(d.Box,{sx:{width:"100%",height:"100%",display:"flex",justifyContent:"center",alignItems:"center",overflow:"auto",backgroundColor:"#fff"},children:e.jsx(d.Box,{sx:{transform:`scale(${S})`,transformOrigin:"top left",pointerEvents:"none",userSelect:"none",width:F,height:n},children:e.jsx(d.Box,{ref:B,sx:{width:"100%",height:"100%","& *":{maxWidth:"100% !important",boxSizing:"border-box !important"},"& body":{margin:0,padding:0,overflow:"hidden"},"& img":{maxWidth:"100% !important",height:"auto !important"},"& table":{width:"100% !important",tableLayout:"fixed !important"},'& *[style*="position: absolute"]':{position:"relative !important"},"& .email-container":{width:"85% !important"}},dangerouslySetInnerHTML:{__html:l.contents}})})}),(null==l?void 0:l.is_default)&&e.jsx(d.Box,{sx:e=>({position:"absolute",top:8,left:8,width:12,height:12,borderRadius:"50%",backgroundColor:e.palette.theme.primary[800],zIndex:3})})]}),(null==l?void 0:l.name)&&e.jsx(o.Typography,{type:"s3",weight:"medium",color:"theme.secondary.1000",align:"center",sx:{width:a,mt:.5},children:null==l?void 0:l.name}),i&&e.jsx(d.Fade,{in:k,timeout:200,children:e.jsxs(d.Box,{sx:{position:"absolute",top:-8,right:-8,display:"flex",gap:.5,zIndex:4,backgroundColor:"rgba(255,255,255,0.95)",border:"1px solid",borderColor:"grey.300",borderRadius:2,padding:.5,boxShadow:"0 4px 12px rgba(0,0,0,0.15)",backdropFilter:"blur(4px)"},children:[e.jsx(d.Tooltip,{title:`Zoom In (${Math.round(100*S)}%)`,arrow:!0,children:e.jsx("span",{children:e.jsx(d.IconButton,{size:"small",onClick:D,disabled:!q,children:e.jsx(f.ZoomIn,{fontSize:"small"})})})}),e.jsx(d.Divider,{orientation:"vertical",flexItem:!0}),e.jsx(d.Tooltip,{title:`Zoom Out (${Math.round(100*S)}%)`,arrow:!0,children:e.jsx("span",{children:e.jsx(d.IconButton,{size:"small",onClick:P,disabled:!W,children:e.jsx(f.ZoomOut,{fontSize:"small"})})})}),e.jsx(d.Divider,{orientation:"vertical",flexItem:!0}),e.jsx(d.Tooltip,{title:"Refresh Preview",arrow:!0,children:e.jsx(d.IconButton,{size:"small",onClick:z,children:e.jsx(f.Refresh,{fontSize:"small"})})}),m&&e.jsxs(e.Fragment,{children:[e.jsx(d.Divider,{orientation:"vertical",flexItem:!0}),e.jsx(d.Tooltip,{title:H?"Delete Template":"Cannot delete default template",arrow:!0,children:e.jsx("span",{children:e.jsx(d.IconButton,{size:"small",onClick:N,disabled:!H,children:e.jsx(T.Trash,{fontSize:"small"})})})})]})]})})]})},nl=({email:a,onClose:n,open:r,companies:i=[],templateRoutes:s,source:u="add"})=>{var m;const[p,h]=t.useState([]),[g,x]=t.useState(""),[b,f]=t.useState(""),[y,v]=t.useState(!0),[j,C]=t.useState((null==(m=null==i?void 0:i[0])?void 0:m.id)||0),[_,k]=t.useState(null),[T,I]=t.useState(null),B=l.useNavigate(),A=()=>{n()},M=async()=>{var e;v(!0);const t=await Z.getV1Templates({...w.getToken(),filters:`(company_id.eq=${j}&subject_id.eq=${a._id})`});if(null==t?void 0:t.data){const l=null==(e=null==t?void 0:t.data)?void 0:e.find(e=>!0===e.is_default);f(l),x(null==l?void 0:l._id),h(null==t?void 0:t.data)}v(!1)};return t.useEffect(()=>(M(),()=>{v(!0)}),[j]),e.jsxs("div",{children:[e.jsxs(c.Modal,{open:r,onClose:A,maxWidth:"lg",fullWidth:!0,"aria-labelledby":"email-template-selection",sx:{"& .MuiDialog-paper":{height:"85vh",display:"flex",flexDirection:"column"}},children:[console.log(u,"soure in modal +++++++++++++++++++++++debug"),e.jsxs(d.DialogTitle,{sx:{marginBottom:"1rem",padding:"0.75rem 1rem 0.75rem 1.5rem",borderBottom:"1px solid #D3D3D4"},children:[e.jsxs(d.Box,{display:"flex",alignItems:"center",gap:2,children:[T&&e.jsx(d.IconButton,{onClick:()=>I(null),size:"small",sx:{color:e=>e.palette.grey[700]},children:e.jsx(o.Typography,{children:"← Back"})}),e.jsx(o.Typography,{type:"s1",weight:"medium",color:"theme.secondary.1000",sx:{flex:1,textAlign:"center"},children:T||"view"===u?"Template Preview":"Select Template"})]}),e.jsxs(d.Box,{display:"flex",alignItems:"center",gap:1,position:"absolute",right:"1%",top:"4px",children:[e.jsx(o.Typography,{type:"s3",weight:"medium",color:"theme.secondary.800",children:" Company"}),e.jsx(c.Select,{displayEmpty:!0,value:j,size:"small",renderValue:e=>{var t;return e?null==(t=i.find(t=>t.value===e))?void 0:t.label:"Select Company"},onChange:e=>{e.target.value&&C(e.target.value)},children:i.map(t=>e.jsx(d.MenuItem,{value:t.value,children:e.jsx(o.Typography,{type:"s3",color:"theme.secondary.1000",children:t.label})},t.value))}),e.jsx(d.IconButton,{"aria-label":"close",onClick:A,size:"small",sx:{color:e=>e.palette.grey[500]},children:e.jsx(E,{fontSize:"small"})})]})]}),T?e.jsx(d.DialogContent,{sx:{display:"flex",flexDirection:"column",gap:3,width:"100%",p:3,flex:1,overflow:"auto",scrollbarWidth:"none",msOverflowStyle:"none","&::-webkit-scrollbar":{display:"none"}},children:e.jsx(d.Box,{sx:{width:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(ol,{template:T,width:"100%",height:600,scale:1,showControls:!0,isFetching:y,normalView:!0})})}):e.jsxs(d.DialogContent,{sx:{flex:1,overflow:"auto",display:"flex",flexDirection:"column",scrollbarWidth:"none",msOverflowStyle:"none","&::-webkit-scrollbar":{display:"none"}},children:[!p.length&&e.jsx(d.Box,{display:"flex",alignItems:"center",width:"100%",height:"100%",justifyContent:"center",children:!y&&e.jsx(o.Typography,{type:"s1",weight:"medium",color:"theme.secondary.1000",sx:{textAlign:"center"},children:"No templates found"})}),e.jsx(d.Box,{sx:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(300px, 1fr))",gap:2,p:2,justifyItems:"center",alignItems:"center"},children:p.map((t,l)=>e.jsx(al,{template:t,width:300,height:200,showControls:"add"===u,selectedTemplateId:g,onClick:e=>{(e=>{if("view"===u){const t=p.find(t=>(null==t?void 0:t._id)===e);I(t),x(e),B(s.EDIT_TEMPLATE(a._id,g),{state:{company_id:j,isViewOnly:!0,fromPreview:!0}})}else x(e)})(e._id)},normalView:"add"===u,isFetching:y,onDelete:e=>k(e)},t._id||l))})]}),"add"===u&&e.jsxs(d.DialogActions,{sx:{p:2,justifyContent:"center",borderTop:"1px solid #D3D3D4"},children:[e.jsx(c.Button,{onClick:()=>B(s.EDIT_TEMPLATE(a._id,g),{state:{company_id:j}}),disabled:!g,children:"Continue"}),e.jsx(c.Button,{onClick:()=>(async()=>{try{await Z.patchV1TemplatesIdSetDefault({...w.getToken(),id:g}),S.enqueueSnackbar("Template has been set as default")}catch(e){const t=w.getErrorMessage(null==e?void 0:e.message);S.enqueueSnackbar(t,{variant:"error"})}})(),disabled:!g||(null==b?void 0:b._id)===g,children:"Set to Default"})]})]}),e.jsx(c.ConfirmPopUp,{open:null!==_,onClose:()=>k(null),title:"Remove Template",description:"Are you sure you want to delete ?",onConfirm:()=>(async()=>{try{_&&(await Z.deleteV1TemplatesId({...w.getToken(),id:null==_?void 0:_._id}),S.enqueueSnackbar("Template has been deleted"),k(null),await M())}catch(e){const t=w.getErrorMessage(null==e?void 0:e.message);S.enqueueSnackbar(t,{variant:"error"})}})(),loading:y})]})},rl=({isOpen:a,setIsOpen:n,modalProps:r,companies:i,email:s,templateRoutes:u})=>{const m=l.useNavigate(),[p,h]=t.useState(0),g=()=>{n(null)};return e.jsxs(c.Modal,{open:a,onClose:g,maxWidth:"xs",fullWidth:!0,...r,children:[e.jsxs(d.DialogTitle,{className:"companySelectionModal--DialogTitle",children:[e.jsx(o.Typography,{type:"s3",color:"inherit",weight:"medium",children:"Select Company"}),e.jsx(d.IconButton,{onClick:g,children:e.jsx(E,{fontSize:"small"})})]}),e.jsx(d.DialogContent,{className:"companySelectionModal--DialogContents",children:e.jsx(c.Select,{displayEmpty:!0,value:p,size:"small",renderValue:e=>{var t;return e?null==(t=i.find(t=>t.value===e))?void 0:t.label:"Select Company"},fullWidth:!0,sx:{bgcolor:"white",borderRadius:1,"& .MuiSelect-select":{py:.75}},onChange:e=>{e.target.value&&h(e.target.value)},children:i.map(t=>e.jsx(d.MenuItem,{value:t.value,children:e.jsx(o.Typography,{type:"s4",color:"theme.secondary.1000",children:t.label})},t.value))})}),e.jsx(d.DialogActions,{className:"companySelectionModal--DialogAction",children:e.jsxs(d.Box,{display:"flex",gap:1.5,children:[e.jsx(c.Button,{className:"companySelectionModal--DialogAction--WhiteBtn",onClick:g,children:"Cancel"}),e.jsx(c.Button,{onClick:()=>{p?s?m(u.ADD_TEMPLATE(s._id),{state:{company_id:p}}):S.enqueueSnackbar("Something went wrong for a subject",{variant:"error"}):S.enqueueSnackbar("Please select a company",{variant:"error"})},disabled:!p,children:"Continue"})]})})]})},il=({type:a,module:r,modulePath:i})=>{const{t:c}=j.useTranslation(),{activePage:m,updatePageInfo:p,schemaFields:h,generatedColumns:g,updateGeneratedColumns:x}=te.usePages(),b=te.useDeepMemo(m),[f,y]=t.useState(null),v=localStorage.getItem("email-subjects-view"),[C,_]=t.useState(v?JSON.parse(v):[{label:"Table",position:0}]),[k,T]=t.useState(ee.viewTypes.TABLE),[I,E]=t.useState({pageNo:1,limit:10,totalCount:0,skip:0}),[B,A]=t.useState([]),[M]=t.useState(!1),[F,$]=t.useState([]),[D,P]=t.useState(null),[z,R]=t.useState("add"),[N,L]=t.useState(null),[O,q]=t.useState([]),W=l.useNavigate(),{pageNo:H,limit:V,totalCount:G}=I,U=b.page_size||V,K=U?Math.ceil(G/U):0,J=U*(H-1),Y=te.usePermissions(),X=it(i,a),Q=(null==Y?void 0:Y.Subjects)||{},{canAdd:le=!1,canEdit:ae=!1}=Q,oe=[{label:"New Template",handleAction:e=>(e=>{var t,l;(null==O?void 0:O.length)?(null==O?void 0:O.length)>1?L(e):W(X.ADD_TEMPLATE(e._id),{state:{company_id:(null==(t=O[0])?void 0:t.id)||(null==(l=O[0])?void 0:l.value)}}):S.enqueueSnackbar("Please add a company first",{variant:"error"})})(e),disabled:e=>!ae},{label:"Add From Template",handleAction:e=>{R("add"),P(e)},disabled:e=>!le}],ne=t.useCallback(async()=>{const{sort:e,filterQueryString:t,search:l}=b,o=l?`&subject.like=${l}`:"",n=[];n.push(a),"email"==a&&n.push("approval_email");const i=w.appendConditionSafely(t,`&type.in=[${n.join(",")}]&module.eq=${r}${o}`),s=await Z.getV1Subjects({...w.getToken(),skip:J,limit:U,...e&&{order:`${e.id}:${e.desc?-1:1}`},...i&&"()"!==i&&{filters:i}});A((null==s?void 0:s.data)||[]),E({...I,...(null==s?void 0:s.pagination)||{}})},[U,J,null==b?void 0:b.search,null==b?void 0:b.filterQueryString,null==b?void 0:b.sort]),re=t.useMemo(()=>B||[],[B]),ie=t.useMemo(()=>s.transformTableColumns({columns:g.columns,currencySymbol:e=>{var t,l;return(null==(l=null==(t=e.original)?void 0:t.currency_data)?void 0:l.symbol)||w.defaultCurrencySymbol()},translationFn:c,enableFooter:!0,rows:re,statusClasses:""}),[re,c,g.columns]),se=()=>{E({pageNo:1,limit:10,totalCount:0})};return t.useEffect(()=>{ne()},[ne]),t.useEffect(()=>((async()=>{const e=await w.fetchApi({apiKey:"company",filters:{skip:0,limit:100,order:"id:1"}});q((null==e?void 0:e.data)||[])})(),se),[]),t.useEffect(()=>{(null==C?void 0:C.length)&&localStorage.setItem("email-subjects-view",JSON.stringify(C))},[C]),e.jsxs("section",{className:"templates",children:[e.jsx(n.ActionBar,{title:"email"===a?"Emails":"PDFs",data:C,setData:_,active:k,setActive:T,handleSearch:e=>{p({search:e}),E({...I,pageNo:1})},disabledViews:["Kanban","Calendar","Gantt",ee.viewTypes.GRID],fields:h,selectedIds:F,button:!1}),k===ee.viewTypes.TABLE&&e.jsx(n.MaterialTable,{rows:re||[],columns:ie,paginationModel:I,totalPages:K,columnOrder:["mrt-row-select",...g.orderKeys],states:{isLoading:M},onSortingChange:e=>p({sort:e}),enableColumnDragging:!1,enableEditing:!1,onSelectRow:e=>$(e.map(e=>e.original.id)),enableAddCustomField:!1,rowActionMenu:oe,isResetRow:!1,handleColumnOrdering:e=>x({orderKeys:e.slice(1)}),onColumnVisibility:e=>x({columns:e}),showPreview:!0,handlePreview:e=>{R("view"),P(e)}}),k===ee.viewTypes.GRID&&e.jsx(GridCard,{data:re,rowActionMenu:oe}),!k&&e.jsx(n.Fallback,{heading:c("rental.settings.termsAndConditions.title"),subHeading:"No data available",icon:e.jsx("img",{src:u.images.invoiceFallback})}),e.jsx(n.Footer,{total:K,paginationModel:{...I,limit:b.page_size},handlePaginationModel:e=>{b.page_size!=(null==e?void 0:e.limit)&&p({page_size:e.limit}),E(e)},resource:""}),e.jsxs(s.Menu,{anchorEl:f,open:Boolean(f),onClose:()=>y(null),children:[e.jsx(d.MenuItem,{children:e.jsx(o.Typography,{type:"s4",color:"theme.secondary.1000",children:c("common.upload")})}),e.jsx(d.MenuItem,{children:e.jsx(o.Typography,{type:"s4",color:"theme.secondary.1000",children:c("common.print")})})]}),D&&e.jsx(nl,{email:D,onClose:()=>P(null),open:null!==D,companies:O,templateRoutes:X,source:z}),N&&e.jsx(rl,{isOpen:null!==N,setIsOpen:L,companies:O,email:N,templateRoutes:X})]})};exports.AddTemplate=ll,exports.AlignmentControl=Ct,exports.BorderControl=Ft,exports.ButtonControls=Bt,exports.ChangePassword=()=>{const{control:n,handleSubmit:r}=m.useForm({resolver:c.o(we),mode:"all"}),[i,s]=t.useState(null),[p,x]=t.useState(!1),{changePassword:b}=o.useAuth(),f=l.useLocation(),y=l.useNavigate(),v=h.getApiConfig().appLogo||u.images.erp_logo;return e.jsxs(d.Box,{children:[e.jsxs(ve,{container:!0,children:[e.jsx(je,{item:!0,sm:6,children:e.jsx("img",{src:u.images.login.LoginLeftSiteImage})}),e.jsx(Se,{item:!0,sm:6,xs:12,children:e.jsxs(Ce,{display:"flex",flexDirection:"column",gap:4,sx:e=>({minWidth:400,[e.breakpoints.down("md")]:{minWidth:300},[e.breakpoints.down("sm")]:{minWidth:300}}),children:[e.jsx(d.Box,{textAlign:"center",children:e.jsx("img",{src:v,width:160,height:55})}),e.jsx("form",{onSubmit:r(async e=>{var t;const l=null==(t=f.state)?void 0:t.token;return l?(e.login.token=l,await b(e.login,()=>{s({message:"Password changed successfully",type:"normal"}),setTimeout(()=>{y(a.Pathname.LOGIN)},2e3)}),e):void s({message:"Token missing",type:"alert"})}),children:e.jsxs(Ce,{gap:4,children:[e.jsxs(Ce,{gap:3,children:[e.jsxs(d.Box,{children:[e.jsx(o.Typography,{align:"center",type:"h1",weight:"medium",color:"theme.secondary.1000",children:"Change Password"}),e.jsx(o.Typography,{align:"center",type:"h5",weight:"normal",color:"theme.secondary81000",children:"Enter Details below"})]}),e.jsxs(Ce,{gap:2,children:[e.jsx(d.Box,{children:e.jsx(c.DynamicInput,{formControl:n,label:"Password",name:"password",type:"password",placeholder:"Enter Password",fieldArrayName:"login"})}),e.jsx(d.Box,{children:e.jsx(c.DynamicInput,{formControl:n,label:"Confirm Password",name:"confirm_password",type:p?"text":"password",fieldArrayName:"login",endIcon:e.jsx(e.Fragment,{children:p?e.jsx(g.Eye,{fontSize:"small",htmlColor:"#292D32"}):e.jsx(g.EyeOff,{fontSize:"small",htmlColor:"#292D32"})}),onIconClick:()=>x(!p),placeholder:"Enter confirm password"})})]})]}),e.jsx(Ce,{gap:2,children:e.jsx(c.Button,{type:"submit",size:"large",variant:"contained",children:"Change Password"})})]})})]})})]}),e.jsx(c.Toast,{open:Boolean(i),message:null==i?void 0:i.message,type:null==i?void 0:i.type,handleClose:()=>s(null),anchorOrigin:{horizontal:"right",vertical:"bottom"},autoHideDuration:3e3})]})},exports.CheckboxEditForm=qe,exports.CodeControls=Wt,exports.ColumnWidth=({onChange:l})=>{const[a,o]=t.useState(6);return t.useEffect(()=>{l(a)},[a]),e.jsxs(d.Box,{sx:{display:"flex",alignItems:"center",gap:2,p:4},children:[e.jsx(d.TextField,{value:a,onChange:e=>{const t=Number.parseInt(e.target.value)||0;o(Math.max(0,t))},name:"custom_width",size:"small",sx:{width:"120px","& .MuiOutlinedInput-root":{paddingLeft:0,paddingRight:0,"& input":{textAlign:"center",padding:"8px 4px"}}},InputProps:{startAdornment:e.jsx(d.InputAdornment,{position:"start",children:e.jsx(d.IconButton,{onClick:()=>{o(e=>Math.max(0,e-1))},size:"small",sx:{marginLeft:"-4px",borderRadius:"4px 0 0 4px",border:"none","&:hover":{backgroundColor:"rgba(0, 0, 0, 0.04)"}},children:e.jsx(f.Remove,{fontSize:"small"})})}),endAdornment:e.jsx(d.InputAdornment,{position:"end",children:e.jsx(d.IconButton,{onClick:()=>{o(e=>e+1)},size:"small",sx:{marginRight:"-4px",borderRadius:"0 4px 4px 0",border:"none","&:hover":{backgroundColor:"rgba(0, 0, 0, 0.04)"}},children:e.jsx(f.Add,{fontSize:"small"})})})},inputProps:{type:"number",min:0}}),e.jsxs(d.Box,{sx:{ml:2,color:"text.secondary"},children:["Current value: ",a]})]})},exports.CompanySelectionModal=rl,exports.CustomForm=function({redirectionPath:a}){const{t:i}=j.useTranslation(),s=r.useAppDispatch(),p=l.useNavigate(),h=l.useLocation(),x=h.state??[],b=r.useAppSelector(e=>e.formBuilder),{control:T}=m.useForm({reValidateMode:"onBlur"}),{fields:I,append:E,remove:B,update:A,move:M,insert:F}=m.useFieldArray({control:T,name:"members"}),{fields:$,append:D,remove:P,update:z}=m.useFieldArray({control:T,name:"section"}),[R,N]=t.useState(""),[L,O]=t.useState(),[q,W]=t.useState(),[H,V]=t.useState([]),[G,U]=t.useState(null),[K,J]=t.useState(),[Y,Z]=t.useState([]),[X,Q]=t.useState({}),[ee,te]=t.useState(),[le,ae]=t.useState(!1),[oe,ne]=t.useState(!1),[re,ie]=t.useState(),[se,de]=t.useState(!0),[ce,ue]=t.useState([]),[me,pe]=t.useState(0),[he,ge]=t.useState(!1),[xe,be]=t.useState(!1),[fe,ye]=t.useState(null),[ve,je]=t.useState(null),[Se,Ce]=t.useState(),we=h.pathname.split("/")[2],_e=a||lt(we);tt(b,ce,me,{removeSection:P,remove:B,setTabsData:ue,append:E,appendSection:D});const ke=t.useCallback(l=>{try{if(!l||"string"!=typeof l)return console.warn("Invalid field type provided to pickPropertyEditForm"),e.jsx("div",{className:"text-gray-500 p-4",children:"Select a field to edit"});const a=l.toLowerCase().trim(),o={text:["text","number","email","phone","date","time","url","currency","file","geolocation","image","relation","info","tagsinput"],select:["select"],section:["section"],checkbox:["checkbox","togglebutton","radiobutton"],table:["table"]},n={element:G,handlePropertyValueUpdate:Ne,handleWidthChange:Pe,handleColumnSelect:ze,fields:(null==b?void 0:b.fields)||[]},r={element:G,handlePropertyValueUpdate:Ne,handleSelectOptionValueUpdate:He,handleWidthChange:Pe,handleColumnSelect:ze};return o.text.includes(a)?t.createElement(Re,{...n,key:`text-form-${(null==G?void 0:G.id)||"default"}`}):o.select.includes(a)?t.createElement(Le,{...r,key:`select-form-${(null==G?void 0:G.id)||"default"}`}):o.section.includes(a)?e.jsx(Oe,{element:X,handlePropertyValueUpdate:De},`section-form-${(null==X?void 0:X.id)||"default"}`):o.checkbox.includes(a)?t.createElement(qe,{...r,key:`checkbox-form-${(null==G?void 0:G.id)||"default"}`}):o.table.includes(a)?e.jsx(We,{element:G,handlePropertyValueUpdate:Ne,handleColumnsUpdate:Ge,fields:(null==b?void 0:b.fields)||[]},`table-form-${(null==G?void 0:G.id)||"default"}`):(console.warn(`Unknown field type: ${l}`),e.jsxs("div",{className:"text-gray-500 p-4 border border-gray-200 rounded",children:[e.jsx("p",{className:"font-medium",children:"Unknown Field Type"}),e.jsxs("p",{className:"text-sm mt-1",children:['Field type "',l,'" is not supported. Please select a valid field to edit.']})]}))}catch(a){return console.error("Error in pickPropertyEditForm:",a),e.jsxs("div",{className:"text-red-500 p-4 border border-red-200 rounded bg-red-50",children:[e.jsx("p",{className:"font-medium",children:"Error Loading Form"}),e.jsx("p",{className:"text-sm mt-1",children:"There was an error loading the property edit form. Please try again."})]})}},[G,X,b]),Te=t.useCallback(()=>{try{if(!(null==Ie?void 0:Ie.section))return void console.error("Element section template is not available");const{uniqueStringId:e}=nt("-"),t={...ot(Ie.section),id:e};t.switcher_forms&&(t.switcher_forms=t.switcher_forms.map(e=>({...e,id:nt("-").uniqueStringId})));const l=$.length;D(t),O(l),N("section");const a={field_type:t.field_type,section_type:t.section_type,switcher_forms:t.switcher_forms,form_switcher_label:t.form_switcher_label,form_switcher_name:t.form_switcher_name,label:t.label,is_accordion:t.is_accordion,id:t.id??l};Q(a),te(l),ke(t.field_type)}catch(e){console.error("Error adding new section:",e)}},[Ie,$,D,O,N,Q,te,ke]),Ee=t.useCallback(()=>{try{const e=ot(Y);e.forEach((e,t)=>{e.members=I.filter(e=>(null==e?void 0:e.section_order)===t)});const t=e.some(e=>{var t;return null==(t=e.members)?void 0:t.some(e=>Boolean(null==e?void 0:e.is_system_field))}),l=!(null==ce?void 0:ce.length)&&t,a={tab_order:ce.length+1,title:"data",remove_tab:l,data:(null==ce?void 0:ce.length)?[]:e};ue(e=>[...e,a])}catch(e){console.error("Error adding new tab:",e)}},[Y,I,ce,ue]),Be=t.useCallback((e,t)=>{try{if(!at(e)||!(null==t?void 0:t.trim()))return void console.error("Invalid tab ID or title provided");ue(l=>l.map(l=>l.tab_order===e?{...l,title:t.trim()}:l))}catch(l){console.error("Error editing tab title:",l)}},[ue]),Ae=t.useCallback(e=>{try{if(!at(e))return void console.error("Invalid tab ID provided");const t=ce.filter(t=>t.tab_order!==e).map(t=>({...t,tab_order:t.tab_order>e?t.tab_order-1:t.tab_order}));if(ue(t),me==e&&pe((null==t?void 0:t.length)-1),t.length>0){const e=t.find(e=>e.tab_order===(me??0)+1);if(null==e?void 0:e.data){const t=e.data.map(({field_type:e,label:t,is_accordion:l,id:a,remove_section:o})=>({field_type:e,label:t,is_accordion:l,id:a,remove_section:o})),l=e.data.flatMap(e=>{var t;return(null==(t=e.members)?void 0:t.map(e=>({...e})))||[]});B(),P(),l.forEach(e=>E(e)),t.forEach(e=>D(e))}}else B(),P()}catch(t){console.error("Error removing tab:",t)}},[ce,me,ue,B,P,E,D]),Me=t.useCallback(e=>{try{const t=e.target.dataset.position;if(!t||!at(t))return void console.error("Invalid element position index");const l=Number(t);if(l<0||l>=H.length)return void console.error("Element position index out of bounds");W(l);const a=ot(H[l]);J(l),U(a),N("element")}catch(t){console.error("Error selecting element:",t)}},[H,W,J,U,N]),Fe=t.useCallback(e=>{try{const t=e.target.dataset.position;if(!t||!at(t))return void console.error("Invalid section position index");const l=Number(t);if(l<0||l>=Y.length)return void console.error("Section position index out of bounds");O(l);const a=ot(Y[l]);te(l),Q(a),N("section")}catch(t){console.error("Error selecting section:",t)}},[Y,O,te,Q,N]),$e=t.useCallback((e,t)=>{var l;try{const a=e.currentTarget,o=null==(l=null==a?void 0:a.dataset)?void 0:l.position;if(void 0===o||!at(o))return void console.error("Invalid section position index for adding member");const n=Number(o);if(n<0)return void console.error("Section position index cannot be negative");if(!(null==Ie?void 0:Ie.text))return void console.error("Element text template is not available");const r={...ot(Ie.text),...t,section_order:n,type:"custom",is_new:!0,custom_width:Math.floor(6),is_fullwidth:!1,is_system_field:Boolean(null==t?void 0:t.is_system_field),id:nt().uniqueStringId};O(n),E(r);const i=I.length;W(i),N("element"),J(i),U(r),ke(r.field_type)}catch(a){console.error("Error adding new member:",a)}},[Ie,I,O,E,W,N,J,U,ke]),De=t.useCallback((e,t)=>{try{const{name:l,type:a,checked:o,value:n}=e.target;if(!l)return void console.error("Property name is required for update");const r=void 0!==t?t:"checkbox"===a?o:n;X[l]!==r&&Q(e=>({...e,[l]:r}))}catch(l){console.error("Error updating section property:",l)}},[X,Q]),Pe=t.useCallback(e=>{try{if(!at(e)||e<1||e>12)return void console.error("Invalid width value provided");U(t=>({...t,custom_width:e}))}catch(t){console.error("Error updating width:",t)}},[U]),ze=t.useCallback(e=>{try{const t=Number(e.target.value);if(!at(t)||t<=0)return void console.error("Invalid column value provided");const l=Math.floor(12/t);if(l<=0)return void console.error("Calculated element per column is invalid");I.forEach((e,t)=>{A(t,{...e,custom_width:l})})}catch(t){console.error("Error updating column selection:",t)}},[I,A]),Ne=t.useCallback((e,t,l,a)=>{var o,n;try{const r=a||(void 0!==l?l:void 0!==t?t:null==(n=null==e?void 0:e.target)?void 0:n.value),i=ot(G);if((null==(o=null==e?void 0:e.target)?void 0:o.name)&&(i[e.target.name]="checkbox"===e.target.type?e.target.checked:r),a){const{uniqueStringId:e}=nt(),t={...Ie[a],section_form_id:null==i?void 0:i.section_form_id,is_form_switcher_section:null==i?void 0:i.is_form_switcher_section,section_order:i.section_order,id:e,type:"custom",is_system_field:Boolean(null==i?void 0:i.is_system_field),is_new:!0,column_width:(null==i?void 0:i.column_width)||6,custom_width:(null==i?void 0:i.custom_width)||6};U(t)}else JSON.stringify(G)!==JSON.stringify(i)&&U({...G,...i})}catch(r){console.error("Error updating property value:",r)}},[G,Ie,U]),He=t.useCallback(e=>{try{if(!Array.isArray(e))return void console.error("Options must be an array");const t=ot(G);t.options=[...e];const{uniqueStringId:l}=nt("-");JSON.stringify(G.options)!==JSON.stringify(e)&&U({...G,...t,id:l})}catch(t){console.error("Error updating select options:",t)}},[G,U]),Ge=t.useCallback(e=>{try{if(!Array.isArray(e))return void console.error("Columns must be an array");const t=ot(G);t.table_columns=[...e];const{uniqueStringId:l}=nt("-");JSON.stringify(G.table_columns)!==JSON.stringify(e)&&U({...G,...t,id:l})}catch(t){console.error("Error updating table columns:",t)}},[G,U]),Ue=t.useCallback(e=>{try{if(!at(e)||e<0||e>=$.length)return void console.error("Invalid section index for removal");ie(e),P(e);const t=[];I.forEach((l,a)=>{(null==l?void 0:l.section_order)===e&&t.push(a)}),t.reverse().forEach(e=>{B(e)}),ae(!0)}catch(t){console.error("Error removing section:",t)}},[$,I,ie,P,B,ae]),Ke=t.useCallback(e=>{try{if(!at(e)||e<0||e>=$.length)return void console.error("Invalid section index for accordion conversion");be(!0),te(e),O(e);const t={...ot($[e]),is_accordion:!0};z(e,t),N("section"),Q(t),ke(t.field_type)}catch(t){console.error("Error making section accordion:",t)}},[$,be,te,O,z,N,Q,ke]),Je=t.useCallback(()=>{try{const e=ot(Y);e.forEach((e,t)=>{e.members=I.filter(e=>(null==e?void 0:e.section_order)===t)});const t=e.some(e=>{var t;return null==(t=e.members)?void 0:t.some(e=>Boolean(null==e?void 0:e.is_system_field))}),l=Number(me);if(at(l)&&l>=0&&l<ce.length){const a=[...ce];a[l]={...a[l],data:e,remove_tab:t},ue(a),B(),P(),W(void 0),N(""),O(void 0)}}catch(e){console.error("Error updating tab data:",e)}},[Y,I,me,ce,ue]),Ye=t.useMemo(()=>Y&&I?Y.map((e,t)=>({...e,members:I.filter(e=>(null==e?void 0:e.section_order)===t)})):null,[Y,I]),Ze=t.useMemo(()=>Ye?(null==ce?void 0:ce.length)?{tab:ce}:{section:Ye}:null,[ce,Ye]),Xe=t.useMemo(()=>Ze?C.formBuilderConversion(Ze):null,[Ze]),Qe=t.useCallback(()=>{Xe&&je(Xe)},[Xe,je]),et=t.useCallback(()=>{je(null)},[]),rt=t.useCallback(async()=>{var e;try{if(!Y||!Array.isArray(Y))return void console.warn("Invalid sectionFormJSON provided");if(!I||!Array.isArray(I))return void console.warn("Invalid members array provided");if(!(null==x?void 0:x._id))return void console.warn("Missing rowData._id for form update");let a;try{a=structuredClone(Y)}catch(t){a=JSON.parse(JSON.stringify(Y))}a.forEach((e,t)=>{e&&"object"==typeof e?e.members=I.filter(e=>e&&"object"==typeof e&&"number"==typeof e.section_order&&e.section_order===t):console.warn(`Invalid section at index ${t}`)});const o=a.some(e=>{var t;return null==(t=e.members)?void 0:t.some(e=>Boolean(null==e?void 0:e.is_system_field))}),n=Number(me);let r=[...ce];at(n)&&n>=0&&n<ce.length&&(r=[...ce],r[n]={...r[n],data:a,remove_tab:o},ue(r));const i=(null==r?void 0:r.length)>0?{tab:r}:{section:a};if("function"!=typeof C.formBuilderConversion)return void console.error("formBuilderConversion is not a function");let d;try{d=C.formBuilderConversion(i)}catch(l){return void console.error("Error during form builder conversion:",l)}if(!d)return void console.warn("Form builder conversion returned empty result");const c={gridCol:2,fields:d},u=await s(k.patchFormDataById({id:x._id,data:c}));if("rejected"===u.meta.requestStatus){const t=w.getErrorMessage(null==(e=null==u?void 0:u.error)?void 0:e.message);S.enqueueSnackbar(t,{variant:"error"})}else S.enqueueSnackbar("Form updated successfully",{variant:"success"}),p(_e)}catch(a){const e=(null==a?void 0:a.message)||"Something went wrong while updating the form";S.enqueueSnackbar(e,{variant:"error"})}},[Y,I,ce,null==x?void 0:x._id,void 0,s,C.formBuilderConversion]),it=e=>{const t={...I[e],type:"custom"};t&&F(e+1,t),W(e+1),N("element"),J(e+1),U(t),ke(t.field_type)},st=[{link:_e,label:"Forms"},{link:"",label:w.formatLabel(null==x?void 0:x.name)},{link:"",label:"Edit Form"}];t.useEffect(()=>{le&&(I.forEach((e,t)=>{void 0!==re&&Boolean(null==re?void 0:re.toString)&&e.section_order>re&&A(t,{...e,section_order:e.section_order-1})}),ae(!1),ne(!0),ie(void 0),N(""))},[le]),t.useEffect(()=>{b.isSuccess&&p(_e)},[b.isSuccess]),t.useEffect(()=>{b.isError&&ye({type:"alert",message:b.error})},[b.error,b.isError]),t.useEffect(()=>{if("number"!=typeof K||"string"!=typeof K){const e=Number(K);if(H[e]){const t=JSON.parse(JSON.stringify(H[e]));A(e,{...t})}}},[H]),t.useEffect(()=>{const e=H.map((e,t)=>t===Number(K)?{...G}:{...e});V(e)},[G]),t.useEffect(()=>{if(I.length!==H.length&&V(JSON.parse(JSON.stringify(I))),Boolean(he)&&JSON.stringify(I)!==JSON.stringify(H)){V(JSON.parse(JSON.stringify(I))),ge(!1);const e=K&&I[K];e&&N("element"),e&&U(e),e&&ke(e.field_type)}oe&&JSON.stringify(I)!==JSON.stringify(H)&&(V(JSON.parse(JSON.stringify(I))),ne(!1))},[I,he]),t.useEffect(()=>{if("number"!=typeof ee||"string"!=typeof ee){const e=Number(ee);if(Y[e]){const t=JSON.parse(JSON.stringify(Y[e]));z(e,{...t})}}},[Y]),t.useEffect(()=>{const e=Y.map((e,t)=>t===Number(ee)?{...e,...X}:{...e});Z(e)},[X]),t.useEffect(()=>{$.length!==Y.length&&Z(JSON.parse(JSON.stringify($))),JSON.stringify(Y)!==JSON.stringify($)&&xe&&(Z(JSON.parse(JSON.stringify($))),be(!1))},[$]),t.useEffect(()=>{},[]);const dt=t.useCallback(async()=>{de(!0);try{(null==x?void 0:x._id)&&(ue([]),await s(k.getFormDataById(null==x?void 0:x._id)),await s(k.getFieldsByFormId({id:null==x?void 0:x._id})))}finally{de(!1)}},[null==x?void 0:x._id]);t.useEffect(()=>{dt()},[dt]);const ct=e=>e&&Object.keys(e).length>0,ut=()=>e.jsx(o.Typography,{type:"s5",color:"theme.secondary.800",className:"formSection--Text",children:"Select a field to edit its properties."}),mt=(e,t="text")=>(null==e?void 0:e.field_type)||t,pt=t.useMemo(()=>{if(!R)return e.jsx(ut,{});if("element"===R){if(!ct(I))return console.warn("Element selected but no members data available"),e.jsx(ut,{});const t=mt(G);return ke(t)}if("section"===R){if(!ct($))return console.warn("Section selected but no section data available"),e.jsx(ut,{});const t=mt(X);return ke(t)}return console.warn(`Unknown selectedHoc type: ${R}`),e.jsx(ut,{})},[R,Object.keys(I).length,Object.keys($).length,null==G?void 0:G.field_type,null==G?void 0:G.field_properties,null==X?void 0:X.field_type,null==X?void 0:X.field_properties,ke]);return e.jsx(d.Box,{position:"relative",children:se?e.jsx(_.ErpLoader,{}):e.jsxs(y.DndProvider,{backend:v.HTML5Backend,children:[e.jsx(n.FormHeader,{breadCrumbPath:st,children:e.jsxs("div",{className:"formSection--Buttons",children:[e.jsx(n.DynamicButton,{variant:"outlined",className:"formSection--PreviewButton",text:"Preview",onClick:()=>{ve?et():Qe()},disable:!(null==I?void 0:I.length),startIcon:ve?e.jsx(g.EyeOff,{}):e.jsx(g.Eye,{})}),e.jsx(n.DynamicButton,{variant:"contained",type:"submit",text:"Update",onClick:rt,disable:ve})]})}),ve?e.jsx(n.FormParser,{data:ve||[],handleFormSubmit:e=>console.log("Preview Data",e),className:"form-container",fieldArrayName:"form-builder-preview",getFormMethods:e=>Ce({...e})}):e.jsxs(d.Grid,{className:"formSection--Grid",container:!0,children:[e.jsx(d.Grid,{item:!0,xs:9,component:"form",sx:{position:"relative",background:"#F5F6F5",padding:"0.75rem"},children:e.jsxs(d.Grid,{className:"formSection--GridContainer",children:[e.jsxs(d.Box,{className:"formSection--Tab",children:[ce&&e.jsx(n.TabBar,{tabs:ce,onEditTabTitle:Be,activeValue:me,setActiveValue:pe,handleTabChange:()=>{Je()},handleRemoveTab:Ae,containerProps:{mb:0}}),e.jsx(n.DynamicButton,{variant:"outlined",text:"Add Tab",onClick:Ee,style:{color:"#292D32",margin:"0.5rem"}})]}),e.jsxs("div",{className:"formSection--Form",children:[null==$?void 0:$.map((t,l)=>{var a;const r=I.filter(e=>e.section_order===l),s=t.section_type===w.SECTION_TYPES.FORM_SWITCH_SECTION,c=null==(a=null==t?void 0:t.switcher_forms)?void 0:a.map(e=>({...e,formMembers:I.filter(t=>t.section_form_id===e.id)}));return e.jsxs(n.DynamicSectionHOC,{index:l,label:i(t.label),onClick:Fe,position:l,fieldArrayName:"section",isFormSwitcher:s,activeIndex:L===l,removeSection:()=>Ue(l),handleAccordion:()=>Ke(l),handleAddButton:e=>$e(e),remove_section:t.remove_section,children:[s?e.jsxs("div",{style:{width:"100%"},children:[e.jsx(o.Typography,{type:"s5",style:{fontWeight:500},color:"theme.secondary.800",children:t.form_switcher_label}),e.jsx(d.RadioGroup,{"aria-labelledby":"theme-radio-buttons-group-label",name:t.form_switcher_name||t.form_switcher_label,children:null==c?void 0:c.map(({name:t,id:a,formMembers:o})=>e.jsxs(e.Fragment,{children:[e.jsx("div",{children:e.jsx(d.FormControlLabel,{value:t,control:e.jsx(n.Radio,{}),label:i(t),disabled:!0},a)}),e.jsx(d.Grid,{container:!0,sx:{mb:3},children:e.jsx(Ve,{sectionMembers:o||[],members:I,activeMember:q,control:T,t:i,element:Ie,images:u.images,elementJSON:G,remove:B,move:M,handleElementSelection:Me,setElementSwap:ge,handleDuplicateElement:it,setSelectedHoc:N,setActiveMember:W})}),e.jsx(n.DynamicButton,{text:"Add",variant:"outlined",className:"formSection--PreviewButton","data-position":l,onClick:e=>$e(e,{section_form_id:a,is_form_switcher_section:!0}),startIcon:e.jsx(f.Add,{})})]}))})]}):null,!s&&e.jsx(Ve,{sectionMembers:r||[],members:I,activeMember:q,control:T,t:i,element:Ie,images:u.images,elementJSON:G,remove:B,move:M,handleElementSelection:Me,setElementSwap:ge,handleDuplicateElement:it,setSelectedHoc:N,setActiveMember:W})]})}),e.jsx("div",{className:"formSection--Section",children:e.jsx(n.DynamicButton,{text:"Add a section",variant:"outlined",className:"formSection--PreviewButton",onClick:Te,startIcon:e.jsx(f.Add,{})})})]})]})}),e.jsx(d.Grid,{item:!0,xs:3,className:Boolean(R)&&((null==I?void 0:I.length)||$.length)?"formSection--RightGrid":"formSection--RightGrid formSection--Text",children:pt})]}),e.jsx(c.Toast,{open:Boolean(fe),type:null==fe?void 0:fe.type,message:null==fe?void 0:fe.message,handleClose:()=>ye(null),anchorOrigin:{horizontal:"right",vertical:"bottom"}})]})})},exports.DividerControls=Pt,exports.EditSectionModal=xt,exports.EditorCanvas=Qt,exports.EditorHeader=ht,exports.EditorSidebar=Jt,exports.FieldSelect=Be,exports.ForgotPassword=()=>{const{forgotPassword:n}=o.useAuth(),r=b.styled(d.Grid)(()=>({height:"100vh"})),i=l.useNavigate(),[s,p]=t.useState(null),g=ae.object({login:ae.object({email:ae.string().required("Please enter email").email("Provided email is invalid")})}),{control:x,handleSubmit:f}=m.useForm({resolver:c.o(g),mode:"all"}),y=b.styled(d.Grid)(({theme:e})=>({[e.breakpoints.down("sm")]:{display:"none"},backgroundImage:`url(${u.images.login.LoginLeftBg})`,backgroundRepeat:"no-repeat",backgroundSize:"cover",display:"flex",justifyContent:"center",alignItems:"center",[e.breakpoints.down("lg")]:{"& img":{width:350,height:350}},[e.breakpoints.down("md")]:{"& img":{width:300,height:300}}})),v=b.styled(d.Grid)(()=>({display:"flex",justifyContent:"center",alignItems:"center",padding:"1rem"})),j=b.styled(d.Box)(()=>({display:"flex",flexDirection:"column"}));t.useEffect(()=>{});const S=h.getApiConfig().appLogo||u.images.erp_logo;return e.jsxs(d.Box,{children:[e.jsxs(r,{container:!0,children:[e.jsx(y,{item:!0,sm:6,children:e.jsx("img",{src:u.images.login.LoginLeftSiteImage})}),e.jsx(v,{item:!0,sm:6,xs:12,children:e.jsxs(j,{display:"flex",flexDirection:"column",gap:4,sx:e=>({minWidth:400,[e.breakpoints.down("md")]:{minWidth:300},[e.breakpoints.down("sm")]:{minWidth:300}}),children:[e.jsx(d.Box,{textAlign:"center",children:e.jsx("img",{src:S,width:160,height:55})}),e.jsx("form",{onSubmit:f(async e=>(await n(e.login,(e,t)=>{e?(p({message:t,type:"normal"}),setTimeout(()=>{i(a.Pathname.LOGIN)},1500)):p({message:t,type:"alert"})}),e)),children:e.jsxs(j,{gap:4,children:[e.jsxs(j,{gap:3,children:[e.jsxs(d.Box,{children:[e.jsx(o.Typography,{align:"center",type:"h1",weight:"medium",color:"theme.secondary.1000",children:"Forgot Password"}),e.jsx(o.Typography,{align:"center",type:"h5",weight:"normal",color:"theme.secondary81000",children:"Enter your email to reset password"})]}),e.jsx(j,{gap:2,children:e.jsx(d.Box,{children:e.jsx(c.DynamicInput,{formControl:x,label:"Email",name:"email",placeholder:"Enter email",fieldArrayName:"login"})})})]}),e.jsxs(j,{gap:2,children:[e.jsx(c.Button,{type:"submit",size:"large",variant:"contained",children:"Reset Password"}),e.jsx(c.Button,{variant:"text",sx:e=>{var t;return{color:`${null==(t=e.palette.theme)?void 0:t.primary[700]} !important`}},onClick:()=>{i(a.Pathname.LOGIN)},children:"Back to login"})]})]})})]})})]}),e.jsx(c.Toast,{open:Boolean(s),message:null==s?void 0:s.message,type:null==s?void 0:s.type,handleClose:()=>p(null),anchorOrigin:{horizontal:"right",vertical:"bottom"},autoHideDuration:3e3})]})},exports.FormField=He,exports.FormFields=Ve,exports.HtmlThumbnailPreview=al,exports.ImageControls=Dt,exports.Landing=function(){return e.jsx("div",{className:"Landing",children:e.jsxs("div",{className:"Landing--Home",id:"home",children:[e.jsx("div",{className:"Landing--HomeAnimation",children:e.jsx("video",{className:"Landing--HomeAnimationVideo",autoPlay:!0,muted:!0,loop:!0,playsInline:!0,children:e.jsx("source",{src:"https://ak.picdn.net/shutterstock/videos/1063309405/preview/stock-footage-modern-office-portrait-of-beautiful-authentic-specialist-with-short-pink-hair-standing-holding.webm",type:"video/mp4"})})}),e.jsx("div",{className:"Landing--HomeContent",children:e.jsxs("div",{className:"Landing--HomeContentTop",children:[e.jsxs("h1",{className:"Landing--SubTitle",children:["Introducing Dummy",e.jsx("span",{style:{fontWeight:"700"},children:" Land, "})]}),e.jsx("h1",{className:"Landing--Para",children:"This is the hero section.Lorem ipsum dolor sit amet, consectetur adipisicing elit.Dicta fugiat perspiciatis temporibus ut impedit expedita maiores officiis porro ? At commodi suscipit atque eligendi cumque ? Impedit magnam eligendi fugiat.Non, quam."})]})})]})})},exports.MemoizedEditorSection=jt,exports.NotFound=se,exports.PageView=()=>{const l=r.useAppDispatch(),{pages:a,currentPage:o,rows:i,columns:d,columnOrder:u,paginationModel:m}=r.useAppSelector(e=>null==e?void 0:e.pages),{pageNo:p,limit:h}=m;t.useEffect(()=>{l(de(1))},[l]),t.useEffect(()=>{l(de(o))},[l,o]);const g=t.useMemo(()=>{const e=h*(p-1);return i.slice(e,e+h)},[i,p,h]),x=t.useMemo(()=>null==d?void 0:d.map(t=>{let l={...t,enableSorting:!0};return"number"===(null==t?void 0:t.type)?l={...l,muiEditTextFieldProps:{type:"number"},Footer:({column:t})=>e.jsx(ie,{data:g,column:null==t?void 0:t.id})}:"string"===t.type&&(l={...l,Footer:({column:t})=>e.jsx(s.DefaultAggregation,{data:g,column:t.id})}),l}),[g,d]),b=h?Math.ceil(i.length/h):0;return e.jsxs(e.Fragment,{children:[e.jsx(c.Button,{children:"Open Filter"}),e.jsx(n.MaterialTable,{rows:g,columns:x,paginationModel:m,totalPages:b,columnOrder:["mrt-row-select",...u],handleColumnOrdering:e=>{l(be(e.slice(1)))},updateData:(e,t,a)=>{var o;const n={value:"number"===(null==(o=null==t?void 0:t.columnDef)?void 0:o.type)?Number(e):e,columnId:t.id,rowId:a};l(fe(n))}}),e.jsx(n.Footer,{pages:a,setPages:e=>l(ge(e)),currentPage:o,setCurrentPage:e=>l(he(e)),total:b,paginationModel:m,handlePaginationModel:e=>{l(xe(e))}})]})},exports.PrivateRoute=()=>{const{user:t,loading:r}=o.useAuth();return r?e.jsx(n.Loader,{}):t?e.jsx(l.Outlet,{}):e.jsx(l.Navigate,{to:a.Pathname.LOGIN})},exports.ResetPassword=()=>{const{resetPassword:n}=o.useAuth(),[r]=l.useSearchParams(),i=l.useNavigate();return t.useEffect(()=>{const e=r.get("token");e?n({token:e},t=>{var l;console.log("response ",t),t?t&&(null==t?void 0:t.data)&&(null==(l=null==t?void 0:t.data)?void 0:l.isValid)&&i(a.Pathname.CHANGE_PASSWORD,{state:{token:e}}):i(a.Pathname.LOGIN)}):i(a.Pathname.LOGIN)},[r,n,i]),e.jsx(d.Box,{children:"Resetting password, please wait..."})},exports.SectionEditForm=Oe,exports.SectionFlowEditor=tl,exports.SectionFormatPanel=Vt,exports.SelectEditForm=Le,exports.SignatureControls=qt,exports.TableControls=Ot,exports.TableEditForm=We,exports.TemplateModal=nl,exports.TemplateNameModal=el,exports.Templates=il,exports.TextControls=It,exports.TextEditForm=Re,exports.activityTag={comments:[{name:"You",dateTime:"01-11-2024 12:45:10",text:"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."},{name:"Siddhant",dateTime:"01-12-2024 15:05:22",text:"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}],activities:[{dateTime:"12-27-2023 19:17:10",text:"Prasun assigned HR Admin role to Avneet Singh."},{dateTime:"12-27-2023 19:15:10",text:"Prasun created a new user Avneet Singh"},{dateTime:"12-27-2023 15:17:10",text:"Prasun created a new role HR Admin"},{dateTime:"12-27-2023 14:17:10",text:"Prasun updated a role UI/UX Designer ‣ Product Designer"},{dateTime:"12-27-2023 14:17:10",text:"Amrit updated resources for UI/UX Designer role."},{dateTime:"12-27-2023 14:17:10",text:"Amrit updated user Prashant Singh ‣ Prasun Singh"},{dateTime:"12-27-2023 14:17:10",text:"Amrit updated user Prashant Singh ‣ Prasun Singh"}]},exports.board={columns:[{id:1,title:"Backlog",cards:[{id:1.1,title:"Card title 1",description:"Card content"},{id:1.2,title:"Card title 2",description:"Card content"},{id:1.3,title:"Card title 3",description:"Card content"}]},{id:2,title:"Doing",cards:[{id:2.1,title:"Card title 9",description:"Card content"}]},{id:3,title:"Q&A",cards:[{id:3.1,title:"Card title 10",description:"Card content"},{id:3.2,title:"Card title 11",description:"Card content"}]},{id:4,title:"Production",cards:[{id:4.1,title:"Card title 12",description:"Card content"},{id:4.2,title:"Card title 13",description:"Card content"}]}]},exports.calendarData=_e,exports.column=Te,exports.createDefaultTableColumns=()=>[{header:"Column 1",accessorKey:"column_1",visible:!0},{header:"Column 2",accessorKey:"column_2",visible:!0}],exports.data=[{name:"Naidu Setti",company:"ERP Force",status:"Paid",email:"naidu@gmail.com",amount:"$1,00,000"},{name:"Shashank Yadav",company:"Antino Labs",status:"Pending",email:"shashank@gmail.com",amount:"$50,000"},{name:"Tarun Prajapati",company:"Goldenflitch",status:"Lost",email:"tarun@gmail.com",amount:"$60,000"},{name:"Rajneesh Kumar",company:"ERP Force",status:"Lost",email:"rajneesh@gmail.com",amount:"$10,000"},{name:"Radhakanth",company:"Antino",status:"Upcomming",email:"radhakanth@gmail.com",amount:"$1,00,000"}],exports.defaultData=ce,exports.element=Ie,exports.emailColumns=[{header:"ID",accessorKey:"_id",visible:!0,type:"string"},{header:"Date",accessorKey:"created_at",visible:!0,type:"date"},{header:"Subject",accessorKey:"subject",visible:!0,type:"string"}],exports.extractSections=Ye,exports.extractStyles=ct,exports.fetchPage=de,exports.formatText=Ue,exports.generateCustomFormPath=(e,t)=>{try{return`/dashboard/${e}${t}`}catch(l){throw console.error("Error generating module path:",l),l}},exports.generateEmailPreview=st,exports.generateHeaderFooterPreview=dt,exports.generateInlineStyles=mt,exports.generateModulePath=lt,exports.getInitialSectionData=pt,exports.local=ue,exports.multilineData=[{id:1,name:"Customer",role:"Selling"},{id:2,name:"Producer",role:"sdf"},{id:3,name:"Director",role:"wer"}],exports.pageViewChangeCurrentPage=he,exports.processMembers=Je,exports.processTableColumns=Ke,exports.reducer=ye,exports.setColumnOrder=be,exports.setPageViewPages=ge,exports.setPageViewPaginationModel=xe,exports.setRowData=fe,exports.tableData=[{age:33,name:"Delaney Cortez",company:"IZZBY",email:"delaneycortez@izzby.com",phone:"+1 (844) 567-3740",image:"https://picsum.photos/id/74/900/900",address:"870 Hegeman Avenue, Crawfordsville, Kentucky, 2953",about:"Nostrud labore esse labore aliquip. Qui excepteur sint exercitation adipisicing deserunt ad veniam sunt ipsum nulla deserunt dolor est culpa. Eu deserunt nostrud ipsum mollit consectetur mollit et. Commodo mollit qui Lorem fugiat eiusmod dolore amet est officia aliqua. Est tempor veniam sit magna. Ullamco veniam eiusmod nostrud sit dolor. Est proident cupidatat proident ullamco irure commodo nisi fugiat adipisicing ullamco adipisicing ad officia.\r\n",date:"2023-01-10T09:02:53.870Z"},{age:24,name:"Williamson Davenport",company:"ONTAGENE",email:"williamsondavenport@ontagene.com",phone:"+1 (844) 564-3345",image:"https://picsum.photos/id/40/900/900",address:"274 Forest Place, Vowinckel, Maine, 9510",about:"Quis ipsum ad deserunt cillum consequat do ex laboris sit eiusmod pariatur occaecat voluptate. Laborum ea sit duis mollit est sunt culpa ut et commodo consectetur veniam adipisicing amet. Ipsum mollit proident ea deserunt veniam Lorem duis aliquip dolor duis proident ut. Velit esse officia occaecat exercitation magna consequat ullamco ea nisi. Ad ea deserunt occaecat quis occaecat eiusmod ad do. Elit veniam quis aliquip qui nostrud laborum irure minim aute irure fugiat. Ullamco aliquip dolor est sit nulla consectetur.\r\n",date:"2023-01-10T09:02:53.870Z"},{age:30,name:"Alexander Wong",company:"QUADEEBO",email:"alexanderwong@quadeebo.com",phone:"+1 (834) 497-2624",image:"https://picsum.photos/id/8/900/900",address:"420 Borinquen Pl, Kenvil, Vermont, 7377",about:"Dolor mollit elit est ex. Sit mollit laboris ad pariatur magna est amet veniam ad ad velit incididunt eu. Minim ipsum qui labore eiusmod magna veniam in magna pariatur Lorem.\r\n",date:"2023-01-10T09:02:53.870Z"},{age:24,name:"Blanca Schultz",company:"CUJO",email:"blancaschultz@cujo.com",phone:"+1 (954) 412-2870",image:"https://picsum.photos/id/42/900/900",address:"144 Albemarle Terrace, Watchtower, Delaware, 2829",about:"Pariatur sunt dolore nostrud cillum cupidatat culpa. Ipsum laborum laboris reprehenderit Lorem culpa. Consequat duis do occaecat ipsum cupidatat sunt minim minim cillum commodo in qui culpa anim. Et ullamco nisi eiusmod laboris veniam laborum ullamco reprehenderit aliqua nulla labore. Elit excepteur sunt exercitation anim sint non ea.\r\n",date:"2023-01-10T09:02:53.870Z"},{age:34,name:"Eunice Romero",company:"CENTREGY",email:"euniceromero@centregy.com",phone:"+1 (949) 568-3290",image:"https://picsum.photos/id/3/900/900",address:"698 Clermont Avenue, Harmon, Washington, 1094",about:"Nulla aute enim incididunt labore aute id officia fugiat tempor aliqua. Fugiat incididunt sint nisi eiusmod fugiat magna minim in. Officia eu enim magna magna pariatur deserunt esse amet veniam sint consequat est sit.\r\n",date:"2023-01-10T09:02:53.870Z"}],exports.tabsData=[{tab_order:1,title:"Tab One",content:"Tab one Content"},{tab_order:2,title:"Tab Two",content:"Tab two Content"},{tab_order:3,title:"Tab Three",content:"Tab three Content"}],exports.templateEditorRoutes=(t,l)=>[{path:`${M.TEMPLATE_EDITOR_PATHS.TEMPLATES_LIST("email")}`,element:e.jsx(il,{type:"email",module:l,modulePath:t})},{path:`${M.TEMPLATE_EDITOR_PATHS.TEMPLATES_ADD("email")}`,element:e.jsx(ll,{modulePath:t,type:"email",module:l})},{path:`${M.TEMPLATE_EDITOR_PATHS.TEMPLATES_EDIT("email")}`,element:e.jsx(ll,{modulePath:t,type:"email",module:l})},{path:`${M.TEMPLATE_EDITOR_PATHS.TEMPLATES_LIST("pdf")}`,element:e.jsx(il,{module:l,type:"pdf",modulePath:t})},{path:`${M.TEMPLATE_EDITOR_PATHS.TEMPLATES_ADD("pdf")}`,element:e.jsx(ll,{modulePath:t,type:"pdf",module:l})},{path:`${M.TEMPLATE_EDITOR_PATHS.TEMPLATES_EDIT("pdf")}`,element:e.jsx(ll,{modulePath:t,type:"pdf",module:l})}],exports.templateRoutes=it,exports.textOptions=[{label:"Heading 1",value:"heading"},{label:"Heading 2",value:"heading-2"},{label:"Heading 3",value:"heading-3"},{label:"Heading 4",value:"heading-4"},{label:"Body",value:"text"},{label:"Text Block",value:"text-block"}],exports.useCKEditorStyleExtractor=bt,exports.useFormDataEffect=tt,exports.useFormDataProcessor=(e,l,a,o)=>{const{removeSection:n,remove:r,append:i}=o,d=t.useMemo(()=>JSON.stringify(null==e?void 0:e.formData),[null==e?void 0:e.formData]),c=t.useMemo(()=>{var t;if(!(null==(t=null==e?void 0:e.formData)?void 0:t.length))return null;try{return s.formBuilderDeConversion(e.formData)}catch(l){return console.error("Error processing form data:",l),null}},[d]);return t.useEffect(()=>{if(!c)return n(),r(),void i([]);try{l.length>0?Ze({tabsData:l},a,e,l,o):c.tab?Ze(c,a,e,l,o):c.section?Ze(c,0,e,l,o):(console.warn("No valid data structure found in initialData"),n(),r(),i([]))}catch(t){console.error("Error in form data processing:",t),n(),r(),i([])}},[a,d,l.length,c,o,e]),{initialData:c}},exports.userData=[{id:1,name:"Aman Gupta",role:"Accountant & Finance",roleId:2},{id:2,name:"Deepak Sharma",role:"Sales",roleId:4},{id:3,name:"Avhinav Dhingra",role:"Operation",roleId:3},{id:4,name:"Rajiv Mehta",role:"Maintenance",roleId:1},{id:5,name:"Rajiv Mehta",role:"Stakes",roleId:6},{id:6,name:"Rajdeep Dutta",role:"Research & Development",roleId:5},{id:7,name:"Sonia Verma",role:"Accountant & Finance",roleId:2},{id:8,name:"Vikram Singh",role:"Sales",roleId:4},{id:9,name:"Neha Patel",role:"Operation",roleId:3},{id:10,name:"Ankit Kapoor",role:"Maintenance",roleId:1},{id:11,name:"Kavita Shah",role:"Stakes",roleId:6},{id:12,name:"Rohit Singh",role:"Research & Development",roleId:5},{id:13,name:"Priya Agarwal",role:"Human Resources",roleId:7},{id:14,name:"Amit Trivedi",role:"Marketing",roleId:8},{id:15,name:"Sara Khan",role:"Customer Support",roleId:9},{id:16,name:"Amit Gupta",role:"Accountant & Finance",roleId:2},{id:17,name:"Neha Sharma",role:"Sales",roleId:4},{id:18,name:"Rahul Verma",role:"Operation",roleId:3},{id:19,name:"Meera Kapoor",role:"Maintenance",roleId:1},{id:20,name:"Rajesh Khanna",role:"Stakes",roleId:6},{id:21,name:"Sonia Dutta",role:"Research & Development",roleId:5},{id:22,name:"Alok Gupta",role:"Human Resources",roleId:7},{id:23,name:"Preeti Singh",role:"Marketing",roleId:8},{id:24,name:"Anuj Kumar",role:"Customer Support",roleId:9},{id:25,name:"Deepa Patel",role:"IT Support",roleId:10},{id:26,name:"Vishal Kapoor",role:"Legal",roleId:11},{id:27,name:"Asha Singh",role:"Quality Assurance",roleId:12},{id:28,name:"Rajeev Sharma",role:"Logistics",roleId:13},{id:29,name:"Kavita Trivedi",role:"Public Relations",roleId:14},{id:30,name:"Alok Singh",role:"Training and Development",roleId:15},{id:31,name:"Pooja Kapoor",role:"Accountant & Finance",roleId:2},{id:32,name:"Rohit Verma",role:"Sales",roleId:4},{id:33,name:"Sanjay Mehta",role:"Operation",roleId:3},{id:34,name:"Nisha Khanna",role:"Maintenance",roleId:1},{id:35,name:"Varun Dutta",role:"Stakes",roleId:6},{id:36,name:"Sapna Gupta",role:"Research & Development",roleId:5},{id:37,name:"Vikas Sharma",role:"Human Resources",roleId:7},{id:38,name:"Ritu Verma",role:"Marketing",roleId:8},{id:39,name:"Manish Singh",role:"Customer Support",roleId:9},{id:40,name:"Neha Patel",role:"IT Support",roleId:10},{id:41,name:"Anil Kapoor",role:"Legal",roleId:11},{id:42,name:"Priya Dutta",role:"Quality Assurance",roleId:12},{id:43,name:"Rahul Sharma",role:"Logistics",roleId:13},{id:44,name:"Sneha Trivedi",role:"Public Relations",roleId:14},{id:45,name:"Anita Singh",role:"Training and Development",roleId:15},{id:46,name:"Amit Trivedi",role:"Accountant & Finance",roleId:2},{id:47,name:"Priyanka Sharma",role:"Sales",roleId:4},{id:48,name:"Rajat Verma",role:"Operation",roleId:3},{id:49,name:"Anu Khanna",role:"Maintenance",roleId:1},{id:50,name:"Sumit Dutta",role:"Stakes",roleId:6}];
2
- //# sourceMappingURL=default-data-D2cqOmp4.js.map
1
+ "use strict";const e=require("react/jsx-runtime"),t=require("react"),l=require("react-router-dom"),a=require("./pathname.rental-Br768eN2.js"),o=require("./useAuth-C1y8BBuX.js"),n=require("./android-12-switch-CphTHRb8.js"),r=require("./hooks-BdfwliGF.js"),i=require("@reduxjs/toolkit"),s=require("./form-builder-deconversion-BbeAseMU.js"),d=require("@mui/material"),c=require("./appbar-C6Es9HGk.js"),u=require("./images-DrJQoSCu.js"),m=require("react-hook-form"),p=require("yup"),h=require("./api-config-CkfRrKRY.js"),g=require("./tick-ChY3vEPD.js"),x=require("@glideapps/glide-data-grid"),b=require("@mui/material/styles");;/* empty css */const f=require("@mui/icons-material"),y=require("react-dnd"),v=require("react-dnd-html5-backend"),j=require("react-i18next"),S=require("notistack"),C=require("./form-builder-conversion-CfUcZgLV.js"),w=require("./common-wRWMk0Fs.js"),_=require("./page-context-qa1FKO9A.js"),k=require("./reducer-BfnLOnkL.js"),T=require("./trash-lbX6jsCI.js"),I=require("./toggle-switch-tXRsnOmX.js"),E=require("@mui/icons-material/Close"),B=require("./pathname.hrms-DGxdM-k7.js"),A=require("@mui/icons-material/CodeOutlined"),M=require("./route-page-map-CDdU1EAs.js"),F=require("@dnd-kit/core"),$=require("@mui/icons-material/DragIndicator"),D=require("@mui/icons-material/CallSplit"),P=require("@mui/icons-material/FormatBold"),z=require("@mui/icons-material/FormatItalic"),R=require("@mui/icons-material/FormatUnderlined"),N=require("@mui/icons-material/ColorLens"),L=require("lodash"),O=require("@mui/icons-material/FormatAlignLeft"),q=require("@mui/icons-material/FormatAlignCenter"),W=require("@mui/icons-material/FormatAlignRight"),H=require("@mui/icons-material/FormatAlignJustify"),V=require("@mui/icons-material/ExpandMore"),G=require("@mui/icons-material/Add"),U=require("@mui/icons-material/Refresh"),K=require("@mui/icons-material/MergeType"),J=require("react-dropzone"),Y=require("lucide-react"),Z=require("./api-DG3x2G1d.js"),X=require("@mui/icons-material/Check"),Q=require("uuid"),ee=require("./action-bar-BmEN5Ob9.js"),te=require("./useAccountSetting-DZvJOGz7.js");function le(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const l in e)if("default"!==l){const a=Object.getOwnPropertyDescriptor(e,l);Object.defineProperty(t,l,a.get?a:{enumerable:!0,get:()=>e[l]})}return t.default=e,Object.freeze(t)}const ae=le(p),oe=[{label:"Average",value:"avg"},{label:"Sum",value:"sum"},{label:"Min",value:"min"},{label:"Max",value:"max"},{label:"Count Empty",value:"count_empty"},{label:"Count Full",value:"count_full"},{label:"Percentage Full",value:"percentage_full"},{label:"Percentage Empty",value:"percentage_empty"},{label:"None",value:"none"}],ne=[{label:"Count Empty",value:"count_empty"},{label:"Count Full",value:"count_full"},{label:"Percentage Full",value:"percentage_full"},{label:"Percentage Empty",value:"percentage_empty"},{label:"None",value:"none"}],re={avg:s.aggregationFns.average,sum:s.aggregationFns.sum,max:s.aggregationFns.max,count_empty:s.aggregationFns.countEmpty,count_full:s.aggregationFns.countFull,percentage_empty:s.aggregationFns.percentageEmpty,percentage_full:s.aggregationFns.percentageFull,min:s.aggregationFns.min,none:s.aggregationFns.none},ie=({data:l,column:a,type:n})=>{const[r,i]=t.useState("none"),[c,u]=t.useState(null),[m,p]=t.useState(),h=Boolean(c),g=()=>{u(null)};t.useEffect(()=>{p((0,re[r])(l,a))},[r,a,l]);const x="number"===n?oe:ne;return e.jsxs(e.Fragment,{children:[e.jsx(o.Typography,{onClick:e=>{u(e.currentTarget)},sx:{cursor:"pointer"},type:"s4",weight:"normal",color:m?"theme.secondary.1000":"theme.secondary.500",children:m||"+ Add Calculation"}),e.jsx(s.Menu,{id:"basic-menu",anchorEl:c,open:h,onClose:g,children:null==x?void 0:x.map(t=>e.jsx(d.MenuItem,{selected:r==(null==t?void 0:t.value),onClick:()=>{return e=null==t?void 0:t.value,i(e),void g();var e},children:e.jsx(o.Typography,{color:"theme.secondary.1000",type:"s4",children:null==t?void 0:t.label})},t.value))})]})};class se extends t.Component{componentDidMount(){setTimeout(()=>{},2e3)}render(){return e.jsxs("div",{style:{textAlign:"center",position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)"},children:[e.jsx("strong",{children:e.jsx("p",{children:"404"})}),e.jsx("hr",{}),e.jsx("p",{children:"Not Found"})]})}}const de=i.createAsyncThunk("pageView/fetchPage",(e,{getState:t})=>{const{pages:l}=t(),{data:a}=l.pages.find(t=>(null==t?void 0:t.value)===e);return a}),ce={rows:[{name:"John",age:30,gender:"Male",company:"NASA",location:"USA",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4}],columns:[{header:"Name",type:"string",accessorKey:"name"},{type:"number",header:"Age",accessorKey:"age"},{header:"Gender",type:"string",accessorKey:"gender"},{header:"Company",type:"string",accessorKey:"company"},{header:"Location",type:"string",accessorKey:"location"},{header:"Price",type:"number",accessorKey:"price"}],columnOrder:["name","age","gender","company","location","price"]},ue={rows:[{name:"John",age:30,gender:"Male",company:"NASA",location:"USA",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4},{name:"Sara",age:35,gender:"Female",company:"SpaceX",location:"Russia",price:1e4}],columns:[{type:"number",header:"Age",accessorKey:"age"},{header:"Gender",type:"string",accessorKey:"gender"},{header:"Company",type:"string",accessorKey:"company"},{header:"Name",type:"string",accessorKey:"name"},{header:"Location",type:"string",accessorKey:"location"},{header:"Price",type:"number",accessorKey:"price"}],columnOrder:["age","gender","company","name","location","price"]},me={currentPage:1,rows:[],columns:[],columnOrder:[],loading:!0,error:"",pages:[{name:"Default",_id:1,data:ce},{name:"Local",_id:2,data:ue}],paginationModel:{pageNo:1,limit:10}},pe=i.createSlice({name:"pageView",initialState:me,reducers:{changeCurrentPage(e,t){e.currentPage=t.payload},setPages(e,t){e.pages=t.payload},setPaginationModel(e,t){e.paginationModel=t.payload},setColumnOrder(e,t){e.columnOrder=t.payload},setRowData(e,{payload:t}){const l=JSON.parse(JSON.stringify(e.rows));l[t.rowId][t.columnId]=t.value,e.rows=l}},extraReducers:e=>{e.addCase(de.pending,e=>{e.loading=!0}),e.addCase(de.fulfilled,(e,t)=>{e.loading=!1,e.error="",e.rows=t.payload.rows,e.columns=t.payload.columns,e.columnOrder=t.payload.columnOrder}),e.addCase(de.rejected,e=>{e.loading=!1,e.rows=[],e.columns=[],e.error="Unable to get data"})}}),{changeCurrentPage:he,setPages:ge,setPaginationModel:xe,setColumnOrder:be,setRowData:fe}=pe.actions,ye=pe.reducer,ve=d.styled(d.Grid)(()=>({height:"100vh"})),je=d.styled(d.Grid)(({theme:e})=>({[e.breakpoints.down("sm")]:{display:"none"},backgroundImage:`url(${u.images.login.LoginLeftBg})`,backgroundRepeat:"no-repeat",backgroundSize:"cover",display:"flex",justifyContent:"center",alignItems:"center",[e.breakpoints.down("lg")]:{"& img":{width:350,height:350}},[e.breakpoints.down("md")]:{"& img":{width:300,height:300}}})),Se=d.styled(d.Grid)(()=>({display:"flex",justifyContent:"center",alignItems:"center",padding:"1rem"})),Ce=d.styled(d.Box)(()=>({display:"flex",flexDirection:"column"})),we=ae.object({login:ae.object({password:ae.string().required("Please enter password").min(8,"Password must be at least 8 characters").matches(/[A-Z]/,"Password must contain at least one uppercase letter").matches(/[!@#$%^&*(),.?":{}|<>]/,"Password must contain at least one special character"),confirm_password:ae.string().required("Please enter confirm password").oneOf([ae.ref("password")],"Passwords must match")})}),_e={events:[{title:"All Day Event",start:ke("YEAR-MONTH-01")},{title:"Long Event",start:ke("YEAR-MONTH-07"),end:ke("YEAR-MONTH-10")},{groupId:"999",title:"Repeating Event",start:ke("YEAR-MONTH-09T16:00:00+00:00")},{groupId:"999",title:"Repeating Event",start:ke("YEAR-MONTH-16T16:00:00+00:00")},{title:"Conference",start:"YEAR-MONTH-17",end:ke("YEAR-MONTH-19")},{title:"Meeting",start:ke("YEAR-MONTH-18T10:30:00+00:00"),end:ke("YEAR-MONTH-18T12:30:00+00:00")},{title:"Lunch",start:ke("YEAR-MONTH-18T12:00:00+00:00")},{title:"Birthday Party",start:ke("YEAR-MONTH-19T07:00:00+00:00")},{title:"Meeting",start:ke("YEAR-MONTH-18T14:30:00+00:00")},{title:"Happy Hour",start:ke("YEAR-MONTH-18T17:30:00+00:00")},{title:"Dinner",start:ke("YEAR-MONTH-18T20:00:00+00:00")}]};function ke(e){const t=new Date,l=t.getFullYear().toString();let a=(t.getMonth()+1).toString();return 1===a.length&&(a="0"+a),e.replace("YEAR",l).replace("MONTH",a)}const Te=[{title:"Name",id:"name",hasMenu:!0,icon:x.GridColumnIcon.HeaderString},{title:"Company",id:"company",hasMenu:!0,dataType:"Bubble"},{title:"Age",id:"age",hasMenu:!0,dataType:"Number"},{title:"Image dd",id:"image",key:"image",dataType:"Image"},{title:"Email",id:"email",hasMenu:!0},{title:"Date",id:"date",hasMenu:!0,dataType:"DatePicker"},{title:"Phone",id:"phone"},{title:"Address",id:"address"},{title:"about",id:"about"}],Ie={text:{field_type:"text",label:"label",placeholder:"Enter text",default_value:"",min_length:2,max_length:30,is_multiline:!1,is_required:!0,is_unique:!1},number:{field_type:"number",label:"label",placeholder:"Enter number",default_value:"",float_step:"0.001",min_length:0,max_length:1e3,is_negative:!1,is_required:!0,is_unique:!1},email:{field_type:"email",label:"label",placeholder:"Enter email",default_value:"",is_required:!1,is_unique:!1},phone:{field_type:"phone",label:"label",placeholder:"Enter phone",default_value:"",is_required:!1,is_unique:!1},select:{field_type:"select",label:"Select",placeholder:"Choose option",default_value:"",options:[],is_multiselect:!1,is_required:!0,is_unique:!1},date:{field_type:"date",label:"label",placeholder:"Select Date",default_value:"",is_future_dates_allowed:!1,is_past_dates_allowed:!1,is_required:!1,is_unique:!1},time:{field_type:"time",label:"label",placeholder:"Select Time",default_value:"",is_required:!1,is_unique:!1,option:"12hr"},url:{field_type:"url",label:"label",placeholder:"Enter URL",default_value:"",is_required:!1,is_unique:!1},currency:{field_type:"currency",label:"label",placeholder:"Enter Currency",default_value:"",is_required:!1,is_unique:!1,option:"inr"},file:{field_type:"file",label:"label",placeholder:"Upload File or Media",is_required:!1,is_unique:!1,max_size:20,default_value:""},geoLocation:{field_type:"geoLocation",label:"label",placeholder:"Enter geo location",default_value:"",is_required:!1,is_unique:!1},image:{field_type:"image",label:"label",placeholder:"Upload Image",is_required:!1,is_unique:!1,max_size:20,default_value:""},section:{field_type:"section",label:"section",section_type:"Default",form_switcher_label:"Form section",form_switcher_name:"",switcher_forms:[{value:"",name:"Form 1",id:null}],is_accordion:!1,members:[]},info:{field_type:"info",label:"label",placeholder:"Add Label Text",default_value:""},relation:{field_type:"relation",label:"label",placeholder:"Add Label Text",is_required:!1,is_unique:!1,module:"",field:"",default_value:""},checkbox:{field_type:"checkbox",label:"label",placeholder:"Add Label Text",is_required:!1,is_checked:!1,title_position:"end",title:"Checkbox"},toggleButton:{field_type:"toggleButton",label:"label",placeholder:"Add Label Text",is_required:!1,is_checked:!1,title_position:"end",title:"Toggle"},radioButton:{field_type:"radioButton",placeholder:"",label:"label",title:"",is_required:!1,title_position:"end",options:[],display:"row",default_value:""},table:{field_type:"table",label:"label",placeholder:"Add Label Text",is_required:!1,table_columns:[],table:"custom"},tagsInput:{field_type:"tagsInput",label:"label",placeholder:"Enter tagsInput",default_value:"",min_length:2,max_length:30,is_multiline:!1,is_required:!0,is_unique:!1}},Ee=[{label:"Text",value:"text",icon:T.Paragraph},{label:"Number",value:"number",icon:T.Hashtag},{label:"Select",value:"select",icon:T.ArrowCircleDown},{label:"Date",value:"date",icon:T.Calendar},{label:"Files & Media",value:"file",icon:T.PaperClip},{label:"URL",value:"url",icon:T.Link},{label:"Email",value:"email",icon:T.Email},{label:"Phone",value:"phone",icon:T.Phone},{label:"Currency",value:"currency",icon:T.DollarCircle},{label:"Time",value:"time",icon:T.Clock},{label:"Table",value:"table",icon:T.Grid},{label:"Geolocation",value:"geoLocation",icon:T.Location},{label:"Check Box",value:"checkbox",icon:T.CheckboxSquare},{label:"Image Upload",value:"image",icon:T.Image},{label:"Relation Field",value:"relation",icon:T.LinkHorizontal},{label:"Info Card",value:"info",icon:T.InfoCircle},{label:"Toggle Button",value:"toggleButton",icon:I.ToggleSwitch},{label:"Radio Button",value:"radioButton",icon:T.RadioButton},{label:"tagsInput",value:"tagsInput",icon:T.Paragraph}],Be=l=>{const[a,n]=t.useState(Ee),[r,i]=t.useState(""),s=e=>{i(e.target.value)};return t.useEffect(()=>{var e;n((e=r)?[...Ee.filter(t=>t.value.includes(e))]:Ee)},[r]),e.jsx(c.Select,{fullWidth:!0,placeholder:"Select Field",size:"small",labelName:"Field Type",renderValue:e=>{var t;return null==(t=Ee.find(t=>t.value===e))?void 0:t.label},handleSearch:()=>s,searchPlaceholder:"Search Attributes",searchValue:r,...l,children:a.map(t=>e.jsx(d.MenuItem,{value:t.value,onKeyDown:e=>e.stopPropagation(),children:e.jsxs(d.Stack,{direction:"row",spacing:1,alignItems:"center",children:[t.icon&&e.jsx(t.icon,{fontSize:"small"}),e.jsx(o.Typography,{type:"s3",color:"theme.secondary.1000",children:t.label})]})}))})},Ae=[1,2,3,4,5,6],Me=[{text:"12 Hour",value:"12hr"},{text:"24 Hour",value:"24hr"}],Fe=[{text:"INR (India)",value:"inr"},{text:"USD (US)",value:"usd"}],$e=new Set(["time","file","geoLocation","image","info","relation"]),De=new Set(["text","number"]),Pe=({option:t,index:l,prefix:a})=>e.jsx(d.MenuItem,{value:t.value,children:t.text||t.label},`${a}-${l}`),ze=({option:t,index:l,prefix:a})=>e.jsx(d.MenuItem,{value:t.value,children:e.jsx(o.Typography,{type:"s3",color:"theme.secondary.1000",children:t.label})},`${a}-${l}`);function Re(l){const{handlePropertyValueUpdate:a,handleColumnSelect:r,handleWidthChange:i,fields:s,element:u}=l,[m,p]=t.useState(u),[h,g]=t.useState(!1),[x,b]=t.useState([]),[y,v]=t.useState(""),j=t.useRef(u),S=t.useRef(s),C=t.useMemo(()=>s&&s!==S.current||!S.current||!s?(S.current=s,s?Object.keys(s).map(e=>({label:w.formatText(e),value:e})):[]):S.current,[s]),_=t.useCallback(e=>{if(!s||!e)return void b(e=>e.length>0?[]:e);const t=s[e];if(null==t?void 0:t.length){const e=t.map(e=>({label:e.field,value:e.field}));b(t=>t.length!==e.length||t.some((t,l)=>{var a,o;return t.value!==(null==(a=e[l])?void 0:a.value)||t.label!==(null==(o=e[l])?void 0:o.label)})?e:t)}else b(e=>e.length>0?[]:e)},[s]),k=t.useCallback(e=>{if(m){if(m.default_value!==e){const t={...m,default_value:e};p(t),a(null,null,e)}e&&(v(""),g(!1))}},[m,a]),T=t.useCallback(e=>{if(!m)return;const t=e.target.value;if(m.field_type!==t){const l={...m,field_type:t};p(l),a(null,null,null,e.target.value)}},[m,a]),I=t.useCallback(e=>{if(!m)return;const t=e.target.value;if(m.option!==t){const e={...m,option:t};p(e),a(null,null,t)}},[m,a]),E=t.useCallback(e=>{const t=e.target.value;(null==m?void 0:m.module)!==t&&(_(t),a(e))},[null==m?void 0:m.module,_,a]),B=t.useCallback((e,t)=>{if(!m)return;const l=Array.isArray(t)?t[0]:t;if(m.custom_width!==l){const e={...m,custom_width:l};p(e),i(l)}},[m,i]),A=t.useCallback(e=>{if(!m)return;const t=e.target.checked;if(m.is_fullwidth!==t){const l={...m,is_fullwidth:t};p(l),a(e)}},[m,a]),M=t.useCallback(e=>{const t=Number(e.target.value);r(t)},[r]),F=t.useCallback(e=>{var t;return["number","currency","geoLocation"].includes(e.field_type)?(null==(t=e.default_value)?void 0:t.toString().replace(/[^0-9]/g,""))||"":e.default_value||""},[]),$=t.useCallback(e=>"text"===e?{min:"Min character count (with spaces)",max:"Max character count (with spaces)"}:{min:"Min number",max:"Max number"},[]),D=t.useCallback(()=>g(!0),[]),P=t.useCallback(()=>{g(!1),v("")},[]),z=t.useCallback(e=>{v(e.target.value)},[]);t.useEffect(()=>{u!==j.current&&(p(u),j.current=u,(null==u?void 0:u.module)&&_(u.module))},[u,_]);const R=t.useMemo(()=>"currency"!==(null==m?void 0:m.field_type)?null:e.jsx(d.Box,{children:e.jsx(d.FormControl,{fullWidth:!0,children:e.jsx(c.Select,{fullWidth:!0,placeholder:"Select Currency",size:"small",onChange:I,defaultValue:m.option,label:"Currency",name:"option",variant:"outlined",children:Fe.map((t,l)=>e.jsx(Pe,{option:t,index:l,prefix:"currency"},`currency-${l}`))})})}),[null==m?void 0:m.field_type,null==m?void 0:m.option,I]),N=t.useMemo(()=>"time"!==(null==m?void 0:m.field_type)?null:e.jsx(d.Box,{children:e.jsx(d.FormControl,{fullWidth:!0,children:e.jsx(c.Select,{fullWidth:!0,placeholder:"Select Time Format",size:"small",onChange:I,defaultValue:m.option,label:"Time Format",name:"option",variant:"outlined",children:Me.map((t,l)=>e.jsx(Pe,{option:t,index:l,prefix:"time"},`time-${l}`))})})}),[null==m?void 0:m.field_type,null==m?void 0:m.option,I]),L=t.useMemo(()=>"relation"!==(null==m?void 0:m.field_type)?null:e.jsxs(e.Fragment,{children:[e.jsx(d.Box,{children:e.jsx(d.FormControl,{fullWidth:!0,children:e.jsx(c.Select,{fullWidth:!0,placeholder:C.length?"Select Relation Module":"No data available",size:"small",onChange:E,value:m.module||"",label:"Relation Module",name:"module",children:C.length?C.map((t,l)=>e.jsx(ze,{option:t,index:l,prefix:"module"},`module-${l}`)):e.jsx(d.MenuItem,{disabled:!0,children:e.jsx(o.Typography,{type:"s3",color:"theme.secondary.1000",children:e.jsx("em",{children:"No data available"})})})})})}),e.jsx(d.Box,{children:e.jsx(d.FormControl,{fullWidth:!0,children:e.jsx(c.Select,{fullWidth:!0,placeholder:m.module?x.length?"Select Relation Field":"No data available":"Select Module First",size:"small",onChange:a,value:m.field||"",label:"Relation Field",disabled:!m.module,name:"field",children:x.length?x.map((t,l)=>e.jsx(ze,{option:t,index:l,prefix:"field"},`field-${l}`)):e.jsx(d.MenuItem,{disabled:!0,children:e.jsx(o.Typography,{type:"s3",color:"theme.secondary.1000",children:e.jsx("em",{children:"No data available"})})})})})})]}),[null==m?void 0:m.field_type,null==m?void 0:m.module,null==m?void 0:m.field,C,x,E,a]);if(!m)return null;const{field_type:O}=m,q=$(O);return e.jsxs(d.Box,{className:"formSection--FieldContainer",children:[e.jsx(d.Box,{children:e.jsx(Be,{variant:"outlined",onChange:T,defaultValue:O,label:"Field Type",disabled:"system"===m.type||!m.is_new})}),e.jsx(d.Box,{children:e.jsx(c.TextField,{fullWidth:!0,label:"Label",is_required:!0,name:"label",type:"text",onChange:a,defaultValue:m.label})}),("file"===O||"image"===O)&&e.jsx(d.Box,{children:e.jsx(c.TextField,{fullWidth:!0,label:"Max File Size (in MB)",name:"max_size",type:"number",onChange:a,defaultValue:m.max_size})}),R,!$e.has(O)&&e.jsxs(e.Fragment,{children:[e.jsx(d.Box,{children:e.jsx(c.TextField,{fullWidth:!0,label:"Placeholder",name:"placeholder",type:"text",onChange:a,defaultValue:m.placeholder})}),e.jsx(d.Box,{children:e.jsx(c.TextField,{fullWidth:!0,label:"Default Value",placeholder:"Default Value",name:"default_value",type:"phone"===O?"tel":"number"===O?"number":"text",onChange:a,defaultValue:F(m)})})]}),N,L,De.has(O)&&e.jsxs(e.Fragment,{children:[e.jsx(d.Box,{children:e.jsx(c.TextField,{fullWidth:!0,label:q.min,name:"min_length",type:"number",onChange:e=>a(e,Number(e.target.value)),defaultValue:m.min_length||m.min||1})}),e.jsx(d.Box,{children:e.jsx(c.TextField,{fullWidth:!0,label:q.max,name:"max_length",type:"number",onChange:e=>a(e,Number(e.target.value)),defaultValue:m.max_length||m.max||("number"===O?1e4:255)})})]}),e.jsx(d.Box,{children:e.jsx(d.FormControl,{fullWidth:!0,children:e.jsx(c.Select,{fullWidth:!0,placeholder:"Select Column Per Row",size:"small",onChange:M,value:m.columns_per_row||1,label:"Select Column Per Row",name:"columns_per_row",variant:"outlined",children:Ae.map((t,l)=>e.jsx(d.MenuItem,{value:t,children:t},`column-${l}`))})})}),e.jsxs(d.Box,{children:[e.jsx(o.Typography,{sx:{color:"black",mb:1},children:"Adjust Width:"}),e.jsx(d.Slider,{value:m.custom_width||12,name:"custom_width",min:1,max:12,step:1,onChange:B,"aria-labelledby":"width-slider",sx:{color:"#4AC08C"},disabled:m.is_fullwidth,marks:!0,valueLabelDisplay:"auto"})]}),"number"===O&&e.jsxs(e.Fragment,{children:[e.jsx(d.Box,{children:e.jsx(c.TextField,{fullWidth:!0,label:"Float Step",name:"float_step",type:"number",step:"0.01",onChange:a,defaultValue:m.float_step})}),e.jsx(d.Box,{children:e.jsx(d.FormControlLabel,{name:"is_negative",control:e.jsx(n.Checkbox,{}),onChange:a,checked:m.is_negative||!1,label:"Allow Negative Numbers"})})]}),"date"===O&&e.jsxs(e.Fragment,{children:[e.jsx(d.Box,{children:e.jsx(d.FormControlLabel,{name:"is_future_dates_allowed",control:e.jsx(n.Checkbox,{}),onChange:a,checked:m.is_future_dates_allowed||!1,label:"Allow Future Dates"})}),e.jsx(d.Box,{children:e.jsx(d.FormControlLabel,{name:"is_past_dates_allowed",control:e.jsx(n.Checkbox,{}),onChange:a,checked:m.is_past_dates_allowed||!1,label:"Allow Past Dates"})})]}),"info"!==O&&e.jsx(d.Box,{children:e.jsx(d.FormControlLabel,{name:"is_required",control:e.jsx(n.Checkbox,{}),onChange:a,checked:m.is_required||!1,label:"This field is required"})}),"email"===O&&e.jsx(d.Box,{children:e.jsx(d.FormControlLabel,{name:"is_unique",control:e.jsx(n.Checkbox,{}),onChange:a,checked:m.is_unique||!1,label:"Is Unique"})}),"text"===O&&e.jsx(d.Box,{children:e.jsx(d.FormControlLabel,{name:"is_multiline",control:e.jsx(n.Checkbox,{}),onChange:a,checked:m.is_multiline||!1,label:"Is Multiline"})}),e.jsx(d.Box,{children:e.jsx(d.FormControlLabel,{name:"is_fullwidth",control:e.jsx(n.Checkbox,{}),onChange:A,checked:m.is_fullwidth||!1,label:"Full Width"})}),"info"===O&&e.jsx(d.Box,{children:e.jsx(c.Button,{variant:"outlined",startIcon:e.jsx(f.Add,{}),onClick:D,className:"formSection--PreviewButton",children:"Add Function"})}),e.jsxs(c.Modal,{fullWidth:!0,onClose:P,open:h,children:[e.jsxs(d.DialogTitle,{children:[e.jsx(o.Typography,{type:"s3",weight:"medium",color:"theme.secondary.1000",children:"Add Function"}),e.jsx(d.IconButton,{edge:"end",onClick:P,size:"small",children:e.jsx(f.Close,{fontSize:"inherit"})})]}),e.jsxs(d.DialogContent,{dividers:!0,children:[e.jsxs(o.Typography,{weight:"medium",type:"s3",color:"theme.secondary.700",sx:{mb:2},children:["Label: ",e.jsx("span",{style:{color:"#1F2125"},children:m.label})]}),e.jsx(c.TextField,{name:"default_value",fullWidth:!0,placeholder:"Add a function",multiline:!0,minRows:4,defaultValue:m.default_value,onChange:z,value:y})]}),e.jsxs(d.DialogActions,{children:[e.jsx(c.Button,{variant:"outlined",onClick:P,style:{color:"black"},children:"Cancel"}),e.jsx(c.Button,{onClick:()=>k(y),children:"Save"})]})]})]})}const Ne=[1,2,3,4,5,6],Le=t.memo(({element:l,handlePropertyValueUpdate:a,handleSelectOptionValueUpdate:r,handleColumnSelect:i,handleWidthChange:s})=>{const[u,m]=t.useState(l.options||[]),[p,h]=t.useState({label:"",value:""}),[g,x]=t.useState(!1);t.useEffect(()=>{JSON.stringify(u)!==JSON.stringify(l.options||[])&&m(l.options||[])},[l.options,u]);const b=t.useMemo(()=>"system"===l.type||!l.is_new,[l.type,l.is_new]),y=t.useMemo(()=>{const e=u.find(e=>e.value===l.default_value);return(null==e?void 0:e.label)||"Select Default"},[u,l.default_value]),v=t.useCallback(e=>{a(null,null,null,e.target.value)},[a]),j=t.useCallback(e=>{a(null,null,e.target.value)},[a]),C=t.useCallback(e=>{const t=e.target.checked;a({target:{name:"is_multiselect",checked:t,value:t}}),t&&l.default_value&&a(null,"default_value",null)},[a,l.default_value]),w=t.useCallback(e=>{const{name:t,value:l}=e.target;h(e=>({...e,[t]:l}))},[]),_=t.useCallback(()=>{if(!p.label.trim()||!p.value.trim())return;if(u.some(e=>e.value===p.value||e.label===p.label))return void S.enqueueSnackbar("Option with this value or label already exists.",{variant:"error"});const e=[...u,{...p}];m(e),r(e),h({label:"",value:""}),x(!1)},[p,u,r]),k=t.useCallback(e=>{const t=u.filter((t,l)=>l!==e);m(t),r(t);const o=u[e];l.default_value===(null==o?void 0:o.value)&&a(null,"default_value",null)},[u,r,l.default_value,a]),I=t.useCallback((e,t)=>{s(t)},[s]);return e.jsxs(d.Box,{className:"formSection--FieldContainer",children:[e.jsx(d.Box,{children:e.jsx(Be,{variant:"outlined",onChange:v,defaultValue:l.field_type,label:"Field Type",disabled:b})}),e.jsx(d.Box,{children:e.jsx(c.TextField,{fullWidth:!0,label:"Label",is_required:!0,name:"label",type:"text",onChange:a,defaultValue:l.label})}),e.jsx(d.Box,{children:e.jsx(c.TextField,{fullWidth:!0,label:"Placeholder",is_required:!0,name:"placeholder",type:"text",onChange:a,defaultValue:l.placeholder})}),e.jsx(d.Box,{children:e.jsx(c.Select,{fullWidth:!0,placeholder:"Select Default",size:"small",name:"default_value",onChange:j,value:l.default_value||"",label:"Default",variant:"outlined",disabled:l.is_multiselect,renderValue:()=>y,children:u.map((t,l)=>e.jsx(d.MenuItem,{value:t.value,children:t.label},`${t.value}-${l}`))})}),e.jsx(d.Box,{children:e.jsx(d.FormControl,{fullWidth:!0,children:e.jsx(c.Select,{fullWidth:!0,placeholder:"Select Column Per Row",size:"small",onChange:i,label:"Select Column Per Row",name:"columnPerRow",variant:"outlined",children:Ne.map(t=>e.jsx(d.MenuItem,{value:t,children:t},t))})})}),e.jsxs(d.Box,{children:[e.jsx(o.Typography,{sx:{color:"black",mb:1},children:"Adjust Width:"}),e.jsx(d.Box,{pr:2,children:e.jsx(d.Slider,{value:l.custom_width||6,min:1,max:12,step:1,onChange:I,"aria-labelledby":"width-slider",sx:{color:"#4AC08C"},marks:!0,valueLabelDisplay:"auto"})})]}),e.jsxs(d.Box,{className:"formSection--SelectOption",children:[e.jsx(o.Typography,{type:"s5",weight:"medium",color:"theme.secondary.800",sx:{mb:.5},children:"Options"}),u.map((t,l)=>e.jsxs(d.Box,{sx:{mb:1,display:"flex",gap:1},children:[e.jsx(c.TextField,{fullWidth:!0,value:`${t.label} (${t.value})`,InputProps:{readOnly:!0}}),e.jsx(d.IconButton,{color:"error",size:"small",onClick:()=>k(l),children:e.jsx(T.Trash,{})})]},`option-${l}`)),g&&e.jsxs(d.Box,{className:"formSection--SelectOption",sx:{mt:.5,p:2,border:"1px solid #ddd",borderRadius:1},children:[e.jsx(d.Box,{sx:{mb:2},children:e.jsx(c.TextField,{fullWidth:!0,label:"Option Label",is_required:!0,name:"label",type:"text",placeholder:"Enter option label",value:p.label,onChange:w})}),e.jsx(d.Box,{sx:{mb:2},children:e.jsx(c.TextField,{fullWidth:!0,label:"Option Value",placeholder:"Enter option value",is_required:!0,name:"value",type:"text",value:p.value,onChange:w})}),e.jsxs(d.Box,{sx:{display:"flex",gap:1},children:[e.jsx(c.Button,{onClick:_,startIcon:e.jsx(f.Add,{}),disabled:!p.label.trim()||!p.value.trim(),children:"Add Option"}),e.jsx(c.Button,{onClick:()=>{x(!1),h({label:"",value:""})},variant:"outlined",children:"Cancel"})]})]}),!g&&e.jsx(c.Button,{onClick:()=>x(!0),variant:"outlined",className:"formSection--Button",startIcon:e.jsx(f.Add,{}),sx:{mt:1},children:"Add Option"})]}),e.jsxs(d.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:[e.jsx(d.FormControlLabel,{name:"is_multiselect",control:e.jsx(n.Checkbox,{}),onChange:C,checked:l.is_multiselect,label:"Enable Multi Select"}),e.jsx(d.FormControlLabel,{name:"is_required",control:e.jsx(n.Checkbox,{}),onChange:a,checked:l.is_required,label:"This field is required"}),e.jsx(d.FormControlLabel,{name:"is_unique",control:e.jsx(n.Checkbox,{}),onChange:a,checked:l.is_unique,label:"Is Unique"}),e.jsx(d.FormControlLabel,{name:"is_fullwidth",control:e.jsx(n.Checkbox,{}),onChange:a,checked:l.is_fullwidth,label:"Full Width"})]})]})});Le.displayName="SelectEditForm";const Oe=l=>{var a;const{handlePropertyValueUpdate:r}=l,[i,s]=t.useState(l.element),[u,m]=t.useState(!1),[p,h]=t.useState(""),g=["section"],x=t.useMemo(()=>{var e;return null==(e=i.switcher_forms)?void 0:e.map(e=>e.name).includes(p)},[i.switcher_forms,p]);return t.useEffect(()=>{s(l.element)},[l.element]),e.jsxs(d.Box,{className:"formSection--FieldContainer",children:[e.jsx("div",{children:e.jsx(c.Select,{fullWidth:!0,placeholder:"Select Field",size:"small",disabled:!0,defaultValue:i.field_type,label:"Field Type",variant:"outlined",children:null==g?void 0:g.map(t=>e.jsx(d.MenuItem,{value:t,children:t}))},i.id)}),e.jsx("div",{children:e.jsx(c.Select,{fullWidth:!0,placeholder:"Select Field",size:"small",name:"section_type",defaultValue:i.section_type,label:"Section Type",variant:"outlined",onChange:e=>r(e),children:Object.values(w.SECTION_TYPES).map(t=>e.jsx(d.MenuItem,{value:t,children:t},t))},i.id)}),e.jsx("div",{children:e.jsx(c.TextField,{fullWidth:!0,label:"Label",is_required:!0,name:"label",type:"text",onChange:r,defaultValue:i.label},i.id)}),e.jsx(d.FormControlLabel,{name:"is_accordion",control:e.jsx(n.Checkbox,{}),onChange:r,checked:i.is_accordion,label:"Is Accordion"},i.id),i.section_type===w.SECTION_TYPES.FORM_SWITCH_SECTION?e.jsxs("div",{className:"formSection--SubFieldContainer",children:[e.jsx("div",{children:e.jsx(c.TextField,{fullWidth:!0,label:"Form label",is_required:!0,name:"form_switcher_label",type:"text",onChange:r,defaultValue:i.form_switcher_label},i.id)}),e.jsxs("div",{children:[e.jsx(o.Typography,{type:"s5",weight:"medium",color:"theme.secondary.800",children:"Forms"}),null==(a=null==i?void 0:i.switcher_forms)?void 0:a.map(t=>e.jsxs("div",{className:"formSection--MultiOptions",children:[e.jsx(c.TextField,{fullWidth:!0,value:t.name,style:{marginBottom:"10px"},name:"switcher_forms",onChange:e=>{var l;const a=null==(l=i.switcher_forms)?void 0:l.map(l=>t.id===l.id?{...l,name:e.target.value}:{...l});r(e,a)}},t.id),e.jsx(E,{style:{fontSize:"1rem",color:"#656669"},onClick:e=>{const l=[...i.switcher_forms].filter(e=>e.id!==t.id);e.target.name="switcher_forms",r(e,l)}})]},i.id))]}),u?e.jsxs("div",{children:[e.jsxs("div",{className:"formSection--MultiOptions formSection--FullWidth",children:[e.jsx("div",{className:"formSection--FullWidth",children:e.jsx(c.TextField,{fullWidth:!0,label:"Form section name",placeholder:"Form section name",is_required:!0,type:"text",value:p,error:x,helperText:x?"Form section name can not duplicate":"",onChange:e=>h(e.target.value)},i.id)}),e.jsx(E,{style:{fontSize:"1rem",color:"#656669"},onClick:()=>{m(!1),h("")}})]},i.id),e.jsx(c.Button,{onClick:e=>{const{uniqueStringId:t}=w.generateRandomId(),l=[...i.switcher_forms,{name:p,id:t}];r(e,l),h(""),m(!1)},name:"switcher_forms",variant:"text",className:"formSection--Button",disabled:x||!p,startIcon:e.jsx(f.Add,{}),children:"Add"})]}):null,u?null:e.jsx(c.Button,{onClick:()=>m(!0),variant:"text",className:"formSection--Button",startIcon:e.jsx(f.Add,{}),children:"Add forms"})]}):null]},i.id)};function qe(l){const[a,r]=t.useState(!1),{handlePropertyValueUpdate:i,handleSelectOptionValueUpdate:s,handleColumnSelect:u,handleWidthChange:m}=l,p=[1,2,3,4,5,6],[h,g]=t.useState(l.element.options||[]),[x,b]=t.useState(l.element),y="radioButton"!==x.field_type,[v,j]=t.useState({label:"",value:"",is_checked:!1}),S=e=>{const t=e.target.name,l=e.target.value,a={...v};a[t]=l,j(a)},C=e=>{x.default_value=e.target.value,i(null,null,e.target.value)};return t.useEffect(()=>{b(l.element),g(l.element.options||[])},[l.element]),t.useEffect(()=>{j({label:"",value:"",is_checked:!1}),r(!1),s(h)},[h]),e.jsxs(d.Box,{className:"formSection--FieldContainer",children:[e.jsx("div",{children:e.jsx(Be,{variant:"outlined",onChange:e=>{x.field_type=e.target.value,i(null,null,null,e.target.value)},defaultValue:x.field_type,label:"Field Type",disabled:"system"===x.type||!x.is_new},x.id)},x.id),e.jsx("div",{children:e.jsx(c.TextField,{fullWidth:!0,label:"Label",is_required:!0,name:"label",type:"text",onChange:i,defaultValue:x.label},x.id)},x.id),e.jsx("div",{children:e.jsx(d.Select,{variant:"outlined",fullWidth:!0,placeholder:"Select Default",size:"small",name:"options",onChange:()=>C,defaultValue:x.default_value,label:"Default",disabled:!h.length,children:null==h?void 0:h.map((t,l)=>e.jsx(d.MenuItem,{value:t.value,children:t.label},l))},x.id)},x.id),e.jsx(d.FormControl,{children:e.jsx(d.Select,{fullWidth:!0,placeholder:"Select Column Per Row",size:"small",onChange:u,label:"Select Column Per Row",name:"option",variant:"outlined",children:null==p?void 0:p.map((t,l)=>e.jsx(d.MenuItem,{value:t,children:t},l))},x.id)}),e.jsxs(d.Box,{children:[e.jsx(o.Typography,{sx:{color:"black"},children:"Adjust Width:"}),e.jsx(d.Slider,{value:null==x?void 0:x.custom_width,name:"custom_width",min:1,max:12,step:1,onChange:(e,t)=>m(t),"aria-labelledby":"width-slider",sx:{color:"#4AC08C"}})]}),e.jsxs("div",{className:"formSection--SelectOption",children:[e.jsx(o.Typography,{type:"s5",weight:"medium",color:"theme.secondary.800",children:"Options"}),h.map((t,l)=>e.jsxs("div",{className:"formSection--MultiOptions",children:[e.jsx(c.TextField,{fullWidth:!0,value:`${t.label} (${t.value})`,InputProps:{readOnly:!0}},l),e.jsx(E,{style:{fontSize:"1rem",color:"#656669"},onClick:()=>{g([...h.filter((e,t)=>t!==l)])}})]}))]}),a?e.jsxs("div",{className:"formSection--SelectOption",children:[e.jsx("div",{children:e.jsx(c.TextField,{fullWidth:!0,label:"Label",is_required:!0,name:"label",type:"text",placeholder:"Label",defaultValue:v.label,onChange:S})}),e.jsx("div",{children:e.jsx(c.TextField,{fullWidth:!0,label:"Value",placeholder:"Value",is_required:!0,name:"value",type:"text",defaultValue:v.value,onChange:S})}),e.jsx(d.Button,{onClick:()=>g([...h,{...v}]),disabled:!!h.find(e=>e.value===v.value),variant:"text",className:"formSection--Button",startIcon:e.jsx(f.Add,{}),children:"Add"})]}):e.jsx(d.Button,{onClick:()=>r(!0),variant:"text",className:"formSection--Button",startIcon:e.jsx(f.Add,{}),children:"Add Option"}),e.jsxs(d.FormControl,{children:[e.jsx(o.Typography,{type:"s4",color:"theme.secondary.800",children:"Display style"}),e.jsxs(d.RadioGroup,{row:!0,"aria-labelledby":"demo-radio-buttons-group-label",name:"display",onChange:i,defaultValue:x.display,children:[e.jsx(d.FormControlLabel,{value:"row",control:e.jsx(n.Radio,{size:"small"}),label:"Row",slotProps:{typography:{variant:"body2"}}}),e.jsx(d.FormControlLabel,{value:"column",control:e.jsx(n.Radio,{size:"small"}),label:"Column",slotProps:{typography:{variant:"body2"}}})]},x.id)]}),e.jsx("div",{children:e.jsx(c.TextField,{fullWidth:!0,label:"Title",is_required:!0,name:"title",type:"text",onChange:i,defaultValue:x.title},x.id)},x.id),e.jsxs(d.FormControl,{disabled:!y,children:[e.jsx(o.Typography,{type:"s4",color:"theme.secondary.800",children:"Title Position"}),e.jsxs(d.RadioGroup,{row:!0,"aria-labelledby":"demo-radio-buttons-group-label",name:"title_position",onChange:i,defaultValue:y?"end":"",children:[e.jsx(d.FormControlLabel,{value:"start",control:e.jsx(n.Radio,{size:"small"}),label:"Start",slotProps:{typography:{variant:"body2"}}}),e.jsx(d.FormControlLabel,{value:"end",control:e.jsx(n.Radio,{size:"small"}),label:"End",slotProps:{typography:{variant:"body2"}}})]},x.id)]}),e.jsx(d.FormControlLabel,{name:"is_required",control:e.jsx(n.Checkbox,{}),onChange:i,checked:x.is_required,label:"This field is required"},x.id),e.jsx(d.FormControlLabel,{name:"is_unique",control:e.jsx(n.Checkbox,{}),onChange:i,checked:x.is_unique,label:"Is Unique"},x.id),e.jsx(d.FormControlLabel,{name:"is_fullwidth",control:e.jsx(n.Checkbox,{}),onChange:i,checked:null==x?void 0:x.is_fullwidth,label:"Full Width "},x.id)]},x.id)}const We=({handlePropertyValueUpdate:l,element:a,handleColumnsUpdate:o,fields:n})=>{const[r,i]=t.useState(a),[s,u]=t.useState([]);return t.useEffect(()=>{i(a)},[a]),t.useEffect(()=>{if(r&&r.table&&n){const e=n[r.table];let t=[];t=e&&(null==e?void 0:e.length)?e.map((e,t)=>({header:w.formatText(e.field),accessorKey:e.field,visible:!(t>3),type:e.type})):[{header:"Column 1",accessorKey:"column_1",visible:!0},{header:"Column 2",accessorKey:"column_1",visible:!0}],t&&o(t)}},[null==r?void 0:r.table]),t.useEffect(()=>{if(n){const e=Object.keys(n).map(e=>({label:w.formatText(e),value:e}));u(e)}},[n]),r?e.jsxs(d.Box,{className:"formSection--FieldContainer",children:[e.jsx("div",{children:e.jsx(Be,{variant:"outlined",onChange:e=>{r&&(r.field_type=e.target.value,l(null,null,null,e.target.value))},defaultValue:r.field_type,disabled:"system"===r.type||!r.is_new},r.id)},r.id),e.jsx("div",{children:e.jsx(c.TextField,{fullWidth:!0,label:"Label",is_required:!0,name:"label",type:"text",onChange:l,defaultValue:r.label},r.id)},r.id),e.jsx("div",{children:e.jsx(c.Select,{variant:"outlined",label:"Table",fullWidth:!0,placeholder:"Select Table",size:"small",name:"table",defaultValue:r.table,disabled:"system"===r.type,onChange:e=>{l(e)},renderValue:e=>{var t;return null==(t=s.find(t=>t.value===e))?void 0:t.label},children:null==s?void 0:s.map(t=>e.jsx(d.MenuItem,{value:t.value,children:t.label}))},r.id)},r.id)]},r.id):null},He=t.memo(({field:l,index:a,gridItemSize:o,activeMember:r,control:i,t:s,element:u,images:m,elementJSON:p,remove:h,move:g,handleElementSelection:x,setElementSwap:b,handleDuplicateElement:f,setSelectedHoc:y,setActiveMember:v})=>{const j=t.useMemo(()=>({activeIndex:r===a,removeElement:h,index:a,onClick:x,swap:g,elementSwap:()=>b(!0),handleDuplicate:f,setElementHoc:()=>{y(""),v(void 0)}}),[r,a,h,x,g,b,f,y,v]),S=t.useMemo(()=>({key:l.id,position:a,placeholder:s(l.placeholder||""),label:s(l.label),formControl:i,name:"message",fieldArrayName:"members",required:l.is_required,formType:"builder",typeOfField:l.type,disabled:!0}),[l.id,l.placeholder,l.label,l.is_required,l.type,a,s,i]),C=t.useCallback(()=>{const{field_type:t}=l;switch(t){case u.text.field_type:return e.jsx(c.DynamicInput,{...S,type:t,defaultValue:l.default_value,is_multiline:l.is_multiline,min:l.min_length,max:l.max_length});case u.email.field_type:return e.jsx(c.DynamicInput,{...S,type:t,defaultValue:l.default_value,endIcon:e.jsx("img",{src:m.sms,alt:"email"})});case u.number.field_type:return e.jsx(c.DynamicInput,{...S,type:t,defaultValue:l.default_value,min:l.min_length,max:l.max_length,float_step:l.float_step});case u.phone.field_type:return e.jsx(n.DynamicPhone,{...S,type:t,default_value:l.default_value});case u.select.field_type:return e.jsx(n.DynamicSelect,{...S,options:l.options,defaultValue:l.default_value,is_multiselect:l.is_multiselect});case u.date.field_type:return e.jsx(n.DynamicDate,{...S,defaultValue:l.default_value,is_future_dates_allowed:l.is_future_dates_allowed,is_past_dates_allowed:l.is_past_dates_allowed,disable:!0});case u.time.field_type:return e.jsx(n.DynamicTime,{...S,option:l.option});case u.url.field_type:return e.jsx(c.DynamicInput,{...S,type:t,defaultValue:l.default_value,endIcon:e.jsx("img",{src:m.url,alt:"url"})});case u.currency.field_type:return e.jsx(c.DynamicInput,{...S,type:t,defaultValue:l.default_value,endIcon:e.jsx("img",{src:m.dollar,alt:"currency"})});case u.file.field_type:case u.image.field_type:return e.jsx(n.DynamicMedia,{...S,type:t,max_size:l.max_size});case u.geoLocation.field_type:return e.jsx(c.DynamicInput,{...S,type:t,defaultValue:l.default_value,endIcon:e.jsx("img",{src:m.location,alt:"location"})});case u.relation.field_type:return e.jsx(c.DynamicInput,{...S,type:t,defaultValue:l.default_value,is_multiline:l.is_multiline,min:l.min_length,max:l.max_length,label:e.jsxs("span",{className:"formSection--Relation","data-position":a,"data-name":`members.${a}.message`,children:[s(l.label),e.jsx("img",{src:m.relation,alt:"relation"})]})});case u.info.field_type:return e.jsx(n.DynamicInfo,{...S,defaultValue:l.default_value});case u.toggleButton.field_type:return e.jsx(n.DynamicToggleButton,{...S,title:s(l.title||""),titlePosition:null==p?void 0:p.title_position});case u.radioButton.field_type:return e.jsx(n.DynamicRadioButton,{...S,options:l.options,display:l.display,titlePosition:null==p?void 0:p.title_position});case u.tagsInput.field_type:return e.jsx(c.DynamicInput,{...S,type:t,defaultValue:l.default_value,is_multiline:l.is_multiline,min:l.min_length,max:l.max_length});case u.checkbox.field_type:return e.jsx(n.DynamicCheckBox,{...S,title:s(l.title||""),titlePosition:l.title_position});case u.table.field_type:return e.jsx(n.DynamicTable,{...S,columns:l.table_columns||(null==p?void 0:p.table_columns)||[]});default:return console.warn(`Unknown field type: ${t}`),null}},[l,S,u,m,p,s,a]);return e.jsx(d.Grid,{item:!0,xs:o,children:e.jsx(n.DynamicElementHOC,{...j,element:l.field_type,children:C()})})});He.displayName="FormField";const Ve=t.memo(({sectionMembers:l,members:a,activeMember:o,control:n,t:r,element:i,images:s,elementJSON:d,remove:c,move:u,handleElementSelection:m,setElementSwap:p,handleDuplicateElement:h,setSelectedHoc:g,setActiveMember:x})=>{const b=t.useCallback(e=>e.is_fullwidth||"table"===e.field_type?12:e.custom_width?e.custom_width:6,[]),f=t.useMemo(()=>l.map(t=>{const l=a.findIndex(e=>e===t),f=b(t);return e.jsx(He,{field:t,index:l,gridItemSize:f,activeMember:o,control:n,t:r,element:i,images:s,elementJSON:d,remove:c,move:u,handleElementSelection:m,setElementSwap:p,handleDuplicateElement:h,setSelectedHoc:g,setActiveMember:x},`${t.id}-${l}`)}),[l,a,o,n,r,i,s,d,c,u,m,p,h,g,x,b,null==d?void 0:d.field_type]);return e.jsx(e.Fragment,{children:f})});Ve.displayName="FormFields";const Ge={accounting:a.PathnameAccounting.FORMS,inventory:a.PathnameInventory.FORMS,manufacturing:a.PathnameManufacturing.FORMS,procurement:a.PathnamePurchase.FORMS,crm:a.PathnameCrm.FORMS,rental:a.PathnameRental.FORMS,user:B.PathnameUsers.FORMS,hrms:B.PathnameHrms.FORMS},Ue=e=>e.split("_").map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(" "),Ke=(e,t)=>{var l,a;if(null==(l=e.table_columns)?void 0:l.length)return e.table_columns;if(!e.table||!(null==(a=t.fields)?void 0:a[e.table]))return[{header:"Column 1",accessorKey:"column_1",visible:!0},{header:"Column 2",accessorKey:"column_2",visible:!0}];const o=t.fields[e.table];return Array.isArray(o)&&0!==o.length?o.map((e,t)=>({header:Ue(e.field),accessorKey:e.field,visible:t<=3})):[{header:"Column 1",accessorKey:"column_1",visible:!0},{header:"Column 2",accessorKey:"column_2",visible:!0}]},Je=(e,t)=>e.flatMap(e=>e.members.map(e=>"table"===e.field_type?{...e,table_columns:Ke(e,t)}:{...e})),Ye=e=>e.map(({field_type:e,label:t,is_accordion:l,id:a,remove_section:o,form_switcher_label:n,form_switcher_name:r,is_section_field:i,section_type:s,switcher_forms:d})=>({field_type:e,label:t,is_accordion:l,id:a,remove_section:o,form_switcher_label:n,form_switcher_name:r,is_section_field:i,section_type:s,switcher_forms:d})),Ze=(e,t=0,l,a,o)=>{const{removeSection:n,remove:r}=o;try{if(n(),r(),e.tab)Xe(e.tab,t,l,o);else if(e.section)Qe(e.section,l,o);else{if(!e.tabsData||!a)throw new Error("Invalid data format: Missing required properties (tab, section, or tabsData)");et(a,t,o)}}catch(i){console.error("Error processing data:",i),alert(i instanceof Error?i.message:"An error occurred while processing data")}},Xe=(e,t,l,a)=>{const{setTabsData:o,append:n,appendSection:r}=a;o(e);const i=e.find(e=>e.tab_order===t+1);if(!(null==i?void 0:i.data))return void console.warn(`No active tab found for tab order: ${t+1}`);const s=Ye(i.data);n(Je(i.data,l)),r(s)},Qe=(e,t,l)=>{const{append:a,appendSection:o}=l,n=Ye(e);a(Je(e,t)),o(n)},et=(e,t,l)=>{const{append:a,appendSection:o}=l,n=e.find(e=>e.tab_order===t+1);if(!(null==n?void 0:n.data))return void console.warn(`No active tab found for tab order: ${t+1}`);const r=Ye(n.data),i=n.data.flatMap(e=>e.members.map(e=>({...e})));i.length>0&&a(i),r.length>0&&o(r)},tt=(e,l,a=0,o)=>{const{removeSection:n,remove:r,append:i}=o;t.useEffect(()=>{var t;let d=null;if(null==(t=null==e?void 0:e.formData)?void 0:t.length)try{d=s.formBuilderDeConversion(e.formData)}catch(c){console.error("Error converting form data:",c)}if(!d)return n(),r(),void i([]);try{l.length>0?Ze({tabsData:l},a,e,l,o):d.tab?Ze(d,a,e,l,o):d.section?Ze(d,0,e,l,o):(console.warn("Invalid data structure in initialData"),n(),r(),i([]))}catch(c){console.error("Error processing form data:",c),n(),r(),i([])}},[a,JSON.stringify(null==e?void 0:e.formData),l.length])},lt=e=>{try{const t=(e=>{if(!(e in Ge))throw new Error(`Invalid module: ${e}`);return Ge[e]})(e);return`/dashboard/${e}${t}`}catch(t){throw console.error("Error generating module path:",t),t}},at=e=>!isNaN(Number(e))&&isFinite(Number(e)),ot=e=>JSON.parse(JSON.stringify(e)),nt=(e="")=>({uniqueStringId:`${Date.now()}${e}${Math.random().toString(36).substr(2,9)}`}),rt=new class{generateScopeId(){return`email-tpl-${Date.now()}-${Math.random().toString(36).substring(2,11)}`}scopeCSS(e,t){return e&&t?this.parseCSS(e).map(e=>this.scopeRule(e,t)).join("\n"):e}parseCSS(e){const t=[];let l="",a=0,o=!1;for(let n=0;n<e.length;n++){const r=e[n],i=e[n+1];"/"!==r||"*"!==i?o&&"*"===r&&"/"===i?(o=!1,l+=r):(l+=r,o||("{"===r?a++:"}"===r&&(a--,0===a&&l.trim()&&(t.push(l.trim()),l="")))):(o=!0,l+=r)}return l.trim()&&t.push(l.trim()),t}scopeRule(e,t){const l=e.indexOf("{");if(-1===l)return e;const a=e.substring(0,l).trim(),o=e.substring(l);return`${a.split(",").map(e=>e.trim()).map(e=>this.scopeSelector(e,t)).join(", ")} ${o}`}scopeSelector(e,t){return e.startsWith(":root")||e.startsWith(":host")||e.startsWith("@")?e:`.${t} ${e}`}wrapHTMLWithScope(e,t){return e&&t?`<div class="${t}">\n${e}\n</div>`:e}extractInlineStyles(e){const t=new Map;return(new DOMParser).parseFromString(e,"text/html").querySelectorAll("[style]").forEach((e,l)=>{const a=e.getAttribute("style");if(a){const o=this.parseInlineStyles(a),n=`${e.tagName.toLowerCase()}-${l}`;t.set(n,o)}}),t}parseInlineStyles(e){const t={};return e.split(";").filter(e=>e.trim()).forEach(e=>{const l=e.indexOf(":");if(l>-1){const a=e.substring(0,l).trim(),o=e.substring(l+1).trim();t[a]=o}}),t}mergeStyles(e,t){return{...e,...t}}scopeTemplate(e,t=""){const l=this.generateScopeId();return{scopeId:l,scopedCSS:t?this.scopeCSS(t,l):"",wrappedHTML:this.wrapHTMLWithScope(e,l)}}},it=(e,t)=>{const l=`${e}${M.TEMPLATE_EDITOR_PATHS.TEMPLATES_LIST(t)}`,a=`${e}${M.TEMPLATE_EDITOR_PATHS.TEMPLATES_ADD(t)}`,o=`${e}${M.TEMPLATE_EDITOR_PATHS.TEMPLATES_EDIT(t)}`;return{LIST:l,ADD_TEMPLATE:e=>a.replace(":id",e),EDIT_TEMPLATE:(e,t)=>o.replace(":id",e).replace(":template_id",t)}},st=(e,t=[],l=[],a=!1,o)=>{const n=t&&(null==t?void 0:t.length)?dt(t,"header"):"",r=l&&(null==l?void 0:l.length)?dt(l,"footer"):"";let i=`\n <html>\n <head>\n <style>\n .email-container {\n margin: 0 auto;\n margin-bottom: 20px;\n background-color: #fff;\n border-radius: 8px;\n max-width: ${a?"65%":"800px"};\n width: 100%;\n }\n a {\n color: #007bff !important;\n text-decoration: none !important;\n }\n a:hover {\n text-decoration: underline;\n }\n * {\n margin: 0;\n padding: 0;\n box-sizing: border-box;\n }\n\n body {\n font-family: "Inter", sans-serif !important;\n font-size: 16px;\n font-weight: 400;\n color: #00011c;\n font-style: normal;\n }\n\n img {\n display: block;\n height: auto;\n }\n\n table,\n tr,\n td {\n border-collapse: collapse;\n }\n\n a {\n text-decoration: none;\n }\n\n table.our-details,\n .our-details td,\n .our-details th {\n border: 1px solid #d3d3d4;\n }\n\n table.amount-word-table,\n table.amount-word-table td,\n table.amount-word-table th {\n border: 1px solid #d6d6d6;\n }\n\n .amount-word-table thead th {\n background-color: #f5f6f5;\n }\n\n .amount-word-table thead td {\n background-color: #f5f6f5;\n }\n\n .amount-word-table tbody tr:nth-child(even) {\n background-color: #f5f6f5;\n }\n\n .amount-word-table tbody tr td {\n border-top: 0;\n border-bottom: 0;\n }\n\n .deliver-table thead th {\n background-color: transparent;\n }\n </style>\n </head>\n <body>\n <div class="email-container ${o||rt.generateScopeId()}">\n ${n}\n ${n?"<hr/>":""}\n `;const s=[];let d=[],c=null;for(const u of e)u.isSplitPair&&0!==u.splitGroupId?(c!==u.splitGroupId&&d.length>0&&(s.push(d),d=[]),d.push(u),c=u.splitGroupId):(d.length>0&&(s.push(d),d=[],c=null),s.push([u]));d.length>0&&s.push(d);for(const u of s)if(1!==u.length||u[0].isSplitPair){i+='<table style="width: 100%; border-collapse: collapse;"><tr>';for(const e of u)i+=`<td style="width: ${e.splitWidth}%; vertical-align: top; padding: 10px;">\n ${e.content}\n </td>`;i+="</tr></table>"}else i+=`<div style="padding: 10px;">${u[0].content}</div>`;return i+=`\n ${r?"<hr/>":""}\n ${r}\n </div></body></html>`,i},dt=(e,t="header",l)=>{let a=`<${t} class="${t}${l?` ${l}`:""}">`;const o=[];let n=[],r=null;for(const i of e)i.isSplitPair&&0!==i.splitGroupId?(r!==i.splitGroupId&&n.length>0&&(o.push(n),n=[]),n.push(i),r=i.splitGroupId):(n.length>0&&(o.push(n),n=[],r=null),o.push([i]));n.length>0&&o.push(n);for(const i of o)if(1!==i.length||i[0].isSplitPair){a+='<table style="width: 100%; border-collapse: collapse;"><tr>';for(const e of i)a+=`<td style="width: ${e.splitWidth}%; vertical-align: top; padding: 10px;">\n ${e.content}\n </td>`;a+="</tr></table>"}else a+=`<div style="padding: 10px;">${i[0].content}</div>`;return a+=`</${t}>`,a},ct=(e,t)=>{const l=document.createElement("div");l.innerHTML=e;const a=l.firstChild;if(!a)return{};if((null==a?void 0:a.getAttribute)instanceof Function==0)return{};const o=null==a?void 0:a.getAttribute("style"),n=(null==a?void 0:a.attributes)||[],r=Array.from(n).reduce((e,t)=>(e[t.name]=t.value,e),{});if(!o)return{};const i={};return o.split(";").filter(e=>""!==e.trim()).forEach(e=>{const[t,l]=e.split(":").map(e=>e.trim());if(t&&l){const e=t.replace(/-([a-z])/g,e=>e[1].toUpperCase());i[e]=l}}),r.styles=i,r},ut=new Set(["background","background-color","border","border-style","border-collapse","border-top","border-right","border-bottom","border-left","border-color","border-radius","color","display","font","font-family","font-size","font-style","font-weight","height","line-height","margin","margin-top","margin-right","margin-bottom","margin-left","padding","padding-top","padding-right","padding-bottom","padding-left","text-align","text-decoration","vertical-align","width","max-width","min-width","max-height","min-height"]),mt=(e,t="")=>e&&"object"==typeof e?Object.entries(e).reduce((e,[l,a])=>{if(null==a)return e;const o=t?`${t}-${l}`:l;if("object"==typeof a&&!Array.isArray(a))return e.push(mt(a,o)),e;const n=o.replace(/([A-Z])/g,"-$1").toLowerCase();if(!ut.has(n)&&"fullWidth"!==l&&"alignment"!==l)return e;if("fullWidth"===l&&!0===a)return e.push("width: 100%"),e;if("alignment"===l&&"string"==typeof a)return e.push(`text-align: ${a}`),e;if("boolean"==typeof a)return e;const r="number"!=typeof a||["z-index","opacity","line-height"].includes(l)?a:`${a}px`;return e.push(`${n}: ${r}`),e},[]).filter(Boolean).join("; "):"",pt=(e,t={})=>{let l="";const a=M.initialStyles[e]||{},o=mt(a);switch(e){case"heading":l=`<h1 style="${o}">Heading 1</h1>`;break;case"heading-2":l=`<h2 style="${o}">Heading 2</h2>`;break;case"heading-3":l=`<h3 style="${o}">Heading 3</h3>`;break;case"heading-4":l=`<h4 style="${o}">Heading 4</h4>`;break;case"text":l=`<p style="${o}">Hello, enter your text here...</p>`;break;case"image":l=`<img src="${(null==t?void 0:t.src)||""}" alt="${(null==t?void 0:t.alt)||""}" style="${o};" />`;break;case"buttons":t.text=(null==t?void 0:t.text)||"Button text",l=`<button style="${o}">${t.text}</button>`;break;case"divider":l=`<hr style="${o}" />`;break;case"table":{const{border:e,borderStyle:t,borderColor:o,...n}=a,r=mt(a.is_bordered?a:n),i=mt(a.tHead),s=mt(a.tBody),d=mt({...a.thCells,border:e,borderStyle:t,borderColor:o}),c=mt({...a.tbCells,border:e,borderStyle:t,borderColor:o});l=`\n <table style="${r}">\n <thead style="${i}">\n <tr style="background-color: #f5f5f5;">\n <th style="${d}"></th>\n <th style="${d}"></th>\n <th style="${d}"></th>\n </tr>\n </thead>\n <tbody style="${s}">\n <tr>\n <td style="${c}"></td>\n <td style="${c}"></td>\n <td style="${c}"></td>\n </tr>\n </tbody>\n </table>\n `;break}case"signature":l=`<div style="${o}">Signature: <input type='text' style="border:0; border-bottom:1px solid black" class='signature-input'/></div>`;break;case"qr-code":t.placeholder=(null==t?void 0:t.placeholder)||"{{qr_data}}",l=`<div style="background-color: #f5f5f5; padding: 16px; text-align: center; color: #666666;">${t.placeholder}</div>`;break;case"bar-code":t.placeholder=(null==t?void 0:t.placeholder)||"{{barcode_data}}",l=`<div style="background-color: #f5f5f5; padding: 16px; text-align: center; color: #666666;">${t.placeholder}</div>`;break;default:l='<p style="font-size: 16px; color: #333333; line-height: 1.5;">New section</p>'}return ct(l),{content:l,type:e,attributes:{...t||{},styles:a}}},ht=({onSave:t,onPreview:a,preview:n,editHtml:r,onEditHtml:i,sections:s,isEditingHeaderFooter:u,onEditModeChange:m,setIsEditingHeaderFooter:p,onSaveHeaderFooter:h,modulePath:x,type:b,mode:y="add",templateData:v,isSaving:j=!1,editMode:S,fromPreview:C=!1,zoom:w,onZoomIn:_,onZoomOut:k,onResetZoom:I})=>{const E=it(x,b);return e.jsx(d.AppBar,{position:"static",color:"default",elevation:0,sx:{borderColor:"divider",bgcolor:"background.paper"},children:e.jsxs(d.Toolbar,{variant:"dense",sx:{justifyContent:"space-between",p:3},children:[e.jsxs(d.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(d.Link,{component:l.Link,to:E.LIST,underline:"hover",color:"text.secondary",sx:{fontSize:"0.875rem"},children:e.jsx(o.Typography,{type:"s5",color:"theme.secondary.800",children:"email"===b?"Emails":"PDF"})}),e.jsx(o.Typography,{type:"s5",weight:"medium",color:"theme.secondary.1000",children:"/"}),e.jsxs(o.Typography,{type:"s5",weight:"medium",color:"theme.secondary.1000",children:["add"===y?"Add New":S?"Edit":"Preview"," Template"]}),v&&(null==v?void 0:v.name)&&e.jsxs(e.Fragment,{children:[e.jsx(o.Typography,{type:"s5",weight:"medium",color:"theme.secondary.1000",children:"/"}),e.jsx(o.Typography,{type:"s5",weight:"medium",color:"theme.secondary.1000",children:null==v?void 0:v.name})]})]}),e.jsxs(d.Stack,{direction:"row",spacing:1,alignItems:"center",children:[n&&e.jsxs(e.Fragment,{children:[e.jsxs(d.Box,{sx:{display:"flex",alignItems:"center",gap:1,borderRadius:1,bgcolor:"rgba(74, 192, 140, 0.08)",border:"1px solid rgba(74, 192, 140, 0.2)"},children:[e.jsx(d.IconButton,{size:"small",onClick:k,disabled:w<=50,color:"#4AC08C",sx:{color:"#4AC08C","&:hover":{bgcolor:"rgba(74, 192, 140, 0.15)"},"&.Mui-disabled":{opacity:.3,color:"#4AC08C"}},children:e.jsx(f.ZoomOut,{fontSize:"small"})}),e.jsxs(o.Typography,{type:"s5",weight:"medium",sx:{minWidth:"50px",textAlign:"center",color:"#4AC08C"},children:[w,"%"]}),e.jsx(d.IconButton,{size:"small",onClick:_,disabled:w>=150,sx:{color:"#4AC08C","&:hover":{bgcolor:"rgba(74, 192, 140, 0.15)"},"&.Mui-disabled":{opacity:.3,color:"#4AC08C"}},children:e.jsx(f.ZoomIn,{fontSize:"small"})}),e.jsx(d.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5,bgcolor:"rgba(74, 192, 140, 0.3)"}}),e.jsx(d.IconButton,{size:"small",onClick:I,disabled:100===w,title:"Reset Zoom",sx:{color:"#4AC08C","&:hover":{bgcolor:"rgba(74, 192, 140, 0.15)"},"&.Mui-disabled":{opacity:.3,color:"#4AC08C"}},children:e.jsx(f.ZoomOutMap,{fontSize:"small"})})]}),e.jsx(d.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:1}})]}),C?S?e.jsx(e.Fragment,{children:u?e.jsxs(e.Fragment,{children:[e.jsx(c.Button,{onClick:()=>p(!1),size:"small",variant:"outlined",sx:e=>({color:`${e.palette.theme.secondary[1e3]} !important`}),children:"Cancel Editing"}),e.jsx(c.Button,{variant:"contained",onClick:h,size:"small",sx:{boxShadow:"none"},children:"Save Changes"})]}):e.jsxs(e.Fragment,{children:[e.jsx(c.Button,{onClick:()=>p(!0),size:"small",variant:"outlined",sx:e=>({color:`${e.palette.theme.secondary[1e3]} !important`}),startIcon:e.jsx(T.Edit,{fontSize:"small"}),disabled:n,children:"Edit Header/Footer"}),e.jsx(c.Button,{onClick:a,size:"small",variant:"outlined",sx:e=>({color:`${e.palette.theme.secondary[1e3]} !important`}),startIcon:n?e.jsx(g.EyeOff,{fontSize:"small"}):e.jsx(g.Eye,{fontSize:"small"}),disabled:!(null==s?void 0:s.length),children:"Preview"}),e.jsx(c.Button,{variant:"contained",onClick:t,size:"small",sx:{boxShadow:"none"},disabled:!(null==s?void 0:s.length),children:"Save"}),e.jsx(c.Button,{onClick:()=>m&&m(),size:"small",variant:"outlined",sx:e=>({color:`${e.palette.theme.secondary[1e3]} !important`}),children:"Cancel"})]})}):e.jsx(c.Button,{variant:"contained",onClick:()=>m&&m(),size:"small",sx:{boxShadow:"none"},startIcon:e.jsx(T.Edit,{fontSize:"small"}),disabled:!(null==s?void 0:s.length),children:"Edit"}):e.jsxs(e.Fragment,{children:[e.jsx(c.Button,{onClick:()=>p(!0),size:"small",variant:"outlined",sx:e=>({color:`${e.palette.theme.secondary[1e3]} !important`}),startIcon:e.jsx(T.Edit,{fontSize:"small"}),disabled:n,children:"Edit Header/Footer"}),e.jsx(c.Button,{onClick:a,size:"small",variant:"outlined",sx:e=>({color:`${e.palette.theme.secondary[1e3]} !important`}),startIcon:n?e.jsx(g.EyeOff,{fontSize:"small"}):e.jsx(g.Eye,{fontSize:"small"}),disabled:!(null==s?void 0:s.length),children:"Preview"}),e.jsx(c.Button,{onClick:i,size:"small",variant:r?"contained":"outlined",color:r?"primary":"inherit",sx:e=>({color:r?void 0:`${e.palette.theme.secondary[1e3]} !important`}),startIcon:e.jsx(A,{fontSize:"small"}),disabled:!(null==s?void 0:s.length)||n,children:r?"Exit HTML Edit":"Edit HTML"}),e.jsx(c.Button,{variant:"contained",onClick:t,size:"small",sx:{boxShadow:"none"},disabled:!(null==s?void 0:s.length)||j,children:j?"Saving...":"Save"})]})]})]})})},gt=t.lazy(()=>Promise.resolve().then(()=>require("./custom-editor-CqKvR1Cc.js"))),xt=({isOpen:l,setIsOpen:a,modalProps:n,section:r,placeholders:i,handleSave:s,handleAddPlaceholder:u,handleEditorReady:m})=>{const p=()=>{a(null)};return e.jsxs(c.Modal,{open:l,onClose:p,maxWidth:"lg",maxHeight:"md",fullWidth:!0,...n,children:[e.jsxs(d.DialogTitle,{className:"editSectionModal--DialogTitle",children:[e.jsx(o.Typography,{type:"s3",color:"inherit",weight:"medium",children:"Edit Content"}),e.jsxs(d.Box,{display:"flex",alignItems:"center",gap:1,position:"absolute",right:"1%",top:"4px",children:[e.jsx(c.Select,{displayEmpty:!0,value:"",size:"small",renderValue:()=>"Add placeholder",fullWidth:!0,sx:{bgcolor:"white",borderRadius:1,"& .MuiSelect-select":{py:.75}},onChange:e=>{e.target.value&&(u(e.target.value),e.target.value="")},children:i.map(t=>e.jsx(d.MenuItem,{value:t.value,children:e.jsx(o.Typography,{type:"s4",color:"theme.secondary.1000",children:t.label})},t.value))}),e.jsx(d.IconButton,{onClick:p,children:e.jsx(E,{fontSize:"small"})})]})]}),e.jsx(d.DialogContent,{className:"editSectionModal--DialogContents",children:e.jsx(t.Suspense,{children:e.jsx(gt,{handleEditorReady:m,data:r.content})})}),e.jsx(d.DialogActions,{className:"editSectionModal--DialogAction",children:e.jsxs(d.Box,{display:"flex",gap:1.5,children:[e.jsx(c.Button,{className:"editSectionModal--DialogAction--WhiteBtn",onClick:p,children:"Cancel"}),e.jsx(c.Button,{onClick:e=>(e=>{s(e)})(e),children:"Save"})]})})]})},bt=()=>{const e=t.useMemo(()=>({i:{fontStyle:"italic"},em:{fontStyle:"italic"},b:{fontWeight:"bold"},strong:{fontWeight:"bold"},u:{textDecoration:"underline"},s:{textDecoration:"line-through"},strike:{textDecoration:"line-through"},del:{textDecoration:"line-through"},sup:{verticalAlign:"super",fontSize:"smaller"},sub:{verticalAlign:"sub",fontSize:"smaller"},small:{fontSize:"smaller"},big:{fontSize:"larger"},mark:{backgroundColor:"yellow"},code:{fontFamily:"monospace"},kbd:{fontFamily:"monospace",backgroundColor:"#f1f1f1",padding:"2px 4px",borderRadius:"3px"},samp:{fontFamily:"monospace"},var:{fontStyle:"italic",fontFamily:"monospace"}}),[]),l=t.useMemo(()=>{const e={};return Object.entries({"fontStyle-italic":"i","fontWeight-bold":"b","textDecoration-underline":"u","textDecoration-line-through":"s","verticalAlign-super":"sup","verticalAlign-sub":"sub","fontSize-smaller":"small","fontSize-larger":"big","backgroundColor-yellow":"mark"}).forEach(([t,l])=>{e[t]=l}),e},[]),a=t.useMemo(()=>({"font-family":"fontFamily","font-size":"fontSize","font-weight":"fontWeight","font-style":"fontStyle","text-align":"textAlign","text-decoration":"textDecoration","text-transform":"textTransform","line-height":"lineHeight","letter-spacing":"letterSpacing","word-spacing":"wordSpacing",color:"color","background-color":"backgroundColor","background-image":"backgroundImage","background-size":"backgroundSize","background-position":"backgroundPosition","background-repeat":"backgroundRepeat",border:"border","border-color":"borderColor","border-width":"borderWidth","border-style":"borderStyle","border-radius":"borderRadius",margin:"margin","margin-top":"marginTop","margin-right":"marginRight","margin-bottom":"marginBottom","margin-left":"marginLeft",padding:"padding","padding-top":"paddingTop","padding-right":"paddingRight","padding-bottom":"paddingBottom","padding-left":"paddingLeft",width:"width",height:"height","max-width":"maxWidth","max-height":"maxHeight","min-width":"minWidth","min-height":"minHeight",display:"display",position:"position",top:"top",right:"right",bottom:"bottom",left:"left",float:"float",clear:"clear",overflow:"overflow",opacity:"opacity","z-index":"zIndex","box-shadow":"boxShadow","text-shadow":"textShadow","vertical-align":"verticalAlign"}),[]),o=t.useCallback(e=>a[e]||e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase()),[a]),n=t.useCallback(e=>e.replace(/([A-Z])/g,"-$1").toLowerCase(),[]),r=t.useCallback(e=>{const t={};for(let l=0;l<e.length;l++){const a=e[l],n=e.getPropertyValue(a);n&&(t[o(a)]=n.trim())}return t},[o]),i=t.useCallback(t=>{const l=t.tagName.toLowerCase();return e[l]||{}},[e]),s=t.useCallback(t=>{const l={};let a=t.parentElement;for(;a&&"BODY"!==a.tagName;){const t=a.tagName.toLowerCase();if(e[t]&&Object.entries(e[t]).forEach(([e,t])=>{l[e]||(l[e]=t)}),a.style.length>0){const e=["color","fontFamily","fontSize","lineHeight","textAlign"],t=r(a.style);e.forEach(e=>{t[e]&&!l[e]&&(l[e]=t[e])})}a=a.parentElement}return l},[e,r]),d=t.useCallback((e,t)=>{const l={};e.width&&(l.width=`${e.width}px`),e.height&&(l.height=`${e.height}px`),e.getAttribute("align")&&(l.textAlign=e.getAttribute("align")),Object.assign(t.styles,l),t.src=e.src,t.alt=e.alt},[]),c=t.useCallback((e,t={})=>{const{includeInlineStyles:l=!0,includeTagStyles:a=!0,filterEmptyStyles:o=!0,mergeNestedStyles:n=!0}=t,c=document.createElement("div");c.innerHTML=e;const u=[];return c.querySelectorAll("*").forEach((e,t)=>{var c;const m={elementType:e.tagName.toLowerCase(),elementIndex:t,className:e.className||null,id:e.id||null,styles:{},textContent:(null==(c=e.textContent)?void 0:c.trim())||null};if(l&&e.style.length>0&&(m.styles={...m.styles,...r(e.style)}),a){const t=i(e);m.styles={...m.styles,...t}}if(n){const t=s(e);m.styles={...m.styles,...t},m.inheritedStyles=t}"img"===e.tagName.toLowerCase()&&d(e,m),o&&0===Object.keys(m.styles).length&&!m.textContent||u.push(m)}),u},[r,i,s,d]),u=t.useCallback(t=>{const l=document.createElement("div");l.innerHTML=t;const a={};return["i","em","b","strong","u","s","strike","del","sup","sub"].forEach(t=>{l.querySelectorAll(t).forEach((l,o)=>{a[`${t}_${o}`]={...e[t],textContent:l.textContent}})}),a},[e]),m=t.useCallback((e,t={},a={})=>{const{preferSemanticTags:o=!0,wrapInParagraph:r=!0}=a;if(!e||"string"!=typeof e)return"";let i=e;const s={};if(Object.entries(t).forEach(([e,t])=>{const a=`${e}-${t}`;if(o&&l[a]){const e=l[a];i=`<${e}>${i}</${e}>`}else s[e]=t}),Object.keys(s).length>0){const e=Object.entries(s).map(([e,t])=>`${n(e)}: ${t}`).join("; ");i=`<span style="${e}">${i}</span>`}return r&&(i=`<p>${i}</p>`),i},[l,n]),p=t.useCallback((e,t={})=>{const{wrapInContainer:l=!0,containerTag:a="div",separateElements:o=!1}=t;if(!Array.isArray(e))return"";const n=e.map(e=>{const{text:l,styles:a={},wrapInParagraph:o=!1}=e;return m(l,a,{...t,wrapInParagraph:o})});let r=o?n.join("\n"):n.join(" ");return l&&(r=`<${a}>${r}</${a}>`),r},[m]),h=t.useCallback((e,t={},a="*")=>{const o=document.createElement("div");return o.innerHTML=e,("*"===a?o.querySelectorAll("*"):o.querySelectorAll(a)).forEach(e=>{Object.entries(t).forEach(([t,a])=>{const o=`${t}-${a}`;if(l[o]){const t=l[o],a=document.createElement(t);for(;e.firstChild;)a.appendChild(e.firstChild);e.appendChild(a)}else{const l=n(t);e.style[l]=a}})}),o.innerHTML},[l,n]),g=t.useCallback((e,t={})=>{const l=c(e),a={};return l.forEach(e=>{const l=e.className||e.id||`${e.elementType}_${e.elementIndex}`,o={...e.styles,...t};e.textContent&&(a[l]=m(e.textContent,o,{wrapInParagraph:!1}))}),a},[c,m]),x=t.useCallback(e=>{let t="";return e.forEach((e,l)=>{const a=e.className?`.${e.className}`:e.id?`#${e.id}`:`${e.elementType}-${l}`,o=Object.entries(e.styles).map(([e,t])=>` ${n(e)}: ${t};`).join("\n");o&&(t+=`${a} {\n${o}\n}\n\n`)}),t},[n]),b=t.useCallback(e=>{const t={};return e.forEach((e,l)=>{const a=e.className||e.id||`${e.elementType}_${l}`;Object.entries(e.styles).forEach(([e,l])=>{t[`${a}_${e}`]=l})}),t},[]),f=t.useCallback(e=>{const t={};return e.forEach((e,l)=>{Object.entries(e.styles).forEach(([e,l])=>{t[e]=l})}),t},[]);return{extractStyles:c,extractFormattingStyles:u,generateCSS:x,getFlattenedStyles:b,getSingleStyles:f,stylesToHtml:m,multipleStylesToHtml:p,applyStylesToHtml:h,extractAndConvert:g}},ft=(e,l=300)=>{const a=t.useRef(null);return t.useCallback((...t)=>{a.current&&clearTimeout(a.current),a.current=setTimeout(()=>{e(...t)},l)},[e,l])},yt=t.lazy(()=>Promise.resolve().then(()=>require("./custom-editor-CqKvR1Cc.js"))),vt=["text","text-block","heading","heading-1","heading-2","heading-3","heading-4"],jt=t.memo(({section:l,isSelected:a,isDragging:r,isOver:i,onSelect:u,onUpdate:m,onSplit:p,onDelete:h,placeholders:g,setIsSectionEditing:x})=>{const{extractStyles:b,getSingleStyles:f}=bt(),{attributes:y,listeners:v,setNodeRef:j,transform:S}=F.useDraggable({id:l.id}),{setNodeRef:C}=F.useDroppable({id:l.id}),[w,_]=t.useState(!1),[k,I]=t.useState(!1),[B,A]=t.useState(!1),[M,P]=t.useState(Boolean(null==l?void 0:l.is_edited_from_source)),[z,R]=t.useState(l.content),[N,L]=t.useState(!1),O=t.useRef(null),q=t.useRef(null),W=t.useRef(null),H=t.useRef(!1),V=t.useRef(l.content),G=t.useRef(l.content),U=ft(m,300),K=t.useMemo(()=>S?{transform:`translate3d(${S.x}px, ${S.y}px, 0)`,transition:"none"}:{transition:"all 0.2s ease"},[S]),J=t.useMemo(()=>({position:"relative",border:"1px dashed",borderColor:a||i?"primary.main":"grey.400",borderRadius:1,bgcolor:"white",opacity:r?.7:1,boxShadow:"none",transition:"all 0.2s ease","&:hover":{boxShadow:"none"},...i&&{borderColor:"primary.main",boxShadow:"none"}}),[a,i,r]),Y=t.useCallback(e=>{j(e),C(e)},[j,C]),Z=t.useCallback(()=>{vt.includes(l.type)&&X()},[l.type]),X=t.useCallback(()=>{G.current=l.content,L(!1),(null==l?void 0:l.isSplitPair)?A(!0):(_(!0),x(!0))},[null==l?void 0:l.isSplitPair,l.content,x]),Q=t.useCallback(e=>{O.current=e,(null==e?void 0:e._tiptap)&&(e._tiptap.on("selectionUpdate",()=>{if(!H.current&&e._tiptap){const{from:t,to:l}=e._tiptap.state.selection;W.current={from:t,to:l}}}),e._tiptap.on("update",({transaction:e})=>{e.docChanged&&L(!0)}))},[]),ee=t.useCallback(e=>{var t;if(e.stopPropagation(),O.current){if(O.current._tiptap){const{from:e,to:t}=O.current._tiptap.state.selection;W.current={from:e,to:t}}const e=O.current.getData();V.current=e,R(e);const a=b(l.content,{includeTagStyles:!0,includeInlineStyles:!0,mergeNestedStyles:!0,filterEmptyStyles:!0}),o=f(a),n={...(null==(t=l.attributes)?void 0:t.styles)||{},...o},r={...l.attributes||{},styles:n};U(e,{is_edited_from_source:M,attributes:r})}_(!1),x(!1),A(!1),L(!1)},[U,M,b,f,l.content,l.attributes,x,N]),te=t.useCallback(()=>{const e=l.content||"";p(e,"")},[l.content,p]),le=t.useCallback(e=>{if(O.current){const t=O.current.data.processor.toView(`{{${e}}}`),l=O.current.data.toModel(t);O.current.model.insertContent(l)}},[]),ae=t.useCallback(()=>{null!==q.current&&window.clearTimeout(q.current),q.current=window.setTimeout(()=>{I(!0)},50)},[]),oe=t.useCallback(()=>{null!==q.current&&window.clearTimeout(q.current),q.current=window.setTimeout(()=>{I(!1)},50)},[]),ne=t.useCallback(e=>{e.stopPropagation(),u()},[u]),re=t.useCallback(e=>{e.stopPropagation(),h()},[h]),ie=t.useCallback(()=>{_(!1),x(!1)},[x]),se=t.useCallback(e=>{P(e.target.checked)},[]),de=t.useCallback(e=>{e.target.value&&(le(e.target.value),e.target.value="")},[le]);t.useEffect(()=>()=>{null!==q.current&&window.clearTimeout(q.current)},[]),t.useEffect(()=>{var e;if(V.current!==l.content&&(V.current=l.content,R(l.content),w&&(null==(e=O.current)?void 0:e._tiptap)&&W.current&&!H.current)){const e=O.current._tiptap,{from:t,to:l}=W.current;requestAnimationFrame(()=>{try{H.current=!0;const a=e.state.doc.content.size,o=Math.min(t,a),n=Math.min(l,a);e.commands.setTextSelection({from:o,to:n}),e.isFocused||e.commands.focus()}catch(a){console.warn("Failed to restore cursor position:",a)}finally{H.current=!1}})}},[l.content,w]);const ce=t.useMemo(()=>w?e.jsx(t.Suspense,{fallback:e.jsx(d.Skeleton,{}),children:e.jsx(yt,{editorRef:O,handleEditorReady:Q,data:z,onError:e=>console.error("Editor error:",e)},`editor-${l.id}`)}):e.jsx(d.Box,{dangerouslySetInnerHTML:{__html:z},sx:{position:"relative",py:"divider"===l.type?1:0,lineHeight:1.6,"& p":{margin:0}}}),[w,z,l.type,l.id]),ue=t.useMemo(()=>g.map(t=>e.jsx(d.MenuItem,{value:t.value,children:e.jsx(o.Typography,{type:"s4",color:"theme.secondary.1000",children:t.label})},t.value)),[g]);return e.jsxs(d.Paper,{ref:Y,style:K,elevation:k||a?3:1,sx:J,onClick:ne,onDoubleClick:Z,onMouseEnter:ae,onMouseLeave:oe,children:[i&&!r&&e.jsx(d.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,border:"2px dashed",borderColor:"primary.main",borderRadius:1,bgcolor:"rgba(25, 118, 210, 0.04)",zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"none"},children:e.jsx(o.Typography,{type:"s2",color:"primary",weight:"medium",children:"Drop here"})}),e.jsxs(d.Box,{sx:{bgcolor:"grey.50",p:1,display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid",borderColor:"grey.200"},children:[e.jsxs(d.Box,{...v,...y,sx:{display:"flex",alignItems:"center",cursor:"grab",px:1,py:.5,borderRadius:1,transition:"background-color 0.2s ease","&:hover":{bgcolor:"grey.100"},"&:active":{cursor:"grabbing"}},children:[e.jsx($,{sx:{color:"grey.600",fontSize:"1.2rem",mr:.5}}),e.jsx(o.Typography,{type:"s3",color:"theme.secondary.600",weight:"medium",children:"Move"})]}),e.jsx(d.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:w?e.jsxs(e.Fragment,{children:[e.jsx(d.FormControlLabel,{control:e.jsx(n.Checkbox,{onChange:se,defaultChecked:M}),label:e.jsx(o.Typography,{type:"s2",color:"theme.secondary.1000",children:"Edited from source"})}),e.jsx(d.FormControl,{size:"small",sx:{minWidth:160},children:e.jsx(c.Select,{displayEmpty:!0,value:"",size:"small",renderValue:()=>"Add placeholder...",sx:{bgcolor:"white",borderRadius:1,"& .MuiSelect-select":{py:.75}},onChange:de,children:ue})}),e.jsxs(d.Box,{children:[e.jsx(d.IconButton,{size:"small",onClick:ee,children:e.jsx(T.Save,{fontSize:"small",color:"inherit"})}),e.jsx(d.IconButton,{size:"small",onClick:ie,color:"error",children:e.jsx(E,{fontSize:"small",color:"inherit"})})]})]}):e.jsx(d.Fade,{in:k||a,timeout:200,children:e.jsxs(d.Box,{sx:{display:"flex",gap:.5},children:[(null==l?void 0:l.is_edited_from_source)&&e.jsx(s.Chip,{label:"Edited From Source",size:"small",sx:e=>{var t,l,a,o;return{textTransform:"capitalize",backgroundColor:null==(l=null==(t=e.palette.theme)?void 0:t.tertiary1)?void 0:l[200],color:null==(o=null==(a=e.palette.theme)?void 0:a.tertiary1)?void 0:o[900]}}}),vt.includes(l.type)&&e.jsx(d.IconButton,{size:"small",onClick:X,sx:{bgcolor:"grey.100","&:hover":{bgcolor:"grey.200"}},children:e.jsx(T.Edit,{fontSize:"small",sx:{color:"theme.secondary.1000"}})}),e.jsx(d.IconButton,{size:"small",onClick:te,sx:{bgcolor:"grey.100","&:hover":{bgcolor:"grey.200"},opacity:25===(null==l?void 0:l.splitWidth)?.5:1},disabled:25===(null==l?void 0:l.splitWidth),children:e.jsx(D,{fontSize:"small",color:"primary"})}),e.jsx(d.IconButton,{size:"small",onClick:re,sx:{bgcolor:"grey.100","&:hover":{bgcolor:"grey.200"}},children:e.jsx(T.Trash,{fontSize:"small",sx:{color:"theme.error.500"}})})]})})})]}),e.jsxs(d.Box,{sx:{p:3,bgcolor:"white"},children:[e.jsx("style",{children:"\n\t\t\t\t\t\ta {\n\t\t\t\t\t\t\tcolor: #007bff !important;\n\t\t\t\t\t\t\ttext-decoration: none !important;\n\t\t\t\t\t\t}\n\t\t\t\t\t\ta:hover {\n\t\t\t\t\t\t\ttext-decoration: underline;\n\t\t\t\t\t\t}\n "}),ce]}),B&&e.jsx(xt,{isOpen:B,setIsOpen:A,modalProps:{open:B},placeholders:g,handleSave:ee,handleAddPlaceholder:le,handleEditorReady:Q,section:l})]})},(e,t)=>e.section.id===t.section.id&&(e.section.content===t.section.content&&(e.section.type===t.section.type&&(e.section.is_edited_from_source===t.section.is_edited_from_source&&(e.section.isSplitPair===t.section.isSplitPair&&(e.section.splitWidth===t.section.splitWidth&&(e.isSelected===t.isSelected&&(e.isDragging===t.isDragging&&(e.isOver===t.isOver&&(e.placeholders===t.placeholders&&JSON.stringify(e.section.attributes)===JSON.stringify(t.section.attributes)))))))))));jt.displayName="EditorSection";const St=d.styled(d.ToggleButtonGroup)(({theme:e,item:t})=>({display:"grid",borderRadius:4,border:"1px solid #e3e3e3",width:"100%",gridTemplateColumns:`repeat(${t||4}, 1fr)`,[`& .${d.toggleButtonGroupClasses.grouped}`]:{margin:e.spacing(.5),border:0,borderRadius:e.shape.borderRadius,[`&.${d.toggleButtonGroupClasses.disabled}`]:{border:0}},[`& .${d.toggleButtonGroupClasses.middleButton},& .${d.toggleButtonGroupClasses.lastButton}`]:{marginLeft:-1,borderLeft:"1px solid transparent"},[`& .${d.toggleButtonGroupClasses.selected}`]:{backgroundColor:`${e.palette.theme.primary[800]}!important`,color:"#fff !important"}})),Ct=({alignment:t,onAlignmentChange:l,displayLabel:a=!1})=>e.jsxs(d.Box,{sx:{display:"flex",flexWrap:"wrap",gap:1,mb:2},children:[a&&e.jsx(o.Typography,{type:"s5",weight:"medium",color:"theme.secondary.800",children:"Alignment"}),e.jsxs(St,{value:t,exclusive:!0,onChange:l,"aria-label":"text alignment",size:"small",children:[e.jsx(d.Tooltip,{title:"Align Left",children:e.jsx(d.ToggleButton,{value:"left","aria-label":"left aligned",children:e.jsx(O,{fontSize:"small"})})}),e.jsx(d.Tooltip,{title:"Align Center",children:e.jsx(d.ToggleButton,{value:"center","aria-label":"centered",children:e.jsx(q,{fontSize:"small"})})}),e.jsx(d.Tooltip,{title:"Align Right",children:e.jsx(d.ToggleButton,{value:"right","aria-label":"right aligned",children:e.jsx(W,{fontSize:"small"})})}),e.jsx(d.Tooltip,{title:"Justify",children:e.jsx(d.ToggleButton,{value:"justify","aria-label":"justified",children:e.jsx(H,{fontSize:"small"})})})]})]}),wt=d.styled(d.ToggleButtonGroup)(({theme:e,item:t=4})=>({display:"grid",borderRadius:4,border:"1px solid #e3e3e3",width:"100%",gridTemplateColumns:`repeat(${t}, 1fr)`,[`& .${d.toggleButtonGroupClasses.grouped}`]:{margin:e.spacing(.5),border:0,borderRadius:e.shape.borderRadius,[`&.${d.toggleButtonGroupClasses.disabled}`]:{border:0}},[`& .${d.toggleButtonGroupClasses.middleButton}, & .${d.toggleButtonGroupClasses.lastButton}`]:{marginLeft:-1,borderLeft:"1px solid transparent"},[`& .${d.toggleButtonGroupClasses.selected}`]:{backgroundColor:`${e.palette.theme.primary[800]} !important`,color:"#fff !important"}})),_t=[10,12,14,16,20,24,28,32],kt=[1,1.2,1.5,2],Tt=["Arial","Times New Roman","Roboto","Helvetica","Georgia","Courier New"],It=t.memo(({attrs:l,updateAttrs:a})=>{const o=t.useMemo(()=>l.styles||{},[JSON.stringify(l.styles)]),n=t.useMemo(()=>{const e=[];return"bold"===o.fontWeight&&e.push("bold"),"italic"===o.fontStyle&&e.push("italic"),"underline"===o.textDecoration&&e.push("underline"),e},[o.fontWeight,o.fontStyle,o.textDecoration]),r=t.useCallback(e=>{a({styles:{...o,...e}})},[o,a]),i=t.useCallback(L.debounce(e=>{r({color:e})},300),[r]),s=t.useCallback(e=>{const t=n.includes(e);r({bold:{fontWeight:t?"normal":"bold"},italic:{fontStyle:t?"normal":"italic"},underline:{textDecoration:t?"none":"underline"}}[e])},[n,r]),u=t.useCallback((e,t)=>{null!==t&&r({textAlign:t})},[r]),m=t.useCallback(e=>{i(e.target.value)},[i]),p=t.useCallback(e=>r({fontFamily:e.target.value}),[r]),h=t.useCallback(e=>r({fontSize:Number(e.target.value)}),[r]),g=t.useCallback(e=>r({lineHeight:String(e.target.value)}),[r]);return e.jsxs(e.Fragment,{children:[e.jsx(d.Box,{sx:{mb:2},children:e.jsx(d.FormControl,{size:"small",fullWidth:!0,children:e.jsx(c.Select,{value:o.fontFamily||"",onChange:p,displayEmpty:!0,label:"Select Font",children:Tt.map(t=>e.jsx(d.MenuItem,{value:t,children:t},t))})})}),e.jsxs(d.Box,{sx:{mb:2,display:"flex",gap:1},children:[e.jsx(d.FormControl,{size:"small",fullWidth:!0,children:e.jsx(c.Select,{value:o.fontSize||"",onChange:h,renderValue:e=>`${e}px`,label:"Size",displayEmpty:!0,children:_t.map(t=>e.jsxs(d.MenuItem,{value:t,children:[t,"px"]},t))})}),e.jsx(d.FormControl,{size:"small",fullWidth:!0,children:e.jsx(c.Select,{value:o.lineHeight||"",onChange:g,renderValue:e=>`${e}x`,label:"Line Height",displayEmpty:!0,children:kt.map(t=>e.jsxs(d.MenuItem,{value:t,children:[t,"x"]},t))})})]}),e.jsx(Ct,{alignment:o.textAlign,onAlignmentChange:u}),e.jsx(d.Box,{sx:{display:"flex",flexWrap:"wrap",gap:1,mb:2},children:e.jsxs(wt,{item:3,children:[e.jsx(d.Tooltip,{title:"Bold",children:e.jsx(d.ToggleButton,{value:"bold",selected:n.includes("bold"),onClick:()=>s("bold"),"aria-label":"bold",size:"small",sx:{borderRadius:1},children:e.jsx(P,{fontSize:"small"})})}),e.jsx(d.Tooltip,{title:"Italic",children:e.jsx(d.ToggleButton,{value:"italic",selected:n.includes("italic"),onClick:()=>s("italic"),"aria-label":"italic",size:"small",sx:{borderRadius:1},children:e.jsx(z,{fontSize:"small"})})}),e.jsx(d.Tooltip,{title:"Underline",children:e.jsx(d.ToggleButton,{value:"underline",selected:n.includes("underline"),onClick:()=>s("underline"),"aria-label":"underline",size:"small",sx:{borderRadius:1},children:e.jsx(R,{fontSize:"small"})})})]})}),e.jsx(d.Box,{sx:{mb:2,width:"100%"},children:e.jsx(d.TextField,{label:"Text Color",variant:"outlined",type:"color",value:o.color||"#000000",onChange:m,size:"small",fullWidth:!0,InputProps:{startAdornment:e.jsx(d.InputAdornment,{position:"start",children:e.jsx(N,{fontSize:"small"})})}})})]})}),Et=[{label:"None",value:"none"},{value:"1px solid #e0e0e0",label:"Solid"},{value:"1px dashed #e0e0e0",label:"Dashed"},{value:"1px dotted #e0e0e0",label:"Dotted"}],Bt=({attrs:t,updateAttrs:l})=>{const{text:a,styles:r}=t;return e.jsxs(e.Fragment,{children:[e.jsx(c.TextField,{label:"Button Text",fullWidth:!0,value:a,onChange:e=>l({text:e.target.value}),size:"small",sx:{mb:2}}),e.jsx(d.Box,{sx:{mb:2},children:e.jsx(n.ColorPickerInput,{value:(null==r?void 0:r.backgroundColor)||"#333333",onChange:e=>l({styles:{backgroundColor:e}}),label:"Background Color"})}),e.jsx(d.Box,{sx:{mb:2},children:e.jsx(n.ColorPickerInput,{value:(null==r?void 0:r.color)||"#333333",onChange:e=>l({styles:{color:e}}),label:"Text Color"})}),e.jsx(d.FormControl,{fullWidth:!0,size:"small",sx:{mb:2},children:e.jsxs(c.Select,{value:null==r?void 0:r.border,renderValue:e=>{var t;return(null==(t=Et.find(t=>t.value===e))?void 0:t.label)||"None"},onChange:e=>l({styles:{border:e.target.value}}),label:"Border",children:[e.jsx(d.MenuItem,{value:"none",children:"None"}),e.jsx(d.MenuItem,{value:"1px solid #e0e0e0",children:"Solid"}),e.jsx(d.MenuItem,{value:"1px dashed #e0e0e0",children:"Dashed"})]})}),e.jsxs(d.Box,{sx:{mb:2},children:[e.jsx(o.Typography,{type:"s3",color:"theme.neutral.800",children:"Border Radius"}),e.jsx(d.Slider,{value:null==r?void 0:r.borderRadius,onChange:(e,t)=>l({styles:{borderRadius:t}}),min:0,max:20,step:1,valueLabelDisplay:"auto",size:"small",marks:!0,sx:e=>({"& .MuiSlider-rail":{color:e.palette.theme.primary[500]},"& .MuiSlider-thumb":{color:e.palette.theme.primary[800]},"& .MuiSlider-track":{color:e.palette.theme.primary[600]}})})]}),e.jsxs(d.Box,{sx:{mb:2},children:[e.jsx(o.Typography,{type:"s3",color:"theme.neutral.800",children:"Font Size"}),e.jsx(d.Slider,{value:null==r?void 0:r.fontSize,onChange:(e,t)=>l({styles:{fontSize:t}}),min:10,max:20,step:1,valueLabelDisplay:"auto",size:"small",marks:!0,sx:e=>({"& .MuiSlider-rail":{color:e.palette.theme.primary[500]},"& .MuiSlider-thumb":{color:e.palette.theme.primary[800]},"& .MuiSlider-track":{color:e.palette.theme.primary[600]}})})]}),e.jsx(Ct,{alignment:"0 auto"===(null==r?void 0:r.margin)?"center":"0 0 0 auto"===(null==r?void 0:r.margin)?"right":"auto 0 0 0"===(null==r?void 0:r.margin)?"left":"justify",onAlignmentChange:(e,t)=>{if(t){let e="0";switch(t){case"justify":case"center":default:e="0 auto";break;case"right":e="0 0 0 auto";break;case"left":e="auto 0 0 0"}l({styles:{margin:e}})}}})]})},At=d.styled(d.Switch)(({theme:e})=>({padding:8,"& .MuiSwitch-track":{borderRadius:11,"&::before, &::after":{content:'""',position:"absolute",top:"50%",transform:"translateY(-50%)",width:16,height:16},"&::before":{backgroundImage:`url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" viewBox="0 0 24 24"><path fill="${encodeURIComponent(e.palette.getContrastText(e.palette.primary.main))}" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"/></svg>')`,left:12},"&::after":{backgroundImage:`url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" viewBox="0 0 24 24"><path fill="${encodeURIComponent(e.palette.getContrastText(e.palette.primary.main))}" d="M19,13H5V11H19V13Z" /></svg>')`,right:12}},"& .MuiSwitch-thumb":{boxShadow:"none",width:16,height:16,margin:2},"& .Mui-checked":{color:`${e.palette.theme.primary[800]} !important`},"& .Mui-checked+.MuiSwitch-track":{backgroundColor:`${e.palette.theme.primary[800]} !important`}})),Mt=["none","solid","dashed","dotted","double","groove","ridge","inset","outset"],Ft=({styles:l,onChange:a,isBordered:r,disableWidth:i=!1,disableStyle:s=!1,disableColor:u=!1,disableCollapse:m=!1,disableRadius:p=!1,initiateStyles:h})=>(t.useEffect(()=>{h instanceof Function&&h(r?{border:1,borderStyle:"solid",borderColor:"#000000",borderCollapse:"collapse",borderRadius:0}:{border:0,borderStyle:"none",borderColor:"#000000",borderCollapse:"separate",borderRadius:0})},[r]),e.jsxs(d.Grid,{container:!0,spacing:2,children:[e.jsx(d.Grid,{item:!0,xs:12,children:e.jsx(d.FormControlLabel,{control:e.jsx(At,{checked:r,onChange:e=>a("is_bordered",e.target.checked)}),label:e.jsx(o.Typography,{type:"s5",weight:"medium",color:"theme.secondary.800",children:"Bordered Table"}),labelPlacement:"start",sx:{display:"flex",alignItems:"center",justifyContent:"space-between",margin:"auto"}})}),r&&e.jsxs(e.Fragment,{children:[!i&&e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(c.Select,{value:l.border||1,onChange:e=>a("border",e.target.value),label:"Border Width",fullWidth:!0,size:"small",children:[1,2,3,4,5,6,7,8,9,10].map(t=>e.jsx(d.MenuItem,{value:t,children:e.jsx(o.Typography,{type:"s5",color:"theme.secondary.1000",children:t})},t))})}),!s&&e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(d.FormControl,{fullWidth:!0,size:"small",children:e.jsx(c.Select,{value:l.borderStyle||"solid",onChange:e=>a("borderStyle",e.target.value),renderValue:e=>w.formatText(e),label:"Border Style",children:Mt.map(t=>e.jsx(d.MenuItem,{value:t,children:e.jsx(o.Typography,{type:"s5",color:"theme.secondary.1000",children:w.formatText(t)})},t))})})}),!u&&e.jsxs(d.Grid,{item:!0,xs:6,children:[e.jsx(o.Typography,{type:"s5",weight:"medium",color:"theme.secondary.800",mb:.5,children:"Border Color"}),e.jsx(n.ColorPickerInput,{value:l.borderColor||"#e0e0e0",onChange:e=>a("borderColor",e),fullWidth:!0})]}),!m&&e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(d.FormControl,{fullWidth:!0,size:"small",children:e.jsxs(c.Select,{value:l.borderCollapse||"collapse",onChange:e=>a("borderCollapse",e.target.value),label:"Border Collapse",renderValue:e=>w.formatText(e),children:[e.jsx(d.MenuItem,{value:"collapse",children:e.jsx(o.Typography,{type:"s5",color:"theme.secondary.1000",children:"Collapse"})}),e.jsx(d.MenuItem,{value:"separate",children:e.jsx(o.Typography,{type:"s5",color:"theme.secondary.1000",children:"Separate"})})]})})}),!p&&e.jsxs(d.Grid,{item:!0,xs:12,children:[e.jsx(o.Typography,{type:"s5",weight:"medium",color:"theme.secondary.800",variant:"caption",children:"Border Radius"}),e.jsx(d.Slider,{value:"number"==typeof l.borderRadius?l.borderRadius:1,min:0,max:20,step:1,marks:!0,onChange:(e,t)=>a("borderRadius",t),valueLabelDisplay:"auto",sx:e=>({"& .MuiSlider-rail":{color:e.palette.theme.primary[500]},"& .MuiSlider-thumb":{color:e.palette.theme.primary[800]},"& .MuiSlider-track":{color:e.palette.theme.primary[600]}})})]})]})]})),$t=d.styled(d.Switch)(({theme:e})=>({padding:8,"& .MuiSwitch-track":{borderRadius:11,"&::before, &::after":{content:'""',position:"absolute",top:"50%",transform:"translateY(-50%)",width:16,height:16},"&::before":{backgroundImage:`url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" viewBox="0 0 24 24"><path fill="${encodeURIComponent(e.palette.getContrastText(e.palette.primary.main))}" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"/></svg>')`,left:12},"&::after":{backgroundImage:`url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" viewBox="0 0 24 24"><path fill="${encodeURIComponent(e.palette.getContrastText(e.palette.primary.main))}" d="M19,13H5V11H19V13Z" /></svg>')`,right:12}},"& .MuiSwitch-thumb":{boxShadow:"none",width:16,height:16,margin:2},"& .Mui-checked":{color:e.palette.theme.primary[800]},"& .Mui-checked+.MuiSwitch-track":{backgroundColor:`${e.palette.theme.primary[700]}`}})),Dt=({attrs:t,updateAttrs:l})=>{const{src:a,alt:n,styles:r}=t||{};return e.jsxs(e.Fragment,{children:[e.jsx(c.TextField,{label:"Image URL",fullWidth:!0,value:a,onChange:e=>l({src:e.target.value}),size:"small",sx:{mb:2}}),e.jsx(c.TextField,{label:"Alt Text",fullWidth:!0,value:n,onChange:e=>l({alt:e.target.value}),size:"small",sx:{mb:2}}),e.jsx(d.FormControlLabel,{control:e.jsx($t,{defaultChecked:!0,checked:Boolean(null==r?void 0:r.fullWidth)}),label:e.jsx(o.Typography,{type:"s5",color:"theme.secondary.800",weight:"medium",children:"Full Width"}),labelPlacement:"start",value:Boolean(null==r?void 0:r.fullWidth),onClick:e=>{const t=e.target.checked;l({styles:{fullWidth:t,width:t?100:150,height:t?"auto":150}})},sx:{display:"flex",alignItems:"center",justifyContent:"space-between",margin:"auto",mb:2}}),e.jsxs(d.Grid,{container:!0,spacing:2,children:[e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(c.TextField,{label:"Width (px)",type:"number",fullWidth:!0,value:(null==r?void 0:r.fullWidth)?"":null==r?void 0:r.width,onChange:e=>l({styles:{width:Number(e.target.value)}}),size:"small",sx:{mb:2},inputProps:{min:1},disabled:null==r?void 0:r.fullWidth})}),e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(c.TextField,{label:"Height (px)",type:"number",fullWidth:!0,value:(null==r?void 0:r.fullWidth)?"":null==r?void 0:r.height,onChange:e=>l({styles:{height:Number(e.target.value)}}),size:"small",sx:{mb:2},inputProps:{min:1},disabled:null==r?void 0:r.fullWidth})})]}),e.jsx(d.Box,{sx:{mb:2},children:e.jsx(d.FormControl,{size:"small",fullWidth:!0,children:e.jsxs(c.Select,{label:"Object Fit",value:null==r?void 0:r.objectFit,onChange:e=>l({styles:{objectFit:e.target.value}}),displayEmpty:!0,children:[e.jsx(d.MenuItem,{value:"contain",children:"Contain"}),e.jsx(d.MenuItem,{value:"cover",children:"Cover"}),e.jsx(d.MenuItem,{value:"fill",children:"Fill"}),e.jsx(d.MenuItem,{value:"none",children:"None"}),e.jsx(d.MenuItem,{value:"scale-down",children:"Scale Down"})]})})}),e.jsx(Ct,{alignment:"0 auto"===(null==r?void 0:r.margin)||"center"===(null==r?void 0:r.alignment)?"center":"0 0 0 auto"===(null==r?void 0:r.margin)||"right"===(null==r?void 0:r.alignment)?"right":"auto 0 0 0"===(null==r?void 0:r.margin)||"left"===(null==r?void 0:r.alignment)?"left":"justify",onAlignmentChange:(e,t)=>{if(t){let e="0";switch(t){case"justify":case"center":default:e="0 auto";break;case"right":e="0 0 0 auto";break;case"left":e="auto 0 0 0"}l({styles:{margin:e,alignment:t}})}},displayLabel:!0}),e.jsx(Ft,{styles:r,onChange:(e,t)=>l({styles:{[e]:t}}),isBordered:null==r?void 0:r.is_bordered,disableCollapse:!0,initiateStyles:e=>l({styles:e})})]})},Pt=({attrs:t,updateAttrs:l})=>{const{styles:a}=t;return e.jsxs(e.Fragment,{children:[e.jsx(d.FormControl,{fullWidth:!0,size:"small",sx:{mb:2},children:e.jsxs(c.Select,{label:"Style",value:null==a?void 0:a.borderStyle,onChange:e=>l({styles:{borderStyle:e.target.value}}),renderValue:e=>w.formatText(e),children:[e.jsx(d.MenuItem,{value:"solid",children:"Solid"}),e.jsx(d.MenuItem,{value:"dashed",children:"Dashed"}),e.jsx(d.MenuItem,{value:"dotted",children:"Dotted"})]})}),e.jsxs(d.Box,{sx:{mb:1},children:[e.jsx(o.Typography,{type:"s5",color:"theme.secondary.800",weight:"medium",children:"Thickness (px)"}),e.jsx(d.Slider,{value:null==a?void 0:a.borderWidth,onChange:(e,t)=>l({styles:{borderWidth:t}}),min:1,max:10,step:1,valueLabelDisplay:"auto",size:"small",sx:e=>({"& .MuiSlider-rail":{color:e.palette.theme.primary[500]},"& .MuiSlider-thumb":{color:e.palette.theme.primary[800]},"& .MuiSlider-track":{color:e.palette.theme.primary[600]}})})]}),e.jsx(d.Box,{sx:{mb:2},children:e.jsx(c.TextField,{label:"Divider Color",type:"color",value:null==a?void 0:a.borderColor,onChange:e=>l({styles:{borderColor:e.target.value}}),size:"small",fullWidth:!0,InputProps:{startAdornment:e.jsx(d.InputAdornment,{position:"start",children:e.jsx(N,{fontSize:"small"})})}})})]})},zt=d.styled(t=>e.jsx(d.Accordion,{disableGutters:!0,elevation:0,square:!0,...t}))(({theme:e})=>({border:`1px solid ${e.palette.divider}`,borderRadius:0,"&:not(:last-child)":{borderBottom:0},"&::before":{display:"none"}})),Rt=["left","center","right","justify"],Nt=["normal","bold","100","200","300","400","500","600","700","800","900"],Lt=["Arial, sans-serif","Helvetica, sans-serif","Times New Roman, serif","Georgia, serif","Courier New, monospace","Verdana, sans-serif","Tahoma, sans-serif","Trebuchet MS, sans-serif"],Ot=({tableData:l,setTableData:a,attrs:r,updateAttrs:i,placeholders:s,handleSave:u,setParentRowLevel:m,levelType:p,relation_table:h})=>{var g,x,b,f,y,v,j,S,C,_,k,I,E,B,A,M,F,$,P,z;const[R,N]=t.useState(0),[L,O]=t.useState("tableBasic"),[q,W]=t.useState(!0),[H,J]=t.useState(!1),[Y,Z]=t.useState([]),[X,Q]=t.useState(""),[ee,te]=t.useState(!1),{placeholders:le}=r,[ae,oe]=t.useState(null),[ne,re]=t.useState({}),[ie,se]=t.useState({}),de=l.mergedCells||[],[ce,ue]=t.useState(!1),me=t.useMemo(()=>ae?(e=>{if(!h||!Array.isArray(h))return[];const t=h.find(t=>(null==t?void 0:t.dataKey)==e);return t&&t.fields&&Array.isArray(t.fields)?t.fields:[]})(ae):s,[s,ae,h]),[pe,he]=t.useState((null==r?void 0:r.styles)||{is_bordered:!0,border:1,borderStyle:"solid",borderColor:"#e0e0e0",borderCollapse:"collapse",width:"100%",thCells:{padding:8},tbCells:{padding:8},tHead:{backgroundColor:"#f5f5f5",color:"#333333",fontSize:14,fontWeight:"bold",fontFamily:"Arial, sans-serif",textAlign:"left",margin:"0.5em 0"},tBody:{backgroundColor:"#ffffff",color:"#333333",fontSize:14,fontWeight:"normal",fontFamily:"Arial, sans-serif",textAlign:"left"}});t.useEffect(()=>{i({styles:pe})},[JSON.stringify(pe)]),t.useEffect(()=>{q&&(le||ee)&&xe()},[le,q,ee,ie]);const ge=e=>{const t=me.find(t=>t.value===e);if(!t)return"";if(ee)return`{{${t.value}}}`;if(void 0!==t.actualValue)return String(t.actualValue);switch(t.type){case"date":return(new Date).toLocaleDateString();case"datetime":return(new Date).toLocaleString();case"number":return"123";case"currency":return"$1,234.56";case"email":return"example@domain.com";case"phone":return"+1 (555) 123-4567";case"url":return"https://example.com";default:return`{{${t.value}}}`||t.label}},xe=()=>{(le||ee)&&(a(e=>({...e,name:ae||"",rows:e.rows.map((t,l)=>{const a={...t};return e.columns.forEach(e=>{var t,o;let n;if(ee&&(null==(t=ie[l])?void 0:t[e.id])?n=ie[l][e.id]:(null==le?void 0:le[e.id])&&(n=le[e.id]),n){a[e.id]=ge(n);const t=(null==(o=ne[l])?void 0:o[e.id])||"";t&&(a[`${e.id}_static`]=`${t} ${a[e.id]}`)}}),a})})),ue(!1))},be=(e,t,l)=>{const a=null==de?void 0:de.find(a=>a.section===e&&t>=a.rowStart&&t<=a.rowEnd&&l>=a.colStart&&l<=a.colEnd);return a?{merge:a,isTopLeft:t===a.rowStart&&l===a.colStart,isCovered:!(t===a.rowStart&&l===a.colStart)}:null},fe=(e,t,l)=>Y.some(a=>a.section===e&&a.row===t&&a.col===l),ye=(e,t,l)=>{const a={section:e,row:t,col:l};if(fe(e,t,l))Z(a=>a.filter(a=>!(a.section===e&&a.row===t&&a.col===l)));else{if(Y.some(t=>t.section!==e))return void alert("Cannot select cells from both header and body for the same merge");Z(e=>[...e,a])}},ve=e=>{const t=s.find(t=>t.value===e);return t?{label:t.label,type:t.type||"text",description:t.description||""}:null},je=e=>(t,l)=>{O(l?e:"")},Se=(e,t)=>{he(l=>({...l,tHead:{...l.tHead,[e]:t}}))},Ce=(e,t)=>{he(l=>({...l,tBody:{...l.tBody,[e]:t}}))},we=()=>{a(e=>({...e,name:ae||"",rows:e.rows.map(t=>({...Object.fromEntries(e.columns.map(e=>[null==e?void 0:e.id,""]))}))}))},_e=le?Object.keys(le).length:0;return t.useEffect(()=>{te(p),oe((null==l?void 0:l.name)||null),re(e=>{const t={};return l.rows.forEach((e,l)=>{Object.keys(e).forEach(a=>{if(a.endsWith("_static")){const o=a.replace("_static","");t[l]||(t[l]={});const n=e[o]||"";let r=e[a]||"";n&&r.includes(n)&&(r=r.replace(n,"").trim()),r=r.replace(/\{\{\s*value\s*\}\}/g,"").trim(),t[l][o]=r}})}),t})},[l]),t.useEffect(()=>{ae||we()},[ae]),e.jsxs(e.Fragment,{children:[e.jsx(d.Box,{sx:{mb:2,borderBottom:1,paddingBottom:5,borderColor:"divider"},children:e.jsxs(d.Tabs,{value:R,onChange:(e,t)=>{N(t)},variant:"fullWidth",sx:e=>{var t,l;return{"& .MuiTabs-indicator":{backgroundColor:null==(t=e.palette.theme)?void 0:t.primary[700]},"& .MuiTab-root.Mui-selected":{color:null==(l=e.palette.theme)?void 0:l.primary[700]},"& .MuiTab-root":{textTransform:"none"}}},children:[e.jsx(d.Tab,{label:"Content"}),e.jsx(d.Tab,{label:"Styles"}),e.jsx(d.Tab,{label:"Cell Merging"})]})}),0===R&&e.jsxs(e.Fragment,{children:[e.jsxs(d.Box,{sx:{mb:2,p:2,bgcolor:"grey.50",borderRadius:1,border:"1px solid",borderColor:"divider"},children:[e.jsxs(d.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1},children:[e.jsx(o.Typography,{type:"s4",weight:"medium",color:"theme.primary.700",children:"Dynamic Data Settings"}),e.jsx(d.Chip,{label:`${_e} columns linked`,size:"small",color:"primary",variant:"outlined",sx:e=>{var t,l;return{color:null==(t=e.palette.theme)?void 0:t.primary[700],borderColor:null==(l=e.palette.theme)?void 0:l.primary[700]}}})]}),e.jsx(d.FormControlLabel,{control:e.jsx(n.Android12Switch,{checked:q,onChange:e=>W(e.target.checked)}),label:e.jsx(o.Typography,{type:"s5",color:"theme.secondary.800",children:"Auto-populate rows with placeholder data"})}),e.jsx(d.FormControlLabel,{control:e.jsx(n.Android12Switch,{checked:ee,onChange:e=>{te(e.target.checked),oe(null),m(e.target.checked),we()}}),label:e.jsx(o.Typography,{type:"s5",color:"theme.secondary.800",children:"Row Level Management"})}),q&&e.jsx(d.Box,{sx:{mt:1},children:e.jsx(c.Button,{variant:"outlined",size:"small",onClick:()=>{xe()},startIcon:e.jsx(U,{}),className:"black-outlined-btn",children:"Refresh Data"})})]}),e.jsxs(d.Box,{sx:{mb:2},children:[e.jsx(o.Typography,{type:"s3",weight:"medium",color:"theme.secondary.1000",sx:{mb:1},children:"Columns"}),null==(g=l.columns)?void 0:g.map((t,o)=>e.jsxs(d.Box,{sx:{mb:1,display:"flex",alignItems:"center",gap:1},children:[e.jsx(c.TextField,{label:`Column ${o+1} Header`,value:t.header,onChange:e=>{return l=t.id,o=e.target.value,void a(e=>({...e,columns:e.columns.map(e=>e.id===l?{...e,header:o}:e)}));var l,o},size:"small",sx:{flex:1}}),e.jsx(d.IconButton,{size:"small",onClick:()=>(e=>{const t=l.columns.findIndex(t=>t.id===e);if(a(l=>{var a;return{...l,name:ae||"",columns:l.columns.filter(t=>t.id!==e),rows:l.rows.map(t=>{const{[e]:l,...a}=t;return a}),mergedCells:(null==(a=l.mergedCells)?void 0:a.filter(e=>!(e.colStart<=t&&e.colEnd>=t)).map(e=>({...e,colStart:e.colStart>t?e.colStart-1:e.colStart,colEnd:e.colEnd>t?e.colEnd-1:e.colEnd})))||[]}}),le&&le[e]){const t={...le};delete t[e],i({placeholders:t})}})(t.id),disabled:l.columns.length<=1,color:"error",children:e.jsx(T.Trash,{})})]},t.id)),e.jsx(c.Button,{variant:"outlined",size:"small",onClick:()=>{const e=(()=>{const e=l.columns.map(e=>e.id);let t=1;for(;e.includes(`col${t}`);)t++;return`col${t}`})(),t={id:e,header:`Column ${l.columns.length+1}`};a(l=>{var a;return{...l,name:ae||"",columns:[...l.columns,t],rows:l.rows.map(t=>({...t,[e]:""})),mergedCells:(null==(a=l.mergedCells)?void 0:a.map(e=>({...e})))||[]}})},startIcon:e.jsx(G,{}),sx:{mt:1},className:"black-outlined-btn",children:"Add Column"})]}),e.jsx(d.Divider,{sx:{my:2}}),e.jsxs(d.Box,{sx:{mb:2},children:[e.jsxs(d.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1},children:[e.jsxs(o.Typography,{type:"s3",weight:"medium",color:"theme.secondary.1000",children:["Rows (",l.rows.length,")"]}),e.jsx(c.Button,{variant:"outlined",size:"small",disabled:ae,onClick:()=>(()=>{const e={};l.columns.forEach(t=>{if(null==le?void 0:le[t.id]){const l=le[t.id];e[t.id]=`{{${l}}}`,ee&&(e[`${t.id}_static`]=e[t.id])}else l.rows.length>0?(e[t.id]=l.rows[0][t.id]||"",ee&&(e[`${t.id}_static`]=l.rows[0][`${t.id}_static`]||"")):(ee&&(e[`${t.id}_static`]=""),e[t.id]="")}),a(t=>{var l;const a=[...t.rows,e];return{...t,rows:a,name:ae||"",mergedCells:(null==(l=t.mergedCells)?void 0:l.map(e=>({...e})))||[]}}),u()})(),startIcon:e.jsx(G,{}),className:"black-outlined-btn",children:"Add Row"})]}),!ee&&e.jsx(d.Box,{sx:{mb:2},children:e.jsx(n.SearchableSelect,{value:ae||"",label:"Select Table",options:(null==h?void 0:h.map(e=>({value:null==e?void 0:e.dataKey,label:(e.name.charAt(0).toUpperCase()+e.name.slice(1)).replaceAll("_"," ")})))||[],onChange:e=>{oe(e.target.value)}})}),l.rows.map((t,r)=>e.jsxs(d.Box,{sx:{mb:2,p:2,border:1,borderColor:"divider",borderRadius:1},children:[e.jsxs(d.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1},children:[e.jsxs(o.Typography,{type:"s4",weight:"medium",color:"theme.secondary.800",children:["Row ",r+1]}),e.jsx(d.IconButton,{size:"small",onClick:()=>(e=>{a(t=>{var l;return{...t,name:ae||"",rows:t.rows.filter((t,l)=>l!==e),mergedCells:(null==(l=t.mergedCells)?void 0:l.filter(t=>!("tbody"===t.section&&t.rowStart<=e&&t.rowEnd>=e)).map(t=>({...t,rowStart:"tbody"===t.section&&t.rowStart>e?t.rowStart-1:t.rowStart,rowEnd:"tbody"===t.section&&t.rowEnd>e?t.rowEnd-1:t.rowEnd})))||[]}}),se(t=>{const l={...t};return delete l[e],l}),re(t=>{const l={...t};return delete l[e],l})})(r),disabled:l.rows.length<=1,color:"error",children:e.jsx(T.Trash,{})})]}),e.jsx(d.Grid,{container:!0,spacing:1,children:l.columns.map((i,u)=>{var m,p,h,g;const x=ee?null==(m=ie[r])?void 0:m[i.id]:null==le?void 0:le[i.id],b=x?ve((null==le?void 0:le[i.id])||(null==(p=ie[r])?void 0:p[i.id])):null,f=be("tbody",r,u);return e.jsx(d.Grid,{item:!0,xs:12,children:ee?e.jsxs(e.Fragment,{children:[e.jsxs(o.Typography,{type:"s4",weight:"medium",color:"theme.secondary.800",children:[" ",i.header," "]}),e.jsxs(d.Box,{sx:{display:"flex",flexDirection:"row",gap:1,alignItems:"center",justifyContent:"space-between"},children:[e.jsx(c.TextField,{value:(null==(h=ne[r])?void 0:h[i.id])||"",onChange:e=>{const t=e.target.value;re(e=>{const l={...e};return l[r]||(l[r]={}),l[r][i.id]=t,l}),a(e=>({...e,rows:e.rows.map((e,l)=>l===r?{...e,[`${i.id}_static`]:t?`${t} ${e[i.id]||""}`.trim():""}:e)}))},size:"small",placeholder:"Enter custom text...",sx:{flex:1,minWidth:150}}),e.jsx(d.Box,{sx:{flex:1,minWidth:150},children:e.jsx(n.SearchableSelect,{value:f?f.merge.value:(null==(g=ie[r])?void 0:g[i.id])||t[i.id]||"",onChange:e=>((e,t,o)=>{var n;ue(!0);const r=l.columns.findIndex(e=>e.id===t),i=be("tbody",e,r),s=ee&&(null==(n=ne[e])?void 0:n[t])||"";i?a(e=>{var t;return{...e,name:ae||"",mergedCells:(null==(t=e.mergedCells)?void 0:t.map(e=>e===i.merge?{...e,value:o}:e))||[]}}):(ee&&o?se(l=>{const a={...l};return a[e]||(a[e]={}),a[e][t]=o,a}):ee&&!o&&se(l=>{var a;const o={...l};return(null==(a=o[e])?void 0:a[t])&&(delete o[e][t],0===Object.keys(o[e]).length&&delete o[e]),o}),a(l=>({...l,name:ae||"",rows:l.rows.map((l,a)=>a===e?{...l,[t]:ee?o?`{{${o}}}`:"":o?ge(o):"",[`${t}_static`]:s?`${s} ${o?ge(o):""}`.trim():o?ge(o):""}:l)})),xe())})(r,i.id,e.target.value),size:"small",options:s||[],sx:{flex:1,maxWidth:150,minWidth:150,"& .MuiInputBase-input":{bgcolor:x&&q?"grey.100":f?"blue.50":"transparent",width:150}}})})]})]}):e.jsx(c.TextField,{label:i.header,value:f?f.merge.value:t[i.id]||"",onChange:e=>((e,t,o)=>{var n;ue(!0);const r=l.columns.findIndex(e=>e.id===t),i=be("tbody",e,r),s=(null==(n=ne[e])?void 0:n[t])||"";i?a(e=>{var t;return{...e,name:ae||"",mergedCells:(null==(t=e.mergedCells)?void 0:t.map(e=>e===i.merge?{...e,value:o}:e))||[]}}):(ee&&se(l=>{const a={...l};return a[e]||(a[e]={}),o?a[e][t]=o:(delete a[e][t],0===Object.keys(a[e]).length&&delete a[e]),a}),a(l=>({...l,name:ae||"",rows:l.rows.map((l,a)=>a===e?{...l,[t]:ee?o?`{{${o}}}`:"":o,[`${t}_static`]:s?`${s} ${o||""}`.trim():o||""}:l)})),(ee||q&&(null==le?void 0:le[t]))&&xe(),ue(!1))})(r,i.id,e.target.value),size:"small",fullWidth:!0,disabled:q||x,helperText:f?`Merged cell (${f.merge.rowEnd-f.merge.rowStart+1}×${f.merge.colEnd-f.merge.colStart+1})`:x&&b?`Linked to: ${b.label}`:void 0,sx:{"& .MuiInputBase-input":{bgcolor:x&&q?"grey.100":f?"blue.50":"transparent"}}})},i.id)})})]},r))]}),e.jsx(d.Divider,{sx:{my:2}}),e.jsx(o.Typography,{type:"s3",weight:"medium",color:"theme.secondary.1000",sx:{mb:1},children:"Column Data Sources"}),0===s.length&&e.jsx(d.Alert,{severity:"info",sx:{mb:2},children:"No placeholders available. Add placeholders to dynamically populate table data."}),e.jsx(d.Grid,{container:!0,spacing:1,alignItems:"center",children:l.columns.map(r=>{var s,c;const u=(null==le?void 0:le[r.id])||(null==(c=null==(s=l.rows)?void 0:s[0])?void 0:c[r.id]),m=u?ve(u):null;return e.jsxs(t.Fragment,{children:[e.jsxs(d.Grid,{item:!0,xs:4,children:[e.jsx(o.Typography,{type:"s5",weight:"medium",color:"theme.secondary.800",children:r.header}),m&&e.jsx(o.Typography,{type:"s6",color:"theme.secondary.600",sx:{fontStyle:"italic"},children:m.type})]}),e.jsx(d.Grid,{item:!0,xs:8,children:e.jsx(n.SearchableSelect,{value:ee?"":u||"",onChange:e=>{((e,t)=>{ue(!0);const l={...le,[e]:t};if(t||delete l[e],i({placeholders:l}),q){const l=t?ge(t):"";a(t=>({...t,name:ae||"",rows:t.rows.map(t=>({...t,[e]:l}))}))}ue(!1)})(r.id,e.target.value)},size:"small",options:me.map(e=>({value:e.value,label:e.label,description:e.description})),disabled:ce||ee,sx:{flex:1,maxWidth:150,minWidth:150,"& .MuiInputBase-input":{bgcolor:"transparent",width:150}},renderOption:(l,a)=>t.createElement(d.MenuItem,{...l,key:a.value},e.jsxs(d.Box,{children:[e.jsx(o.Typography,{type:"s5",color:"theme.secondary.1000",children:a.label}),a.description&&e.jsx(o.Typography,{type:"s6",color:"theme.secondary.600",sx:{fontStyle:"italic"},children:a.description})]})),noOptionsText:e.jsx(d.MenuItem,{disabled:!0,children:e.jsx(o.Typography,{type:"s5",color:"theme.secondary.600",children:"No Data Source"})})})})]},r.id)})})]}),1===R&&e.jsxs(d.Box,{sx:{"& >:first-child":{borderTopLeftRadius:8,borderTopRightRadius:8},"& >:last-child":{borderBottomLeftRadius:8,borderBottomRightRadius:8}},children:[e.jsxs(zt,{expanded:"tableBasic"===L,onChange:je("tableBasic"),disableGutters:!0,children:[e.jsx(d.AccordionSummary,{expandIcon:e.jsx(V,{}),children:e.jsx(o.Typography,{type:"s3",color:"theme.secondary.1000",children:"Table Basic Properties"})}),e.jsx(d.AccordionDetails,{children:e.jsx(Ft,{styles:pe,onChange:(e,t)=>((e,t)=>{he(l=>({...l,[e]:t}))})(e,t),isBordered:pe.is_bordered,disableRadius:!0})})]}),e.jsxs(zt,{expanded:"tableHeader"===L,onChange:je("tableHeader"),disableGutters:!0,children:[e.jsx(d.AccordionSummary,{expandIcon:e.jsx(V,{}),children:e.jsx(o.Typography,{type:"s3",color:"theme.secondary.1000",children:"Table Header Styles"})}),e.jsx(d.AccordionDetails,{children:e.jsxs(d.Grid,{container:!0,spacing:2,children:[e.jsx(d.Grid,{item:!0,xs:12,children:e.jsx(n.ColorPickerInput,{value:(null==(x=pe.tHead)?void 0:x.backgroundColor)||"#f5f5f5",onChange:e=>Se("backgroundColor",e),fullWidth:!0,label:"Background Color"})}),e.jsx(d.Grid,{item:!0,xs:12,children:e.jsx(n.ColorPickerInput,{value:(null==(b=pe.tHead)?void 0:b.color)||"#333333",onChange:e=>Se("color",e),fullWidth:!0,label:"Text Color"})}),e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(c.TextField,{label:"Font Size",type:"number",value:(null==(f=pe.tHead)?void 0:f.fontSize)||14,onChange:e=>Se("fontSize",parseInt(e.target.value)||14),size:"small",fullWidth:!0})}),e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(c.Select,{value:(null==(y=pe.tHead)?void 0:y.fontWeight)||"bold",onChange:e=>Se("fontWeight",e.target.value),fullWidth:!0,size:"small",label:"Font Weight",children:Nt.map(t=>e.jsx(d.MenuItem,{value:t,children:w.formatText(t)},t))})}),e.jsx(d.Grid,{item:!0,xs:12,children:e.jsx(c.Select,{value:(null==(v=pe.tHead)?void 0:v.fontFamily)||"Arial, sans-serif",onChange:e=>Se("fontFamily",e.target.value),fullWidth:!0,size:"small",label:"Font Family",children:Lt.map(t=>e.jsx(d.MenuItem,{value:t,children:t.split(",")[0]},t))})}),e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(c.Select,{value:(null==(j=pe.tHead)?void 0:j.textAlign)||"left",onChange:e=>Se("textAlign",e.target.value),fullWidth:!0,size:"small",label:"Text Align",children:Rt.map(t=>e.jsx(d.MenuItem,{value:t,children:w.formatText(t)},t))})}),e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(c.TextField,{label:"Cell Padding",type:"number",value:(null==(S=pe.thCells)?void 0:S.padding)||8,onChange:e=>{return t="padding",l=parseInt(e.target.value)||8,void he(e=>({...e,thCells:{...e.thCells,[t]:l}}));var t,l},size:"small",fullWidth:!0})}),e.jsx(d.Grid,{item:!0,xs:12,children:e.jsx(d.FormControlLabel,{control:e.jsx(n.Android12Switch,{checked:!!(null==(C=pe.tBody)?void 0:C.zebraStriping),onChange:e=>Ce("zebraStriping",e.target.checked)}),label:"Zebra Striping"})}),(null==(_=pe.tBody)?void 0:_.zebraStriping)&&e.jsxs(d.Grid,{item:!0,xs:12,children:[e.jsx(o.Typography,{type:"s5",weight:"medium",color:"theme.secondary.1000",variant:"caption",children:"Alternating Row Color"}),e.jsx(n.ColorPickerInput,{value:(null==(k=pe.tBody)?void 0:k.alternateRowColor)||"#f9f9f9",onChange:e=>Ce("alternateRowColor",e),fullWidth:!0})]})]})})]}),e.jsxs(zt,{expanded:"tableBody"===L,onChange:je("tableBody"),disableGutters:!0,children:[e.jsx(d.AccordionSummary,{expandIcon:e.jsx(V,{}),children:e.jsx(o.Typography,{type:"s3",color:"theme.secondary.1000",children:"Table Body Styles"})}),e.jsx(d.AccordionDetails,{children:e.jsxs(d.Grid,{container:!0,spacing:2,children:[e.jsx(d.Grid,{item:!0,xs:12,children:e.jsx(n.ColorPickerInput,{value:(null==(I=pe.tBody)?void 0:I.backgroundColor)||"#ffffff",onChange:e=>Ce("backgroundColor",e),fullWidth:!0,label:"Background Color"})}),e.jsx(d.Grid,{item:!0,xs:12,children:e.jsx(n.ColorPickerInput,{value:(null==(E=pe.tBody)?void 0:E.color)||"#333333",onChange:e=>Ce("color",e),fullWidth:!0,label:"Text Color"})}),e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(c.TextField,{label:"Font Size",type:"number",value:(null==(B=pe.tBody)?void 0:B.fontSize)||14,onChange:e=>Ce("fontSize",parseInt(e.target.value)||14),size:"small",fullWidth:!0})}),e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(c.Select,{value:(null==(A=pe.tBody)?void 0:A.fontWeight)||"normal",onChange:e=>Ce("fontWeight",e.target.value),fullWidth:!0,size:"small",label:"Font Weight",children:Nt.map(t=>e.jsx(d.MenuItem,{value:t,children:w.formatText(t)},t))})}),e.jsx(d.Grid,{item:!0,xs:12,children:e.jsx(c.Select,{value:(null==(M=pe.tBody)?void 0:M.fontFamily)||"Arial, sans-serif",onChange:e=>Ce("fontFamily",e.target.value),fullWidth:!0,size:"small",label:"Font Family",children:Lt.map(t=>e.jsx(d.MenuItem,{value:t,children:t.split(",")[0]},t))})}),e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(c.Select,{value:(null==(F=pe.tBody)?void 0:F.textAlign)||"left",onChange:e=>Ce("textAlign",e.target.value),fullWidth:!0,size:"small",label:"Text Align",children:Rt.map(t=>e.jsx(d.MenuItem,{value:t,children:w.formatText(t)},t))})}),e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(c.TextField,{label:"Cell Padding",type:"number",value:(null==($=pe.tbCells)?void 0:$.padding)||8,onChange:e=>{return t="padding",l=parseInt(e.target.value)||8,void he(e=>({...e,tbCells:{...e.tbCells,[t]:l}}));var t,l},size:"small",fullWidth:!0})})]})})]})]}),2===R&&e.jsxs(d.Box,{children:[e.jsxs(d.Box,{sx:{mb:3},children:[e.jsx(o.Typography,{type:"s3",weight:"medium",color:"theme.secondary.1000",sx:{mb:2},children:"Cell Selection & Merging"}),e.jsx(d.Alert,{severity:"info",sx:{mb:2},children:"Click on cells in the table below to select them for merging. Selected cells will be highlighted. You can merge cells within the header or body, but not across both."}),e.jsxs(d.Box,{sx:{display:"flex",gap:1,mb:2,flexWrap:"wrap"},children:[e.jsxs(c.Button,{variant:"contained",size:"small",onClick:()=>{var e,t,a,o;if(Y.length<2)return void alert("Please select at least 2 cells to merge");const n=Y[0];let r="",i="";if("tbody"===n.section){const o=null==(e=l.columns[n.col])?void 0:e.id;r=(null==(t=l.rows[n.row])?void 0:t[o])||"",ee&&(i=(null==(a=ne[n.row])?void 0:a[o])||"")}else r=(null==(o=l.columns[n.col])?void 0:o.header)||"";const s=ee&&i?`${i} ${r}`.trim():r;Q(s),J(!0)},startIcon:e.jsx(K,{}),disabled:Y.length<2,color:"primary",children:["Merge Selected (",Y.length,")"]}),e.jsx(c.Button,{variant:"outlined",size:"small",onClick:()=>Z([]),disabled:0===Y.length,className:"black-outlined-btn",children:"Clear Selection"})]}),e.jsx(d.Box,{sx:{border:1,borderColor:"divider",borderRadius:1,overflow:"auto",maxHeight:400},children:e.jsxs(d.Table,{size:"small",sx:{minWidth:300},children:[e.jsx(d.TableHead,{children:e.jsx(d.TableRow,{children:l.columns.map((t,l)=>{const a=be("thead",0,l),o=fe("thead",0,l);if(null==a?void 0:a.isCovered)return null;const r=a?a.merge.value:t.header,i=a?a.merge.rowEnd-a.merge.rowStart+1:1,s=a?a.merge.colEnd-a.merge.colStart+1:1;return e.jsxs(d.TableCell,{rowSpan:i,colSpan:s,onClick:()=>!a&&ye("thead",0,l),sx:e=>({fontWeight:"bold",bgcolor:a?"blue.50":o?"primary.100":"grey.100",position:"sticky",top:0,zIndex:1,cursor:a?"default":"pointer",border:o?2:1,borderColor:o?e.palette.theme.primary[800]:"divider","&:hover":a?{}:{bgcolor:o?"primary.200":"grey.50"}}),children:[r,a&&e.jsx(d.Chip,{label:`${i}×${s}`,size:"small",color:"primary",variant:"outlined",sx:e=>({position:"absolute",top:2,right:2,fontSize:"0.6rem",height:16,color:e.palette.theme.primary[800],borderColor:e.palette.theme.primary[800]})}),o&&e.jsx(n.Checkbox,{checked:!0,size:"small",sx:{position:"absolute",top:2,left:2,padding:0}})]},t.id)})})}),e.jsx(d.TableBody,{children:l.rows.map((t,a)=>e.jsx(d.TableRow,{children:l.columns.map((l,o)=>{var r;const i=be("tbody",a,o),s=fe("tbody",a,o);if(null==i?void 0:i.isCovered)return null;const c=(null==(r=ne[a])?void 0:r[l.id])||"",u=i?i.merge.value:c?`${c} ${t[l.id]||""}`.trim():t[l.id]||"",m=i?i.merge.rowEnd-i.merge.rowStart+1:1,p=i?i.merge.colEnd-i.merge.colStart+1:1;return e.jsxs(d.TableCell,{rowSpan:m,colSpan:p,onClick:()=>!i&&ye("tbody",a,o),sx:e=>{var t;return{cursor:i?"default":"pointer",bgcolor:i?"blue.50":s?"primary.100":"transparent",border:s?2:1,borderColor:s?null==(t=e.palette.theme)?void 0:t.primary[800]:"divider","&:hover":i?{}:{bgcolor:s?"primary.200":"grey.50"},position:"relative"}},children:[u,i&&e.jsx(d.Chip,{label:`${m}×${p}`,size:"small",color:"primary",variant:"outlined",sx:e=>{var t,l;return{position:"absolute",top:2,right:2,fontSize:"0.6rem",height:16,color:null==(t=e.palette.theme)?void 0:t.primary[800],borderColor:null==(l=e.palette.theme)?void 0:l.primary[800]}}}),s&&e.jsx(n.Checkbox,{checked:!0,size:"small",sx:{position:"absolute",top:2,left:2,padding:0}})]},l.id)})},a))})]})})]}),de.length>0&&e.jsxs(d.Box,{sx:{mt:3},children:[e.jsxs(o.Typography,{type:"s3",weight:"medium",color:"theme.secondary.1000",sx:{mb:2},children:["Merged Cells (",de.length,")"]}),de.map((t,l)=>e.jsxs(d.Box,{sx:{p:2,mb:1,border:1,borderColor:"divider",borderRadius:1,bgcolor:"blue.25"},children:[e.jsxs(d.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",mb:1},children:[e.jsxs(d.Box,{children:[e.jsxs(o.Typography,{type:"s4",weight:"medium",color:"theme.secondary.900",children:["Merge ",l+1,": ",t.rowEnd-t.rowStart+1,"×",t.colEnd-t.colStart+1," cells (",t.section,")"]}),e.jsxs(o.Typography,{type:"s5",color:"theme.secondary.700",children:["Rows ",t.rowStart+1,"-",t.rowEnd+1,", Columns ",t.colStart+1,"-",t.colEnd+1]})]}),e.jsx(c.Button,{variant:"outlined",size:"small",onClick:()=>(e=>{const t=de[e];a(l=>{var a,o;const n=[...l.rows],r=[...l.columns];if("tbody"===t.section)for(let e=t.rowStart;e<=t.rowEnd;e++)for(let o=t.colStart;o<=t.colEnd;o++){const r=null==(a=l.columns[o])?void 0:a.id;r&&n[e]&&(n[e][r]=t.value)}else r[t.colStart]&&(r[t.colStart].header=t.value);return{...l,rows:n,name:ae||"",columns:r,mergedCells:(null==(o=l.mergedCells)?void 0:o.filter((t,l)=>l!==e))||[]}})})(l),startIcon:e.jsx(D,{}),className:"black-outlined-btn",children:"Split"})]}),e.jsx(c.TextField,{label:"Merged Cell Value",value:t.value,onChange:e=>{a(t=>{var a;return{...t,mergedCells:(null==(a=t.mergedCells)?void 0:a.map((t,a)=>a===l?{...t,value:e.target.value}:t))||[]}})},size:"small",fullWidth:!0,multiline:!0,rows:2})]},l))]})]}),e.jsxs(d.Dialog,{open:H,onClose:()=>J(!1),maxWidth:"sm",fullWidth:!0,children:[e.jsx(d.DialogTitle,{children:e.jsx(o.Typography,{type:"s2",weight:"medium",children:"Merge Selected Cells"})}),e.jsxs(d.DialogContent,{children:[e.jsxs(o.Typography,{type:"s4",color:"theme.secondary.700",sx:{mb:2},children:["You are about to merge ",Y.length," selected cells in ",null==(P=Y[0])?void 0:P.section,". Enter the value for the merged cell:"]}),e.jsx(c.TextField,{label:"Merged Cell Value",value:X,onChange:e=>Q(e.target.value),fullWidth:!0,multiline:!0,rows:3,sx:{mt:1}}),e.jsxs(d.Alert,{severity:"info",sx:{mt:2},children:["The merged cell will span from row ",Math.min(...Y.map(e=>e.row))+1," to ",Math.max(...Y.map(e=>e.row))+1,"and column ",Math.min(...Y.map(e=>e.col))+1," to ",Math.max(...Y.map(e=>e.col))+1," in ",null==(z=Y[0])?void 0:z.section,"."]})]}),e.jsxs(d.DialogActions,{children:[e.jsx(c.Button,{onClick:()=>J(!1),children:"Cancel"}),e.jsx(c.Button,{onClick:()=>{if(Y.length<2)return;const e=Y[0].section,t=Y.map(e=>e.row),l=Y.map(e=>e.col),o=Math.min(...t),n=Math.max(...t),r=Math.min(...l),i=Math.max(...l),s=(n-o+1)*(i-r+1);if(Y.length!==s)return void alert("Please select a rectangular area of cells to merge");if(de.some(t=>t.section===e&&!(n<t.rowStart||o>t.rowEnd||i<t.colStart||r>t.colEnd)))return void alert("Cannot merge cells that overlap with existing merged cells");const d={section:e,rowStart:o,rowEnd:n,colStart:r,colEnd:i,value:X};a(t=>({...t,name:ae||"",mergedCells:[...t.mergedCells||[],d],columns:"thead"===e?t.columns.map((e,t)=>t===r?{...e,header:X}:e):t.columns})),Z([]),Q(""),J(!1)},variant:"contained",color:"primary",children:"Merge Cells"})]})]})]})},qt=({attrs:t,updateAttrs:l})=>{const{styles:a}=t;return e.jsxs(e.Fragment,{children:[e.jsxs(d.Box,{sx:{mb:1},children:[e.jsx(o.Typography,{type:"s5",color:"theme.secondary.800",weight:"medium",children:"Font Size"}),e.jsx(d.Slider,{value:null==a?void 0:a.fontSize,onChange:(e,t)=>l({styles:{fontSize:t}}),min:10,max:20,step:1,valueLabelDisplay:"auto",size:"small",sx:e=>({"& .MuiSlider-rail":{color:e.palette.theme.primary[500]},"& .MuiSlider-thumb":{color:e.palette.theme.primary[800]},"& .MuiSlider-track":{color:e.palette.theme.primary[600]}})})]}),e.jsx(d.Box,{sx:{mb:2},children:e.jsx(c.TextField,{label:"Text Color",type:"color",value:null==a?void 0:a.color,onChange:e=>l({styles:{color:e.target.value}}),fullWidth:!0,InputProps:{startAdornment:e.jsx(d.InputAdornment,{position:"start",children:e.jsx(N,{fontSize:"small"})})}})})]})},Wt=({attrs:t,updateAttrs:l})=>{const{styles:a}=t,n=e=>{l({styles:e})};return e.jsxs(e.Fragment,{children:[e.jsxs(d.Box,{sx:{mb:2},children:[e.jsx(o.Typography,{type:"s3",color:"theme.neutral.800",children:"Size (px)"}),e.jsx(d.Slider,{value:a.fontSize,onChange:(e,t)=>n({fontSize:t}),min:10,max:25,step:5,valueLabelDisplay:"auto",size:"small",sx:e=>({"& .MuiSlider-rail":{color:e.palette.theme.primary[500]},"& .MuiSlider-thumb":{color:e.palette.theme.primary[800]},"& .MuiSlider-track":{color:e.palette.theme.primary[600]}})})]}),e.jsx(Ct,{alignment:null==a?void 0:a.textAlign,onAlignmentChange:(e,t)=>{null!==t&&n({textAlign:t})},displayLabel:!0})]})},Ht=["text","text-block","heading","heading-2","heading-3","heading-4","buttons","image","divider","table","signature","qr-code","bar-code"],Vt=({section:l,onClose:a,onUpdate:n,placeholders:r,relation_table:i,handleSave:s})=>{var u,m;const p=t.useMemo(()=>(null==l?void 0:l.type)||"text",[null==l?void 0:l.type]),h=t.useMemo(()=>(null==l?void 0:l.content)||"text",[null==l?void 0:l.content]);t.useState([]);const[g,x]=t.useState((null==(u=null==l?void 0:l.attributes)?void 0:u.rowLevel)||!1),[b,f]=t.useState({name:"",columns:[{id:"col1",header:"Column 1"},{id:"col2",header:"Column 2"},{id:"col3",header:"Column 3"}],rows:[{col1:"",col2:"",col3:""}],border:!0,mergedCells:[]}),[y,v]=t.useState(!0),[j,S]=t.useState(ct(h));t.useEffect(()=>{var e,t;if(l&&"table"===l.type)if(null==(e=l.attributes)?void 0:e.tableData)f(l.attributes.tableData);else{const e=C(l.content);e&&(f(e),x((null==(t=null==l?void 0:l.attributes)?void 0:t.rowLevel)||!1))}},[]),t.useEffect(()=>{var e;l&&!y&&(document.createElement("div").innerHTML=l.content,S(null==(e=ct(l.content))?void 0:e.styles),v(!1))},[l]);const C=e=>{try{const t=(new DOMParser).parseFromString(e,"text/html").querySelector("table");if(!t)return null;const l=t.querySelectorAll("thead tr"),a=t.querySelectorAll("tbody tr");if(0===l.length)return null;const o=l[0].querySelectorAll("th"),n=Array.from(o).map((e,t)=>{var l;return{id:`col${t+1}`,header:(null==(l=e.textContent)?void 0:l.trim())||`Column ${t+1}`}}),r=[];Array.from(l).forEach((e,t)=>{e.querySelectorAll("th").forEach((e,l)=>{var a;const o=parseInt(e.getAttribute("rowspan")||"1"),n=parseInt(e.getAttribute("colspan")||"1");(o>1||n>1)&&r.push({section:"thead",rowStart:t,rowEnd:t+o-1,colStart:l,colEnd:l+n-1,value:(null==(a=e.textContent)?void 0:a.trim())||""})})});const i=Array.from(a).map(e=>{const t=e.querySelectorAll("td"),l={};return t.forEach((e,t)=>{var a;t<n.length&&(l[n[t].id]=(null==(a=e.textContent)?void 0:a.trim())||"")}),l});return Array.from(a).forEach((e,t)=>{e.querySelectorAll("td").forEach((e,l)=>{var a;const o=parseInt(e.getAttribute("rowspan")||"1"),n=parseInt(e.getAttribute("colspan")||"1");(o>1||n>1)&&r.push({section:"tbody",rowStart:t,rowEnd:t+o-1,colStart:l,colEnd:l+n-1,value:(null==(a=e.textContent)?void 0:a.trim())||""})})}),{name:"",columns:n,rows:i.length>0?i:[{}],border:!0,mergedCells:r}}catch(t){return null}},w=t.useCallback(e=>{var t;const{src:a,alt:o,styles:n,text:i,placeholder:s,placeholders:d}=e||(null==l?void 0:l.attributes)||j||{},c={...M.initialStyles[p],...n,...null==j?void 0:j.styles,...null==e?void 0:e.styles},u=mt(c);if("buttons"===p)return`<button style="${u}">${i||"Button Text"}</button>`;if("image"===p){let e=u;return(null==c?void 0:c.is_bordered)?(c.padding="10px",e=mt(c)):(c.padding="0",e=mt(c)),`<img src="${a||""}" alt="${o||""}" style="${e}" />`}if("divider"===p)return`<hr style="${u}" />`;if("table"===p){const{border:e,borderStyle:l,borderColor:a,...o}=c,n=mt(c.is_bordered?c:o),i=mt(c.tHead||{}),s=mt(c.tBody||{}),u=mt({...c.thCells||{},...c.is_bordered?{border:e,borderStyle:l,borderColor:a}:{}}),m=mt({...c.tbCells||{},...c.is_bordered?{border:e,borderStyle:l,borderColor:a}:{}}),p=(e,t,l)=>{var a;return null==(a=b.mergedCells)?void 0:a.find(a=>a.section===e&&t>=a.rowStart&&t<=a.rowEnd&&l>=a.colStart&&l<=a.colEnd)},h=b.columns.map((e,t)=>{const l=p("thead",0,t);if(l&&t!==l.colStart)return"";const a=l?` rowspan="${l.rowEnd-l.rowStart+1}" colspan="${l.colEnd-l.colStart+1}"`:"",o=l?l.value:e.header;return`<th style="${u}"${a}>${o}</th>`}).filter(e=>""!==e).join("");let g="";if(b.name){const e=b.columns.map((e,t)=>{var l,a;const o=p("tbody",0,t);if(o&&t!==o.colStart)return"";const n=o?` rowspan="${o.rowEnd-o.rowStart+1}" colspan="${o.colEnd-o.colStart+1}"`:"";let r="";if("index"===e.id||"incrementIndex"===e.id)r="{{incrementIndex @index}}";else if(e.id.includes(".")){const t=null==(l=null==b?void 0:b.rows)?void 0:l[0][e.id];r="string"==typeof t?t.replace(b.name+".",""):String(t||"")}else{const t=null==(a=null==b?void 0:b.rows)?void 0:a[0][e.id];r="string"==typeof t?t.replace(b.name+".",""):String(t||"")}return`<td style="${m}"${n}>${r}</td>`}).filter(e=>""!==e).join(""),l=(null==(t=c.tBody)?void 0:t.zebraStriping)?`{{#if (isOdd @index)}}${s}; background-color: ${c.tBody.alternateRowColor||"#f9f9f9"}{{else}}${s}{{/if}}`:s;g=`{{#each ${b.name}}}\n <tr style="${l}">\n ${e}\n </tr>\n {{/each}}`}else g=b.rows.map((e,t)=>{var l;const a=(null==(l=c.tBody)?void 0:l.zebraStriping)&&t%2==1?`; background-color: ${c.tBody.alternateRowColor||"#f9f9f9"}`:"",o=b.columns.map((l,a)=>{const o=p("tbody",t,a);if(o&&(t!==o.rowStart||a!==o.colStart))return"";let n=e[l.id]||"";Object.keys(e).includes(`${l.id}_static`)&&(n=e[`${l.id}_static`]||""),!n&&(null==d?void 0:d[l.id])&&(n=(e=>{const t=r.find(t=>t.value===e);if(!t)return"";if(void 0!==t.actualValue)return String(t.actualValue);switch(t.type){case"date":return(new Date).toLocaleDateString();case"datetime":return(new Date).toLocaleString();case"number":return"123";case"currency":return"$1,234.56";case"email":return"example@domain.com";case"phone":return"+1 (555) 123-4567";case"url":return"https://example.com";default:return t.label||t.value}})(d[l.id]));const i=o?` rowspan="${o.rowEnd-o.rowStart+1}" colspan="${o.colEnd-o.colStart+1}"`:"",s=o?o.value:n;return`<td style="${m}"${i}>${s}</td>`}).filter(e=>""!==e).join("");return`<tr style="${s}${a}">${o}</tr>`}).join("");return`\n <table style="${n}">\n <thead>\n <tr style="${i}">\n ${h}\n </tr>\n </thead>\n <tbody>\n ${g}\n </tbody>\n </table>\n `}if("qr-code"===p||"bar-code"===p)return`<div style="${u}">${s}</div>`;if(/<\/?[a-z][\s\S]*>/i.test(h)){const e=(new DOMParser).parseFromString(`<div>${h}</div>`,"text/html").body.firstChild;return e&&e.nodeType===Node.ELEMENT_NODE?(e.querySelectorAll("*").forEach(e=>{if("SCRIPT"===e.tagName||"STYLE"===e.tagName)return;const t=e.getAttribute("style")||"",l={};t.split(";").forEach(e=>{const[t,a]=e.split(":").map(e=>e.trim());t&&a&&(l[t]=a)});const a={};u.split(";").forEach(e=>{const[t,l]=e.split(":").map(e=>e.trim());t&&l&&(a[t]=l)}),"P"===e.tagName||"DIV"===e.tagName?a["line-height"]="1.5":["H1","H2","H3","H4","H5","H6"].includes(e.tagName)&&(a["line-height"]="1.2",a.margin="0.5em 0");const o={...l,...a},n=Object.entries(o).filter(([e,t])=>e&&t).map(([e,t])=>`${e}: ${t}`).join("; ");e.setAttribute("style",n)}),e.innerHTML):h}switch(p){case"text":case"text-block":default:return`<p style="${u}">${h}</p>`;case"heading":return`<h1 style="${u}">${h}</h1>`;case"heading-2":return`<h2 style="${u}">${h}</h2>`;case"heading-3":return`<h3 style="${u}">${h}</h3>`;case"heading-4":return`<h4 style="${u}">${h}</h4>`;case"signature":return`<div style="${u}">${h}</div>`}},[JSON.stringify(l)]),_=()=>{const e={content:w(),type:p,rowLevel:g,name:b.name||"",attributes:{...(null==l?void 0:l.attributes)||{},..."table"===p?{tableData:b}:{}},is_edited_from_source:(null==l?void 0:l.is_edited_from_source)||!1};n(e)};t.useEffect(()=>{_()},[b]);const k=e=>{var t;if(!l)return;const a={...(null==(t=l.attributes)?void 0:t.styles)||{},...e.styles||{}},o={...l.attributes||{},...e,styles:a,..."table"===p?{tableData:b}:{}},{id:r,...i}=l,s=w(o);S(o),n({...i,content:s,attributes:o})};return e.jsxs(d.Paper,{elevation:3,sx:{width:{xs:"100%",sm:320,lg:390},height:"100%",overflow:"auto",borderLeft:"1px solid",borderColor:"divider",display:"flex",flexDirection:"column",bgcolor:"background.paper",boxShadow:"none"},children:[e.jsxs(d.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",p:2,borderBottom:"1px solid",borderColor:"divider",bgcolor:"grey.50"},children:[e.jsxs(o.Typography,{type:"s1",weight:"bold",color:"theme.neutral.1000",children:["Format ",p?(null==(m=null==p?void 0:p.charAt(0))?void 0:m.toUpperCase())+(null==p?void 0:p.slice(1).replace(/-/g," ")):""]}),e.jsx(d.Tooltip,{title:"Save and Close",children:e.jsxs(d.Box,{children:[e.jsx(d.IconButton,{size:"small",onClick:()=>{_(),null==s||s(),a()},"aria-label":"Save",children:e.jsx(T.Save,{fontSize:"small"})}),e.jsx(d.IconButton,{size:"small",onClick:a,"aria-label":"Close",children:e.jsx(E,{fontSize:"small"})})]})})]}),e.jsxs(d.Box,{sx:{p:2,flex:1,pb:10,overflowY:"auto"},children:[e.jsx(d.Box,{sx:{mb:2},children:e.jsx(d.FormControl,{size:"small",fullWidth:!0,children:e.jsx(c.Select,{value:null==l?void 0:l.type,onChange:e=>(e=>{const t=pt(e);n({...l,...t}),"table"===e&&f({name:"",columns:[{id:"col1",header:"Column 1"},{id:"col2",header:"Column 2"},{id:"col3",header:"Column 3"}],rows:[{col1:"",col2:"",col3:""}],border:!0,mergedCells:[]})})(e.target.value),renderValue:e=>e?e.charAt(0).toUpperCase()+e.slice(1).replace(/-/g," "):"",label:"Select Preset",displayEmpty:!0,children:Ht.map(t=>e.jsx(d.MenuItem,{value:t,children:e.jsx(o.Typography,{type:"s4",color:"theme.secondary.1000",children:t.charAt(0).toUpperCase()+t.slice(1).replace(/-/g," ")})},t))})})}),l&&("text"===p||"heading"===p||"heading-2"===p||"heading-3"===p||"heading-4"===p)&&e.jsx(It,{attrs:(null==l?void 0:l.attributes)||{},updateAttrs:k}),"buttons"===p&&e.jsx(Bt,{attrs:(null==l?void 0:l.attributes)||{},updateAttrs:k}),"image"===p&&e.jsx(Dt,{attrs:(null==l?void 0:l.attributes)||{},updateAttrs:k}),"divider"===p&&e.jsx(Pt,{attrs:(null==l?void 0:l.attributes)||{},updateAttrs:k}),"table"===p&&e.jsx(Ot,{tableData:{...b,rows:b.rows.map(e=>{const t={};return Object.keys(e).forEach(l=>{t[l]=String(e[l]??"")}),t})},setTableData:e=>{var t;t={...e,border:b.border,name:b.name||""},f(t),_()},attrs:(null==l?void 0:l.attributes)||{},updateAttrs:k,placeholders:r,handleSave:s,setParentRowLevel:x,levelType:g,relation_table:i}),"signature"===p&&e.jsx(qt,{attrs:(null==l?void 0:l.attributes)||{},updateAttrs:k}),l&&("qr-code"===p||"bar-code"===p)&&e.jsx(Wt,{attrs:(null==l?void 0:l.attributes)||{},updateAttrs:k})]})]})},Gt=b.styled(d.ListItem)(({theme:e})=>({padding:e.spacing(1.5),cursor:"grab",borderRadius:e.shape.borderRadius,"&:hover":{backgroundColor:e.palette.grey[100]},"&.dragging":{opacity:.5}})),Ut=b.styled(d.Box)(({theme:e})=>({border:`2px dashed ${e.palette.grey[400]}`,borderRadius:e.shape.borderRadius,padding:e.spacing(2),textAlign:"center",backgroundColor:e.palette.grey[50],cursor:"pointer","&:hover":{backgroundColor:e.palette.grey[100]}})),Kt=({id:t,icon:l,label:a,imageUrl:o})=>{const n="string"==typeof t?t.replace("sidebar-",""):t,{attributes:r,listeners:i,setNodeRef:s,isDragging:c}=F.useDraggable({id:t,data:{type:o?"image":n,imageUrl:o,label:a}});return e.jsx(Gt,{ref:s,...i,...r,className:c?"dragging":"",sx:{border:"1px solid",borderColor:"grey.200",p:.75},children:o?e.jsx("img",{src:o,alt:a,style:{width:"100%",height:140,objectFit:"cover",marginRight:8}}):e.jsxs(e.Fragment,{children:[e.jsx(d.ListItemIcon,{sx:{minWidth:40},children:l}),e.jsx(d.ListItemText,{primary:a,primaryTypographyProps:{variant:"body2"}})]})})},Jt=({onHtmlUpload:l})=>{const[a,o]=t.useState("text"),[n,r]=t.useState([]),[i,s]=t.useState(!1),[u,m]=t.useState(!1),[p,g]=t.useState(null),x=t.useCallback(async e=>{s(!0),g(null);try{for(const t of e){const e=await w.uploadFiles([t],"document"),l=w.getToken(),a={...l,"x-timezone":String(l["x-timezone"]||""),title:null==t?void 0:t.name.split(".")[0],path:"/",is_private:!0,is_directory:!1,file_size:t.size,is_child:!1,file_extension:null==t?void 0:t.name.split(".")[1],type:"image",mime_type:t.type,url:`${h.getApiConfig().s3BucketUrl}${e[0]}`};await Z.postV1Drive(a),r(l=>[...l,{id:`uploaded-image-${Date.now()}-${Math.random()}`,url:`${h.getApiConfig().s3BucketUrl}${e[0]}`,name:t.name}])}}catch(t){g("Failed to upload image. Please try again.")}finally{s(!1)}},[]),{getRootProps:b,getInputProps:f,isDragActive:y}=J.useDropzone({onDrop:x,accept:{"image/*":[".jpeg",".png",".jpg",".gif"]},multiple:!0}),v=t.useCallback(async e=>{if(l){m(!0),g(null);try{const t=e[0];if(!t)return;const a=new FileReader;a.onload=e=>{var t;const a=null==(t=e.target)?void 0:t.result;a&&(l(a),m(!1))},a.onerror=()=>{g("Failed to read HTML file. Please try again."),m(!1)},a.readAsText(t)}catch(t){g("Failed to process HTML file. Please try again."),m(!1)}}},[l]),{getRootProps:j,getInputProps:S,isDragActive:C}=J.useDropzone({onDrop:v,accept:{"text/html":[".html",".htm"]},multiple:!1,maxFiles:1}),_=[{id:"html-upload",icon:e.jsx(Y.FileCode,{size:18}),label:"Upload HTML",content:e.jsxs(d.Box,{sx:{mt:2},children:[e.jsxs(Ut,{...j(),children:[e.jsx("input",{...S()}),C?e.jsx(d.Typography,{variant:"body2",color:"text.secondary",children:"Drop the HTML file here..."}):e.jsx(d.Typography,{variant:"body2",color:"text.secondary",children:"Drag and drop HTML file here, or click to select"}),u&&e.jsx(d.Box,{sx:{mt:1},children:e.jsx(d.CircularProgress,{size:20})})]}),e.jsx(d.Typography,{variant:"caption",color:"text.secondary",sx:{mt:1,display:"block"},children:"Upload an HTML file to replace current sections with the file content"})]})},{id:"text",icon:e.jsx(Y.Text,{size:18}),label:"Text",content:e.jsxs(d.Box,{sx:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:1},children:[e.jsx(Kt,{id:"sidebar-heading",icon:e.jsx(Y.Heading,{size:20}),label:"Heading 1"}),e.jsx(Kt,{id:"sidebar-heading-2",icon:e.jsx(Y.Heading,{size:18}),label:"Heading 2"}),e.jsx(Kt,{id:"sidebar-heading-3",icon:e.jsx(Y.Heading,{size:16}),label:"Heading 3"}),e.jsx(Kt,{id:"sidebar-heading-4",icon:e.jsx(Y.Heading,{size:14}),label:"Heading 4"}),e.jsx(Kt,{id:"sidebar-text",icon:e.jsx(Y.Text,{size:20}),label:"Body"}),e.jsx(Kt,{id:"sidebar-text-block",icon:e.jsx(Y.Text,{size:20}),label:"Text Block"})]})},{id:"images",icon:e.jsx(Y.Image,{size:18}),label:"Images",content:e.jsx(d.Box,{sx:{mt:2},children:e.jsxs(d.Box,{sx:{mt:2},children:[e.jsxs(Ut,{...b(),children:[e.jsx("input",{...f()}),y?e.jsx(d.Typography,{variant:"body2",color:"text.secondary",children:"Drop the images here..."}):e.jsx(d.Typography,{variant:"body2",color:"text.secondary",children:"Drag and drop images here, or click to select"}),i&&e.jsx(d.Box,{sx:{mt:1},children:e.jsx(d.CircularProgress,{size:20})})]}),p&&e.jsx(d.Alert,{severity:"error",sx:{mt:2},children:p}),n.length>0&&e.jsxs(d.Box,{sx:{mt:2},children:[e.jsx(d.Typography,{variant:"body2",sx:{mb:1,color:"grey.500"},children:"Uploaded Images"}),e.jsx(d.Grid,{container:!0,spacing:1,children:n.map(t=>e.jsx(d.Grid,{item:!0,xs:6,children:e.jsx(Kt,{id:t.id,label:t.name,imageUrl:t.url})},t.id))})]})]})})},{id:"buttons",icon:e.jsx(d.Box,{sx:{width:16,height:16,bgcolor:"grey.400",borderRadius:1,color:"white",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"8px"},children:"BTN"}),label:"Buttons",content:e.jsx(d.Box,{sx:{mt:2},children:e.jsx(Kt,{id:"sidebar-buttons",icon:e.jsx(d.Box,{sx:{width:20,height:20,bgcolor:"success.main",borderRadius:1,color:"white",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px"},children:"BTN"}),label:"Buttons"})})},{id:"divider",icon:e.jsx(d.Divider,{sx:{width:18}}),label:"Divider",content:e.jsx(d.Box,{sx:{mt:2},children:e.jsx(Kt,{id:"sidebar-divider",icon:e.jsx(d.Divider,{sx:{width:20}}),label:"Divider"})})},{id:"table",icon:e.jsx(Y.Table,{size:18}),label:"Table",content:e.jsx(d.Box,{sx:{mt:2},children:e.jsx(Kt,{id:"sidebar-table",icon:e.jsx(Y.Table,{size:20}),label:"Table"})})},{id:"signature",icon:e.jsx(Y.Blocks,{size:18}),label:"Signature",content:e.jsx(d.Box,{sx:{mt:2},children:e.jsx(Kt,{id:"sidebar-signature",icon:e.jsx(Y.Blocks,{size:20}),label:"Signature"})})},{id:"qr-code",icon:e.jsx(Y.QrCode,{size:18}),label:"QR Code",content:e.jsx(d.Box,{sx:{mt:2},children:e.jsx(Kt,{id:"sidebar-qr-code",icon:e.jsx(Y.QrCode,{size:20}),label:"QR Code"})})},{id:"bar-code",icon:e.jsx(Y.Barcode,{size:18}),label:"Bar Code",content:e.jsx(d.Box,{sx:{mt:2},children:e.jsx(Kt,{id:"sidebar-bar-code",icon:e.jsx(Y.Barcode,{size:20}),label:"Bar Code"})})}];return t.useEffect(()=>{(async()=>{try{const e=w.getToken(),t=await Z.getV1Drive({...e,"x-timezone":String(e["x-timezone"]||""),skip:0,limit:10,filters:"(is_directory.eq=0)"});if("data"in t&&t.data&&"object"==typeof t.data&&"drive"in t.data){const e=t.data.drive||[];r(e)}}catch(e){console.log(e)}})()},[]),e.jsxs(d.Box,{sx:{bgcolor:"background.paper",borderRight:1,borderColor:"grey.200",width:390,display:"flex",flexDirection:"column",height:"calc(100vh - 104px)",boxShadow:"0 2px 8px rgba(0,0,0,0.05)",fontFamily:"Inter, system-ui, Avenir, Helvetica, Arial, sans-serif"},children:[e.jsx(d.Box,{sx:{p:2,borderBottom:1,borderColor:"grey.200"},children:e.jsx(c.SearchBar,{handleSearch:e=>console.log("Search:",e),sx:{backgroundColor:"#fff !important",border:"1px solid grey"}})}),e.jsx(d.Box,{sx:{flexGrow:1,overflowY:"auto",p:1},children:_.map(t=>{return e.jsxs(d.Accordion,{expanded:a===t.id,onChange:(l=t.id,(e,t)=>{o(!!t&&l)}),sx:{border:"none",boxShadow:"none",backgroundColor:"transparent","&:before":{display:"none"},marginBottom:1},children:[e.jsx(d.AccordionSummary,{expandIcon:e.jsx(V,{sx:{color:"grey.600"}}),sx:{borderRadius:"8px",padding:"0 12px",backgroundColor:a===t.id?"grey.200":"grey.50","&:hover":{backgroundColor:"grey.50"},transition:"background-color 0.2s ease",minHeight:42,"& .MuiAccordionSummary-content":{alignItems:"center",margin:"8px 0"},"&.Mui-expanded":{minHeight:42}},children:e.jsxs(d.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[t.icon,e.jsx(d.Typography,{variant:"body2",sx:{fontWeight:500,color:"text.primary"},children:t.label})]})}),e.jsx(d.AccordionDetails,{sx:{padding:"8px 16px"},children:t.content})]},t.id);var l})})]})},Yt="header",Zt="main",Xt="footer",Qt=({sections:l,headerSections:a,footerSections:n,activeId:r,selectedSection:i,onSelectSection:s,onUpdateSection:u,onSplitSection:m,onDeleteSection:p,preview:h,editHtml:g,onApplyHtmlEdit:x,onCancelHtmlEdit:b,editMode:f,isFromPreview:y,placeholders:v,isEditingHeaderFooter:j,handleSave:S,relation_table:C,zoom:w=100})=>{const _=t.useMemo(()=>v.map(e=>({value:e.value||e.key||"",label:e.label||e.name||String(e.value||e.key||"")})),[v]),{setNodeRef:k}=F.useDroppable({id:"main-canvas"}),{setNodeRef:T}=F.useDroppable({id:"header-canvas"}),{setNodeRef:I}=F.useDroppable({id:"footer-canvas"}),B=t.useMemo(()=>[...l,...a,...n].find(e=>e.id===i),[l,i]),[A,M]=t.useState({id:null,type:"inside",canvasType:Zt}),[$,D]=t.useState(!1),[P,z]=t.useState(!1),[R,N]=t.useState("");t.useEffect(()=>{g&&N(st(l,a,n))},[g]);const L=t.useRef(0),O=t.useRef({x:0,y:0}),q=t.useRef(null),W=t.useRef(null),H=t.useRef(null),V=t.useRef(null),G=e=>{switch(e){case Yt:return a;case Xt:return n;default:return l}};t.useEffect(()=>{q.current=r,r&&String(r).includes("sidebar-")?(D(!0),(null==l?void 0:l.length)>0?U(l[0].id,"before",Zt):(null==a?void 0:a.length)>0&&j?U(a[0].id,"before",Yt):(null==n?void 0:n.length)>0&&j?U(n[0].id,"before",Xt):U(null,"inside",Zt)):r||(D(!1),M({id:null,type:"inside",canvasType:Zt}))},[r,l,a,n,j]);const U=t.useCallback((e,t,l)=>{const a=Date.now();a-L.current<50||M(o=>o.id===e&&o.type===t&&o.canvasType===l?o:(L.current=a,{id:e,type:t,canvasType:l}))},[]),K=t.useCallback((e,t)=>{if(!q.current)return;if(t!==Zt&&!j)return;const l=e.clientX-O.current.x,a=e.clientY-O.current.y;if(Math.sqrt(l*l+a*a)<5)return;O.current={x:e.clientX,y:e.clientY};const o=document.elementsFromPoint(e.clientX,e.clientY).find(e=>e.hasAttribute("data-section-id")),n=G(t);if(!o)return void(0===n.length?U(null,"inside",t):$&&U(n[n.length-1].id,"after",t));const r=o.getAttribute("data-section-id");if(!r)return;const i=o.hasAttribute("data-canvas-type")?o.getAttribute("data-canvas-type"):t,s=o.getBoundingClientRect(),d=e.clientY-s.top,c=e.clientX-s.left,u=s.height,m=s.width,p=G(i).find(e=>e.id===r);if(r.startsWith("split-group-")||p&&p.isSplitPair)U(r,c<.4*m?"left":c>.6*m?"right":"inside",i);else{let e="inside";e=d<.19999999999999998*u?"before":d>.7999999999999999*u?"after":"inside",U(r,e,i)}},[j,$,U]),J=t.useCallback((e,t)=>{if(!q.current||!$)return;if(t!==Zt&&!j)return;const l=G(t);l.length>0?U(l[0].id,"before",t):U(null,"inside",t),O.current={x:e.clientX,y:e.clientY}},[$,j,U]),Y=t.useCallback((l,a)=>{const n=[],c=new Set;let h=0;const g=(t,l=!1)=>e.jsx(d.Box,{sx:{[l?"width":"height"]:"50px",border:"2px dashed",borderColor:"primary.main",borderRadius:1,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"rgba(25, 118, 210, 0.04)",[l?"mx":"mb"]:2,opacity:0,animation:"fadeIn 0.3s ease-in-out forwards","@keyframes fadeIn":{"0%":{opacity:0,transform:l?"translateX(-10px)":"translateY(-10px)"},"100%":{opacity:1,transform:"translate(0)"}}},children:e.jsx(o.Typography,{type:"s2",color:"primary",weight:"medium",children:"Drop here"})},t);for($&&(null==l?void 0:l.length)>0&&"before"===A.type&&A.id===l[0].id&&A.canvasType===a&&n.push(g(`drop-before-first-${a}`));h<(null==l?void 0:l.length);){const o=l[h],x=o.id;if(A.id!==x||"before"!==A.type||A.canvasType!==a||$&&0===h||n.push(g(`drop-before-${x}-${a}`)),o.isSplitPair){const x=o.splitGroupId;if(x&&c.has(x)){h++;continue}const b=l.filter(e=>e.splitGroupId===x);if(b.length>0){x&&c.add(x);const l=e.jsx(d.Box,{sx:{display:"flex",gap:2,mb:2,bgcolor:"rgba(0, 0, 0, 0.02)",p:1,borderRadius:1},"data-section-id":`split-group-${x}`,"data-canvas-type":a,children:b.map((l,o)=>e.jsxs(t.Fragment,{children:[A.id===l.id&&"left"===A.type&&A.canvasType===a&&g(`drop-left-${l.id}-${a}`,!0),e.jsx(d.Box,{sx:{width:l.splitWidth?`${l.splitWidth}%`:100/b.length+"%",transition:"width 0.3s ease-in-out"},"data-section-id":l.id,"data-canvas-type":a,children:e.jsx(jt,{section:l,isSelected:i===l.id,isDragging:r===l.id,isOver:A.id===l.id&&"inside"===A.type&&A.canvasType===a,onSelect:()=>s(l.id),onUpdate:(e,t)=>{u(l.id,{content:e,...t},a),s(null)},onSplit:(e,t)=>m(l.id,e,t,a),onDelete:()=>p(l.id,a),placeholders:_,setIsSectionEditing:z})}),A.id===l.id&&"right"===A.type&&A.canvasType===a&&g(`drop-right-${l.id}-${a}`,!0)]},l.id))},`split-row-${x}`);n.push(l),h+=b.length}else h++}else n.push(e.jsx(d.Box,{"data-section-id":o.id,"data-canvas-type":a,children:e.jsx(jt,{section:o,isSelected:i===o.id,isDragging:r===o.id,isOver:A.id===o.id&&"inside"===A.type&&A.canvasType===a,onSelect:()=>s(o.id),onUpdate:(e,t)=>{u(o.id,{content:e,...t},a),s(null)},onSplit:(e,t)=>m(o.id,e,t,a),onDelete:()=>p(o.id,a),placeholders:_,setIsSectionEditing:z})},o.id)),h++;A.id===x&&"after"===A.type&&A.canvasType===a&&n.push(g(`drop-after-${x}-${a}`))}return(0===(null==l?void 0:l.length)&&r&&A.canvasType===a||0===(null==l?void 0:l.length)&&$&&A.canvasType===a)&&n.push(g(`drop-empty-canvas-${a}`)),n},[$,A,r,i,s,u,m,p,_]),Z=t.useMemo(()=>Y(l,Zt),[l,A,r,$,i]),Q=t.useMemo(()=>Y(a,Yt),[a,A,r,$,i,j]),ee=t.useMemo(()=>Y(n,Xt),[n,A,r,$,i,j]),te=(t,l,i,c,u,m=!0)=>{var p;return m?e.jsxs(d.Box,{sx:{mb:3},children:[Zt===l&&m&&a.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(o.Typography,{type:"h4",weight:"bold",color:"theme.secondary.800",children:"Header"}),e.jsx(d.Paper,{sx:{mb:1,boxShadow:"none",opacity:.5},dangerouslySetInnerHTML:{__html:dt(a)}})]}),e.jsx(o.Typography,{type:"h4",weight:"bold",color:"theme.secondary.800",sx:{mb:1},children:t}),e.jsx(d.Paper,{ref:e=>{c(e),u.current=e},elevation:0,sx:{p:4,border:"1px dashed",borderColor:$&&A.canvasType===l?"primary.main":"primary.light",borderRadius:1,bgcolor:"background.paper",position:"relative",minHeight:"Header"===t||"Footer"===t?"100px":"200px",transition:"border-color 0.3s ease, background-color 0.3s ease","&:hover":{bgcolor:$&&A.canvasType===l?"rgba(25, 118, 210, 0.04)":"background.paper"},pointerEvents:l!==Yt&&l!==Xt||j?"auto":"none",opacity:l!==Yt&&l!==Xt||j?1:.5},onClick:()=>{(l!==Yt&&l!==Xt||j)&&s(null)},onMouseMove:e=>K(e,l),onMouseEnter:e=>J(e,l),children:e.jsxs(d.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:[i,0===(null==(p=G(l))?void 0:p.length)&&!r&&!$&&e.jsx(d.Box,{sx:{borderRadius:1,p:2,textAlign:"center",color:"text.secondary"},children:e.jsxs(o.Typography,{type:"s2",color:"theme.secondary.600",weight:"medium",children:["Drag Sections from side panel to start building the ",t.toLowerCase()]})})]})}),Zt===l&&m&&n.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(o.Typography,{type:"h4",weight:"bold",color:"theme.secondary.800",sx:{mt:1},children:"Footer"}),e.jsx(d.Paper,{sx:{mb:1,boxShadow:"none",opacity:.5},dangerouslySetInnerHTML:{__html:dt(n)}})]})]}):null};return e.jsxs(d.Box,{sx:{display:"flex",flex:1,overflow:"hidden"},children:[e.jsx(d.Box,{sx:{flex:1,overflow:"auto",height:"calc(100vh - 104px)"},children:e.jsx(d.Container,{maxWidth:!g&&"lg",sx:{py:g?0:4,height:g?"100%":void 0},children:g?e.jsxs(d.Box,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:[e.jsxs(d.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,bgcolor:"#1e1e1e",borderBottom:"1px solid #333",borderRadius:"4px 4px 0 0"},children:[e.jsx(o.Typography,{type:"s3",sx:{color:"#ccc",fontFamily:"monospace"},children:"HTML Source Editor — changes will replace current sections"}),e.jsxs(d.Box,{sx:{display:"flex",gap:1},children:[e.jsx(c.Button,{size:"small",variant:"contained",color:"primary",startIcon:e.jsx(X,{fontSize:"small"}),onClick:()=>x(R),sx:{boxShadow:"none"},children:"Apply"}),e.jsx(c.Button,{size:"small",variant:"outlined",startIcon:e.jsx(E,{fontSize:"small"}),onClick:()=>b(),sx:e=>({color:`${e.palette.theme.secondary[1e3]} !important`,borderColor:"#555 !important"}),children:"Cancel"})]})]}),e.jsx("textarea",{value:R,onChange:e=>N(e.target.value),spellCheck:!1,style:{flex:1,width:"100%",minHeight:"calc(100vh - 220px)",padding:"16px",fontFamily:'"Fira Code", "Cascadia Code", "Consolas", monospace',fontSize:"13px",lineHeight:"1.6",color:"#d4d4d4",backgroundColor:"#1e1e1e",border:"none",outline:"none",resize:"none",boxSizing:"border-box",borderRadius:"0 0 4px 4px",tabSize:2}})]}):h?e.jsx(d.Box,{sx:{transform:`scale(${w/100})`,transformOrigin:"top center",transition:"transform 0.2s ease-in-out",bgcolor:"white",p:2,borderRadius:1,boxShadow:1},children:e.jsx(d.Box,{dangerouslySetInnerHTML:{__html:st(l,a,n)}})}):e.jsxs(e.Fragment,{children:[te("Header",Yt,Q,T,H,j),te("Content",Zt,Z,k,W,!j),te("Footer",Xt,ee,I,V,j)]})})}),!g&&e.jsx(d.Box,{sx:{width:y?f?400:0:400,flexShrink:0,position:"sticky",top:0,alignSelf:"flex-start",height:"calc(100vh - 104px)",overflowY:"auto",borderLeft:"1px solid",borderColor:"divider",bgcolor:"background.paper",zIndex:1},children:!i||(null==B?void 0:B.is_edited_from_source)||P?y?f&&e.jsx(Jt,{}):e.jsx(Jt,{}):e.jsx(Vt,{section:B,onClose:()=>s(null),onUpdate:e=>{if(i){const t=a.some(e=>e.id===i)?Yt:n.some(e=>e.id===i)?Xt:Zt;u(i,e,t)}},placeholders:v,handleSave:S,relation_table:C})})]})},el=({isOpen:a,setIsOpen:n,modalProps:r,templateRoutes:i,payload:s,mode:u="add",templateData:p,onSaveSuccess:h,onSaveError:g,isSaving:x=!1})=>{console.log("is saving...........",x);const{handleSubmit:b,control:f,setValue:y}=m.useForm({mode:"all",resolver:c.o(ae.object().shape({template_name:ae.object().shape({name:ae.string().trim().required("Template name is required")})}))}),v=l.useNavigate(),[j,C]=t.useState(!1);console.log("isSubmitting............",j);const w=()=>{j||x||n(null)};return t.useEffect(()=>{p&&(null==p?void 0:p.name)&&y("template_name.name",null==p?void 0:p.name)},[y,p]),e.jsxs(c.Modal,{open:a,onClose:w,maxWidth:"xs",fullWidth:!0,...r,children:[e.jsxs(d.DialogTitle,{className:"companySelectionModal--DialogTitle",children:[e.jsx(o.Typography,{type:"s3",color:"inherit",weight:"medium",children:x?"Saving Template...":"Template Name"}),e.jsx(d.IconButton,{onClick:w,disabled:j||x,children:e.jsx(E,{fontSize:"small"})})]}),e.jsx(d.DialogContent,{className:"companySelectionModal--DialogContents",children:e.jsx("form",{onSubmit:b(async e=>{C(!0);try{const{name:t=""}=(null==e?void 0:e.template_name)||{};s.name=t,200===(await("edit"===u?Z.patchV1TemplatesId(s):Z.postV1Templates(s))).status_code&&(S.enqueueSnackbar("Template saved successfully",{variant:"success"}),null==h||h(),v(i.LIST)),C(!1)}catch(t){const e=(null==t?void 0:t.message)||"Something went wrong";C(!1),S.enqueueSnackbar(e,{variant:"error"}),null==g||g()}}),id:"template_name",children:e.jsx(c.DynamicInput,{label:"Name",name:"name",placeholder:"Enter Name",fieldArrayName:"template_name",formControl:f,required:!0})})}),e.jsx(d.DialogActions,{className:"companySelectionModal--DialogAction",children:e.jsxs(d.Box,{display:"flex",gap:1.5,children:[e.jsx(c.Button,{className:"companySelectionModal--DialogAction--WhiteBtn",onClick:w,disabled:j||x,children:"Cancel"}),e.jsx(c.Button,{type:"submit",form:"template_name",disabled:j||x,endIcon:(j||x)&&e.jsx(d.CircularProgress,{size:15}),children:x?"Saving...":"Save"})]})})]})},tl=({modulePath:a,module:o,type:n})=>{const{id:r,template_id:i}=l.useParams(),{state:s}=l.useLocation(),[c,u]=t.useState([]),[m,p]=t.useState([]),[h,g]=t.useState([]),[x,b]=t.useState(null),[f,y]=t.useState(!1),[v,j]=t.useState(!1),[C,_]=t.useState(null),[k,T]=t.useState(null),[I,E]=t.useState(!!(null==s?void 0:s.fromPreview)),[B,A]=t.useState(!1),[$,D]=t.useState([]),[P,z]=t.useState("main"),[R,N]=t.useState(!1),[O,q]=t.useState(null),[W,H]=t.useState(""),V=it(a,n),[G,U]=t.useState([]),[K,J]=t.useState(null),[Y,X]=t.useState(!1),[ee,te]=t.useState(null),[le,ae]=t.useState(100),[oe,ne]=t.useState({past:[],future:[]}),re=t.useMemo(()=>$,[JSON.stringify($)]),ie=t.useCallback(()=>{ne(e=>({past:[...e.past,{sections:[...c],headerSections:[...m],footerSections:[...h]}].slice(-50),future:[]}))},[c,m,h]),se=t.useCallback(()=>{if(0===oe.past.length)return;const e=oe.past[oe.past.length-1],t=oe.past.slice(0,-1);ne({past:t,future:[{sections:[...c],headerSections:[...m],footerSections:[...h]},...oe.future].slice(0,50)}),u(e.sections),p(e.headerSections),g(e.footerSections)},[oe,c,m,h]),de=t.useCallback(()=>{if(0===oe.future.length)return;const e=oe.future[0],t=oe.future.slice(1);ne({past:[...oe.past,{sections:[...c],headerSections:[...m],footerSections:[...h]}].slice(-50),future:t}),u(e.sections),p(e.headerSections),g(e.footerSections)},[oe,c,m,h]);t.useEffect(()=>{const e=e=>{!e.ctrlKey&&!e.metaKey||"z"!==e.key||e.shiftKey?((e.ctrlKey||e.metaKey)&&"y"===e.key||(e.ctrlKey||e.metaKey)&&e.shiftKey&&"z"===e.key)&&(e.preventDefault(),de()):(e.preventDefault(),se())};return window.addEventListener("keydown",e),()=>{window.removeEventListener("keydown",e)}},[se,de]);const ce=t.useCallback((e,t={})=>{let l="";const a=M.initialStyles[e]||{},o=mt(a),n="header"===P&&R?"header-":"footer"===P&&R?"footer-":"";switch(e){case"heading":l=`<h1 style="${o}">Heading 1</h1>`;break;case"heading-2":l=`<h2 style="${o}">Heading 2</h2>`;break;case"heading-3":l=`<h3 style="${o}">Heading 3</h3>`;break;case"heading-4":l=`<h4 style="${o}">Heading 4</h4>`;break;case"text":l=`<p style="${o}">Hello, enter your text here...</p>`;break;case"image":l=`<img src="${t.src}" alt="${t.alt}" style="${o};" />`;break;case"buttons":t.text=(null==t?void 0:t.text)||"Button text",l=`<button style="${o}">${t.text}</button>`;break;case"divider":l=`<hr style="${o}" />`;break;case"table":const e=a,{border:n,borderStyle:r,borderColor:i,...s}=e,d=mt(e.is_bordered?e:s),c=mt(e.tHead),u=mt(e.tBody),m=mt({...e.thCells,border:n,borderStyle:r,borderColor:i}),p=mt({...e.tbCells,border:n,borderStyle:r,borderColor:i});l=`\n <table style="${d}">\n <thead style="${c}">\n <tr style="background-color: #f5f5f5;">\n <th style="${m}"></th>\n <th style="${m}"></th>\n <th style="${m}"></th>\n </tr>\n </thead>\n <tbody style="${u}">\n <tr>\n <td style="${p}"></td>\n <td style="${p}"></td>\n <td style="${p}"></td>\n </tr>\n </tbody>\n </table>\n `;break;case"signature":l=`<div style="${o}">Signature: <input type='text' style="border:0; border-bottom:1px solid black" class='signature-input'/></div>`;break;case"qr-code":t.placeholder=(null==t?void 0:t.placeholder)||"{{qr_data}}",l=`<div style="background-color: #f5f5f5; padding: 16px; text-align: center; color: #666666;">${t.placeholder}</div>`;break;case"bar-code":t.placeholder=(null==t?void 0:t.placeholder)||"{{barcode_data}}",l=`<div style="background-color: #f5f5f5; padding: 16px; text-align: center; color: #666666;">${t.placeholder}</div>`;break;default:l='<p style="font-size: 16px; color: #333333; line-height: 1.5;">New section</p>'}return ct(l),{id:`${n}section-${Q.v4()}`,content:l,type:e,attributes:{...t||{},styles:a},is_edited_from_source:!1}},[P,R]),ue=t.useCallback(e=>{const{active:t}=e;b(t.id)},[]),me=t.useCallback(e=>{const{over:t}=e;t?("header-canvas"===t.id&&R?z("header"):"footer-canvas"===t.id&&R?z("footer"):"main-canvas"===t.id&&z("main"),"header-canvas"!==t.id&&"main-canvas"!==t.id&&"footer-canvas"!==t.id&&T(t.id)):T(null)},[R]),pe=t.useCallback(e=>{var t;const{active:l,over:a}=e;if(b(null),T(null),!a)return;let o=c,n=u;if(("header-canvas"===a.id||(null==k?void 0:k.startsWith("header-")))&&R?(o=m,n=p,z("header")):("footer-canvas"===a.id||(null==k?void 0:k.startsWith("footer-")))&&R?(o=h,n=g,z("footer")):z("main"),"image"===(null==(t=l.data.current)?void 0:t.type)){ie();const e=l.data.current.imageUrl,t=ce("image",{src:e,alt:"Image"}),r=o.findIndex(e=>e.id===a.id),i=[...o];return"header-canvas"===a.id||"main-canvas"===a.id||"footer-canvas"===a.id||-1===r?n([...o,t]):(i.splice(r,0,t),n(i)),void S.enqueueSnackbar("Added uploaded image section")}if("string"==typeof l.id&&l.id.startsWith("sidebar-")){ie();const e=l.id.replace("sidebar-",""),t=ce(e),r=o.findIndex(e=>e.id===a.id);if(-1!==r&&"header-canvas"!==a.id&&"main-canvas"!==a.id&&"footer-canvas"!==a.id){const l=o[r];if(!l.content||l.content.includes("Click to add")||l.content.includes("enter your text")){const a=[...o];a[r]={...l,type:e,content:t.content},n(a)}else{const e=[...o];e.splice(r,0,t),n(e)}}else n([...o,t]);return}if(l.id!==a.id&&"string"==typeof l.id&&"string"==typeof a.id){ie();let e=[],t=null;l.id.startsWith("header-")&&R?(e=m,t=p):l.id.startsWith("footer-")&&R?(e=h,t=g):(e=c,t=u);const r=l.id.replace(/^(header-|footer-)/,""),i=e.findIndex(e=>e.id===r||e.id===l.id);let s=o.findIndex(e=>e.id===String(a.id).replace(/^(header-|footer-)/,""));if("header-canvas"!==a.id&&"main-canvas"!==a.id&&"footer-canvas"!==a.id||(s=o.length),-1!==i&&-1!==s)if(e===o){const l=[...e],[a]=l.splice(i,1);if(a.isSplitPair&&a.splitGroupId){const o=a.splitGroupId,n=[a,...e.filter(e=>e.splitGroupId===o&&e.id!==a.id)],r=l.filter(e=>e.splitGroupId!==o);r.splice(s,0,...n),t(r)}else l.splice(s,0,a),t(l)}else{const l=e[i],r=[...e];r.splice(i,1),t(r);const d=[...o],c={...l};("header-canvas"===a.id||a.id.startsWith("header-"))&&R?c.id.startsWith("header-")||(c.id=`header-${c.id}`):("footer-canvas"===a.id||a.id.startsWith("footer-"))&&R?c.id.startsWith("footer-")||(c.id=`footer-${c.id}`):c.id=c.id.replace(/^(header-|footer-)/,""),d.splice(s,0,c),n(d)}}},[c,m,h,k,R,P,ce,ie]),he=t.useCallback(e=>"header"===e&&R?m:"footer"===e&&R?h:c,[c,m,h,R]),ge=t.useCallback(e=>"header"===e&&R?p:"footer"===e&&R?g:u,[R]),xe=t.useCallback((e,t,l)=>{const a=he(l),o=ge(l),n=e.replace(/^(header-|footer-)/,"");o(a.map(l=>l.id===n||l.id===e?{...l,...t}:l))},[he,ge]),be=ft(xe,300),fe=t.useCallback((e,t,l)=>{void 0!==t.content&&1===Object.keys(t).length?be(e,t,l):xe(e,t,l)},[xe,be]),ye=t.useCallback((e,t,l,a)=>{ie();const o=he(a),n=ge(a),r=e.replace(/^(header-|footer-)/,""),i=o.findIndex(t=>t.id===r||t.id===e);if(-1===i)return;const s=o[i],d=[...o],c="header"===a?"header-":"footer"===a?"footer-":"";if(s.isSplitPair&&s.splitGroupId){const e=s.splitGroupId,a=100/(d.filter(t=>t.splitGroupId===e).length+1);d[i]={...s,content:t,splitWidth:a};const o={id:`${c}section-${Q.v4()}`,content:l,type:s.type,isSplitPair:!0,splitGroupId:e,splitWidth:a,attributes:s.attributes,is_edited_from_source:!1};d.splice(i+1,0,o);for(let t=0;t<d.length;t++)d[t].splitGroupId===e&&(d[t].splitWidth=a)}else{const e=Q.v4(),a=50;d[i]={...s,content:t,isSplitPair:!0,splitGroupId:e,splitWidth:a};const o={id:`${c}section-${Q.v4()}`,content:l,type:s.type,isSplitPair:!0,splitGroupId:e,splitWidth:a,attributes:s.attributes,is_edited_from_source:!1};d.splice(i+1,0,o)}n(d)},[he,ge,P,R,ie]),ve=t.useCallback((e,t)=>{ie();const l=he(t),a=ge(t),o=e.replace(/^(header-|footer-)/,""),n=l.find(t=>t.id===o||t.id===e);if(n){if(n.isSplitPair&&n.splitGroupId){const t=l.filter(e=>e.splitGroupId===n.splitGroupId);if(t.length<=2){const n=t.find(t=>t.id!==o&&t.id!==e);n&&(n.isSplitPair=!1,n.splitGroupId=void 0,n.splitWidth=void 0),a(l.filter(t=>t.id!==o&&t.id!==e))}else{const r=100/t.filter(t=>t.id!==o&&t.id!==e).length;a(l.filter(t=>t.id!==o&&t.id!==e).map(e=>e.splitGroupId===n.splitGroupId?{...e,splitWidth:r}:e))}}else a(l.filter(t=>t.id!==o&&t.id!==e));C===e&&_(null)}},[he,ge,C,ie]);t.useEffect(()=>{var e;(null==s?void 0:s.fromPreview)&&(y(!(null==s?void 0:s.isViewOnly)),j(!0)),document.body.style.overflow="hidden";const t=null==(e=document.getElementsByTagName("main"))?void 0:e[0];return t&&(t.style.marginTop="4.125rem"),()=>{document.body.removeAttribute("style")}},[]),t.useEffect(()=>{(async()=>{var e,t,l,a;if(r){const l=w.getToken(),a=await Z.getV1SubjectsId({...l,"x-timezone":(null==(e=l["x-timezone"])?void 0:e.toString())||"",id:r});if("data"in a&&a.data&&"object"==typeof a.data&&"resource"in a.data){const e=a.data.resource,l=w.getToken(),o=await Z.getV1FormBuilderRelationalSchemaFieldsName({...l,"x-timezone":(null==(t=l["x-timezone"])?void 0:t.toString())||"",name:e}),n="data"in o&&o.data&&"object"==typeof o.data&&"fields"in o.data&&o.data.fields||[],r="data"in o&&o.data&&"object"==typeof o.data&&"relational_fields"in o.data&&o.data.relational_fields||[],i=n.map(e=>({...e,key:e.key.replace("__replaceKey","")})).filter(e=>{var t;return!e.is_inner_join&&"id"!==e.alias&&!(null==(t=null==e?void 0:e.alias)?void 0:t.includes("_id"))}),s=[],d=[];r.forEach(e=>{if(!e)return;const t=(e.fields||[]).map(t=>{const l={...t,key:t.key.replace("__replaceKey",""),alias:(null==t?void 0:t.templateKey)?null==t?void 0:t.templateKey:t.alias};return"object"===e.type&&e.dataKey&&(l.key=`${e.dataKey}.${l.key}`),l}).filter(e=>!e.is_inner_join&&"id"!==e.alias&&!e.alias.includes("_id")),l=L.differenceWith(t,t,(e,t)=>e.key===(null==t?void 0:t.joinKey)).map(t=>({label:w.formatText(t.alias.replace(/_data$/,"").replace(/_/g," ")),value:"object"===e.type&&e.dataKey?`${e.dataKey}.${t.alias.replace(/ /g,"_").toLowerCase()}`:t.alias.replace(/ /g,"_").toLowerCase()}));"object"===e.type?d.push(...l):s.push({...e,fields:l})});const c=[...i.map(e=>{const t=(null==e?void 0:e.alias)||(null==e?void 0:e.key),l=w.formatText(t.replace(/_data$/,"").replace(/_/g," "));return{label:l,value:l.replace(/ /g,"_").toLowerCase()}}),...d],u=L.uniqBy(c,"value");D(u),U(s)}}if(i){const e=w.getToken(),t=await Z.getV1TemplatesId({...e,"x-timezone":(null==(l=e["x-timezone"])?void 0:l.toString())||"",id:i}),a=("data"in t&&t.data&&"object"==typeof t.data&&"sections"in t.data&&t.data.sections||[]).map(e=>{var t;return{...e,id:e.id||`section-${Q.v4()}`,attributes:{...e.attributes,styles:(null==(t=e.attributes)?void 0:t.styles)||M.initialStyles[e.type]||{}}}});J("data"in t&&t.data?t.data:null),u(a)}if(null==s?void 0:s.company_id){const e=w.getToken(),t=await Z.getV1TemplateHeaderFooterCompanyIdHeaderFooter({...e,"x-timezone":(null==(a=e["x-timezone"])?void 0:a.toString())||"",company_id:s.company_id}),l="data"in t&&t.data&&"object"==typeof t.data?t.data:null;H((null==l?void 0:l._id)||"");const o=(null==l?void 0:l.header_sections)||[],n=(null==l?void 0:l.footer_sections)||[],r=o.map(e=>{var t;return{...e,id:e.id||`header-section-${Q.v4()}`,attributes:{...e.attributes,styles:(null==(t=e.attributes)?void 0:t.styles)||M.initialStyles[e.type]||{}}}}),i=n.map(e=>{var t;return{...e,id:e.id||`footer-section-${Q.v4()}`,attributes:{...e.attributes,styles:(null==(t=e.attributes)?void 0:t.styles)||M.initialStyles[e.type]||{}}}});p(r),g(i)}})()},[i,r,null==s?void 0:s.company_id]);const je=t.useCallback(e=>{ie();const t={id:`section-${Q.v4()}`,content:e,type:"text",is_edited_from_source:!0};u([t]),A(!1)},[ie]),Se=t.useCallback(()=>{A(!1)},[]),Ce=t.useCallback(async()=>{if(0===c.length&&0===m.length&&0===h.length)return void S.enqueueSnackbar("Please add at least one section");te({sections:[...c],headerSections:[...m],footerSections:[...h]});const e=st(c,m,h,!0);try{const t={...w.getToken(),...i?{id:i}:{subject_id:r,is_default:!1,company_id:s.company_id},sections:c.map(e=>({...e,attributes:e.attributes})),contents:e};q(t)}catch(t){const e=w.getErrorMessage(null==t?void 0:t.message);S.enqueueSnackbar(e,{variant:"error"}),te(null)}},[c,m,h,i,r,s]),we=t.useCallback(async()=>{var e,t;if(0===c.length&&0===m.length&&0===h.length)return void S.enqueueSnackbar("Please add at least one section",{variant:"error"});if(!(null==s?void 0:s.company_id))return void S.enqueueSnackbar("Company has not been selected",{variant:"error"});te({sections:[...c],headerSections:[...m],footerSections:[...h]}),X(!0);const l=`${dt(m,"header")}${dt(h,"footer")}`,a=e=>({id:e.id,content:e.content,type:e.type,isSplitPair:e.isSplitPair,splitGroupId:e.splitGroupId,splitWidth:void 0!==e.splitWidth?String(e.splitWidth):void 0,attributes:e.attributes}),o=m.map(a),n=h.map(a);try{if(W){const t=w.getToken();200===(await Z.patchV1TemplateHeaderFooterId({...t,"x-timezone":(null==(e=t["x-timezone"])?void 0:e.toString())||"",id:W,header_sections:o,footer_sections:n,contents:l})).status_code&&(S.enqueueSnackbar("Header/Footer saved successfully",{variant:"success"}),N(!1),te(null))}else{const e=w.getToken();200===(await Z.postV1TemplateHeaderFooter({...e,"x-timezone":(null==(t=e["x-timezone"])?void 0:t.toString())||"",header_sections:o,footer_sections:n,contents:l,company_id:s.company_id})).status_code&&(S.enqueueSnackbar("Header/Footer saved successfully",{variant:"success"}),N(!1),te(null))}}catch(r){const e=w.getErrorMessage(null==r?void 0:r.message);S.enqueueSnackbar(e,{variant:"error"}),ee&&(u(ee.sections),p(ee.headerSections),g(ee.footerSections),S.enqueueSnackbar("Changes reverted due to save error",{variant:"warning"}))}finally{X(!1),te(null)}},[c,m,h,W,s,ee]),_e=t.useCallback(()=>{N(!R),R&&z("main")},[R]),ke=t.useCallback(()=>{te(null),q(null)},[]),Te=t.useCallback(()=>{ee&&(u(ee.sections),p(ee.headerSections),g(ee.footerSections),S.enqueueSnackbar("Changes reverted due to save error",{variant:"warning"})),te(null),q(null)},[ee]);return e.jsxs(d.Box,{sx:{display:"flex",flexDirection:"column",height:"100vh"},children:[e.jsx(ht,{fromPreview:v,onPreview:()=>E(!I),onSave:Ce,onEditModeChange:()=>{y(!f),E(!!f)},zoom:le,onZoomIn:()=>{ae(e=>Math.min(e+10,150))},onZoomOut:()=>{ae(e=>Math.max(e-10,50))},onResetZoom:()=>{ae(100)},editMode:f,preview:I,editHtml:B,onEditHtml:()=>A(!B),sections:c,isEditingHeaderFooter:R,setIsEditingHeaderFooter:_e,onSaveHeaderFooter:we,modulePath:a,type:n,mode:i?"edit":"add",templateData:K,isSaving:Y}),e.jsx(d.Box,{sx:{display:"flex",flex:1,overflow:"hidden"},children:e.jsx(F.DndContext,{onDragStart:ue,onDragOver:me,onDragEnd:pe,collisionDetection:F.pointerWithin,children:e.jsx(Qt,{sections:c,headerSections:m,footerSections:h,activeId:x,overSection:k,selectedSection:C,onSelectSection:_,onUpdateSection:fe,onSplitSection:ye,onDeleteSection:ve,preview:I,editHtml:B,onApplyHtmlEdit:je,onCancelHtmlEdit:Se,zoom:le,editMode:f,isFromPreview:v,handleSave:Ce,placeholders:re,isEditingHeaderFooter:R,relation_table:G})})}),null!==O&&e.jsx(el,{isOpen:null!==O,setIsOpen:()=>q(null),payload:O,templateRoutes:V,mode:i?"edit":"add",templateData:K,onSaveSuccess:ke,onSaveError:Te,isSaving:Y})]})},ll=({modulePath:t,module:l,type:a})=>e.jsx(d.Box,{sx:{minHeight:"100vh",bgcolor:"grey.50"},children:e.jsx(tl,{modulePath:t,module:l,type:a})}),al=({template:l,width:a=300,height:n=200,scale:r=.25,showControls:i=!1,onClick:s=null,selectedTemplateId:c="",isFetching:u=!1,onDelete:m,minScale:p=.1,maxScale:h=1,scaleStep:g=1.2,loadingDelay:x=500,refreshDelay:b=300,normalView:y=!1})=>{const[v,j]=t.useState(u||!0),[S,C]=t.useState(r),[w,_]=t.useState(null),[k,I]=t.useState(!1),E=t.useRef(null),B=t.useRef(null),A=t.useRef(null),M=t.useRef(null),F=a/S,$=n/S;t.useEffect(()=>()=>{A.current&&clearTimeout(A.current),M.current&&clearTimeout(M.current)},[]),t.useEffect(()=>(A.current&&clearTimeout(A.current),A.current=setTimeout(()=>{j(!1)},x),()=>{A.current&&clearTimeout(A.current)}),[l.contents,x]),t.useEffect(()=>{j(u)},[u]);const D=t.useCallback(()=>{C(e=>Math.min(e*g,h))},[g,h]),P=t.useCallback(()=>{C(e=>Math.max(e/g,p))},[g,p]),z=t.useCallback(()=>{j(!0),_(null),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{j(!1)},b)},[b]),R=t.useCallback(()=>{s&&!v&&s(l)},[s,l,v]),N=t.useCallback(e=>{e.stopPropagation(),m&&!(null==l?void 0:l.is_default)&&m(l)},[m,l]),L=t.useCallback(()=>{I(!0)},[]),O=t.useCallback(()=>{I(!1)},[]);if(v)return e.jsx(d.Box,{sx:{width:a,height:n,borderRadius:1,overflow:"hidden",border:"1px solid",borderColor:"divider"},children:e.jsx(d.Skeleton,{variant:"rectangular",width:"100%",height:"100%",animation:"wave"})});if(w)return e.jsx(d.Box,{sx:{width:a,height:n,borderRadius:1,overflow:"hidden",border:"1px solid",borderColor:"error.main",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"error.light",color:"error.contrastText"},children:"Failed to load template"});const q=c===l._id,W=S<h,H=S>p,V=!(null==l?void 0:l.is_default);return e.jsxs(d.Box,{sx:{position:"relative",display:"inline-block"},onMouseEnter:L,onMouseLeave:O,children:[e.jsxs(d.Box,{ref:E,onClick:R,sx:e=>({width:a,height:n,border:"1px solid",borderRadius:1,overflow:"hidden",position:"relative",cursor:s?"pointer":"default",backgroundColor:"#fff",transition:"all 0.2s ease-in-out","&:hover":s?{boxShadow:"0 4px 16px rgba(0,0,0,0.15)",transform:"translateY(-1px)"}:{},borderColor:y&&q?e.palette.theme.primary[800]:"grey.300",borderWidth:q?2:1}),children:[e.jsx(d.Box,{sx:{width:F,height:$,transform:`scale(${S})`,transformOrigin:"top left",position:"absolute",top:0,left:0,overflow:"hidden"},children:e.jsx(d.Box,{ref:B,sx:{width:"100%",height:"100%",userSelect:"none",pointerEvents:"none",pt:2,"& *":{maxWidth:"100% !important",boxSizing:"border-box !important"},"& body":{margin:"0 !important",padding:"0 !important",overflow:"hidden !important"},"& img":{maxWidth:"100% !important",height:"auto !important"},"& table":{width:"100% !important",tableLayout:"fixed !important"},'& *[style*="position: absolute"]':{position:"relative !important"},"& .email-container":{width:"85% !important"}},dangerouslySetInnerHTML:{__html:l.contents}})}),v&&e.jsx(d.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(255,255,255,0.8)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:2},children:e.jsx(d.Skeleton,{variant:"rectangular",width:"90%",height:"90%"})}),(null==l?void 0:l.is_default)&&e.jsx(d.Box,{sx:e=>{var t;return{position:"absolute",top:8,left:8,width:12,height:12,borderRadius:"50%",backgroundColor:null==(t=e.palette.theme)?void 0:t.primary[800],zIndex:3}}})]}),(null==l?void 0:l.name)&&e.jsx(o.Typography,{type:"s3",weight:"medium",color:"theme.secondary.1000",align:"center",sx:{width:a,mt:.5},children:null==l?void 0:l.name}),i&&e.jsx(d.Fade,{in:k,timeout:200,children:e.jsxs(d.Box,{sx:{position:"absolute",top:-8,right:-8,display:"flex",gap:.5,zIndex:4,backgroundColor:"rgba(255,255,255,0.95)",border:"1px solid",borderColor:"grey.300",borderRadius:2,padding:.5,boxShadow:"0 4px 12px rgba(0,0,0,0.15)",backdropFilter:"blur(4px)"},children:[e.jsx(d.Tooltip,{title:`Zoom In (${Math.round(100*S)}%)`,arrow:!0,children:e.jsx("span",{children:e.jsx(d.IconButton,{size:"small",onClick:D,disabled:!W,sx:{backgroundColor:"transparent","&:hover":{backgroundColor:"primary.light",color:"primary.contrastText"},"&:disabled":{opacity:.5}},children:e.jsx(f.ZoomIn,{fontSize:"small"})})})}),e.jsx(d.Divider,{orientation:"vertical",variant:"middle",flexItem:!0}),e.jsx(d.Tooltip,{title:`Zoom Out (${Math.round(100*S)}%)`,arrow:!0,children:e.jsx("span",{children:e.jsx(d.IconButton,{size:"small",onClick:P,disabled:!H,sx:{backgroundColor:"transparent","&:hover":{backgroundColor:"primary.light",color:"primary.contrastText"},"&:disabled":{opacity:.5}},children:e.jsx(f.ZoomOut,{fontSize:"small"})})})}),e.jsx(d.Divider,{orientation:"vertical",variant:"middle",flexItem:!0}),e.jsx(d.Tooltip,{title:"Refresh Preview",arrow:!0,children:e.jsx(d.IconButton,{size:"small",onClick:z,sx:{backgroundColor:"transparent","&:hover":{backgroundColor:"primary.light",color:"primary.contrastText"}},children:e.jsx(f.Refresh,{fontSize:"small"})})}),m&&e.jsxs(e.Fragment,{children:[e.jsx(d.Divider,{orientation:"vertical",variant:"middle",flexItem:!0}),e.jsx(d.Tooltip,{title:V?"Delete Template":"Cannot delete default template",arrow:!0,children:e.jsx("span",{children:e.jsx(d.IconButton,{size:"small",onClick:N,disabled:!V,sx:{backgroundColor:"transparent","&:hover":V?{backgroundColor:"error.light",color:"error.contrastText"}:{},"&:disabled":{opacity:.5}},children:e.jsx(T.Trash,{fontSize:"small"})})})})]})]})})]})},ol=({template:l,width:a="100%",height:n=800,scale:r=.25,showControls:i=!1,onClick:s=null,selectedTemplateId:c="",isFetching:u=!1,onDelete:m,normalView:p=!1,minScale:h=.1,maxScale:g=1,scaleStep:x=1.2,loadingDelay:b=500,refreshDelay:y=300})=>{const[v,j]=t.useState(u||!0),[S,C]=t.useState(r),[w,_]=t.useState(null),[k,I]=t.useState(!1),E=t.useRef(null),B=t.useRef(null),A=t.useRef(null),M=t.useRef(null),[F,$]=t.useState("number"==typeof a?a:800);t.useEffect(()=>{const e=()=>{if(E.current){const e=E.current.offsetWidth;$(e)}};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),t.useEffect(()=>()=>{clearTimeout(A.current),clearTimeout(M.current)},[]),t.useEffect(()=>(clearTimeout(A.current),A.current=setTimeout(()=>j(!1),b),()=>clearTimeout(A.current)),[l.contents,b]),t.useEffect(()=>j(u),[u]);const D=t.useCallback(()=>C(e=>Math.min(e*x,g)),[x,g]),P=t.useCallback(()=>C(e=>Math.max(e/x,h)),[x,h]),z=t.useCallback(()=>{j(!0),_(null),clearTimeout(M.current),M.current=setTimeout(()=>j(!1),y)},[y]),R=t.useCallback(()=>{s&&!v&&s(l)},[s,l,v]),N=t.useCallback(e=>{e.stopPropagation(),m&&!(null==l?void 0:l.is_default)&&m(l)},[m,l]),L=t.useCallback(()=>I(!0),[]),O=t.useCallback(()=>I(!1),[]);if(v)return e.jsx(d.Box,{sx:{width:a,height:n,borderRadius:1,overflow:"hidden",border:"1px solid",borderColor:"divider"},children:e.jsx(d.Skeleton,{variant:"rectangular",width:"100%",height:"100%",animation:"wave"})});if(w)return e.jsx(d.Box,{sx:{width:a,height:n,borderRadius:1,overflow:"hidden",border:"1px solid",borderColor:"error.main",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"error.light",color:"error.contrastText"},children:"Failed to load template"});const q=S<g,W=S>h,H=!(null==l?void 0:l.is_default);return e.jsxs(d.Box,{ref:E,sx:{position:"relative",width:a,marginInline:"auto",display:"inline-block"},onMouseEnter:L,onMouseLeave:O,children:[e.jsxs(d.Box,{onClick:R,sx:e=>({width:"100%",height:n,marginBlock:0,overflow:"hidden",position:"relative",backgroundColor:"#fff",transition:"all 0.2s ease-in-out","&:hover":s?{boxShadow:"0 4px 16px rgba(0,0,0,0.15)",transform:"translateY(-1px)"}:{}}),children:[e.jsx(d.Box,{sx:{width:"100%",height:"100%",display:"flex",justifyContent:"center",alignItems:"center",overflow:"auto",backgroundColor:"#fff"},children:e.jsx(d.Box,{sx:{transform:`scale(${S})`,transformOrigin:"top left",pointerEvents:"none",userSelect:"none",width:F,height:n},children:e.jsx(d.Box,{ref:B,sx:{width:"100%",height:"100%","& *":{maxWidth:"100% !important",boxSizing:"border-box !important"},"& body":{margin:0,padding:0,overflow:"hidden"},"& img":{maxWidth:"100% !important",height:"auto !important"},"& table":{width:"100% !important",tableLayout:"fixed !important"},'& *[style*="position: absolute"]':{position:"relative !important"},"& .email-container":{width:"85% !important"}},dangerouslySetInnerHTML:{__html:l.contents}})})}),(null==l?void 0:l.is_default)&&e.jsx(d.Box,{sx:e=>({position:"absolute",top:8,left:8,width:12,height:12,borderRadius:"50%",backgroundColor:e.palette.theme.primary[800],zIndex:3})})]}),(null==l?void 0:l.name)&&e.jsx(o.Typography,{type:"s3",weight:"medium",color:"theme.secondary.1000",align:"center",sx:{width:a,mt:.5},children:null==l?void 0:l.name}),i&&e.jsx(d.Fade,{in:k,timeout:200,children:e.jsxs(d.Box,{sx:{position:"absolute",top:-8,right:-8,display:"flex",gap:.5,zIndex:4,backgroundColor:"rgba(255,255,255,0.95)",border:"1px solid",borderColor:"grey.300",borderRadius:2,padding:.5,boxShadow:"0 4px 12px rgba(0,0,0,0.15)",backdropFilter:"blur(4px)"},children:[e.jsx(d.Tooltip,{title:`Zoom In (${Math.round(100*S)}%)`,arrow:!0,children:e.jsx("span",{children:e.jsx(d.IconButton,{size:"small",onClick:D,disabled:!q,children:e.jsx(f.ZoomIn,{fontSize:"small"})})})}),e.jsx(d.Divider,{orientation:"vertical",flexItem:!0}),e.jsx(d.Tooltip,{title:`Zoom Out (${Math.round(100*S)}%)`,arrow:!0,children:e.jsx("span",{children:e.jsx(d.IconButton,{size:"small",onClick:P,disabled:!W,children:e.jsx(f.ZoomOut,{fontSize:"small"})})})}),e.jsx(d.Divider,{orientation:"vertical",flexItem:!0}),e.jsx(d.Tooltip,{title:"Refresh Preview",arrow:!0,children:e.jsx(d.IconButton,{size:"small",onClick:z,children:e.jsx(f.Refresh,{fontSize:"small"})})}),m&&e.jsxs(e.Fragment,{children:[e.jsx(d.Divider,{orientation:"vertical",flexItem:!0}),e.jsx(d.Tooltip,{title:H?"Delete Template":"Cannot delete default template",arrow:!0,children:e.jsx("span",{children:e.jsx(d.IconButton,{size:"small",onClick:N,disabled:!H,children:e.jsx(T.Trash,{fontSize:"small"})})})})]})]})})]})},nl=({email:a,onClose:n,open:r,companies:i=[],templateRoutes:s,source:u="add"})=>{var m;const[p,h]=t.useState([]),[g,x]=t.useState(""),[b,f]=t.useState(""),[y,v]=t.useState(!0),[j,C]=t.useState((null==(m=null==i?void 0:i[0])?void 0:m.id)||0),[_,k]=t.useState(null),[T,I]=t.useState(null),B=l.useNavigate(),A=()=>{n()},M=async()=>{var e;v(!0);const t=await Z.getV1Templates({...w.getToken(),filters:`(company_id.eq=${j}&subject_id.eq=${a._id})`});if(null==t?void 0:t.data){const l=null==(e=null==t?void 0:t.data)?void 0:e.find(e=>!0===e.is_default);f(l),x(null==l?void 0:l._id),h(null==t?void 0:t.data)}v(!1)};return t.useEffect(()=>(M(),()=>{v(!0)}),[j]),e.jsxs("div",{children:[e.jsxs(c.Modal,{open:r,onClose:A,maxWidth:"lg",fullWidth:!0,"aria-labelledby":"email-template-selection",sx:{"& .MuiDialog-paper":{height:"85vh",display:"flex",flexDirection:"column"}},children:[console.log(u,"soure in modal +++++++++++++++++++++++debug"),e.jsxs(d.DialogTitle,{sx:{marginBottom:"1rem",padding:"0.75rem 1rem 0.75rem 1.5rem",borderBottom:"1px solid #D3D3D4"},children:[e.jsxs(d.Box,{display:"flex",alignItems:"center",gap:2,children:[T&&e.jsx(d.IconButton,{onClick:()=>I(null),size:"small",sx:{color:e=>e.palette.grey[700]},children:e.jsx(o.Typography,{children:"← Back"})}),e.jsx(o.Typography,{type:"s1",weight:"medium",color:"theme.secondary.1000",sx:{flex:1,textAlign:"center"},children:T||"view"===u?"Template Preview":"Select Template"})]}),e.jsxs(d.Box,{display:"flex",alignItems:"center",gap:1,position:"absolute",right:"1%",top:"4px",children:[e.jsx(o.Typography,{type:"s3",weight:"medium",color:"theme.secondary.800",children:" Company"}),e.jsx(c.Select,{displayEmpty:!0,value:j,size:"small",renderValue:e=>{var t;return e?null==(t=i.find(t=>t.value===e))?void 0:t.label:"Select Company"},onChange:e=>{e.target.value&&C(e.target.value)},children:i.map(t=>e.jsx(d.MenuItem,{value:t.value,children:e.jsx(o.Typography,{type:"s3",color:"theme.secondary.1000",children:t.label})},t.value))}),e.jsx(d.IconButton,{"aria-label":"close",onClick:A,size:"small",sx:{color:e=>e.palette.grey[500]},children:e.jsx(E,{fontSize:"small"})})]})]}),T?e.jsx(d.DialogContent,{sx:{display:"flex",flexDirection:"column",gap:3,width:"100%",p:3,flex:1,overflow:"auto",scrollbarWidth:"none",msOverflowStyle:"none","&::-webkit-scrollbar":{display:"none"}},children:e.jsx(d.Box,{sx:{width:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(ol,{template:T,width:"100%",height:600,scale:1,showControls:!0,isFetching:y,normalView:!0})})}):e.jsxs(d.DialogContent,{sx:{flex:1,overflow:"auto",display:"flex",flexDirection:"column",scrollbarWidth:"none",msOverflowStyle:"none","&::-webkit-scrollbar":{display:"none"}},children:[!p.length&&e.jsx(d.Box,{display:"flex",alignItems:"center",width:"100%",height:"100%",justifyContent:"center",children:!y&&e.jsx(o.Typography,{type:"s1",weight:"medium",color:"theme.secondary.1000",sx:{textAlign:"center"},children:"No templates found"})}),e.jsx(d.Box,{sx:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(300px, 1fr))",gap:2,p:2,justifyItems:"center",alignItems:"center"},children:p.map((t,l)=>e.jsx(al,{template:t,width:300,height:200,showControls:"add"===u,selectedTemplateId:g,onClick:e=>{(e=>{if("view"===u){const t=p.find(t=>(null==t?void 0:t._id)===e);I(t),x(e),B(s.EDIT_TEMPLATE(a._id,g),{state:{company_id:j,isViewOnly:!0,fromPreview:!0}})}else x(e)})(e._id)},normalView:"add"===u,isFetching:y,onDelete:e=>k(e)},t._id||l))})]}),"add"===u&&e.jsxs(d.DialogActions,{sx:{p:2,justifyContent:"center",borderTop:"1px solid #D3D3D4"},children:[e.jsx(c.Button,{onClick:()=>B(s.EDIT_TEMPLATE(a._id,g),{state:{company_id:j}}),disabled:!g,children:"Continue"}),e.jsx(c.Button,{onClick:()=>(async()=>{try{await Z.patchV1TemplatesIdSetDefault({...w.getToken(),id:g}),S.enqueueSnackbar("Template has been set as default")}catch(e){const t=w.getErrorMessage(null==e?void 0:e.message);S.enqueueSnackbar(t,{variant:"error"})}})(),disabled:!g||(null==b?void 0:b._id)===g,children:"Set to Default"})]})]}),e.jsx(c.ConfirmPopUp,{open:null!==_,onClose:()=>k(null),title:"Remove Template",description:"Are you sure you want to delete ?",onConfirm:()=>(async()=>{try{_&&(await Z.deleteV1TemplatesId({...w.getToken(),id:null==_?void 0:_._id}),S.enqueueSnackbar("Template has been deleted"),k(null),await M())}catch(e){const t=w.getErrorMessage(null==e?void 0:e.message);S.enqueueSnackbar(t,{variant:"error"})}})(),loading:y})]})},rl=({isOpen:a,setIsOpen:n,modalProps:r,companies:i,email:s,templateRoutes:u})=>{const m=l.useNavigate(),[p,h]=t.useState(0),g=()=>{n(null)};return e.jsxs(c.Modal,{open:a,onClose:g,maxWidth:"xs",fullWidth:!0,...r,children:[e.jsxs(d.DialogTitle,{className:"companySelectionModal--DialogTitle",children:[e.jsx(o.Typography,{type:"s3",color:"inherit",weight:"medium",children:"Select Company"}),e.jsx(d.IconButton,{onClick:g,children:e.jsx(E,{fontSize:"small"})})]}),e.jsx(d.DialogContent,{className:"companySelectionModal--DialogContents",children:e.jsx(c.Select,{displayEmpty:!0,value:p,size:"small",renderValue:e=>{var t;return e?null==(t=i.find(t=>t.value===e))?void 0:t.label:"Select Company"},fullWidth:!0,sx:{bgcolor:"white",borderRadius:1,"& .MuiSelect-select":{py:.75}},onChange:e=>{e.target.value&&h(e.target.value)},children:i.map(t=>e.jsx(d.MenuItem,{value:t.value,children:e.jsx(o.Typography,{type:"s4",color:"theme.secondary.1000",children:t.label})},t.value))})}),e.jsx(d.DialogActions,{className:"companySelectionModal--DialogAction",children:e.jsxs(d.Box,{display:"flex",gap:1.5,children:[e.jsx(c.Button,{className:"companySelectionModal--DialogAction--WhiteBtn",onClick:g,children:"Cancel"}),e.jsx(c.Button,{onClick:()=>{p?s?m(u.ADD_TEMPLATE(s._id),{state:{company_id:p}}):S.enqueueSnackbar("Something went wrong for a subject",{variant:"error"}):S.enqueueSnackbar("Please select a company",{variant:"error"})},disabled:!p,children:"Continue"})]})})]})},il=({type:a,module:r,modulePath:i})=>{const{t:c}=j.useTranslation(),{activePage:m,updatePageInfo:p,schemaFields:h,generatedColumns:g,updateGeneratedColumns:x}=te.usePages(),b=te.useDeepMemo(m),[f,y]=t.useState(null),v=localStorage.getItem("email-subjects-view"),[C,_]=t.useState(v?JSON.parse(v):[{label:"Table",position:0}]),[k,T]=t.useState(ee.viewTypes.TABLE),[I,E]=t.useState({pageNo:1,limit:10,totalCount:0,skip:0}),[B,A]=t.useState([]),[M]=t.useState(!1),[F,$]=t.useState([]),[D,P]=t.useState(null),[z,R]=t.useState("add"),[N,L]=t.useState(null),[O,q]=t.useState([]),W=l.useNavigate(),{pageNo:H,limit:V,totalCount:G}=I,U=b.page_size||V,K=U?Math.ceil(G/U):0,J=U*(H-1),Y=te.usePermissions(),X=it(i,a),Q=(null==Y?void 0:Y.Subjects)||{},{canAdd:le=!1,canEdit:ae=!1}=Q,oe=[{label:"New Template",handleAction:e=>(e=>{var t,l;(null==O?void 0:O.length)?(null==O?void 0:O.length)>1?L(e):W(X.ADD_TEMPLATE(e._id),{state:{company_id:(null==(t=O[0])?void 0:t.id)||(null==(l=O[0])?void 0:l.value)}}):S.enqueueSnackbar("Please add a company first",{variant:"error"})})(e),disabled:e=>!ae},{label:"Add From Template",handleAction:e=>{R("add"),P(e)},disabled:e=>!le}],ne=t.useCallback(async()=>{const{sort:e,filterQueryString:t,search:l}=b,o=l?`&subject.like=${l}`:"",n=[];n.push(a),"email"==a&&n.push("approval_email");const i=w.appendConditionSafely(t,`&type.in=[${n.join(",")}]&module.eq=${r}${o}`),s=await Z.getV1Subjects({...w.getToken(),skip:J,limit:U,...e&&{order:`${e.id}:${e.desc?-1:1}`},...i&&"()"!==i&&{filters:i}});A((null==s?void 0:s.data)||[]),E({...I,...(null==s?void 0:s.pagination)||{}})},[U,J,null==b?void 0:b.search,null==b?void 0:b.filterQueryString,null==b?void 0:b.sort]),re=t.useMemo(()=>B||[],[B]),ie=t.useMemo(()=>s.transformTableColumns({columns:g.columns,currencySymbol:e=>{var t,l;return(null==(l=null==(t=e.original)?void 0:t.currency_data)?void 0:l.symbol)||w.defaultCurrencySymbol()},translationFn:c,enableFooter:!0,rows:re,statusClasses:""}),[re,c,g.columns]),se=()=>{E({pageNo:1,limit:10,totalCount:0})};return t.useEffect(()=>{ne()},[ne]),t.useEffect(()=>((async()=>{const e=await w.fetchApi({apiKey:"company",filters:{skip:0,limit:100,order:"id:1"}});q((null==e?void 0:e.data)||[])})(),se),[]),t.useEffect(()=>{(null==C?void 0:C.length)&&localStorage.setItem("email-subjects-view",JSON.stringify(C))},[C]),e.jsxs("section",{className:"templates",children:[e.jsx(n.ActionBar,{title:"email"===a?"Emails":"PDFs",data:C,setData:_,active:k,setActive:T,handleSearch:e=>{p({search:e}),E({...I,pageNo:1})},disabledViews:["Kanban","Calendar","Gantt",ee.viewTypes.GRID],fields:h,selectedIds:F,button:!1}),k===ee.viewTypes.TABLE&&e.jsx(n.MaterialTable,{rows:re||[],columns:ie,paginationModel:I,totalPages:K,columnOrder:["mrt-row-select",...g.orderKeys],states:{isLoading:M},onSortingChange:e=>p({sort:e}),enableColumnDragging:!1,enableEditing:!1,onSelectRow:e=>$(e.map(e=>e.original.id)),enableAddCustomField:!1,rowActionMenu:oe,isResetRow:!1,handleColumnOrdering:e=>x({orderKeys:e.slice(1)}),onColumnVisibility:e=>x({columns:e}),showPreview:!0,handlePreview:e=>{R("view"),P(e)}}),k===ee.viewTypes.GRID&&e.jsx(GridCard,{data:re,rowActionMenu:oe}),!k&&e.jsx(n.Fallback,{heading:c("rental.settings.termsAndConditions.title"),subHeading:"No data available",icon:e.jsx("img",{src:u.images.invoiceFallback})}),e.jsx(n.Footer,{total:K,paginationModel:{...I,limit:b.page_size},handlePaginationModel:e=>{b.page_size!=(null==e?void 0:e.limit)&&p({page_size:e.limit}),E(e)},resource:""}),e.jsxs(s.Menu,{anchorEl:f,open:Boolean(f),onClose:()=>y(null),children:[e.jsx(d.MenuItem,{children:e.jsx(o.Typography,{type:"s4",color:"theme.secondary.1000",children:c("common.upload")})}),e.jsx(d.MenuItem,{children:e.jsx(o.Typography,{type:"s4",color:"theme.secondary.1000",children:c("common.print")})})]}),D&&e.jsx(nl,{email:D,onClose:()=>P(null),open:null!==D,companies:O,templateRoutes:X,source:z}),N&&e.jsx(rl,{isOpen:null!==N,setIsOpen:L,companies:O,email:N,templateRoutes:X})]})};exports.AddTemplate=ll,exports.AlignmentControl=Ct,exports.BorderControl=Ft,exports.ButtonControls=Bt,exports.ChangePassword=()=>{const{control:n,handleSubmit:r}=m.useForm({resolver:c.o(we),mode:"all"}),[i,s]=t.useState(null),[p,x]=t.useState(!1),{changePassword:b}=o.useAuth(),f=l.useLocation(),y=l.useNavigate(),v=h.getApiConfig().appLogo||u.images.erp_logo;return e.jsxs(d.Box,{children:[e.jsxs(ve,{container:!0,children:[e.jsx(je,{item:!0,sm:6,children:e.jsx("img",{src:u.images.login.LoginLeftSiteImage})}),e.jsx(Se,{item:!0,sm:6,xs:12,children:e.jsxs(Ce,{display:"flex",flexDirection:"column",gap:4,sx:e=>({minWidth:400,[e.breakpoints.down("md")]:{minWidth:300},[e.breakpoints.down("sm")]:{minWidth:300}}),children:[e.jsx(d.Box,{textAlign:"center",children:e.jsx("img",{src:v,width:160,height:55})}),e.jsx("form",{onSubmit:r(async e=>{var t;const l=null==(t=f.state)?void 0:t.token;return l?(e.login.token=l,await b(e.login,()=>{s({message:"Password changed successfully",type:"normal"}),setTimeout(()=>{y(a.Pathname.LOGIN)},2e3)}),e):void s({message:"Token missing",type:"alert"})}),children:e.jsxs(Ce,{gap:4,children:[e.jsxs(Ce,{gap:3,children:[e.jsxs(d.Box,{children:[e.jsx(o.Typography,{align:"center",type:"h1",weight:"medium",color:"theme.secondary.1000",children:"Change Password"}),e.jsx(o.Typography,{align:"center",type:"h5",weight:"normal",color:"theme.secondary81000",children:"Enter Details below"})]}),e.jsxs(Ce,{gap:2,children:[e.jsx(d.Box,{children:e.jsx(c.DynamicInput,{formControl:n,label:"Password",name:"password",type:"password",placeholder:"Enter Password",fieldArrayName:"login"})}),e.jsx(d.Box,{children:e.jsx(c.DynamicInput,{formControl:n,label:"Confirm Password",name:"confirm_password",type:p?"text":"password",fieldArrayName:"login",endIcon:e.jsx(e.Fragment,{children:p?e.jsx(g.Eye,{fontSize:"small",htmlColor:"#292D32"}):e.jsx(g.EyeOff,{fontSize:"small",htmlColor:"#292D32"})}),onIconClick:()=>x(!p),placeholder:"Enter confirm password"})})]})]}),e.jsx(Ce,{gap:2,children:e.jsx(c.Button,{type:"submit",size:"large",variant:"contained",children:"Change Password"})})]})})]})})]}),e.jsx(c.Toast,{open:Boolean(i),message:null==i?void 0:i.message,type:null==i?void 0:i.type,handleClose:()=>s(null),anchorOrigin:{horizontal:"right",vertical:"bottom"},autoHideDuration:3e3})]})},exports.CheckboxEditForm=qe,exports.CodeControls=Wt,exports.ColumnWidth=({onChange:l})=>{const[a,o]=t.useState(6);return t.useEffect(()=>{l(a)},[a]),e.jsxs(d.Box,{sx:{display:"flex",alignItems:"center",gap:2,p:4},children:[e.jsx(d.TextField,{value:a,onChange:e=>{const t=Number.parseInt(e.target.value)||0;o(Math.max(0,t))},name:"custom_width",size:"small",sx:{width:"120px","& .MuiOutlinedInput-root":{paddingLeft:0,paddingRight:0,"& input":{textAlign:"center",padding:"8px 4px"}}},InputProps:{startAdornment:e.jsx(d.InputAdornment,{position:"start",children:e.jsx(d.IconButton,{onClick:()=>{o(e=>Math.max(0,e-1))},size:"small",sx:{marginLeft:"-4px",borderRadius:"4px 0 0 4px",border:"none","&:hover":{backgroundColor:"rgba(0, 0, 0, 0.04)"}},children:e.jsx(f.Remove,{fontSize:"small"})})}),endAdornment:e.jsx(d.InputAdornment,{position:"end",children:e.jsx(d.IconButton,{onClick:()=>{o(e=>e+1)},size:"small",sx:{marginRight:"-4px",borderRadius:"0 4px 4px 0",border:"none","&:hover":{backgroundColor:"rgba(0, 0, 0, 0.04)"}},children:e.jsx(f.Add,{fontSize:"small"})})})},inputProps:{type:"number",min:0}}),e.jsxs(d.Box,{sx:{ml:2,color:"text.secondary"},children:["Current value: ",a]})]})},exports.CompanySelectionModal=rl,exports.CustomForm=function({redirectionPath:a}){const{t:i}=j.useTranslation(),s=r.useAppDispatch(),p=l.useNavigate(),h=l.useLocation(),x=h.state??[],b=r.useAppSelector(e=>e.formBuilder),{control:T}=m.useForm({reValidateMode:"onBlur"}),{fields:I,append:E,remove:B,update:A,move:M,insert:F}=m.useFieldArray({control:T,name:"members"}),{fields:$,append:D,remove:P,update:z}=m.useFieldArray({control:T,name:"section"}),[R,N]=t.useState(""),[L,O]=t.useState(),[q,W]=t.useState(),[H,V]=t.useState([]),[G,U]=t.useState(null),[K,J]=t.useState(),[Y,Z]=t.useState([]),[X,Q]=t.useState({}),[ee,te]=t.useState(),[le,ae]=t.useState(!1),[oe,ne]=t.useState(!1),[re,ie]=t.useState(),[se,de]=t.useState(!0),[ce,ue]=t.useState([]),[me,pe]=t.useState(0),[he,ge]=t.useState(!1),[xe,be]=t.useState(!1),[fe,ye]=t.useState(null),[ve,je]=t.useState(null),[Se,Ce]=t.useState(),we=h.pathname.split("/")[2],_e=a||lt(we);tt(b,ce,me,{removeSection:P,remove:B,setTabsData:ue,append:E,appendSection:D});const ke=t.useCallback(l=>{try{if(!l||"string"!=typeof l)return console.warn("Invalid field type provided to pickPropertyEditForm"),e.jsx("div",{className:"text-gray-500 p-4",children:"Select a field to edit"});const a=l.toLowerCase().trim(),o={text:["text","number","email","phone","date","time","url","currency","file","geolocation","image","relation","info","tagsinput"],select:["select"],section:["section"],checkbox:["checkbox","togglebutton","radiobutton"],table:["table"]},n={element:G,handlePropertyValueUpdate:Ne,handleWidthChange:Pe,handleColumnSelect:ze,fields:(null==b?void 0:b.fields)||[]},r={element:G,handlePropertyValueUpdate:Ne,handleSelectOptionValueUpdate:He,handleWidthChange:Pe,handleColumnSelect:ze};return o.text.includes(a)?t.createElement(Re,{...n,key:`text-form-${(null==G?void 0:G.id)||"default"}`}):o.select.includes(a)?t.createElement(Le,{...r,key:`select-form-${(null==G?void 0:G.id)||"default"}`}):o.section.includes(a)?e.jsx(Oe,{element:X,handlePropertyValueUpdate:De},`section-form-${(null==X?void 0:X.id)||"default"}`):o.checkbox.includes(a)?t.createElement(qe,{...r,key:`checkbox-form-${(null==G?void 0:G.id)||"default"}`}):o.table.includes(a)?e.jsx(We,{element:G,handlePropertyValueUpdate:Ne,handleColumnsUpdate:Ge,fields:(null==b?void 0:b.fields)||[]},`table-form-${(null==G?void 0:G.id)||"default"}`):(console.warn(`Unknown field type: ${l}`),e.jsxs("div",{className:"text-gray-500 p-4 border border-gray-200 rounded",children:[e.jsx("p",{className:"font-medium",children:"Unknown Field Type"}),e.jsxs("p",{className:"text-sm mt-1",children:['Field type "',l,'" is not supported. Please select a valid field to edit.']})]}))}catch(a){return console.error("Error in pickPropertyEditForm:",a),e.jsxs("div",{className:"text-red-500 p-4 border border-red-200 rounded bg-red-50",children:[e.jsx("p",{className:"font-medium",children:"Error Loading Form"}),e.jsx("p",{className:"text-sm mt-1",children:"There was an error loading the property edit form. Please try again."})]})}},[G,X,b]),Te=t.useCallback(()=>{try{if(!(null==Ie?void 0:Ie.section))return void console.error("Element section template is not available");const{uniqueStringId:e}=nt("-"),t={...ot(Ie.section),id:e};t.switcher_forms&&(t.switcher_forms=t.switcher_forms.map(e=>({...e,id:nt("-").uniqueStringId})));const l=$.length;D(t),O(l),N("section");const a={field_type:t.field_type,section_type:t.section_type,switcher_forms:t.switcher_forms,form_switcher_label:t.form_switcher_label,form_switcher_name:t.form_switcher_name,label:t.label,is_accordion:t.is_accordion,id:t.id??l};Q(a),te(l),ke(t.field_type)}catch(e){console.error("Error adding new section:",e)}},[Ie,$,D,O,N,Q,te,ke]),Ee=t.useCallback(()=>{try{const e=ot(Y);e.forEach((e,t)=>{e.members=I.filter(e=>(null==e?void 0:e.section_order)===t)});const t=e.some(e=>{var t;return null==(t=e.members)?void 0:t.some(e=>Boolean(null==e?void 0:e.is_system_field))}),l=!(null==ce?void 0:ce.length)&&t,a={tab_order:ce.length+1,title:"data",remove_tab:l,data:(null==ce?void 0:ce.length)?[]:e};ue(e=>[...e,a])}catch(e){console.error("Error adding new tab:",e)}},[Y,I,ce,ue]),Be=t.useCallback((e,t)=>{try{if(!at(e)||!(null==t?void 0:t.trim()))return void console.error("Invalid tab ID or title provided");ue(l=>l.map(l=>l.tab_order===e?{...l,title:t.trim()}:l))}catch(l){console.error("Error editing tab title:",l)}},[ue]),Ae=t.useCallback(e=>{try{if(!at(e))return void console.error("Invalid tab ID provided");const t=ce.filter(t=>t.tab_order!==e).map(t=>({...t,tab_order:t.tab_order>e?t.tab_order-1:t.tab_order}));if(ue(t),me==e&&pe((null==t?void 0:t.length)-1),t.length>0){const e=t.find(e=>e.tab_order===(me??0)+1);if(null==e?void 0:e.data){const t=e.data.map(({field_type:e,label:t,is_accordion:l,id:a,remove_section:o})=>({field_type:e,label:t,is_accordion:l,id:a,remove_section:o})),l=e.data.flatMap(e=>{var t;return(null==(t=e.members)?void 0:t.map(e=>({...e})))||[]});B(),P(),l.forEach(e=>E(e)),t.forEach(e=>D(e))}}else B(),P()}catch(t){console.error("Error removing tab:",t)}},[ce,me,ue,B,P,E,D]),Me=t.useCallback(e=>{try{const t=e.target.dataset.position;if(!t||!at(t))return void console.error("Invalid element position index");const l=Number(t);if(l<0||l>=H.length)return void console.error("Element position index out of bounds");W(l);const a=ot(H[l]);J(l),U(a),N("element")}catch(t){console.error("Error selecting element:",t)}},[H,W,J,U,N]),Fe=t.useCallback(e=>{try{const t=e.target.dataset.position;if(!t||!at(t))return void console.error("Invalid section position index");const l=Number(t);if(l<0||l>=Y.length)return void console.error("Section position index out of bounds");O(l);const a=ot(Y[l]);te(l),Q(a),N("section")}catch(t){console.error("Error selecting section:",t)}},[Y,O,te,Q,N]),$e=t.useCallback((e,t)=>{var l;try{const a=e.currentTarget,o=null==(l=null==a?void 0:a.dataset)?void 0:l.position;if(void 0===o||!at(o))return void console.error("Invalid section position index for adding member");const n=Number(o);if(n<0)return void console.error("Section position index cannot be negative");if(!(null==Ie?void 0:Ie.text))return void console.error("Element text template is not available");const r={...ot(Ie.text),...t,section_order:n,type:"custom",is_new:!0,custom_width:Math.floor(6),is_fullwidth:!1,is_system_field:Boolean(null==t?void 0:t.is_system_field),id:nt().uniqueStringId};O(n),E(r);const i=I.length;W(i),N("element"),J(i),U(r),ke(r.field_type)}catch(a){console.error("Error adding new member:",a)}},[Ie,I,O,E,W,N,J,U,ke]),De=t.useCallback((e,t)=>{try{const{name:l,type:a,checked:o,value:n}=e.target;if(!l)return void console.error("Property name is required for update");const r=void 0!==t?t:"checkbox"===a?o:n;X[l]!==r&&Q(e=>({...e,[l]:r}))}catch(l){console.error("Error updating section property:",l)}},[X,Q]),Pe=t.useCallback(e=>{try{if(!at(e)||e<1||e>12)return void console.error("Invalid width value provided");U(t=>({...t,custom_width:e}))}catch(t){console.error("Error updating width:",t)}},[U]),ze=t.useCallback(e=>{try{const t=Number(e.target.value);if(!at(t)||t<=0)return void console.error("Invalid column value provided");const l=Math.floor(12/t);if(l<=0)return void console.error("Calculated element per column is invalid");I.forEach((e,t)=>{A(t,{...e,custom_width:l})})}catch(t){console.error("Error updating column selection:",t)}},[I,A]),Ne=t.useCallback((e,t,l,a)=>{var o,n;try{const r=a||(void 0!==l?l:void 0!==t?t:null==(n=null==e?void 0:e.target)?void 0:n.value),i=ot(G);if((null==(o=null==e?void 0:e.target)?void 0:o.name)&&(i[e.target.name]="checkbox"===e.target.type?e.target.checked:r),a){const{uniqueStringId:e}=nt(),t={...Ie[a],section_form_id:null==i?void 0:i.section_form_id,is_form_switcher_section:null==i?void 0:i.is_form_switcher_section,section_order:i.section_order,id:e,type:"custom",is_system_field:Boolean(null==i?void 0:i.is_system_field),is_new:!0,column_width:(null==i?void 0:i.column_width)||6,custom_width:(null==i?void 0:i.custom_width)||6};U(t)}else JSON.stringify(G)!==JSON.stringify(i)&&U({...G,...i})}catch(r){console.error("Error updating property value:",r)}},[G,Ie,U]),He=t.useCallback(e=>{try{if(!Array.isArray(e))return void console.error("Options must be an array");const t=ot(G);t.options=[...e];const{uniqueStringId:l}=nt("-");JSON.stringify(G.options)!==JSON.stringify(e)&&U({...G,...t,id:l})}catch(t){console.error("Error updating select options:",t)}},[G,U]),Ge=t.useCallback(e=>{try{if(!Array.isArray(e))return void console.error("Columns must be an array");const t=ot(G);t.table_columns=[...e];const{uniqueStringId:l}=nt("-");JSON.stringify(G.table_columns)!==JSON.stringify(e)&&U({...G,...t,id:l})}catch(t){console.error("Error updating table columns:",t)}},[G,U]),Ue=t.useCallback(e=>{try{if(!at(e)||e<0||e>=$.length)return void console.error("Invalid section index for removal");ie(e),P(e);const t=[];I.forEach((l,a)=>{(null==l?void 0:l.section_order)===e&&t.push(a)}),t.reverse().forEach(e=>{B(e)}),ae(!0)}catch(t){console.error("Error removing section:",t)}},[$,I,ie,P,B,ae]),Ke=t.useCallback(e=>{try{if(!at(e)||e<0||e>=$.length)return void console.error("Invalid section index for accordion conversion");be(!0),te(e),O(e);const t={...ot($[e]),is_accordion:!0};z(e,t),N("section"),Q(t),ke(t.field_type)}catch(t){console.error("Error making section accordion:",t)}},[$,be,te,O,z,N,Q,ke]),Je=t.useCallback(()=>{try{const e=ot(Y);e.forEach((e,t)=>{e.members=I.filter(e=>(null==e?void 0:e.section_order)===t)});const t=e.some(e=>{var t;return null==(t=e.members)?void 0:t.some(e=>Boolean(null==e?void 0:e.is_system_field))}),l=Number(me);if(at(l)&&l>=0&&l<ce.length){const a=[...ce];a[l]={...a[l],data:e,remove_tab:t},ue(a),B(),P(),W(void 0),N(""),O(void 0)}}catch(e){console.error("Error updating tab data:",e)}},[Y,I,me,ce,ue]),Ye=t.useMemo(()=>Y&&I?Y.map((e,t)=>({...e,members:I.filter(e=>(null==e?void 0:e.section_order)===t)})):null,[Y,I]),Ze=t.useMemo(()=>Ye?(null==ce?void 0:ce.length)?{tab:ce}:{section:Ye}:null,[ce,Ye]),Xe=t.useMemo(()=>Ze?C.formBuilderConversion(Ze):null,[Ze]),Qe=t.useCallback(()=>{Xe&&je(Xe)},[Xe,je]),et=t.useCallback(()=>{je(null)},[]),rt=t.useCallback(async()=>{var e;try{if(!Y||!Array.isArray(Y))return void console.warn("Invalid sectionFormJSON provided");if(!I||!Array.isArray(I))return void console.warn("Invalid members array provided");if(!(null==x?void 0:x._id))return void console.warn("Missing rowData._id for form update");let a;try{a=structuredClone(Y)}catch(t){a=JSON.parse(JSON.stringify(Y))}a.forEach((e,t)=>{e&&"object"==typeof e?e.members=I.filter(e=>e&&"object"==typeof e&&"number"==typeof e.section_order&&e.section_order===t):console.warn(`Invalid section at index ${t}`)});const o=a.some(e=>{var t;return null==(t=e.members)?void 0:t.some(e=>Boolean(null==e?void 0:e.is_system_field))}),n=Number(me);let r=[...ce];at(n)&&n>=0&&n<ce.length&&(r=[...ce],r[n]={...r[n],data:a,remove_tab:o},ue(r));const i=(null==r?void 0:r.length)>0?{tab:r}:{section:a};if("function"!=typeof C.formBuilderConversion)return void console.error("formBuilderConversion is not a function");let d;try{d=C.formBuilderConversion(i)}catch(l){return void console.error("Error during form builder conversion:",l)}if(!d)return void console.warn("Form builder conversion returned empty result");const c={gridCol:2,fields:d},u=await s(k.patchFormDataById({id:x._id,data:c}));if("rejected"===u.meta.requestStatus){const t=w.getErrorMessage(null==(e=null==u?void 0:u.error)?void 0:e.message);S.enqueueSnackbar(t,{variant:"error"})}else S.enqueueSnackbar("Form updated successfully",{variant:"success"}),p(_e)}catch(a){const e=(null==a?void 0:a.message)||"Something went wrong while updating the form";S.enqueueSnackbar(e,{variant:"error"})}},[Y,I,ce,null==x?void 0:x._id,void 0,s,C.formBuilderConversion]),it=e=>{const t={...I[e],type:"custom"};t&&F(e+1,t),W(e+1),N("element"),J(e+1),U(t),ke(t.field_type)},st=[{link:_e,label:"Forms"},{link:"",label:w.formatLabel(null==x?void 0:x.name)},{link:"",label:"Edit Form"}];t.useEffect(()=>{le&&(I.forEach((e,t)=>{void 0!==re&&Boolean(null==re?void 0:re.toString)&&e.section_order>re&&A(t,{...e,section_order:e.section_order-1})}),ae(!1),ne(!0),ie(void 0),N(""))},[le]),t.useEffect(()=>{b.isSuccess&&p(_e)},[b.isSuccess]),t.useEffect(()=>{b.isError&&ye({type:"alert",message:b.error})},[b.error,b.isError]),t.useEffect(()=>{if("number"!=typeof K||"string"!=typeof K){const e=Number(K);if(H[e]){const t=JSON.parse(JSON.stringify(H[e]));A(e,{...t})}}},[H]),t.useEffect(()=>{const e=H.map((e,t)=>t===Number(K)?{...G}:{...e});V(e)},[G]),t.useEffect(()=>{if(I.length!==H.length&&V(JSON.parse(JSON.stringify(I))),Boolean(he)&&JSON.stringify(I)!==JSON.stringify(H)){V(JSON.parse(JSON.stringify(I))),ge(!1);const e=K&&I[K];e&&N("element"),e&&U(e),e&&ke(e.field_type)}oe&&JSON.stringify(I)!==JSON.stringify(H)&&(V(JSON.parse(JSON.stringify(I))),ne(!1))},[I,he]),t.useEffect(()=>{if("number"!=typeof ee||"string"!=typeof ee){const e=Number(ee);if(Y[e]){const t=JSON.parse(JSON.stringify(Y[e]));z(e,{...t})}}},[Y]),t.useEffect(()=>{const e=Y.map((e,t)=>t===Number(ee)?{...e,...X}:{...e});Z(e)},[X]),t.useEffect(()=>{$.length!==Y.length&&Z(JSON.parse(JSON.stringify($))),JSON.stringify(Y)!==JSON.stringify($)&&xe&&(Z(JSON.parse(JSON.stringify($))),be(!1))},[$]),t.useEffect(()=>{},[]);const dt=t.useCallback(async()=>{de(!0);try{(null==x?void 0:x._id)&&(ue([]),await s(k.getFormDataById(null==x?void 0:x._id)),await s(k.getFieldsByFormId({id:null==x?void 0:x._id})))}finally{de(!1)}},[null==x?void 0:x._id]);t.useEffect(()=>{dt()},[dt]);const ct=e=>e&&Object.keys(e).length>0,ut=()=>e.jsx(o.Typography,{type:"s5",color:"theme.secondary.800",className:"formSection--Text",children:"Select a field to edit its properties."}),mt=(e,t="text")=>(null==e?void 0:e.field_type)||t,pt=t.useMemo(()=>{if(!R)return e.jsx(ut,{});if("element"===R){if(!ct(I))return console.warn("Element selected but no members data available"),e.jsx(ut,{});const t=mt(G);return ke(t)}if("section"===R){if(!ct($))return console.warn("Section selected but no section data available"),e.jsx(ut,{});const t=mt(X);return ke(t)}return console.warn(`Unknown selectedHoc type: ${R}`),e.jsx(ut,{})},[R,Object.keys(I).length,Object.keys($).length,null==G?void 0:G.field_type,null==G?void 0:G.field_properties,null==X?void 0:X.field_type,null==X?void 0:X.field_properties,ke]);return e.jsx(d.Box,{position:"relative",children:se?e.jsx(_.ErpLoader,{}):e.jsxs(y.DndProvider,{backend:v.HTML5Backend,children:[e.jsx(n.FormHeader,{breadCrumbPath:st,children:e.jsxs("div",{className:"formSection--Buttons",children:[e.jsx(n.DynamicButton,{variant:"outlined",className:"formSection--PreviewButton",text:"Preview",onClick:()=>{ve?et():Qe()},disable:!(null==I?void 0:I.length),startIcon:ve?e.jsx(g.EyeOff,{}):e.jsx(g.Eye,{})}),e.jsx(n.DynamicButton,{variant:"contained",type:"submit",text:"Update",onClick:rt,disable:ve})]})}),ve?e.jsx(n.FormParser,{data:ve||[],handleFormSubmit:e=>console.log("Preview Data",e),className:"form-container",fieldArrayName:"form-builder-preview",getFormMethods:e=>Ce({...e})}):e.jsxs(d.Grid,{className:"formSection--Grid",container:!0,children:[e.jsx(d.Grid,{item:!0,xs:9,component:"form",sx:{position:"relative",background:"#F5F6F5",padding:"0.75rem"},children:e.jsxs(d.Grid,{className:"formSection--GridContainer",children:[e.jsxs(d.Box,{className:"formSection--Tab",children:[ce&&e.jsx(n.TabBar,{tabs:ce,onEditTabTitle:Be,activeValue:me,setActiveValue:pe,handleTabChange:()=>{Je()},handleRemoveTab:Ae,containerProps:{mb:0}}),e.jsx(n.DynamicButton,{variant:"outlined",text:"Add Tab",onClick:Ee,style:{color:"#292D32",margin:"0.5rem"}})]}),e.jsxs("div",{className:"formSection--Form",children:[null==$?void 0:$.map((t,l)=>{var a;const r=I.filter(e=>e.section_order===l),s=t.section_type===w.SECTION_TYPES.FORM_SWITCH_SECTION,c=null==(a=null==t?void 0:t.switcher_forms)?void 0:a.map(e=>({...e,formMembers:I.filter(t=>t.section_form_id===e.id)}));return e.jsxs(n.DynamicSectionHOC,{index:l,label:i(t.label),onClick:Fe,position:l,fieldArrayName:"section",isFormSwitcher:s,activeIndex:L===l,removeSection:()=>Ue(l),handleAccordion:()=>Ke(l),handleAddButton:e=>$e(e),remove_section:t.remove_section,children:[s?e.jsxs("div",{style:{width:"100%"},children:[e.jsx(o.Typography,{type:"s5",style:{fontWeight:500},color:"theme.secondary.800",children:t.form_switcher_label}),e.jsx(d.RadioGroup,{"aria-labelledby":"theme-radio-buttons-group-label",name:t.form_switcher_name||t.form_switcher_label,children:null==c?void 0:c.map(({name:t,id:a,formMembers:o})=>e.jsxs(e.Fragment,{children:[e.jsx("div",{children:e.jsx(d.FormControlLabel,{value:t,control:e.jsx(n.Radio,{}),label:i(t),disabled:!0},a)}),e.jsx(d.Grid,{container:!0,sx:{mb:3},children:e.jsx(Ve,{sectionMembers:o||[],members:I,activeMember:q,control:T,t:i,element:Ie,images:u.images,elementJSON:G,remove:B,move:M,handleElementSelection:Me,setElementSwap:ge,handleDuplicateElement:it,setSelectedHoc:N,setActiveMember:W})}),e.jsx(n.DynamicButton,{text:"Add",variant:"outlined",className:"formSection--PreviewButton","data-position":l,onClick:e=>$e(e,{section_form_id:a,is_form_switcher_section:!0}),startIcon:e.jsx(f.Add,{})})]}))})]}):null,!s&&e.jsx(Ve,{sectionMembers:r||[],members:I,activeMember:q,control:T,t:i,element:Ie,images:u.images,elementJSON:G,remove:B,move:M,handleElementSelection:Me,setElementSwap:ge,handleDuplicateElement:it,setSelectedHoc:N,setActiveMember:W})]})}),e.jsx("div",{className:"formSection--Section",children:e.jsx(n.DynamicButton,{text:"Add a section",variant:"outlined",className:"formSection--PreviewButton",onClick:Te,startIcon:e.jsx(f.Add,{})})})]})]})}),e.jsx(d.Grid,{item:!0,xs:3,className:Boolean(R)&&((null==I?void 0:I.length)||$.length)?"formSection--RightGrid":"formSection--RightGrid formSection--Text",children:pt})]}),e.jsx(c.Toast,{open:Boolean(fe),type:null==fe?void 0:fe.type,message:null==fe?void 0:fe.message,handleClose:()=>ye(null),anchorOrigin:{horizontal:"right",vertical:"bottom"}})]})})},exports.DividerControls=Pt,exports.EditSectionModal=xt,exports.EditorCanvas=Qt,exports.EditorHeader=ht,exports.EditorSidebar=Jt,exports.FieldSelect=Be,exports.ForgotPassword=()=>{const{forgotPassword:n}=o.useAuth(),r=b.styled(d.Grid)(()=>({height:"100vh"})),i=l.useNavigate(),[s,p]=t.useState(null),g=ae.object({login:ae.object({email:ae.string().required("Please enter email").email("Provided email is invalid")})}),{control:x,handleSubmit:f}=m.useForm({resolver:c.o(g),mode:"all"}),y=b.styled(d.Grid)(({theme:e})=>({[e.breakpoints.down("sm")]:{display:"none"},backgroundImage:`url(${u.images.login.LoginLeftBg})`,backgroundRepeat:"no-repeat",backgroundSize:"cover",display:"flex",justifyContent:"center",alignItems:"center",[e.breakpoints.down("lg")]:{"& img":{width:350,height:350}},[e.breakpoints.down("md")]:{"& img":{width:300,height:300}}})),v=b.styled(d.Grid)(()=>({display:"flex",justifyContent:"center",alignItems:"center",padding:"1rem"})),j=b.styled(d.Box)(()=>({display:"flex",flexDirection:"column"}));t.useEffect(()=>{});const S=h.getApiConfig().appLogo||u.images.erp_logo;return e.jsxs(d.Box,{children:[e.jsxs(r,{container:!0,children:[e.jsx(y,{item:!0,sm:6,children:e.jsx("img",{src:u.images.login.LoginLeftSiteImage})}),e.jsx(v,{item:!0,sm:6,xs:12,children:e.jsxs(j,{display:"flex",flexDirection:"column",gap:4,sx:e=>({minWidth:400,[e.breakpoints.down("md")]:{minWidth:300},[e.breakpoints.down("sm")]:{minWidth:300}}),children:[e.jsx(d.Box,{textAlign:"center",children:e.jsx("img",{src:S,width:160,height:55})}),e.jsx("form",{onSubmit:f(async e=>(await n(e.login,(e,t)=>{e?(p({message:t,type:"normal"}),setTimeout(()=>{i(a.Pathname.LOGIN)},1500)):p({message:t,type:"alert"})}),e)),children:e.jsxs(j,{gap:4,children:[e.jsxs(j,{gap:3,children:[e.jsxs(d.Box,{children:[e.jsx(o.Typography,{align:"center",type:"h1",weight:"medium",color:"theme.secondary.1000",children:"Forgot Password"}),e.jsx(o.Typography,{align:"center",type:"h5",weight:"normal",color:"theme.secondary81000",children:"Enter your email to reset password"})]}),e.jsx(j,{gap:2,children:e.jsx(d.Box,{children:e.jsx(c.DynamicInput,{formControl:x,label:"Email",name:"email",placeholder:"Enter email",fieldArrayName:"login"})})})]}),e.jsxs(j,{gap:2,children:[e.jsx(c.Button,{type:"submit",size:"large",variant:"contained",children:"Reset Password"}),e.jsx(c.Button,{variant:"text",sx:e=>{var t;return{color:`${null==(t=e.palette.theme)?void 0:t.primary[700]} !important`}},onClick:()=>{i(a.Pathname.LOGIN)},children:"Back to login"})]})]})})]})})]}),e.jsx(c.Toast,{open:Boolean(s),message:null==s?void 0:s.message,type:null==s?void 0:s.type,handleClose:()=>p(null),anchorOrigin:{horizontal:"right",vertical:"bottom"},autoHideDuration:3e3})]})},exports.FormField=He,exports.FormFields=Ve,exports.HtmlThumbnailPreview=al,exports.ImageControls=Dt,exports.Landing=function(){return e.jsx("div",{className:"Landing",children:e.jsxs("div",{className:"Landing--Home",id:"home",children:[e.jsx("div",{className:"Landing--HomeAnimation",children:e.jsx("video",{className:"Landing--HomeAnimationVideo",autoPlay:!0,muted:!0,loop:!0,playsInline:!0,children:e.jsx("source",{src:"https://ak.picdn.net/shutterstock/videos/1063309405/preview/stock-footage-modern-office-portrait-of-beautiful-authentic-specialist-with-short-pink-hair-standing-holding.webm",type:"video/mp4"})})}),e.jsx("div",{className:"Landing--HomeContent",children:e.jsxs("div",{className:"Landing--HomeContentTop",children:[e.jsxs("h1",{className:"Landing--SubTitle",children:["Introducing Dummy",e.jsx("span",{style:{fontWeight:"700"},children:" Land, "})]}),e.jsx("h1",{className:"Landing--Para",children:"This is the hero section.Lorem ipsum dolor sit amet, consectetur adipisicing elit.Dicta fugiat perspiciatis temporibus ut impedit expedita maiores officiis porro ? At commodi suscipit atque eligendi cumque ? Impedit magnam eligendi fugiat.Non, quam."})]})})]})})},exports.MemoizedEditorSection=jt,exports.NotFound=se,exports.PageView=()=>{const l=r.useAppDispatch(),{pages:a,currentPage:o,rows:i,columns:d,columnOrder:u,paginationModel:m}=r.useAppSelector(e=>null==e?void 0:e.pages),{pageNo:p,limit:h}=m;t.useEffect(()=>{l(de(1))},[l]),t.useEffect(()=>{l(de(o))},[l,o]);const g=t.useMemo(()=>{const e=h*(p-1);return i.slice(e,e+h)},[i,p,h]),x=t.useMemo(()=>null==d?void 0:d.map(t=>{let l={...t,enableSorting:!0};return"number"===(null==t?void 0:t.type)?l={...l,muiEditTextFieldProps:{type:"number"},Footer:({column:t})=>e.jsx(ie,{data:g,column:null==t?void 0:t.id})}:"string"===t.type&&(l={...l,Footer:({column:t})=>e.jsx(s.DefaultAggregation,{data:g,column:t.id})}),l}),[g,d]),b=h?Math.ceil(i.length/h):0;return e.jsxs(e.Fragment,{children:[e.jsx(c.Button,{children:"Open Filter"}),e.jsx(n.MaterialTable,{rows:g,columns:x,paginationModel:m,totalPages:b,columnOrder:["mrt-row-select",...u],handleColumnOrdering:e=>{l(be(e.slice(1)))},updateData:(e,t,a)=>{var o;const n={value:"number"===(null==(o=null==t?void 0:t.columnDef)?void 0:o.type)?Number(e):e,columnId:t.id,rowId:a};l(fe(n))}}),e.jsx(n.Footer,{pages:a,setPages:e=>l(ge(e)),currentPage:o,setCurrentPage:e=>l(he(e)),total:b,paginationModel:m,handlePaginationModel:e=>{l(xe(e))}})]})},exports.PrivateRoute=()=>{const{user:t,loading:r}=o.useAuth();return r?e.jsx(n.Loader,{}):t?e.jsx(l.Outlet,{}):e.jsx(l.Navigate,{to:a.Pathname.LOGIN})},exports.ResetPassword=()=>{const{resetPassword:n}=o.useAuth(),[r]=l.useSearchParams(),i=l.useNavigate();return t.useEffect(()=>{const e=r.get("token");e?n({token:e},t=>{var l;console.log("response ",t),t?t&&(null==t?void 0:t.data)&&(null==(l=null==t?void 0:t.data)?void 0:l.isValid)&&i(a.Pathname.CHANGE_PASSWORD,{state:{token:e}}):i(a.Pathname.LOGIN)}):i(a.Pathname.LOGIN)},[r,n,i]),e.jsx(d.Box,{children:"Resetting password, please wait..."})},exports.SectionEditForm=Oe,exports.SectionFlowEditor=tl,exports.SectionFormatPanel=Vt,exports.SelectEditForm=Le,exports.SignatureControls=qt,exports.TableControls=Ot,exports.TableEditForm=We,exports.TemplateModal=nl,exports.TemplateNameModal=el,exports.Templates=il,exports.TextControls=It,exports.TextEditForm=Re,exports.activityTag={comments:[{name:"You",dateTime:"01-11-2024 12:45:10",text:"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."},{name:"Siddhant",dateTime:"01-12-2024 15:05:22",text:"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}],activities:[{dateTime:"12-27-2023 19:17:10",text:"Prasun assigned HR Admin role to Avneet Singh."},{dateTime:"12-27-2023 19:15:10",text:"Prasun created a new user Avneet Singh"},{dateTime:"12-27-2023 15:17:10",text:"Prasun created a new role HR Admin"},{dateTime:"12-27-2023 14:17:10",text:"Prasun updated a role UI/UX Designer ‣ Product Designer"},{dateTime:"12-27-2023 14:17:10",text:"Amrit updated resources for UI/UX Designer role."},{dateTime:"12-27-2023 14:17:10",text:"Amrit updated user Prashant Singh ‣ Prasun Singh"},{dateTime:"12-27-2023 14:17:10",text:"Amrit updated user Prashant Singh ‣ Prasun Singh"}]},exports.board={columns:[{id:1,title:"Backlog",cards:[{id:1.1,title:"Card title 1",description:"Card content"},{id:1.2,title:"Card title 2",description:"Card content"},{id:1.3,title:"Card title 3",description:"Card content"}]},{id:2,title:"Doing",cards:[{id:2.1,title:"Card title 9",description:"Card content"}]},{id:3,title:"Q&A",cards:[{id:3.1,title:"Card title 10",description:"Card content"},{id:3.2,title:"Card title 11",description:"Card content"}]},{id:4,title:"Production",cards:[{id:4.1,title:"Card title 12",description:"Card content"},{id:4.2,title:"Card title 13",description:"Card content"}]}]},exports.calendarData=_e,exports.column=Te,exports.createDefaultTableColumns=()=>[{header:"Column 1",accessorKey:"column_1",visible:!0},{header:"Column 2",accessorKey:"column_2",visible:!0}],exports.data=[{name:"Naidu Setti",company:"ERP Force",status:"Paid",email:"naidu@gmail.com",amount:"$1,00,000"},{name:"Shashank Yadav",company:"Antino Labs",status:"Pending",email:"shashank@gmail.com",amount:"$50,000"},{name:"Tarun Prajapati",company:"Goldenflitch",status:"Lost",email:"tarun@gmail.com",amount:"$60,000"},{name:"Rajneesh Kumar",company:"ERP Force",status:"Lost",email:"rajneesh@gmail.com",amount:"$10,000"},{name:"Radhakanth",company:"Antino",status:"Upcomming",email:"radhakanth@gmail.com",amount:"$1,00,000"}],exports.defaultData=ce,exports.element=Ie,exports.emailColumns=[{header:"ID",accessorKey:"_id",visible:!0,type:"string"},{header:"Date",accessorKey:"created_at",visible:!0,type:"date"},{header:"Subject",accessorKey:"subject",visible:!0,type:"string"}],exports.extractSections=Ye,exports.extractStyles=ct,exports.fetchPage=de,exports.formatText=Ue,exports.generateCustomFormPath=(e,t)=>{try{return`/dashboard/${e}${t}`}catch(l){throw console.error("Error generating module path:",l),l}},exports.generateEmailPreview=st,exports.generateHeaderFooterPreview=dt,exports.generateInlineStyles=mt,exports.generateModulePath=lt,exports.getInitialSectionData=pt,exports.local=ue,exports.multilineData=[{id:1,name:"Customer",role:"Selling"},{id:2,name:"Producer",role:"sdf"},{id:3,name:"Director",role:"wer"}],exports.pageViewChangeCurrentPage=he,exports.processMembers=Je,exports.processTableColumns=Ke,exports.reducer=ye,exports.setColumnOrder=be,exports.setPageViewPages=ge,exports.setPageViewPaginationModel=xe,exports.setRowData=fe,exports.tableData=[{age:33,name:"Delaney Cortez",company:"IZZBY",email:"delaneycortez@izzby.com",phone:"+1 (844) 567-3740",image:"https://picsum.photos/id/74/900/900",address:"870 Hegeman Avenue, Crawfordsville, Kentucky, 2953",about:"Nostrud labore esse labore aliquip. Qui excepteur sint exercitation adipisicing deserunt ad veniam sunt ipsum nulla deserunt dolor est culpa. Eu deserunt nostrud ipsum mollit consectetur mollit et. Commodo mollit qui Lorem fugiat eiusmod dolore amet est officia aliqua. Est tempor veniam sit magna. Ullamco veniam eiusmod nostrud sit dolor. Est proident cupidatat proident ullamco irure commodo nisi fugiat adipisicing ullamco adipisicing ad officia.\r\n",date:"2023-01-10T09:02:53.870Z"},{age:24,name:"Williamson Davenport",company:"ONTAGENE",email:"williamsondavenport@ontagene.com",phone:"+1 (844) 564-3345",image:"https://picsum.photos/id/40/900/900",address:"274 Forest Place, Vowinckel, Maine, 9510",about:"Quis ipsum ad deserunt cillum consequat do ex laboris sit eiusmod pariatur occaecat voluptate. Laborum ea sit duis mollit est sunt culpa ut et commodo consectetur veniam adipisicing amet. Ipsum mollit proident ea deserunt veniam Lorem duis aliquip dolor duis proident ut. Velit esse officia occaecat exercitation magna consequat ullamco ea nisi. Ad ea deserunt occaecat quis occaecat eiusmod ad do. Elit veniam quis aliquip qui nostrud laborum irure minim aute irure fugiat. Ullamco aliquip dolor est sit nulla consectetur.\r\n",date:"2023-01-10T09:02:53.870Z"},{age:30,name:"Alexander Wong",company:"QUADEEBO",email:"alexanderwong@quadeebo.com",phone:"+1 (834) 497-2624",image:"https://picsum.photos/id/8/900/900",address:"420 Borinquen Pl, Kenvil, Vermont, 7377",about:"Dolor mollit elit est ex. Sit mollit laboris ad pariatur magna est amet veniam ad ad velit incididunt eu. Minim ipsum qui labore eiusmod magna veniam in magna pariatur Lorem.\r\n",date:"2023-01-10T09:02:53.870Z"},{age:24,name:"Blanca Schultz",company:"CUJO",email:"blancaschultz@cujo.com",phone:"+1 (954) 412-2870",image:"https://picsum.photos/id/42/900/900",address:"144 Albemarle Terrace, Watchtower, Delaware, 2829",about:"Pariatur sunt dolore nostrud cillum cupidatat culpa. Ipsum laborum laboris reprehenderit Lorem culpa. Consequat duis do occaecat ipsum cupidatat sunt minim minim cillum commodo in qui culpa anim. Et ullamco nisi eiusmod laboris veniam laborum ullamco reprehenderit aliqua nulla labore. Elit excepteur sunt exercitation anim sint non ea.\r\n",date:"2023-01-10T09:02:53.870Z"},{age:34,name:"Eunice Romero",company:"CENTREGY",email:"euniceromero@centregy.com",phone:"+1 (949) 568-3290",image:"https://picsum.photos/id/3/900/900",address:"698 Clermont Avenue, Harmon, Washington, 1094",about:"Nulla aute enim incididunt labore aute id officia fugiat tempor aliqua. Fugiat incididunt sint nisi eiusmod fugiat magna minim in. Officia eu enim magna magna pariatur deserunt esse amet veniam sint consequat est sit.\r\n",date:"2023-01-10T09:02:53.870Z"}],exports.tabsData=[{tab_order:1,title:"Tab One",content:"Tab one Content"},{tab_order:2,title:"Tab Two",content:"Tab two Content"},{tab_order:3,title:"Tab Three",content:"Tab three Content"}],exports.templateEditorRoutes=(t,l)=>[{path:`${M.TEMPLATE_EDITOR_PATHS.TEMPLATES_LIST("email")}`,element:e.jsx(il,{type:"email",module:l,modulePath:t})},{path:`${M.TEMPLATE_EDITOR_PATHS.TEMPLATES_ADD("email")}`,element:e.jsx(ll,{modulePath:t,type:"email",module:l})},{path:`${M.TEMPLATE_EDITOR_PATHS.TEMPLATES_EDIT("email")}`,element:e.jsx(ll,{modulePath:t,type:"email",module:l})},{path:`${M.TEMPLATE_EDITOR_PATHS.TEMPLATES_LIST("pdf")}`,element:e.jsx(il,{module:l,type:"pdf",modulePath:t})},{path:`${M.TEMPLATE_EDITOR_PATHS.TEMPLATES_ADD("pdf")}`,element:e.jsx(ll,{modulePath:t,type:"pdf",module:l})},{path:`${M.TEMPLATE_EDITOR_PATHS.TEMPLATES_EDIT("pdf")}`,element:e.jsx(ll,{modulePath:t,type:"pdf",module:l})}],exports.templateRoutes=it,exports.textOptions=[{label:"Heading 1",value:"heading"},{label:"Heading 2",value:"heading-2"},{label:"Heading 3",value:"heading-3"},{label:"Heading 4",value:"heading-4"},{label:"Body",value:"text"},{label:"Text Block",value:"text-block"}],exports.useCKEditorStyleExtractor=bt,exports.useFormDataEffect=tt,exports.useFormDataProcessor=(e,l,a,o)=>{const{removeSection:n,remove:r,append:i}=o,d=t.useMemo(()=>JSON.stringify(null==e?void 0:e.formData),[null==e?void 0:e.formData]),c=t.useMemo(()=>{var t;if(!(null==(t=null==e?void 0:e.formData)?void 0:t.length))return null;try{return s.formBuilderDeConversion(e.formData)}catch(l){return console.error("Error processing form data:",l),null}},[d]);return t.useEffect(()=>{if(!c)return n(),r(),void i([]);try{l.length>0?Ze({tabsData:l},a,e,l,o):c.tab?Ze(c,a,e,l,o):c.section?Ze(c,0,e,l,o):(console.warn("No valid data structure found in initialData"),n(),r(),i([]))}catch(t){console.error("Error in form data processing:",t),n(),r(),i([])}},[a,d,l.length,c,o,e]),{initialData:c}},exports.userData=[{id:1,name:"Aman Gupta",role:"Accountant & Finance",roleId:2},{id:2,name:"Deepak Sharma",role:"Sales",roleId:4},{id:3,name:"Avhinav Dhingra",role:"Operation",roleId:3},{id:4,name:"Rajiv Mehta",role:"Maintenance",roleId:1},{id:5,name:"Rajiv Mehta",role:"Stakes",roleId:6},{id:6,name:"Rajdeep Dutta",role:"Research & Development",roleId:5},{id:7,name:"Sonia Verma",role:"Accountant & Finance",roleId:2},{id:8,name:"Vikram Singh",role:"Sales",roleId:4},{id:9,name:"Neha Patel",role:"Operation",roleId:3},{id:10,name:"Ankit Kapoor",role:"Maintenance",roleId:1},{id:11,name:"Kavita Shah",role:"Stakes",roleId:6},{id:12,name:"Rohit Singh",role:"Research & Development",roleId:5},{id:13,name:"Priya Agarwal",role:"Human Resources",roleId:7},{id:14,name:"Amit Trivedi",role:"Marketing",roleId:8},{id:15,name:"Sara Khan",role:"Customer Support",roleId:9},{id:16,name:"Amit Gupta",role:"Accountant & Finance",roleId:2},{id:17,name:"Neha Sharma",role:"Sales",roleId:4},{id:18,name:"Rahul Verma",role:"Operation",roleId:3},{id:19,name:"Meera Kapoor",role:"Maintenance",roleId:1},{id:20,name:"Rajesh Khanna",role:"Stakes",roleId:6},{id:21,name:"Sonia Dutta",role:"Research & Development",roleId:5},{id:22,name:"Alok Gupta",role:"Human Resources",roleId:7},{id:23,name:"Preeti Singh",role:"Marketing",roleId:8},{id:24,name:"Anuj Kumar",role:"Customer Support",roleId:9},{id:25,name:"Deepa Patel",role:"IT Support",roleId:10},{id:26,name:"Vishal Kapoor",role:"Legal",roleId:11},{id:27,name:"Asha Singh",role:"Quality Assurance",roleId:12},{id:28,name:"Rajeev Sharma",role:"Logistics",roleId:13},{id:29,name:"Kavita Trivedi",role:"Public Relations",roleId:14},{id:30,name:"Alok Singh",role:"Training and Development",roleId:15},{id:31,name:"Pooja Kapoor",role:"Accountant & Finance",roleId:2},{id:32,name:"Rohit Verma",role:"Sales",roleId:4},{id:33,name:"Sanjay Mehta",role:"Operation",roleId:3},{id:34,name:"Nisha Khanna",role:"Maintenance",roleId:1},{id:35,name:"Varun Dutta",role:"Stakes",roleId:6},{id:36,name:"Sapna Gupta",role:"Research & Development",roleId:5},{id:37,name:"Vikas Sharma",role:"Human Resources",roleId:7},{id:38,name:"Ritu Verma",role:"Marketing",roleId:8},{id:39,name:"Manish Singh",role:"Customer Support",roleId:9},{id:40,name:"Neha Patel",role:"IT Support",roleId:10},{id:41,name:"Anil Kapoor",role:"Legal",roleId:11},{id:42,name:"Priya Dutta",role:"Quality Assurance",roleId:12},{id:43,name:"Rahul Sharma",role:"Logistics",roleId:13},{id:44,name:"Sneha Trivedi",role:"Public Relations",roleId:14},{id:45,name:"Anita Singh",role:"Training and Development",roleId:15},{id:46,name:"Amit Trivedi",role:"Accountant & Finance",roleId:2},{id:47,name:"Priyanka Sharma",role:"Sales",roleId:4},{id:48,name:"Rajat Verma",role:"Operation",roleId:3},{id:49,name:"Anu Khanna",role:"Maintenance",roleId:1},{id:50,name:"Sumit Dutta",role:"Stakes",roleId:6}];
2
+ //# sourceMappingURL=default-data-Dsjlvwev.js.map