import{__spreadArrays as n,__assign as r}from"../../../../node_modules/tslib/tslib.es6.js";import{useCallback as e}from"react";import{Transforms as t}from"../../../../node_modules/slate/dist/index.es.js";import{TableElementTypes as i}from"../TableTypes.js";var u=function(n,r,e){return void 0===e&&(e=0),new Array(n).fill(0).map((function(n,t){return{type:i.TableCell,children:[{text:""}],column:t+e,row:r}}))},o=function(n){var r=n.find((function(n){return n.type&&n.type===i.Table}));if(r){var e=r.children.find((function(n){return n.type===i.TableBody}));if(e)return e.children}return[]},c=function(n){var r=n.find((function(n){return n.type&&n.type===i.Table}));if(r){var e=r.children.find((function(n){return n.type===i.TableHead}));if(e)return e.children}return[]},l=function(n,r,e){return n.map((function(n){if(n.type&&n.type===i.Table){var t=n.children.map((function(n){return n.type===e?Object.assign({},n,{children:r}):n}));return Object.assign({},n,{children:t})}return n}))},a=function(n,r){return l(n,r,i.TableBody)},f=function(n,r){return l(n,r,i.TableHead)},d=function(n,e){return void 0===e&&(e=!1),n.map((function(n,t){return r(r({},n),{row:e?-1:t,children:n.children.map((function(n,i){return r(r({},n),{row:e?-1:t,column:i})}))})}))},p=function(e,t,o){var c=function(n,r){var e=u(r,n,0);return{type:i.TableRow,row:n,children:e}}(e,o);if(e===t.length)return n(t,[c]);var l=t.slice(0,e),a=t.slice(e).map((function(n){return r(r({},n),{row:n.row+1,children:n.children.map((function(n){return r(r({},n),{row:n.row+1})}))})}));return n(l,[c],a)},m=function(e,t,i){void 0===i&&(i=!1);var o=t.map((function(t,i){return r(r({},t),{children:n(t.children.slice(0,e+1),u(1,i,e+1),t.children.slice(e+1,t.children.length))})}));return d(o,i)},s=function(n,e,t){void 0===t&&(t=!1);var i=e.map((function(e,t){return r(r({},e),{children:e.children.filter((function(r){return r.column!==n}))})}));return d(i,t)};export default function(r){var i=r.updateTableData,u=r.tableData,l=r.editor,v=e((function(r,e){t.deselect(l);var c=n(u),f=o(u),d=p(r+1,f,e);i(a(c,d))}),[i,u,l]),h=e((function(r){t.deselect(l);var e=n(u),c=o(u),f=d(c.filter((function(n,e){return e!==r})));i(a(e,f))}),[i,u,l]);return{addRowAfter:v,addColumnAfter:e((function(r){t.deselect(l);var e=n(u),d=o(u),p=c(u),s=m(r,d),v=m(r,p,!0);i(f(a(e,s),v))}),[i,u,l]),removeRow:h,removeColumn:e((function(r){t.deselect(l);var e=n(u),d=o(u),p=c(u),m=s(r,p,!0),v=s(r,d);i(f(a(e,v),m))}),[i,u,l])}}
//# sourceMappingURL=useTableActions.js.map
