@univerjs-pro/sheets-pivot-ui 1.5.2 → 1.6.0
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.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +1 -1
- package/lib/index.js +1 -1
- package/lib/types/views/widgets/drawing.d.ts +2 -3
- package/lib/umd/index.js +1 -1
- package/package.json +19 -18
- package/lib/types/views/widgets/icons.d.ts +0 -5
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs-pro/engine-pivot"),require("@univerjs-pro/sheets-pivot"),require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/ui"),require("@univerjs/sheets-ui"),require("rxjs"),require("@univerjs/design"),require("@univerjs-pro/license"),require("@univerjs/engine-render"),require("react"),require("react/jsx-runtime"),require("@univerjs/engine-formula"),require("@univerjs/sheets-formula-ui"),require("@univerjs/docs"),require("@univerjs/docs-ui")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs-pro/engine-pivot`,`@univerjs-pro/sheets-pivot`,`@univerjs/core`,`@univerjs/sheets`,`@univerjs/ui`,`@univerjs/sheets-ui`,`rxjs`,`@univerjs/design`,`@univerjs-pro/license`,`@univerjs/engine-render`,`react`,`react/jsx-runtime`,`@univerjs/engine-formula`,`@univerjs/sheets-formula-ui`,`@univerjs/docs`,`@univerjs/docs-ui`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverProSheetsPivotUi={},e.UniverProEnginePivot,e.UniverProSheetsPivot,e.UniverCore,e.UniverSheets,e.UniverUi,e.UniverSheetsUi,e.rxjs,e.UniverDesign,e.UniverProLicense,e.UniverEngineRender,e.React,e.React,e.UniverEngineFormula,e.UniverSheetsFormulaUi,e.UniverDocs,e.UniverDocsUi))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let _=`UNIVER_SHEET_PIVOT_PANEL`,v=`UNIVER_SHEET_PIVOT_PANEL_ID`,y=`UNIVER_SHEET_PIVOT_FILTER_PANEL`,b=`UNIVER_SHEET_PIVOT_FILTER_PANEL_ID`,x=`UNIVER_SHEET_PIVOT_FIELD_SETTING`,S=`UNIVER_SHEET_PIVOT_FIELD_SETTING_ID`,C=`UNIVER_SHEET_PIVOT_FIELD_NUMFMT`,w=`UNIVER_SHEET_PIVOT_FIELD_NUMFMT_ID`,T=`UNIVER_SHEET_PIVOT_SHOW_DATA_AS_DIALOG`,E=`UNIVER_SHEET_PIVOT_VALUE_FILTER_DIALOG`,D=`UNIVER_SHEET_PIVOT_EXCEL_DATE_GROUP_DIALOG`,O=`UNIVER_SHEET_PIVOT_NUMBER_GROUP_DIALOG`,k=`UNIVER_SHEET_PIVOT_MANUAL_GROUP_DIALOG`,A=`univer.sheet.pivot-table-range-selector`,j=`UNIVER_SHEET_PIVOT_MOBILE_ACTION_PANEL`,M=`UNIVER_SHEET_PIVOT_MOBILE_ACTION_PANEL_ID`,N={type:r.CommandType.OPERATION,id:`sheet.operation.open-pivot-table-range-selector-panel`,async handler(e){let a=e.get(r.IUniverInstanceService),o=e.get(r.ICommandService),s=(0,i.getSheetCommandTarget)(a),c=e.get(r.LocaleService);if(!s)return!1;let{unitId:l,subUnitId:u,worksheet:d,workbook:f}=s,p=e.get(i.SheetsSelectionsService).getCurrentLastSelection(),m=(p==null?void 0:p.range)??{startRow:0,endRow:0,startColumn:0,endColumn:0,rangeType:r.RANGE_TYPE.NORMAL},h=await P(e,l,u,(0,i.isSingleCellSelection)(p)?(0,i.expandToContinuousRange)(m,{up:!0,left:!0,right:!0,down:!0},d):m,d.getName());if(!h)return!1;let g=f.getSheets().find(e=>e.getName()===h.sourceSheetName);if(!g)return!1;let _;if(h.positionType===n.PositionType.New)_={row:0,col:0,unitId:l,subUnitId:(0,r.generateRandomId)(),sheetName:f.generateNewSheetName(`${c.t(`sheets-pivot-ui.sheet`)}`)};else{if(!h.positionRange||!h.positionSheetName)return!1;let e=f.getSheets().find(e=>e.getName()===h.positionSheetName);if(!e)return!1;_={row:h.positionRange.startRow,col:h.positionRange.startColumn,unitId:l,subUnitId:e.getSheetId(),sheetName:e.getName()}}let v=(0,t.generateHexNumber)(8);return await o.executeCommand(n.AddPivotTableCommand.id,{pivotTableId:v,pivotTableConfig:{targetCellInfo:_,sourceRangeInfo:{range:h.sourceRange,unitId:l,sheetName:h.sourceSheetName,subUnitId:g.getSheetId()}},positionType:h.positionType})?{unitId:_.unitId,subUnitId:_.subUnitId,pivotTableId:v}:!1}};async function P(e,t,n,i,o){let s=e.get(a.IDialogService),c=e.get(r.LocaleService);return new Promise(e=>{let r,a={unitId:t,subUnitId:n,sourceRange:i,positionRange:null,sourceSheetName:o,positionSheetName:o,onConfirm:t=>{e(t),r==null||r.dispose()},onCancel:()=>{e(null),r==null||r.dispose()}};r=s.open({id:A,title:{title:c.t(`sheets-pivot-ui.dialog.source.insertPivotTable`)},draggable:!0,mask:!1,maskClosable:!1,children:{label:{name:A,props:a}},width:400,onClose:()=>{r.dispose()}})})}let F={type:r.CommandType.OPERATION,id:`sheet.operation.set-pivot-date-group`,async handler(e,t){if(!t)return!1;let i=I(e);return i?e.get(r.ICommandService).executeCommand(n.SetPivotDateGroupCommand.id,{unitId:i.unitId,subUnitId:i.subUnitId,pivotTableId:i.pivotTableId,tableFieldId:i.tableFieldId,dateType:t.dateType}):!1}};function I(e,a=t.PivotDateGroupingMode.Legacy){let o=e.get(r.IUniverInstanceService),s=(0,i.getSheetCommandTarget)(o);if(!s)return;let c=e.get(i.SheetsSelectionsService).getCurrentLastSelection(),l=c==null?void 0:c.primary;if(!l)return;let{unitId:u,subUnitId:d}=s,f=l.startRow,p=l.startColumn,m=e.get(n.SheetsPivotTableAdaptorModel).getPivotTableIdByCell(u,d,f,p);if(!m)return;let h=L(e,u,d,m,f,p);if(!h)return;let g=e.get(n.SheetsPivotTableConfigModel),_=g.getPivotTableConfig(u,d,m);if((0,t.getPivotDateGroupingMode)(_==null?void 0:_.fieldsConfig.options)!==a)return;let v=g.getCollection(u,m),y=(0,n.getPivotDateGroupContext)(_==null?void 0:_.fieldsConfig,v,h);if(y)return{unitId:u,subUnitId:d,pivotTableId:m,tableFieldId:h,row:f,col:p,dateGroupContext:y}}function L(e,t,r,i,a,o){let s=e.get(n.SheetsPivotTableAdaptorModel).getPivotItemRenderInfoCache(t,r,i);if(!s)return;let c=e.get(n.SheetsPivotTableAdaptorModel).getPivotTableCellData(t,r,a,o),l=(0,n.resolvePivotSheetCell)(a,o,c,s);return l==null?void 0:l.tableFieldId}function R(e){let r=I(e,t.PivotDateGroupingMode.ExcelLike);if(!r)return;let i=e.get(n.SheetsPivotTableConfigModel),a=i.getPivotTableConfig(r.unitId,r.subUnitId,r.pivotTableId),o=a==null?void 0:a.fieldsConfig.dimension[r.tableFieldId];if(!o)return;let s=i.getCollection(r.unitId,r.pivotTableId),c=(r.dateGroupContext.area===t.PivotTableFiledAreaEnum.Row?a.fieldsConfig.rowFields:a.fieldsConfig.columnFields).flatMap(e=>{let n=a.fieldsConfig.dimension[e],i=n?s==null?void 0:s.fields[n.dataFieldId]:void 0;return i&&(0,t.isDateGroupFieldJSON)(i)&&i.originalFieldId===r.dateGroupContext.originalDataFieldId&&i.excelLike?[i.excelLike]:[]}),l=c[0],u=l?{units:c.map(e=>e.unit),autoStart:l.autoStart,autoEnd:l.autoEnd,...l.start===void 0?{}:{start:l.start},...l.end===void 0?{}:{end:l.end},...l.daysInterval===void 0?{}:{daysInterval:l.daysInterval}}:void 0;return{...r,targetFieldName:o.displayName,grouping:u}}let z={id:`sheet.operation.set-pivot-excel-date-group`,type:r.CommandType.OPERATION,async handler(e){let t=R(e);if(!t)return!1;let i=e.get(n.SheetsPivotTableConfigModel),o=i.getPivotTableConfig(t.unitId,t.subUnitId,t.pivotTableId),s=i.getCollection(t.unitId,t.pivotTableId),c=e.get(a.IDialogService),l=e.get(r.LocaleService),u=e.get(r.IUniverInstanceService).getUnit(t.unitId),d=(u==null?void 0:u.getDateSystem())??r.DateSystem.Date1900,f=null,p=!1,m=!1,h=()=>{p||(p=!0,f==null||f.dispose(),f=null)},g=async a=>{if(!(m||p)){m=!0;try{let c=R(e);if(!c||c.unitId!==t.unitId||c.subUnitId!==t.subUnitId||c.pivotTableId!==t.pivotTableId||c.tableFieldId!==t.tableFieldId||i.getPivotTableConfig(t.unitId,t.subUnitId,t.pivotTableId)!==o||i.getCollection(t.unitId,t.pivotTableId)!==s)return;await e.get(r.ICommandService).executeCommand(n.SetPivotExcelDateGroupCommand.id,{unitId:t.unitId,subUnitId:t.subUnitId,pivotTableId:t.pivotTableId,tableFieldId:t.tableFieldId,grouping:{...a,units:a.units.concat()}})}catch{}finally{h()}}};try{f=c.open({id:`UNIVER_SHEET_PIVOT_EXCEL_DATE_GROUP_DIALOG_ID`,title:{title:l.t(`sheets-pivot-ui.dateGroup.excelLikeTitle`)},draggable:!0,mask:!0,maskClosable:!1,width:440,children:{label:{name:D,props:{targetFieldName:t.targetFieldName,dateSystem:d,grouping:t.grouping,onConfirm:g,onCancel:h}}},onClose:h})}catch{return h(),!1}return!0}};function B(e){return e.map(e=>({...e,members:e.members.map(e=>({...e}))}))}function V(e){let n;try{n=JSON.parse(e)}catch{return}if(!(!Array.isArray(n)||n.length<1||typeof n[0]!=`string`))return n[0]===r.RecordValueType.Blank?t.GlobalConfig.BLANK_PLACEHOLDER:String(n[1])}function ee(e,a){var o;let s=()=>({error:`invalidSelection`}),c=(0,i.getSheetCommandTarget)(e.get(r.IUniverInstanceService)),l=e.get(i.SheetsSelectionsService).getCurrentSelections();if(!c||!l.length)return s();let{unitId:u,subUnitId:d}=c,f=l[0].primary;if(!f)return s();let p=e.get(n.SheetsPivotTableAdaptorModel),m=p.getPivotTableIdByCell(u,d,f.startRow,f.startColumn),h=e.get(n.SheetsPivotTableConfigModel),g=m&&h.getPivotTableConfig(u,d,m),_=m&&h.getCollection(u,m),v=m&&p.getPivotItemRenderInfoCache(u,d,m);if(!m||!g||!_||!v)return s();let y=(0,n.resolvePivotSheetCell)(f.startRow,f.startColumn,p.getPivotTableCellData(u,d,f.startRow,f.startColumn),v),b=y==null?void 0:y.tableFieldId,x=b&&g.fieldsConfig.dimension[b];if(!b||!x||!(g.fieldsConfig.rowFields.includes(b)||g.fieldsConfig.columnFields.includes(b)))return s();let S=_.fields[x.dataFieldId];if(!S)return s();let C=S.dataFieldType===t.PivotDataFieldTypeEnum.textGroupField?S:void 0;if(!C&&S.dataFieldType!==t.PivotDataFieldTypeEnum.defaultNormalField)return s();let w=(C==null?void 0:C.originalFieldId)??S.id;if(((o=_.fields[w])==null?void 0:o.dataFieldType)!==t.PivotDataFieldTypeEnum.defaultNormalField)return s();let T=B((C==null?void 0:C.grouping.groups)??[]),E=/* @__PURE__ */ new Map,D=/* @__PURE__ */ new Set,O=0;for(let e of l){let{startRow:r,endRow:i,startColumn:a,endColumn:o}=e.range;if(O+=(i-r+1)*(o-a+1),O>512)return s();for(let e=r;e<=i;e++)for(let r=a;r<=o;r++){if(p.getPivotTableIdByCell(u,d,e,r)!==m)return s();let i=(0,n.resolvePivotSheetCell)(e,r,p.getPivotTableCellData(u,d,e,r),v),a=i==null?void 0:i.info;if(!i||i.area!==`rowRanges`&&i.area!==`colRanges`||i.tableFieldId!==b||!a||a.isValue||a.isSubtotal||a.isBottomTotal||a.isTopTotal||a.rowType&&a.rowType!==`item`||a.level<1)return s();let o=a.paths[a.level-1];if(o===void 0)return s();if(C){let e;try{e=JSON.parse(o)}catch{return s()}if(!Array.isArray(e)||e.length!==2||typeof e[1]!=`string`)return s();if(e[0]===`group`){if(!T.some(t=>t.id===e[1]))return s();D.add(e[1]);continue}if(e[0]!==`member`)return s();let t=V(e[1]);if(t===void 0)return s();E.set(e[1],{path:t,memberKey:e[1]})}else{var k;let n=(k=p.getPivotTableCellData(u,d,e,r))==null?void 0:k.v,i=n==null||n===``?t.GlobalConfig.BLANK_PLACEHOLDER:String(n);E.set(o,{path:i,tupleKey:o})}}}return a===`group`&&(E.size<2||D.size>0)||a!==`group`&&(E.size>0||D.size!==1)?s():{context:{unitId:u,subUnitId:d,pivotTableId:m,tableFieldId:b,sourceFieldId:w,targetFieldName:x.displayName,groups:T,memberPaths:Array.from(E.values()),selectedGroupId:Array.from(D)[0]}}}function H(e,t){return ee(e,t).context}function te(e,t){e.get(a.IMessageService).show({type:c.MessageType.Error,content:e.get(r.LocaleService).t(`sheets-pivot-ui.manualGroup.${t}`)})}function ne(e,t,n){let r=H(e,t);return!!r&&r.unitId===n.unitId&&r.subUnitId===n.subUnitId&&r.pivotTableId===n.pivotTableId&&r.tableFieldId===n.tableFieldId&&r.sourceFieldId===n.sourceFieldId&&r.selectedGroupId===n.selectedGroupId&&JSON.stringify(r.memberPaths)===JSON.stringify(n.memberPaths)&&JSON.stringify(r.groups)===JSON.stringify(n.groups)}async function re(e,t){let i=ee(e,t),o=i.context;if(!o)return te(e,i.error),!1;let s=e.get(n.SheetsPivotTableConfigModel),c=s.getPivotTableConfig(o.unitId,o.subUnitId,o.pivotTableId),l=s.getCollection(o.unitId,o.pivotTableId),u=[];if(t===`group`){try{let t=(await e.get(n.SheetsPivotRPCService).getPivotDisplayConfig({unitId:o.unitId,subUnitId:o.subUnitId,pivotTableId:o.pivotTableId,params:{type:n.PivotDisplayDataType.ManualGroupMembers,manualGroupMembers:{sourceFieldId:o.sourceFieldId,paths:o.memberPaths}}})).result.manualGroupMembers;if(!t||t.error||t.members.length<2)return te(e,(t==null?void 0:t.error)??`invalidSelection`),!1;u=t.members}catch{return te(e,`invalidSelection`),!1}if(!ne(e,t,o)||s.getPivotTableConfig(o.unitId,o.subUnitId,o.pivotTableId)!==c||s.getCollection(o.unitId,o.pivotTableId)!==l)return!1}let d=e.get(a.IDialogService),f=e.get(r.LocaleService),p=o.groups.find(e=>e.id===o.selectedGroupId),m=(p==null?void 0:p.name)??f.t(`sheets-pivot-ui.manualGroup.defaultName`,String(o.groups.length+1));if(!p){let e=o.groups.length+1;for(;o.groups.some(e=>e.name===m);)e++,m=f.t(`sheets-pivot-ui.manualGroup.defaultName`,String(e))}let h=null,g=!1,_=!1,v=()=>{g||(g=!0,h==null||h.dispose(),h=null)},y=async i=>{if(_||g)return;let a=i.trim();if(!a||o.groups.some(e=>e.name===a&&e.id!==o.selectedGroupId))te(e,`invalidSelection`);else{_=!0;try{if(!ne(e,t,o)||s.getPivotTableConfig(o.unitId,o.subUnitId,o.pivotTableId)!==c||s.getCollection(o.unitId,o.pivotTableId)!==l)return;let i=t===`group`?o.groups.concat({id:(0,r.generateRandomId)(),name:a,members:u.map(e=>({...e}))}):o.groups.map(e=>e.id===o.selectedGroupId?{...e,name:a}:e);await e.get(r.ICommandService).executeCommand(n.SetPivotManualGroupsCommand.id,{unitId:o.unitId,subUnitId:o.subUnitId,pivotTableId:o.pivotTableId,sourceFieldId:o.sourceFieldId,groups:i})}catch{}finally{v()}}};try{h=d.open({id:`UNIVER_SHEET_PIVOT_MANUAL_GROUP_DIALOG_ID`,title:{title:f.t(t===`group`?`sheets-pivot-ui.manualGroup.groupTitle`:`sheets-pivot-ui.manualGroup.renameTitle`)},draggable:!0,mask:!0,maskClosable:!1,width:400,children:{label:{name:k,props:{name:m,onConfirm:y,onCancel:v}}},onClose:v})}catch{return v(),!1}return!0}let ie={id:`sheet.operation.set-pivot-manual-group`,type:r.CommandType.OPERATION,handler:e=>re(e,`group`)},ae={id:`sheet.operation.rename-pivot-manual-group`,type:r.CommandType.OPERATION,handler:e=>re(e,`rename`)},oe={id:`sheet.operation.ungroup-pivot-manual-group`,type:r.CommandType.OPERATION,async handler(e){let t=ee(e,`ungroup`),i=t.context;if(!i)return te(e,t.error),!1;let a=e.get(n.SheetsPivotTableConfigModel),o=a.getPivotTableConfig(i.unitId,i.subUnitId,i.pivotTableId),s=a.getCollection(i.unitId,i.pivotTableId);return!ne(e,`ungroup`,i)||a.getPivotTableConfig(i.unitId,i.subUnitId,i.pivotTableId)!==o||a.getCollection(i.unitId,i.pivotTableId)!==s?!1:e.get(r.ICommandService).executeCommand(n.SetPivotManualGroupsCommand.id,{unitId:i.unitId,subUnitId:i.subUnitId,pivotTableId:i.pivotTableId,sourceFieldId:i.sourceFieldId,groups:i.groups.filter(e=>e.id!==i.selectedGroupId)})}};function se(e){return typeof e.autoStart==`boolean`&&typeof e.autoEnd==`boolean`&&Number.isFinite(e.interval)&&e.interval>0&&(e.start===void 0||Number.isFinite(e.start))&&(e.end===void 0||Number.isFinite(e.end))&&(e.autoStart||e.start!==void 0)&&(e.autoEnd||e.end!==void 0)&&(e.start===void 0||e.end===void 0||e.start<=e.end)}function ce(e,n){if(e.dataFieldType===t.PivotDataFieldTypeEnum.numberGroupField){let r=e,i=n.fields[r.originalFieldId];return!i||i.dataFieldType!==t.PivotDataFieldTypeEnum.defaultNormalField||i.fieldDataType!==t.PivotDataFieldDataTypeEnum.number?void 0:{sourceFieldId:r.originalFieldId,grouping:{...r.grouping}}}if(e.dataFieldType===t.PivotDataFieldTypeEnum.defaultNormalField&&e.fieldDataType===t.PivotDataFieldDataTypeEnum.number)return{sourceFieldId:e.id}}function le(e){var t;let a=(0,i.getSheetCommandTarget)(e.get(r.IUniverInstanceService)),o=(t=e.get(i.SheetsSelectionsService).getCurrentLastSelection())==null?void 0:t.primary;if(!a||!o)return;let{unitId:s,subUnitId:c}=a,l=o.startRow,u=o.startColumn,d=e.get(n.SheetsPivotTableAdaptorModel),f=d.getPivotTableIdByCell(s,c,l,u);if(!f)return;let p=d.getPivotItemRenderInfoCache(s,c,f);if(!p)return;let m=(0,n.resolvePivotSheetCell)(l,u,d.getPivotTableCellData(s,c,l,u),p),h=m==null?void 0:m.tableFieldId;if(!h||m.area!==`rowRanges`&&m.area!==`colRanges`)return;let g=e.get(n.SheetsPivotTableConfigModel),_=g.getPivotTableConfig(s,c,f),v=g.getCollection(s,f),y=_==null?void 0:_.fieldsConfig.dimension[h];if(!y||!v||!(_.fieldsConfig.rowFields.includes(h)||_.fieldsConfig.columnFields.includes(h)))return;let b=v.fields[y.dataFieldId];if(!b)return;let x=ce(b,v);if(x)return{unitId:s,subUnitId:c,pivotTableId:f,tableFieldId:h,targetFieldName:y.displayName,...x}}let ue={id:`sheet.operation.set-pivot-number-group`,type:r.CommandType.OPERATION,async handler(e){let t=le(e);if(!t)return!1;let i=e.get(n.SheetsPivotTableConfigModel),o=i.getCollection(t.unitId,t.pivotTableId),c=i.getPivotTableConfig(t.unitId,t.subUnitId,t.pivotTableId),l=e.get(r.IUniverInstanceService),u=()=>{let n=le(e);return!!n&&n.unitId===t.unitId&&n.subUnitId===t.subUnitId&&n.pivotTableId===t.pivotTableId&&n.tableFieldId===t.tableFieldId&&n.sourceFieldId===t.sourceFieldId&&JSON.stringify(n.grouping)===JSON.stringify(t.grouping)},d=e.get(a.IDialogService),f=e.get(r.LocaleService),p=null,m=!1,h=!1,g=new s.Subject,_=async()=>{if(!m&&u())try{let r=(await e.get(n.SheetsPivotRPCService).getPivotDisplayConfig({unitId:t.unitId,subUnitId:t.subUnitId,pivotTableId:t.pivotTableId,params:{type:n.PivotDisplayDataType.NumberGroupDefaults,numberGroupDefaults:{tableFieldId:t.tableFieldId}}})).result.numberGroupDefaults;return!m&&u()&&r&&se(r)?r:void 0}catch{return}},v=()=>{m||(m=!0,g.next(),g.complete(),p==null||p.dispose(),p=null)},y=await _();if(!y)return v(),!1;let b=l.unitDisposed$.pipe((0,s.filter)(e=>e.getUnitId()===t.unitId),(0,s.tap)(v)),x=(0,s.defer)(()=>{if(m||!l.getUnit(t.unitId))return v(),s.EMPTY;let e=i.watchPivotTableChanges(t.unitId,t.subUnitId,t.pivotTableId).pipe((0,s.debounceTime)(0),(0,s.map)(()=>void 0));return(0,s.merge)((0,s.of)(y),e).pipe((0,s.switchMap)(e=>e&&i.getCollection(t.unitId,t.pivotTableId)===o&&i.getPivotTableConfig(t.unitId,t.subUnitId,t.pivotTableId)===c?(0,s.of)(e):(0,s.concat)((0,s.of)(void 0),_())),(0,s.takeUntil)((0,s.merge)(g,b)))}),S=async i=>{if(!(h||m)){h=!0;try{if(!se(i)||!u())return;await e.get(r.ICommandService).executeCommand(n.SetPivotNumberGroupCommand.id,{unitId:t.unitId,subUnitId:t.subUnitId,pivotTableId:t.pivotTableId,tableFieldId:t.tableFieldId,grouping:{...i}})}catch{}finally{v()}}};try{p=d.open({id:`UNIVER_SHEET_PIVOT_NUMBER_GROUP_DIALOG_ID`,title:{title:f.t(`sheets-pivot-ui.numberGroup.title`)},draggable:!0,mask:!0,maskClosable:!1,width:400,children:{label:{name:O,props:{targetFieldName:t.targetFieldName,grouping:t.grouping,defaults$:x,onConfirm:S,onCancel:v}}},onClose:v})}catch{return v(),!1}return!0}},de=[{type:t.PivotShowAsTypeEnum.normal,localeKey:`sheets-pivot-ui.showValuesAs.normal`,requiresParameters:!1,baseItemMode:`none`},{type:t.PivotShowAsTypeEnum.percentOfGrandTotal,localeKey:`sheets-pivot-ui.showValuesAs.percentOfGrandTotal`,requiresParameters:!1,baseItemMode:`none`},{type:t.PivotShowAsTypeEnum.percentOfRowTotal,localeKey:`sheets-pivot-ui.showValuesAs.percentOfRowTotal`,requiresParameters:!1,baseItemMode:`none`},{type:t.PivotShowAsTypeEnum.percentOfColumnTotal,localeKey:`sheets-pivot-ui.showValuesAs.percentOfColumnTotal`,requiresParameters:!1,baseItemMode:`none`},{type:t.PivotShowAsTypeEnum.percentOfParentRowTotal,localeKey:`sheets-pivot-ui.showValuesAs.percentOfParentRowTotal`,requiresParameters:!1,baseItemMode:`none`},{type:t.PivotShowAsTypeEnum.percentOfParentColumnTotal,localeKey:`sheets-pivot-ui.showValuesAs.percentOfParentColumnTotal`,requiresParameters:!1,baseItemMode:`none`},{type:t.PivotShowAsTypeEnum.index,localeKey:`sheets-pivot-ui.showValuesAs.index`,requiresParameters:!1,baseItemMode:`none`},{type:t.PivotShowAsTypeEnum.percentOfParent,localeKey:`sheets-pivot-ui.showValuesAs.percentOfParent`,requiresParameters:!0,baseItemMode:`none`,parentFieldOnly:!0},{type:t.PivotShowAsTypeEnum.percentOf,localeKey:`sheets-pivot-ui.showValuesAs.percentOf`,requiresParameters:!0,baseItemMode:`item`},{type:t.PivotShowAsTypeEnum.differenceFrom,localeKey:`sheets-pivot-ui.showValuesAs.differenceFrom`,requiresParameters:!0,baseItemMode:`item-or-relative`},{type:t.PivotShowAsTypeEnum.percentDifferenceFrom,localeKey:`sheets-pivot-ui.showValuesAs.percentDifferenceFrom`,requiresParameters:!0,baseItemMode:`item-or-relative`},{type:t.PivotShowAsTypeEnum.runningTotal,localeKey:`sheets-pivot-ui.showValuesAs.runningTotal`,requiresParameters:!0,baseItemMode:`none`},{type:t.PivotShowAsTypeEnum.percentRunningTotal,localeKey:`sheets-pivot-ui.showValuesAs.percentRunningTotal`,requiresParameters:!0,baseItemMode:`none`},{type:t.PivotShowAsTypeEnum.rankAscending,localeKey:`sheets-pivot-ui.showValuesAs.rankAscending`,requiresParameters:!0,baseItemMode:`none`},{type:t.PivotShowAsTypeEnum.rankDescending,localeKey:`sheets-pivot-ui.showValuesAs.rankDescending`,requiresParameters:!0,baseItemMode:`none`}],fe={type:r.CommandType.OPERATION,id:`sheet.operation.set-pivot-show-data-as`,async handler(e,t){let i=t&&de.find(e=>e.type===t.type);if(!i)return!1;let o=me(e);if(!o)return!1;if(!i.requiresParameters)return e.get(r.ICommandService).executeCommand(n.UpdatePivotFieldSettingCommand.id,{unitId:o.unitId,subUnitId:o.subUnitId,pivotTableId:o.pivotTableId,tableFieldId:o.tableFieldId,showDataAs:{type:i.type,baseFieldId:``,baseItem:``},tableFieldInfo:o.tableFieldInfo,dataFieldInfo:o.dataFieldInfo});let s=he(e,o);if(!s)return!1;let c=pe(s.config,s.collection,i);if(c.length===0)return!1;let l={};if(i.baseItemMode!==`none`){try{l=await ge(e,s.config,o.pivotTableId,c)}catch{return!1}if(!c.some(e=>l[e]&&(i.baseItemMode===`item-or-relative`||l[e].items.length>0)))return!1}let u=e.get(a.IDialogService),d=e.get(r.LocaleService),f=null,p=!1,m=!1,h=()=>{p||(p=!0,f==null||f.dispose(),f=null)};try{f=u.open({id:`UNIVER_SHEET_PIVOT_SHOW_DATA_AS_DIALOG_ID`,title:{title:d.t(`sheets-pivot-ui.showValuesAs.dialogTitle`)},draggable:!0,mask:!0,maskClosable:!1,width:400,children:{label:{name:T,props:{unitId:o.unitId,subUnitId:o.subUnitId,pivotTableId:o.pivotTableId,tableFieldId:o.tableFieldId,type:i.type,baseItems:l,onCancel:h,onConfirm:async t=>{if(!m){m=!0;try{let s=he(e,o);if(!s||!_e(s.config,s.collection,i,t))return;if(i.baseItemMode!==`none`&&t.baseItemType===void 0){var a;if(!((a=(await ge(e,s.config,s.context.pivotTableId,[t.baseFieldId]))[t.baseFieldId])!=null&&a.items.includes(t.baseItem)))return}await e.get(r.ICommandService).executeCommand(n.UpdatePivotFieldSettingCommand.id,{unitId:s.context.unitId,subUnitId:s.context.subUnitId,pivotTableId:s.context.pivotTableId,tableFieldId:s.context.tableFieldId,showDataAs:t,tableFieldInfo:s.context.tableFieldInfo,dataFieldInfo:s.context.dataFieldInfo})}catch{}finally{h()}}}}}},onClose:h})}catch{return h(),!1}return!0}};function pe(e,t,n){let{rowFields:r,columnFields:i,dimension:a}=e.fieldsConfig;return(n.parentFieldOnly?[...r.slice(0,-1),...i.slice(0,-1)]:[...r,...i]).filter(e=>{let n=a[e];return!!(n&&(t.fields[n.dataFieldId]||t.customFields.find(e=>e.id===n.dataFieldId)))})}function me(e){var t,a;let o=(0,i.getSheetCommandTarget)(e.get(r.IUniverInstanceService)),s=(t=e.get(i.SheetsSelectionsService).getCurrentLastSelection())==null?void 0:t.primary;if(!o||!s)return;let{unitId:c,subUnitId:l}=o,u=s.startRow,d=s.startColumn,f=e.get(n.SheetsPivotTableAdaptorModel),p=f.getPivotTableIdByCell(c,l,u,d);if(!p)return;let m=e.get(n.SheetsPivotTableConfigModel).getPivotTableConfig(c,l,p),h=f.getPivotItemRenderInfoCache(c,l,p),g=f.getPivotTableCellData(c,l,u,d);if(!m||!h)return;let _=(0,n.resolvePivotSheetCell)(u,d,g,h);if(!_)return;let v=(0,n.resolvePivotValueFieldId)(_,m.fieldsConfig.valueFields);if(v)return(a=he(e,{unitId:c,subUnitId:l,pivotTableId:p,tableFieldId:v}))==null?void 0:a.context}function he(e,t){let{unitId:r,subUnitId:i,pivotTableId:a,tableFieldId:o}=t,s=e.get(n.SheetsPivotTableConfigModel),c=s.getPivotTableConfig(r,i,a),l=s.getCollection(r,a),u=c==null?void 0:c.fieldsConfig.measure[o];if(!c||!l||!u||!c.fieldsConfig.valueFields.includes(u.id))return;let d=l.fields[u.dataFieldId]??l.customFields.find(e=>e.id===u.dataFieldId);if(!d)return;let f={...u.showDataAs};return{config:c,collection:l,context:{unitId:r,subUnitId:i,pivotTableId:a,tableFieldId:u.id,currentShowDataAs:f,tableFieldInfo:{tableFieldId:u.id,displayName:u.displayName,dataFieldId:u.dataFieldId,format:u.format,subTotalType:u.subtotal,showDataAs:{...f}},dataFieldInfo:{id:d.id,dataFieldId:d.id,name:d.name,type:d.fieldDataType,checked:!0,pivotTableId:a}}}}async function ge(e,t,r,i){let{unitId:a,subUnitId:o}=t.targetCellInfo,s=t.targetCellInfo,c=e.get(n.SheetsPivotTableAdaptorModel).getPivotItemRenderInfoCache(a,o,r);if(!c)throw Error(`[sheets-pivot-ui]: Pivot render cache is unavailable`);return(await Promise.all(i.map(async t=>{try{return[t,(await e.get(n.SheetsPivotRPCService).getPivotDisplayConfig({unitId:a,subUnitId:o,pivotTableId:r,params:{type:n.PivotDisplayDataType.Filter,filter:{row:s.row,col:s.col,tableFieldId:t,pivotItemRenderInfoCache:c}}})).result.filter]}catch{return[t,void 0]}}))).reduce((e,[t,n])=>(n&&(e[t]={items:n.items,itemTypes:n.itemTypes,...n.itemLabels?{itemLabels:n.itemLabels}:{},format:n.format}),e),{})}function _e(e,n,r,i){return i.type!==r.type||!pe(e,n,r).includes(i.baseFieldId)?!1:r.baseItemMode===`none`?i.baseItem===``&&i.baseItemType===void 0:i.baseItemType===void 0?i.baseItem!==``:r.baseItemMode===`item-or-relative`&&i.baseItem===``&&(i.baseItemType===t.PivotShowAsBaseItemTypeEnum.previous||i.baseItemType===t.PivotShowAsBaseItemTypeEnum.next)}function ve(e){return{...e,expected:Array.isArray(e.expected)?e.expected.concat():e.expected}}function ye(e,t){let r=e.get(n.SheetsPivotTableConfigModel).getPivotTableConfig(t.unitId,t.subUnitId,t.pivotTableId);if(r&&r.fieldsConfig.dimension[t.targetFieldId]&&(r.fieldsConfig.rowFields.includes(t.targetFieldId)||r.fieldsConfig.columnFields.includes(t.targetFieldId)))return r}function be(e){var t,a;let o=(0,i.getSheetCommandTarget)(e.get(r.IUniverInstanceService)),s=(t=e.get(i.SheetsSelectionsService).getCurrentLastSelection())==null?void 0:t.primary;if(!o||!s)return;let{unitId:c,subUnitId:l}=o,u=s.startRow,d=s.startColumn,f=e.get(n.SheetsPivotTableAdaptorModel),p=f.getPivotTableIdByCell(c,l,u,d);if(!p)return;let m=e.get(n.SheetsPivotTableConfigModel).getPivotTableConfig(c,l,p),h=f.getPivotItemRenderInfoCache(c,l,p);if(!m||!h)return;let g=(0,n.resolvePivotSheetCell)(u,d,f.getPivotTableCellData(c,l,u,d),h),_=g&&(0,n.resolvePivotValueFilterTarget)(g,m.fieldsConfig);if(!_)return;let v=m.fieldsConfig.dimension[_.targetFieldId],y=m.fieldsConfig.valueFields.flatMap(e=>{let t=m.fieldsConfig.measure[e];return t?[{id:t.id,label:t.displayName}]:[]});if(!v||y.length===0)return;let b=(a=m.fieldsConfig.valueFilter)==null||(a=a.find(e=>e.fieldId===_.targetFieldId))==null?void 0:a.filterInfo;return{unitId:c,subUnitId:l,pivotTableId:p,targetFieldId:_.targetFieldId,targetFieldName:v.displayName,valueFields:y,defaultValueFieldId:_.defaultValueFieldId,...b?{currentFilter:ve(b)}:{}}}let xe={type:r.CommandType.OPERATION,id:`sheet.operation.set-pivot-value-filter`,async handler(e){let i=be(e);if(!i)return!1;let o=e.get(a.IDialogService),s=e.get(r.LocaleService),c=null,l=!1,u=!1,d=()=>{l||(l=!0,c==null||c.dispose(),c=null)},f=async a=>{if(!u){u=!0;try{let o=ye(e,i);if(!o||a&&(!o.fieldsConfig.measure[a.valueFieldId]||!o.fieldsConfig.valueFields.includes(a.valueFieldId)||!(0,t.isValueFilterOperator)(a.operator)))return;await e.get(r.ICommandService).executeCommand(n.SetPivotValueFilterCommand.id,{unitId:i.unitId,subUnitId:i.subUnitId,pivotTableId:i.pivotTableId,fieldId:i.targetFieldId,valueFilterInfo:a?{...a,type:t.PivotFilterTypeEnum.ValueFilter,expected:Array.isArray(a.expected)?a.expected.concat():a.expected}:void 0})}catch{}finally{d()}}};try{c=o.open({id:`UNIVER_SHEET_PIVOT_VALUE_FILTER_DIALOG_ID`,title:{title:s.t(`sheets-pivot-ui.valueFilter.dialogTitle`)},draggable:!0,mask:!0,maskClosable:!1,width:420,children:{label:{name:E,props:{targetFieldId:i.targetFieldId,targetFieldName:i.targetFieldName,valueFields:i.valueFields,defaultValueFieldId:i.defaultValueFieldId,currentFilter:i.currentFilter,onConfirm:e=>f(e),onClear:()=>f(void 0),onCancel:d}}},onClose:d})}catch{return d(),!1}return!0}},Se=`sheet.pivot.context-menu.date-group`,Ce=`sheet.pivot.context-menu.excel-date-group`,we=`sheet.pivot.context-menu.number-group`,Te=`sheet.pivot.context-menu.manual-group`,Ee=`sheet.pivot.context-menu.manual-rename`,De=`sheet.pivot.context-menu.manual-ungroup`,Oe=`sheet.pivot.context-menu.show-data-as`,ke=`sheet.pivot.context-menu.value-filter`,Ae={year:`sheets-pivot-ui.dateGroup.year`,"year-quarter":`sheets-pivot-ui.dateGroup.yearQuarter`,quarter:`sheets-pivot-ui.dateGroup.quarter`,"year-month":`sheets-pivot-ui.dateGroup.yearMonth`,month:`sheets-pivot-ui.dateGroup.month`,"month-date":`sheets-pivot-ui.dateGroup.monthDate`,"year-month-date":`sheets-pivot-ui.dateGroup.yearMonthDate`,date:`sheets-pivot-ui.dateGroup.date`,hour:`sheets-pivot-ui.dateGroup.hour`,minute:`sheets-pivot-ui.dateGroup.minute`,"hour-minute":`sheets-pivot-ui.dateGroup.hourMinute`};function je(e){return{id:N.id,type:a.MenuItemType.BUTTON,icon:`PivotTableIcon`,hidden$:(0,a.getMenuHiddenObservable)(e,r.UniverInstanceType.UNIVER_SHEET),disabled$:(0,o.getObservableWithExclusiveRange$)(e,(0,o.getCurrentRangeDisable$)(e,{workbookTypes:[i.WorkbookEditablePermission],worksheetTypes:[i.WorksheetViewPermission,i.WorksheetPivotTablePermission],rangeTypes:[i.RangeProtectionPermissionViewPoint]})),tooltip:`sheets-pivot-ui.title`,title:`sheets-pivot-ui.title`}}function Me(e){return{id:Se,type:a.MenuItemType.SUBITEMS,title:`sheets-pivot-ui.dateGroup.title`,hidden$:Be(e)}}function Ne(e){return{id:Ce,commandId:z.id,type:a.MenuItemType.BUTTON,title:`sheets-pivot-ui.dateGroup.excelLikeTitle`,hidden$:U(e).pipe((0,s.map)(()=>!R(e)))}}function Pe(e){return{id:we,commandId:ue.id,type:a.MenuItemType.BUTTON,title:`sheets-pivot-ui.numberGroup.title`,hidden$:U(e).pipe((0,s.map)(()=>!le(e)))}}function Fe(e){return{id:Te,commandId:ie.id,type:a.MenuItemType.BUTTON,title:`sheets-pivot-ui.manualGroup.groupTitle`,hidden$:U(e).pipe((0,s.map)(()=>!H(e,`group`)))}}function Ie(e){return{id:Ee,commandId:ae.id,type:a.MenuItemType.BUTTON,title:`sheets-pivot-ui.manualGroup.renameTitle`,hidden$:U(e).pipe((0,s.map)(()=>!H(e,`rename`)))}}function Le(e){return{id:De,commandId:oe.id,type:a.MenuItemType.BUTTON,title:`sheets-pivot-ui.manualGroup.ungroupTitle`,hidden$:U(e).pipe((0,s.map)(()=>!H(e,`ungroup`)))}}function Re(e){return t=>({id:ze(e),commandId:F.id,type:a.MenuItemType.BUTTON,title:Ae[e],params:{dateType:e},disabled$:Ve(t,e),activated$:He(t,e)})}function ze(e){return`sheet.pivot.context-menu.date-group.${e}`}function Be(e){return U(e).pipe((0,s.map)(()=>!I(e)))}function Ve(e,t){return U(e).pipe((0,s.map)(()=>{let r=I(e);return!r||(0,n.isPivotDateGroupTypeDisabled)(r.dateGroupContext,t)}))}function He(e,t){return U(e).pipe((0,s.map)(()=>{let n=I(e);return(n==null?void 0:n.dateGroupContext.currentDateType)===t}))}function U(e){let t=e.get(n.SheetsPivotTableConfigModel),a=()=>{var t;let a=(0,i.getSheetCommandTarget)(e.get(r.IUniverInstanceService)),o=(t=e.get(i.SheetsSelectionsService).getCurrentLastSelection())==null?void 0:t.primary;if(!a||!o)return;let{unitId:s,subUnitId:c}=a,l=e.get(n.SheetsPivotTableAdaptorModel).getPivotTableIdByCell(s,c,o.startRow,o.startColumn);return l?{unitId:s,subUnitId:c,pivotTableId:l}:void 0};return(0,s.merge)(e.get(i.SheetsSelectionsService).selectionMoveEnd$,t.pivotConfigChange$.pipe((0,s.filter)(e=>{let t=a();return(t==null?void 0:t.unitId)===e.unitId&&t.subUnitId===e.subUnitId&&t.pivotTableId===e.pivotTableId})),t.collectionChange$.pipe((0,s.filter)(e=>{let n=a();if(!n||!e.pivotTableIds.includes(n.pivotTableId))return!1;let r=t.getPivotTableConfig(n.unitId,n.subUnitId,n.pivotTableId);return e.unitId===((r==null?void 0:r.sourceRangeInfo.unitId)??n.unitId)}))).pipe((0,s.startWith)(null))}let Ue=n.PIVOT_DATE_GROUP_TYPES.map(e=>({dateType:e,id:ze(e),menuItemFactory:Re(e)}));function We(e){return{id:Oe,type:a.MenuItemType.SUBITEMS,title:`sheets-pivot-ui.showValuesAs.title`,hidden$:qe(e).pipe((0,s.map)(()=>!me(e)))}}function Ge(e){return n=>({id:Ke(e.type),commandId:fe.id,type:a.MenuItemType.BUTTON,title:e.localeKey,params:{type:e.type},activated$:qe(n).pipe((0,s.map)(()=>{let r=me(n);return!!(r&&(r.currentShowDataAs.type??t.PivotShowAsTypeEnum.normal)===e.type)}))})}function Ke(e){return`sheet.pivot.context-menu.show-data-as.${e}`}function qe(e){return e.get(i.SheetsSelectionsService).selectionMoveEnd$.pipe((0,s.startWith)(null))}let Je=de.map(e=>({rule:e,id:Ke(e.type),menuItemFactory:Ge(e)}));function Ye(e){return{id:ke,commandId:xe.id,type:a.MenuItemType.BUTTON,title:`sheets-pivot-ui.valueFilter.title`,hidden$:e.get(i.SheetsSelectionsService).selectionMoveEnd$.pipe((0,s.startWith)(null),(0,s.map)(()=>!be(e)))}}let Xe=Ue.reduce((e,t,n)=>(e[t.id]={order:n+1,menuItemFactory:t.menuItemFactory},e),{}),Ze=Je.reduce((e,t,n)=>(e[t.id]={order:n+1,menuItemFactory:t.menuItemFactory},e),{}),Qe={[a.RibbonDataGroup.ORGANIZATION]:{[N.id]:{order:1,gridLayout:{row:2,column:1},menuItemFactory:je}},[a.ContextMenuPosition.MAIN_AREA]:{[a.ContextMenuGroup.DATA]:{[N.id]:{order:1,menuItemFactory:je},[Se]:{order:2,menuItemFactory:Me,...Xe},[Ce]:{order:3,menuItemFactory:Ne},[we]:{order:4,menuItemFactory:Pe},[Te]:{order:5,menuItemFactory:Fe},[Ee]:{order:6,menuItemFactory:Ie},[De]:{order:7,menuItemFactory:Le},[Oe]:{order:8,menuItemFactory:We,...Ze},[ke]:{order:9,menuItemFactory:Ye}}},[a.ContextMenuPosition.COL_HEADER]:{[a.ContextMenuGroup.DATA]:{[N.id]:{order:1,menuItemFactory:je},[Se]:{order:2,menuItemFactory:Me,...Xe},[Ce]:{order:3,menuItemFactory:Ne},[we]:{order:4,menuItemFactory:Pe},[Te]:{order:5,menuItemFactory:Fe},[Ee]:{order:6,menuItemFactory:Ie},[De]:{order:7,menuItemFactory:Le}}}};var $e=`@univerjs-pro/sheets-pivot-ui`,et=`1.5.2`;let tt={type:r.CommandType.OPERATION,id:`sheet.operation.open-pivot-table-filter-panel`,async handler(e,t){if(!t)return!1;let{row:r,col:i,unitId:o,subUnitId:s,tableFieldId:c,pivotTableId:l}=t,u=e.get(n.SheetsPivotTableAdaptorModel),d=l||u.getPivotTableIdByCell(o,s,r,i);if(!d)return!1;let f=e.get(n.SheetsPivotRPCService),p=u.getPivotItemRenderInfoCache(o,s,d);if(!(p!=null&&p.rangesInfo))return!1;let m=u.getPivotTableCellData(o,s,r,i),h=(await f.getPivotDisplayConfig({unitId:o,subUnitId:s,pivotTableId:d,params:{type:n.PivotDisplayDataType.Filter,filter:{row:r,col:i,tableFieldId:c,cellData:m,pivotItemRenderInfoCache:p}}})).result.filter;if(!h)return!1;let g=e.get(a.IDialogService),_={id:b,draggable:!0,mask:!1,maskClosable:!1,width:336,dialogStyles:{header:{padding:`16px 16px 0`,height:0},body:{padding:`0 16px 16px`}},closable:!1,children:{label:y,unitId:o,subUnitId:s,key:`${r}-${i}-${c||``}`,filterItemInfo:h},onClose:()=>{g.close(b)}};return g.open(_),!0}},nt={type:r.CommandType.OPERATION,id:`sheet.operation.open-pivot-table-field-setting-panel`,handler(e,t){if(!t)return!1;let n=e.get(r.LocaleService),{tableFieldId:i,pivotTableId:o,unitId:s,subUnitId:c,tableFieldInfo:l,dataFieldInfo:u}=t,d=e.get(a.IDialogService),f={id:S,title:{title:n.t(`sheets-pivot-ui.fieldSettings`)},draggable:!0,mask:!1,maskClosable:!1,width:400,children:{label:x,tableFieldId:i,pivotTableId:o,tableFieldInfo:l,dataFieldInfo:u,unitId:s,subUnitId:c,version:Math.random(),key:`field-setting-${i||``}`,closeFn:()=>{d.close(S)}},onClose:()=>{d.close(S)}};return d.open(f),!0}};function rt(e,n,r){let i=r.fieldIds,{fieldsConfig:a}=n,{rowFields:o,columnFields:s,valueFields:c,filterFields:l,hiddenFields:u,dimension:d,measure:f,valueIndex:p,valuePosition:m}=a,h=/* @__PURE__ */ new Set;[...o,...s,...c,...l,...u].forEach(e=>{let t=d[e]||f[e];t&&h.add(t.dataFieldId)});let g=i.map(t=>{let n=r.fields[t];return{checked:h.has(t),dataFieldId:n.id,id:n.id,name:n.name,type:n.fieldDataType,pivotTableId:e}}),_=o.flatMap(e=>{let t=d[e];return t?[{dataFieldId:t.dataFieldId,tableFieldId:t.id,displayName:t.displayName}]:[]}),v=s.flatMap(e=>{let t=d[e];return t?[{dataFieldId:t.dataFieldId,tableFieldId:t.id,displayName:t.displayName}]:[]}),y=c.flatMap(e=>{let t=f[e];return t?[{dataFieldId:t.dataFieldId,tableFieldId:t.id,displayName:t.displayName,format:t.format,subTotalType:t.subtotal}]:[]}),b=l.flatMap(e=>{let t=d[e];return t?[{dataFieldId:t.dataFieldId,tableFieldId:t.id,displayName:t.displayName}]:[]}),x=u.flatMap(e=>{let t=d[e];return t?[{dataFieldId:t.dataFieldId,tableFieldId:t.id,displayName:t.displayName,filterInfo:t.filterInfo}]:[]});return y.length>1&&(m===t.PivotTableValuePositionEnum.Row?_:v).splice(p,0,{dataFieldId:``,tableFieldId:`PivotMultipleValueId`,displayName:`ΣValue`}),{sourceList:g,sourceRange:n.sourceRangeInfo,rowFields:_,columnFields:v,valueFields:y,filterFields:b,hiddenFields:x,positionInfo:n.targetCellInfo}}let it={type:r.CommandType.OPERATION,id:`sheet.operation.open-pivot-table-panel`,async handler(e,t){let o=t==null?void 0:t.pivotTableId;if(!o)return!1;let s=e.get(a.ISidebarService),c=e.get(r.IUniverInstanceService),l=e.get(r.LocaleService),u=e.get(n.SheetsPivotTableConfigModel),d=(0,i.getSheetCommandTarget)(c);if(!d)return!1;let{unitId:f,subUnitId:p}=d,m=u.getPivotTableConfig(f,p,o),h=u.getCollection(f,o);if(!m||!h)return!1;let g=rt(o,m,h),y={header:{title:l.t(`sheets-pivot-ui.title`)},id:v,children:{label:_,panelInfo:g,version:Math.random(),setVersion:()=>Math.random(),pivotTableId:o,unitId:f,subUnitId:p},width:346};return s.open(y),!0}},at=`sheets-pivot-ui.config`,ot={};function st(e){"@babel/helpers - typeof";return st=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},st(e)}function ct(e,t){if(st(e)!=`object`||!e)return e;var n;if(typeof Symbol<`u`&&(n=e[Symbol.toPrimitive])!==void 0){var r=n.call(e,t||`default`);if(st(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function lt(e){var t=ct(e,`string`);return st(t)==`symbol`?t:t+``}function W(e,t,n){return(t=lt(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function G(e,t){return function(n,r){t(n,r,e)}}function K(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let q=class extends r.Disposable{constructor(e,t,r,i,a,o,s,c){var l;super(),this._localeService=e,this._sheetInterceptorService=t,this._injector=r,this._confirmService=i,this._sheetsPivotTableService=a,this._configService=o,this._sheetPermissionCheckController=s,this._sheetsRenderService=c,W(this,`_defaultOverride`,!1),this.disposeWithMe(this._sheetsRenderService.registerSelfRenderingMutations(n.InitializePivotRuntimeLocalMutation.id)),this._initUIInterceptListener(),this._defaultOverride=((l=this._configService.getConfig(n.SHEETS_PIVOT_PLUGIN_CONFIG_KEY))==null?void 0:l.defaultOverride)??!1}_getPivotAppliedRanges(e,t,r){return(0,n.getPivotAppliedRanges)(e,t,r,this._localeService.getDirection())}_initUIInterceptListener(){this._sheetsPivotTableService.asyncInterceptor.interceptAsync(this._sheetsPivotTableService.asyncInterceptor.getInterceptPoints().PIVOT_PERFORM_CHECK,{handler:async(e,t)=>{let{cellInfo:r,view:a,isEmpty:o}=t,{unitId:s,subUnitId:c}=r,l=this._getPivotAppliedRanges(r,a,o);if(!(0,i.checkRangesEditablePermission)(this._injector,s,c,l)){let e=this._localeService.t(`sheets-pivot-ui.msg.permissionError`);this._sheetPermissionCheckController.blockExecuteWithoutPermission(e)}let u=this._sheetInterceptorService.generateMutationsByRanges({unitId:s,subUnitId:c,ranges:l}),d=(0,n.generateSetRangeValueMutations)(this._injector,s,c,l);if(u.redos.length||d.shouldClear){if(this._defaultOverride)return Promise.resolve(!0);{let e=await this._confirmService.confirm({id:`sheet-pivot.confirm.add-sheet-pivot`,title:{title:this._localeService.t(`sheets-pivot-ui.perform.tips`)},children:{title:this._localeService.t(`sheets-pivot-ui.perform.info`)},cancelText:this._localeService.t(`sheets-pivot-ui.perform.cancel`),confirmText:this._localeService.t(`sheets-pivot-ui.perform.confirm`)});return Promise.resolve(e)}}return Promise.resolve(!0)}})}};q=K([G(0,(0,r.Inject)(r.LocaleService)),G(1,(0,r.Inject)(i.SheetInterceptorService)),G(2,(0,r.Inject)(r.Injector)),G(3,(0,r.Inject)(r.IConfirmService)),G(4,(0,r.Inject)(n.SheetsPivotTableService)),G(5,(0,r.Inject)(r.IConfigService)),G(6,(0,r.Inject)(i.SheetPermissionCheckController)),G(7,(0,r.Inject)(o.SheetsRenderService))],q);function J({ref:e,...t}){let{preserveStrokeWidth:n,icon:r,id:i,className:a,extend:o,...s}=t,c=`univerjs-icon univerjs-icon-${i} ${a||``}`.trim(),l=`_${(0,d.useId)()}`,u=(0,d.useRef)(null);return(0,d.useImperativeHandle)(e,()=>u.current),(0,d.useLayoutEffect)(()=>{if(n&&u.current&&u.current.localName===r.tag)return pt(u.current)},[n,r]),ut(r,`${i}`,{defIds:r.defIds,idSuffix:l},{ref:u,className:c,...s},o)}function ut(e,t,n,r,i){return(0,d.createElement)(e.tag,{key:t,...dt(e,n,i),...r},(ft(e,n).children||[]).map((r,a)=>ut(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function dt(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),n!=null&&n.colorChannel1&&r.stroke===`colorChannel1`&&(r.stroke=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0||(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))})),r}function ft(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function pt(e){let t=e.viewBox.baseVal,n=Math.max(t.width,t.height);if(!Number.isFinite(n)||n<=0||t.width<=0||t.height<=0)return()=>void 0;let r=16/n,i=Array.from(e.querySelectorAll(`circle, ellipse, line, path, polygon, polyline, rect, text, textPath, tspan, use`)).flatMap(e=>{let t=getComputedStyle(e),n=Number.parseFloat(t.strokeWidth);return t.stroke===`none`||Number.parseFloat(t.strokeOpacity)===0||t.vectorEffect===`non-scaling-stroke`||!Number.isFinite(n)||n<=0?[]:[{element:e,hadStyleAttribute:e.hasAttribute(`style`),originalStrokeWidth:n,strokeWidth:mt(e.style,`stroke-width`)}]}).map(e=>({appliedStrokeWidth:null,element:e.element,hadStyleAttribute:e.hadStyleAttribute,isReleased:!1,originalStrokeWidth:e.originalStrokeWidth,strokeWidth:e.strokeWidth}));if(i.length===0)return()=>void 0;let a=(e,n)=>{if(t.width<=0||t.height<=0||e<=0||n<=0)return;let a=Math.min(e/t.width,n/t.height);!Number.isFinite(a)||a<=0||i.forEach(e=>{if(e.isReleased)return;if(e.appliedStrokeWidth!==null&&(e.element.style.getPropertyValue(`stroke-width`)!==e.appliedStrokeWidth||e.element.style.getPropertyPriority(`stroke-width`)!==e.strokeWidth.priority)){e.appliedStrokeWidth=null,e.isReleased=!0;return}let t=e.originalStrokeWidth*r/a,n=`${Number(t.toFixed(12))}px`;e.element.style.setProperty(`stroke-width`,n,e.strokeWidth.priority),e.appliedStrokeWidth=n})},o=e.getBoundingClientRect();a(o.width,o.height);let s=typeof ResizeObserver>`u`?null:new ResizeObserver(t=>{if(t.some(t=>t.target===e)){let t=e.getBoundingClientRect();a(t.width,t.height)}});return s==null||s.observe(e),()=>{s==null||s.disconnect(),i.forEach(e=>{e.appliedStrokeWidth!==null&&(ht(e.element.style,`stroke-width`,e.appliedStrokeWidth,e.strokeWidth.priority,e.strokeWidth),!e.hadStyleAttribute&&e.element.style.length===0&&e.element.removeAttribute(`style`))})}}function mt(e,t){return{priority:e.getPropertyPriority(t),value:e.getPropertyValue(t)}}function ht(e,t,n,r,i){e.getPropertyValue(t)===n&&e.getPropertyPriority(t)===r&&(i.value?e.setProperty(t,i.value,i.priority):e.removeProperty(t))}J.displayName=`UniverIcon`;let gt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M13.5 8H2.5M7.5 3L2.5 8L7.5 13`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}}]},_t=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`arrow-left-icon`,ref:t,icon:gt}))});_t.displayName=`ArrowLeftIcon`;let vt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M12.4208 14.4667C12.4208 14.798 12.1522 15.0667 11.8208 15.0667C11.4895 15.0667 11.2208 14.798 11.2208 14.4667V2.98193L9.97861 4.22417C9.7443 4.45848 9.3644 4.45848 9.13008 4.22417C8.89577 3.98985 8.89577 3.60995 9.13008 3.37564L11.3967 1.10897C11.6311 0.874657 12.011 0.874657 12.2453 1.10897L14.5119 3.37564C14.7463 3.60995 14.7463 3.98985 14.5119 4.22417C14.2776 4.45848 13.8977 4.45848 13.6634 4.22417L12.4208 2.9816V14.4667Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.98967 10.2798C1.6583 10.2798 1.38967 10.0112 1.38967 9.67983C1.38967 9.34846 1.6583 9.07983 1.98967 9.07983H6.50138C6.74406 9.07983 6.96284 9.22602 7.05571 9.45022C7.14858 9.67443 7.09725 9.9325 6.92565 10.1041L3.43819 13.5916H6.50138C6.83276 13.5916 7.10138 13.8602 7.10138 14.1916C7.10138 14.5229 6.83276 14.7916 6.50138 14.7916H1.98967C1.74699 14.7916 1.52821 14.6454 1.43534 14.4212C1.34247 14.197 1.3938 13.9389 1.5654 13.7673L5.05286 10.2798H1.98967Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M5.1846 1.86439C4.8641 0.989866 3.62725 0.989866 3.30674 1.86439L1.34882 7.20672C1.23479 7.51786 1.39458 7.86252 1.70571 7.97655C2.01684 8.09058 2.3615 7.93079 2.47553 7.61966L3.06159 6.02055L3.06338 6.02056H5.42975L6.01581 7.61966C6.12984 7.93079 6.4745 8.09058 6.78563 7.97655C7.09677 7.86252 7.25655 7.51786 7.14252 7.20672L5.1846 1.86439ZM4.98996 4.82056L4.24567 2.78971L3.50138 4.82056H4.98996Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},yt=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`ascending-icon`,ref:t,icon:vt}))});yt.displayName=`AscendingIcon`;let bt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`g`,attrs:{stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2},children:[{tag:`rect`,attrs:{width:12.4,height:11,x:1.8,y:3.2,rx:1.2}},{tag:`path`,attrs:{d:`M5 1.5V4.5M11 1.5V4.5M1.8 6.2H14.2M4.2 9.2H6.2M9.8 9.2H11.8M4.2 11.8H6.2M9.8 11.8H11.8`}}]}]},xt=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`calendar-icon`,ref:t,icon:bt}))});xt.displayName=`CalendarIcon`;let St={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M2.27 8L6.09 11.82L13.73 4.18`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}}]},Ct=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`check-mark-icon`,ref:t,icon:St}))});Ct.displayName=`CheckMarkIcon`;let wt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 17`,width:`1em`,height:`1em`},children:[{tag:`rect`,attrs:{width:12.52,height:4,x:2.63,y:2.89,stroke:`currentColor`,rx:1.1,strokeWidth:1.2}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M6.80825 2.89202V6.89199M10.9821 2.89202V6.89199`,strokeWidth:1.2}},{tag:`rect`,attrs:{width:4,height:4,x:2.63,y:9.8,stroke:`currentColor`,rx:1.1,strokeWidth:1.2}}]},Tt=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`column-icon`,ref:t,icon:wt}))});Tt.displayName=`ColumnIcon`;let Et={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M12.4208 1.53335C12.4208 1.20198 12.1522 0.93335 11.8208 0.93335C11.4895 0.93335 11.2208 1.20198 11.2208 1.53335V13.0181L9.97861 11.7758C9.7443 11.5415 9.3644 11.5415 9.13008 11.7758C8.89577 12.0101 8.89577 12.39 9.13008 12.6244L11.3967 14.891C11.6311 15.1253 12.011 15.1253 12.2453 14.891L14.5119 12.6244C14.7463 12.39 14.7463 12.0101 14.5119 11.7758C14.2776 11.5415 13.8977 11.5415 13.6634 11.7758L12.4208 13.0184V1.53335Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.98967 10.2798C1.6583 10.2798 1.38967 10.0112 1.38967 9.67983C1.38967 9.34846 1.6583 9.07983 1.98967 9.07983H6.50138C6.74406 9.07983 6.96284 9.22602 7.05571 9.45022C7.14858 9.67443 7.09725 9.9325 6.92565 10.1041L3.43819 13.5916H6.50138C6.83276 13.5916 7.10138 13.8602 7.10138 14.1916C7.10138 14.5229 6.83276 14.7916 6.50138 14.7916H1.98967C1.74699 14.7916 1.52821 14.6454 1.43534 14.4212C1.34247 14.197 1.3938 13.9389 1.5654 13.7673L5.05286 10.2798H1.98967Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M5.1846 1.86439C4.8641 0.989866 3.62725 0.989866 3.30674 1.86439L1.34882 7.20672C1.23479 7.51786 1.39458 7.86252 1.70571 7.97655C2.01684 8.09058 2.3615 7.93079 2.47553 7.61966L3.06159 6.02055L3.06338 6.02056H5.42975L6.01581 7.61966C6.12984 7.93079 6.4745 8.09058 6.78563 7.97655C7.09677 7.86252 7.25655 7.51786 7.14252 7.20672L5.1846 1.86439ZM4.98996 4.82056L4.24567 2.78971L3.50138 4.82056H4.98996Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},Dt=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`descending-icon`,ref:t,icon:Et}))});Dt.displayName=`DescendingIcon`;let Ot={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M3.32182 2.60967C2.98161 2.60967 2.79671 3.0074 3.01601 3.2675L6.85819 7.8246C6.94943 7.93282 6.99947 8.06981 6.99947 8.21136V12.7338C6.99947 12.898 7.0998 13.0455 7.2525 13.1058L8.73833 13.6928C9.00085 13.7965 9.28531 13.6031 9.28531 13.3208V8.21136C9.28531 8.06981 9.33535 7.93282 9.42659 7.8246L13.2688 3.2675C13.4881 3.0074 13.3032 2.60967 12.963 2.60967H3.32182ZM2.09858 4.04101C1.22139 3.0006 1.96097 1.40967 3.32182 1.40967H12.963C14.3238 1.40967 15.0634 3.0006 14.1862 4.04101L10.4853 8.43054V13.3208C10.4853 14.4498 9.34747 15.2237 8.29742 14.8089L6.81158 14.2219C6.20078 13.9806 5.79947 13.3905 5.79947 12.7338V8.43054L2.09858 4.04101Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},kt=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`filter-icon`,ref:t,icon:Ot}))});kt.displayName=`FilterIcon`;let At={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M12.8325 3.00753L12.2725 2.44328C11.9909 2.15966 11.6076 1.9999 11.2079 1.9999H4.08689C3.55342 1.9999 3.28522 2.64412 3.66105 3.02295L7.78136 7.17471C8.25623 7.65323 8.25623 8.43812 7.78136 8.91664L3.66105 13.0684C3.28522 13.4473 3.55342 14.0915 4.08689 14.0915H11.2079C11.6076 14.0915 11.9909 13.9317 12.2725 13.648L12.8325 13.0838`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}}]},jt=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`function-icon`,ref:t,icon:At}))});jt.displayName=`FunctionIcon`;let Mt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 20 20`,width:`1em`,height:`1em`},children:[{tag:`circle`,attrs:{cx:7,cy:5,r:1.1,fill:`currentColor`}},{tag:`circle`,attrs:{cx:13,cy:5,r:1.1,fill:`currentColor`}},{tag:`circle`,attrs:{cx:7,cy:10,r:1.1,fill:`currentColor`}},{tag:`circle`,attrs:{cx:13,cy:10,r:1.1,fill:`currentColor`}},{tag:`circle`,attrs:{cx:7,cy:15,r:1.1,fill:`currentColor`}},{tag:`circle`,attrs:{cx:13,cy:15,r:1.1,fill:`currentColor`}}]},Nt=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`grip-vertical-icon`,ref:t,icon:Mt}))});Nt.displayName=`GripVerticalIcon`;let Pt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M5 6.5L8 9.5L11 6.5`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}}]},Ft=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`more-down-icon`,ref:t,icon:Pt}))});Ft.displayName=`MoreDownIcon`;let It={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M3 9C3.55228 9 4 8.55228 4 8C4 7.44772 3.55228 7 3 7C2.44772 7 2 7.44772 2 8C2 8.55228 2.44772 9 3 9Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8 9C8.55228 9 9 8.55228 9 8C9 7.44772 8.55228 7 8 7C7.44772 7 7 7.44772 7 8C7 8.55228 7.44772 9 8 9Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M13 9C13.5523 9 14 8.55228 14 8C14 7.44772 13.5523 7 13 7C12.4477 7 12 7.44772 12 8C12 8.55228 12.4477 9 13 9Z`}}]},Lt=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`more-horizontal-icon`,ref:t,icon:It}))});Lt.displayName=`MoreHorizontalIcon`;let Rt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M5.9334 2.00527C5.9334 1.6739 5.66477 1.40527 5.3334 1.40527C5.00203 1.40527 4.7334 1.6739 4.7334 2.00527V4.73877H1.9999C1.66853 4.73877 1.3999 5.0074 1.3999 5.33877C1.3999 5.67014 1.66853 5.93877 1.9999 5.93877H4.7334V10.072H1.9999C1.66853 10.072 1.3999 10.3407 1.3999 10.672C1.3999 11.0034 1.66853 11.272 1.9999 11.272H4.7334V14.0053C4.7334 14.3366 5.00203 14.6053 5.3334 14.6053C5.66477 14.6053 5.9334 14.3366 5.9334 14.0053V11.272H10.0667V14.0053C10.0667 14.3366 10.3353 14.6053 10.6667 14.6053C10.998 14.6053 11.2667 14.3366 11.2667 14.0053V11.272H13.9999C14.3313 11.272 14.5999 11.0034 14.5999 10.672C14.5999 10.3407 14.3313 10.072 13.9999 10.072H11.2667V5.93877H13.9999C14.3313 5.93877 14.5999 5.67014 14.5999 5.33877C14.5999 5.0074 14.3313 4.73877 13.9999 4.73877H11.2667V2.00527C11.2667 1.6739 10.998 1.40527 10.6667 1.40527C10.3353 1.40527 10.0667 1.6739 10.0667 2.00527V4.73877H5.9334V2.00527ZM10.0667 10.072V5.93877H5.9334V10.072H10.0667Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},zt=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`number-icon`,ref:t,icon:Rt}))});zt.displayName=`NumberIcon`;let Bt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M1.4082 3.74922C1.4082 4.63288 2.12455 5.34922 3.0082 5.34922H4.2082C5.09186 5.34922 5.8082 4.63287 5.8082 3.74922V2.54922C5.8082 1.66556 5.09186 0.949219 4.2082 0.949219H3.0082C2.12455 0.949219 1.4082 1.66556 1.4082 2.54922V3.74922ZM3.0082 4.14922C2.78729 4.14922 2.6082 3.97013 2.6082 3.74922V2.54922C2.6082 2.32831 2.78729 2.14922 3.0082 2.14922H4.2082C4.42912 2.14922 4.6082 2.32831 4.6082 2.54922V3.74922C4.6082 3.97013 4.42912 4.14922 4.2082 4.14922L3.0082 4.14922Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.60757 5.24912C7.72391 5.24912 7.00757 4.53278 7.00757 3.64912V2.64912C7.00757 1.76547 7.72391 1.04912 8.60757 1.04912L14.0076 1.04912C14.8912 1.04912 15.6076 1.76546 15.6076 2.64912V3.64912C15.6076 4.53278 14.8912 5.24912 14.0076 5.24912L8.60757 5.24912ZM8.20757 3.64912C8.20757 3.87003 8.38665 4.04912 8.60757 4.04912L14.0076 4.04912C14.2285 4.04912 14.4076 3.87003 14.4076 3.64912V2.64912C14.4076 2.42821 14.2285 2.24912 14.0076 2.24912L8.60757 2.24912C8.38665 2.24912 8.20757 2.42821 8.20757 2.64912V3.64912Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.5083 8.05078C1.5083 7.16713 2.22464 6.45078 3.1083 6.45078H4.1083C4.99196 6.45078 5.7083 7.16713 5.7083 8.05078V13.4508C5.7083 14.3344 4.99196 15.0508 4.1083 15.0508H3.1083C2.22464 15.0508 1.5083 14.3344 1.5083 13.4508V8.05078ZM3.1083 7.65078C2.88739 7.65078 2.7083 7.82987 2.7083 8.05078V13.4508C2.7083 13.6717 2.88739 13.8508 3.1083 13.8508H4.1083C4.32921 13.8508 4.5083 13.6717 4.5083 13.4508V8.05078C4.5083 7.82987 4.32921 7.65078 4.1083 7.65078H3.1083Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.01375 13.0622L9.82677 14.8752C10.0611 15.1095 10.441 15.1095 10.6753 14.8752C10.9096 14.6409 10.9096 14.261 10.6753 14.0267L9.60391 12.9553L12.5981 12.9537C14.0335 12.953 15.1968 11.7891 15.1968 10.3537V7.70108C15.1968 7.3697 14.9281 7.10108 14.5968 7.10108C14.2654 7.10108 13.9968 7.3697 13.9968 7.70108V10.3537C13.9968 11.1266 13.3704 11.7533 12.5975 11.7537L9.60349 11.7553L10.6753 10.6835C10.9096 10.4492 10.9096 10.0693 10.6753 9.83495C10.441 9.60063 10.0611 9.60063 9.82677 9.83495L8.01375 11.648C7.62322 12.0385 7.62322 12.6717 8.01375 13.0622Z`}}]},Vt=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`pivot-table-icon`,ref:t,icon:Bt}))});Vt.displayName=`PivotTableIcon`;let Ht={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 17`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M8.04163 6.24451L8.0418 6.25869L8.04163 6.27285L8.04173 10.4233L8.0418 10.4325L8.04173 10.4417L8.0418 13.5069C8.04182 14.4458 7.2807 15.2069 6.3418 15.2069H4.54183C3.60294 15.2069 2.84182 14.4458 2.84183 13.5069L2.84184 10.4397L2.8418 10.4325L2.84184 10.4253L2.84186 6.26726L2.8418 6.25869L2.84186 6.25011L2.84187 3.18486C2.84187 2.24596 3.60301 1.48484 4.54191 1.48486L6.3416 1.48491C7.28046 1.48493 8.04154 2.24602 8.04156 3.18487L8.04163 6.24451ZM6.8418 13.5069L6.84174 11.0325H4.04184L4.04183 13.5069C4.04183 13.783 4.26568 14.0069 4.54183 14.0069H6.3418C6.61794 14.0069 6.8418 13.783 6.8418 13.5069ZM6.84171 9.83252H4.04184L4.04185 6.85869H6.84165L6.84171 9.83252ZM6.84162 5.65869H4.04186L4.04187 3.18486C4.04187 2.90871 4.26574 2.68486 4.54188 2.68486L6.34158 2.68491C6.61771 2.68491 6.84156 2.90876 6.84156 3.1849L6.84162 5.65869Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M9.74932 4.98481L9.74934 3.18484C9.74936 2.24595 10.5105 1.48484 11.4494 1.48486L13.2493 1.48491C14.1882 1.48494 14.9493 2.24604 14.9493 3.18491V4.98483C14.9493 5.92372 14.1882 6.68483 13.2493 6.68483H11.4493C10.5104 6.68483 9.7493 5.9237 9.74932 4.98481ZM10.9493 3.18486L10.9493 4.98483C10.9493 5.26097 11.1732 5.48483 11.4493 5.48483H13.2493C13.5254 5.48483 13.7493 5.26098 13.7493 4.98483V3.18491C13.7493 2.90877 13.5254 2.68492 13.2493 2.68491L11.4494 2.68486C11.1732 2.68486 10.9493 2.90871 10.9493 3.18486Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},Ut=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`row-icon`,ref:t,icon:Ht}))});Ut.displayName=`RowIcon`;let Wt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`g`,attrs:{stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2},children:[{tag:`circle`,attrs:{cx:7,cy:7,r:5.2}},{tag:`path`,attrs:{d:`M10.8 10.8L14.2 14.2`}}]}]},Gt=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`search-icon`,ref:t,icon:Wt}))});Gt.displayName=`SearchIcon`;let Kt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M2.22891 2.67227H11.5622M6.89541 2.67227V14.0056M10.2289 7.00552H15.5622M12.8954 7.00552V14.0055`,strokeLinecap:`round`,strokeWidth:1.2}}]},qt=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`text-icon`,ref:t,icon:Kt}))});qt.displayName=`TextIcon`;function Jt(e){let{editable:t,pivotTableId:i,subUnitId:o,unitId:s}=e,l=(0,a.useDependency)(r.ICommandService),u=(0,a.useDependency)(a.IDialogService),d=(0,a.useDependency)(r.LocaleService),p=[{command:{id:it.id,params:{pivotTableId:i}},disabled:!t,label:`sheets-pivot-ui.mobile.edit`},{command:{id:n.RemovePivotTableCommand.id,params:{unitId:s,subUnitId:o,pivotTableId:i}},disabled:!t,label:`sheets-pivot-ui.mobile.delete`}];async function m(e){await l.executeCommand(e.id,e.params),u.close(M)}return/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-flex-col univer-gap-2`,children:p.map(e=>{let t=d.t(e.label);return/* @__PURE__ */ (0,f.jsx)(c.MobileActionRow,{title:t,"aria-label":t,variant:`subtle`,disabled:e.disabled,onClick:()=>m(e.command)},e.command.id)})})}let Yt=[{label:`1930-08-05`,suffix:`yyyy-MM-dd`},{label:`1930/08/05`,suffix:`yyyy/MM/dd`},{label:`1930年08月05日`,suffix:`yyyy"年"MM"月"dd"日"`},{label:`08-05`,suffix:`MM-dd`},{label:`8月5日`,suffix:`M"月"d"日"`},{label:`13:30:30`,suffix:`h:mm:ss`},{label:`13:30`,suffix:`h:mm`},{label:`下午01:30`,suffix:`A/P hh:mm`},{label:`下午1:30`,suffix:`A/P h:mm`},{label:`下午1:30:30`,suffix:`A/P h:mm:ss`},{label:`08-05 下午 01:30`,suffix:`MM-dd A/P hh:mm`}],Xt=[{label:`(1,235)`,suffix:`#,##0_);(#,##0)`},{label:`(1,235) `,suffix:`#,##0_);[Red](#,##0)`,color:`red`},{label:`1,234.56`,suffix:`#,##0.00_);#,##0.00`},{label:`1,234.56`,suffix:`#,##0.00_);[Red]#,##0.00`,color:`red`},{label:`-1,234.56`,suffix:`#,##0.00_);-#,##0.00`},{label:`-1,234.56`,suffix:`#,##0.00_);[Red]-#,##0.00`,color:`red`}],Zt=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:`red`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:`red`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:`red`}],Qt=`PivotMultipleValueId`;function $t(e,n){if(n===t.PivotDataFieldDataTypeEnum.blank)return`sheets-pivot-ui.dialog.filter.blank`;if(n===t.PivotDataFieldDataTypeEnum.other&&e===t.GlobalConfig.otherDataKey)return`sheets-pivot-ui.showValuesAs.other`}function en(e,t){let r=(0,n.isolateTextForBidiContext)(t,e);return e.includes(`{0}`)?e.replace(`{0}`,r):`${e}${r}`}let tn=e=>{switch(e){case`filter`:return t.PivotTableFiledAreaEnum.Filter;case`row`:return t.PivotTableFiledAreaEnum.Row;case`column`:return t.PivotTableFiledAreaEnum.Column;case`value`:return t.PivotTableFiledAreaEnum.Value;default:return t.PivotTableFiledAreaEnum.Row}};function nn(e,t){switch(t.rangeType||r.RANGE_TYPE.NORMAL){case r.RANGE_TYPE.NORMAL:return{startRow:t.startRow,startColumn:t.startColumn,endRow:t.endRow,endColumn:t.endColumn};case r.RANGE_TYPE.ROW:return{startRow:t.startRow,startColumn:0,endRow:t.endRow,endColumn:e.getColumnCount()-1};case r.RANGE_TYPE.COLUMN:return{startRow:0,startColumn:t.startColumn,endRow:e.getRowCount()-1,endColumn:t.endColumn};case r.RANGE_TYPE.ALL:return{startRow:0,startColumn:0,endRow:e.getRowCount()-1,endColumn:e.getColumnCount()-1}}}function rn(e,t){if(!t||!e||t.endRow-t.startRow<=0)return 1;let{startRow:n,startColumn:r,endRow:i,endColumn:a}=nn(e,t),o=e.getCellMatrix(),s=!1;for(let e=n;e<=i;e++){for(let t=r;t<=a;t++)if(o.getValue(e,t)!=null){s=!0;break}if(s)break}return s?2:0}async function an(e,t,r){let{commandService:i,pivotTableInfo:a,pivotTableId:o,unitId:s,subUnitId:c}=e,l=[],{rowFields:u,columnFields:d,filterFields:f,valueFields:p}=a,m=[...u,...d,...f,...p];t===`PivotMultipleValueId`&&p.forEach(e=>{l.push(e.tableFieldId)}),r===`source`&&m.forEach(e=>{e.dataFieldId===t&&l.push(e.tableFieldId)}),r!==`source`&&m.find(e=>e.tableFieldId===t)&&l.push(t),await i.executeCommand(n.RemovePivotFieldCommand.id,{pivotTableId:o,fieldIds:l,unitId:s,subUnitId:c})}async function on(e,t,r,i,a){let o={unitId:i,subUnitId:a,token:t,dataRangeInfo:r};await e.executeCommand(n.UpdatePivotTableSourceRangeCommand.id,o)}let sn=(e,t)=>{let{rowFields:n,columnFields:r,filterFields:i}=e,a=[...n,...r,...i],o=[];return a.forEach(e=>{e.dataFieldId===t&&o.push(e.tableFieldId)}),o};async function cn(e,t,r,i,a){if(r===`source`&&i===`source`)return;let o=t===Qt,{commandService:s,pivotTableInfo:c,pivotTableId:l,unitId:u,subUnitId:d}=e;if(r===`source`&&i!==`source`){let{sourceList:e}=c,r=e.find(e=>e.id===t);if(r){let e=sn(c,t);if(i!==`value`&&e.length>0){let t=e[0];await s.executeCommand(n.MovePivotFieldCommand.id,{pivotTableId:l,fieldId:t,area:tn(i),index:a,unitId:u,subUnitId:d})}else await s.executeCommand(n.AddPivotFieldCommand.id,{pivotTableId:l,dataFieldId:r.dataFieldId,fieldArea:tn(i),index:a,unitId:u,subUnitId:d})}}if(r!==`source`&&i===`source`){let{rowFields:n,columnFields:r,filterFields:i,valueFields:a}=c,s=[...n,...r,...i,...a],l=[];o?a.forEach(e=>{l.push(e.tableFieldId)}):s.find(e=>e.tableFieldId===t)&&l.push(t),await ln(e,l)}else r!==`source`&&i!==`source`&&await dn(e,t,r,i,a)}async function ln(e,t){let{commandService:r,pivotTableId:i,unitId:a,subUnitId:o}=e;await r.executeCommand(n.RemovePivotFieldCommand.id,{pivotTableId:i,fieldIds:t,unitId:a,subUnitId:o})}async function un(e,t,r){let{commandService:i,pivotTableId:a,unitId:o,subUnitId:s}=e;await i.executeCommand(n.UpdatePivotValuePositionCommand.id,{pivotTableId:a,position:t,index:r,unitId:o,subUnitId:s})}async function dn(e,r,i,a,o){let s=r===Qt,{commandService:c,pivotTableInfo:l,pivotTableId:u,unitId:d,subUnitId:f}=e;if(s){let e=tn(a);(e===t.PivotTableFiledAreaEnum.Row||e===t.PivotTableFiledAreaEnum.Column)&&await c.executeCommand(n.UpdatePivotValuePositionCommand.id,{pivotTableId:u,position:e===t.PivotTableFiledAreaEnum.Row?t.PivotTableValuePositionEnum.Row:t.PivotTableValuePositionEnum.Column,index:o,unitId:d,subUnitId:f});return}let{rowFields:p,columnFields:m,filterFields:h,valueFields:g}=l,_=[...p,...m,...h,...g].find(e=>e.tableFieldId===r);if(_){let t=[...p,...m,...h];if(i===`value`&&a!==`value`&&t.find(e=>e.dataFieldId===_.dataFieldId)){await ln(e,[r]);return}await c.executeCommand(n.MovePivotFieldCommand.id,{pivotTableId:u,fieldId:r,area:tn(a),index:o,unitId:d,subUnitId:f})}}function fn(e,t,n,r,i){e.executeCommand(tt.id,{row:-1,col:-1,unitId:t,subUnitId:n,tableFieldId:i,pivotTableId:r})}function pn(e,t,n,r,i,a){let{sourceList:o,rowFields:s,columnFields:c,valueFields:l,filterFields:u}=a,d=[...s,...c,...l,...u].find(e=>e.tableFieldId===n),f=o.find(e=>e.id===(d==null?void 0:d.dataFieldId));if(d&&f){let a={tableFieldId:n,pivotTableId:t,unitId:r,subUnitId:i,tableFieldInfo:d,dataFieldInfo:f};e.executeCommand(nt.id,a)}}let mn=[{type:t.PivotSubtotalTypeEnum.average,textKey:`sheets-pivot-ui.subtotal.average`},{type:t.PivotSubtotalTypeEnum.count,textKey:`sheets-pivot-ui.subtotal.count`},{type:t.PivotSubtotalTypeEnum.countNums,textKey:`sheets-pivot-ui.subtotal.countNums`},{type:t.PivotSubtotalTypeEnum.max,textKey:`sheets-pivot-ui.subtotal.max`},{type:t.PivotSubtotalTypeEnum.min,textKey:`sheets-pivot-ui.subtotal.min`},{type:t.PivotSubtotalTypeEnum.product,textKey:`sheets-pivot-ui.subtotal.product`},{type:t.PivotSubtotalTypeEnum.stdDev,textKey:`sheets-pivot-ui.subtotal.stdDev`},{type:t.PivotSubtotalTypeEnum.stdDevp,textKey:`sheets-pivot-ui.subtotal.stdDevp`},{type:t.PivotSubtotalTypeEnum.sum,textKey:`sheets-pivot-ui.subtotal.sum`},{type:t.PivotSubtotalTypeEnum.var,textKey:`sheets-pivot-ui.subtotal.var`},{type:t.PivotSubtotalTypeEnum.varp,textKey:`sheets-pivot-ui.subtotal.varp`}],hn=(e,t=0)=>e?r.numfmt.getFormatInfo(e).maxDecimals??t:t,gn=e=>Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(``),Y=(e,t)=>e.split(`;`).map(e=>/\.0?/.test(e)?e.replace(/\.0*/g,`${t>0?`.`:``}${gn(Number(t||0))}`):/0[^0]?/.test(e)?e.replace(/0[^0]+|0$/,`0${t>0?`.`:``}${gn(Number(t||0))}`):e).join(`;`),_n=e=>r.currencySymbols.find(t=>e.includes(t)),vn=e=>!e,yn=e=>!!_n(e)&&e.startsWith(`_(`),bn=e=>!!_n(e)&&!e.startsWith(`_(`),xn=()=>Yt.map(e=>({label:e.label,value:e.suffix})),Sn=e=>{let t=r.numfmt.getFormatInfo(e);return xn().map(e=>e.value).includes(e)||[`date`,`datetime`,`time`].includes(t.type)},Cn=()=>Xt.map(e=>({label:e.label,value:e.suffix,color:e.color})),wn=e=>Cn().some(t=>(0,r.isPatternEqualWithoutDecimal)(t.value,e)),Tn=(e,n)=>{switch(n){case t.PivotTableFiledAreaEnum.Row:return e.rowFields.length;case t.PivotTableFiledAreaEnum.Column:return e.columnFields.length;case t.PivotTableFiledAreaEnum.Filter:return e.filterFields.length;case t.PivotTableFiledAreaEnum.Value:return e.valueFields.length;default:return 0}},En=(e,t,r)=>{for(let i of[`sheets-pivot-ui.averageName`,`sheets-pivot-ui.countName`,`sheets-pivot-ui.countNumsName`,`sheets-pivot-ui.maxName`,`sheets-pivot-ui.minName`,`sheets-pivot-ui.productName`,`sheets-pivot-ui.stdDevName`,`sheets-pivot-ui.stdDevpName`,`sheets-pivot-ui.sumName`,`sheets-pivot-ui.varName`,`sheets-pivot-ui.varpName`]){let a=r[i];if(a+(0,n.isolateTextForBidiContext)(e,a)===t||a+e===t)return!0}return!1},Dn=(e,r,i)=>{let a=``;switch(i){case t.PivotSubtotalTypeEnum.average:a=r[`sheets-pivot-ui.averageName`];break;case t.PivotSubtotalTypeEnum.count:a=r[`sheets-pivot-ui.countName`];break;case t.PivotSubtotalTypeEnum.countNums:a=r[`sheets-pivot-ui.countNumsName`];break;case t.PivotSubtotalTypeEnum.max:a=r[`sheets-pivot-ui.maxName`];break;case t.PivotSubtotalTypeEnum.min:a=r[`sheets-pivot-ui.minName`];break;case t.PivotSubtotalTypeEnum.product:a=r[`sheets-pivot-ui.productName`];break;case t.PivotSubtotalTypeEnum.stdDev:a=r[`sheets-pivot-ui.stdDevName`];break;case t.PivotSubtotalTypeEnum.stdDevp:a=r[`sheets-pivot-ui.stdDevpName`];break;case t.PivotSubtotalTypeEnum.sum:a=r[`sheets-pivot-ui.sumName`];break;case t.PivotSubtotalTypeEnum.var:a=r[`sheets-pivot-ui.varName`];break;case t.PivotSubtotalTypeEnum.varp:a=r[`sheets-pivot-ui.varpName`];break;default:return e}return a+(0,n.isolateTextForBidiContext)(e,a)};function On(e,n){if(n.conditionFilter&&(0,t.isPivotTableFilterRestrictive)(n.conditionFilter))return`HasFilter`;if(!e)return`NotFilter`;if((0,t.isPivotDateFilter)(e))return`HasFilter`;if((0,t.isManualPivotFilter)(e)){var r;return e.isAll||((r=n.items)==null?void 0:r.length)===e.list.length?`NotFilter`:`HasFilter`}return(0,t.isPivotTableFilterRestrictive)(e)?`HasFilter`:`NotFilter`}function kn(e){return yn(e)?`accounting`:bn(e)?`currency`:Sn(e)?`date`:wn(e)?`thousandthPercentile`:`general`}function An(e){let{originPattern:t=``,onChange:n}=e,i=(0,a.useDependency)(r.LocaleService),[o,s]=(0,d.useState)(()=>kn(t)),[l,u]=(0,d.useState)(()=>hn(t,2)),[p,m]=(0,d.useState)(()=>_n(t)||r.currencySymbols[0]),[h,g]=(0,d.useState)(t),_=(0,d.useMemo)(()=>[{value:`general`,label:i.t(`sheets-pivot-ui.dialog.numfmt.general`)},{value:`accounting`,label:i.t(`sheets-pivot-ui.dialog.numfmt.accounting`)},{value:`currency`,label:i.t(`sheets-pivot-ui.dialog.numfmt.currency`)},{value:`date`,label:i.t(`sheets-pivot-ui.dialog.numfmt.date`)},{value:`thousandthPercentile`,label:i.t(`sheets-pivot-ui.dialog.numfmt.thousandthPercentile`)}],[i]),v=r.currencySymbols.map(e=>({label:e,value:e}));function y(e){g(e),n(e)}function b(e,t){return Y(`_("${e}"* #,##0${t>0?`.0`:``}_)`,t)}function x(e){s(e),y(e===`general`?``:e===`accounting`?b(p,l):e===`currency`?Y(Zt[0].suffix(p),l):e===`date`?Yt[0].suffix:Y(Xt[0].suffix,l))}function S(e){m(e),y(o===`accounting`?b(e,l):Y(Zt[0].suffix(e),l))}function C(e){let t=e??0;u(t),y(o===`accounting`?b(p,t):Y(h,t))}let w=Zt.map(e=>({label:e.label(p),value:e.suffix(p),color:e.color})),T=Xt.map(e=>({label:e.label,value:e.suffix,color:e.color})),E=Yt.map(e=>({label:e.label,value:e.suffix}));return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:i.t(`sheets-pivot-ui.dialog.numfmt.formatTypes`)}),/* @__PURE__ */ (0,f.jsx)(c.MobileSelect,{className:`univer-w-full`,value:o,options:_,onChange:e=>x(e),size:`small`})]}),(o===`accounting`||o===`currency`)&&/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-grid univer-grid-cols-2 univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:i.t(`sheets-pivot-ui.dialog.numfmt.decimalPlaces`)}),/* @__PURE__ */ (0,f.jsx)(c.InputNumber,{className:`univer-w-full`,value:l,min:0,max:20,onChange:C,size:`small`,controls:!1})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:i.t(`sheets-pivot-ui.dialog.numfmt.currencyTypes`)}),/* @__PURE__ */ (0,f.jsx)(c.MobileSelect,{className:`univer-w-full`,value:p,options:v,onChange:S,size:`small`})]})]}),o===`thousandthPercentile`&&/* @__PURE__ */ (0,f.jsxs)(`div`,{children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:i.t(`sheets-pivot-ui.dialog.numfmt.decimalPlaces`)}),/* @__PURE__ */ (0,f.jsx)(c.InputNumber,{className:`univer-w-full`,value:l,min:0,max:20,onChange:C,size:`small`,controls:!1})]}),o===`currency`&&/* @__PURE__ */ (0,f.jsx)(c.SelectList,{className:`univer-rounded-xl univer-p-2`,options:w,value:h,onChange:e=>y(Y(e,l))}),o===`date`&&/* @__PURE__ */ (0,f.jsx)(c.SelectList,{className:`univer-rounded-xl univer-p-2`,options:E,value:h,onChange:e=>y(e)}),o===`thousandthPercentile`&&/* @__PURE__ */ (0,f.jsx)(c.SelectList,{className:`univer-rounded-xl univer-p-2`,options:T,value:h,onChange:e=>y(Y(e,l))}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-text-sm univer-text-gray-500`,children:i.t(`sheets-pivot-ui.dialog.numfmt.${o}Desc`)})]})}function jn(e){let{unitId:t,subUnitId:i,pivotTableId:o,tableFieldId:s,originPattern:l,tableFieldInfo:u,dataFieldInfo:p}=e,m=(0,a.useDependency)(r.ICommandService),h=(0,a.useDependency)(a.IDialogService),g=(0,a.useDependency)(r.LocaleService),[_,v]=(0,d.useState)(l??``);async function y(){let e={format:_,tableFieldId:s,pivotTableId:o,unitId:t,subUnitId:i,tableFieldInfo:u,dataFieldInfo:p};await m.executeCommand(n.UpdatePivotFieldSettingCommand.id,e),h.close(w)}return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-5`,dir:g.getDirection(),children:[/* @__PURE__ */ (0,f.jsx)(An,{originPattern:l,onChange:v}),/* @__PURE__ */ (0,f.jsxs)(c.MobileActionRowGroup,{children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{onClick:()=>h.close(w),size:`middle`,children:g.t(`sheets-pivot-ui.dialog.numfmt.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`primary`,onClick:y,size:`middle`,children:g.t(`sheets-pivot-ui.dialog.numfmt.confirm`)})]})]})}function Mn(e){let{unitId:t,subUnitId:i,pivotTableId:o,tableFieldId:s,tableFieldInfo:l,dataFieldInfo:u,closeFn:p,format:m,version:h}=e,g=(0,a.useDependency)(r.ICommandService),_=(0,a.useDependency)(n.SheetsPivotTableConfigModel),v=(0,a.useDependency)(r.LocaleService),[y,b]=(0,d.useState)(`field`),[x,S]=(0,d.useState)(l.displayName),[C,w]=(0,d.useState)(l.subTotalType),[T,E]=(0,d.useState)(m??l.format??``),[D,O]=(0,d.useState)(T);(0,d.useEffect)(()=>{b(`field`),S(l.displayName),w(l.subTotalType),E(m??l.format??``),O(m??l.format??``)},[m,l,h]);let k={..._.getTextInfo()};[`sheets-pivot-ui.averageName`,`sheets-pivot-ui.countName`,`sheets-pivot-ui.countNumsName`,`sheets-pivot-ui.maxName`,`sheets-pivot-ui.minName`,`sheets-pivot-ui.productName`,`sheets-pivot-ui.stdDevName`,`sheets-pivot-ui.stdDevpName`,`sheets-pivot-ui.sumName`,`sheets-pivot-ui.varName`,`sheets-pivot-ui.varpName`].forEach(e=>{k[e]=v.t(e)});function A(e){w(e),En(u.name,x,k)&&S(Dn(u.name,k,e))}async function j(){let e={displayName:l.displayName===x?void 0:x,subtotalType:l.subTotalType===C?void 0:C,format:l.format===T?void 0:T,tableFieldId:s,pivotTableId:o,unitId:t,subUnitId:i,tableFieldInfo:l,dataFieldInfo:u};await g.executeCommand(n.UpdatePivotFieldSettingCommand.id,e),p()}return y===`format`?/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-5`,dir:v.getDirection(),children:[/* @__PURE__ */ (0,f.jsxs)(`button`,{type:`button`,className:`univer-flex univer-h-10 univer-items-center univer-gap-2 univer-border-0 univer-bg-transparent univer-p-0 univer-text-base univer-font-semibold`,onClick:()=>b(`field`),children:[/* @__PURE__ */ (0,f.jsx)(_t,{}),v.t(`sheets-pivot-ui.dialog.numfmt.fieldSetting`)]}),/* @__PURE__ */ (0,f.jsx)(An,{originPattern:T,onChange:O}),/* @__PURE__ */ (0,f.jsxs)(c.MobileActionRowGroup,{children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{onClick:()=>b(`field`),size:`middle`,children:v.t(`sheets-pivot-ui.dialog.numfmt.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`primary`,onClick:()=>{E(D),b(`field`)},size:`middle`,children:v.t(`sheets-pivot-ui.dialog.numfmt.confirm`)})]})]}):/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,dir:v.getDirection(),children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-sm univer-font-medium`,children:v.t(`sheets-pivot-ui.dialog.fieldName`)}),/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-truncate univer-text-xs univer-text-gray-500`,children:en(v.t(`sheets-pivot-ui.dialog.sourceName`),u.name)})]}),/* @__PURE__ */ (0,f.jsx)(c.Input,{className:`univer-mt-2 univer-w-full`,value:x,onChange:S,size:`small`})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:v.t(`sheets-pivot-ui.dialog.summarizeBy`)}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-max-h-[40vh] univer-overflow-y-auto univer-rounded-xl univer-bg-gray-50 univer-p-1 dark:!univer-bg-gray-800`,children:mn.map(e=>/* @__PURE__ */ (0,f.jsxs)(`button`,{type:`button`,className:(0,c.clsx)(`univer-flex univer-h-12 univer-w-full univer-items-center univer-gap-2 univer-rounded-xl univer-border-0 univer-bg-transparent univer-px-3 univer-text-left univer-text-sm`,{"univer-bg-primary-50 dark:!univer-bg-gray-700":C===e.type}),onClick:()=>A(e.type),children:[/* @__PURE__ */ (0,f.jsx)(Ct,{className:(0,c.clsx)(`univer-text-primary-600`,{"univer-invisible":C!==e.type})}),v.t(e.textKey)]},e.type))})]}),/* @__PURE__ */ (0,f.jsx)(c.Button,{className:`univer-w-full`,onClick:()=>{O(T),b(`format`)},size:`middle`,children:v.t(`sheets-pivot-ui.dialog.format`)}),/* @__PURE__ */ (0,f.jsxs)(c.MobileActionRowGroup,{children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{onClick:p,size:`middle`,children:v.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`primary`,disabled:!x,onClick:j,size:`middle`,children:v.t(`sheets-pivot-ui.dialog.ok`)})]})]})}function Nn(e){var i;let{filterItemInfo:o,unitId:s,subUnitId:l}=e,u=(0,a.useDependency)(r.ICommandService),p=(0,a.useDependency)(a.IDialogService),m=(0,a.useDependency)(r.LocaleService),h=(0,a.useDependency)(r.IUniverInstanceService),g=(0,a.useObservable)(m.direction$,m.getDirection()),[_,v]=(0,d.useState)(()=>{var e;return o.checkedItems??((e=o.filterInfo)==null?void 0:e.list)??o.items}),[y,x]=(0,d.useState)(()=>o.partialItems??[]),[S,C]=(0,d.useState)((i=o.sortInfo)==null?void 0:i.type),w=y.length===0&&_.length===o.items.length,T=On(o.filterInfo,{items:o.items,conditionFilter:o.conditionFilter});(0,d.useEffect)(()=>{let e=h.getCurrentUnitOfType(r.UniverInstanceType.UNIVER_SHEET);if(!e)return;let t=e.activeSheet$.subscribe(e=>{(e==null?void 0:e.getSheetId())!==l&&p.close(b)});return()=>t.unsubscribe()},[p,l,h]);function E(){p.close(b)}function D(e){y.includes(e)?(x(t=>t.filter(t=>t!==e)),v(t=>[...t,e])):v(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])}async function O(e,t,r,i=!1){await u.executeCommand(n.SetPivotFilterCommand.id,{unitId:s,subUnitId:l,pivotTableId:o.pivotTableId,tableFieldId:o.tableFieldId,items:e,partialItems:r,isAll:t,clearAllFilters:i}),E()}async function k(e){await u.executeCommand(n.SetPivotSortCommand.id,{unitId:s,subUnitId:l,pivotTableId:o.pivotTableId,tableFieldId:o.tableFieldId,info:{type:e}}),C(e),E()}return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,dir:g,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-text-base univer-font-semibold`,children:m.t(`sheets-pivot-ui.filterField`)}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-grid univer-grid-cols-2 univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsxs)(c.Button,{className:(0,c.clsx)(``,{"univer-bg-gray-100 dark:!univer-bg-gray-700":S===t.PivotDataFieldSortOperatorEnum.ascending}),onClick:()=>k(t.PivotDataFieldSortOperatorEnum.ascending),size:`middle`,children:[/* @__PURE__ */ (0,f.jsx)(yt,{}),m.t(`sheets-pivot-ui.dialog.filter.ascending`)]}),/* @__PURE__ */ (0,f.jsxs)(c.Button,{className:(0,c.clsx)(``,{"univer-bg-gray-100 dark:!univer-bg-gray-700":S===t.PivotDataFieldSortOperatorEnum.descending}),onClick:()=>k(t.PivotDataFieldSortOperatorEnum.descending),size:`middle`,children:[/* @__PURE__ */ (0,f.jsx)(Dt,{}),m.t(`sheets-pivot-ui.dialog.filter.descending`)]})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-max-h-[40vh] univer-overflow-y-auto univer-rounded-xl univer-bg-gray-50 univer-p-2 dark:!univer-bg-gray-800`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-min-h-12 univer-items-center univer-px-2`,children:/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:w,indeterminate:!w&&(_.length>0||y.length>0),onChange:()=>{x([]),v(w?[]:o.items)},children:m.t(`sheets-pivot-ui.dialog.filter.selectAll`)})}),o.items.map((e,n)=>{var i;let a=o.itemTypes[n],s=(i=o.itemLabels)==null?void 0:i[e],l=$t(e,a),u=e;return l?u=m.t(l):s===void 0?a===t.PivotDataFieldDataTypeEnum.date&&o.format&&(u=r.numfmt.format(o.format,Number(e))):u=s,/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-min-h-12 univer-items-center univer-px-2`,children:/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:_.includes(e),indeterminate:y.includes(e),contentClassName:`univer-max-w-[70vw] univer-truncate`,onChange:()=>D(e),children:u})},e)})]}),/* @__PURE__ */ (0,f.jsx)(c.Button,{className:`univer-w-full`,variant:`link`,disabled:T===`NotFilter`,onClick:()=>O(o.items,!0,[],!0),size:`middle`,children:m.t(`sheets-pivot-ui.dialog.filter.clearFilter`)}),/* @__PURE__ */ (0,f.jsxs)(c.MobileActionRowGroup,{children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{onClick:E,size:`middle`,children:m.t(`sheets-pivot-ui.dialog.filter.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`primary`,disabled:!_.length&&!y.length,onClick:()=>O(_,w,y),size:`middle`,children:m.t(`sheets-pivot-ui.dialog.filter.confirm`)})]})]})}let Pn=[{label:`sheets-pivot-ui.config.pageDownThenOver`,value:`false`},{label:`sheets-pivot-ui.config.pageOverThenDown`,value:`true`}],Fn=[{label:`sheets-pivot-ui.config.layoutTabular`,value:String(t.PivotLayoutTypeEnum.tabular)},{label:`sheets-pivot-ui.config.layoutCompact`,value:String(t.PivotLayoutTypeEnum.compact)},{label:`sheets-pivot-ui.config.layoutOutline`,value:String(t.PivotLayoutTypeEnum.outline)}],In=[{label:`sheets-pivot-ui.config.rowSubtotalTop`,value:String(t.PivotSubtotalPositionEnum.top)},{label:`sheets-pivot-ui.config.rowSubtotalBottom`,value:String(t.PivotSubtotalPositionEnum.bottom)}],Ln=[{label:`sheets-pivot-ui.config.dateGroupingLegacy`,value:t.PivotDateGroupingMode.Legacy},{label:`sheets-pivot-ui.config.dateGroupingExcelLike`,value:t.PivotDateGroupingMode.ExcelLike}];function Rn(e){let{unitId:i,subUnitId:o,pivotTableId:l}=e,u=(0,a.useDependency)(r.ICommandService),p=(0,a.useDependency)(r.IConfirmService),m=(0,a.useDependency)(r.ILogService),h=(0,a.useDependency)(r.LocaleService),g=(0,a.useDependency)(n.SheetsPivotTableConfigModel),_=(0,d.useMemo)(()=>g.watchPivotTableChanges(i,o,l).pipe((0,s.debounceTime)(0)),[g,i,o,l]);(0,a.useObservable)(_);let[v,y]=(0,d.useState)(!1),b=(0,d.useRef)(!1),x=g.getPivotTableConfig(i,o,l),S=(0,t.getPivotDateGroupingMode)(x==null?void 0:x.fieldsConfig.options),[C,w]=(0,d.useState)(()=>{var e,n;let r=g.getPivotTableConfig(i,o,l),a=(r==null||(e=r.fieldsConfig)==null?void 0:e.options)??{};return{showRowSubtotal:a.showRowSubtotal??!0,showRowGrandTotal:a.showRowGrandTotal??!0,showColSubtotal:a.showColSubtotal??!0,showColGrandTotal:a.showColGrandTotal??!0,pageWrap:a.pageWrap??1,pageOverThenDown:a.pageOverThenDown??!1,repeatRowLabels:a.repeatRowLabels??!1,repeatColLabels:a.repeatColLabels??!1,layout:(r==null||(n=r.fieldsConfig)==null?void 0:n.layout)??t.PivotLayoutTypeEnum.tabular,rowSubtotalPosition:a.rowSubtotalPosition??t.PivotSubtotalPositionEnum.top}});function T(e){let t={unitId:i,subUnitId:o,pivotTableId:l,options:e};return w(t=>({...t,...e})),u.executeCommand(n.SetPivotOptionCommand.id,t).catch(e=>m.error(`[MobilePivotConfigPanel]`,e))}function E(e){let t={unitId:i,subUnitId:o,pivotTableId:l,layout:e};return w(t=>({...t,layout:e})),u.executeCommand(n.SetPivotLayoutCommand.id,t).catch(e=>m.error(`[MobilePivotConfigPanel]`,e))}async function D(e){if(!(b.current||e===S)){b.current=!0,y(!0);try{let r=g.getPivotTableConfig(i,o,l),a=g.getCollection(i,l);if(!r||!a||(Object.values(a.fields).some(t.isDateGroupFieldJSON)||a.customFields.some(t.isDateGroupFieldJSON))&&!await p.confirm({id:`sheet-pivot.confirm.change-date-grouping-mode`,title:{title:h.t(`sheets-pivot-ui.config.dateGroupingSwitchTitle`)},children:{title:h.t(`sheets-pivot-ui.config.dateGroupingSwitchMessage`)},cancelText:h.t(`sheets-pivot-ui.dialog.cancel`),confirmText:h.t(`sheets-pivot-ui.dialog.ok`)})||g.getPivotTableConfig(i,o,l)!==r||g.getCollection(i,l)!==a||(0,t.getPivotDateGroupingMode)(r.fieldsConfig.options)===e)return;await u.executeCommand(n.SetPivotOptionCommand.id,{unitId:i,subUnitId:o,pivotTableId:l,options:{dateGroupingMode:e}})}catch(e){m.error(`[MobilePivotConfigPanel]`,e)}finally{b.current=!1,y(!1)}}}let O=e=>e.map(e=>({...e,label:h.t(e.label)}));return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-5 univer-py-4`,children:[/* @__PURE__ */ (0,f.jsxs)(`section`,{className:`univer-flex univer-flex-col univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-text-sm univer-font-medium univer-text-gray-600`,children:h.t(`sheets-pivot-ui.config.displaySection`)}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-min-h-10 univer-items-center univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-sm`,children:h.t(`sheets-pivot-ui.config.dateGroupingMode`)}),/* @__PURE__ */ (0,f.jsx)(c.MobileSelect,{className:`univer-w-40`,value:S,options:O(Ln),disabled:v,onChange:e=>D(e),size:`small`})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-min-h-10 univer-items-center univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-sm`,children:h.t(`sheets-pivot-ui.config.layout`)}),/* @__PURE__ */ (0,f.jsx)(c.MobileSelect,{className:`univer-w-40`,value:String(C.layout),options:O(Fn),onChange:e=>E(Number(e)),size:`small`})]}),/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:C.repeatRowLabels,disabled:C.layout===t.PivotLayoutTypeEnum.compact,onChange:e=>T({repeatRowLabels:!!e}),children:h.t(`sheets-pivot-ui.config.repeatRowLabels`)}),/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:C.repeatColLabels,onChange:e=>T({repeatColLabels:!!e}),children:h.t(`sheets-pivot-ui.config.repeatColLabels`)})]}),/* @__PURE__ */ (0,f.jsxs)(`section`,{className:`univer-flex univer-flex-col univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-text-sm univer-font-medium univer-text-gray-600`,children:h.t(`sheets-pivot-ui.config.totalsSection`)}),/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:C.showRowSubtotal,onChange:e=>T({showRowSubtotal:!!e}),children:h.t(`sheets-pivot-ui.config.showRowSubtotal`)}),C.layout===t.PivotLayoutTypeEnum.outline&&/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-min-h-10 univer-items-center univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-sm`,children:h.t(`sheets-pivot-ui.config.rowSubtotalPosition`)}),/* @__PURE__ */ (0,f.jsx)(c.MobileSelect,{className:`univer-w-40`,value:String(C.rowSubtotalPosition),options:O(In),onChange:e=>T({rowSubtotalPosition:Number(e)}),size:`small`})]}),/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:C.showRowGrandTotal,onChange:e=>T({showRowGrandTotal:!!e}),children:h.t(`sheets-pivot-ui.config.showRowGrandTotal`)}),/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:C.showColSubtotal,onChange:e=>T({showColSubtotal:!!e}),children:h.t(`sheets-pivot-ui.config.showColSubtotal`)}),/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:C.showColGrandTotal,onChange:e=>T({showColGrandTotal:!!e}),children:h.t(`sheets-pivot-ui.config.showColGrandTotal`)})]}),/* @__PURE__ */ (0,f.jsxs)(`section`,{className:`univer-flex univer-flex-col univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-text-sm univer-font-medium univer-text-gray-600`,children:h.t(`sheets-pivot-ui.config.pageSection`)}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-min-h-10 univer-items-center univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-sm`,children:h.t(`sheets-pivot-ui.config.pageWrap`)}),/* @__PURE__ */ (0,f.jsx)(c.InputNumber,{className:`univer-w-24`,value:C.pageWrap,min:1,max:20,onChange:e=>{let t=Number(e);return Number.isFinite(t)&&t>=1?T({pageWrap:t}):void 0},size:`small`,controls:!1})]}),/* @__PURE__ */ (0,f.jsx)(`p`,{className:`univer-text-xs univer-text-gray-600`,children:h.t(C.pageOverThenDown?`sheets-pivot-ui.config.pageWrapOverThenDownHelp`:`sheets-pivot-ui.config.pageWrapDownThenOverHelp`)}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-min-h-10 univer-items-center univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-sm`,children:h.t(`sheets-pivot-ui.config.pageDirection`)}),/* @__PURE__ */ (0,f.jsx)(c.MobileSelect,{className:`univer-w-40`,value:String(C.pageOverThenDown),options:O(Pn),onChange:e=>T({pageOverThenDown:e===`true`}),size:`small`})]})]})]})}function zn(e,t,n,r){let i=[];return t>0&&i.push(`moveUp`),t<n-1&&i.push(`moveDown`),r?(i.push(e===`column`?`moveToRow`:`moveToColumn`),i.push(`remove`),i):(e!==`filter`&&i.push(`moveToFilter`),e!==`column`&&i.push(`moveToColumn`),e!==`row`&&i.push(`moveToRow`),e===`value`?i.push(`settings`):(i.push(`moveToValue`),i.push(`filter`)),i.push(`remove`),i)}let Bn=[`filter`,`column`,`row`,`value`];function Vn(e,t){switch(t){case`filter`:return e.filterFields;case`column`:return e.columnFields;case`row`:return e.rowFields;case`value`:return e.valueFields;default:return[]}}function Hn(e){switch(e){case`filter`:return`sheets-pivot-ui.filter`;case`column`:return`sheets-pivot-ui.column`;case`row`:return`sheets-pivot-ui.row`;default:return`sheets-pivot-ui.value`}}function Un(e){switch(e){case`filter`:return`sheets-pivot-ui.mobile.filterDesc`;case`column`:return`sheets-pivot-ui.mobile.columnDesc`;case`row`:return`sheets-pivot-ui.mobile.rowDesc`;default:return`sheets-pivot-ui.valueDesc`}}function Wn(e){switch(e.area){case`filter`:return/* @__PURE__ */ (0,f.jsx)(kt,{});case`column`:return/* @__PURE__ */ (0,f.jsx)(Ut,{});case`row`:return/* @__PURE__ */ (0,f.jsx)(Tt,{});default:return/* @__PURE__ */ (0,f.jsx)(jt,{})}}function Gn(e){switch(e){case`moveUp`:return`sheets-pivot-ui.mobile.moveUp`;case`moveDown`:return`sheets-pivot-ui.mobile.moveDown`;case`moveToFilter`:return`sheets-pivot-ui.mobile.moveToFilter`;case`moveToColumn`:return`sheets-pivot-ui.mobile.moveToColumn`;case`moveToRow`:return`sheets-pivot-ui.mobile.moveToRow`;case`moveToValue`:return`sheets-pivot-ui.mobile.moveToValue`;case`filter`:return`sheets-pivot-ui.filterField`;case`settings`:return`sheets-pivot-ui.fieldSettings`;default:return`sheets-pivot-ui.removeField`}}function Kn(e){switch(e){case`moveToFilter`:return`filter`;case`moveToColumn`:return`column`;case`moveToRow`:return`row`;case`moveToValue`:return`value`;default:return null}}function qn(e){let{area:t,field:n,index:i,fieldCount:o,info:s,pivotTableId:l,unitId:u,subUnitId:d,refresh:p}=e,m=(0,a.useDependency)(r.ICommandService),h=(0,a.useDependency)(r.LocaleService),g=n.tableFieldId===Qt,_={pivotTableInfo:s,pivotTableId:l,commandService:m,unitId:u,subUnitId:d};async function v(e){if(e===`filter`){fn(m,u,d,l,n.tableFieldId);return}if(e===`settings`){pn(m,l,n.tableFieldId,u,d,s);return}if(e===`remove`){await an(_,n.tableFieldId,t),await p();return}let r=Kn(e)??t,a=Vn(s,r).length;e===`moveUp`?a=i-1:e===`moveDown`&&(a=i+1),await cn(_,n.tableFieldId,t,r,a),await p()}let y=zn(t,i,o,g).map(e=>({type:`item`,children:h.t(Gn(e)),variant:e===`remove`?`destructive`:`default`,onSelect:()=>v(e)}));return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-min-h-12 univer-items-center univer-gap-3 univer-rounded-xl univer-px-3`,children:[/* @__PURE__ */ (0,f.jsx)(`bdi`,{className:`univer-min-w-0 univer-flex-1 univer-truncate univer-text-sm`,dir:`auto`,children:g?h.t(`sheets-pivot-ui.multipleValue`):n.displayName}),/* @__PURE__ */ (0,f.jsx)(c.MobileDropdownMenu,{items:y,children:/* @__PURE__ */ (0,f.jsx)(`button`,{type:`button`,className:`univer-flex univer-size-10 univer-shrink-0 univer-items-center univer-justify-center univer-rounded-lg univer-border-0 univer-bg-transparent active:univer-bg-gray-100 dark:active:!univer-bg-gray-700`,children:/* @__PURE__ */ (0,f.jsx)(Lt,{})})})]})}function Jn(e){let t=(0,a.useDependency)(r.LocaleService);return/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,children:Bn.map(n=>{let r=Vn(e.info,n);return/* @__PURE__ */ (0,f.jsxs)(`section`,{children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mb-2 univer-flex univer-items-center univer-gap-2 univer-text-sm univer-font-medium`,children:[/* @__PURE__ */ (0,f.jsx)(Wn,{area:n}),t.t(Hn(n))]}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-rounded-xl univer-bg-gray-50 univer-p-1 dark:!univer-bg-gray-800`,children:r.length?r.map((t,i)=>/* @__PURE__ */ (0,f.jsx)(qn,{...e,area:n,field:t,index:i,fieldCount:r.length},t.tableFieldId)):/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-p-4 univer-text-center univer-text-xs univer-text-gray-500`,children:t.t(Un(n))})})]},n)})})}function Yn(e,t){switch(t){case`filter`:return e.filterFields.length;case`column`:return e.columnFields.length;case`row`:return e.rowFields.length;case`value`:return e.valueFields.length;default:return 0}}function Xn(e){let n=`univer-size-4 univer-shrink-0 univer-text-gray-500`;switch(e.type){case t.PivotDataFieldDataTypeEnum.number:return/* @__PURE__ */ (0,f.jsx)(zt,{className:n});case t.PivotDataFieldDataTypeEnum.date:return/* @__PURE__ */ (0,f.jsx)(xt,{className:n});default:return/* @__PURE__ */ (0,f.jsx)(qt,{className:n})}}function Zn(e){let{field:n,info:i,pivotTableId:o,unitId:s,subUnitId:l,refresh:u}=e,d=(0,a.useDependency)(r.ICommandService),p=(0,a.useDependency)(r.LocaleService),m={pivotTableInfo:i,pivotTableId:o,commandService:d,unitId:s,subUnitId:l};async function h(e){if(e){let e=n.type===t.PivotDataFieldDataTypeEnum.number?`value`:`row`;await cn(m,n.dataFieldId,`source`,e,Yn(i,e))}else await an(m,n.dataFieldId,`source`);await u()}async function g(e){await cn(m,n.dataFieldId,`source`,e,Yn(i,e)),await u()}let _=[{type:`item`,children:p.t(`sheets-pivot-ui.addToRow`),onSelect:()=>g(`row`)},{type:`item`,children:p.t(`sheets-pivot-ui.addToColumn`),onSelect:()=>g(`column`)},{type:`item`,children:p.t(`sheets-pivot-ui.addToValue`),onSelect:()=>g(`value`)},{type:`item`,children:p.t(`sheets-pivot-ui.addToFilter`),onSelect:()=>g(`filter`)}];return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-min-h-12 univer-items-center univer-gap-3 univer-rounded-xl univer-px-2`,children:[/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:n.checked,onChange:e=>h(!!e)}),/* @__PURE__ */ (0,f.jsx)(Xn,{type:n.type}),/* @__PURE__ */ (0,f.jsx)(`bdi`,{className:`univer-min-w-0 univer-flex-1 univer-truncate univer-text-sm`,dir:`auto`,children:n.name}),/* @__PURE__ */ (0,f.jsx)(c.MobileDropdownMenu,{items:_,children:/* @__PURE__ */ (0,f.jsx)(`button`,{type:`button`,className:`univer-flex univer-size-10 univer-shrink-0 univer-items-center univer-justify-center univer-rounded-lg univer-border-0 univer-bg-transparent active:univer-bg-gray-100 dark:active:!univer-bg-gray-700`,children:/* @__PURE__ */ (0,f.jsx)(Lt,{})})})]})}function Qn(e){let{info:t}=e,n=(0,a.useDependency)(r.LocaleService),[i,o]=(0,d.useState)(``),s=i.trim().toLocaleLowerCase(),l=s?t.sourceList.filter(e=>e.name.toLocaleLowerCase().includes(s)):t.sourceList;return/* @__PURE__ */ (0,f.jsxs)(`section`,{className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.sourceFieldTile`)}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mt-1 univer-text-xs univer-text-gray-500`,children:n.t(`sheets-pivot-ui.mobile.sourceFieldDescription`)})]}),/* @__PURE__ */ (0,f.jsx)(c.Input,{allowClear:!0,value:i,placeholder:n.t(`sheets-pivot-ui.searchFieldPlaceholder`),slot:/* @__PURE__ */ (0,f.jsx)(Gt,{}),onChange:o,size:`small`}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-rounded-xl univer-bg-gray-50 univer-p-1 dark:!univer-bg-gray-800`,children:l.length?l.map(t=>/* @__PURE__ */ (0,f.jsx)(Zn,{...e,field:t},t.id)):/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-p-4 univer-text-center univer-text-sm univer-text-gray-500`,children:n.t(`sheets-pivot-ui.noMatchingFields`)})})]})}function $n(e){var t;let{sourceRangeInfo:n,positionInfo:i,pivotTableId:o,refresh:s}=e,c=(0,a.useDependency)(r.ICommandService),l=(0,a.useDependency)(r.ILogService),u=(0,a.useDependency)(r.LocaleService),h=(0,a.useDependency)(r.IUniverInstanceService).getUnit(n.unitId),g=(h==null||(t=h.getSheetBySheetId(n.subUnitId))==null?void 0:t.getName())??n.sheetName,[_,v]=(0,d.useState)(n.range),[y,b]=(0,d.useState)(g),[x,S]=(0,d.useState)(``);(0,d.useEffect)(()=>{v(n.range),b(g)},[g,n]);async function C(e){let t=e.split(`,`).filter(Boolean).map(p.deserializeRangeWithSheet)[0];if(!t||!h){S(u.t(`sheets-pivot-ui.msg.emptySourceRange`));return}let r=t.sheetName||n.sheetName,a=h.getSheetBySheetName(r),l=rn(a,t.range);if(l!==2||!a){let e=l===0?`sheets-pivot-ui.msg.emptySourceRange`:`sheets-pivot-ui.msg.invalidSize`;S(u.t(e))}else S(``),v(t.range),b(r),await on(c,o,{unitId:n.unitId,subUnitId:a.getSheetId(),range:t.range,sheetName:r},i.unitId,i.subUnitId),await s()}return/* @__PURE__ */ (0,f.jsxs)(`section`,{children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:u.t(`sheets-pivot-ui.sourceRangeLabel`)}),/* @__PURE__ */ (0,f.jsx)(m.MobileRangeSelector,{unitId:n.unitId,subUnitId:n.subUnitId,initialValue:(0,p.serializeRangeWithSheet)(y,_),maxRangeCount:1,keepSheetReference:!0,supportAcrossSheet:!0,onChange:(e,t)=>C(t).catch(e=>{l.error(`[MobilePivotSourceRange]`,e)})}),x&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mt-2 univer-text-xs univer-text-red-500`,children:x})]})}function er(e){let{pivotTableId:t,version:i,unitId:o,subUnitId:c,panelInfo:l}=e,u=(0,a.useDependency)(n.SheetsPivotTableConfigModel),p=(0,a.useDependency)(n.SheetsPivotRPCService),m=(0,a.useDependency)(r.ILogService),h=(0,d.useMemo)(()=>u.watchPivotTableChanges(o,c,t).pipe((0,s.debounceTime)(0)),[u,o,c,t]),g=(0,a.useObservable)(h),[_,v]=(0,d.useState)(l),y=(0,d.useCallback)(async()=>{if(!u.getPivotTableConfig(o,c,t))return;let e=await p.getPivotDisplayConfig({unitId:o,subUnitId:c,pivotTableId:t,params:{type:n.PivotDisplayDataType.Panel,panel:{pivotTableId:t}}});e.result.panel&&v(e.result.panel)},[u,t,p,c,o]);return(0,d.useEffect)(()=>{y().catch(e=>m.error(`[MobilePivotPanel]`,e))},[g,m,y,i]),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-5 univer-py-4`,children:[/* @__PURE__ */ (0,f.jsx)($n,{sourceRangeInfo:_.sourceRange,positionInfo:_.positionInfo,pivotTableId:t,refresh:y}),/* @__PURE__ */ (0,f.jsx)(Qn,{info:_,pivotTableId:t,unitId:o,subUnitId:c,refresh:y}),/* @__PURE__ */ (0,f.jsx)(Jn,{info:_,pivotTableId:t,unitId:o,subUnitId:c,refresh:y})]})}function tr(e){let{className:t,unitId:n,subUnitId:i,pivotTableId:o}=e,[s,l]=(0,d.useState)(`fields`),u=(0,a.useDependency)(r.LocaleService);return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:(0,c.clsx)(`univer-flex univer-size-full univer-min-h-0 univer-flex-col`,t),dir:u.getDirection(),children:[/* @__PURE__ */ (0,f.jsx)(c.Segmented,{className:`univer-sticky univer-top-0 univer-z-10 univer-my-3 univer-w-full univer-shrink-0`,items:[{label:u.t(`sheets-pivot-ui.fieldPanel`),value:`fields`},{label:u.t(`sheets-pivot-ui.configPanel`),value:`config`}],value:s,onChange:l}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-min-h-0 univer-flex-1 univer-overflow-y-auto`,children:s===`fields`?/* @__PURE__ */ (0,f.jsx)(er,{...e}):/* @__PURE__ */ (0,f.jsx)(Rn,{unitId:n,subUnitId:i,pivotTableId:o})})]})}function nr(e,t){switch(e){case 1:return t.t(`sheets-pivot-ui.msg.invalidSize`);case 0:return t.t(`sheets-pivot-ui.msg.emptySourceRange`);default:return``}}function rr(e){let{unitId:t,subUnitId:i,sourceRange:o,positionRange:s,sourceSheetName:l,positionSheetName:u,onConfirm:h,onCancel:g}=e,_=(0,a.useDependency)(r.LocaleService),v=(0,a.useDependency)(r.IUniverInstanceService).getUnit(t),[y,b]=(0,d.useState)(o),[x,S]=(0,d.useState)(s),[C,w]=(0,d.useState)(l),[T,E]=(0,d.useState)(u),[D,O]=(0,d.useState)(n.PositionType.New),[k,A]=(0,d.useState)(``),[j,M]=(0,d.useState)(!0);(0,d.useEffect)(()=>{let e=rn(v.getSheetBySheetName(C),y);A(nr(e,_))},[_,y,C,v]);function N(e){let t=e.split(`,`).filter(Boolean).map(p.deserializeRangeWithSheet)[0];t?(b(t.range),w(t.sheetName||C)):A(_.t(`sheets-pivot-ui.msg.emptySourceRange`))}function P(e){let t=e.split(`,`).filter(Boolean).map(p.deserializeRangeWithSheet)[0];if(!t){S(null);return}let n=t.sheetName||l;S(t.range),E(n),M(n!==C||!r.Rectangle.intersects(t.range,y))}function F(){if(k)return;let e;if(D===n.PositionType.Existing){if(!x||!j)return;e={sourceRange:y,sourceSheetName:C,positionRange:x,positionSheetName:T,positionType:D}}else e={sourceRange:y,sourceSheetName:C,positionType:D};h(e)}return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-5`,dir:_.getDirection(),children:[/* @__PURE__ */ (0,f.jsxs)(`section`,{children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:_.t(`sheets-pivot-ui.dialog.source.sourceData`)}),/* @__PURE__ */ (0,f.jsx)(m.MobileRangeSelector,{unitId:t,subUnitId:i,initialValue:(0,p.serializeRangeWithSheet)(C,y),maxRangeCount:1,supportAcrossSheet:!0,keepSheetReference:!0,onChange:(e,t)=>N(t)}),k&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mt-2 univer-text-xs univer-text-red-500`,children:k})]}),/* @__PURE__ */ (0,f.jsxs)(`section`,{children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:_.t(`sheets-pivot-ui.dialog.source.position`)}),/* @__PURE__ */ (0,f.jsxs)(c.RadioGroup,{className:`univer-flex univer-flex-col univer-gap-3`,value:D,onChange:e=>O(e),children:[/* @__PURE__ */ (0,f.jsx)(c.Radio,{value:n.PositionType.New,children:_.t(`sheets-pivot-ui.dialog.source.newSheet`)}),/* @__PURE__ */ (0,f.jsx)(c.Radio,{value:n.PositionType.Existing,children:_.t(`sheets-pivot-ui.dialog.source.existingSheet`)})]}),D===n.PositionType.Existing&&/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mt-3`,children:[/* @__PURE__ */ (0,f.jsx)(m.MobileRangeSelector,{unitId:t,subUnitId:i,initialValue:x?(0,p.serializeRangeWithSheet)(T,x):``,maxRangeCount:1,supportAcrossSheet:!0,keepSheetReference:!0,onChange:(e,t)=>P(t)}),!j&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mt-2 univer-text-xs univer-text-red-500`,children:_.t(`sheets-pivot-ui.dialog.source.intersect`)})]})]}),/* @__PURE__ */ (0,f.jsxs)(c.MobileActionRowGroup,{children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{onClick:g,size:`middle`,children:_.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`primary`,onClick:F,size:`middle`,children:_.t(`sheets-pivot-ui.dialog.ok`)})]})]})}let ir=class extends r.Disposable{constructor(e,t){super(),[[A,rr],[_,tr],[y,Nn],[x,Mn],[C,jn],[j,Jt]].forEach(([t,n])=>{this.disposeWithMe(e.register(t,n))}),this.disposeWithMe(t.register({PivotTableIcon:Vt}))}};ir=K([G(0,(0,r.Inject)(a.ComponentManager)),G(1,(0,r.Inject)(a.IconManager))],ir);function ar(e){return{id:N.id,commandId:N.id,type:a.MenuItemType.BUTTON,icon:`PivotTableIcon`,title:`sheets-pivot-ui.title`,tooltip:`sheets-pivot-ui.title`,hidden$:(0,a.getMenuHiddenObservable)(e,r.UniverInstanceType.UNIVER_SHEET),disabled$:(0,o.getObservableWithExclusiveRange$)(e,(0,o.getCurrentRangeDisable$)(e,{workbookTypes:[i.WorkbookEditablePermission],worksheetTypes:[i.WorksheetViewPermission,i.WorksheetPivotTablePermission],rangeTypes:[i.RangeProtectionPermissionViewPoint]}))}}let or={[a.RibbonDataGroup.ORGANIZATION]:{[N.id]:{order:1,gridLayout:{row:2,column:1},menuItemFactory:ar}},[a.ContextMenuPosition.MAIN_AREA]:{[a.ContextMenuGroup.DATA]:{[N.id]:{order:1,menuItemFactory:ar}}}},sr=class extends r.Disposable{constructor(e){super(),e.mergeMenu(or)}};sr=K([G(0,a.IMenuManagerService)],sr);let cr=class extends r.Disposable{constructor(e,t,i,a){super(),this._sidebarService=i,this._dialogService=a,W(this,`_pivotTableId`,null),this.disposeWithMe(e.onCommandExecuted(e=>{e.id===it.id?this._pivotTableId=e.params.pivotTableId:e.id===n.RemovePivotTableMutation.id&&e.params.pivotTableId===this._pivotTableId&&this._closePanel()}));let o=t.getCurrentUnitOfType(r.UniverInstanceType.UNIVER_SHEET);o&&(this.disposeWithMe(o.activeSheet$.pipe((0,s.skip)(1)).subscribe(()=>this._closePanel())),this.disposeWithMe(o.sheetDisposed$.subscribe(()=>this._closePanel()))),this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(e=>{e.id===`UNIVER_SHEET_PIVOT_PANEL_ID`&&e.visible===!1&&(this._pivotTableId=null,this._closeChildDialogs())}))}_closePanel(){this._pivotTableId=null,this._sidebarService.close(v),this._closeChildDialogs()}_closeChildDialogs(){this._dialogService.close(b),this._dialogService.close(S),this._dialogService.close(w)}};cr=K([G(0,r.ICommandService),G(1,r.IUniverInstanceService),G(2,a.ISidebarService),G(3,a.IDialogService)],cr),new Path2D(`M3.30363 3C2.79117 3 2.51457 3.60097 2.84788 3.99024L6.8 8.60593V12.5662C6.8 12.7184 6.8864 12.8575 7.02289 12.9249L8.76717 13.7863C8.96655 13.8847 9.2 13.7396 9.2 13.5173V8.60593L13.1521 3.99024C13.4854 3.60097 13.2088 3 12.6964 3H3.30363Z`);var X=class{static drawNoSetting(e,t,n,r){e.save(),u.Rect.drawWith(e,{radius:2,width:16,height:16,fill:r}),e.lineCap=`square`,e.strokeStyle=n,e.scale(t/16,t/16),e.beginPath(),e.lineWidth=1,e.lineCap=`round`,e.moveTo(3,4),e.lineTo(13,4),e.moveTo(4.5,8),e.lineTo(11.5,8),e.moveTo(6,12),e.lineTo(10,12),e.stroke(),e.restore()}static drawExpand(e,t,n,r,i){let a=(i-t)/2;e.save(),e.fillStyle=r,e.strokeStyle=n,e.beginPath(),e.moveTo(6,a),e.lineTo(4+t-2,a),e.arcTo(4+t,a,4+t,a+2,2),e.lineTo(4+t,a+t-2),e.arcTo(4+t,a+t,4+t-2,a+t,2),e.lineTo(6,a+t),e.arcTo(4,a+t,4,a+t-2,2),e.lineTo(4,a+2),e.arcTo(4,a,6,a,2),e.closePath(),e.stroke(),e.fill(),e.beginPath(),e.moveTo(4+t/2,a+2),e.lineTo(4+t/2,a+t-2),e.moveTo(6,a+t/2),e.lineTo(4+t-2,a+t/2),e.stroke(),e.restore()}static drawCollapse(e,t,n,r,i){let a=(i-t)/2;e.save(),e.fillStyle=r,e.strokeStyle=n,e.beginPath(),e.moveTo(6,a),e.lineTo(4+t-2,a),e.arcTo(4+t,a,4+t,a+2,2),e.lineTo(4+t,a+t-2),e.arcTo(4+t,a+t,4+t-2,a+t,2),e.lineTo(6,a+t),e.arcTo(4,a+t,4,a+t-2,2),e.lineTo(4,a+2),e.arcTo(4,a,6,a,2),e.closePath(),e.fill(),e.stroke(),e.beginPath(),e.moveTo(6,a+t/2),e.lineTo(4+t-2,a+t/2),e.stroke(),e.restore()}static drawIconByPath(e,t,n,r){e.save(),e.strokeStyle=n,e.fillStyle=r,u.Rect.drawWith(e,{radius:2,width:16,height:16,fill:r}),t.forEach(t=>{let r=new Path2D(t);e.fillStyle=n,e.fill(r,`evenodd`)}),e.restore()}};let lr=[`M3.30363 3C2.79117 3 2.51457 3.60097 2.84788 3.99024L6.8 8.60593V12.5662C6.8 12.7184 6.8864 12.8575 7.02289 12.9249L8.76717 13.7863C8.96655 13.8847 9.2 13.7396 9.2 13.5173V8.60593L13.1521 3.99024C13.4854 3.60097 13.2088 3 12.6964 3H3.30363Z`],ur=[`M12.4008 13.1831C12.6907 13.1831 12.9258 12.9481 12.9258 12.6581V4.60873L14.013 5.69597C14.218 5.901 14.5505 5.901 14.7555 5.69597C14.9605 5.49094 14.9605 5.15853 14.7555 4.95351L12.7721 2.97017C12.5671 2.76515 12.2347 2.76515 12.0297 2.97017L10.0463 4.95351C9.84132 5.15853 9.84132 5.49094 10.0463 5.69597C10.2514 5.901 10.5838 5.901 10.7888 5.69597L11.8758 4.60901V12.6581C11.8758 12.9481 12.1108 13.1831 12.4008 13.1831Z`,`M1.28069 4.85447C0.842195 4.33439 1.21191 3.5391 1.89218 3.5391H8.59333C9.2736 3.5391 9.64331 4.33439 9.20482 4.85447L6.51052 8.0501V11.6601C6.51052 12.2245 5.94174 12.6114 5.41683 12.404L4.48092 12.0343C4.1756 11.9136 3.97498 11.6187 3.97498 11.2904V8.0501L1.28069 4.85447Z`],dr=[`M12.4008 2.81641C12.6907 2.81641 12.9258 3.05146 12.9258 3.34141V11.3908L14.013 10.3036C14.218 10.0986 14.5505 10.0986 14.7555 10.3036C14.9605 10.5086 14.9605 10.841 14.7555 11.046L12.7721 13.0294C12.5671 13.2344 12.2347 13.2344 12.0297 13.0294L10.0463 11.046C9.84132 10.841 9.84132 10.5086 10.0463 10.3036C10.2514 10.0986 10.5838 10.0986 10.7888 10.3036L11.8758 11.3905V3.34141C11.8758 3.05146 12.1108 2.81641 12.4008 2.81641Z`,`M1.28069 4.85444C0.842195 4.33435 1.21191 3.53906 1.89218 3.53906H8.59333C9.2736 3.53906 9.64331 4.33435 9.20482 4.85443L6.51052 8.05006V11.6601C6.51052 12.2245 5.94174 12.6113 5.41683 12.404L4.48092 12.0342C4.1756 11.9136 3.97498 11.6186 3.97498 11.2903V8.05006L1.28069 4.85444Z`],fr=[`M11.9003 13.7046C11.9003 13.9969 11.6633 14.2339 11.371 14.2339C11.0787 14.2339 10.8417 13.9969 10.8417 13.7046V3.57272L9.74577 4.66862C9.53906 4.87534 9.20391 4.87534 8.9972 4.66862C8.79048 4.46191 8.79048 4.12676 8.9972 3.92005L10.9969 1.92039C11.2036 1.71368 11.5387 1.71368 11.7454 1.92039L13.7451 3.92005C13.9518 4.12676 13.9518 4.46191 13.7451 4.66862C13.5384 4.87534 13.2032 4.87534 12.9965 4.66862L11.9003 3.57243V13.7046Z`,`M2.69779 10.0113C2.40546 10.0113 2.16847 9.77429 2.16847 9.48196C2.16847 9.18962 2.40546 8.95264 2.69779 8.95264H6.67804C6.89213 8.95264 7.08514 9.0816 7.16707 9.2794C7.249 9.47719 7.20371 9.70486 7.05233 9.85624L3.97569 12.9329H6.67804C6.97038 12.9329 7.20736 13.1699 7.20736 13.4622C7.20736 13.7545 6.97038 13.9915 6.67804 13.9915H2.69779C2.4837 13.9915 2.29069 13.8626 2.20876 13.6648C2.12684 13.467 2.17212 13.2393 2.32351 13.0879L5.40015 10.0113H2.69779Z`,`M5.51638 2.58693C5.23363 1.81542 4.14248 1.81543 3.85973 2.58693L2.13245 7.29995C2.03185 7.57443 2.17281 7.87849 2.4473 7.97909C2.72178 8.07969 3.02584 7.93872 3.12644 7.66424L3.64346 6.25351L3.64504 6.25351H5.73266L6.24968 7.66424C6.35027 7.93872 6.65433 8.07969 6.92882 7.97909C7.2033 7.87849 7.34426 7.57443 7.24367 7.29995L5.51638 2.58693ZM5.34467 5.19487L4.68806 3.40325L4.03144 5.19487H5.34467Z`],pr=[`M11.9003 2.29495C11.9003 2.00261 11.6633 1.76562 11.371 1.76562C11.0787 1.76562 10.8417 2.00261 10.8417 2.29495V12.4268L9.74577 11.3309C9.53906 11.1242 9.20391 11.1242 8.9972 11.3309C8.79048 11.5376 8.79048 11.8727 8.9972 12.0795L10.9969 14.0791C11.2036 14.2858 11.5387 14.2858 11.7454 14.0791L13.7451 12.0795C13.9518 11.8727 13.9518 11.5376 13.7451 11.3309C13.5384 11.1242 13.2032 11.1242 12.9965 11.3309L11.9003 12.4271V2.29495Z`,`M2.69792 10.0113C2.40558 10.0113 2.16859 9.77429 2.16859 9.48196C2.16859 9.18962 2.40558 8.95264 2.69792 8.95264H6.67816C6.89225 8.95264 7.08526 9.0816 7.16719 9.2794C7.24912 9.47719 7.20384 9.70486 7.05245 9.85624L3.97581 12.9329H6.67816C6.9705 12.9329 7.20749 13.1699 7.20749 13.4622C7.20749 13.7545 6.9705 13.9915 6.67816 13.9915H2.69792C2.48383 13.9915 2.29082 13.8626 2.20889 13.6648C2.12696 13.467 2.17224 13.2393 2.32363 13.0879L5.40027 10.0113H2.69792Z`,`M5.5165 2.58693C5.23375 1.81542 4.1426 1.81543 3.85985 2.58693L2.13257 7.29995C2.03197 7.57443 2.17294 7.8785 2.44742 7.97909C2.7219 8.07969 3.02596 7.93872 3.12656 7.66424L3.64358 6.25351L3.64516 6.25351H5.73278L6.2498 7.66424C6.35039 7.93872 6.65446 8.07969 6.92894 7.97909C7.20342 7.8785 7.34438 7.57443 7.24379 7.29995L5.5165 2.58693ZM5.34479 5.19487L4.68818 3.40325L4.03156 5.19487H5.34479Z`],mr=/* @__PURE__ */ new Set([t.PivotCellStyleTypeEnum.FilterAll,t.PivotCellStyleTypeEnum.FilterPartial,t.PivotCellStyleTypeEnum.FilterSingle,t.PivotCellStyleTypeEnum.FilterNoneSortNone,t.PivotCellStyleTypeEnum.FilteredSortAsc,t.PivotCellStyleTypeEnum.FilteredSortDesc,t.PivotCellStyleTypeEnum.FilteredSortNone,t.PivotCellStyleTypeEnum.FilterNoneSortAsc,t.PivotCellStyleTypeEnum.FilterNoneSortDesc]),hr=/* @__PURE__ */ new Set([t.PivotCellStyleTypeEnum.Expand,t.PivotCellStyleTypeEnum.Collapse]),gr=class extends u.Shape{constructor(e,t,n,r){super(e,t),this._commandService=n,this._themeService=r,W(this,`_cellWidth`,0),W(this,`_cellHeight`,0),W(this,`_hovered`,!1),W(this,`_pivotParams`,void 0),this.setShapeProps(t),this.onPointerDown$.subscribeEvent(e=>this.onPointerDown(e)),this.onPointerEnter$.subscribeEvent(()=>this.onPointerEnter()),this.onPointerLeave$.subscribeEvent(()=>this.onPointerLeave())}setShapeProps(e){e.cellHeight!==void 0&&(this._cellHeight=e.cellHeight),e.cellWidth!==void 0&&(this._cellWidth=e.cellWidth),e.pivotParams!==void 0&&(this._pivotParams=e.pivotParams),this.transformByState({width:e.width,height:e.height})}onPointerDown(e){if(e.button===2)return;let{col:r,row:i,unitId:a,subUnitId:o,buttonType:s}=this._pivotParams;mr.has(s)?setTimeout(()=>{this._commandService.executeCommand(tt.id,{row:i,col:r,unitId:a,subUnitId:o})},200):this._commandService.executeCommand(n.SetPivotCollapseCommand.id,{row:i,col:r,unitId:a,subUnitId:o,collapse:s===t.PivotCellStyleTypeEnum.Expand})}onPointerEnter(){this._hovered=!0,this.setCursor(u.CURSOR_TYPE.POINTER),this.makeDirty(!0)}onPointerLeave(){this._hovered=!1,this.setCursor(u.CURSOR_TYPE.DEFAULT),this.makeDirty(!0)}_draw(e){var n,r;if(!((n=this._pivotParams)!=null&&n.buttonType))return;let i=this._themeService.getColorFromTheme(`primary.600`),a=this._themeService.getColorFromTheme(`gray.50`);e.save();let o=new Path2D;o.rect(0,0,this._cellWidth,this._cellHeight),e.clip(o),((r=this._pivotParams)==null?void 0:r.buttonType)===t.PivotCellStyleTypeEnum.Collapse?X.drawExpand(e,12,i,a,this._cellHeight):this._pivotParams.buttonType===t.PivotCellStyleTypeEnum.Expand?X.drawCollapse(e,12,i,a,this._cellHeight):this._pivotParams.buttonType===t.PivotCellStyleTypeEnum.FilterAll||this._pivotParams.buttonType===t.PivotCellStyleTypeEnum.FilterNoneSortNone?X.drawNoSetting(e,16,i,a):this._pivotParams.buttonType===t.PivotCellStyleTypeEnum.FilterPartial||this._pivotParams.buttonType===t.PivotCellStyleTypeEnum.FilterSingle||this._pivotParams.buttonType===t.PivotCellStyleTypeEnum.FilteredSortNone?X.drawIconByPath(e,lr,i,a):this._pivotParams.buttonType===t.PivotCellStyleTypeEnum.FilterNoneSortAsc?X.drawIconByPath(e,fr,i,a):this._pivotParams.buttonType===t.PivotCellStyleTypeEnum.FilterNoneSortDesc?X.drawIconByPath(e,pr,i,a):this._pivotParams.buttonType===t.PivotCellStyleTypeEnum.FilteredSortAsc?X.drawIconByPath(e,ur,i,a):this._pivotParams.buttonType===t.PivotCellStyleTypeEnum.FilteredSortDesc&&X.drawIconByPath(e,dr,i,a),e.restore()}};gr=K([G(2,r.ICommandService),G(3,(0,r.Inject)(r.ThemeService))],gr);let _r=class extends u.Shape{constructor(e,t,n,r){super(e,t),this._commandService=n,this._themeService=r,W(this,`_cellWidth`,void 0),W(this,`_cellHeight`,void 0),W(this,`_pivotParams`,void 0),this._cellWidth=t.cellWidth,this._cellHeight=t.cellHeight,this._pivotParams=t.pivotParams,this.transformByState({width:t.width,height:t.height}),this.onPointerUp$.subscribeEvent(e=>this._handlePointerUp(e))}_handlePointerUp(e){if(e.button===2)return;let{col:r,row:i,unitId:a,subUnitId:o,buttonType:s}=this._pivotParams;if(mr.has(s))return this._commandService.executeCommand(tt.id,{row:i,col:r,unitId:a,subUnitId:o});if(hr.has(s))return this._commandService.executeCommand(n.SetPivotCollapseCommand.id,{row:i,col:r,unitId:a,subUnitId:o,collapse:s===t.PivotCellStyleTypeEnum.Expand})}_draw(e){let n=this._pivotParams.buttonType,r=this._themeService.getColorFromTheme(`primary.600`),i=this._themeService.getColorFromTheme(`gray.50`);e.save();let a=new Path2D;a.rect(0,0,this._cellWidth,this._cellHeight),e.clip(a),e.translate(6,6),n===t.PivotCellStyleTypeEnum.Collapse?X.drawExpand(e,12,r,i,this._cellHeight):n===t.PivotCellStyleTypeEnum.Expand?X.drawCollapse(e,12,r,i,this._cellHeight):n===t.PivotCellStyleTypeEnum.FilterAll||n===t.PivotCellStyleTypeEnum.FilterNoneSortNone?X.drawNoSetting(e,16,r,i):n===t.PivotCellStyleTypeEnum.FilterPartial||n===t.PivotCellStyleTypeEnum.FilterSingle||n===t.PivotCellStyleTypeEnum.FilteredSortNone?X.drawIconByPath(e,lr,r,i):n===t.PivotCellStyleTypeEnum.FilterNoneSortAsc?X.drawIconByPath(e,fr,r,i):n===t.PivotCellStyleTypeEnum.FilterNoneSortDesc?X.drawIconByPath(e,pr,r,i):n===t.PivotCellStyleTypeEnum.FilteredSortAsc?X.drawIconByPath(e,ur,r,i):n===t.PivotCellStyleTypeEnum.FilteredSortDesc&&X.drawIconByPath(e,dr,r,i),e.restore()}};_r=K([G(2,r.ICommandService),G(3,(0,r.Inject)(r.ThemeService))],_r);function vr(e,t,n){let{startX:r,startY:i,endX:a,endY:o}=n;return{left:(t===`filter`?e!==`rtl`:e===`rtl`)?a-16-1:r+1,top:t===`filter`?o-16-1:i+1}}let yr=class extends r.Disposable{constructor(e,t,n,r,i,a,o,s,c,l){super(),this._context=e,this._injector=t,this._adaptorModel=n,this._skeletonManagerService=r,this._configModel=i,this._permissionController=a,this._permissionService=o,this._localeService=s,this._dialogService=c,this._contextMenuController=l,W(this,`_buttonShapes`,[]),this._initContextMenu(),this._initButtonRender(),this._initSkeleton()}dispose(){this._clearButtons(),super.dispose()}_clearButtons(){this._buttonShapes.forEach(e=>e.dispose()),this._buttonShapes.length=0}_initContextMenu(){if(!this._contextMenuController)return;let e=this._contextMenuController.contextMenuInterceptor.intercept(o.MOBILE_CONTEXT_MENU,{handler:(e,t,n)=>{if(e||t.menuPosition!==a.ContextMenuPosition.MAIN_AREA)return n(e);let{col:r,row:i,subUnitId:o,unitId:s}=t;if(r==null||i==null)return n(e);let c=this._adaptorModel.getPivotTableIdByCell(s,o,i,r);return c?(this._openPivotActionPanel(s,o,c,i,r),!0):n(e)}});this.disposeWithMe((0,r.toDisposable)(e))}_openPivotActionPanel(e,t,n,r,a){let o=this._permissionController.permissionCheckWithRanges({workbookTypes:[i.WorkbookEditablePermission],worksheetTypes:[i.WorksheetPivotTablePermission],rangeTypes:[i.RangeProtectionPermissionEditPoint]},[{startRow:r,endRow:r,startColumn:a,endColumn:a}],e,t);this._dialogService.open({id:M,title:{title:this._localeService.t(`sheets-pivot-ui.title`)},children:{label:{name:j,props:{editable:o,pivotTableId:n,subUnitId:t,unitId:e}}},onClose:()=>this._dialogService.close(M)})}_initButtonRender(){this.disposeWithMe((0,s.merge)(this._adaptorModel.viewUpdate$.pipe((0,s.auditTime)(0)),this._skeletonManagerService.currentSkeleton$,this._configModel.pivotConfigChange$,this._permissionService.permissionPointUpdate$.pipe((0,s.auditTime)(100))).subscribe(()=>{let e=this._context.unit,t=this._skeletonManagerService.getCurrentSkeleton();if(!e||!t)return;let n=e.getActiveSheet(),r=e.getUnitId(),a=n.getSheetId(),s=this._localeService.getDirection(),{scene:c}=this._context;this._clearButtons(),this._adaptorModel.getSubUnitPivotMatrix(r,a).forValue((e,n,l)=>{if(!(l!=null&&l.pbt))return;let{startX:u,startY:d,endX:f,endY:p}=(0,o.getCoordByCell)(e,n,c,t),m=f-u,h=p-d;if(h<8||m<8||!this._permissionController.permissionCheckWithRanges({workbookTypes:[i.WorkbookEditablePermission],worksheetTypes:[i.WorksheetViewPermission,i.WorksheetEditPermission,i.WorksheetPivotTablePermission],rangeTypes:[i.RangeProtectionPermissionViewPoint,i.RangeProtectionPermissionEditPoint]},[{startRow:e,endRow:e,startColumn:n,endColumn:n}],r,a))return;let g;if(mr.has(l.pbt))g=`filter`;else if(hr.has(l.pbt))g=`collapse`;else return;let _=vr(s,g,{startX:u,startY:d,endX:f,endY:p}),v={left:_.left-6,top:_.top-6,width:28,height:28,zIndex:5e3,cellWidth:m,cellHeight:h,pivotParams:{row:e,col:n,unitId:r,subUnitId:a,buttonType:l.pbt}},y=`sheets-mobile-pivot-button-${e}-${n}-${r}-${a}`;this._buttonShapes.push(this._injector.createInstance(_r,y,v))}),this._buttonShapes.length&&c.addObjects(this._buttonShapes),c.makeDirty()}))}_initSkeleton(){var e;this.disposeWithMe(this._adaptorModel.markDirty$.subscribe(({unitId:e,subUnitId:t})=>{if(e===this._context.unitId&&(this._skeletonManagerService.makeDirty({sheetId:t}),this._context.unit.getActiveSheet().getSheetId()===t)){var n;this._skeletonManagerService.reCalculate(),(n=this._context.mainComponent)==null||n.makeDirty()}}));let t=this._context.unitId;this._context.unit.getSheets().forEach(e=>{var n;let r=e.getSheetId();(n=this._adaptorModel.getSubUnitPivotRenderCache(t,r))!=null&&n.size&&this._skeletonManagerService.makeDirty({sheetId:r})}),this._skeletonManagerService.reCalculate(),(e=this._context.mainComponent)==null||e.makeDirty()}};yr=K([G(1,(0,r.Inject)(r.Injector)),G(2,(0,r.Inject)(n.SheetsPivotTableAdaptorModel)),G(3,(0,r.Inject)(o.SheetSkeletonManagerService)),G(4,(0,r.Inject)(n.SheetsPivotTableConfigModel)),G(5,(0,r.Inject)(i.SheetPermissionCheckController)),G(6,(0,r.Inject)(r.IPermissionService)),G(7,(0,r.Inject)(r.LocaleService)),G(8,a.IDialogService),G(9,(0,r.Optional)(o.SheetContextMenuMobileRenderController))],yr);let br=class extends r.Disposable{constructor(e,t,n){super(),this._univerInstanceService=e,this._sheetsPivotTableAdaptorModel=t,this._sheetClipboardService=n,this._initialize()}_initialize(){let e=this,t,i;this.disposeWithMe(this._sheetClipboardService.addClipboardHook({id:n.SHEET_PIVOT_TABLE_PLUGIN,onBeforeCopy(n,a){let o=e._univerInstanceService.getUnit(n,r.UniverInstanceType.UNIVER_SHEET);o&&(t=e._sheetsPivotTableAdaptorModel.getSubUnitPivotMatrix(n,a),i=o.getStyles())},onAfterCopy(){t=null,i=null},getCellValueBySpecialMatrix(e,n){if(!t)return;let r=t==null?void 0:t.getValue(e,n);if(r){var a;return{...r,s:i==null?void 0:i.get(r.s),displayV:((a=r.v)==null?void 0:a.toString())||``}}}}))}};br=K([G(0,(0,r.Inject)(r.IUniverInstanceService)),G(1,(0,r.Inject)(n.SheetsPivotTableAdaptorModel)),G(2,o.ISheetClipboardService)],br);let xr=[i.InsertRowCommand.id,i.RemoveColCommand.id,i.RemoveRowCommand.id,i.InsertColCommand.id],Sr=class extends r.Disposable{constructor(e,t,r,i,a,o,s,c,l){var u;super(),this._injector=e,this._univerInstanceService=t,this._sheetsPivotTableAdaptorModel=r,this._sheetInterceptorService=i,this._confirmService=a,this._localeService=o,this._sheetsPivotTableConfigModel=s,this._messageService=c,this._configService=l,W(this,`_defaultOverride`,!1),this._initMoveRangeConfirmCheck(),this._initRowColOperationCheck(),this._defaultOverride=((u=this._configService.getConfig(n.SHEETS_PIVOT_PLUGIN_CONFIG_KEY))==null?void 0:u.defaultOverride)??!1}_initMoveRangeConfirmCheck(){this.disposeWithMe(this._sheetInterceptorService.interceptBeforeCommand({performCheck:async e=>{if(e.id===i.MoveRangeCommand.id){let t=(0,i.getSheetCommandTarget)(this._univerInstanceService);if(!t)return Promise.resolve(!1);let{unitId:r,subUnitId:a}=t,{fromRange:o,toRange:s}=e.params,c=this._sheetsPivotTableConfigModel.getSubUnitPivotConfigs(r,a);if(!(c!=null&&c.size))return Promise.resolve(!0);for(let[e,t]of c){let{targetCellInfo:i}=t,{row:c,col:l}=i,u=c-o.startRow,d=l-o.startColumn,f={row:s.startRow+u,col:s.startColumn+d},p=f.row-i.row,m=f.col-i.col,h=this._sheetsPivotTableAdaptorModel.getPivotItemRenderInfoCache(r,a,e),g=h==null?void 0:h.rangesInfo;if(!g)return Promise.resolve(!0);let _=[];Object.keys(g).forEach(e=>{g[e].forEach(e=>{let t={...e};t.startRow=e.startRow+p,t.endRow=e.endRow+p,t.startColumn=e.startColumn+m,t.endColumn=e.endColumn+m,_.push(t)})});let v=this._sheetInterceptorService.generateMutationsByRanges({unitId:r,subUnitId:a,ranges:_}),y=(0,n.generateSetRangeValueMutations)(this._injector,r,a,_);if(v.redos.length||y.shouldClear){if(this._defaultOverride)return Promise.resolve(!0);{let e=await this._confirmService.confirm({id:`sheet-pivot.confirm.add-sheet-pivot`,title:{title:this._localeService.t(`sheets-pivot-ui.perform.tips`)},children:{title:this._localeService.t(`sheets-pivot-ui.perform.info`)},cancelText:this._localeService.t(`sheets-pivot-ui.perform.cancel`),confirmText:this._localeService.t(`sheets-pivot-ui.perform.confirm`)});return Promise.resolve(e)}}}}return Promise.resolve(!0)}}))}_initRowColOperationCheck(){this.disposeWithMe(this._sheetInterceptorService.interceptBeforeCommand({performCheck:async e=>{if(xr.includes(e.id)){let t=e.params,{range:n}=t,a=(0,i.getSheetCommandTarget)(this._univerInstanceService),o=t.unitId||(a==null?void 0:a.unitId),s=t.subUnitId||(a==null?void 0:a.subUnitId);if(!o||!s)return Promise.resolve(!0);let l=this._sheetsPivotTableConfigModel.getSubUnitPivotConfigs(o,s);if(l!=null&&l.size)for(let[e,t]of l){let t=this._sheetsPivotTableAdaptorModel.getPivotItemRenderInfoCache(o,s,e);if(t!=null&&t.rangesInfo){for(let e of Object.keys(t.rangesInfo))if(t.rangesInfo[e].some(e=>r.Rectangle.intersects(e,n)))return this._messageService.show({type:c.MessageType.Error,content:this._localeService.t(`sheets-pivot-ui.perform.rowColError`)}),Promise.resolve(!1)}}}return Promise.resolve(!0)}}))}};Sr=K([G(0,(0,r.Inject)(r.Injector)),G(1,(0,r.Inject)(r.IUniverInstanceService)),G(2,(0,r.Inject)(n.SheetsPivotTableAdaptorModel)),G(3,(0,r.Inject)(i.SheetInterceptorService)),G(4,(0,r.Inject)(r.IConfirmService)),G(5,(0,r.Inject)(r.LocaleService)),G(6,(0,r.Inject)(n.SheetsPivotTableConfigModel)),G(7,(0,r.Inject)(a.IMessageService)),G(8,(0,r.Inject)(r.IConfigService))],Sr);let Cr=[h.InsertTextCommand.id,g.IMEInputCommand.id,o.SetCellEditVisibleOperation.id],wr=class extends r.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetsSelectionsService=e,this._univerInstanceService=t,this._sheetsPivotTableAdaptorModel=n,this._commandService=r,this._sheetsPivotTableConfigModel=i,this._localeService=a,this._initEditListener()}_initEditListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(Cr.includes(e.id)){var t;let n=(t=this._sheetsSelectionsService.getCurrentLastSelection())==null?void 0:t.primary;if(!n)return;let{actualRow:a,actualColumn:o}=n,s=(0,r.cellToRange)(a,o),c=(0,i.getSheetCommandTarget)(this._univerInstanceService,e.params);if(!c)return;let{unitId:l,subUnitId:u}=c,d=this._sheetsPivotTableConfigModel.getSubUnitPivotConfigs(l,u);if(d!=null&&d.size)for(let[e]of d){let t=this._sheetsPivotTableAdaptorModel.getPivotItemRenderInfoCache(l,u,e);if(t!=null&&t.rangesInfo){for(let e of Object.keys(t.rangesInfo))if(t.rangesInfo[e].some(e=>r.Rectangle.intersects(e,s)))throw new r.CustomCommandExecutionError(this._localeService.t(`sheets-pivot-ui.msg.editCellError`))}}}}))}};wr=K([G(0,(0,r.Inject)(i.SheetsSelectionsService)),G(1,(0,r.Inject)(r.IUniverInstanceService)),G(2,(0,r.Inject)(n.SheetsPivotTableAdaptorModel)),G(3,(0,r.Inject)(r.ICommandService)),G(4,(0,r.Inject)(n.SheetsPivotTableConfigModel)),G(5,(0,r.Inject)(r.LocaleService))],wr);let Tr=class extends r.Disposable{constructor(e,t,n,r){super(),this._sheetsPivotTableAdaptorModel=e,this._formatPainterService=t,this._messageService=n,this._localeService=r,this._initFormatPainterListener()}_initFormatPainterListener(){let e=this._sheetsPivotTableAdaptorModel,t=this._messageService,n=this._localeService;this._formatPainterService.addHook({id:`pivot-format-painter-hook`,onBeforeApply(r){let{redoMutationsInfo:a}=r;for(let r of a)if(r.id===i.AddWorksheetMergeMutation.id){let{unitId:i,subUnitId:a,ranges:o}=r.params;for(let r of o)if(e.getIntersectsPivotTable(i,a,r).length>0)return t.show({type:c.MessageType.Error,content:n.t(`sheets-pivot-ui.msg.mergeCellError`)}),!1}return!0}})}};Tr=K([G(0,(0,r.Inject)(n.SheetsPivotTableAdaptorModel)),G(1,(0,r.Inject)(o.IFormatPainterService)),G(2,(0,r.Inject)(a.IMessageService)),G(3,(0,r.Inject)(r.LocaleService))],Tr);let Er=class extends r.Disposable{constructor(e,t,n){super(),this._sheetPrintInterceptorService=e,this._sheetsPivotTableAdaptorModel=t,this._sheetsPivotTableConfigModel=n,this._initPrintArea()}_initPrintArea(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(e,t,n)=>{let{unitId:i,subUnitId:a}=t,o=(e==null?void 0:e.startRow)??1/0,s=(e==null?void 0:e.endRow)??-1/0,c=(e==null?void 0:e.startColumn)??1/0,l=(e==null?void 0:e.endColumn)??-1/0,u=this._sheetsPivotTableConfigModel.getSubUnitPivotConfigs(i,a);if(!u)return n(e);for(let[e,t]of u){var d;let t=(d=this._sheetsPivotTableAdaptorModel.getPivotItemRenderInfoCache(i,a,e))==null?void 0:d.rangesInfo;t&&Object.values(t).forEach(e=>{e.forEach(e=>{let{startRow:t,endRow:n,startColumn:r,endColumn:i}=e;o=Math.min(t,o),s=Math.max(n,s),c=Math.min(r,c),l=Math.max(i,l)})})}let f={startRow:o,endRow:s,startColumn:c,endColumn:l};return(0,r.isValidRange)(f)?n(f):n(e)}}))}};Er=K([G(0,(0,r.Inject)(o.SheetPrintInterceptorService)),G(1,(0,r.Inject)(n.SheetsPivotTableAdaptorModel)),G(2,(0,r.Inject)(n.SheetsPivotTableConfigModel))],Er);let Dr=class extends r.Disposable{constructor(e,t,n){super(),this._mergeCellController=e,this._univerInstanceService=t,this._sheetsPivotTableConfigModel=n,this._initMenuInterceptor()}_initMenuInterceptor(){this.disposeWithMe(this._mergeCellController.interceptor.intercept(this._mergeCellController.interceptor.getInterceptPoints().MERGE_CELL_INTERCEPTOR_CHECK,{handler:(e,t)=>{let n=(0,i.getSheetCommandTarget)(this._univerInstanceService);if(!n)return e;let{unitId:a,subUnitId:o}=n,s=this._sheetsPivotTableConfigModel.getSubUnitPivotConfigs(a,o),c=[];return s&&s.forEach((e,t)=>{var n;let r=(n=this._sheetsPivotTableConfigModel.getPivotTableRangeInfo(a,o,t))==null?void 0:n.rangeInfo;r&&Object.keys(r).forEach(e=>{let t=r[e];Array.isArray(t)&&c.push(...t)})}),c.length&&t.some(e=>c.some(t=>r.Rectangle.intersects(t,e)))?!0:e}}))}};Dr=K([G(0,(0,r.Inject)(i.MergeCellController)),G(1,(0,r.Inject)(r.IUniverInstanceService)),G(2,(0,r.Inject)(n.SheetsPivotTableConfigModel))],Dr);let Z=class extends r.Plugin{constructor(e=ot,t,n,i,a){super(),this._config=e,this._injector=t,this._commandService=n,this._renderManagerService=i,this._configService=a;let{menu:o,...s}=(0,r.merge)({},ot,this._config);o&&this._configService.setConfig(`menu`,o,{merge:!0}),this._configService.setConfig(at,s),this._registerCommands()}onStarting(){[[ir],[sr],[cr],[Dr],[Sr],[Er],[wr],[Tr],[q],[br]].forEach(e=>this._injector.add(e)),(0,r.touchDependencies)(this._injector,[[ir],[sr],[cr],[q]])}onRendered(){this._registerRenderModules(),(0,r.touchDependencies)(this._injector,[[Sr],[Er],[wr],[Tr],[br]])}onSteady(){(0,r.touchDependencies)(this._injector,[[Dr]])}_registerCommands(){[it,N,tt,nt,F].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerRenderModules(){this.disposeWithMe(this._renderManagerService.registerRenderModule(r.UniverInstanceType.UNIVER_SHEET,[yr]))}};W(Z,`pluginName`,`${n.SHEET_PIVOT_TABLE_PLUGIN}_UI_PLUGIN`),W(Z,`packageName`,$e),W(Z,`version`,et),W(Z,`type`,r.UniverInstanceType.UNIVER_SHEET),Z=K([(0,r.DependentOn)(l.UniverLicensePlugin,u.UniverRenderEnginePlugin,i.UniverSheetsPlugin,n.UniverSheetsPivotTablePlugin,o.UniverSheetsMobileUIPlugin,a.UniverMobileUIPlugin),G(1,(0,r.Inject)(r.Injector)),G(2,r.ICommandService),G(3,u.IRenderManagerService),G(4,r.IConfigService)],Z);let Or=[t.PivotExcelDateGroupUnit.Year,t.PivotExcelDateGroupUnit.Quarter,t.PivotExcelDateGroupUnit.Month,t.PivotExcelDateGroupUnit.Day,t.PivotExcelDateGroupUnit.Hour,t.PivotExcelDateGroupUnit.Minute,t.PivotExcelDateGroupUnit.Second],kr={[t.PivotExcelDateGroupUnit.Year]:`sheets-pivot-ui.dateGroup.year`,[t.PivotExcelDateGroupUnit.Quarter]:`sheets-pivot-ui.dateGroup.quarter`,[t.PivotExcelDateGroupUnit.Month]:`sheets-pivot-ui.dateGroup.month`,[t.PivotExcelDateGroupUnit.Day]:`sheets-pivot-ui.dateGroup.day`,[t.PivotExcelDateGroupUnit.Hour]:`sheets-pivot-ui.dateGroup.hour`,[t.PivotExcelDateGroupUnit.Minute]:`sheets-pivot-ui.dateGroup.minute`,[t.PivotExcelDateGroupUnit.Second]:`sheets-pivot-ui.dateGroup.second`},Ar=`univer-h-8 univer-rounded-md univer-border univer-border-gray-300 univer-bg-gray-0 univer-px-2 univer-text-sm univer-text-gray-900 dark:univer-bg-gray-700 dark:univer-text-gray-0`;function jr({targetFieldName:e,dateSystem:n,grouping:i,onConfirm:o,onCancel:s}){let l=(0,a.useDependency)(r.LocaleService),u=(0,a.useObservable)(l.direction$,l.getDirection()),p=(e,t)=>{let i=e===void 0?null:(0,r.excelSerialToDateTimeParts)(e,{dateSystem:n});if(!i)return{date:``,time:t};let a=e=>String(e).padStart(2,`0`);return{date:`${i.year}-${a(i.month)}-${a(i.day)}`,time:`${a(i.hours)}:${a(i.minutes)}:${a(i.seconds)}`}},[m,h]=(0,d.useState)((i==null?void 0:i.units)??[t.PivotExcelDateGroupUnit.Day]),[g,_]=(0,d.useState)((i==null?void 0:i.autoStart)??!0),[v,y]=(0,d.useState)((i==null?void 0:i.autoEnd)??!0),[b,x]=(0,d.useState)(()=>p(i==null?void 0:i.start,`00:00:00`).date),[S,C]=(0,d.useState)(()=>p(i==null?void 0:i.end,`23:59:59`).date),[w,T]=(0,d.useState)(()=>p(i==null?void 0:i.start,`00:00:00`).time),[E,D]=(0,d.useState)(()=>p(i==null?void 0:i.end,`23:59:59`).time),[O,k]=(0,d.useState)((i==null?void 0:i.daysInterval)??1),[A,j]=(0,d.useState)(!1),M=(0,d.useRef)(!1),N=m.some(e=>e===t.PivotExcelDateGroupUnit.Hour||e===t.PivotExcelDateGroupUnit.Minute||e===t.PivotExcelDateGroupUnit.Second),P=m.length===1&&m[0]===t.PivotExcelDateGroupUnit.Day,F=(e,t,i)=>{let a=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e),o=/^(\d{2}):(\d{2})(?::(\d{2}))?$/.exec(t);return!a||!o?null:(0,r.excelDateTimePartsToSerial)({year:Number(a[1]),month:Number(a[2]),day:Number(a[3]),hours:N?Number(o[1]):i?23:0,minutes:N?Number(o[2]):i?59:0,seconds:N?Number(o[3]??0):i?59:0,fractionalSecond:i?.999:0},{dateSystem:n})},I=g?void 0:F(b,w,!1),L=v?void 0:F(S,E,!0),R=m.length>0&&(g||I!==null)&&(v||L!==null)&&(I==null||L==null||I<=L)&&(!P||Number.isInteger(O)&&O>=1);return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,dir:u,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-text-sm univer-font-medium`,children:e}),/* @__PURE__ */ (0,f.jsxs)(`fieldset`,{children:[/* @__PURE__ */ (0,f.jsx)(`legend`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:l.t(`sheets-pivot-ui.dateGroup.groupBy`)}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-grid univer-grid-cols-2 univer-gap-2`,children:Or.map(e=>/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:m.includes(e),onChange:t=>h(n=>t?Or.filter(t=>t===e||n.includes(t)):n.filter(t=>t!==e)),children:l.t(kr[e])},e))})]}),P&&/* @__PURE__ */ (0,f.jsxs)(`label`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-3 univer-text-sm`,children:[l.t(`sheets-pivot-ui.dateGroup.daysInterval`),/* @__PURE__ */ (0,f.jsx)(c.InputNumber,{className:`univer-w-24`,value:O,min:1,onChange:e=>k(Number(e))})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:g,onChange:e=>_(!!e),children:l.t(`sheets-pivot-ui.dateGroup.autoStart`)}),!g&&/* @__PURE__ */ (0,f.jsxs)(`label`,{className:`univer-flex univer-items-center univer-gap-2 univer-text-sm`,children:[l.t(`sheets-pivot-ui.dateGroup.start`),/* @__PURE__ */ (0,f.jsx)(c.Input,{type:`date`,value:b,onChange:x}),N&&/* @__PURE__ */ (0,f.jsx)(`input`,{className:Ar,type:`time`,step:1,value:w,onChange:e=>T(e.target.value)})]}),/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:v,onChange:e=>y(!!e),children:l.t(`sheets-pivot-ui.dateGroup.autoEnd`)}),!v&&/* @__PURE__ */ (0,f.jsxs)(`label`,{className:`univer-flex univer-items-center univer-gap-2 univer-text-sm`,children:[l.t(`sheets-pivot-ui.dateGroup.end`),/* @__PURE__ */ (0,f.jsx)(c.Input,{type:`date`,value:S,onChange:C}),N&&/* @__PURE__ */ (0,f.jsx)(`input`,{className:Ar,type:`time`,step:1,value:E,onChange:e=>D(e.target.value)})]})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-justify-end univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{onClick:s,children:l.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`primary`,disabled:!R||A,onClick:async()=>{if(!R||M.current)return;let e={units:Or.filter(e=>m.includes(e)),autoStart:g,autoEnd:v};!g&&I!=null&&(e.start=I),!v&&L!=null&&(e.end=L),P&&O>1&&(e.daysInterval=O),M.current=!0,j(!0);try{await o(e)}catch{}finally{M.current=!1,j(!1)}},children:l.t(`sheets-pivot-ui.dialog.ok`)})]})]})}function Mr(e){let n=e.operator===t.ST_PivotFilterOperatorEnum.dateBetween||e.operator===t.ST_PivotFilterOperatorEnum.dateNotBetween,r={type:t.PivotFilterTypeEnum.CustomFilter,operator:e.operator,expected:n?[e.lower,e.upper]:e.lower,useWholeDay:e.useWholeDay};try{return(0,t.compilePivotDateFilter)(r),r}catch{return}}function Nr(e,t){let n=(0,r.excelSerialToDateTimeParts)(e,{dateSystem:t});if(!n||n.day===0||n.year===1900&&n.month===2&&n.day===29)return;let i=new Date(2e3,0,1,12);return i.setFullYear(n.year,n.month-1,n.day),i}function Pr(e,t,n){let i=(0,r.excelDateTimePartsToSerial)({year:t.getFullYear(),month:t.getMonth()+1,day:t.getDate(),hours:0,minutes:0,seconds:0,fractionalSecond:0},{dateSystem:n});return i===null?void 0:i+(e===void 0?0:e-Math.floor(e))}function Fr(e,t){return e===void 0||!Number.isFinite(t.getTime())?e:Math.floor(e)+(t.getHours()*3600+t.getMinutes()*60+t.getSeconds()+t.getMilliseconds()/1e3)/86400}let Ir=[{value:t.ST_PivotFilterOperatorEnum.dateEqual,label:`sheets-pivot-ui.dateFilter.equal`},{value:t.ST_PivotFilterOperatorEnum.dateNotEqual,label:`sheets-pivot-ui.dateFilter.notEqual`},{value:t.ST_PivotFilterOperatorEnum.dateNewerThan,label:`sheets-pivot-ui.dateFilter.after`},{value:t.ST_PivotFilterOperatorEnum.dateNewerThanOrEqual,label:`sheets-pivot-ui.dateFilter.afterOrEqual`},{value:t.ST_PivotFilterOperatorEnum.dateOlderThan,label:`sheets-pivot-ui.dateFilter.before`},{value:t.ST_PivotFilterOperatorEnum.dateOlderThanOrEqual,label:`sheets-pivot-ui.dateFilter.beforeOrEqual`},{value:t.ST_PivotFilterOperatorEnum.dateBetween,label:`sheets-pivot-ui.dateFilter.between`},{value:t.ST_PivotFilterOperatorEnum.dateNotBetween,label:`sheets-pivot-ui.dateFilter.notBetween`}];function Lr({dateSystem:e,defaultDate:n,currentFilter:i,onConfirm:o,onCancel:s}){let l=(0,a.useDependency)(r.LocaleService);(0,a.useObservable)(l.currentLocale$);let u=(0,a.useObservable)(l.direction$,l.getDirection()),[p,m]=(0,d.useState)((i==null?void 0:i.operator)??t.ST_PivotFilterOperatorEnum.dateEqual),h=Array.isArray(i==null?void 0:i.expected)?i.expected[0]:i==null?void 0:i.expected,g=Array.isArray(i==null?void 0:i.expected)?i.expected[1]:void 0,[_,v]=(0,d.useState)(()=>h??n??Pr(void 0,/* @__PURE__ */ new Date,e)),[y,b]=(0,d.useState)(()=>g??h??n??Pr(void 0,/* @__PURE__ */ new Date,e)),[x,S]=(0,d.useState)((i==null?void 0:i.useWholeDay)===!0),[C,w]=(0,d.useState)(!1),[T,E]=(0,d.useState)(!1),D=(0,d.useRef)(!1),O=P(_),k=P(y),A=p===t.ST_PivotFilterOperatorEnum.dateBetween||p===t.ST_PivotFilterOperatorEnum.dateNotBetween,j=Mr({operator:p,lower:O,upper:k,useWholeDay:x}),M=j!==void 0&&i!==void 0&&p===i.operator&&x===(i.useWholeDay===!0)&&r.Tools.diffValue(j.expected,i.expected);async function N(e){if(!D.current){D.current=!0,w(!0),E(!1);try{await o(e)||E(!0)}catch{E(!0)}finally{D.current=!1,w(!1)}}}function P(e){return typeof e==`string`?e.trim()===``?void 0:Number(e):e}function F(e,t){t?b(e):v(e)}function I(t,n){let r=Pr(n?k:O,t,e);n?b(r):v(r)}function L(e,t){let n=t?k:O;if(n===void 0)return;let r=Fr(n,e);t?b(r):v(r)}return/* @__PURE__ */ (0,f.jsxs)(`div`,{dir:u,className:`univer-flex univer-min-w-0 univer-flex-col univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-text-sm univer-font-medium`,children:l.t(`sheets-pivot-ui.dateFilter.title`)}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-1`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-xs`,children:l.t(`sheets-pivot-ui.dateFilter.rule`)}),/* @__PURE__ */ (0,f.jsx)(c.Select,{className:`univer-w-full`,value:String(p),options:Ir.map(e=>({value:String(e.value),label:l.t(e.label)})),onChange:e=>m(Number(e))})]}),(A?[!1,!0]:[!1]).map(t=>{let i=t?k:O,a=i===void 0?void 0:Nr(i,e),o=(t?g:void 0)??h??n,s=o!==void 0&&!Nr(o,e),u=i===void 0?null:(0,r.excelSerialToDateTimeParts)(i,{dateSystem:e}),d=u?new Date(2e3,0,1,u.hours,u.minutes,u.seconds,Math.floor(u.fractionalSecond*1e3)):void 0,p=`sheets-pivot-ui.dateFilter.date`;return A&&(p=t?`sheets-pivot-ui.dateFilter.to`:`sheets-pivot-ui.dateFilter.from`),/* @__PURE__ */ (0,f.jsxs)(`div`,{role:`group`,"aria-label":l.t(p),className:`univer-flex univer-min-w-0 univer-flex-col univer-gap-1`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-xs`,children:l.t(p)}),s?/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-1`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-xs univer-text-gray-500`,children:l.t(`sheets-pivot-ui.dateFilter.serial`)}),/* @__PURE__ */ (0,f.jsx)(c.Input,{value:String((t?y:_)??``),onChange:e=>F(e,t)})]}):/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-wrap univer-items-center univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsx)(c.DatePicker,{value:a,onValueChange:e=>I(e,t)}),!x&&i!==void 0&&/* @__PURE__ */ (0,f.jsx)(c.TimeInput,{value:d,onValueChange:e=>L(e,t)})]})]},String(t))}),/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:x,onChange:e=>S(e===!0),children:l.t(`sheets-pivot-ui.dateFilter.wholeDay`)}),T&&/* @__PURE__ */ (0,f.jsx)(`div`,{role:`alert`,className:`univer-text-xs univer-text-red-500`,children:l.t(`sheets-pivot-ui.dateFilter.failed`)}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-wrap univer-items-center univer-justify-between univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`link`,disabled:C||!i,onClick:()=>N(void 0),children:l.t(`sheets-pivot-ui.dialog.filter.clearFilter`)}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{disabled:C,onClick:s,children:l.t(`sheets-pivot-ui.dialog.filter.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`primary`,disabled:C||!j||M,onClick:()=>N(j),children:l.t(`sheets-pivot-ui.dialog.filter.confirm`)})]})]})]})}function Rr(e){let{dialogId:i=b,filterItemInfo:o,onClose:s,onSetFilter:l,onSetSort:u,onSetDateFilter:p,unitId:m,subUnitId:h}=e,{format:g,filterInfo:_,sortInfo:v}=o,y=o.conditionFilter??_,x=(0,a.useDependency)(r.ICommandService),S=(0,a.useDependency)(r.LocaleService);(0,a.useObservable)(S.currentLocale$);let C=(0,a.useDependency)(a.IDialogService),w=(0,a.useDependency)(r.IUniverInstanceService),T=(0,a.useObservable)(S.direction$,S.getDirection()),E=(0,d.useRef)(!0),[D,O]=(0,d.useState)(!1);(0,d.useEffect)(()=>(E.current=!0,()=>{E.current=!1}),[]);let[k,A]=(0,d.useState)(()=>o?o.checkedItems??(_==null?void 0:_.list)??o.items:[]),[j,M]=(0,d.useState)(()=>o.partialItems??[]),N=j.length===0&&k.length===o.items.length,P=k.length===0&&j.length===0,[F,I]=(0,d.useState)(()=>{if(o)return v==null?void 0:v.type}),L=()=>{E.current&&(E.current=!1,s?s():C.close(i))};if((0,d.useEffect)(()=>{let e=w.getCurrentUnitOfType(r.UniverInstanceType.UNIVER_SHEET);if(!e)return;let t=e.activeSheet$.subscribe(e=>{e&&e.getSheetId()!==h&&E.current&&(E.current=!1,s?s():C.close(i))});return()=>t==null?void 0:t.unsubscribe()},[i,C,s,h,w]),!o)return;let R=()=>{M([]),A(N?[]:o.items)},z=e=>{j.includes(e)?(M(j.filter(t=>t!==e)),A([...k,e])):k.includes(e)?A(k.filter(t=>t!==e)):A([...k,e])},B=async()=>{let{tableFieldId:e,pivotTableId:t}=o;if(e&&t)try{(l?await l(k,N,j):await x.executeCommand(n.SetPivotFilterCommand.id,{unitId:m,subUnitId:h,pivotTableId:t,tableFieldId:e,items:k,partialItems:j,isAll:N}))&&E.current&&L()}catch{}},V=()=>{L()},ee=async()=>{let{tableFieldId:e,pivotTableId:t}=o;if(e&&t){A(o.items),M([]);try{(l?await l(o.items,!0,[],!0):await x.executeCommand(n.SetPivotFilterCommand.id,{unitId:m,subUnitId:h,pivotTableId:t,tableFieldId:e,items:o.items,partialItems:[],isAll:!0,clearAllFilters:!0}))&&E.current&&L()}catch{}}},H=async e=>{let{tableFieldId:t,pivotTableId:r}=o;if(!t||!r)return;let i={type:e};try{(u?await u(i):await x.executeCommand(n.SetPivotSortCommand.id,{unitId:m,subUnitId:h,pivotTableId:r,tableFieldId:t,info:i}))&&E.current&&(I(e),L())}catch{}},te=On(_,{items:o.items,conditionFilter:o.conditionFilter});async function ne(e){if(!E.current)return!1;let t=p?await p(e):await x.executeCommand(n.SetPivotDateFilterCommand.id,{unitId:m,subUnitId:h,pivotTableId:o.pivotTableId,tableFieldId:o.tableFieldId,filterInfo:e});return t&&E.current&&L(),t}if(D){let e=w.getUnit(m),n=o.itemTypes.findIndex(e=>e===t.PivotDataFieldDataTypeEnum.date),i=Number(o.items[n]);return/* @__PURE__ */ (0,f.jsx)(Lr,{dateSystem:(e==null?void 0:e.getDateSystem())??r.DateSystem.Date1900,defaultDate:Number.isFinite(i)?i:void 0,currentFilter:(0,t.isPivotDateFilter)(y)?y:void 0,onConfirm:ne,onCancel:()=>O(!1)})}return/* @__PURE__ */ (0,f.jsxs)(`div`,{dir:T,children:[o.supportsDateFilter&&/* @__PURE__ */ (0,f.jsx)(c.Button,{className:`univer-mb-3 univer-w-full`,onClick:()=>O(!0),children:S.t(`sheets-pivot-ui.dateFilter.title`)}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex`,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:(0,c.clsx)(`univer-flex univer-h-8 univer-w-[140px] univer-flex-1 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-l-md univer-text-center univer-text-sm hover:univer-bg-gray-100 rtl:univer-rounded-l-none rtl:univer-rounded-r-md dark:hover:!univer-bg-gray-700`,c.borderClassName,{"univer-bg-gray-100 dark:!univer-bg-gray-700":F===t.PivotDataFieldSortOperatorEnum.ascending}),onClick:()=>H(t.PivotDataFieldSortOperatorEnum.ascending),children:[/* @__PURE__ */ (0,f.jsx)(yt,{}),S.t(`sheets-pivot-ui.dialog.filter.ascending`)]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:(0,c.clsx)(`univer-flex univer-h-8 univer-w-[140px] univer-flex-1 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-r-md univer-text-center univer-text-sm hover:univer-bg-gray-100 rtl:univer-rounded-l-md rtl:univer-rounded-r-none dark:hover:!univer-bg-gray-700`,c.borderClassName,{"univer-bg-gray-100 dark:!univer-bg-gray-700":F===t.PivotDataFieldSortOperatorEnum.descending}),onClick:()=>H(t.PivotDataFieldSortOperatorEnum.descending),children:[/* @__PURE__ */ (0,f.jsx)(Dt,{}),S.t(`sheets-pivot-ui.dialog.filter.descending`)]})]}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:(0,c.clsx)(`univer-mx-0 univer-mb-4 univer-mt-3 univer-h-[300px] univer-rounded-lg univer-p-2`,c.borderClassName),children:/* @__PURE__ */ (0,f.jsxs)(`div`,{className:(0,c.clsx)(`univer-h-full univer-overflow-y-auto`,c.scrollbarClassName),children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-1 univer-box-border univer-h-7 univer-py-[5px] univer-pl-[22px] univer-pr-1 univer-text-sm rtl:univer-pl-1 rtl:univer-pr-[22px]`,children:/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:N,onChange:R,indeterminate:!N&&(k.length>0||j.length>0),children:S.t(`sheets-pivot-ui.dialog.filter.selectAll`)})}),o.items.map((e,n)=>{var i,a;let s=e,l=(i=o.itemLabels)==null?void 0:i[e],u=(a=o.itemTypes)==null?void 0:a[n],d=$t(e,u);return d?s=S.t(d):l===void 0?u===t.PivotDataFieldDataTypeEnum.date&&g&&(s=r.numfmt.format(g,Number(e))):s=l,/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-1 univer-box-border univer-h-7 univer-py-1 univer-pl-[22px] univer-pr-1 univer-text-sm rtl:univer-pl-1 rtl:univer-pr-[22px]`,children:/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:k.includes(e),indeterminate:j.includes(e),onChange:()=>z(e),contentClassName:`univer-max-w-[200px] univer-truncate`,children:s})},e)})]})}),/* @__PURE__ */ (0,f.jsxs)(c.ActionRow,{className:`univer-flex univer-items-center univer-justify-between`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-cursor-pointer univer-text-xs univer-text-primary-600`,children:/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`link`,disabled:te===`NotFilter`,onClick:ee,children:S.t(`sheets-pivot-ui.dialog.filter.clearFilter`)})}),/* @__PURE__ */ (0,f.jsxs)(c.ActionRow,{className:`univer-flex univer-flex-1 univer-items-center univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{onClick:V,children:S.t(`sheets-pivot-ui.dialog.filter.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`primary`,disabled:P,onClick:B,children:S.t(`sheets-pivot-ui.dialog.filter.confirm`)})]})]})]})}function zr({name:e,onConfirm:t,onCancel:n}){let i=(0,a.useDependency)(r.LocaleService),o=(0,a.useObservable)(i.direction$,i.getDirection()),[s,l]=(0,d.useState)(e),[u,p]=(0,d.useState)(!1),m=(0,d.useRef)(!1);return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,dir:o,children:[/* @__PURE__ */ (0,f.jsxs)(`label`,{className:`univer-flex univer-flex-col univer-gap-2 univer-text-sm`,children:[i.t(`sheets-pivot-ui.manualGroup.name`),/* @__PURE__ */ (0,f.jsx)(c.Input,{value:s,onChange:l})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-justify-end univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{onClick:n,children:i.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`primary`,disabled:!s.trim()||u,onClick:async()=>{if(s.trim()&&!m.current){m.current=!0,p(!0);try{await t(s)}catch{}finally{m.current=!1,p(!1)}}},children:i.t(`sheets-pivot-ui.dialog.ok`)})]})]})}let Br=`univer-flex univer-items-center univer-justify-between univer-gap-3 univer-text-sm`;function Vr({targetFieldName:e,grouping:t,defaults$:n,onConfirm:i,onCancel:o}){let s=(0,a.useDependency)(r.LocaleService),l=(0,a.useObservable)(s.direction$,s.getDirection()),u=(0,a.useObservable)(n),[p,m]=(0,d.useState)((t==null?void 0:t.autoStart)??!0),[h,g]=(0,d.useState)((t==null?void 0:t.autoEnd)??!0),[_,v]=(0,d.useState)((t==null?void 0:t.autoStart)===!1?String(t.start):void 0),[y,b]=(0,d.useState)((t==null?void 0:t.autoEnd)===!1?String(t.end):void 0),[x,S]=(0,d.useState)(t?String(t.interval):void 0),[C,w]=(0,d.useState)(!1),T=(0,d.useRef)(!1),E=e=>e===void 0||!/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i.test(e.trim())?NaN:Number(e),D={autoStart:p,autoEnd:h,start:p?u==null?void 0:u.start:E(_),end:h?u==null?void 0:u.end:E(y),interval:x===void 0||x.trim()===``?(u==null?void 0:u.interval)??0:E(x)},O=!!u&&se(D),k=e=>{!e&&_===void 0&&(u==null?void 0:u.start)!==void 0&&v(String(u.start)),m(e)},A=e=>{!e&&y===void 0&&(u==null?void 0:u.end)!==void 0&&b(String(u.end)),g(e)};return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,dir:l,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-text-sm univer-font-medium`,children:e}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:p,onChange:e=>k(!!e),children:s.t(`sheets-pivot-ui.numberGroup.autoStart`)}),/* @__PURE__ */ (0,f.jsxs)(`label`,{className:Br,children:[s.t(`sheets-pivot-ui.numberGroup.start`),/* @__PURE__ */ (0,f.jsx)(c.Input,{className:`univer-w-32`,value:p?String((u==null?void 0:u.start)??``):_??``,disabled:p,onChange:v})]}),/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:h,onChange:e=>A(!!e),children:s.t(`sheets-pivot-ui.numberGroup.autoEnd`)}),/* @__PURE__ */ (0,f.jsxs)(`label`,{className:Br,children:[s.t(`sheets-pivot-ui.numberGroup.end`),/* @__PURE__ */ (0,f.jsx)(c.Input,{className:`univer-w-32`,value:h?String((u==null?void 0:u.end)??``):y??``,disabled:h,onChange:b})]}),/* @__PURE__ */ (0,f.jsxs)(`label`,{className:Br,children:[s.t(`sheets-pivot-ui.numberGroup.interval`),/* @__PURE__ */ (0,f.jsx)(c.Input,{className:`univer-w-32`,value:x??String((u==null?void 0:u.interval)??``),placeholder:String((u==null?void 0:u.interval)??``),onChange:S})]})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-justify-end univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{onClick:o,children:s.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`primary`,disabled:!O||C,onClick:async()=>{if(O&&!T.current){T.current=!0,w(!0);try{await i(D)}catch{}finally{T.current=!1,w(!1)}}},children:s.t(`sheets-pivot-ui.dialog.ok`)})]})]})}let Hr=({handlePatternChange:e})=>{let t=(0,a.useDependency)(r.LocaleService);return(0,d.useEffect)(()=>{e(``)},[]),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mt-1.5 univer-text-sm univer-leading-5 univer-text-gray-600 dark:!univer-text-gray-200`,children:t.t(`sheets-pivot-ui.dialog.numfmt.generalDesc`)})},Ur=({originPattern:e,handlePatternChange:t})=>{let n=(0,a.useDependency)(r.LocaleService),i=r.currencySymbols.map(e=>({label:e,value:e})),[o,s]=(0,d.useState)(()=>hn(e||``,2)),[l,u]=(0,d.useState)(()=>_n(e??``)||i[0].value);return(0,d.useEffect)(()=>{t(Y(`_("${l}"* #,##0${o>0?`.0`:``}_)`,o))},[]),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mt-5`,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-between`,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-w-[136px]`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.decimalPlaces`)}),/* @__PURE__ */ (0,f.jsx)(c.InputNumber,{className:`univer-box-border univer-h-8`,value:o,max:20,min:0,onChange:e=>{let n=e??0;s(n),t(Y(`_("${l}"* #,##0${n>0?`.0`:``}_)`,n))}})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-w-[136px]`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.currencyTypes`)}),/* @__PURE__ */ (0,f.jsx)(c.Select,{options:i,value:l,onChange:e=>{u(e),t(Y(`_("${e}"* #,##0${o>0?`.0`:``}_)`,o))}})]})]}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mt-1.5 univer-text-sm univer-leading-5 univer-text-gray-600 dark:!univer-text-gray-200`,children:n.t(`sheets-pivot-ui.dialog.numfmt.accountingDesc`)})]})},Wr=({originPattern:e,handlePatternChange:t})=>{let n=(0,a.useDependency)(r.LocaleService),i=r.currencySymbols.map(e=>({label:e,value:e})),[o,s]=(0,d.useState)(()=>hn(e||``,2)),[l,u]=(0,d.useState)(()=>_n(e??``)||i[0].value),p=Zt.map(e=>({label:e.label(l),value:e.suffix(l),color:e.color})),[m,h]=(0,d.useState)(()=>{var t;return((t=p.find(t=>(0,r.isPatternEqualWithoutDecimal)(t.value,e??``)))==null?void 0:t.value)||p[0].value});return(0,d.useEffect)(()=>{t(Y(m,o))},[]),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mt-5`,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-between`,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-w-[136px]`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.decimalPlaces`)}),/* @__PURE__ */ (0,f.jsx)(c.InputNumber,{className:`univer-box-border univer-h-8`,value:o,max:20,min:0,onChange:e=>{e&&(s(e),t(Y(m,e)))}})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-w-[136px]`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.currencyTypes`)}),/* @__PURE__ */ (0,f.jsx)(c.Select,{options:i,value:l,onChange:e=>{u(e);let n=Zt.map(t=>({label:t.label(e),value:t.suffix(e),color:t.color}));h(n[0].value),t(Y(n[0].value,o))}})]})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mt-4`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.negativeNumberTypes`)}),/* @__PURE__ */ (0,f.jsx)(c.SelectList,{className:`univer-rounded-lg univer-p-2`,options:p,value:m,onChange:e=>{h(e),t(Y(e,o))}}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mt-1.5 univer-text-sm univer-leading-5 univer-text-gray-600 dark:!univer-text-gray-200`,children:n.t(`sheets-pivot-ui.dialog.numfmt.currencyDesc`)})]})]})},Gr=({originPattern:e,handlePatternChange:t})=>{let n=(0,a.useDependency)(r.LocaleService),i=Yt.map(e=>({label:e.label,value:e.suffix})),[o,s]=(0,d.useState)(()=>{if(e){let t=i.find(t=>t.value===e);if(t)return t.value}return i[0].value});return(0,d.useEffect)(()=>{t(o)},[]),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mt-5`,children:/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mt-5`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.dateTypes`)}),/* @__PURE__ */ (0,f.jsx)(`div`,{children:/* @__PURE__ */ (0,f.jsx)(c.SelectList,{className:`univer-rounded-lg univer-p-2`,options:i,value:o,onChange:e=>{s(e),t(e)}})}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mt-1.5 univer-text-sm univer-leading-5 univer-text-gray-600 dark:!univer-text-gray-200`,children:n.t(`sheets-pivot-ui.dialog.numfmt.dateDesc`)})]})})},Kr=({originPattern:e,handlePatternChange:t})=>{let n=(0,a.useDependency)(r.LocaleService),[i,o]=(0,d.useState)(()=>hn(e||``,0)),s=Xt.map(e=>({label:e.label,value:e.suffix,color:e.color})),[l,u]=(0,d.useState)(()=>{let t=s.find(t=>(0,r.isPatternEqualWithoutDecimal)(t.value,e||``));return(t==null?void 0:t.value)||s[0].value});return(0,d.useEffect)(()=>{t(Y(l,Number(i||0)))},[]),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mt-5`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-items-center univer-justify-between`,children:/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-w-[136px]`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.decimalPlaces`)}),/* @__PURE__ */ (0,f.jsx)(c.InputNumber,{className:`univer-box-border univer-h-8`,value:i,max:20,min:0,onChange:e=>{e&&(o(e),t(Y(l,Number(e))))}})]})}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mt-4`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.negativeNumberTypes`)}),/* @__PURE__ */ (0,f.jsx)(c.SelectList,{className:`univer-rounded-lg univer-p-2`,options:s,value:l,onChange:e=>{o(hn(e,0)),u(e),t(e)}}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mt-1.5 univer-text-sm univer-leading-5 univer-text-gray-600 dark:!univer-text-gray-200`,children:n.t(`sheets-pivot-ui.dialog.numfmt.thousandthPercentileDesc`)})]})]})},qr=({unitId:e,subUnitId:t,pivotTableId:n,tableFieldId:i,originPattern:o,tableFieldInfo:s,dataFieldInfo:l})=>{let u=(0,a.useDependency)(r.LocaleService),p=(0,a.useDependency)(a.IDialogService),m=u.getDirection(),h=(0,d.useMemo)(()=>[{label:`sheets-pivot-ui.dialog.numfmt.general`,component:Hr,key:`sheet.numfmt.general`},{label:`sheets-pivot-ui.dialog.numfmt.accounting`,component:Ur,key:`sheet.numfmt.accounting`},{label:`sheets-pivot-ui.dialog.numfmt.currency`,component:Wr,key:`sheet.numfmt.currency`},{label:`sheets-pivot-ui.dialog.numfmt.date`,component:Gr,key:`sheet.numfmt.date`},{label:`sheets-pivot-ui.dialog.numfmt.thousandthPercentile`,component:Kr,key:`sheet.numfmt.thousandthPercentile`}].map(e=>({...e,label:u.t(e.label)})),[u]),g=h.map(e=>({label:e.label,value:e.key})),[_,v]=(0,d.useState)(()=>[vn,yn,bn,Sn,wn].reduce((e,t,n)=>e||(t(o??``)?h[n].key:``),``)||h[0].key),[y,b]=(0,d.useState)(o),C=e=>b(e),T=e=>{v(e)},E=r=>({id:S,title:{title:u.t(`sheets-pivot-ui.fieldSettings`)},draggable:!0,mask:!1,maskClosable:!1,width:400,children:{label:x,tableFieldId:i,pivotTableId:n,unitId:e,subUnitId:t,tableFieldInfo:s,dataFieldInfo:l,key:`field-setting-${i||``}`,closeFn:()=>{p.close(S)},format:r?y:``},onClose:()=>{p.close(S)}}),D=()=>{p.close(w);let e=E(!1);p.open(e)};return/* @__PURE__ */ (0,f.jsxs)(`div`,{dir:m,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex`,children:/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mb-5 univer-flex univer-h-6 univer-cursor-pointer univer-items-center univer-text-base univer-font-medium univer-leading-6`,onClick:D,children:[/* @__PURE__ */ (0,f.jsx)(_t,{}),u.t(`sheets-pivot-ui.dialog.numfmt.fieldSetting`)]})}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-h-5 univer-text-sm univer-font-medium univer-leading-5`,children:u.t(`sheets-pivot-ui.dialog.numfmt.formatTypes`)}),/* @__PURE__ */ (0,f.jsx)(`div`,{children:/* @__PURE__ */ (0,f.jsx)(c.Select,{className:`univer-w-full`,value:_,options:g,onChange:e=>T(e)})}),/* @__PURE__ */ (0,f.jsxs)(`div`,{children:[_===`sheet.numfmt.general`&&/* @__PURE__ */ (0,f.jsx)(Hr,{originPattern:o,handlePatternChange:C}),_===`sheet.numfmt.accounting`&&/* @__PURE__ */ (0,f.jsx)(Ur,{originPattern:o,handlePatternChange:C}),_===`sheet.numfmt.currency`&&/* @__PURE__ */ (0,f.jsx)(Wr,{originPattern:o,handlePatternChange:C}),_===`sheet.numfmt.date`&&/* @__PURE__ */ (0,f.jsx)(Gr,{originPattern:o,handlePatternChange:C}),_===`sheet.numfmt.thousandthPercentile`&&/* @__PURE__ */ (0,f.jsx)(Kr,{originPattern:o,handlePatternChange:C})]}),/* @__PURE__ */ (0,f.jsxs)(c.ActionRow,{className:`univer-mt-2 univer-flex univer-justify-end`,children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{onClick:D,children:u.t(`sheets-pivot-ui.dialog.numfmt.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{className:`univer-ml-3 rtl:univer-ml-0 rtl:univer-mr-3`,variant:`primary`,onClick:()=>{p.close(w);let e=E(!0);p.open(e)},children:u.t(`sheets-pivot-ui.dialog.numfmt.confirm`)})]})]})};function Jr(e){var o,s;let{scope:l,report:u,getCurrentReport:p,onChange:m}=e,h=(0,a.useDependency)(r.LocaleService),g=(0,a.useDependency)(r.IConfirmService),_=(0,a.useDependency)(n.SheetsPivotTableService),v=(0,a.useDependency)(r.IPermissionService),y=(0,a.useDependency)(r.ILogService);(0,a.useObservable)(v.permissionPointUpdate$);let[b,x]=(0,d.useState)(!1),S=(0,d.useRef)(!1),C=(0,d.useRef)(!0),w=JSON.stringify(l),T=(0,d.useRef)(w);T.current=w,(0,d.useEffect)(()=>(C.current=!0,()=>{C.current=!1}),[]);let E=b||!u||((o=v.getPermissionPoint(new i.WorkbookEditablePermission(l.unitId).id))==null?void 0:o.value)===!1||((s=v.getPermissionPoint(new i.WorksheetFilterPermission(l.unitId,l.subUnitId).id))==null?void 0:s.value)===!1,D=async e=>{if(S.current||E||!u||u.options.allowMultipleFilters===e)return;S.current=!0,x(!0);let i=r.Tools.deepClone(u);try{if(!e&&(0,t.hasPivotMultipleFilters)(u)){let e=await _.asyncInterceptor.fetchThroughAsyncInterceptors(n.PIVOT_OPTION_FILTER_COORDINATION)({redos:[],undos:[],groups:[],validate:()=>void 0},l);if(!C.current||T.current!==w||!await g.confirm({id:`sheet-pivot.confirm.disable-multiple-filters`,title:{title:h.t(`sheets-pivot-ui.config.multipleFiltersTitle`)},children:{title:h.t(`sheets-pivot-ui.config.multipleFiltersClearWarning`)},cancelText:h.t(`sheets-pivot-ui.dialog.cancel`),confirmText:h.t(`sheets-pivot-ui.dialog.ok`)}))return;e==null||e.validate()}if(!C.current||T.current!==w||!r.Tools.diffValue(i,p()))return;await m(e)}catch(e){y.error(`[PivotFilterOptions]`,e)}finally{S.current=!1,C.current&&x(!1)}};return/* @__PURE__ */ (0,f.jsxs)(`section`,{className:`univer-flex univer-flex-col univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-text-sm univer-font-medium univer-text-gray-600`,children:h.t(`sheets-pivot-ui.config.filteringSection`)}),/* @__PURE__ */ (0,f.jsxs)(`label`,{className:`univer-flex univer-items-start univer-gap-2 univer-text-sm`,children:[/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:(u==null?void 0:u.options.allowMultipleFilters)===!0,disabled:E,onChange:e=>D(!!e)}),/* @__PURE__ */ (0,f.jsx)(`span`,{children:h.t(`sheets-pivot-ui.config.allowMultipleFilters`)})]})]})}let Yr=[{label:`sheets-pivot-ui.config.pageDownThenOver`,value:`false`},{label:`sheets-pivot-ui.config.pageOverThenDown`,value:`true`}],Xr=[{label:`sheets-pivot-ui.config.layoutTabular`,value:String(t.PivotLayoutTypeEnum.tabular)},{label:`sheets-pivot-ui.config.layoutCompact`,value:String(t.PivotLayoutTypeEnum.compact)},{label:`sheets-pivot-ui.config.layoutOutline`,value:String(t.PivotLayoutTypeEnum.outline)}],Zr=[{label:`sheets-pivot-ui.config.rowSubtotalTop`,value:String(t.PivotSubtotalPositionEnum.top)},{label:`sheets-pivot-ui.config.rowSubtotalBottom`,value:String(t.PivotSubtotalPositionEnum.bottom)}],Qr=[{label:`sheets-pivot-ui.config.dateGroupingLegacy`,value:t.PivotDateGroupingMode.Legacy},{label:`sheets-pivot-ui.config.dateGroupingExcelLike`,value:t.PivotDateGroupingMode.ExcelLike}];function $r(e){let{unitId:i,subUnitId:o,pivotTableId:l}=e,u=(0,a.useDependency)(r.ICommandService),p=(0,a.useDependency)(r.IConfirmService),m=(0,a.useDependency)(r.ILogService),h=(0,a.useDependency)(r.LocaleService),g=(0,a.useDependency)(n.SheetsPivotTableConfigModel),_=(0,d.useMemo)(()=>g.watchPivotTableChanges(i,o,l).pipe((0,s.debounceTime)(0)),[g,i,o,l]);(0,a.useObservable)(_);let[v,y]=(0,d.useState)(!1),b=(0,d.useRef)(!1),x=g.getPivotTableConfig(i,o,l),S=(0,t.getPivotDateGroupingMode)(x==null?void 0:x.fieldsConfig.options),[C,w]=(0,d.useState)(()=>{var e,n;let r=g.getPivotTableConfig(i,o,l),a=(r==null||(e=r.fieldsConfig)==null?void 0:e.options)??{};return{showRowSubtotal:a.showRowSubtotal??!0,showRowGrandTotal:a.showRowGrandTotal??!0,showColSubtotal:a.showColSubtotal??!0,showColGrandTotal:a.showColGrandTotal??!0,pageWrap:a.pageWrap??1,pageOverThenDown:a.pageOverThenDown??!1,repeatRowLabels:a.repeatRowLabels??!1,repeatColLabels:a.repeatColLabels??!1,layout:(r==null||(n=r.fieldsConfig)==null?void 0:n.layout)??t.PivotLayoutTypeEnum.tabular,rowSubtotalPosition:a.rowSubtotalPosition??t.PivotSubtotalPositionEnum.top}}),T=e=>{let t={unitId:i,subUnitId:o,pivotTableId:l,options:e};u.executeCommand(n.SetPivotOptionCommand.id,t).catch(e=>m.error(`[PivotConfigPanel]`,e)),w(t=>({...t,...e}))},E=e=>{let t={unitId:i,subUnitId:o,pivotTableId:l,layout:e};u.executeCommand(n.SetPivotLayoutCommand.id,t).catch(e=>m.error(`[PivotConfigPanel]`,e)),w(t=>({...t,layout:e}))},D=async e=>{if(!(b.current||e===S)){b.current=!0,y(!0);try{let r=g.getPivotTableConfig(i,o,l),a=g.getCollection(i,l);if(!r||!a||(Object.values(a.fields).some(t.isDateGroupFieldJSON)||a.customFields.some(t.isDateGroupFieldJSON))&&!await p.confirm({id:`sheet-pivot.confirm.change-date-grouping-mode`,title:{title:h.t(`sheets-pivot-ui.config.dateGroupingSwitchTitle`)},children:{title:h.t(`sheets-pivot-ui.config.dateGroupingSwitchMessage`)},cancelText:h.t(`sheets-pivot-ui.dialog.cancel`),confirmText:h.t(`sheets-pivot-ui.dialog.ok`)})||g.getPivotTableConfig(i,o,l)!==r||g.getCollection(i,l)!==a||(0,t.getPivotDateGroupingMode)(r.fieldsConfig.options)===e)return;await u.executeCommand(n.SetPivotOptionCommand.id,{unitId:i,subUnitId:o,pivotTableId:l,options:{dateGroupingMode:e}})}catch(e){m.error(`[PivotConfigPanel]`,e)}finally{b.current=!1,y(!1)}}};return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-4 univer-py-4`,children:[/* @__PURE__ */ (0,f.jsx)(Jr,{scope:{unitId:i,subUnitId:o,pivotTableId:l},report:x==null?void 0:x.fieldsConfig,getCurrentReport:()=>{var e;return(e=g.getPivotTableConfig(i,o,l))==null?void 0:e.fieldsConfig},onChange:e=>u.executeCommand(n.SetPivotOptionCommand.id,{unitId:i,subUnitId:o,pivotTableId:l,options:{allowMultipleFilters:e}})}),/* @__PURE__ */ (0,f.jsxs)(`section`,{children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-600`,children:h.t(`sheets-pivot-ui.config.displaySection`)}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-sm univer-text-gray-600`,children:h.t(`sheets-pivot-ui.config.dateGroupingMode`)}),/* @__PURE__ */ (0,f.jsx)(c.Select,{className:`univer-w-36`,value:S,options:Qr.map(e=>({...e,label:h.t(e.label)})),disabled:v,onChange:e=>D(e)})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-sm univer-text-gray-600`,children:h.t(`sheets-pivot-ui.config.layout`)}),/* @__PURE__ */ (0,f.jsx)(c.Select,{className:`univer-w-36`,value:String(C.layout),options:Xr.map(e=>({...e,label:h.t(e.label)})),onChange:e=>E(Number(e))})]}),/* @__PURE__ */ (0,f.jsxs)(`label`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-text-sm univer-text-gray-600`,children:[/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:C.repeatRowLabels,disabled:C.layout===t.PivotLayoutTypeEnum.compact,onChange:e=>T({repeatRowLabels:!!e})}),h.t(`sheets-pivot-ui.config.repeatRowLabels`)]}),/* @__PURE__ */ (0,f.jsxs)(`label`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-text-sm univer-text-gray-600`,children:[/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:C.repeatColLabels,onChange:e=>T({repeatColLabels:!!e})}),h.t(`sheets-pivot-ui.config.repeatColLabels`)]})]})]}),/* @__PURE__ */ (0,f.jsxs)(`section`,{children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:(0,c.clsx)(`univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-600`),children:h.t(`sheets-pivot-ui.config.totalsSection`)}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsxs)(`label`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-text-sm univer-text-gray-600`,children:[/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:C.showRowSubtotal,onChange:e=>T({showRowSubtotal:!!e})}),h.t(`sheets-pivot-ui.config.showRowSubtotal`)]}),C.layout===t.PivotLayoutTypeEnum.outline&&/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-sm univer-text-gray-600`,children:h.t(`sheets-pivot-ui.config.rowSubtotalPosition`)}),/* @__PURE__ */ (0,f.jsx)(c.Select,{className:`univer-w-36`,value:String(C.rowSubtotalPosition),options:Zr.map(e=>({...e,label:h.t(e.label)})),onChange:e=>T({rowSubtotalPosition:Number(e)})})]}),/* @__PURE__ */ (0,f.jsxs)(`label`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-text-sm univer-text-gray-600`,children:[/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:C.showRowGrandTotal,onChange:e=>T({showRowGrandTotal:!!e})}),h.t(`sheets-pivot-ui.config.showRowGrandTotal`)]}),/* @__PURE__ */ (0,f.jsxs)(`label`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-text-sm univer-text-gray-600`,children:[/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:C.showColSubtotal,onChange:e=>T({showColSubtotal:!!e})}),h.t(`sheets-pivot-ui.config.showColSubtotal`)]}),/* @__PURE__ */ (0,f.jsxs)(`label`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-text-sm univer-text-gray-600`,children:[/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:C.showColGrandTotal,onChange:e=>T({showColGrandTotal:!!e})}),h.t(`sheets-pivot-ui.config.showColGrandTotal`)]})]})]}),/* @__PURE__ */ (0,f.jsxs)(`section`,{children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-600`,children:h.t(`sheets-pivot-ui.config.pageSection`)}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-sm univer-text-gray-600`,children:h.t(`sheets-pivot-ui.config.pageWrap`)}),/* @__PURE__ */ (0,f.jsx)(c.InputNumber,{className:`univer-w-24`,value:C.pageWrap,min:1,max:20,onChange:e=>{let t=Number(e);Number.isFinite(t)&&t>=1&&T({pageWrap:t})}})]}),/* @__PURE__ */ (0,f.jsx)(`p`,{className:`univer-text-xs univer-text-gray-600`,children:h.t(C.pageOverThenDown?`sheets-pivot-ui.config.pageWrapOverThenDownHelp`:`sheets-pivot-ui.config.pageWrapDownThenOverHelp`)}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-sm univer-text-gray-600`,children:h.t(`sheets-pivot-ui.config.pageDirection`)}),/* @__PURE__ */ (0,f.jsx)(c.Select,{className:`univer-w-36`,value:String(C.pageOverThenDown),options:Yr.map(e=>({...e,label:h.t(e.label)})),onChange:e=>T({pageOverThenDown:e===`true`})})]})]})]})]})}let Q=class extends r.Disposable{constructor(e,t,n,r,i,a,o,c){super(),this._sheetsSelectionsService=e,this._univerInstanceService=t,this._sheetsPivotTableAdaptorModel=n,this._commandService=r,this._sidebarService=i,this._dialogService=a,this._injector=o,this._permissionService=c,W(this,`_pivotTableId`,void 0),W(this,`_pivotTablePanelVisible$`,new s.Subject),W(this,`pivotTablePanelVisible$`,this._pivotTablePanelVisible$.asObservable()),W(this,`_isRangeSelectorFocus`,!1),W(this,`_isRangeSelector2Focus`,!1),this._initPanelOpen(),this._initSheetChange()}setIsRangeSelectorFocus(e){this._isRangeSelectorFocus=e}setIsRangeSelector2Focus(e){this._isRangeSelector2Focus=e}_setPivotTableId(e){this._pivotTableId=e}_closePivotPanel(){this._isRangeSelectorFocus||this._isRangeSelector2Focus||(this._setPivotTableId(void 0),this._sidebarService.close(v))}_initPanelOpen(){let e=this._univerInstanceService.getCurrentUnitOfType(r.UniverInstanceType.UNIVER_SHEET);if(e){let t=e.activeSheet$;this.disposeWithMe((0,s.merge)(t,this._sheetsSelectionsService.selectionMoveEnd$).subscribe(()=>{let e=this._sheetsSelectionsService.getCurrentSelections();if(!e)return;let t=e[e.length-1];if(!t)return;let a=t.primary;if(!a)return;let o=this._univerInstanceService.getCurrentUnitOfType(r.UniverInstanceType.UNIVER_SHEET),s=o==null?void 0:o.getActiveSheet();if(!o||!s)return;let c=o.getUnitId(),l=s.getSheetId(),u=this._sheetsPivotTableAdaptorModel.getPivotTableIdByCell(c,l,a.startRow,a.startColumn);if(u){var d,f;let e=(d=this._sheetsPivotTableAdaptorModel.getPivotItemRenderInfoCache(c,l,u))==null?void 0:d.rangesInfo,t=(0,n.unionPivotViewRange)(e),r=(0,i.checkRangesEditablePermission)(this._injector,c,l,t),a=(f=this._permissionService.getPermissionPoint(new i.WorksheetPivotTablePermission(c,l).id))==null?void 0:f.value;if(!r||!a)return;this._setPivotTableId(u),this._pivotTablePanelVisible$.next(!0),this._commandService.executeCommand(it.id,{pivotTableId:u})}else this._closePivotPanel()})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{e.id===n.RemovePivotTableMutation.id&&e.params.pivotTableId===this._pivotTableId&&this._sidebarService.close(v)}))}}_initSheetChange(){let e=this._univerInstanceService.getCurrentUnitOfType(r.UniverInstanceType.UNIVER_SHEET);e&&this.disposeWithMe(e.sheetDisposed$.subscribe(()=>{this._sidebarService.close()})),this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(e=>{if(e.id===`UNIVER_SHEET_PIVOT_PANEL_ID`){let t=!!e.visible;this._pivotTablePanelVisible$.next(t),t||this._dialogService.close(S)}})),this.disposeWithMe(this._dialogService.getDialogs$().subscribe(e=>{let t=e.find(e=>e.id===A);t&&t.open===!1&&this._dialogService.close(A)}))}};Q=K([G(0,(0,r.Inject)(i.SheetsSelectionsService)),G(1,(0,r.Inject)(r.IUniverInstanceService)),G(2,(0,r.Inject)(n.SheetsPivotTableAdaptorModel)),G(3,(0,r.Inject)(r.ICommandService)),G(4,(0,r.Inject)(a.ISidebarService)),G(5,(0,r.Inject)(a.IDialogService)),G(6,(0,r.Inject)(r.Injector)),G(7,(0,r.Inject)(r.IPermissionService))],Q);let ei=(0,d.createContext)(null),ti=(0,d.createContext)(null);function ni(e,t){return e===t?!0:!e||!t?!1:e.droppableId===t.droppableId&&e.index===t.index}function ri(e){if(!(e instanceof Element))return null;let t=e.closest(`[data-univer-dnd-droppable-id]`);return t instanceof HTMLElement?t:null}function ii(e,t,n,r){let i=Array.from(e.querySelectorAll(`[data-univer-dnd-item="true"]`)).filter(e=>{let t=e.dataset.univerDndId;return t?t!==n.draggableId||n.source.droppableId!==r:!1});if(!i.length)return 0;for(let e=0;e<i.length-1;e++){let n=i[e].getBoundingClientRect();if(t<n.top+n.height/2)return e}let a=i.length-1,o=i[a].getBoundingClientRect();return t<o.top+o.height*.35?a:i.length}function ai(){let e=(0,d.useContext)(ei);if(!e)throw Error(`Draggable/Droppable must be used inside DragDropContext`);return e}function oi(e){let{children:t,onDragEnd:n,onDragStart:r,onDragUpdate:i}=e,[a,o]=(0,d.useState)(null),s=(0,d.useRef)(null),c=(0,d.useCallback)((e,t)=>{let n={draggableId:e,source:t,destination:null};s.current=n,o(n),r==null||r({draggableId:e,source:t}),i==null||i({draggableId:e,source:t,destination:null})},[r,i]),l=(0,d.useCallback)(e=>{let t=s.current;if(!t||ni(t.destination,e))return;let n={...t,destination:e};s.current=n,o(n),i==null||i({draggableId:n.draggableId,source:n.source,destination:n.destination})},[i]),u=(0,d.useCallback)(async(e,t)=>{let r=s.current;r&&(s.current=null,o(null),await(n==null?void 0:n({draggableId:r.draggableId,source:r.source,destination:t===void 0?r.destination:t,reason:e})))},[n]);(0,d.useEffect)(()=>{if(!a)return;let e=e=>{let t=ri(e.target);t&&t.dataset.univerDndDropDisabled!==`true`||l(null)};return window.addEventListener(`dragover`,e,!0),()=>{window.removeEventListener(`dragover`,e,!0)}},[a,l]);let p=(0,d.useMemo)(()=>({activeDrag:a,startDrag:c,updateDestination:l,endDrag:u}),[a,c,l,u]);return/* @__PURE__ */ (0,f.jsx)(ei.Provider,{value:p,children:t})}function si(e){var t;let{children:n,droppableId:r,isDropDisabled:i=!1}=e,{activeDrag:a,updateDestination:o,endDrag:s}=ai(),c=(0,d.useRef)(null),l={innerRef:(0,d.useCallback)(e=>{c.current=e},[]),droppableProps:{onDragOver:(0,d.useCallback)(e=>{if(!a||i||!c.current)return;e.preventDefault();let t=ii(c.current,e.clientY,a,r);o({droppableId:r,index:t})},[a,i,r,o]),onDrop:(0,d.useCallback)(e=>{var t;if(!a||i||!c.current)return;e.preventDefault();let n=(((t=a.destination)==null?void 0:t.droppableId)===r?a.destination:null)??{droppableId:r,index:ii(c.current,e.clientY,a,r)};return s(`DROP`,n)},[a,s,i,r]),"data-univer-dnd-droppable-id":r,"data-univer-dnd-drop-disabled":String(i)},placeholder:null},u={isDraggingOver:!!(a&&((t=a.destination)==null?void 0:t.droppableId)===r)};return/* @__PURE__ */ (0,f.jsx)(ti.Provider,{value:r,children:n(l,u)})}function ci(e){var t;let{children:n,draggableId:r,index:i,isDragDisabled:a=!1}=e,{activeDrag:o,startDrag:s,updateDestination:c,endDrag:l}=ai(),u=(0,d.useContext)(ti),f=(0,d.useRef)(null),p=(0,d.useRef)(null),m=(0,d.useRef)(!1),h=(0,d.useRef)(null),g=(0,d.useRef)(null),_=(0,d.useRef)(!1),v=(0,d.useRef)(null),y=(0,d.useRef)(null),b=(0,d.useRef)(null),x=(0,d.useCallback)(e=>{f.current=e},[]),S=(o==null?void 0:o.draggableId)===r,C=(0,d.useCallback)(()=>{g.current&&=(window.clearTimeout(g.current),null)},[]),w=(0,d.useCallback)(()=>{C(),b.current=null,h.current&&=(h.current(),null),v.current&&=(v.current.remove(),null),y.current=null,m.current=!1},[C]);(0,d.useEffect)(()=>w,[w]);let T=(0,d.useCallback)((e,t)=>{if(v.current)return;let n=f.current;if(!n)return;let r=n.getBoundingClientRect(),i=e>0?Math.max(0,e-r.left):12,a=t>0?Math.max(0,t-r.top):12,o=n.cloneNode(!0);if(!(o instanceof HTMLDivElement))return;let s=o;s.style.position=`fixed`,s.style.left=`0px`,s.style.top=`0px`,s.style.width=`${r.width}px`,s.style.height=`${r.height}px`,s.style.pointerEvents=`none`,s.style.opacity=`0.9`,s.style.zIndex=`2147483647`,s.style.boxSizing=`border-box`,s.style.transform=`translate(${Math.max(0,e-i)}px, ${Math.max(0,t-a)}px)`,document.body.appendChild(s),v.current=s,y.current={x:i,y:a}},[]),E=(0,d.useCallback)((e,t)=>{let n=v.current,r=y.current;n&&r&&(n.style.transform=`translate(${Math.max(0,e-r.x)}px, ${Math.max(0,t-r.y)}px)`)},[]),D=(0,d.useCallback)((e,t)=>{let n=ri(document.elementFromPoint(e,t));if(!n||n.dataset.univerDndDropDisabled===`true`)return null;let a=n.dataset.univerDndDroppableId;return a?{droppableId:a,index:ii(n,t,{draggableId:r,source:{droppableId:u??``,index:i},destination:null},a)}:null},[r,u,i]),O=(0,d.useCallback)((e,t,n,o)=>{if(m.current||_.current||a||!u)return;m.current=!0,C(),_.current=!1;try{var l;(l=f.current)==null||l.setPointerCapture(t)}catch{}T(n,o),s(r,{droppableId:u,index:i});let d=D(n,o);c(d);try{e.preventDefault()}catch{}},[C,r,u,i,a,T,D,s,c]),k=(0,d.useCallback)(e=>{if(a||!u||e.pointerType===`mouse`&&e.button!==0)return;_.current=!1;let t=e.pointerId;b.current={pointerId:t,pointerType:e.pointerType,startX:e.clientX,startY:e.clientY},C(),e.pointerType!==`mouse`&&(g.current=window.setTimeout(()=>{let n=b.current;n&&n.pointerId===t&&O(e.nativeEvent,n.pointerId,n.startX,n.startY)},150));let n=e=>{let t=b.current;if(!t||e.pointerId!==t.pointerId)return;if(!m.current){if(_.current){w();return}if(t.pointerType===`mouse`){let n=e.clientX-t.startX,r=e.clientY-t.startY;n*n+r*r>=16&&O(e,t.pointerId,e.clientX,e.clientY)}return}E(e.clientX,e.clientY);let n=D(e.clientX,e.clientY);c(n);try{e.preventDefault()}catch{}},r=e=>{let t=b.current;if(!t||e.pointerId!==t.pointerId)return;let n=m.current?D(e.clientX,e.clientY):null,r=m.current?l(n?`DROP`:`CANCEL`,n):Promise.resolve();return w(),r};window.addEventListener(`pointermove`,n,{capture:!0,passive:!1}),window.addEventListener(`pointerup`,r,{capture:!0}),window.addEventListener(`pointercancel`,r,{capture:!0}),h.current=()=>{window.removeEventListener(`pointermove`,n,!0),window.removeEventListener(`pointerup`,r,!0),window.removeEventListener(`pointercancel`,r,!0)}},[w,C,u,l,a,D,O,c,E]),A=(0,d.useCallback)(e=>{let t=e.dataTransfer;if(!t||typeof t.setDragImage!=`function`)return;let n=e.currentTarget,r=n.cloneNode(!0);if(!(r instanceof HTMLDivElement))return;let i=r;i.style.position=`fixed`,i.style.left=`-9999px`,i.style.top=`-9999px`,i.style.width=`${n.getBoundingClientRect().width}px`,i.style.pointerEvents=`none`,i.style.opacity=`0.95`,i.style.zIndex=`2147483647`,document.body.appendChild(i);let a=n.getBoundingClientRect(),o=e.clientX>0?Math.max(0,e.clientX-a.left):12,s=e.clientY>0?Math.max(0,e.clientY-a.top):12;t.setDragImage(i,o,s),p.current&&p.current!==i&&p.current.remove(),p.current=i},[]),j=(0,d.useCallback)(e=>{if(m.current||a||!u){e.preventDefault();return}_.current=!0,C(),b.current=null,h.current&&=(h.current(),null);let t=e.dataTransfer;if(t){try{t.effectAllowed=`move`}catch{}try{t.setData(`text/plain`,r)}catch{}}try{A(e)}catch{}s(r,{droppableId:u,index:i})},[A,C,r,u,i,a,s]),M=(0,d.useCallback)(()=>(p.current&&=(p.current.remove(),null),l(`CANCEL`,null)),[l]);return n({innerRef:x,draggableProps:{draggable:!a,onDragStart:j,onDragEnd:M,style:S?{opacity:1}:void 0,"data-univer-dnd-item":`true`,"data-univer-dnd-id":r,"data-univer-dnd-index":String(i)},dragHandleProps:{onPointerDown:k}},{isDragging:S,draggingOver:o==null||(t=o.destination)==null?void 0:t.droppableId})}function li(e,t){switch(e){case`filter`:return t.t(`sheets-pivot-ui.filter`);case`row`:return t.t(`sheets-pivot-ui.row`);case`column`:return t.t(`sheets-pivot-ui.column`);case`value`:return t.t(`sheets-pivot-ui.value`)}}function ui(e){switch(e){case`filter`:return/* @__PURE__ */ (0,f.jsx)(kt,{className:`univer-flex univer-flex-row univer-gap-4`});case`row`:return/* @__PURE__ */ (0,f.jsx)(Tt,{className:`univer-flex univer-flex-row univer-gap-4`});case`column`:return/* @__PURE__ */ (0,f.jsx)(Ut,{className:`univer-flex univer-flex-row univer-gap-4`});case`value`:return/* @__PURE__ */ (0,f.jsx)(jt,{className:`univer-flex univer-flex-row univer-gap-4`})}}function di(e){switch(e){case`filter`:return/* @__PURE__ */ (0,f.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`32`,height:`32`,viewBox:`0 0 32 32`,fill:`none`,children:[/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M4.99957 1.875C2.84556 1.875 1.67491 4.3932 3.06336 6.04001L11.5946 16.1587V26.4187C11.5946 27.4582 12.2298 28.3922 13.1966 28.7741L16.1601 29.9449C17.8221 30.6015 19.6232 29.3766 19.6232 27.5895V16.1587L28.1544 6.04C29.5428 4.3932 28.3722 1.875 26.2182 1.875H4.99957Z`,fill:`#ECECEC`}),/* @__PURE__ */ (0,f.jsx)(`rect`,{x:`21.9404`,y:`17.8544`,width:`7.59766`,height:`2.2793`,rx:`1.13965`,fill:`#274FEE`}),/* @__PURE__ */ (0,f.jsx)(`rect`,{x:`21.9404`,y:`21.9067`,width:`7.59766`,height:`2.2793`,rx:`1.13965`,fill:`#274FEE`}),/* @__PURE__ */ (0,f.jsx)(`rect`,{x:`21.9404`,y:`25.959`,width:`7.59766`,height:`2.2793`,rx:`1.13965`,fill:`#274FEE`})]});case`row`:return/* @__PURE__ */ (0,f.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`32`,height:`32`,viewBox:`0 0 32 32`,fill:`none`,children:[/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M2 12.3661C2 12.0347 2.26863 11.7661 2.6 11.7661H9.24705C9.57842 11.7661 9.84705 12.0347 9.84705 12.3661V29.278C9.84705 29.6093 9.57842 29.878 9.24705 29.878H4C2.89543 29.878 2 28.9825 2 27.878V12.3661Z`,fill:`#D8D8D8`}),/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M2 4.0863C2 2.98173 2.89543 2.0863 4 2.0863H9.24705C9.57842 2.0863 9.84705 2.35493 9.84705 2.6863V8.73981C9.84705 9.07118 9.57842 9.33981 9.24705 9.33981H2.6C2.26863 9.33981 2 9.07118 2 8.73981V4.0863Z`,fill:`#D8D8D8`}),/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M12.2983 12.4011C12.2982 12.0697 12.5669 11.8009 12.8983 11.8009L29.3931 11.8009C29.7243 11.8009 29.9929 12.0694 29.9931 12.4007L29.9993 27.9129C29.9997 29.0178 29.1042 29.9137 27.9993 29.9137H12.9051C12.5738 29.9137 12.3053 29.6452 12.3051 29.314L12.2983 12.4011Z`,fill:`#ECECEC`}),/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M12.2517 2.6863C12.2517 2.35493 12.5203 2.0863 12.8517 2.0863H27.9582C29.0628 2.0863 29.9582 2.98173 29.9582 4.0863V8.73627C29.9582 9.06764 29.6896 9.33627 29.3582 9.33627H12.8517C12.5203 9.33627 12.2517 9.06764 12.2517 8.73627L12.2517 2.6863Z`,fill:`#274FEE`})]});case`column`:return/* @__PURE__ */ (0,f.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`32`,height:`32`,viewBox:`0 0 32 32`,fill:`none`,children:[/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M2 12.3661C2 12.0347 2.26863 11.7661 2.6 11.7661H9.24705C9.57842 11.7661 9.84705 12.0347 9.84705 12.3661V29.278C9.84705 29.6093 9.57842 29.878 9.24705 29.878H4C2.89543 29.878 2 28.9825 2 27.878V12.3661Z`,fill:`#274FEE`}),/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M2 4.0863C2 2.98173 2.89543 2.0863 4 2.0863H9.24705C9.57842 2.0863 9.84705 2.35493 9.84705 2.6863V8.73981C9.84705 9.07118 9.57842 9.33981 9.24705 9.33981H2.6C2.26863 9.33981 2 9.07118 2 8.73981V4.0863Z`,fill:`#D8D8D8`}),/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M12.2637 2.6863C12.2637 2.35493 12.5323 2.0863 12.8637 2.0863H27.9702C29.0748 2.0863 29.9702 2.98173 29.9702 4.0863V8.73627C29.9702 9.06764 29.7016 9.33627 29.3702 9.33627H12.8637C12.5323 9.33627 12.2637 9.06764 12.2637 8.73627L12.2637 2.6863Z`,fill:`#D8D8D8`}),/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M12.2982 12.4011C12.2981 12.0697 12.5667 11.8009 12.8982 11.8009L29.3929 11.8009C29.7242 11.8009 29.9928 12.0694 29.9929 12.4007L29.9992 27.9129C29.9996 29.0178 29.104 29.9137 27.9992 29.9137H12.905C12.5737 29.9137 12.3051 29.6452 12.305 29.314L12.2982 12.4011Z`,fill:`#ECECEC`})]});case`value`:return/* @__PURE__ */ (0,f.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`32`,height:`32`,viewBox:`0 0 32 32`,fill:`none`,children:[/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M2 12.3661C2 12.0347 2.26863 11.7661 2.6 11.7661H9.24705C9.57842 11.7661 9.84705 12.0347 9.84705 12.3661V29.278C9.84705 29.6093 9.57842 29.878 9.24705 29.878H4C2.89543 29.878 2 28.9825 2 27.878V12.3661Z`,fill:`#D8D8D8`}),/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M2 4.0863C2 2.98173 2.89543 2.0863 4 2.0863H9.24705C9.57842 2.0863 9.84705 2.35493 9.84705 2.6863V8.73981C9.84705 9.07118 9.57842 9.33981 9.24705 9.33981H2.6C2.26863 9.33981 2 9.07118 2 8.73981V4.0863Z`,fill:`#D8D8D8`}),/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M12.2637 2.6863C12.2637 2.35493 12.5323 2.0863 12.8637 2.0863H27.9702C29.0748 2.0863 29.9702 2.98173 29.9702 4.0863V8.73627C29.9702 9.06764 29.7016 9.33627 29.3702 9.33627H12.8637C12.5323 9.33627 12.2637 9.06764 12.2637 8.73627L12.2637 2.6863Z`,fill:`#D8D8D8`}),/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M12.2982 12.4011C12.2981 12.0697 12.5667 11.8009 12.8982 11.8009L29.3929 11.8009C29.7242 11.8009 29.9928 12.0694 29.9929 12.4007L29.9992 27.9129C29.9996 29.0178 29.104 29.9137 27.9992 29.9137H12.905C12.5737 29.9137 12.3051 29.6452 12.305 29.314L12.2982 12.4011Z`,fill:`#274FEE`})]})}}function fi(e,t){switch(e){case`filter`:return t.t(`sheets-pivot-ui.filterDesc`);case`row`:return t.t(`sheets-pivot-ui.rowDesc`);case`column`:return t.t(`sheets-pivot-ui.columnDesc`);case`value`:return t.t(`sheets-pivot-ui.valueDesc`)}}function pi(e){let t=(0,a.useDependency)(r.LocaleService),{areaType:n}=e,i=fi(n,t),o=di(n);return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-h-[140px] univer-flex-col univer-items-center univer-justify-center univer-gap-1 univer-self-stretch univer-px-2`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-size-8`,children:o}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-text-center univer-text-xs univer-leading-4 univer-text-gray-600 dark:!univer-text-gray-200`,children:i})]})}function mi(e){let{areaType:t,items:n,positionInfo:i,pivotTableId:o,pivotTableInfo:s}=e,l=(0,a.useDependency)(r.LocaleService);return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-min-h-[200px] univer-flex-1 univer-p-1`,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mb-2 univer-mt-0 univer-flex univer-w-full univer-text-sm univer-leading-4 univer-text-gray-900`,children:[ui(t),/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-inline-block univer-align-top`,children:li(t,l)})]}),/* @__PURE__ */ (0,f.jsx)(si,{droppableId:`${t}`,isCombineEnabled:!1,isDropDisabled:!1,ignoreContainerClipping:!1,direction:`vertical`,children:(e,r)=>/* @__PURE__ */ (0,f.jsx)(`div`,{className:(0,c.clsx)(`univer-box-border univer-h-[161px] univer-w-full univer-flex-col univer-items-center univer-justify-center univer-overflow-x-hidden univer-rounded-lg univer-bg-gray-50 univer-py-2 dark:!univer-bg-gray-900`,c.borderClassName,{"univer-border-primary-600":r.isDraggingOver}),children:/* @__PURE__ */ (0,f.jsx)(`div`,{className:(0,c.clsx)(`univer-h-full univer-overflow-y-auto`,c.scrollbarClassName),children:/* @__PURE__ */ (0,f.jsxs)(`div`,{ref:e.innerRef,className:`univer-box-border univer-h-full univer-px-2`,...e.droppableProps,children:[n.length>0&&n.map((e,n)=>/* @__PURE__ */ (0,f.jsx)(`div`,{children:/* @__PURE__ */ (0,f.jsx)(ci,{isDragDisabled:!1,draggableId:e.tableFieldId,index:n,children:(n,r)=>/* @__PURE__ */ (0,f.jsx)(f.Fragment,{children:/* @__PURE__ */ (0,f.jsx)(`div`,{ref:n.innerRef,...n.draggableProps,...n.dragHandleProps,style:n.draggableProps.style,className:(0,c.clsx)(`univer-flex univer-items-center univer-gap-1 univer-self-stretch univer-border univer-border-transparent univer-p-0.5 univer-leading-4 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700`,r.draggingOver&&`univer-border-primary-600`),children:/* @__PURE__ */ (0,f.jsx)(hi,{pivotTableId:o,positionInfo:i,item:e,areaType:t,pivotTableInfo:s})})})},e.tableFieldId)},e.tableFieldId)),n.length===0&&/* @__PURE__ */ (0,f.jsx)(pi,{areaType:t})]})})})})]})}function hi(e){let{areaType:n,item:i,positionInfo:o,pivotTableId:s,pivotTableInfo:l}=e,{unitId:u,subUnitId:d}=o,p=i.tableFieldId===Qt,m=(0,a.useDependency)(r.ICommandService),h=(0,a.useDependency)(r.LocaleService),g=()=>{if(p){let e=(l.valueFields||[]).map(e=>e.tableFieldId);ln({pivotTableId:s,unitId:u,subUnitId:d,commandService:m},e)}else ln({pivotTableId:s,unitId:u,subUnitId:d,commandService:m},[i.tableFieldId])},_=()=>{u&&d&&fn(m,u,d,s,i.tableFieldId)},v=()=>{u&&d&&pn(m,s,i.tableFieldId,u,d,l)},y=e=>{let n=e===`column`?t.PivotTableValuePositionEnum.Row:t.PivotTableValuePositionEnum.Column,r=e===`column`?l.rowFields.length:l.columnFields.length;un({pivotTableId:s,unitId:u,subUnitId:d,commandService:m},n,r)},b=/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-inline-flex univer-flex-col univer-rounded-lg univer-border univer-border-gray-200 univer-bg-gray-0 univer-p-2 univer-shadow-lg`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-self-stretch univer-px-2 univer-py-1.5 univer-text-sm univer-leading-5 univer-text-gray-900 dark:!univer-text-gray-0`,onClick:()=>{g()},children:h.t(`sheets-pivot-ui.removeField`)}),n!==`value`&&!p&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-self-stretch univer-px-2 univer-py-1.5 univer-text-sm univer-leading-5 univer-text-gray-900 dark:!univer-text-gray-0`,onClick:()=>{_()},children:h.t(`sheets-pivot-ui.filterField`)}),p&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-self-stretch univer-px-2 univer-py-1.5 univer-text-sm univer-leading-5 univer-text-gray-900 dark:!univer-text-gray-0`,onClick:()=>{y(n)},children:n===`column`?h.t(`sheets-pivot-ui.moveToRow`):h.t(`sheets-pivot-ui.moveToColumn`)}),n===`value`&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-self-stretch univer-px-2 univer-py-1.5 univer-text-sm univer-leading-5 univer-text-gray-900 dark:!univer-text-gray-0`,onClick:()=>{v()},children:h.t(`sheets-pivot-ui.fieldSettings`)})]}),x=p?h.t(`sheets-pivot-ui.multipleValue`):i.displayName,S=/* @__PURE__ */ (0,f.jsx)(`bdi`,{dir:`auto`,children:x});return/* @__PURE__ */ (0,f.jsxs)(f.Fragment,{children:[/* @__PURE__ */ (0,f.jsx)(Nt,{}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-max-w-[66px] univer-flex-1 univer-shrink-0 univer-truncate univer-text-xs univer-leading-4 univer-text-gray-800 dark:!univer-text-gray-100`,children:/* @__PURE__ */ (0,f.jsx)(c.Tooltip,{title:S,children:S})}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-cursor-pointer`,children:/* @__PURE__ */ (0,f.jsx)(c.Dropdown,{align:`end`,overlay:b,children:/* @__PURE__ */ (0,f.jsx)(`span`,{children:/* @__PURE__ */ (0,f.jsx)(Lt,{})})})})]})}function gi(e){var t;let n=(0,a.useDependency)(r.IUniverInstanceService),i=(0,a.useDependency)(r.LocaleService),o=(0,a.useDependency)(r.ICommandService),s=(0,a.useDependency)(Q),{sourceRangeInfo:c,refreshHandler:l,pivotTableId:u,positionInfo:h}=e,{unitId:g,range:_,subUnitId:v}=c,y=n.getUnit(g),b=(y==null||(t=y.getSheetBySheetId(v))==null?void 0:t.getName())??``,[x,S]=(0,d.useState)(void 0),C=(0,d.useRef)(x);C.current=x;let[w,T]=(0,d.useState)(_),[E,D]=(0,d.useState)(b),[O,k]=(0,d.useState)(!1);(0,d.useEffect)(()=>{s.setIsRangeSelectorFocus(O)},[O,s]),(0,d.useEffect)(()=>{T(c.range),D(b)},[c,b]);let A=(0,d.useMemo)(()=>(0,r.debounce)(async e=>{let t=e.split(`,`).filter(e=>!!e).map(p.deserializeRangeWithSheet);if(!t[0])return;let n=t[0];if(!y||C.current)return;let r=n.sheetName||c.sheetName;T(n.range),D(r);let i={unitId:g,subUnitId:y.getSheetBySheetName(r).getSheetId(),range:{...n.range},sheetName:r};await on(o,u,i,h.unitId,h.subUnitId),l()},300,{leading:!1,maxWait:1e3,trailing:!0}),[]);return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mb-4`,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mb-2 univer-flex univer-h-5 univer-justify-between univer-text-sm univer-leading-5`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-justify univer-text-gray-900 dark:!univer-text-gray-0`,children:i.t(`sheets-pivot-ui.sourceRangeLabel`)}),/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-xs univer-text-gray-600 dark:!univer-text-gray-200`,children:i.t(`sheets-pivot-ui.sourceRangePlaceholder`)})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-relative`,children:[/* @__PURE__ */ (0,f.jsx)(m.RangeSelector,{unitId:g,subUnitId:v,initialValue:(0,p.serializeRangeWithSheet)(E,w),onChange:(e,t)=>{(0,p.serializeRangeWithSheet)(E,w)!==t&&A(t)},keepSheetReference:!0,supportAcrossSheet:!0,onVerify:(e,t)=>{let n=t.split(`,`).filter(e=>!!e);if(!n[0]){S(i.t(`sheets-pivot-ui.msg.emptySourceRange`));return}if(!e){S(i.t(`sheets-pivot-ui.msg.invalidSize`));return}let r=(0,p.deserializeRangeWithSheet)(n[0]),a=r.sheetName||c.sheetName;if(y)switch(rn(y.getSheetBySheetName(a),r.range)){case 2:S(void 0);break;case 0:S(i.t(`sheets-pivot-ui.msg.emptySourceRange`));break;case 1:S(i.t(`sheets-pivot-ui.msg.invalidSize`))}},maxRangeCount:1,onFocusChange:e=>{k(e)},onRangeSelectorDialogVisibleChange:e=>{k(!!e)}}),x?/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-my-1 univer-text-xs univer-text-red-500`,children:x}):null]})]})}function _i(e){let{type:n}=e;switch(n){case t.PivotDataFieldDataTypeEnum.text:return/* @__PURE__ */ (0,f.jsx)(qt,{className:`univer-mx-1.5 univer-my-0 univer-h-4 univer-text-xs univer-text-gray-200 dark:!univer-text-gray-600`});case t.PivotDataFieldDataTypeEnum.number:return/* @__PURE__ */ (0,f.jsx)(zt,{className:`univer-mx-1.5 univer-my-0 univer-h-4 univer-text-xs univer-text-gray-200 dark:!univer-text-gray-600`});case t.PivotDataFieldDataTypeEnum.date:return/* @__PURE__ */ (0,f.jsx)(xt,{className:`univer-mx-1.5 univer-my-0 univer-h-4 univer-text-xs univer-text-gray-200 dark:!univer-text-gray-600`})}}function vi(e){if(!e)return!1;if(e.type===t.PivotFilterTypeEnum.RecordFilter){var n;return e.dateRange!==void 0||(((n=e.selection)==null?void 0:n.mode)??r.FilterSelectionMode.All)!==r.FilterSelectionMode.All}return e.type!==t.PivotFilterTypeEnum.ManualFilter||e.isAll!==!0}function yi(e){let{name:i,dataFieldId:o,checked:s,type:l,refreshHandler:u,pivotTableId:p,draggingId:m,pivotTableInfo:h,unitId:g,subUnitId:_}=e,[v,y]=(0,d.useState)(!1),b=(0,a.useDependency)(r.ICommandService),x=(0,a.useDependency)(r.LocaleService);if(!h)return null;let{rowFields:S,columnFields:C,filterFields:w,valueFields:T}=h,E=h.hiddenFields??[],D=[...S,...C,...w,...T,...E],O=E.find(e=>e.dataFieldId===o),k=async e=>{let r=!!e,i=!1;if(r){let e={pivotTableId:p,dataFieldId:o,fieldArea:l===t.PivotDataFieldDataTypeEnum.number?t.PivotTableFiledAreaEnum.Value:t.PivotTableFiledAreaEnum.Row,unitId:g,subUnitId:_,index:l===t.PivotDataFieldDataTypeEnum.number?T.length:S.length};i=await b.executeCommand(n.AddPivotFieldCommand.id,e)}else{let e=[];D.forEach(t=>{t.dataFieldId===o&&e.push(t.tableFieldId)}),i=await b.executeCommand(n.RemovePivotFieldCommand.id,{pivotTableId:p,fieldIds:e,unitId:g,subUnitId:_})}i&&u()},A=async e=>{let r=!1,i=``;if([...S,...C,...w,...E].forEach(e=>{e.dataFieldId===o&&(r=!0,i=e.tableFieldId)}),r&&e!==t.PivotTableFiledAreaEnum.Value){if(p){let t=Tn(h,e),r={pivotTableId:p,area:e,index:t,fieldId:i,unitId:g,subUnitId:_};await b.executeCommand(n.MovePivotFieldCommand.id,r)&&u()}}else if(p){let t={pivotTableId:p,dataFieldId:o,fieldArea:e,unitId:g,subUnitId:_,index:Tn(h,e)};await b.executeCommand(n.AddPivotFieldCommand.id,t)&&u()}};return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:(0,c.clsx)(`univer-group univer-relative univer-box-border univer-flex univer-h-8 univer-w-full univer-flex-row univer-items-center univer-rounded-md univer-px-1 univer-py-2 univer-leading-4 univer-transition-all hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700`,{"univer-flex univer-bg-gray-100 dark:!univer-bg-gray-700":m===o}),id:`source-${o}`,onContextMenu:e=>{e.preventDefault(),y(!0)},children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-mr-2 univer-w-4 rtl:univer-ml-2 rtl:univer-mr-0`,children:/* @__PURE__ */ (0,f.jsx)(Nt,{})}),/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{className:`univer-w-[14px] univer-text-sm univer-text-gray-200`,checked:s,onChange:k}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-min-w-0 univer-flex-1 univer-items-center univer-text-xs univer-leading-4 univer-text-gray-900 dark:!univer-text-gray-0`,children:[/* @__PURE__ */ (0,f.jsx)(_i,{type:l}),/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-truncate`,children:i})]}),/* @__PURE__ */ (0,f.jsx)(c.Dropdown,{align:`end`,side:`bottom`,open:v,onOpenChange:y,overlay:/* @__PURE__ */ (0,f.jsxs)(`div`,{children:[vi(O==null?void 0:O.filterInfo)&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-self-stretch univer-px-2 univer-py-1.5 univer-text-sm univer-leading-5 univer-text-gray-900 hover:univer-bg-gray-100 dark:!univer-text-gray-0 dark:hover:!univer-bg-gray-700`,onClick:async()=>{O&&(y(!1),await b.executeCommand(n.SetPivotFilterCommand.id,{unitId:g,subUnitId:_,pivotTableId:p,tableFieldId:O.tableFieldId,items:[],partialItems:[],isAll:!0})&&u())},children:x.t(`sheets-pivot-ui.dialog.filter.clearFilter`)}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-self-stretch univer-px-2 univer-py-1.5 univer-text-sm univer-leading-5 univer-text-gray-900 hover:univer-bg-gray-100 dark:!univer-text-gray-0 dark:hover:!univer-bg-gray-700`,onClick:()=>{y(!1),A(t.PivotTableFiledAreaEnum.Row)},children:x.t(`sheets-pivot-ui.addToRow`)}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-self-stretch univer-px-2 univer-py-1.5 univer-text-sm univer-leading-5 univer-text-gray-900 hover:univer-bg-gray-100 dark:!univer-text-gray-0 dark:hover:!univer-bg-gray-700`,onClick:()=>{y(!1),A(t.PivotTableFiledAreaEnum.Column)},children:x.t(`sheets-pivot-ui.addToColumn`)}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-self-stretch univer-px-2 univer-py-1.5 univer-text-sm univer-leading-5 univer-text-gray-900 hover:univer-bg-gray-100 dark:!univer-text-gray-0 dark:hover:!univer-bg-gray-700`,onClick:()=>{y(!1),A(t.PivotTableFiledAreaEnum.Value)},children:x.t(`sheets-pivot-ui.addToValue`)}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-self-stretch univer-px-2 univer-py-1.5 univer-text-sm univer-leading-5 univer-text-gray-900 hover:univer-bg-gray-100 dark:!univer-text-gray-0 dark:hover:!univer-bg-gray-700`,onClick:()=>{y(!1),A(t.PivotTableFiledAreaEnum.Filter)},children:x.t(`sheets-pivot-ui.addToFilter`)})]}),children:/* @__PURE__ */ (0,f.jsx)(`div`,{className:(0,c.clsx)(`univer-ml-1 univer-flex univer-size-5 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-md univer-transition-opacity hover:univer-bg-gray-200 rtl:univer-ml-0 rtl:univer-mr-1 dark:hover:!univer-bg-gray-700`,{"univer-opacity-100":v,"univer-opacity-0 group-hover:univer-opacity-100":!v}),onMouseDown:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),children:/* @__PURE__ */ (0,f.jsx)(Ft,{className:`univer-text-gray-400 dark:!univer-text-gray-500`})})})]},o)}function bi(e){let{sourceList:t,refreshHandler:n,pivotTableId:i,pivotTableInfo:o,unitId:s,draggingId:l,subUnitId:u}=e,p=(0,a.useDependency)(r.LocaleService),[m,h]=(0,d.useState)(``),g=m.trim().toLocaleLowerCase(),_=g?t.filter(e=>e.name.toLocaleLowerCase().includes(g)):t;return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mb-4 univer-flex univer-min-h-0 univer-flex-1 univer-flex-col`,children:[/* @__PURE__ */ (0,f.jsx)(`p`,{className:`univer-mb-1 univer-mt-0 univer-text-sm univer-font-medium univer-leading-5 univer-text-gray-900 dark:!univer-text-gray-0`,children:p.t(`sheets-pivot-ui.sourceFieldTile`)}),/* @__PURE__ */ (0,f.jsx)(`p`,{className:`univer-mb-2 univer-mt-0 univer-text-xs univer-leading-4 univer-text-gray-600 dark:!univer-text-gray-200`,children:p.t(`sheets-pivot-ui.sourceFieldDescription`)}),/* @__PURE__ */ (0,f.jsx)(c.Input,{allowClear:!0,className:`univer-mb-2`,placeholder:p.t(`sheets-pivot-ui.searchFieldPlaceholder`),slot:/* @__PURE__ */ (0,f.jsx)(Gt,{}),value:m,onChange:h}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:(0,c.clsx)(`univer-box-border univer-min-h-0 univer-flex-1 univer-rounded-lg univer-bg-gray-0 univer-p-2 dark:!univer-bg-gray-900`,c.borderClassName),children:/* @__PURE__ */ (0,f.jsx)(`div`,{className:(0,c.clsx)(`univer-relative univer-h-full univer-overflow-y-auto`,c.scrollbarClassName),"data-testid":`pivot-source-field-viewport`,children:/* @__PURE__ */ (0,f.jsx)(si,{droppableId:`source`,direction:`vertical`,isCombineEnabled:!1,ignoreContainerClipping:!1,isDropDisabled:!0,children:e=>/* @__PURE__ */ (0,f.jsxs)(`div`,{ref:e.innerRef,className:`univer-box-border univer-h-full univer-px-2`,...e.droppableProps,children:[_.map((e,t)=>/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-relative univer-flex univer-h-8 univer-w-full univer-items-center univer-gap-1 univer-self-stretch univer-border univer-border-transparent univer-p-0.5 univer-leading-4 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700`,children:/* @__PURE__ */ (0,f.jsx)(ci,{draggableId:e.id,isDragDisabled:!1,index:t,children:({innerRef:t,draggableProps:r,dragHandleProps:a})=>/* @__PURE__ */ (0,f.jsx)(`div`,{ref:t,...r,...a,className:`univer-h-8 univer-w-full`,style:r.style,children:/* @__PURE__ */ (0,f.jsx)(yi,{draggingId:l,unitId:s,subUnitId:u,...e,refreshHandler:n,pivotTableId:i,pivotTableInfo:o})})},e.id)},e.id)),_.length===0&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-py-4 univer-text-center univer-text-xs univer-text-gray-500`,children:p.t(`sheets-pivot-ui.noMatchingFields`)})]})})})})]})}function xi(e){let{pivotTableId:t,version:i,unitId:o,subUnitId:l,panelInfo:u}=e,p=(0,a.useDependency)(n.SheetsPivotTableConfigModel),m=(0,d.useMemo)(()=>p.watchPivotTableChanges(o,l,t).pipe((0,s.debounceTime)(0)),[p,o,l,t]),h=(0,a.useObservable)(m),g=(0,a.useDependency)(n.SheetsPivotRPCService),_=(0,a.useDependency)(Q),v=(0,a.useObservable)(_.pivotTablePanelVisible$,!0),y=(0,a.useDependency)(r.ICommandService),b=(0,a.useDependency)(r.ILogService),[x,S]=(0,d.useState)(u),[C,w]=(0,d.useState)(null),T=(0,d.useCallback)(async()=>{if(!p.getPivotTableConfig(o,l,t))return;let e=await g.getPivotDisplayConfig({unitId:o,subUnitId:l,pivotTableId:t,params:{type:n.PivotDisplayDataType.Panel,panel:{pivotTableId:t}}});e.result.panel&&S(e.result.panel)},[t,g,p,l,o]);(0,d.useEffect)(()=>{T().catch(e=>b.error(`[PivotPanel]`,e))},[b,h,t,T,i]);let E=async e=>{let{source:n,destination:r,draggableId:i}=e;w(null);let a={pivotTableInfo:x,pivotTableId:t,commandService:y,unitId:o,subUnitId:l},s=n.droppableId;if(r&&r.droppableId){let e=r.droppableId;await cn(a,i,s,e,r.index),await T()}r===null&&(await an(a,i,s),await T())},D=e=>{w({draggingId:e.draggableId})},O=e=>{let{draggableId:t,destination:n,source:r}=e;w({draggingId:t,destination:n,source:r})};if(!v||!x)return null;let{sourceList:k,rowFields:A,columnFields:j,filterFields:M,valueFields:N,sourceRange:P,positionInfo:F}=x;return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:(0,c.clsx)(`univer-mt-4 univer-flex univer-h-[calc(100%-16px)] univer-min-h-0 univer-w-full univer-flex-col univer-overflow-y-auto univer-overflow-x-hidden`,c.scrollbarClassName),children:[/* @__PURE__ */ (0,f.jsx)(gi,{sourceRangeInfo:P,pivotTableId:t,refreshHandler:T,positionInfo:F}),/* @__PURE__ */ (0,f.jsxs)(oi,{onDragEnd:E,onDragStart:D,onDragUpdate:O,children:[/* @__PURE__ */ (0,f.jsx)(bi,{draggingId:(C==null?void 0:C.draggingId)??``,sourceList:k,refreshHandler:T,pivotTableId:t,pivotTableInfo:x,unitId:o,subUnitId:l}),/* @__PURE__ */ (0,f.jsx)(Si,{rowFields:A,columnFields:j,filterFields:M,valueFields:N,refreshHandler:T,positionInfo:F,pivotTableId:t,pivotTableInfo:x})]})]})}function Si(e){let{rowFields:t,columnFields:n,filterFields:r,valueFields:i,refreshHandler:a,pivotTableInfo:o,positionInfo:s,pivotTableId:c}=e;return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-shrink-0`,"data-testid":`pivot-field-areas`,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-row univer-gap-4`,children:[/* @__PURE__ */ (0,f.jsx)(mi,{areaType:`filter`,items:r,positionInfo:s,pivotTableId:c,pivotTableInfo:o,refreshHandler:a}),/* @__PURE__ */ (0,f.jsx)(mi,{areaType:`column`,items:n,positionInfo:s,pivotTableId:c,pivotTableInfo:o,refreshHandler:a})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-row univer-gap-4`,children:[/* @__PURE__ */ (0,f.jsx)(mi,{areaType:`row`,items:t,positionInfo:s,pivotTableId:c,pivotTableInfo:o,refreshHandler:a}),/* @__PURE__ */ (0,f.jsx)(mi,{areaType:`value`,items:i,positionInfo:s,pivotTableId:c,pivotTableInfo:o,refreshHandler:a})]})]})}function Ci(e){let{className:t,unitId:n,subUnitId:i,pivotTableId:o}=e,[s,l]=(0,d.useState)(0),u=(0,a.useDependency)(r.LocaleService),p=u.getDirection();return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:(0,c.clsx)(`univer-flex univer-size-full univer-min-h-0 univer-flex-col`,t),dir:p,children:[/* @__PURE__ */ (0,f.jsx)(c.Segmented,{className:`univer-my-3 univer-w-full univer-shrink-0`,items:[{label:u.t(`sheets-pivot-ui.fieldPanel`),value:0},{label:u.t(`sheets-pivot-ui.configPanel`),value:1}],value:s,onChange:l}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:(0,c.clsx)(`univer-min-h-0 univer-flex-1`,s===0?`univer-overflow-hidden`:`univer-overflow-auto`),children:s===0?/* @__PURE__ */ (0,f.jsx)(xi,{...e}):/* @__PURE__ */ (0,f.jsx)($r,{unitId:n,subUnitId:i,pivotTableId:o})})]})}function wi(e){let{unitId:t,subUnitId:n,pivotTableId:r,tableFieldId:i,type:a}=e,o=JSON.stringify([t,n,r,i,a]);return/* @__PURE__ */ (0,f.jsx)(Ti,{...e},o)}function Ti({unitId:e,subUnitId:i,pivotTableId:o,tableFieldId:s,type:l,baseItems:u,onConfirm:p,onCancel:m}){var h;let g=(0,a.useDependency)(n.SheetsPivotTableConfigModel),_=(0,a.useDependency)(r.LocaleService),v=(0,a.useObservable)(_.direction$,_.getDirection()),y=de.find(e=>e.type===l),b=g.getPivotTableConfig(e,i,o),x=b==null||(h=b.fieldsConfig.measure[s])==null?void 0:h.showDataAs,S=()=>{var e;if((x==null?void 0:x.type)!==l||!x.baseFieldId)return``;if(x.baseItemType===t.PivotShowAsBaseItemTypeEnum.previous)return`relative:previous`;if(x.baseItemType===t.PivotShowAsBaseItemTypeEnum.next)return`relative:next`;let n=((e=u[x.baseFieldId])==null?void 0:e.items.indexOf(x.baseItem))??-1;return n<0?``:`item:${n}`},[C,w]=(0,d.useState)((x==null?void 0:x.type)===l?x.baseFieldId:``),[T,E]=(0,d.useState)(S),D=(0,d.useRef)(!1),[O,k]=(0,d.useState)(!1),A=g.getPivotTableConfig(e,i,o),j=g.getCollection(e,o),M=A==null?void 0:A.fieldsConfig.measure[s],N=!!(M&&j&&(j.fields[M.dataFieldId]||j.customFields.find(e=>e.id===M.dataFieldId))),P=(A&&j&&y?pe(A,j,y):[]).filter(e=>{let t=u[e];return(y==null?void 0:y.baseItemMode)===`none`||!!(t&&((y==null?void 0:y.baseItemMode)===`item-or-relative`||t.items.length>0))}),F=P.map(e=>({label:A.fieldsConfig.dimension[e].displayName,value:e})),I=A==null?void 0:A.fieldsConfig.dimension[C],L=I&&j&&(j.fields[I.dataFieldId]??j.customFields.find(e=>e.id===I.dataFieldId)),R=u[C],z=(R==null?void 0:R.items.map((e,n)=>{var i;let a=R.itemTypes[n],o=(i=R.itemLabels)==null?void 0:i[e],s=$t(e,a),c=e;return s?c=_.t(s):o===void 0?a===t.PivotDataFieldDataTypeEnum.other?c=_.t(`sheets-pivot-ui.showValuesAs.other`):(a===t.PivotDataFieldDataTypeEnum.date||a===t.PivotDataFieldDataTypeEnum.number)&&R.format&&(c=r.numfmt.format(R.format,Number(e))):c=o,{label:c,value:`item:${n}`,itemKey:e}}))??[];(y==null?void 0:y.baseItemMode)===`item-or-relative`&&z.push({label:_.t(`sheets-pivot-ui.showValuesAs.previous`),value:`relative:previous`,itemKey:``,itemType:t.PivotShowAsBaseItemTypeEnum.previous},{label:_.t(`sheets-pivot-ui.showValuesAs.next`),value:`relative:next`,itemKey:``,itemType:t.PivotShowAsBaseItemTypeEnum.next});let B=z.find(e=>e.value===T),V=!!(y!=null&&y.baseItemMode&&y.baseItemMode!==`none`),ee=!!(y&&A&&j&&N&&A.fieldsConfig.valueFields.includes(s)&&P.includes(C)&&L&&(!V||B));return/* @__PURE__ */ (0,f.jsxs)(`div`,{dir:v,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mb-4`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:_.t(`sheets-pivot-ui.showValuesAs.baseField`)}),/* @__PURE__ */ (0,f.jsx)(c.Select,{className:`univer-w-full`,value:C,options:F,onChange:e=>{w(e),E(``)}})]}),V&&/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mb-4`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:_.t(`sheets-pivot-ui.showValuesAs.baseItem`)}),/* @__PURE__ */ (0,f.jsx)(c.Select,{className:`univer-w-full`,value:T,options:z,disabled:!C,onChange:E})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-justify-end univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{onClick:m,children:_.t(`sheets-pivot-ui.showValuesAs.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`primary`,disabled:!ee||O,onClick:async()=>{let t=g.getPivotTableConfig(e,i,o),n=g.getCollection(e,o),r=t==null?void 0:t.fieldsConfig.measure[s];if(!y||!t||!n||!r||D.current||!t.fieldsConfig.valueFields.includes(s)||!(n.fields[r.dataFieldId]||n.customFields.find(e=>e.id===r.dataFieldId))||!pe(t,n,y).includes(C)||V&&!B)return;let a={type:l,baseFieldId:C,baseItem:(B==null?void 0:B.itemKey)??``};(B==null?void 0:B.itemType)!==void 0&&(a.baseItemType=B.itemType),D.current=!0,k(!0);try{await p(a)}catch{}finally{D.current=!1,k(!1)}},children:_.t(`sheets-pivot-ui.showValuesAs.ok`)})]})]})}let Ei=e=>{let[t,n]=(0,d.useState)(!1),r=(0,a.useDependency)(Q);return(0,d.useEffect)(()=>{r.setIsRangeSelector2Focus(t)},[t,r]),/* @__PURE__ */ (0,f.jsx)(m.RangeSelector,{...e,onFocusChange:t=>{var r;(r=e.onFocusChange)==null||r.call(e,t),n(t)}})},Di=(e,t,n,r,i,a)=>/* @__PURE__ */ (0,f.jsx)(Ei,{unitId:e,subUnitId:t,initialValue:r,onChange:(e,t)=>n(t),maxRangeCount:1,supportAcrossSheet:!0,keepSheetReference:!0}),Oi=(e,t)=>{switch(e){case 1:return t.t(`sheets-pivot-ui.msg.invalidSize`);case 0:return t.t(`sheets-pivot-ui.msg.emptySourceRange`);default:return``}};function ki(e){let{unitId:t,sourceRange:i,positionRange:o,sourceSheetName:s,positionSheetName:l,onConfirm:u,onCancel:m}=e,h=(0,a.useDependency)(r.LocaleService),g=(0,a.useDependency)(r.IUniverInstanceService),_=h.getDirection(),v=g.getUnit(t),y=(0,d.useMemo)(()=>v.getActiveSheet().getSheetId(),[v]),[b,x]=(0,d.useState)(i),[S,C]=(0,d.useState)(o),[w,T]=(0,d.useState)(s),[E,D]=(0,d.useState)(l),O=(0,d.useRef)(void 0),[k,A]=(0,d.useState)(),[j,M]=(0,d.useState)(n.PositionType.New),[N,P]=(0,d.useState)(!0),[F,I]=(0,d.useState)(!0),[L,R]=(0,d.useState)(void 0);(0,d.useEffect)(()=>{let e=rn(v.getSheetBySheetName(w),b);I(e===2),R(Oi(e,h))},[b,w,v,h]);let z=e=>{if((0,p.serializeRangeWithSheet)(w,b)===e)return;let t=e.split(`,`).filter(e=>!!e).map(p.deserializeRangeWithSheet);if(Array.isArray(t)&&t.length>0){let{range:e,sheetName:n}=t[0];x(e),T(n)}t[0]||R(h.t(`sheets-pivot-ui.msg.emptySourceRange`))},B=Di(t,y,e=>{if(S&&(0,p.serializeRangeWithSheet)(E,S)===e)return;let t=e.split(`,`).filter(e=>!!e).map(p.deserializeRangeWithSheet);if(t.length===0){C(null);return}let n=t[0];C(n.range),D(n.sheetName||s),n.sheetName===s&&r.Rectangle.intersects(n.range,b)?P(!1):P(!0)},S?(0,p.serializeRangeWithSheet)(E,S):``,!1,k),V=()=>!!(b&&S&&w&&E&&j===n.PositionType.Existing&&N&&F)||!!(b&&w&&j===n.PositionType.New&&F);return(0,d.useEffect)(()=>{A(O.current)},[]),/* @__PURE__ */ (0,f.jsxs)(`div`,{ref:O,dir:_,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-h-5 univer-text-sm univer-font-medium`,children:h.t(`sheets-pivot-ui.dialog.source.sourceData`)}),Di(t,y,z,(0,p.serializeRangeWithSheet)(w,b),!0,k),L&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mt-2 univer-h-5 univer-text-xs univer-text-red-400`,children:L}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-mt-5 univer-h-5 univer-text-sm univer-font-medium`,children:h.t(`sheets-pivot-ui.dialog.source.position`)}),/* @__PURE__ */ (0,f.jsxs)(c.RadioGroup,{value:j,onChange:e=>M(e),className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsx)(c.Radio,{value:n.PositionType.New,children:h.t(`sheets-pivot-ui.dialog.source.newSheet`)}),/* @__PURE__ */ (0,f.jsx)(c.Radio,{value:n.PositionType.Existing,children:h.t(`sheets-pivot-ui.dialog.source.existingSheet`)})]}),j===n.PositionType.Existing&&/* @__PURE__ */ (0,f.jsxs)(f.Fragment,{children:[B,!N&&/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-h-5 univer-text-sm univer-text-red-400`,children:h.t(`sheets-pivot-ui.dialog.source.intersect`)})]}),/* @__PURE__ */ (0,f.jsx)(`footer`,{className:`univer-mt-5`,children:/* @__PURE__ */ (0,f.jsxs)(c.ActionRow,{className:`univer-flex univer-justify-end univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{onClick:()=>m(),children:h.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`primary`,onClick:()=>{V()&&(j===n.PositionType.Existing?u({sourceRange:b,sourceSheetName:w,positionRange:S,positionSheetName:E,positionType:j}):u({sourceRange:b,sourceSheetName:w,positionType:j}))},children:h.t(`sheets-pivot-ui.dialog.ok`)})]})})]})}ki.componentKey=A;let Ai=[{id:`equal`,localeKey:`sheets-pivot-ui.valueFilter.equal`,operator:t.ST_PivotFilterOperatorEnum.valueEqual},{id:`notEqual`,localeKey:`sheets-pivot-ui.valueFilter.notEqual`,operator:t.ST_PivotFilterOperatorEnum.valueNotEqual},{id:`greaterThan`,localeKey:`sheets-pivot-ui.valueFilter.greaterThan`,operator:t.ST_PivotFilterOperatorEnum.valueGreaterThan},{id:`greaterThanOrEqual`,localeKey:`sheets-pivot-ui.valueFilter.greaterThanOrEqual`,operator:t.ST_PivotFilterOperatorEnum.valueGreaterThanOrEqual},{id:`lessThan`,localeKey:`sheets-pivot-ui.valueFilter.lessThan`,operator:t.ST_PivotFilterOperatorEnum.valueLessThan},{id:`lessThanOrEqual`,localeKey:`sheets-pivot-ui.valueFilter.lessThanOrEqual`,operator:t.ST_PivotFilterOperatorEnum.valueLessThanOrEqual},{id:`between`,localeKey:`sheets-pivot-ui.valueFilter.between`,operator:t.ST_PivotFilterOperatorEnum.valueBetween,isBetween:!0},{id:`notBetween`,localeKey:`sheets-pivot-ui.valueFilter.notBetween`,operator:t.ST_PivotFilterOperatorEnum.valueNotBetween,isBetween:!0},{id:`topCount`,localeKey:`sheets-pivot-ui.valueFilter.topCount`,operator:t.ST_PivotFilterOperatorEnum.count,isCount:!0},{id:`bottomCount`,localeKey:`sheets-pivot-ui.valueFilter.bottomCount`,operator:t.ST_PivotFilterOperatorEnum.count,isBottom:!0,isCount:!0},{id:`topPercent`,localeKey:`sheets-pivot-ui.valueFilter.topPercent`,operator:t.ST_PivotFilterOperatorEnum.percent,isPercent:!0},{id:`bottomPercent`,localeKey:`sheets-pivot-ui.valueFilter.bottomPercent`,operator:t.ST_PivotFilterOperatorEnum.percent,isBottom:!0,isPercent:!0}];function ji({targetFieldId:e,targetFieldName:n,valueFields:i,defaultValueFieldId:o,currentFilter:s,onConfirm:l,onClear:u,onCancel:p}){function m(e){var n;return(e==null?void 0:e.operator)===t.ST_PivotFilterOperatorEnum.count?e.isBottom?`bottomCount`:`topCount`:(e==null?void 0:e.operator)===t.ST_PivotFilterOperatorEnum.percent?e.isBottom?`bottomPercent`:`topPercent`:((n=Ai.find(t=>t.operator===(e==null?void 0:e.operator)))==null?void 0:n.id)??`greaterThan`}let h=(0,a.useDependency)(r.LocaleService),g=(0,a.useObservable)(h.direction$,h.getDirection()),_=s==null?void 0:s.expected,[v,y]=(0,d.useState)(()=>{let e=s==null?void 0:s.valueFieldId;return e&&i.some(t=>t.id===e)?e:o&&i.some(e=>e.id===o)?o:i.length===1?i[0].id:``}),[b,x]=(0,d.useState)(()=>m(s)),[S,C]=(0,d.useState)(()=>String(Array.isArray(_)?_[0]:_??0)),[w,T]=(0,d.useState)(()=>String(Array.isArray(_)?_[1]:0)),E=(0,d.useRef)(!1),[D,O]=(0,d.useState)(!1),k=Ai.find(e=>e.id===b),A=S.trim()!==``&&Number.isFinite(Number(S)),j=!k.isBetween||w.trim()!==``&&Number.isFinite(Number(w)),M=!k.isCount||Number.isInteger(Number(S))&&Number(S)>=1,N=!k.isPercent||Number(S)>=0&&Number(S)<=100,P=!!(i.some(e=>e.id===v)&&A&&j&&M&&N),F=async e=>{if(!E.current){E.current=!0,O(!0);try{await e()}catch{}finally{E.current=!1,O(!1)}}},I=()=>F(async()=>{if(!P)return;let e={operator:k.operator,expected:k.isBetween?[Number(S),Number(w)]:Number(S),valueFieldId:v};k.isBottom&&(e.isBottom=!0),await l(e)}),L=()=>F(u);return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,"data-target-field-id":e,dir:g,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-text-sm univer-font-medium`,children:/* @__PURE__ */ (0,f.jsx)(`bdi`,{dir:`auto`,children:n})}),/* @__PURE__ */ (0,f.jsxs)(`label`,{className:`univer-flex univer-flex-col univer-gap-2 univer-text-sm`,children:[h.t(`sheets-pivot-ui.valueFilter.valueField`),/* @__PURE__ */ (0,f.jsx)(c.Select,{"aria-label":h.t(`sheets-pivot-ui.valueFilter.valueField`),"data-testid":`pivot-value-filter-value-field`,value:v,options:[{value:``,label:h.t(`sheets-pivot-ui.valueFilter.selectValueField`)},...i.map(e=>({value:e.id,label:e.label}))],onChange:y})]}),/* @__PURE__ */ (0,f.jsxs)(`label`,{className:`univer-flex univer-flex-col univer-gap-2 univer-text-sm`,children:[h.t(`sheets-pivot-ui.valueFilter.condition`),/* @__PURE__ */ (0,f.jsx)(c.Select,{"aria-label":h.t(`sheets-pivot-ui.valueFilter.condition`),"data-testid":`pivot-value-filter-rule`,value:b,options:Ai.map(e=>({value:e.id,label:h.t(e.localeKey)})),onChange:e=>x(e)})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsx)(c.Input,{"aria-label":h.t(`sheets-pivot-ui.valueFilter.condition`),"aria-invalid":!A||!M||!N,className:`univer-min-w-0 univer-flex-1`,"data-testid":`pivot-value-filter-expected`,inputMode:`decimal`,value:S,onChange:C}),k.isBetween&&/* @__PURE__ */ (0,f.jsx)(c.Input,{"aria-label":h.t(`sheets-pivot-ui.valueFilter.condition`),"aria-invalid":!j,className:`univer-min-w-0 univer-flex-1`,"data-testid":`pivot-value-filter-expected`,inputMode:`decimal`,value:w,onChange:T})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{"data-testid":`pivot-value-filter-clear`,disabled:D,onClick:L,children:h.t(`sheets-pivot-ui.valueFilter.clear`)}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{disabled:D,onClick:p,children:h.t(`sheets-pivot-ui.valueFilter.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{"data-testid":`pivot-value-filter-confirm`,variant:`primary`,disabled:!P||D,onClick:I,children:h.t(`sheets-pivot-ui.valueFilter.ok`)})]})]})]})}function Mi(e){let{pivotTableId:t,tableFieldId:i,closeFn:o,unitId:s,subUnitId:l,format:u,tableFieldInfo:p,dataFieldInfo:m,version:h}=e,[g,_]=(0,d.useState)(p.displayName),[v,y]=(0,d.useState)(p.subTotalType),b=(0,a.useDependency)(r.LocaleService),x=(0,a.useDependency)(r.ICommandService),w=(0,a.useDependency)(a.IDialogService),T={...(0,a.useDependency)(n.SheetsPivotTableConfigModel).getTextInfo()};for(let e of[`sheets-pivot-ui.averageName`,`sheets-pivot-ui.countName`,`sheets-pivot-ui.countNumsName`,`sheets-pivot-ui.maxName`,`sheets-pivot-ui.minName`,`sheets-pivot-ui.productName`,`sheets-pivot-ui.stdDevName`,`sheets-pivot-ui.stdDevpName`,`sheets-pivot-ui.sumName`,`sheets-pivot-ui.varName`,`sheets-pivot-ui.varpName`])T[e]=b.t(e);if((0,d.useEffect)(()=>{_(p.displayName),y(p.subTotalType)},[h]),!p||!m)return;let E=m.name,D=b.getDirection(),O=u??p.format,k=mn.map(e=>({value:`${e.type}`,type:e.type,label:b.t(e.textKey)})),A=e=>{let t=e;if(Array.isArray(e)&&(t=e[0]),t!==void 0){let e=Number(t);y(e),En(E,g,T)&&_(Dn(E,T,e))}};return/* @__PURE__ */ (0,f.jsxs)(`div`,{dir:D,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-self-stretch univer-leading-5`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-sm univer-font-medium univer-leading-5 univer-text-gray-900`,children:b.t(`sheets-pivot-ui.dialog.fieldName`)}),/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-xs univer-leading-4 univer-text-gray-600`,children:en(b.t(`sheets-pivot-ui.dialog.sourceName`),E)})]}),/* @__PURE__ */ (0,f.jsx)(`div`,{children:/* @__PURE__ */ (0,f.jsx)(c.Input,{className:`univer-mb-5 univer-mt-2 univer-box-border univer-h-8 univer-w-full univer-rounded-md univer-py-1.5 univer-text-sm univer-leading-5`,value:g,onChange:e=>_(e)})}),/* @__PURE__ */ (0,f.jsx)(`label`,{className:`univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-gray-0`,children:b.t(`sheets-pivot-ui.dialog.summarizeBy`)}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:(0,c.clsx)(`univer-h-40 univer-flex-1 univer-overflow-y-auto univer-rounded-lg`,c.borderClassName,c.scrollbarClassName),children:k.map(e=>/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-items-center univer-gap-1.5 univer-self-stretch univer-rounded-md univer-px-2 univer-py-1.5 univer-text-sm univer-capitalize univer-leading-5`,onClick:()=>A(e.value),children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-w-4 univer-text-base univer-text-primary-600`,children:/* @__PURE__ */ (0,f.jsx)(Ct,{className:(0,c.clsx)({"univer-hidden":v!==e.type})})}),/* @__PURE__ */ (0,f.jsx)(`span`,{children:e.label})]},e.type))}),/* @__PURE__ */ (0,f.jsx)(`footer`,{className:`univer-mt-5`,children:/* @__PURE__ */ (0,f.jsxs)(c.ActionRow,{className:`univer-flex univer-items-center univer-justify-between univer-self-stretch`,children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{className:`univer-flex univer-h-8 univer-cursor-pointer univer-items-center univer-justify-center univer-gap-1.5 univer-rounded univer-border-none univer-bg-gray-0 univer-px-3 univer-text-primary-600`,onClick:()=>{let e={id:S,draggable:!0,mask:!1,maskClosable:!1,width:400,children:{label:C,unitId:s,subUnitId:l,pivotTableId:t,tableFieldId:i,originPattern:O,tableFieldInfo:p,dataFieldInfo:m},dialogStyles:{header:{padding:`20px 24px 0`,height:0},body:{padding:`0 24px 20px`}},closable:!1,onClose:()=>{w.close(S)}};w.open(e)},children:b.t(`sheets-pivot-ui.dialog.format`)}),/* @__PURE__ */ (0,f.jsxs)(c.ActionRow,{className:`univer-flex univer-flex-1 univer-gap-2 univer-text-sm rtl:univer-flex-row-reverse`,children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{onClick:()=>{o&&o()},children:b.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`primary`,disabled:g===``,onClick:()=>{let e=p.displayName,r=p.subTotalType,a=p.format,c=e===g?void 0:g,u=r===v?void 0:v,d=a===O?void 0:O;if(e!==g||r!==v||a!==d){let e={displayName:c,subtotalType:u,format:d,tableFieldId:i,pivotTableId:t,unitId:s,subUnitId:l,tableFieldInfo:p,dataFieldInfo:m};x.executeCommand(n.UpdatePivotFieldSettingCommand.id,e)}o&&o()},children:b.t(`sheets-pivot-ui.dialog.ok`)})]})]})})]})}let Ni=class extends r.Disposable{constructor(e,t){super(),this._componentManager=e,this._iconManager=t,this._registerComponents(),this._registerIcons()}_registerComponents(){[[A,ki],[_,Ci],[y,Rr],[x,Mi],[C,qr],[T,wi],[E,ji],[D,jr],[O,Vr],[k,zr]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_registerIcons(){this.disposeWithMe(this._iconManager.register({PivotTableIcon:Vt}))}};Ni=K([G(0,(0,r.Inject)(a.ComponentManager)),G(1,(0,r.Inject)(a.IconManager))],Ni);let Pi=class extends r.Disposable{constructor(e){super(),this._menuManagerService=e,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(Qe)}};Pi=K([G(0,a.IMenuManagerService)],Pi);let Fi=class extends r.Disposable{constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._context=e,this._injector=t,this._sheetsPivotTableAdaptorModel=n,this._sheetSkeletonManagerService=r,this._sheetsPivotTableConfigModel=i,this._commandService=a,this._sheetPermissionCheckController=o,this._permissionService=s,this._localeService=c,this._selectionsService=l,this._cellAlerts=u,W(this,`_pivotButtonShapesArr`,[]),this._initButtonRender(),this._initSkeleton(),this._initListener(),this._initBlockedPivotAlert()}_initBlockedPivotAlert(){let e=`SHEET_PIVOT_BLOCKED:${this._context.unitId}`;this.disposeWithMe((0,s.merge)(this._selectionsService.selectionChanged$,this._context.unit.activeSheet$,this._sheetsPivotTableAdaptorModel.viewUpdate$).pipe((0,s.auditTime)(0)).subscribe(()=>{var t,n,r;let{unitId:i,unit:a}=this._context,s=this._selectionsService.currentSelectionParam,c=(t=a.getActiveSheet())==null?void 0:t.getSheetId(),l=(n=this._selectionsService.getCurrentSelections())==null||(n=n.slice(-1)[0])==null?void 0:n.primary;if(!c||!l||(s==null?void 0:s.unitId)!==i||s.sheetId!==c){this._cellAlerts.removeAlert(e);return}let{actualRow:u,actualColumn:d}=l,f=this._sheetsPivotTableAdaptorModel,m=f.getPivotTableIdByCell(i,c,u,d),h=m&&((r=f.getPivotItemRenderInfoCache(i,c,m))==null?void 0:r.blockedRange);if(!h){this._cellAlerts.removeAlert(e);return}let g=`sheets-pivot-ui.perform.blocked`;h.reason===`pivot`?g=`sheets-pivot-ui.perform.blockedByPivot`:h.reason===`merge`&&(g=`sheets-pivot-ui.perform.blockedByMerge`),this._cellAlerts.showAlert({key:e,type:o.CellAlertType.ERROR,title:this._localeService.t(`sheets-pivot-ui.perform.tips`),message:this._localeService.t(g,(0,p.serializeRange)(h)),location:{unitId:i,subUnitId:c,row:u,col:d},width:260,height:96})})),this.disposeWithMe(()=>this._cellAlerts.removeAlert(e))}_initButtonRender(){this.disposeWithMe((0,s.merge)(this._sheetsPivotTableAdaptorModel.viewUpdate$.pipe((0,s.auditTime)(0)),this._sheetSkeletonManagerService.currentSkeleton$,this._sheetsPivotTableConfigModel.pivotConfigChange$,this._permissionService.permissionPointUpdate$.pipe((0,s.auditTime)(100))).subscribe(()=>{if(!this._context.unit)return;let e=this._context.unitId,t=this._context.unit.getActiveSheet().getSheetId(),{scene:n}=this._context,r=this._localeService.getDirection(),a=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!a)return;let s=this._pivotButtonShapesArr;s.forEach(e=>e.dispose()),s.splice(0,s.length),this._sheetsPivotTableAdaptorModel.getSubUnitPivotMatrix(e,t).forValue((c,l,u)=>{if(u!=null&&u.pbt){let d=`sheets-pivot-button-${c}-${l}-${e}-${t}`,{startX:f,startY:p,endX:m,endY:h}=(0,o.getCoordByCell)(c,l,n,a),g=m-f,_=h-p;if(_<8||g<8||this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[i.WorkbookEditablePermission],worksheetTypes:[i.WorksheetViewPermission,i.WorksheetEditPermission,i.WorksheetPivotTablePermission],rangeTypes:[i.RangeProtectionPermissionViewPoint,i.RangeProtectionPermissionEditPoint]},[{startRow:c,endRow:c,startColumn:l,endColumn:l}],e,t)===!1)return;let v;if(mr.has(u.pbt)){let{left:n,top:i}=vr(r,`filter`,{startX:f,startY:p,endX:m,endY:h});v={left:n,top:i,height:16,width:16,zIndex:5e3,cellWidth:g,cellHeight:_,pivotParams:{col:l,row:c,unitId:e,subUnitId:t,buttonType:u.pbt}}}else if(hr.has(u.pbt)){let{left:n,top:i}=vr(r,`collapse`,{startX:f,startY:p,endX:m,endY:h});v={left:n,top:i,height:16,width:16,zIndex:5e3,cellWidth:g,cellHeight:_,pivotParams:{col:l,row:c,unitId:e,subUnitId:t,buttonType:u.pbt}}}else return;let y=this._injector.createInstance(gr,d,v);s.push(y)}}),s.length&&n.addObjects(s),n.makeDirty()}))}_initSkeleton(){var e;this.disposeWithMe(this._sheetsPivotTableAdaptorModel.markDirty$.subscribe(({unitId:e,subUnitId:t})=>{if(e===this._context.unitId&&(this._sheetSkeletonManagerService.makeDirty({sheetId:t}),this._context.unit.getActiveSheet().getSheetId()===t)){var n;this._sheetSkeletonManagerService.reCalculate(),(n=this._context.mainComponent)==null||n.makeDirty()}}));let t=this._context.unitId;this._context.unit.getSheets().forEach(e=>{var n;let r=e.getSheetId();(n=this._sheetsPivotTableAdaptorModel.getSubUnitPivotRenderCache(t,r))!=null&&n.size&&this._sheetSkeletonManagerService.makeDirty({sheetId:r})}),this._sheetSkeletonManagerService.reCalculate(),(e=this._context.mainComponent)==null||e.makeDirty()}_initListener(){let e=new r.DisposableCollection,{spreadsheet:t}=(0,o.getSheetObject)(this._context.unit,this._context);e.add(t.onDblclick$.subscribeEvent(e=>{if(e.button===2)return;let t=this._sheetSkeletonManagerService.getCurrentSkeleton();if(t==null)return;let r=this._context.scene,{row:i,column:a}=(0,o.getCoordByOffset)(e.offsetX,e.offsetY,r,t);this._commandService.executeCommand(n.PivotDrillDownCommand.id,{row:i,col:a})}))}};Fi=K([G(1,(0,r.Inject)(r.Injector)),G(2,(0,r.Inject)(n.SheetsPivotTableAdaptorModel)),G(3,(0,r.Inject)(o.SheetSkeletonManagerService)),G(4,(0,r.Inject)(n.SheetsPivotTableConfigModel)),G(5,(0,r.Inject)(r.ICommandService)),G(6,(0,r.Inject)(i.SheetPermissionCheckController)),G(7,(0,r.Inject)(r.IPermissionService)),G(8,(0,r.Inject)(r.LocaleService)),G(9,(0,r.Inject)(i.SheetsSelectionsService)),G(10,(0,r.Inject)(o.CellAlertManagerService))],Fi);var Ii=class e extends u.Shape{constructor(e){super(`SHEET_PIVOT_MOVE_KEY`),W(this,`_moveType`,void 0),this._moveType=e}_draw(t){this.width!==0&&this.height!==0&&e.drawWith(t,this)}static drawWith(e,t){let n=t._moveType;if(e.save(),e.strokeStyle=`#8bc34a`,e.lineWidth=2,n===`row`){let n=t.width;if(!n)return;e.beginPath(),e.moveTo(0,0),e.lineTo(0+n,0),e.moveTo(0,-10),e.lineTo(0,10),e.moveTo(0+n,-10),e.lineTo(0+n,10)}else{let n=t.height;if(!n)return;e.moveTo(0,0),e.lineTo(0,0+n),e.moveTo(-10,0),e.lineTo(10,0),e.moveTo(-10,0+n),e.lineTo(10,0+n)}e.stroke(),e.restore()}};let Li=class extends r.Disposable{constructor(e,t,n,r,i,a){super(),this._context=e,this._sheetsPivotTableAdaptorModel=t,this._sheetSkeletonManagerService=n,this._commandService=r,this._selectionRenderService=i,this._sheetsSelectionsService=a,W(this,`_pivotSelectionMoveShape`,void 0),W(this,`_scenePointerMoveSubscribe`,void 0),W(this,`_scenePointerUpSubscribe`,void 0),W(this,`_selectionControl`,void 0),W(this,`_moveStartRange`,void 0),W(this,`_moveStartCellIndex`,void 0),W(this,`_moveRowOrCol`,`row`),W(this,`_targetRange`,void 0),W(this,`_movePivotId`,void 0),this._initControl()}_controlMoving(e,t){let n=this._context.scene,r=n.getScrollXYInfoByViewport(u.Vector2.FromArray([e,t])),{scaleX:i,scaleY:a}=n.getAncestorScale(),o=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!o||!this._moveStartRange||!this._moveStartCellIndex)return;let{row:s,column:c}=o.getCellIndexByOffset(e,t,i,a,r);if(this._moveRowOrCol===`row`){var l;let e=0,t=0,n=this._moveStartRange.endColumn-this._moveStartRange.startColumn+1;if(this._moveStartCellIndex.column===this._moveStartRange.startColumn)e=c,t=c+n-1;else if(this._moveStartCellIndex.column===this._moveStartRange.endColumn)t=c,e=c-n+1;else{let r=this._moveStartCellIndex.column-this._moveStartRange.startColumn;e=c-r,t=c-r+n-1}let r=o.getCellWithCoordByIndex(s,e),i=o.getCellWithCoordByIndex(s,t),{startX:a,endY:u}=r,{endX:d}=i;this._targetRange={startRow:s,endRow:s,startColumn:e,endColumn:t},(l=this._pivotSelectionMoveShape)==null||l.transformByState({left:a,top:u,width:d-a,height:20})}else{var d;let e=0,t=0,n=this._moveStartRange.endRow-this._moveStartRange.startRow+1;if(this._moveStartCellIndex.row===this._moveStartRange.startRow)e=s,t=s+n-1;else if(this._moveStartCellIndex.row===this._moveStartRange.endRow)t=s,e=s-n+1;else{let r=this._moveStartCellIndex.row-this._moveStartRange.startRow;e=s-r,t=s-r+n-1}let r=o.getCellWithCoordByIndex(e,c),i=o.getCellWithCoordByIndex(t,c),{startX:a,startY:l}=r,{endY:u}=i;this._targetRange={startColumn:c,endColumn:c,startRow:e,endRow:t},(d=this._pivotSelectionMoveShape)==null||d.transformByState({left:a,top:l,width:20,height:u-l})}}_controlPointerDownHandler(e){var t,n,i;(t=this._selectionControl)==null||t.setControlExtensionDisable(!1),this._context.scene.setCursor(u.CURSOR_TYPE.DEFAULT);let a=this._sheetsSelectionsService.getCurrentSelections();if(!a.length||a.length>1)return;let o=a[0].range,s=this._context.unit,c=s.getActiveSheet(),l=s.getUnitId(),d=c.getSheetId(),f=this._sheetsPivotTableAdaptorModel.getSubUnitPivotRenderCache(l,d);if(!(f!=null&&f.size))return;let p=Array.from(f).find(([e,t])=>{let{rangesInfo:n}=t;if(!n)return!1;let{rowRanges:i,colRanges:a}=n,s=i[0],c=a[0],l=!1;return s&&(l=r.Rectangle.realContain(s,o),this._moveRowOrCol=`row`),!l&&c&&(l=r.Rectangle.realContain(c,o),this._moveRowOrCol=`col`),l});if(!p)return;this._movePivotId=p[0],this._pivotSelectionMoveShape||(this._pivotSelectionMoveShape=new Ii(this._moveRowOrCol),this._context.scene.addObject(this._pivotSelectionMoveShape));let m=this._context.scene,h=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!h)return;let{offsetX:g,offsetY:_}=e,v=m.getCoordRelativeToViewport(u.Vector2.FromArray([g,_])),{x:y,y:b}=v,x=m.getScrollXYInfoByViewport(v),{scaleX:S,scaleY:C}=m.getAncestorScale(),{row:w,column:T}=h.getCellIndexByOffset(y,b,S,C,x),E=(n=this._selectionControl)==null?void 0:n.model.getRange();if(this._moveStartRange=E,!E)return;let D=0;D=w<E.startRow?E.startRow:w>E.endRow?E.endRow:w;let O=0;O=T<E.startColumn?E.startColumn:T>E.endColumn?E.endColumn:T,this._moveStartCellIndex={row:D,column:O},(i=this._selectionControl)==null||i.setControlExtensionDisable(!0),this._scenePointerMoveSubscribe=m.onPointerMove$.subscribeEvent(e=>{let{offsetX:t,offsetY:n}=e,{x:r,y:i}=m.getCoordRelativeToViewport(u.Vector2.FromArray([t,n]));this._controlMoving(r,i),m.setCursor(u.CURSOR_TYPE.MOVE)}),this._scenePointerUpSubscribe=m.onPointerUp$.subscribeEvent(e=>{var t,n,r;(t=this._scenePointerMoveSubscribe)==null||t.unsubscribe(),this._scenePointerMoveSubscribe=null,(n=this._selectionControl)==null||n.setControlExtensionDisable(!1),this._selectionControl=null,m.setCursor(u.CURSOR_TYPE.DEFAULT),m.removeObject(this._pivotSelectionMoveShape),this._pivotSelectionMoveShape=null,this._updatePivotSort(),(r=this._scenePointerUpSubscribe)==null||r.unsubscribe(),this._scenePointerUpSubscribe=null})}_updatePivotSort(){if(!this._moveStartRange||!this._targetRange||!this._movePivotId)return;let e=this._context.unit.getUnitId(),r=this._context.unit.getActiveSheet().getSheetId();if(this._moveRowOrCol===`row`){var i;let o=(i=this._sheetsPivotTableAdaptorModel.getSubUnitPivotRenderCache(e,r))==null?void 0:i.get(this._movePivotId);if(!o)return;let s=this._sheetsPivotTableAdaptorModel.getSubUnitPivotMatrix(e,r);if(!s)return;let c=[],l=``,{headerMap:u,rangesInfo:d}=o;for(let e=this._moveStartRange.startColumn;e<=this._moveStartRange.endColumn;e++){var a;let n=u==null||(a=u.rowHeaderMap)==null?void 0:a[e];if(!n)continue;l=n.tableFieldId;let r=d==null?void 0:d.rowRanges,i=r==null?void 0:r[0];if(!i)continue;let o={...i,startColumn:e,endColumn:e};for(let n=o.startRow;n<=o.endRow;n++){let r=s.getValue(n,e);if(!r)continue;let{v:i,pbt:a}=r;i&&a!==t.PivotCellStyleTypeEnum.Subtotal&&a!==t.PivotCellStyleTypeEnum.GrandTotal&&(typeof i==`string`?c[n]=i:typeof i==`number`&&(c[n]=i.toString()))}break}if(!l)return;let f=this._moveStartRange.startRow,p=this._moveStartRange.endRow-this._moveStartRange.startRow+1,m=this._targetRange.startRow;if(f<m){let e=c.splice(f,p);c.splice(m-p,0,...e)}else{let e=c.splice(f,p);c.splice(m,0,...e)}let h=c.filter(e=>e!==void 0);this._commandService.executeCommand(n.SetPivotSortCommand.id,{unitId:e,subUnitId:r,pivotTableId:this._movePivotId,tableFieldId:l,info:{type:t.PivotDataFieldSortOperatorEnum.custom,customOrder:h}})}else{var o;let i=(o=this._sheetsPivotTableAdaptorModel.getSubUnitPivotRenderCache(e,r))==null?void 0:o.get(this._movePivotId);if(!i)return;let a=this._sheetsPivotTableAdaptorModel.getSubUnitPivotMatrix(e,r);if(!a)return;let c=[],l=``,{headerMap:u,rangesInfo:d}=i;for(let e=this._moveStartRange.startRow;e<=this._moveStartRange.endRow;e++){var s;let r=u==null||(s=u.colHeaderMap)==null?void 0:s[e];if(!r)continue;l=r.tableFieldId;let o=d==null?void 0:d.colRanges,f=o==null?void 0:o[0];if(!f)continue;let p={...f,startRow:e,endRow:e};for(let r=p.startColumn;r<=p.endColumn;r++){let o=a.getValue(e,r);if(!o)continue;let{v:s,pbt:l}=o;if(s&&l!==t.PivotCellStyleTypeEnum.Subtotal&&l!==t.PivotCellStyleTypeEnum.GrandTotal){if(typeof s==`string`){let e=i.projection?(0,n.mapPivotSheetColumn)(i.projection,r):r;c[e]=s}else if(typeof s==`number`){let e=i.projection?(0,n.mapPivotSheetColumn)(i.projection,r):r;c[e]=s.toString()}}}break}if(!l)return;let f=i.projection?(0,n.mapPivotSheetRange)(i.projection,this._moveStartRange):this._moveStartRange,p=i.projection?(0,n.mapPivotSheetRange)(i.projection,this._targetRange):this._targetRange,m=f.startColumn,h=this._moveStartRange.endColumn-this._moveStartRange.startColumn+1,g=p.startColumn;if(m<g){let e=c.splice(m,h);c.splice(g-h,0,...e)}else{let e=c.splice(m,h);c.splice(g,0,...e)}let _=c.filter(e=>e!==void 0);this._commandService.executeCommand(n.SetPivotSortCommand.id,{unitId:e,subUnitId:r,pivotTableId:this._movePivotId,tableFieldId:l,info:{type:t.PivotDataFieldSortOperatorEnum.custom,customOrder:_}})}}_initControl(){this.disposeWithMe(this._sheetsSelectionsService.selectionMoveEnd$.subscribe(()=>{let e=this._selectionRenderService.getSelectionControls();if(this._selectionControl=e[e.length-1],this._selectionControl&&this._selectionControl.setControlExtensionDisable(!1),!this._selectionControl)return;let{leftControl:t,rightControl:n,topControl:r,bottomControl:i}=this._selectionControl;[t,n,r,i].forEach(e=>{e.onPointerDown$.subscribeEvent(this._controlPointerDownHandler.bind(this))})}))}dispose(){var e,t;(e=this._scenePointerMoveSubscribe)==null||e.unsubscribe(),this._scenePointerMoveSubscribe=null,(t=this._scenePointerUpSubscribe)==null||t.unsubscribe(),this._scenePointerUpSubscribe=null,this._selectionControl=null,this._moveStartRange=null,this._moveStartCellIndex=null,this._targetRange=null,super.dispose()}};Li=K([G(1,(0,r.Inject)(n.SheetsPivotTableAdaptorModel)),G(2,(0,r.Inject)(o.SheetSkeletonManagerService)),G(3,(0,r.Inject)(r.ICommandService)),G(4,o.ISheetSelectionRenderService),G(5,(0,r.Inject)(i.SheetsSelectionsService))],Li);let $=class extends r.Plugin{constructor(e=ot,t,n,i,a){super(),this._config=e,this._injector=t,this._commandService=n,this._renderManagerService=i,this._configService=a;let{menu:o,...s}=(0,r.merge)({},ot,this._config);o&&this._configService.setConfig(`menu`,o,{merge:!0}),this._configService.setConfig(at,s),this._initRegisterCommand()}onStarting(){this._injector.add([Ni]),this._injector.get(Ni),[[Pi],[Dr],[Sr],[Q],[Er],[wr],[Tr],[q],[br]].forEach(e=>this._injector.add(e)),this._injector.get(q)}onReady(){this._registerRenderModules(),this._injector.get(Pi)}onRendered(){this._injector.get(Sr),this._injector.get(Q),this._injector.get(Er),this._injector.get(wr),this._injector.get(Tr),this._injector.get(br)}onSteady(){this._injector.get(Dr)}_registerRenderModules(){[[Fi],[Li]].forEach(e=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(r.UniverInstanceType.UNIVER_SHEET,e))})}_initRegisterCommand(){[it,N,tt,nt,F,z,ie,ae,oe,ue,fe,xe].forEach(e=>this._commandService.registerCommand(e))}};W($,`pluginName`,`${n.SHEET_PIVOT_TABLE_PLUGIN}_UI_PLUGIN`),W($,`packageName`,$e),W($,`version`,et),W($,`type`,r.UniverInstanceType.UNIVER_SHEET),$=K([(0,r.DependentOn)(l.UniverLicensePlugin,u.UniverRenderEnginePlugin,i.UniverSheetsPlugin,n.UniverSheetsPivotTablePlugin,o.UniverSheetsUIPlugin),G(1,(0,r.Inject)(r.Injector)),G(2,(0,r.Inject)(r.ICommandService)),G(3,u.IRenderManagerService),G(4,r.IConfigService)],$),e.DragDropContext=oi,e.Draggable=ci,e.Droppable=si,e.OpenPivotTableRangeSelectorPanelOperation=N,e.PivotFilterOptions=Jr,e.PivotFilterPanel=Rr,e.SheetsPivotTableUIMenuSchema=Qe,Object.defineProperty(e,"UniverSheetsPivotTableMobileUIPlugin",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(e,"UniverSheetsPivotTableUIPlugin",{enumerable:!0,get:function(){return $}})});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs-pro/engine-pivot"),require("@univerjs-pro/sheets-pivot"),require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/ui"),require("@univerjs/sheets-ui"),require("rxjs"),require("@univerjs/design"),require("@univerjs-pro/license"),require("@univerjs/engine-render"),require("react"),require("react/jsx-runtime"),require("@univerjs/engine-formula"),require("@univerjs/sheets-formula-ui"),require("@univerjs/icons-svg"),require("@univerjs/docs"),require("@univerjs/docs-ui")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs-pro/engine-pivot`,`@univerjs-pro/sheets-pivot`,`@univerjs/core`,`@univerjs/sheets`,`@univerjs/ui`,`@univerjs/sheets-ui`,`rxjs`,`@univerjs/design`,`@univerjs-pro/license`,`@univerjs/engine-render`,`react`,`react/jsx-runtime`,`@univerjs/engine-formula`,`@univerjs/sheets-formula-ui`,`@univerjs/icons-svg`,`@univerjs/docs`,`@univerjs/docs-ui`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverProSheetsPivotUi={},e.UniverProEnginePivot,e.UniverProSheetsPivot,e.UniverCore,e.UniverSheets,e.UniverUi,e.UniverSheetsUi,e.rxjs,e.UniverDesign,e.UniverProLicense,e.UniverEngineRender,e.React,e.React,e.UniverEngineFormula,e.UniverSheetsFormulaUi,e.UniverIconsSvg,e.UniverDocs,e.UniverDocsUi))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let v=`UNIVER_SHEET_PIVOT_PANEL`,y=`UNIVER_SHEET_PIVOT_PANEL_ID`,b=`UNIVER_SHEET_PIVOT_FILTER_PANEL`,x=`UNIVER_SHEET_PIVOT_FILTER_PANEL_ID`,S=`UNIVER_SHEET_PIVOT_FIELD_SETTING`,C=`UNIVER_SHEET_PIVOT_FIELD_SETTING_ID`,w=`UNIVER_SHEET_PIVOT_FIELD_NUMFMT`,T=`UNIVER_SHEET_PIVOT_FIELD_NUMFMT_ID`,E=`UNIVER_SHEET_PIVOT_SHOW_DATA_AS_DIALOG`,D=`UNIVER_SHEET_PIVOT_VALUE_FILTER_DIALOG`,O=`UNIVER_SHEET_PIVOT_EXCEL_DATE_GROUP_DIALOG`,k=`UNIVER_SHEET_PIVOT_NUMBER_GROUP_DIALOG`,A=`UNIVER_SHEET_PIVOT_MANUAL_GROUP_DIALOG`,j=`univer.sheet.pivot-table-range-selector`,M=`UNIVER_SHEET_PIVOT_MOBILE_ACTION_PANEL`,N=`UNIVER_SHEET_PIVOT_MOBILE_ACTION_PANEL_ID`,P={type:r.CommandType.OPERATION,id:`sheet.operation.open-pivot-table-range-selector-panel`,async handler(e){let a=e.get(r.IUniverInstanceService),o=e.get(r.ICommandService),s=(0,i.getSheetCommandTarget)(a),c=e.get(r.LocaleService);if(!s)return!1;let{unitId:l,subUnitId:u,worksheet:d,workbook:f}=s,p=e.get(i.SheetsSelectionsService).getCurrentLastSelection(),m=(p==null?void 0:p.range)??{startRow:0,endRow:0,startColumn:0,endColumn:0,rangeType:r.RANGE_TYPE.NORMAL},h=await F(e,l,u,(0,i.isSingleCellSelection)(p)?(0,i.expandToContinuousRange)(m,{up:!0,left:!0,right:!0,down:!0},d):m,d.getName());if(!h)return!1;let g=f.getSheets().find(e=>e.getName()===h.sourceSheetName);if(!g)return!1;let _;if(h.positionType===n.PositionType.New)_={row:0,col:0,unitId:l,subUnitId:(0,r.generateRandomId)(),sheetName:f.generateNewSheetName(`${c.t(`sheets-pivot-ui.sheet`)}`)};else{if(!h.positionRange||!h.positionSheetName)return!1;let e=f.getSheets().find(e=>e.getName()===h.positionSheetName);if(!e)return!1;_={row:h.positionRange.startRow,col:h.positionRange.startColumn,unitId:l,subUnitId:e.getSheetId(),sheetName:e.getName()}}let v=(0,t.generateHexNumber)(8);return await o.executeCommand(n.AddPivotTableCommand.id,{pivotTableId:v,pivotTableConfig:{targetCellInfo:_,sourceRangeInfo:{range:h.sourceRange,unitId:l,sheetName:h.sourceSheetName,subUnitId:g.getSheetId()}},positionType:h.positionType})?{unitId:_.unitId,subUnitId:_.subUnitId,pivotTableId:v}:!1}};async function F(e,t,n,i,o){let s=e.get(a.IDialogService),c=e.get(r.LocaleService);return new Promise(e=>{let r,a={unitId:t,subUnitId:n,sourceRange:i,positionRange:null,sourceSheetName:o,positionSheetName:o,onConfirm:t=>{e(t),r==null||r.dispose()},onCancel:()=>{e(null),r==null||r.dispose()}};r=s.open({id:j,title:{title:c.t(`sheets-pivot-ui.dialog.source.insertPivotTable`)},draggable:!0,mask:!1,maskClosable:!1,children:{label:{name:j,props:a}},width:400,onClose:()=>{r.dispose()}})})}let I={type:r.CommandType.OPERATION,id:`sheet.operation.set-pivot-date-group`,async handler(e,t){if(!t)return!1;let i=L(e);return i?e.get(r.ICommandService).executeCommand(n.SetPivotDateGroupCommand.id,{unitId:i.unitId,subUnitId:i.subUnitId,pivotTableId:i.pivotTableId,tableFieldId:i.tableFieldId,dateType:t.dateType}):!1}};function L(e,a=t.PivotDateGroupingMode.Legacy){let o=e.get(r.IUniverInstanceService),s=(0,i.getSheetCommandTarget)(o);if(!s)return;let c=e.get(i.SheetsSelectionsService).getCurrentLastSelection(),l=c==null?void 0:c.primary;if(!l)return;let{unitId:u,subUnitId:d}=s,f=l.startRow,p=l.startColumn,m=e.get(n.SheetsPivotTableAdaptorModel).getPivotTableIdByCell(u,d,f,p);if(!m)return;let h=R(e,u,d,m,f,p);if(!h)return;let g=e.get(n.SheetsPivotTableConfigModel),_=g.getPivotTableConfig(u,d,m);if((0,t.getPivotDateGroupingMode)(_==null?void 0:_.fieldsConfig.options)!==a)return;let v=g.getCollection(u,m),y=(0,n.getPivotDateGroupContext)(_==null?void 0:_.fieldsConfig,v,h);if(y)return{unitId:u,subUnitId:d,pivotTableId:m,tableFieldId:h,row:f,col:p,dateGroupContext:y}}function R(e,t,r,i,a,o){let s=e.get(n.SheetsPivotTableAdaptorModel).getPivotItemRenderInfoCache(t,r,i);if(!s)return;let c=e.get(n.SheetsPivotTableAdaptorModel).getPivotTableCellData(t,r,a,o),l=(0,n.resolvePivotSheetCell)(a,o,c,s);return l==null?void 0:l.tableFieldId}function z(e){let r=L(e,t.PivotDateGroupingMode.ExcelLike);if(!r)return;let i=e.get(n.SheetsPivotTableConfigModel),a=i.getPivotTableConfig(r.unitId,r.subUnitId,r.pivotTableId),o=a==null?void 0:a.fieldsConfig.dimension[r.tableFieldId];if(!o)return;let s=i.getCollection(r.unitId,r.pivotTableId),c=(r.dateGroupContext.area===t.PivotTableFiledAreaEnum.Row?a.fieldsConfig.rowFields:a.fieldsConfig.columnFields).flatMap(e=>{let n=a.fieldsConfig.dimension[e],i=n?s==null?void 0:s.fields[n.dataFieldId]:void 0;return i&&(0,t.isDateGroupFieldJSON)(i)&&i.originalFieldId===r.dateGroupContext.originalDataFieldId&&i.excelLike?[i.excelLike]:[]}),l=c[0],u=l?{units:c.map(e=>e.unit),autoStart:l.autoStart,autoEnd:l.autoEnd,...l.start===void 0?{}:{start:l.start},...l.end===void 0?{}:{end:l.end},...l.daysInterval===void 0?{}:{daysInterval:l.daysInterval}}:void 0;return{...r,targetFieldName:o.displayName,grouping:u}}let B={id:`sheet.operation.set-pivot-excel-date-group`,type:r.CommandType.OPERATION,async handler(e){let t=z(e);if(!t)return!1;let i=e.get(n.SheetsPivotTableConfigModel),o=i.getPivotTableConfig(t.unitId,t.subUnitId,t.pivotTableId),s=i.getCollection(t.unitId,t.pivotTableId),c=e.get(a.IDialogService),l=e.get(r.LocaleService),u=e.get(r.IUniverInstanceService).getUnit(t.unitId),d=(u==null?void 0:u.getDateSystem())??r.DateSystem.Date1900,f=null,p=!1,m=!1,h=()=>{p||(p=!0,f==null||f.dispose(),f=null)},g=async a=>{if(!(m||p)){m=!0;try{let c=z(e);if(!c||c.unitId!==t.unitId||c.subUnitId!==t.subUnitId||c.pivotTableId!==t.pivotTableId||c.tableFieldId!==t.tableFieldId||i.getPivotTableConfig(t.unitId,t.subUnitId,t.pivotTableId)!==o||i.getCollection(t.unitId,t.pivotTableId)!==s)return;await e.get(r.ICommandService).executeCommand(n.SetPivotExcelDateGroupCommand.id,{unitId:t.unitId,subUnitId:t.subUnitId,pivotTableId:t.pivotTableId,tableFieldId:t.tableFieldId,grouping:{...a,units:a.units.concat()}})}catch{}finally{h()}}};try{f=c.open({id:`UNIVER_SHEET_PIVOT_EXCEL_DATE_GROUP_DIALOG_ID`,title:{title:l.t(`sheets-pivot-ui.dateGroup.excelLikeTitle`)},draggable:!0,mask:!0,maskClosable:!1,width:440,children:{label:{name:O,props:{targetFieldName:t.targetFieldName,dateSystem:d,grouping:t.grouping,onConfirm:g,onCancel:h}}},onClose:h})}catch{return h(),!1}return!0}};function V(e){return e.map(e=>({...e,members:e.members.map(e=>({...e}))}))}function ee(e){let n;try{n=JSON.parse(e)}catch{return}if(!(!Array.isArray(n)||n.length<1||typeof n[0]!=`string`))return n[0]===r.RecordValueType.Blank?t.GlobalConfig.BLANK_PLACEHOLDER:String(n[1])}function te(e,a){var o;let s=()=>({error:`invalidSelection`}),c=(0,i.getSheetCommandTarget)(e.get(r.IUniverInstanceService)),l=e.get(i.SheetsSelectionsService).getCurrentSelections();if(!c||!l.length)return s();let{unitId:u,subUnitId:d}=c,f=l[0].primary;if(!f)return s();let p=e.get(n.SheetsPivotTableAdaptorModel),m=p.getPivotTableIdByCell(u,d,f.startRow,f.startColumn),h=e.get(n.SheetsPivotTableConfigModel),g=m&&h.getPivotTableConfig(u,d,m),_=m&&h.getCollection(u,m),v=m&&p.getPivotItemRenderInfoCache(u,d,m);if(!m||!g||!_||!v)return s();let y=(0,n.resolvePivotSheetCell)(f.startRow,f.startColumn,p.getPivotTableCellData(u,d,f.startRow,f.startColumn),v),b=y==null?void 0:y.tableFieldId,x=b&&g.fieldsConfig.dimension[b];if(!b||!x||!(g.fieldsConfig.rowFields.includes(b)||g.fieldsConfig.columnFields.includes(b)))return s();let S=_.fields[x.dataFieldId];if(!S)return s();let C=S.dataFieldType===t.PivotDataFieldTypeEnum.textGroupField?S:void 0;if(!C&&S.dataFieldType!==t.PivotDataFieldTypeEnum.defaultNormalField)return s();let w=(C==null?void 0:C.originalFieldId)??S.id;if(((o=_.fields[w])==null?void 0:o.dataFieldType)!==t.PivotDataFieldTypeEnum.defaultNormalField)return s();let T=V((C==null?void 0:C.grouping.groups)??[]),E=/* @__PURE__ */ new Map,D=/* @__PURE__ */ new Set,O=0;for(let e of l){let{startRow:r,endRow:i,startColumn:a,endColumn:o}=e.range;if(O+=(i-r+1)*(o-a+1),O>512)return s();for(let e=r;e<=i;e++)for(let r=a;r<=o;r++){if(p.getPivotTableIdByCell(u,d,e,r)!==m)return s();let i=(0,n.resolvePivotSheetCell)(e,r,p.getPivotTableCellData(u,d,e,r),v),a=i==null?void 0:i.info;if(!i||i.area!==`rowRanges`&&i.area!==`colRanges`||i.tableFieldId!==b||!a||a.isValue||a.isSubtotal||a.isBottomTotal||a.isTopTotal||a.rowType&&a.rowType!==`item`||a.level<1)return s();let o=a.paths[a.level-1];if(o===void 0)return s();if(C){let e;try{e=JSON.parse(o)}catch{return s()}if(!Array.isArray(e)||e.length!==2||typeof e[1]!=`string`)return s();if(e[0]===`group`){if(!T.some(t=>t.id===e[1]))return s();D.add(e[1]);continue}if(e[0]!==`member`)return s();let t=ee(e[1]);if(t===void 0)return s();E.set(e[1],{path:t,memberKey:e[1]})}else{var k;let n=(k=p.getPivotTableCellData(u,d,e,r))==null?void 0:k.v,i=n==null||n===``?t.GlobalConfig.BLANK_PLACEHOLDER:String(n);E.set(o,{path:i,tupleKey:o})}}}return a===`group`&&(E.size<2||D.size>0)||a!==`group`&&(E.size>0||D.size!==1)?s():{context:{unitId:u,subUnitId:d,pivotTableId:m,tableFieldId:b,sourceFieldId:w,targetFieldName:x.displayName,groups:T,memberPaths:Array.from(E.values()),selectedGroupId:Array.from(D)[0]}}}function ne(e,t){return te(e,t).context}function H(e,t){e.get(a.IMessageService).show({type:c.MessageType.Error,content:e.get(r.LocaleService).t(`sheets-pivot-ui.manualGroup.${t}`)})}function re(e,t,n){let r=ne(e,t);return!!r&&r.unitId===n.unitId&&r.subUnitId===n.subUnitId&&r.pivotTableId===n.pivotTableId&&r.tableFieldId===n.tableFieldId&&r.sourceFieldId===n.sourceFieldId&&r.selectedGroupId===n.selectedGroupId&&JSON.stringify(r.memberPaths)===JSON.stringify(n.memberPaths)&&JSON.stringify(r.groups)===JSON.stringify(n.groups)}async function ie(e,t){let i=te(e,t),o=i.context;if(!o)return H(e,i.error),!1;let s=e.get(n.SheetsPivotTableConfigModel),c=s.getPivotTableConfig(o.unitId,o.subUnitId,o.pivotTableId),l=s.getCollection(o.unitId,o.pivotTableId),u=[];if(t===`group`){try{let t=(await e.get(n.SheetsPivotRPCService).getPivotDisplayConfig({unitId:o.unitId,subUnitId:o.subUnitId,pivotTableId:o.pivotTableId,params:{type:n.PivotDisplayDataType.ManualGroupMembers,manualGroupMembers:{sourceFieldId:o.sourceFieldId,paths:o.memberPaths}}})).result.manualGroupMembers;if(!t||t.error||t.members.length<2)return H(e,(t==null?void 0:t.error)??`invalidSelection`),!1;u=t.members}catch{return H(e,`invalidSelection`),!1}if(!re(e,t,o)||s.getPivotTableConfig(o.unitId,o.subUnitId,o.pivotTableId)!==c||s.getCollection(o.unitId,o.pivotTableId)!==l)return!1}let d=e.get(a.IDialogService),f=e.get(r.LocaleService),p=o.groups.find(e=>e.id===o.selectedGroupId),m=(p==null?void 0:p.name)??f.t(`sheets-pivot-ui.manualGroup.defaultName`,String(o.groups.length+1));if(!p){let e=o.groups.length+1;for(;o.groups.some(e=>e.name===m);)e++,m=f.t(`sheets-pivot-ui.manualGroup.defaultName`,String(e))}let h=null,g=!1,_=!1,v=()=>{g||(g=!0,h==null||h.dispose(),h=null)},y=async i=>{if(_||g)return;let a=i.trim();if(!a||o.groups.some(e=>e.name===a&&e.id!==o.selectedGroupId))H(e,`invalidSelection`);else{_=!0;try{if(!re(e,t,o)||s.getPivotTableConfig(o.unitId,o.subUnitId,o.pivotTableId)!==c||s.getCollection(o.unitId,o.pivotTableId)!==l)return;let i=t===`group`?o.groups.concat({id:(0,r.generateRandomId)(),name:a,members:u.map(e=>({...e}))}):o.groups.map(e=>e.id===o.selectedGroupId?{...e,name:a}:e);await e.get(r.ICommandService).executeCommand(n.SetPivotManualGroupsCommand.id,{unitId:o.unitId,subUnitId:o.subUnitId,pivotTableId:o.pivotTableId,sourceFieldId:o.sourceFieldId,groups:i})}catch{}finally{v()}}};try{h=d.open({id:`UNIVER_SHEET_PIVOT_MANUAL_GROUP_DIALOG_ID`,title:{title:f.t(t===`group`?`sheets-pivot-ui.manualGroup.groupTitle`:`sheets-pivot-ui.manualGroup.renameTitle`)},draggable:!0,mask:!0,maskClosable:!1,width:400,children:{label:{name:A,props:{name:m,onConfirm:y,onCancel:v}}},onClose:v})}catch{return v(),!1}return!0}let ae={id:`sheet.operation.set-pivot-manual-group`,type:r.CommandType.OPERATION,handler:e=>ie(e,`group`)},oe={id:`sheet.operation.rename-pivot-manual-group`,type:r.CommandType.OPERATION,handler:e=>ie(e,`rename`)},se={id:`sheet.operation.ungroup-pivot-manual-group`,type:r.CommandType.OPERATION,async handler(e){let t=te(e,`ungroup`),i=t.context;if(!i)return H(e,t.error),!1;let a=e.get(n.SheetsPivotTableConfigModel),o=a.getPivotTableConfig(i.unitId,i.subUnitId,i.pivotTableId),s=a.getCollection(i.unitId,i.pivotTableId);return!re(e,`ungroup`,i)||a.getPivotTableConfig(i.unitId,i.subUnitId,i.pivotTableId)!==o||a.getCollection(i.unitId,i.pivotTableId)!==s?!1:e.get(r.ICommandService).executeCommand(n.SetPivotManualGroupsCommand.id,{unitId:i.unitId,subUnitId:i.subUnitId,pivotTableId:i.pivotTableId,sourceFieldId:i.sourceFieldId,groups:i.groups.filter(e=>e.id!==i.selectedGroupId)})}};function ce(e){return typeof e.autoStart==`boolean`&&typeof e.autoEnd==`boolean`&&Number.isFinite(e.interval)&&e.interval>0&&(e.start===void 0||Number.isFinite(e.start))&&(e.end===void 0||Number.isFinite(e.end))&&(e.autoStart||e.start!==void 0)&&(e.autoEnd||e.end!==void 0)&&(e.start===void 0||e.end===void 0||e.start<=e.end)}function le(e,n){if(e.dataFieldType===t.PivotDataFieldTypeEnum.numberGroupField){let r=e,i=n.fields[r.originalFieldId];return!i||i.dataFieldType!==t.PivotDataFieldTypeEnum.defaultNormalField||i.fieldDataType!==t.PivotDataFieldDataTypeEnum.number?void 0:{sourceFieldId:r.originalFieldId,grouping:{...r.grouping}}}if(e.dataFieldType===t.PivotDataFieldTypeEnum.defaultNormalField&&e.fieldDataType===t.PivotDataFieldDataTypeEnum.number)return{sourceFieldId:e.id}}function ue(e){var t;let a=(0,i.getSheetCommandTarget)(e.get(r.IUniverInstanceService)),o=(t=e.get(i.SheetsSelectionsService).getCurrentLastSelection())==null?void 0:t.primary;if(!a||!o)return;let{unitId:s,subUnitId:c}=a,l=o.startRow,u=o.startColumn,d=e.get(n.SheetsPivotTableAdaptorModel),f=d.getPivotTableIdByCell(s,c,l,u);if(!f)return;let p=d.getPivotItemRenderInfoCache(s,c,f);if(!p)return;let m=(0,n.resolvePivotSheetCell)(l,u,d.getPivotTableCellData(s,c,l,u),p),h=m==null?void 0:m.tableFieldId;if(!h||m.area!==`rowRanges`&&m.area!==`colRanges`)return;let g=e.get(n.SheetsPivotTableConfigModel),_=g.getPivotTableConfig(s,c,f),v=g.getCollection(s,f),y=_==null?void 0:_.fieldsConfig.dimension[h];if(!y||!v||!(_.fieldsConfig.rowFields.includes(h)||_.fieldsConfig.columnFields.includes(h)))return;let b=v.fields[y.dataFieldId];if(!b)return;let x=le(b,v);if(x)return{unitId:s,subUnitId:c,pivotTableId:f,tableFieldId:h,targetFieldName:y.displayName,...x}}let de={id:`sheet.operation.set-pivot-number-group`,type:r.CommandType.OPERATION,async handler(e){let t=ue(e);if(!t)return!1;let i=e.get(n.SheetsPivotTableConfigModel),o=i.getCollection(t.unitId,t.pivotTableId),c=i.getPivotTableConfig(t.unitId,t.subUnitId,t.pivotTableId),l=e.get(r.IUniverInstanceService),u=()=>{let n=ue(e);return!!n&&n.unitId===t.unitId&&n.subUnitId===t.subUnitId&&n.pivotTableId===t.pivotTableId&&n.tableFieldId===t.tableFieldId&&n.sourceFieldId===t.sourceFieldId&&JSON.stringify(n.grouping)===JSON.stringify(t.grouping)},d=e.get(a.IDialogService),f=e.get(r.LocaleService),p=null,m=!1,h=!1,g=new s.Subject,_=async()=>{if(!m&&u())try{let r=(await e.get(n.SheetsPivotRPCService).getPivotDisplayConfig({unitId:t.unitId,subUnitId:t.subUnitId,pivotTableId:t.pivotTableId,params:{type:n.PivotDisplayDataType.NumberGroupDefaults,numberGroupDefaults:{tableFieldId:t.tableFieldId}}})).result.numberGroupDefaults;return!m&&u()&&r&&ce(r)?r:void 0}catch{return}},v=()=>{m||(m=!0,g.next(),g.complete(),p==null||p.dispose(),p=null)},y=await _();if(!y)return v(),!1;let b=l.unitDisposed$.pipe((0,s.filter)(e=>e.getUnitId()===t.unitId),(0,s.tap)(v)),x=(0,s.defer)(()=>{if(m||!l.getUnit(t.unitId))return v(),s.EMPTY;let e=i.watchPivotTableChanges(t.unitId,t.subUnitId,t.pivotTableId).pipe((0,s.debounceTime)(0),(0,s.map)(()=>void 0));return(0,s.merge)((0,s.of)(y),e).pipe((0,s.switchMap)(e=>e&&i.getCollection(t.unitId,t.pivotTableId)===o&&i.getPivotTableConfig(t.unitId,t.subUnitId,t.pivotTableId)===c?(0,s.of)(e):(0,s.concat)((0,s.of)(void 0),_())),(0,s.takeUntil)((0,s.merge)(g,b)))}),S=async i=>{if(!(h||m)){h=!0;try{if(!ce(i)||!u())return;await e.get(r.ICommandService).executeCommand(n.SetPivotNumberGroupCommand.id,{unitId:t.unitId,subUnitId:t.subUnitId,pivotTableId:t.pivotTableId,tableFieldId:t.tableFieldId,grouping:{...i}})}catch{}finally{v()}}};try{p=d.open({id:`UNIVER_SHEET_PIVOT_NUMBER_GROUP_DIALOG_ID`,title:{title:f.t(`sheets-pivot-ui.numberGroup.title`)},draggable:!0,mask:!0,maskClosable:!1,width:400,children:{label:{name:k,props:{targetFieldName:t.targetFieldName,grouping:t.grouping,defaults$:x,onConfirm:S,onCancel:v}}},onClose:v})}catch{return v(),!1}return!0}},fe=[{type:t.PivotShowAsTypeEnum.normal,localeKey:`sheets-pivot-ui.showValuesAs.normal`,requiresParameters:!1,baseItemMode:`none`},{type:t.PivotShowAsTypeEnum.percentOfGrandTotal,localeKey:`sheets-pivot-ui.showValuesAs.percentOfGrandTotal`,requiresParameters:!1,baseItemMode:`none`},{type:t.PivotShowAsTypeEnum.percentOfRowTotal,localeKey:`sheets-pivot-ui.showValuesAs.percentOfRowTotal`,requiresParameters:!1,baseItemMode:`none`},{type:t.PivotShowAsTypeEnum.percentOfColumnTotal,localeKey:`sheets-pivot-ui.showValuesAs.percentOfColumnTotal`,requiresParameters:!1,baseItemMode:`none`},{type:t.PivotShowAsTypeEnum.percentOfParentRowTotal,localeKey:`sheets-pivot-ui.showValuesAs.percentOfParentRowTotal`,requiresParameters:!1,baseItemMode:`none`},{type:t.PivotShowAsTypeEnum.percentOfParentColumnTotal,localeKey:`sheets-pivot-ui.showValuesAs.percentOfParentColumnTotal`,requiresParameters:!1,baseItemMode:`none`},{type:t.PivotShowAsTypeEnum.index,localeKey:`sheets-pivot-ui.showValuesAs.index`,requiresParameters:!1,baseItemMode:`none`},{type:t.PivotShowAsTypeEnum.percentOfParent,localeKey:`sheets-pivot-ui.showValuesAs.percentOfParent`,requiresParameters:!0,baseItemMode:`none`,parentFieldOnly:!0},{type:t.PivotShowAsTypeEnum.percentOf,localeKey:`sheets-pivot-ui.showValuesAs.percentOf`,requiresParameters:!0,baseItemMode:`item`},{type:t.PivotShowAsTypeEnum.differenceFrom,localeKey:`sheets-pivot-ui.showValuesAs.differenceFrom`,requiresParameters:!0,baseItemMode:`item-or-relative`},{type:t.PivotShowAsTypeEnum.percentDifferenceFrom,localeKey:`sheets-pivot-ui.showValuesAs.percentDifferenceFrom`,requiresParameters:!0,baseItemMode:`item-or-relative`},{type:t.PivotShowAsTypeEnum.runningTotal,localeKey:`sheets-pivot-ui.showValuesAs.runningTotal`,requiresParameters:!0,baseItemMode:`none`},{type:t.PivotShowAsTypeEnum.percentRunningTotal,localeKey:`sheets-pivot-ui.showValuesAs.percentRunningTotal`,requiresParameters:!0,baseItemMode:`none`},{type:t.PivotShowAsTypeEnum.rankAscending,localeKey:`sheets-pivot-ui.showValuesAs.rankAscending`,requiresParameters:!0,baseItemMode:`none`},{type:t.PivotShowAsTypeEnum.rankDescending,localeKey:`sheets-pivot-ui.showValuesAs.rankDescending`,requiresParameters:!0,baseItemMode:`none`}],pe={type:r.CommandType.OPERATION,id:`sheet.operation.set-pivot-show-data-as`,async handler(e,t){let i=t&&fe.find(e=>e.type===t.type);if(!i)return!1;let o=he(e);if(!o)return!1;if(!i.requiresParameters)return e.get(r.ICommandService).executeCommand(n.UpdatePivotFieldSettingCommand.id,{unitId:o.unitId,subUnitId:o.subUnitId,pivotTableId:o.pivotTableId,tableFieldId:o.tableFieldId,showDataAs:{type:i.type,baseFieldId:``,baseItem:``},tableFieldInfo:o.tableFieldInfo,dataFieldInfo:o.dataFieldInfo});let s=ge(e,o);if(!s)return!1;let c=me(s.config,s.collection,i);if(c.length===0)return!1;let l={};if(i.baseItemMode!==`none`){try{l=await _e(e,s.config,o.pivotTableId,c)}catch{return!1}if(!c.some(e=>l[e]&&(i.baseItemMode===`item-or-relative`||l[e].items.length>0)))return!1}let u=e.get(a.IDialogService),d=e.get(r.LocaleService),f=null,p=!1,m=!1,h=()=>{p||(p=!0,f==null||f.dispose(),f=null)};try{f=u.open({id:`UNIVER_SHEET_PIVOT_SHOW_DATA_AS_DIALOG_ID`,title:{title:d.t(`sheets-pivot-ui.showValuesAs.dialogTitle`)},draggable:!0,mask:!0,maskClosable:!1,width:400,children:{label:{name:E,props:{unitId:o.unitId,subUnitId:o.subUnitId,pivotTableId:o.pivotTableId,tableFieldId:o.tableFieldId,type:i.type,baseItems:l,onCancel:h,onConfirm:async t=>{if(!m){m=!0;try{let s=ge(e,o);if(!s||!ve(s.config,s.collection,i,t))return;if(i.baseItemMode!==`none`&&t.baseItemType===void 0){var a;if(!((a=(await _e(e,s.config,s.context.pivotTableId,[t.baseFieldId]))[t.baseFieldId])!=null&&a.items.includes(t.baseItem)))return}await e.get(r.ICommandService).executeCommand(n.UpdatePivotFieldSettingCommand.id,{unitId:s.context.unitId,subUnitId:s.context.subUnitId,pivotTableId:s.context.pivotTableId,tableFieldId:s.context.tableFieldId,showDataAs:t,tableFieldInfo:s.context.tableFieldInfo,dataFieldInfo:s.context.dataFieldInfo})}catch{}finally{h()}}}}}},onClose:h})}catch{return h(),!1}return!0}};function me(e,t,n){let{rowFields:r,columnFields:i,dimension:a}=e.fieldsConfig;return(n.parentFieldOnly?[...r.slice(0,-1),...i.slice(0,-1)]:[...r,...i]).filter(e=>{let n=a[e];return!!(n&&(t.fields[n.dataFieldId]||t.customFields.find(e=>e.id===n.dataFieldId)))})}function he(e){var t,a;let o=(0,i.getSheetCommandTarget)(e.get(r.IUniverInstanceService)),s=(t=e.get(i.SheetsSelectionsService).getCurrentLastSelection())==null?void 0:t.primary;if(!o||!s)return;let{unitId:c,subUnitId:l}=o,u=s.startRow,d=s.startColumn,f=e.get(n.SheetsPivotTableAdaptorModel),p=f.getPivotTableIdByCell(c,l,u,d);if(!p)return;let m=e.get(n.SheetsPivotTableConfigModel).getPivotTableConfig(c,l,p),h=f.getPivotItemRenderInfoCache(c,l,p),g=f.getPivotTableCellData(c,l,u,d);if(!m||!h)return;let _=(0,n.resolvePivotSheetCell)(u,d,g,h);if(!_)return;let v=(0,n.resolvePivotValueFieldId)(_,m.fieldsConfig.valueFields);if(v)return(a=ge(e,{unitId:c,subUnitId:l,pivotTableId:p,tableFieldId:v}))==null?void 0:a.context}function ge(e,t){let{unitId:r,subUnitId:i,pivotTableId:a,tableFieldId:o}=t,s=e.get(n.SheetsPivotTableConfigModel),c=s.getPivotTableConfig(r,i,a),l=s.getCollection(r,a),u=c==null?void 0:c.fieldsConfig.measure[o];if(!c||!l||!u||!c.fieldsConfig.valueFields.includes(u.id))return;let d=l.fields[u.dataFieldId]??l.customFields.find(e=>e.id===u.dataFieldId);if(!d)return;let f={...u.showDataAs};return{config:c,collection:l,context:{unitId:r,subUnitId:i,pivotTableId:a,tableFieldId:u.id,currentShowDataAs:f,tableFieldInfo:{tableFieldId:u.id,displayName:u.displayName,dataFieldId:u.dataFieldId,format:u.format,subTotalType:u.subtotal,showDataAs:{...f}},dataFieldInfo:{id:d.id,dataFieldId:d.id,name:d.name,type:d.fieldDataType,checked:!0,pivotTableId:a}}}}async function _e(e,t,r,i){let{unitId:a,subUnitId:o}=t.targetCellInfo,s=t.targetCellInfo,c=e.get(n.SheetsPivotTableAdaptorModel).getPivotItemRenderInfoCache(a,o,r);if(!c)throw Error(`[sheets-pivot-ui]: Pivot render cache is unavailable`);return(await Promise.all(i.map(async t=>{try{return[t,(await e.get(n.SheetsPivotRPCService).getPivotDisplayConfig({unitId:a,subUnitId:o,pivotTableId:r,params:{type:n.PivotDisplayDataType.Filter,filter:{row:s.row,col:s.col,tableFieldId:t,pivotItemRenderInfoCache:c}}})).result.filter]}catch{return[t,void 0]}}))).reduce((e,[t,n])=>(n&&(e[t]={items:n.items,itemTypes:n.itemTypes,...n.itemLabels?{itemLabels:n.itemLabels}:{},format:n.format}),e),{})}function ve(e,n,r,i){return i.type!==r.type||!me(e,n,r).includes(i.baseFieldId)?!1:r.baseItemMode===`none`?i.baseItem===``&&i.baseItemType===void 0:i.baseItemType===void 0?i.baseItem!==``:r.baseItemMode===`item-or-relative`&&i.baseItem===``&&(i.baseItemType===t.PivotShowAsBaseItemTypeEnum.previous||i.baseItemType===t.PivotShowAsBaseItemTypeEnum.next)}function ye(e){return{...e,expected:Array.isArray(e.expected)?e.expected.concat():e.expected}}function be(e,t){let r=e.get(n.SheetsPivotTableConfigModel).getPivotTableConfig(t.unitId,t.subUnitId,t.pivotTableId);if(r&&r.fieldsConfig.dimension[t.targetFieldId]&&(r.fieldsConfig.rowFields.includes(t.targetFieldId)||r.fieldsConfig.columnFields.includes(t.targetFieldId)))return r}function xe(e){var t,a;let o=(0,i.getSheetCommandTarget)(e.get(r.IUniverInstanceService)),s=(t=e.get(i.SheetsSelectionsService).getCurrentLastSelection())==null?void 0:t.primary;if(!o||!s)return;let{unitId:c,subUnitId:l}=o,u=s.startRow,d=s.startColumn,f=e.get(n.SheetsPivotTableAdaptorModel),p=f.getPivotTableIdByCell(c,l,u,d);if(!p)return;let m=e.get(n.SheetsPivotTableConfigModel).getPivotTableConfig(c,l,p),h=f.getPivotItemRenderInfoCache(c,l,p);if(!m||!h)return;let g=(0,n.resolvePivotSheetCell)(u,d,f.getPivotTableCellData(c,l,u,d),h),_=g&&(0,n.resolvePivotValueFilterTarget)(g,m.fieldsConfig);if(!_)return;let v=m.fieldsConfig.dimension[_.targetFieldId],y=m.fieldsConfig.valueFields.flatMap(e=>{let t=m.fieldsConfig.measure[e];return t?[{id:t.id,label:t.displayName}]:[]});if(!v||y.length===0)return;let b=(a=m.fieldsConfig.valueFilter)==null||(a=a.find(e=>e.fieldId===_.targetFieldId))==null?void 0:a.filterInfo;return{unitId:c,subUnitId:l,pivotTableId:p,targetFieldId:_.targetFieldId,targetFieldName:v.displayName,valueFields:y,defaultValueFieldId:_.defaultValueFieldId,...b?{currentFilter:ye(b)}:{}}}let Se={type:r.CommandType.OPERATION,id:`sheet.operation.set-pivot-value-filter`,async handler(e){let i=xe(e);if(!i)return!1;let o=e.get(a.IDialogService),s=e.get(r.LocaleService),c=null,l=!1,u=!1,d=()=>{l||(l=!0,c==null||c.dispose(),c=null)},f=async a=>{if(!u){u=!0;try{let o=be(e,i);if(!o||a&&(!o.fieldsConfig.measure[a.valueFieldId]||!o.fieldsConfig.valueFields.includes(a.valueFieldId)||!(0,t.isValueFilterOperator)(a.operator)))return;await e.get(r.ICommandService).executeCommand(n.SetPivotValueFilterCommand.id,{unitId:i.unitId,subUnitId:i.subUnitId,pivotTableId:i.pivotTableId,fieldId:i.targetFieldId,valueFilterInfo:a?{...a,type:t.PivotFilterTypeEnum.ValueFilter,expected:Array.isArray(a.expected)?a.expected.concat():a.expected}:void 0})}catch{}finally{d()}}};try{c=o.open({id:`UNIVER_SHEET_PIVOT_VALUE_FILTER_DIALOG_ID`,title:{title:s.t(`sheets-pivot-ui.valueFilter.dialogTitle`)},draggable:!0,mask:!0,maskClosable:!1,width:420,children:{label:{name:D,props:{targetFieldId:i.targetFieldId,targetFieldName:i.targetFieldName,valueFields:i.valueFields,defaultValueFieldId:i.defaultValueFieldId,currentFilter:i.currentFilter,onConfirm:e=>f(e),onClear:()=>f(void 0),onCancel:d}}},onClose:d})}catch{return d(),!1}return!0}},Ce=`sheet.pivot.context-menu.date-group`,we=`sheet.pivot.context-menu.excel-date-group`,Te=`sheet.pivot.context-menu.number-group`,Ee=`sheet.pivot.context-menu.manual-group`,De=`sheet.pivot.context-menu.manual-rename`,Oe=`sheet.pivot.context-menu.manual-ungroup`,ke=`sheet.pivot.context-menu.show-data-as`,Ae=`sheet.pivot.context-menu.value-filter`,je={year:`sheets-pivot-ui.dateGroup.year`,"year-quarter":`sheets-pivot-ui.dateGroup.yearQuarter`,quarter:`sheets-pivot-ui.dateGroup.quarter`,"year-month":`sheets-pivot-ui.dateGroup.yearMonth`,month:`sheets-pivot-ui.dateGroup.month`,"month-date":`sheets-pivot-ui.dateGroup.monthDate`,"year-month-date":`sheets-pivot-ui.dateGroup.yearMonthDate`,date:`sheets-pivot-ui.dateGroup.date`,hour:`sheets-pivot-ui.dateGroup.hour`,minute:`sheets-pivot-ui.dateGroup.minute`,"hour-minute":`sheets-pivot-ui.dateGroup.hourMinute`};function Me(e){return{id:P.id,type:a.MenuItemType.BUTTON,icon:`PivotTableIcon`,hidden$:(0,a.getMenuHiddenObservable)(e,r.UniverInstanceType.UNIVER_SHEET),disabled$:(0,o.getObservableWithExclusiveRange$)(e,(0,o.getCurrentRangeDisable$)(e,{workbookTypes:[i.WorkbookEditablePermission],worksheetTypes:[i.WorksheetViewPermission,i.WorksheetPivotTablePermission],rangeTypes:[i.RangeProtectionPermissionViewPoint]})),tooltip:`sheets-pivot-ui.title`,title:`sheets-pivot-ui.title`}}function Ne(e){return{id:Ce,type:a.MenuItemType.SUBITEMS,title:`sheets-pivot-ui.dateGroup.title`,hidden$:Ve(e)}}function Pe(e){return{id:we,commandId:B.id,type:a.MenuItemType.BUTTON,title:`sheets-pivot-ui.dateGroup.excelLikeTitle`,hidden$:U(e).pipe((0,s.map)(()=>!z(e)))}}function Fe(e){return{id:Te,commandId:de.id,type:a.MenuItemType.BUTTON,title:`sheets-pivot-ui.numberGroup.title`,hidden$:U(e).pipe((0,s.map)(()=>!ue(e)))}}function Ie(e){return{id:Ee,commandId:ae.id,type:a.MenuItemType.BUTTON,title:`sheets-pivot-ui.manualGroup.groupTitle`,hidden$:U(e).pipe((0,s.map)(()=>!ne(e,`group`)))}}function Le(e){return{id:De,commandId:oe.id,type:a.MenuItemType.BUTTON,title:`sheets-pivot-ui.manualGroup.renameTitle`,hidden$:U(e).pipe((0,s.map)(()=>!ne(e,`rename`)))}}function Re(e){return{id:Oe,commandId:se.id,type:a.MenuItemType.BUTTON,title:`sheets-pivot-ui.manualGroup.ungroupTitle`,hidden$:U(e).pipe((0,s.map)(()=>!ne(e,`ungroup`)))}}function ze(e){return t=>({id:Be(e),commandId:I.id,type:a.MenuItemType.BUTTON,title:je[e],params:{dateType:e},disabled$:He(t,e),activated$:Ue(t,e)})}function Be(e){return`sheet.pivot.context-menu.date-group.${e}`}function Ve(e){return U(e).pipe((0,s.map)(()=>!L(e)))}function He(e,t){return U(e).pipe((0,s.map)(()=>{let r=L(e);return!r||(0,n.isPivotDateGroupTypeDisabled)(r.dateGroupContext,t)}))}function Ue(e,t){return U(e).pipe((0,s.map)(()=>{let n=L(e);return(n==null?void 0:n.dateGroupContext.currentDateType)===t}))}function U(e){let t=e.get(n.SheetsPivotTableConfigModel),a=()=>{var t;let a=(0,i.getSheetCommandTarget)(e.get(r.IUniverInstanceService)),o=(t=e.get(i.SheetsSelectionsService).getCurrentLastSelection())==null?void 0:t.primary;if(!a||!o)return;let{unitId:s,subUnitId:c}=a,l=e.get(n.SheetsPivotTableAdaptorModel).getPivotTableIdByCell(s,c,o.startRow,o.startColumn);return l?{unitId:s,subUnitId:c,pivotTableId:l}:void 0};return(0,s.merge)(e.get(i.SheetsSelectionsService).selectionMoveEnd$,t.pivotConfigChange$.pipe((0,s.filter)(e=>{let t=a();return(t==null?void 0:t.unitId)===e.unitId&&t.subUnitId===e.subUnitId&&t.pivotTableId===e.pivotTableId})),t.collectionChange$.pipe((0,s.filter)(e=>{let n=a();if(!n||!e.pivotTableIds.includes(n.pivotTableId))return!1;let r=t.getPivotTableConfig(n.unitId,n.subUnitId,n.pivotTableId);return e.unitId===((r==null?void 0:r.sourceRangeInfo.unitId)??n.unitId)}))).pipe((0,s.startWith)(null))}let We=n.PIVOT_DATE_GROUP_TYPES.map(e=>({dateType:e,id:Be(e),menuItemFactory:ze(e)}));function Ge(e){return{id:ke,type:a.MenuItemType.SUBITEMS,title:`sheets-pivot-ui.showValuesAs.title`,hidden$:Je(e).pipe((0,s.map)(()=>!he(e)))}}function Ke(e){return n=>({id:qe(e.type),commandId:pe.id,type:a.MenuItemType.BUTTON,title:e.localeKey,params:{type:e.type},activated$:Je(n).pipe((0,s.map)(()=>{let r=he(n);return!!(r&&(r.currentShowDataAs.type??t.PivotShowAsTypeEnum.normal)===e.type)}))})}function qe(e){return`sheet.pivot.context-menu.show-data-as.${e}`}function Je(e){return e.get(i.SheetsSelectionsService).selectionMoveEnd$.pipe((0,s.startWith)(null))}let Ye=fe.map(e=>({rule:e,id:qe(e.type),menuItemFactory:Ke(e)}));function Xe(e){return{id:Ae,commandId:Se.id,type:a.MenuItemType.BUTTON,title:`sheets-pivot-ui.valueFilter.title`,hidden$:e.get(i.SheetsSelectionsService).selectionMoveEnd$.pipe((0,s.startWith)(null),(0,s.map)(()=>!xe(e)))}}let Ze=We.reduce((e,t,n)=>(e[t.id]={order:n+1,menuItemFactory:t.menuItemFactory},e),{}),Qe=Ye.reduce((e,t,n)=>(e[t.id]={order:n+1,menuItemFactory:t.menuItemFactory},e),{}),$e={[a.RibbonDataGroup.ANALYSIS]:{[P.id]:{order:0,gridLayout:{row:1,column:1,showLabel:!0},menuItemFactory:Me}},[a.ContextMenuPosition.MAIN_AREA]:{[a.ContextMenuGroup.DATA]:{[P.id]:{order:1,menuItemFactory:Me},[Ce]:{order:2,menuItemFactory:Ne,...Ze},[we]:{order:3,menuItemFactory:Pe},[Te]:{order:4,menuItemFactory:Fe},[Ee]:{order:5,menuItemFactory:Ie},[De]:{order:6,menuItemFactory:Le},[Oe]:{order:7,menuItemFactory:Re},[ke]:{order:8,menuItemFactory:Ge,...Qe},[Ae]:{order:9,menuItemFactory:Xe}}},[a.ContextMenuPosition.COL_HEADER]:{[a.ContextMenuGroup.DATA]:{[P.id]:{order:1,menuItemFactory:Me},[Ce]:{order:2,menuItemFactory:Ne,...Ze},[we]:{order:3,menuItemFactory:Pe},[Te]:{order:4,menuItemFactory:Fe},[Ee]:{order:5,menuItemFactory:Ie},[De]:{order:6,menuItemFactory:Le},[Oe]:{order:7,menuItemFactory:Re}}}};var et=`@univerjs-pro/sheets-pivot-ui`,tt=`1.6.0`;let nt={type:r.CommandType.OPERATION,id:`sheet.operation.open-pivot-table-filter-panel`,async handler(e,t){if(!t)return!1;let{row:r,col:i,unitId:o,subUnitId:s,tableFieldId:c,pivotTableId:l}=t,u=e.get(n.SheetsPivotTableAdaptorModel),d=l||u.getPivotTableIdByCell(o,s,r,i);if(!d)return!1;let f=e.get(n.SheetsPivotRPCService),p=u.getPivotItemRenderInfoCache(o,s,d);if(!(p!=null&&p.rangesInfo))return!1;let m=u.getPivotTableCellData(o,s,r,i),h=(await f.getPivotDisplayConfig({unitId:o,subUnitId:s,pivotTableId:d,params:{type:n.PivotDisplayDataType.Filter,filter:{row:r,col:i,tableFieldId:c,cellData:m,pivotItemRenderInfoCache:p}}})).result.filter;if(!h)return!1;let g=e.get(a.IDialogService),_={id:x,draggable:!0,mask:!1,maskClosable:!1,width:336,dialogStyles:{header:{padding:`16px 16px 0`,height:0},body:{padding:`0 16px 16px`}},closable:!1,children:{label:b,unitId:o,subUnitId:s,key:`${r}-${i}-${c||``}`,filterItemInfo:h},onClose:()=>{g.close(x)}};return g.open(_),!0}},rt={type:r.CommandType.OPERATION,id:`sheet.operation.open-pivot-table-field-setting-panel`,handler(e,t){if(!t)return!1;let n=e.get(r.LocaleService),{tableFieldId:i,pivotTableId:o,unitId:s,subUnitId:c,tableFieldInfo:l,dataFieldInfo:u}=t,d=e.get(a.IDialogService),f={id:C,title:{title:n.t(`sheets-pivot-ui.fieldSettings`)},draggable:!0,mask:!1,maskClosable:!1,width:400,children:{label:S,tableFieldId:i,pivotTableId:o,tableFieldInfo:l,dataFieldInfo:u,unitId:s,subUnitId:c,version:Math.random(),key:`field-setting-${i||``}`,closeFn:()=>{d.close(C)}},onClose:()=>{d.close(C)}};return d.open(f),!0}};function it(e,n,r){let i=r.fieldIds,{fieldsConfig:a}=n,{rowFields:o,columnFields:s,valueFields:c,filterFields:l,hiddenFields:u,dimension:d,measure:f,valueIndex:p,valuePosition:m}=a,h=/* @__PURE__ */ new Set;[...o,...s,...c,...l,...u].forEach(e=>{let t=d[e]||f[e];t&&h.add(t.dataFieldId)});let g=i.map(t=>{let n=r.fields[t];return{checked:h.has(t),dataFieldId:n.id,id:n.id,name:n.name,type:n.fieldDataType,pivotTableId:e}}),_=o.flatMap(e=>{let t=d[e];return t?[{dataFieldId:t.dataFieldId,tableFieldId:t.id,displayName:t.displayName}]:[]}),v=s.flatMap(e=>{let t=d[e];return t?[{dataFieldId:t.dataFieldId,tableFieldId:t.id,displayName:t.displayName}]:[]}),y=c.flatMap(e=>{let t=f[e];return t?[{dataFieldId:t.dataFieldId,tableFieldId:t.id,displayName:t.displayName,format:t.format,subTotalType:t.subtotal}]:[]}),b=l.flatMap(e=>{let t=d[e];return t?[{dataFieldId:t.dataFieldId,tableFieldId:t.id,displayName:t.displayName}]:[]}),x=u.flatMap(e=>{let t=d[e];return t?[{dataFieldId:t.dataFieldId,tableFieldId:t.id,displayName:t.displayName,filterInfo:t.filterInfo}]:[]});return y.length>1&&(m===t.PivotTableValuePositionEnum.Row?_:v).splice(p,0,{dataFieldId:``,tableFieldId:`PivotMultipleValueId`,displayName:`ΣValue`}),{sourceList:g,sourceRange:n.sourceRangeInfo,rowFields:_,columnFields:v,valueFields:y,filterFields:b,hiddenFields:x,positionInfo:n.targetCellInfo}}let at={type:r.CommandType.OPERATION,id:`sheet.operation.open-pivot-table-panel`,async handler(e,t){let o=t==null?void 0:t.pivotTableId;if(!o)return!1;let s=e.get(a.ISidebarService),c=e.get(r.IUniverInstanceService),l=e.get(r.LocaleService),u=e.get(n.SheetsPivotTableConfigModel),d=(0,i.getSheetCommandTarget)(c);if(!d)return!1;let{unitId:f,subUnitId:p}=d,m=u.getPivotTableConfig(f,p,o),h=u.getCollection(f,o);if(!m||!h)return!1;let g=it(o,m,h),_={header:{title:l.t(`sheets-pivot-ui.title`)},id:y,children:{label:v,panelInfo:g,version:Math.random(),setVersion:()=>Math.random(),pivotTableId:o,unitId:f,subUnitId:p},width:346};return s.open(_),!0}},ot=`sheets-pivot-ui.config`,st={};function ct(e){"@babel/helpers - typeof";return ct=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},ct(e)}function lt(e,t){if(ct(e)!=`object`||!e)return e;var n;if(typeof Symbol<`u`&&(n=e[Symbol.toPrimitive])!==void 0){var r=n.call(e,t||`default`);if(ct(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function ut(e){var t=lt(e,`string`);return ct(t)==`symbol`?t:t+``}function W(e,t,n){return(t=ut(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function G(e,t){return function(n,r){t(n,r,e)}}function K(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let q=class extends r.Disposable{constructor(e,t,r,i,a,o,s,c){var l;super(),this._localeService=e,this._sheetInterceptorService=t,this._injector=r,this._confirmService=i,this._sheetsPivotTableService=a,this._configService=o,this._sheetPermissionCheckController=s,this._sheetsRenderService=c,W(this,`_defaultOverride`,!1),this.disposeWithMe(this._sheetsRenderService.registerSelfRenderingMutations(n.InitializePivotRuntimeLocalMutation.id)),this._initUIInterceptListener(),this._defaultOverride=((l=this._configService.getConfig(n.SHEETS_PIVOT_PLUGIN_CONFIG_KEY))==null?void 0:l.defaultOverride)??!1}_getPivotAppliedRanges(e,t,r){return(0,n.getPivotAppliedRanges)(e,t,r,this._localeService.getDirection())}_initUIInterceptListener(){this._sheetsPivotTableService.asyncInterceptor.interceptAsync(this._sheetsPivotTableService.asyncInterceptor.getInterceptPoints().PIVOT_PERFORM_CHECK,{handler:async(e,t)=>{let{cellInfo:r,view:a,isEmpty:o}=t,{unitId:s,subUnitId:c}=r,l=this._getPivotAppliedRanges(r,a,o);if(!(0,i.checkRangesEditablePermission)(this._injector,s,c,l)){let e=this._localeService.t(`sheets-pivot-ui.msg.permissionError`);this._sheetPermissionCheckController.blockExecuteWithoutPermission(e)}let u=this._sheetInterceptorService.generateMutationsByRanges({unitId:s,subUnitId:c,ranges:l}),d=(0,n.generateSetRangeValueMutations)(this._injector,s,c,l);if(u.redos.length||d.shouldClear){if(this._defaultOverride)return Promise.resolve(!0);{let e=await this._confirmService.confirm({id:`sheet-pivot.confirm.add-sheet-pivot`,title:{title:this._localeService.t(`sheets-pivot-ui.perform.tips`)},children:{title:this._localeService.t(`sheets-pivot-ui.perform.info`)},cancelText:this._localeService.t(`sheets-pivot-ui.perform.cancel`),confirmText:this._localeService.t(`sheets-pivot-ui.perform.confirm`)});return Promise.resolve(e)}}return Promise.resolve(!0)}})}};q=K([G(0,(0,r.Inject)(r.LocaleService)),G(1,(0,r.Inject)(i.SheetInterceptorService)),G(2,(0,r.Inject)(r.Injector)),G(3,(0,r.Inject)(r.IConfirmService)),G(4,(0,r.Inject)(n.SheetsPivotTableService)),G(5,(0,r.Inject)(r.IConfigService)),G(6,(0,r.Inject)(i.SheetPermissionCheckController)),G(7,(0,r.Inject)(o.SheetsRenderService))],q);function J({ref:e,...t}){let{preserveStrokeWidth:n,icon:r,id:i,className:a,extend:o,...s}=t,c=`univerjs-icon univerjs-icon-${i} ${a||``}`.trim(),l=`_${(0,d.useId)()}`,u=(0,d.useRef)(null);return(0,d.useImperativeHandle)(e,()=>u.current),(0,d.useLayoutEffect)(()=>{if(n&&u.current&&u.current.localName===r.tag)return mt(u.current)},[n,r]),dt(r,`${i}`,{defIds:r.defIds,idSuffix:l},{ref:u,className:c,...s},o)}function dt(e,t,n,r,i){return(0,d.createElement)(e.tag,{key:t,...ft(e,n,i),...r},(pt(e,n).children||[]).map((r,a)=>dt(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function ft(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),n!=null&&n.colorChannel1&&r.stroke===`colorChannel1`&&(r.stroke=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0||(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))})),r}function pt(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function mt(e){let t=e.viewBox.baseVal,n=Math.max(t.width,t.height);if(!Number.isFinite(n)||n<=0||t.width<=0||t.height<=0)return()=>void 0;let r=16/n,i=Array.from(e.querySelectorAll(`circle, ellipse, line, path, polygon, polyline, rect, text, textPath, tspan, use`)).flatMap(e=>{let t=getComputedStyle(e),n=Number.parseFloat(t.strokeWidth);return t.stroke===`none`||Number.parseFloat(t.strokeOpacity)===0||t.vectorEffect===`non-scaling-stroke`||!Number.isFinite(n)||n<=0?[]:[{element:e,hadStyleAttribute:e.hasAttribute(`style`),originalStrokeWidth:n,strokeWidth:ht(e.style,`stroke-width`)}]}).map(e=>({appliedStrokeWidth:null,element:e.element,hadStyleAttribute:e.hadStyleAttribute,isReleased:!1,originalStrokeWidth:e.originalStrokeWidth,strokeWidth:e.strokeWidth}));if(i.length===0)return()=>void 0;let a=(e,n)=>{if(t.width<=0||t.height<=0||e<=0||n<=0)return;let a=Math.min(e/t.width,n/t.height);!Number.isFinite(a)||a<=0||i.forEach(e=>{if(e.isReleased)return;if(e.appliedStrokeWidth!==null&&(e.element.style.getPropertyValue(`stroke-width`)!==e.appliedStrokeWidth||e.element.style.getPropertyPriority(`stroke-width`)!==e.strokeWidth.priority)){e.appliedStrokeWidth=null,e.isReleased=!0;return}let t=e.originalStrokeWidth*r/a,n=`${Number(t.toFixed(12))}px`;e.element.style.setProperty(`stroke-width`,n,e.strokeWidth.priority),e.appliedStrokeWidth=e.element.style.getPropertyValue(`stroke-width`)})},o=e.getBoundingClientRect();a(o.width,o.height);let s=typeof ResizeObserver>`u`?null:new ResizeObserver(t=>{if(t.some(t=>t.target===e)){let t=e.getBoundingClientRect();a(t.width,t.height)}});return s==null||s.observe(e),()=>{s==null||s.disconnect(),i.forEach(e=>{e.appliedStrokeWidth!==null&&(gt(e.element.style,`stroke-width`,e.appliedStrokeWidth,e.strokeWidth.priority,e.strokeWidth),!e.hadStyleAttribute&&e.element.style.length===0&&e.element.removeAttribute(`style`))})}}function ht(e,t){return{priority:e.getPropertyPriority(t),value:e.getPropertyValue(t)}}function gt(e,t,n,r,i){e.getPropertyValue(t)===n&&e.getPropertyPriority(t)===r&&(i.value?e.setProperty(t,i.value,i.priority):e.removeProperty(t))}J.displayName=`UniverIcon`;let _t={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M13.5 8H2.5M7.5 3L2.5 8L7.5 13`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}}]},vt=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`arrow-left-icon`,ref:t,icon:_t}))});vt.displayName=`ArrowLeftIcon`;let yt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M12.4208 14.4667C12.4208 14.798 12.1522 15.0667 11.8208 15.0667C11.4895 15.0667 11.2208 14.798 11.2208 14.4667V2.98193L9.97861 4.22417C9.7443 4.45848 9.3644 4.45848 9.13008 4.22417C8.89577 3.98985 8.89577 3.60995 9.13008 3.37564L11.3967 1.10897C11.6311 0.874657 12.011 0.874657 12.2453 1.10897L14.5119 3.37564C14.7463 3.60995 14.7463 3.98985 14.5119 4.22417C14.2776 4.45848 13.8977 4.45848 13.6634 4.22417L12.4208 2.9816V14.4667Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.98967 10.2798C1.6583 10.2798 1.38967 10.0112 1.38967 9.67983C1.38967 9.34846 1.6583 9.07983 1.98967 9.07983H6.50138C6.74406 9.07983 6.96284 9.22602 7.05571 9.45022C7.14858 9.67443 7.09725 9.9325 6.92565 10.1041L3.43819 13.5916H6.50138C6.83276 13.5916 7.10138 13.8602 7.10138 14.1916C7.10138 14.5229 6.83276 14.7916 6.50138 14.7916H1.98967C1.74699 14.7916 1.52821 14.6454 1.43534 14.4212C1.34247 14.197 1.3938 13.9389 1.5654 13.7673L5.05286 10.2798H1.98967Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M5.1846 1.86439C4.8641 0.989866 3.62725 0.989866 3.30674 1.86439L1.34882 7.20672C1.23479 7.51786 1.39458 7.86252 1.70571 7.97655C2.01684 8.09058 2.3615 7.93079 2.47553 7.61966L3.06159 6.02055L3.06338 6.02056H5.42975L6.01581 7.61966C6.12984 7.93079 6.4745 8.09058 6.78563 7.97655C7.09677 7.86252 7.25655 7.51786 7.14252 7.20672L5.1846 1.86439ZM4.98996 4.82056L4.24567 2.78971L3.50138 4.82056H4.98996Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},bt=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`ascending-icon`,ref:t,icon:yt}))});bt.displayName=`AscendingIcon`;let xt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`g`,attrs:{stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2},children:[{tag:`rect`,attrs:{width:12.4,height:11,x:1.8,y:3.2,rx:1.2}},{tag:`path`,attrs:{d:`M5 1.5V4.5M11 1.5V4.5M1.8 6.2H14.2M4.2 9.2H6.2M9.8 9.2H11.8M4.2 11.8H6.2M9.8 11.8H11.8`}}]}]},St=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`calendar-icon`,ref:t,icon:xt}))});St.displayName=`CalendarIcon`;let Ct={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M2.27 8L6.09 11.82L13.73 4.18`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}}]},wt=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`check-mark-icon`,ref:t,icon:Ct}))});wt.displayName=`CheckMarkIcon`;let Tt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 17`,width:`1em`,height:`1em`},children:[{tag:`rect`,attrs:{width:12.52,height:4,x:2.63,y:2.89,stroke:`currentColor`,rx:1.1,strokeWidth:1.2}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M6.80825 2.89202V6.89199M10.9821 2.89202V6.89199`,strokeWidth:1.2}},{tag:`rect`,attrs:{width:4,height:4,x:2.63,y:9.8,stroke:`currentColor`,rx:1.1,strokeWidth:1.2}}]},Et=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`column-icon`,ref:t,icon:Tt}))});Et.displayName=`ColumnIcon`;let Dt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M12.4208 1.53335C12.4208 1.20198 12.1522 0.93335 11.8208 0.93335C11.4895 0.93335 11.2208 1.20198 11.2208 1.53335V13.0181L9.97861 11.7758C9.7443 11.5415 9.3644 11.5415 9.13008 11.7758C8.89577 12.0101 8.89577 12.39 9.13008 12.6244L11.3967 14.891C11.6311 15.1253 12.011 15.1253 12.2453 14.891L14.5119 12.6244C14.7463 12.39 14.7463 12.0101 14.5119 11.7758C14.2776 11.5415 13.8977 11.5415 13.6634 11.7758L12.4208 13.0184V1.53335Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.98967 10.2798C1.6583 10.2798 1.38967 10.0112 1.38967 9.67983C1.38967 9.34846 1.6583 9.07983 1.98967 9.07983H6.50138C6.74406 9.07983 6.96284 9.22602 7.05571 9.45022C7.14858 9.67443 7.09725 9.9325 6.92565 10.1041L3.43819 13.5916H6.50138C6.83276 13.5916 7.10138 13.8602 7.10138 14.1916C7.10138 14.5229 6.83276 14.7916 6.50138 14.7916H1.98967C1.74699 14.7916 1.52821 14.6454 1.43534 14.4212C1.34247 14.197 1.3938 13.9389 1.5654 13.7673L5.05286 10.2798H1.98967Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M5.1846 1.86439C4.8641 0.989866 3.62725 0.989866 3.30674 1.86439L1.34882 7.20672C1.23479 7.51786 1.39458 7.86252 1.70571 7.97655C2.01684 8.09058 2.3615 7.93079 2.47553 7.61966L3.06159 6.02055L3.06338 6.02056H5.42975L6.01581 7.61966C6.12984 7.93079 6.4745 8.09058 6.78563 7.97655C7.09677 7.86252 7.25655 7.51786 7.14252 7.20672L5.1846 1.86439ZM4.98996 4.82056L4.24567 2.78971L3.50138 4.82056H4.98996Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},Ot=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`descending-icon`,ref:t,icon:Dt}))});Ot.displayName=`DescendingIcon`;let kt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M3.32182 2.60967C2.98161 2.60967 2.79671 3.0074 3.01601 3.2675L6.85819 7.8246C6.94943 7.93282 6.99947 8.06981 6.99947 8.21136V12.7338C6.99947 12.898 7.0998 13.0455 7.2525 13.1058L8.73833 13.6928C9.00085 13.7965 9.28531 13.6031 9.28531 13.3208V8.21136C9.28531 8.06981 9.33535 7.93282 9.42659 7.8246L13.2688 3.2675C13.4881 3.0074 13.3032 2.60967 12.963 2.60967H3.32182ZM2.09858 4.04101C1.22139 3.0006 1.96097 1.40967 3.32182 1.40967H12.963C14.3238 1.40967 15.0634 3.0006 14.1862 4.04101L10.4853 8.43054V13.3208C10.4853 14.4498 9.34747 15.2237 8.29742 14.8089L6.81158 14.2219C6.20078 13.9806 5.79947 13.3905 5.79947 12.7338V8.43054L2.09858 4.04101Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},At=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`filter-icon`,ref:t,icon:kt}))});At.displayName=`FilterIcon`;let jt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M12.8325 3.00753L12.2725 2.44328C11.9909 2.15966 11.6076 1.9999 11.2079 1.9999H4.08689C3.55342 1.9999 3.28522 2.64412 3.66105 3.02295L7.78136 7.17471C8.25623 7.65323 8.25623 8.43812 7.78136 8.91664L3.66105 13.0684C3.28522 13.4473 3.55342 14.0915 4.08689 14.0915H11.2079C11.6076 14.0915 11.9909 13.9317 12.2725 13.648L12.8325 13.0838`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}}]},Mt=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`function-icon`,ref:t,icon:jt}))});Mt.displayName=`FunctionIcon`;let Nt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 20 20`,width:`1em`,height:`1em`},children:[{tag:`circle`,attrs:{cx:7,cy:5,r:1.1,fill:`currentColor`}},{tag:`circle`,attrs:{cx:13,cy:5,r:1.1,fill:`currentColor`}},{tag:`circle`,attrs:{cx:7,cy:10,r:1.1,fill:`currentColor`}},{tag:`circle`,attrs:{cx:13,cy:10,r:1.1,fill:`currentColor`}},{tag:`circle`,attrs:{cx:7,cy:15,r:1.1,fill:`currentColor`}},{tag:`circle`,attrs:{cx:13,cy:15,r:1.1,fill:`currentColor`}}]},Pt=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`grip-vertical-icon`,ref:t,icon:Nt}))});Pt.displayName=`GripVerticalIcon`;let Ft={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M5 6.5L8 9.5L11 6.5`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2}}]},It=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`more-down-icon`,ref:t,icon:Ft}))});It.displayName=`MoreDownIcon`;let Lt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M3 9C3.55228 9 4 8.55228 4 8C4 7.44772 3.55228 7 3 7C2.44772 7 2 7.44772 2 8C2 8.55228 2.44772 9 3 9Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8 9C8.55228 9 9 8.55228 9 8C9 7.44772 8.55228 7 8 7C7.44772 7 7 7.44772 7 8C7 8.55228 7.44772 9 8 9Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M13 9C13.5523 9 14 8.55228 14 8C14 7.44772 13.5523 7 13 7C12.4477 7 12 7.44772 12 8C12 8.55228 12.4477 9 13 9Z`}}]},Rt=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`more-horizontal-icon`,ref:t,icon:Lt}))});Rt.displayName=`MoreHorizontalIcon`;let zt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M5.9334 2.00527C5.9334 1.6739 5.66477 1.40527 5.3334 1.40527C5.00203 1.40527 4.7334 1.6739 4.7334 2.00527V4.73877H1.9999C1.66853 4.73877 1.3999 5.0074 1.3999 5.33877C1.3999 5.67014 1.66853 5.93877 1.9999 5.93877H4.7334V10.072H1.9999C1.66853 10.072 1.3999 10.3407 1.3999 10.672C1.3999 11.0034 1.66853 11.272 1.9999 11.272H4.7334V14.0053C4.7334 14.3366 5.00203 14.6053 5.3334 14.6053C5.66477 14.6053 5.9334 14.3366 5.9334 14.0053V11.272H10.0667V14.0053C10.0667 14.3366 10.3353 14.6053 10.6667 14.6053C10.998 14.6053 11.2667 14.3366 11.2667 14.0053V11.272H13.9999C14.3313 11.272 14.5999 11.0034 14.5999 10.672C14.5999 10.3407 14.3313 10.072 13.9999 10.072H11.2667V5.93877H13.9999C14.3313 5.93877 14.5999 5.67014 14.5999 5.33877C14.5999 5.0074 14.3313 4.73877 13.9999 4.73877H11.2667V2.00527C11.2667 1.6739 10.998 1.40527 10.6667 1.40527C10.3353 1.40527 10.0667 1.6739 10.0667 2.00527V4.73877H5.9334V2.00527ZM10.0667 10.072V5.93877H5.9334V10.072H10.0667Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},Bt=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`number-icon`,ref:t,icon:zt}))});Bt.displayName=`NumberIcon`;let Vt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M1.4082 3.74922C1.4082 4.63288 2.12455 5.34922 3.0082 5.34922H4.2082C5.09186 5.34922 5.8082 4.63287 5.8082 3.74922V2.54922C5.8082 1.66556 5.09186 0.949219 4.2082 0.949219H3.0082C2.12455 0.949219 1.4082 1.66556 1.4082 2.54922V3.74922ZM3.0082 4.14922C2.78729 4.14922 2.6082 3.97013 2.6082 3.74922V2.54922C2.6082 2.32831 2.78729 2.14922 3.0082 2.14922H4.2082C4.42912 2.14922 4.6082 2.32831 4.6082 2.54922V3.74922C4.6082 3.97013 4.42912 4.14922 4.2082 4.14922L3.0082 4.14922Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.60757 5.24912C7.72391 5.24912 7.00757 4.53278 7.00757 3.64912V2.64912C7.00757 1.76547 7.72391 1.04912 8.60757 1.04912L14.0076 1.04912C14.8912 1.04912 15.6076 1.76546 15.6076 2.64912V3.64912C15.6076 4.53278 14.8912 5.24912 14.0076 5.24912L8.60757 5.24912ZM8.20757 3.64912C8.20757 3.87003 8.38665 4.04912 8.60757 4.04912L14.0076 4.04912C14.2285 4.04912 14.4076 3.87003 14.4076 3.64912V2.64912C14.4076 2.42821 14.2285 2.24912 14.0076 2.24912L8.60757 2.24912C8.38665 2.24912 8.20757 2.42821 8.20757 2.64912V3.64912Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.5083 8.05078C1.5083 7.16713 2.22464 6.45078 3.1083 6.45078H4.1083C4.99196 6.45078 5.7083 7.16713 5.7083 8.05078V13.4508C5.7083 14.3344 4.99196 15.0508 4.1083 15.0508H3.1083C2.22464 15.0508 1.5083 14.3344 1.5083 13.4508V8.05078ZM3.1083 7.65078C2.88739 7.65078 2.7083 7.82987 2.7083 8.05078V13.4508C2.7083 13.6717 2.88739 13.8508 3.1083 13.8508H4.1083C4.32921 13.8508 4.5083 13.6717 4.5083 13.4508V8.05078C4.5083 7.82987 4.32921 7.65078 4.1083 7.65078H3.1083Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.01375 13.0622L9.82677 14.8752C10.0611 15.1095 10.441 15.1095 10.6753 14.8752C10.9096 14.6409 10.9096 14.261 10.6753 14.0267L9.60391 12.9553L12.5981 12.9537C14.0335 12.953 15.1968 11.7891 15.1968 10.3537V7.70108C15.1968 7.3697 14.9281 7.10108 14.5968 7.10108C14.2654 7.10108 13.9968 7.3697 13.9968 7.70108V10.3537C13.9968 11.1266 13.3704 11.7533 12.5975 11.7537L9.60349 11.7553L10.6753 10.6835C10.9096 10.4492 10.9096 10.0693 10.6753 9.83495C10.441 9.60063 10.0611 9.60063 9.82677 9.83495L8.01375 11.648C7.62322 12.0385 7.62322 12.6717 8.01375 13.0622Z`}}]},Ht=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`pivot-table-icon`,ref:t,icon:Vt}))});Ht.displayName=`PivotTableIcon`;let Ut={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 17`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M8.04163 6.24451L8.0418 6.25869L8.04163 6.27285L8.04173 10.4233L8.0418 10.4325L8.04173 10.4417L8.0418 13.5069C8.04182 14.4458 7.2807 15.2069 6.3418 15.2069H4.54183C3.60294 15.2069 2.84182 14.4458 2.84183 13.5069L2.84184 10.4397L2.8418 10.4325L2.84184 10.4253L2.84186 6.26726L2.8418 6.25869L2.84186 6.25011L2.84187 3.18486C2.84187 2.24596 3.60301 1.48484 4.54191 1.48486L6.3416 1.48491C7.28046 1.48493 8.04154 2.24602 8.04156 3.18487L8.04163 6.24451ZM6.8418 13.5069L6.84174 11.0325H4.04184L4.04183 13.5069C4.04183 13.783 4.26568 14.0069 4.54183 14.0069H6.3418C6.61794 14.0069 6.8418 13.783 6.8418 13.5069ZM6.84171 9.83252H4.04184L4.04185 6.85869H6.84165L6.84171 9.83252ZM6.84162 5.65869H4.04186L4.04187 3.18486C4.04187 2.90871 4.26574 2.68486 4.54188 2.68486L6.34158 2.68491C6.61771 2.68491 6.84156 2.90876 6.84156 3.1849L6.84162 5.65869Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M9.74932 4.98481L9.74934 3.18484C9.74936 2.24595 10.5105 1.48484 11.4494 1.48486L13.2493 1.48491C14.1882 1.48494 14.9493 2.24604 14.9493 3.18491V4.98483C14.9493 5.92372 14.1882 6.68483 13.2493 6.68483H11.4493C10.5104 6.68483 9.7493 5.9237 9.74932 4.98481ZM10.9493 3.18486L10.9493 4.98483C10.9493 5.26097 11.1732 5.48483 11.4493 5.48483H13.2493C13.5254 5.48483 13.7493 5.26098 13.7493 4.98483V3.18491C13.7493 2.90877 13.5254 2.68492 13.2493 2.68491L11.4494 2.68486C11.1732 2.68486 10.9493 2.90871 10.9493 3.18486Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},Wt=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`row-icon`,ref:t,icon:Ut}))});Wt.displayName=`RowIcon`;let Gt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`g`,attrs:{stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.2},children:[{tag:`circle`,attrs:{cx:7,cy:7,r:5.2}},{tag:`path`,attrs:{d:`M10.8 10.8L14.2 14.2`}}]}]},Kt=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`search-icon`,ref:t,icon:Gt}))});Kt.displayName=`SearchIcon`;let qt={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M2.22891 2.67227H11.5622M6.89541 2.67227V14.0056M10.2289 7.00552H15.5622M12.8954 7.00552V14.0055`,strokeLinecap:`round`,strokeWidth:1.2}}]},Jt=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(J,Object.assign({},e,{id:`text-icon`,ref:t,icon:qt}))});Jt.displayName=`TextIcon`;function Yt(e){let{editable:t,pivotTableId:i,subUnitId:o,unitId:s}=e,l=(0,a.useDependency)(r.ICommandService),u=(0,a.useDependency)(a.IDialogService),d=(0,a.useDependency)(r.LocaleService),p=[{command:{id:at.id,params:{pivotTableId:i}},disabled:!t,label:`sheets-pivot-ui.mobile.edit`},{command:{id:n.RemovePivotTableCommand.id,params:{unitId:s,subUnitId:o,pivotTableId:i}},disabled:!t,label:`sheets-pivot-ui.mobile.delete`}];async function m(e){await l.executeCommand(e.id,e.params),u.close(N)}return/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-flex-col univer-gap-2`,children:p.map(e=>{let t=d.t(e.label);return/* @__PURE__ */ (0,f.jsx)(c.MobileActionRow,{title:t,"aria-label":t,variant:`subtle`,disabled:e.disabled,onClick:()=>m(e.command)},e.command.id)})})}let Xt=[{label:`1930-08-05`,suffix:`yyyy-MM-dd`},{label:`1930/08/05`,suffix:`yyyy/MM/dd`},{label:`1930年08月05日`,suffix:`yyyy"年"MM"月"dd"日"`},{label:`08-05`,suffix:`MM-dd`},{label:`8月5日`,suffix:`M"月"d"日"`},{label:`13:30:30`,suffix:`h:mm:ss`},{label:`13:30`,suffix:`h:mm`},{label:`下午01:30`,suffix:`A/P hh:mm`},{label:`下午1:30`,suffix:`A/P h:mm`},{label:`下午1:30:30`,suffix:`A/P h:mm:ss`},{label:`08-05 下午 01:30`,suffix:`MM-dd A/P hh:mm`}],Zt=[{label:`(1,235)`,suffix:`#,##0_);(#,##0)`},{label:`(1,235) `,suffix:`#,##0_);[Red](#,##0)`,color:`red`},{label:`1,234.56`,suffix:`#,##0.00_);#,##0.00`},{label:`1,234.56`,suffix:`#,##0.00_);[Red]#,##0.00`,color:`red`},{label:`-1,234.56`,suffix:`#,##0.00_);-#,##0.00`},{label:`-1,234.56`,suffix:`#,##0.00_);[Red]-#,##0.00`,color:`red`}],Qt=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:`red`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:`red`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:`red`}],$t=`PivotMultipleValueId`;function en(e,n){if(n===t.PivotDataFieldDataTypeEnum.blank)return`sheets-pivot-ui.dialog.filter.blank`;if(n===t.PivotDataFieldDataTypeEnum.other&&e===t.GlobalConfig.otherDataKey)return`sheets-pivot-ui.showValuesAs.other`}function tn(e,t){let r=(0,n.isolateTextForBidiContext)(t,e);return e.includes(`{0}`)?e.replace(`{0}`,r):`${e}${r}`}let nn=e=>{switch(e){case`filter`:return t.PivotTableFiledAreaEnum.Filter;case`row`:return t.PivotTableFiledAreaEnum.Row;case`column`:return t.PivotTableFiledAreaEnum.Column;case`value`:return t.PivotTableFiledAreaEnum.Value;default:return t.PivotTableFiledAreaEnum.Row}};function rn(e,t){switch(t.rangeType||r.RANGE_TYPE.NORMAL){case r.RANGE_TYPE.NORMAL:return{startRow:t.startRow,startColumn:t.startColumn,endRow:t.endRow,endColumn:t.endColumn};case r.RANGE_TYPE.ROW:return{startRow:t.startRow,startColumn:0,endRow:t.endRow,endColumn:e.getColumnCount()-1};case r.RANGE_TYPE.COLUMN:return{startRow:0,startColumn:t.startColumn,endRow:e.getRowCount()-1,endColumn:t.endColumn};case r.RANGE_TYPE.ALL:return{startRow:0,startColumn:0,endRow:e.getRowCount()-1,endColumn:e.getColumnCount()-1}}}function an(e,t){if(!t||!e||t.endRow-t.startRow<=0)return 1;let{startRow:n,startColumn:r,endRow:i,endColumn:a}=rn(e,t),o=e.getCellMatrix(),s=!1;for(let e=n;e<=i;e++){for(let t=r;t<=a;t++)if(o.getValue(e,t)!=null){s=!0;break}if(s)break}return s?2:0}async function on(e,t,r){let{commandService:i,pivotTableInfo:a,pivotTableId:o,unitId:s,subUnitId:c}=e,l=[],{rowFields:u,columnFields:d,filterFields:f,valueFields:p}=a,m=[...u,...d,...f,...p];t===`PivotMultipleValueId`&&p.forEach(e=>{l.push(e.tableFieldId)}),r===`source`&&m.forEach(e=>{e.dataFieldId===t&&l.push(e.tableFieldId)}),r!==`source`&&m.find(e=>e.tableFieldId===t)&&l.push(t),await i.executeCommand(n.RemovePivotFieldCommand.id,{pivotTableId:o,fieldIds:l,unitId:s,subUnitId:c})}async function sn(e,t,r,i,a){let o={unitId:i,subUnitId:a,token:t,dataRangeInfo:r};await e.executeCommand(n.UpdatePivotTableSourceRangeCommand.id,o)}let cn=(e,t)=>{let{rowFields:n,columnFields:r,filterFields:i}=e,a=[...n,...r,...i],o=[];return a.forEach(e=>{e.dataFieldId===t&&o.push(e.tableFieldId)}),o};async function ln(e,t,r,i,a){if(r===`source`&&i===`source`)return;let o=t===$t,{commandService:s,pivotTableInfo:c,pivotTableId:l,unitId:u,subUnitId:d}=e;if(r===`source`&&i!==`source`){let{sourceList:e}=c,r=e.find(e=>e.id===t);if(r){let e=cn(c,t);if(i!==`value`&&e.length>0){let t=e[0];await s.executeCommand(n.MovePivotFieldCommand.id,{pivotTableId:l,fieldId:t,area:nn(i),index:a,unitId:u,subUnitId:d})}else await s.executeCommand(n.AddPivotFieldCommand.id,{pivotTableId:l,dataFieldId:r.dataFieldId,fieldArea:nn(i),index:a,unitId:u,subUnitId:d})}}if(r!==`source`&&i===`source`){let{rowFields:n,columnFields:r,filterFields:i,valueFields:a}=c,s=[...n,...r,...i,...a],l=[];o?a.forEach(e=>{l.push(e.tableFieldId)}):s.find(e=>e.tableFieldId===t)&&l.push(t),await un(e,l)}else r!==`source`&&i!==`source`&&await fn(e,t,r,i,a)}async function un(e,t){let{commandService:r,pivotTableId:i,unitId:a,subUnitId:o}=e;await r.executeCommand(n.RemovePivotFieldCommand.id,{pivotTableId:i,fieldIds:t,unitId:a,subUnitId:o})}async function dn(e,t,r){let{commandService:i,pivotTableId:a,unitId:o,subUnitId:s}=e;await i.executeCommand(n.UpdatePivotValuePositionCommand.id,{pivotTableId:a,position:t,index:r,unitId:o,subUnitId:s})}async function fn(e,r,i,a,o){let s=r===$t,{commandService:c,pivotTableInfo:l,pivotTableId:u,unitId:d,subUnitId:f}=e;if(s){let e=nn(a);(e===t.PivotTableFiledAreaEnum.Row||e===t.PivotTableFiledAreaEnum.Column)&&await c.executeCommand(n.UpdatePivotValuePositionCommand.id,{pivotTableId:u,position:e===t.PivotTableFiledAreaEnum.Row?t.PivotTableValuePositionEnum.Row:t.PivotTableValuePositionEnum.Column,index:o,unitId:d,subUnitId:f});return}let{rowFields:p,columnFields:m,filterFields:h,valueFields:g}=l,_=[...p,...m,...h,...g].find(e=>e.tableFieldId===r);if(_){let t=[...p,...m,...h];if(i===`value`&&a!==`value`&&t.find(e=>e.dataFieldId===_.dataFieldId)){await un(e,[r]);return}await c.executeCommand(n.MovePivotFieldCommand.id,{pivotTableId:u,fieldId:r,area:nn(a),index:o,unitId:d,subUnitId:f})}}function pn(e,t,n,r,i){e.executeCommand(nt.id,{row:-1,col:-1,unitId:t,subUnitId:n,tableFieldId:i,pivotTableId:r})}function mn(e,t,n,r,i,a){let{sourceList:o,rowFields:s,columnFields:c,valueFields:l,filterFields:u}=a,d=[...s,...c,...l,...u].find(e=>e.tableFieldId===n),f=o.find(e=>e.id===(d==null?void 0:d.dataFieldId));if(d&&f){let a={tableFieldId:n,pivotTableId:t,unitId:r,subUnitId:i,tableFieldInfo:d,dataFieldInfo:f};e.executeCommand(rt.id,a)}}let hn=[{type:t.PivotSubtotalTypeEnum.average,textKey:`sheets-pivot-ui.subtotal.average`},{type:t.PivotSubtotalTypeEnum.count,textKey:`sheets-pivot-ui.subtotal.count`},{type:t.PivotSubtotalTypeEnum.countNums,textKey:`sheets-pivot-ui.subtotal.countNums`},{type:t.PivotSubtotalTypeEnum.max,textKey:`sheets-pivot-ui.subtotal.max`},{type:t.PivotSubtotalTypeEnum.min,textKey:`sheets-pivot-ui.subtotal.min`},{type:t.PivotSubtotalTypeEnum.product,textKey:`sheets-pivot-ui.subtotal.product`},{type:t.PivotSubtotalTypeEnum.stdDev,textKey:`sheets-pivot-ui.subtotal.stdDev`},{type:t.PivotSubtotalTypeEnum.stdDevp,textKey:`sheets-pivot-ui.subtotal.stdDevp`},{type:t.PivotSubtotalTypeEnum.sum,textKey:`sheets-pivot-ui.subtotal.sum`},{type:t.PivotSubtotalTypeEnum.var,textKey:`sheets-pivot-ui.subtotal.var`},{type:t.PivotSubtotalTypeEnum.varp,textKey:`sheets-pivot-ui.subtotal.varp`}],gn=(e,t=0)=>e?r.numfmt.getFormatInfo(e).maxDecimals??t:t,_n=e=>Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(``),Y=(e,t)=>e.split(`;`).map(e=>/\.0?/.test(e)?e.replace(/\.0*/g,`${t>0?`.`:``}${_n(Number(t||0))}`):/0[^0]?/.test(e)?e.replace(/0[^0]+|0$/,`0${t>0?`.`:``}${_n(Number(t||0))}`):e).join(`;`),vn=e=>r.currencySymbols.find(t=>e.includes(t)),yn=e=>!e,bn=e=>!!vn(e)&&e.startsWith(`_(`),xn=e=>!!vn(e)&&!e.startsWith(`_(`),Sn=()=>Xt.map(e=>({label:e.label,value:e.suffix})),Cn=e=>{let t=r.numfmt.getFormatInfo(e);return Sn().map(e=>e.value).includes(e)||[`date`,`datetime`,`time`].includes(t.type)},wn=()=>Zt.map(e=>({label:e.label,value:e.suffix,color:e.color})),Tn=e=>wn().some(t=>(0,r.isPatternEqualWithoutDecimal)(t.value,e)),En=(e,n)=>{switch(n){case t.PivotTableFiledAreaEnum.Row:return e.rowFields.length;case t.PivotTableFiledAreaEnum.Column:return e.columnFields.length;case t.PivotTableFiledAreaEnum.Filter:return e.filterFields.length;case t.PivotTableFiledAreaEnum.Value:return e.valueFields.length;default:return 0}},Dn=(e,t,r)=>{for(let i of[`sheets-pivot-ui.averageName`,`sheets-pivot-ui.countName`,`sheets-pivot-ui.countNumsName`,`sheets-pivot-ui.maxName`,`sheets-pivot-ui.minName`,`sheets-pivot-ui.productName`,`sheets-pivot-ui.stdDevName`,`sheets-pivot-ui.stdDevpName`,`sheets-pivot-ui.sumName`,`sheets-pivot-ui.varName`,`sheets-pivot-ui.varpName`]){let a=r[i];if(a+(0,n.isolateTextForBidiContext)(e,a)===t||a+e===t)return!0}return!1},On=(e,r,i)=>{let a=``;switch(i){case t.PivotSubtotalTypeEnum.average:a=r[`sheets-pivot-ui.averageName`];break;case t.PivotSubtotalTypeEnum.count:a=r[`sheets-pivot-ui.countName`];break;case t.PivotSubtotalTypeEnum.countNums:a=r[`sheets-pivot-ui.countNumsName`];break;case t.PivotSubtotalTypeEnum.max:a=r[`sheets-pivot-ui.maxName`];break;case t.PivotSubtotalTypeEnum.min:a=r[`sheets-pivot-ui.minName`];break;case t.PivotSubtotalTypeEnum.product:a=r[`sheets-pivot-ui.productName`];break;case t.PivotSubtotalTypeEnum.stdDev:a=r[`sheets-pivot-ui.stdDevName`];break;case t.PivotSubtotalTypeEnum.stdDevp:a=r[`sheets-pivot-ui.stdDevpName`];break;case t.PivotSubtotalTypeEnum.sum:a=r[`sheets-pivot-ui.sumName`];break;case t.PivotSubtotalTypeEnum.var:a=r[`sheets-pivot-ui.varName`];break;case t.PivotSubtotalTypeEnum.varp:a=r[`sheets-pivot-ui.varpName`];break;default:return e}return a+(0,n.isolateTextForBidiContext)(e,a)};function kn(e,n){if(n.conditionFilter&&(0,t.isPivotTableFilterRestrictive)(n.conditionFilter))return`HasFilter`;if(!e)return`NotFilter`;if((0,t.isPivotDateFilter)(e))return`HasFilter`;if((0,t.isManualPivotFilter)(e)){var r;return e.isAll||((r=n.items)==null?void 0:r.length)===e.list.length?`NotFilter`:`HasFilter`}return(0,t.isPivotTableFilterRestrictive)(e)?`HasFilter`:`NotFilter`}function An(e){return bn(e)?`accounting`:xn(e)?`currency`:Cn(e)?`date`:Tn(e)?`thousandthPercentile`:`general`}function jn(e){let{originPattern:t=``,onChange:n}=e,i=(0,a.useDependency)(r.LocaleService),[o,s]=(0,d.useState)(()=>An(t)),[l,u]=(0,d.useState)(()=>gn(t,2)),[p,m]=(0,d.useState)(()=>vn(t)||r.currencySymbols[0]),[h,g]=(0,d.useState)(t),_=(0,d.useMemo)(()=>[{value:`general`,label:i.t(`sheets-pivot-ui.dialog.numfmt.general`)},{value:`accounting`,label:i.t(`sheets-pivot-ui.dialog.numfmt.accounting`)},{value:`currency`,label:i.t(`sheets-pivot-ui.dialog.numfmt.currency`)},{value:`date`,label:i.t(`sheets-pivot-ui.dialog.numfmt.date`)},{value:`thousandthPercentile`,label:i.t(`sheets-pivot-ui.dialog.numfmt.thousandthPercentile`)}],[i]),v=r.currencySymbols.map(e=>({label:e,value:e}));function y(e){g(e),n(e)}function b(e,t){return Y(`_("${e}"* #,##0${t>0?`.0`:``}_)`,t)}function x(e){s(e),y(e===`general`?``:e===`accounting`?b(p,l):e===`currency`?Y(Qt[0].suffix(p),l):e===`date`?Xt[0].suffix:Y(Zt[0].suffix,l))}function S(e){m(e),y(o===`accounting`?b(e,l):Y(Qt[0].suffix(e),l))}function C(e){let t=e??0;u(t),y(o===`accounting`?b(p,t):Y(h,t))}let w=Qt.map(e=>({label:e.label(p),value:e.suffix(p),color:e.color})),T=Zt.map(e=>({label:e.label,value:e.suffix,color:e.color})),E=Xt.map(e=>({label:e.label,value:e.suffix}));return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:i.t(`sheets-pivot-ui.dialog.numfmt.formatTypes`)}),/* @__PURE__ */ (0,f.jsx)(c.MobileSelect,{className:`univer-w-full`,value:o,options:_,onChange:e=>x(e),size:`small`})]}),(o===`accounting`||o===`currency`)&&/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-grid univer-grid-cols-2 univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:i.t(`sheets-pivot-ui.dialog.numfmt.decimalPlaces`)}),/* @__PURE__ */ (0,f.jsx)(c.InputNumber,{className:`univer-w-full`,value:l,min:0,max:20,onChange:C,size:`small`,controls:!1})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:i.t(`sheets-pivot-ui.dialog.numfmt.currencyTypes`)}),/* @__PURE__ */ (0,f.jsx)(c.MobileSelect,{className:`univer-w-full`,value:p,options:v,onChange:S,size:`small`})]})]}),o===`thousandthPercentile`&&/* @__PURE__ */ (0,f.jsxs)(`div`,{children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:i.t(`sheets-pivot-ui.dialog.numfmt.decimalPlaces`)}),/* @__PURE__ */ (0,f.jsx)(c.InputNumber,{className:`univer-w-full`,value:l,min:0,max:20,onChange:C,size:`small`,controls:!1})]}),o===`currency`&&/* @__PURE__ */ (0,f.jsx)(c.SelectList,{className:`univer-rounded-xl univer-p-2`,options:w,value:h,onChange:e=>y(Y(e,l))}),o===`date`&&/* @__PURE__ */ (0,f.jsx)(c.SelectList,{className:`univer-rounded-xl univer-p-2`,options:E,value:h,onChange:e=>y(e)}),o===`thousandthPercentile`&&/* @__PURE__ */ (0,f.jsx)(c.SelectList,{className:`univer-rounded-xl univer-p-2`,options:T,value:h,onChange:e=>y(Y(e,l))}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-text-sm univer-text-gray-500`,children:i.t(`sheets-pivot-ui.dialog.numfmt.${o}Desc`)})]})}function Mn(e){let{unitId:t,subUnitId:i,pivotTableId:o,tableFieldId:s,originPattern:l,tableFieldInfo:u,dataFieldInfo:p}=e,m=(0,a.useDependency)(r.ICommandService),h=(0,a.useDependency)(a.IDialogService),g=(0,a.useDependency)(r.LocaleService),[_,v]=(0,d.useState)(l??``);async function y(){let e={format:_,tableFieldId:s,pivotTableId:o,unitId:t,subUnitId:i,tableFieldInfo:u,dataFieldInfo:p};await m.executeCommand(n.UpdatePivotFieldSettingCommand.id,e),h.close(T)}return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-5`,dir:g.getDirection(),children:[/* @__PURE__ */ (0,f.jsx)(jn,{originPattern:l,onChange:v}),/* @__PURE__ */ (0,f.jsxs)(c.MobileActionRowGroup,{children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{onClick:()=>h.close(T),size:`middle`,children:g.t(`sheets-pivot-ui.dialog.numfmt.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`primary`,onClick:y,size:`middle`,children:g.t(`sheets-pivot-ui.dialog.numfmt.confirm`)})]})]})}function Nn(e){let{unitId:t,subUnitId:i,pivotTableId:o,tableFieldId:s,tableFieldInfo:l,dataFieldInfo:u,closeFn:p,format:m,version:h}=e,g=(0,a.useDependency)(r.ICommandService),_=(0,a.useDependency)(n.SheetsPivotTableConfigModel),v=(0,a.useDependency)(r.LocaleService),[y,b]=(0,d.useState)(`field`),[x,S]=(0,d.useState)(l.displayName),[C,w]=(0,d.useState)(l.subTotalType),[T,E]=(0,d.useState)(m??l.format??``),[D,O]=(0,d.useState)(T);(0,d.useEffect)(()=>{b(`field`),S(l.displayName),w(l.subTotalType),E(m??l.format??``),O(m??l.format??``)},[m,l,h]);let k={..._.getTextInfo()};[`sheets-pivot-ui.averageName`,`sheets-pivot-ui.countName`,`sheets-pivot-ui.countNumsName`,`sheets-pivot-ui.maxName`,`sheets-pivot-ui.minName`,`sheets-pivot-ui.productName`,`sheets-pivot-ui.stdDevName`,`sheets-pivot-ui.stdDevpName`,`sheets-pivot-ui.sumName`,`sheets-pivot-ui.varName`,`sheets-pivot-ui.varpName`].forEach(e=>{k[e]=v.t(e)});function A(e){w(e),Dn(u.name,x,k)&&S(On(u.name,k,e))}async function j(){let e={displayName:l.displayName===x?void 0:x,subtotalType:l.subTotalType===C?void 0:C,format:l.format===T?void 0:T,tableFieldId:s,pivotTableId:o,unitId:t,subUnitId:i,tableFieldInfo:l,dataFieldInfo:u};await g.executeCommand(n.UpdatePivotFieldSettingCommand.id,e),p()}return y===`format`?/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-5`,dir:v.getDirection(),children:[/* @__PURE__ */ (0,f.jsxs)(`button`,{type:`button`,className:`univer-flex univer-h-10 univer-items-center univer-gap-2 univer-border-0 univer-bg-transparent univer-p-0 univer-text-base univer-font-semibold`,onClick:()=>b(`field`),children:[/* @__PURE__ */ (0,f.jsx)(vt,{}),v.t(`sheets-pivot-ui.dialog.numfmt.fieldSetting`)]}),/* @__PURE__ */ (0,f.jsx)(jn,{originPattern:T,onChange:O}),/* @__PURE__ */ (0,f.jsxs)(c.MobileActionRowGroup,{children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{onClick:()=>b(`field`),size:`middle`,children:v.t(`sheets-pivot-ui.dialog.numfmt.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`primary`,onClick:()=>{E(D),b(`field`)},size:`middle`,children:v.t(`sheets-pivot-ui.dialog.numfmt.confirm`)})]})]}):/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,dir:v.getDirection(),children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-sm univer-font-medium`,children:v.t(`sheets-pivot-ui.dialog.fieldName`)}),/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-truncate univer-text-xs univer-text-gray-500`,children:tn(v.t(`sheets-pivot-ui.dialog.sourceName`),u.name)})]}),/* @__PURE__ */ (0,f.jsx)(c.Input,{className:`univer-mt-2 univer-w-full`,value:x,onChange:S,size:`small`})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:v.t(`sheets-pivot-ui.dialog.summarizeBy`)}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-max-h-[40vh] univer-overflow-y-auto univer-rounded-xl univer-bg-gray-50 univer-p-1 dark:!univer-bg-gray-800`,children:hn.map(e=>/* @__PURE__ */ (0,f.jsxs)(`button`,{type:`button`,className:(0,c.clsx)(`univer-flex univer-h-12 univer-w-full univer-items-center univer-gap-2 univer-rounded-xl univer-border-0 univer-bg-transparent univer-px-3 univer-text-left univer-text-sm`,{"univer-bg-primary-50 dark:!univer-bg-gray-700":C===e.type}),onClick:()=>A(e.type),children:[/* @__PURE__ */ (0,f.jsx)(wt,{className:(0,c.clsx)(`univer-text-primary-600`,{"univer-invisible":C!==e.type})}),v.t(e.textKey)]},e.type))})]}),/* @__PURE__ */ (0,f.jsx)(c.Button,{className:`univer-w-full`,onClick:()=>{O(T),b(`format`)},size:`middle`,children:v.t(`sheets-pivot-ui.dialog.format`)}),/* @__PURE__ */ (0,f.jsxs)(c.MobileActionRowGroup,{children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{onClick:p,size:`middle`,children:v.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`primary`,disabled:!x,onClick:j,size:`middle`,children:v.t(`sheets-pivot-ui.dialog.ok`)})]})]})}function Pn(e){var i;let{filterItemInfo:o,unitId:s,subUnitId:l}=e,u=(0,a.useDependency)(r.ICommandService),p=(0,a.useDependency)(a.IDialogService),m=(0,a.useDependency)(r.LocaleService),h=(0,a.useDependency)(r.IUniverInstanceService),g=(0,a.useObservable)(m.direction$,m.getDirection()),[_,v]=(0,d.useState)(()=>{var e;return o.checkedItems??((e=o.filterInfo)==null?void 0:e.list)??o.items}),[y,b]=(0,d.useState)(()=>o.partialItems??[]),[S,C]=(0,d.useState)((i=o.sortInfo)==null?void 0:i.type),w=y.length===0&&_.length===o.items.length,T=kn(o.filterInfo,{items:o.items,conditionFilter:o.conditionFilter});(0,d.useEffect)(()=>{let e=h.getCurrentUnitOfType(r.UniverInstanceType.UNIVER_SHEET);if(!e)return;let t=e.activeSheet$.subscribe(e=>{(e==null?void 0:e.getSheetId())!==l&&p.close(x)});return()=>t.unsubscribe()},[p,l,h]);function E(){p.close(x)}function D(e){y.includes(e)?(b(t=>t.filter(t=>t!==e)),v(t=>[...t,e])):v(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])}async function O(e,t,r,i=!1){await u.executeCommand(n.SetPivotFilterCommand.id,{unitId:s,subUnitId:l,pivotTableId:o.pivotTableId,tableFieldId:o.tableFieldId,items:e,partialItems:r,isAll:t,clearAllFilters:i}),E()}async function k(e){await u.executeCommand(n.SetPivotSortCommand.id,{unitId:s,subUnitId:l,pivotTableId:o.pivotTableId,tableFieldId:o.tableFieldId,info:{type:e}}),C(e),E()}return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,dir:g,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-text-base univer-font-semibold`,children:m.t(`sheets-pivot-ui.filterField`)}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-grid univer-grid-cols-2 univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsxs)(c.Button,{className:(0,c.clsx)(``,{"univer-bg-gray-100 dark:!univer-bg-gray-700":S===t.PivotDataFieldSortOperatorEnum.ascending}),onClick:()=>k(t.PivotDataFieldSortOperatorEnum.ascending),size:`middle`,children:[/* @__PURE__ */ (0,f.jsx)(bt,{}),m.t(`sheets-pivot-ui.dialog.filter.ascending`)]}),/* @__PURE__ */ (0,f.jsxs)(c.Button,{className:(0,c.clsx)(``,{"univer-bg-gray-100 dark:!univer-bg-gray-700":S===t.PivotDataFieldSortOperatorEnum.descending}),onClick:()=>k(t.PivotDataFieldSortOperatorEnum.descending),size:`middle`,children:[/* @__PURE__ */ (0,f.jsx)(Ot,{}),m.t(`sheets-pivot-ui.dialog.filter.descending`)]})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-max-h-[40vh] univer-overflow-y-auto univer-rounded-xl univer-bg-gray-50 univer-p-2 dark:!univer-bg-gray-800`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-min-h-12 univer-items-center univer-px-2`,children:/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:w,indeterminate:!w&&(_.length>0||y.length>0),onChange:()=>{b([]),v(w?[]:o.items)},children:m.t(`sheets-pivot-ui.dialog.filter.selectAll`)})}),o.items.map((e,n)=>{var i;let a=o.itemTypes[n],s=(i=o.itemLabels)==null?void 0:i[e],l=en(e,a),u=e;return l?u=m.t(l):s===void 0?a===t.PivotDataFieldDataTypeEnum.date&&o.format&&(u=r.numfmt.format(o.format,Number(e))):u=s,/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-min-h-12 univer-items-center univer-px-2`,children:/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:_.includes(e),indeterminate:y.includes(e),contentClassName:`univer-max-w-[70vw] univer-truncate`,onChange:()=>D(e),children:u})},e)})]}),/* @__PURE__ */ (0,f.jsx)(c.Button,{className:`univer-w-full`,variant:`link`,disabled:T===`NotFilter`,onClick:()=>O(o.items,!0,[],!0),size:`middle`,children:m.t(`sheets-pivot-ui.dialog.filter.clearFilter`)}),/* @__PURE__ */ (0,f.jsxs)(c.MobileActionRowGroup,{children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{onClick:E,size:`middle`,children:m.t(`sheets-pivot-ui.dialog.filter.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`primary`,disabled:!_.length&&!y.length,onClick:()=>O(_,w,y),size:`middle`,children:m.t(`sheets-pivot-ui.dialog.filter.confirm`)})]})]})}let Fn=[{label:`sheets-pivot-ui.config.pageDownThenOver`,value:`false`},{label:`sheets-pivot-ui.config.pageOverThenDown`,value:`true`}],In=[{label:`sheets-pivot-ui.config.layoutTabular`,value:String(t.PivotLayoutTypeEnum.tabular)},{label:`sheets-pivot-ui.config.layoutCompact`,value:String(t.PivotLayoutTypeEnum.compact)},{label:`sheets-pivot-ui.config.layoutOutline`,value:String(t.PivotLayoutTypeEnum.outline)}],Ln=[{label:`sheets-pivot-ui.config.rowSubtotalTop`,value:String(t.PivotSubtotalPositionEnum.top)},{label:`sheets-pivot-ui.config.rowSubtotalBottom`,value:String(t.PivotSubtotalPositionEnum.bottom)}],Rn=[{label:`sheets-pivot-ui.config.dateGroupingLegacy`,value:t.PivotDateGroupingMode.Legacy},{label:`sheets-pivot-ui.config.dateGroupingExcelLike`,value:t.PivotDateGroupingMode.ExcelLike}];function zn(e){let{unitId:i,subUnitId:o,pivotTableId:l}=e,u=(0,a.useDependency)(r.ICommandService),p=(0,a.useDependency)(r.IConfirmService),m=(0,a.useDependency)(r.ILogService),h=(0,a.useDependency)(r.LocaleService),g=(0,a.useDependency)(n.SheetsPivotTableConfigModel),_=(0,d.useMemo)(()=>g.watchPivotTableChanges(i,o,l).pipe((0,s.debounceTime)(0)),[g,i,o,l]);(0,a.useObservable)(_);let[v,y]=(0,d.useState)(!1),b=(0,d.useRef)(!1),x=g.getPivotTableConfig(i,o,l),S=(0,t.getPivotDateGroupingMode)(x==null?void 0:x.fieldsConfig.options),[C,w]=(0,d.useState)(()=>{var e,n;let r=g.getPivotTableConfig(i,o,l),a=(r==null||(e=r.fieldsConfig)==null?void 0:e.options)??{};return{showRowSubtotal:a.showRowSubtotal??!0,showRowGrandTotal:a.showRowGrandTotal??!0,showColSubtotal:a.showColSubtotal??!0,showColGrandTotal:a.showColGrandTotal??!0,pageWrap:a.pageWrap??1,pageOverThenDown:a.pageOverThenDown??!1,repeatRowLabels:a.repeatRowLabels??!1,repeatColLabels:a.repeatColLabels??!1,layout:(r==null||(n=r.fieldsConfig)==null?void 0:n.layout)??t.PivotLayoutTypeEnum.tabular,rowSubtotalPosition:a.rowSubtotalPosition??t.PivotSubtotalPositionEnum.top}});function T(e){let t={unitId:i,subUnitId:o,pivotTableId:l,options:e};return w(t=>({...t,...e})),u.executeCommand(n.SetPivotOptionCommand.id,t).catch(e=>m.error(`[MobilePivotConfigPanel]`,e))}function E(e){let t={unitId:i,subUnitId:o,pivotTableId:l,layout:e};return w(t=>({...t,layout:e})),u.executeCommand(n.SetPivotLayoutCommand.id,t).catch(e=>m.error(`[MobilePivotConfigPanel]`,e))}async function D(e){if(!(b.current||e===S)){b.current=!0,y(!0);try{let r=g.getPivotTableConfig(i,o,l),a=g.getCollection(i,l);if(!r||!a||(Object.values(a.fields).some(t.isDateGroupFieldJSON)||a.customFields.some(t.isDateGroupFieldJSON))&&!await p.confirm({id:`sheet-pivot.confirm.change-date-grouping-mode`,title:{title:h.t(`sheets-pivot-ui.config.dateGroupingSwitchTitle`)},children:{title:h.t(`sheets-pivot-ui.config.dateGroupingSwitchMessage`)},cancelText:h.t(`sheets-pivot-ui.dialog.cancel`),confirmText:h.t(`sheets-pivot-ui.dialog.ok`)})||g.getPivotTableConfig(i,o,l)!==r||g.getCollection(i,l)!==a||(0,t.getPivotDateGroupingMode)(r.fieldsConfig.options)===e)return;await u.executeCommand(n.SetPivotOptionCommand.id,{unitId:i,subUnitId:o,pivotTableId:l,options:{dateGroupingMode:e}})}catch(e){m.error(`[MobilePivotConfigPanel]`,e)}finally{b.current=!1,y(!1)}}}let O=e=>e.map(e=>({...e,label:h.t(e.label)}));return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-5 univer-py-4`,children:[/* @__PURE__ */ (0,f.jsxs)(`section`,{className:`univer-flex univer-flex-col univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-text-sm univer-font-medium univer-text-gray-600`,children:h.t(`sheets-pivot-ui.config.displaySection`)}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-min-h-10 univer-items-center univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-sm`,children:h.t(`sheets-pivot-ui.config.dateGroupingMode`)}),/* @__PURE__ */ (0,f.jsx)(c.MobileSelect,{className:`univer-w-40`,value:S,options:O(Rn),disabled:v,onChange:e=>D(e),size:`small`})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-min-h-10 univer-items-center univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-sm`,children:h.t(`sheets-pivot-ui.config.layout`)}),/* @__PURE__ */ (0,f.jsx)(c.MobileSelect,{className:`univer-w-40`,value:String(C.layout),options:O(In),onChange:e=>E(Number(e)),size:`small`})]}),/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:C.repeatRowLabels,disabled:C.layout===t.PivotLayoutTypeEnum.compact,onChange:e=>T({repeatRowLabels:!!e}),children:h.t(`sheets-pivot-ui.config.repeatRowLabels`)}),/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:C.repeatColLabels,onChange:e=>T({repeatColLabels:!!e}),children:h.t(`sheets-pivot-ui.config.repeatColLabels`)})]}),/* @__PURE__ */ (0,f.jsxs)(`section`,{className:`univer-flex univer-flex-col univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-text-sm univer-font-medium univer-text-gray-600`,children:h.t(`sheets-pivot-ui.config.totalsSection`)}),/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:C.showRowSubtotal,onChange:e=>T({showRowSubtotal:!!e}),children:h.t(`sheets-pivot-ui.config.showRowSubtotal`)}),C.layout===t.PivotLayoutTypeEnum.outline&&/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-min-h-10 univer-items-center univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-sm`,children:h.t(`sheets-pivot-ui.config.rowSubtotalPosition`)}),/* @__PURE__ */ (0,f.jsx)(c.MobileSelect,{className:`univer-w-40`,value:String(C.rowSubtotalPosition),options:O(Ln),onChange:e=>T({rowSubtotalPosition:Number(e)}),size:`small`})]}),/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:C.showRowGrandTotal,onChange:e=>T({showRowGrandTotal:!!e}),children:h.t(`sheets-pivot-ui.config.showRowGrandTotal`)}),/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:C.showColSubtotal,onChange:e=>T({showColSubtotal:!!e}),children:h.t(`sheets-pivot-ui.config.showColSubtotal`)}),/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:C.showColGrandTotal,onChange:e=>T({showColGrandTotal:!!e}),children:h.t(`sheets-pivot-ui.config.showColGrandTotal`)})]}),/* @__PURE__ */ (0,f.jsxs)(`section`,{className:`univer-flex univer-flex-col univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-text-sm univer-font-medium univer-text-gray-600`,children:h.t(`sheets-pivot-ui.config.pageSection`)}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-min-h-10 univer-items-center univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-sm`,children:h.t(`sheets-pivot-ui.config.pageWrap`)}),/* @__PURE__ */ (0,f.jsx)(c.InputNumber,{className:`univer-w-24`,value:C.pageWrap,min:1,max:20,onChange:e=>{let t=Number(e);return Number.isFinite(t)&&t>=1?T({pageWrap:t}):void 0},size:`small`,controls:!1})]}),/* @__PURE__ */ (0,f.jsx)(`p`,{className:`univer-text-xs univer-text-gray-600`,children:h.t(C.pageOverThenDown?`sheets-pivot-ui.config.pageWrapOverThenDownHelp`:`sheets-pivot-ui.config.pageWrapDownThenOverHelp`)}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-min-h-10 univer-items-center univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-sm`,children:h.t(`sheets-pivot-ui.config.pageDirection`)}),/* @__PURE__ */ (0,f.jsx)(c.MobileSelect,{className:`univer-w-40`,value:String(C.pageOverThenDown),options:O(Fn),onChange:e=>T({pageOverThenDown:e===`true`}),size:`small`})]})]})]})}function Bn(e,t,n,r){let i=[];return t>0&&i.push(`moveUp`),t<n-1&&i.push(`moveDown`),r?(i.push(e===`column`?`moveToRow`:`moveToColumn`),i.push(`remove`),i):(e!==`filter`&&i.push(`moveToFilter`),e!==`column`&&i.push(`moveToColumn`),e!==`row`&&i.push(`moveToRow`),e===`value`?i.push(`settings`):(i.push(`moveToValue`),i.push(`filter`)),i.push(`remove`),i)}let Vn=[`filter`,`column`,`row`,`value`];function Hn(e,t){switch(t){case`filter`:return e.filterFields;case`column`:return e.columnFields;case`row`:return e.rowFields;case`value`:return e.valueFields;default:return[]}}function Un(e){switch(e){case`filter`:return`sheets-pivot-ui.filter`;case`column`:return`sheets-pivot-ui.column`;case`row`:return`sheets-pivot-ui.row`;default:return`sheets-pivot-ui.value`}}function Wn(e){switch(e){case`filter`:return`sheets-pivot-ui.mobile.filterDesc`;case`column`:return`sheets-pivot-ui.mobile.columnDesc`;case`row`:return`sheets-pivot-ui.mobile.rowDesc`;default:return`sheets-pivot-ui.valueDesc`}}function Gn(e){switch(e.area){case`filter`:return/* @__PURE__ */ (0,f.jsx)(At,{});case`column`:return/* @__PURE__ */ (0,f.jsx)(Wt,{});case`row`:return/* @__PURE__ */ (0,f.jsx)(Et,{});default:return/* @__PURE__ */ (0,f.jsx)(Mt,{})}}function Kn(e){switch(e){case`moveUp`:return`sheets-pivot-ui.mobile.moveUp`;case`moveDown`:return`sheets-pivot-ui.mobile.moveDown`;case`moveToFilter`:return`sheets-pivot-ui.mobile.moveToFilter`;case`moveToColumn`:return`sheets-pivot-ui.mobile.moveToColumn`;case`moveToRow`:return`sheets-pivot-ui.mobile.moveToRow`;case`moveToValue`:return`sheets-pivot-ui.mobile.moveToValue`;case`filter`:return`sheets-pivot-ui.filterField`;case`settings`:return`sheets-pivot-ui.fieldSettings`;default:return`sheets-pivot-ui.removeField`}}function qn(e){switch(e){case`moveToFilter`:return`filter`;case`moveToColumn`:return`column`;case`moveToRow`:return`row`;case`moveToValue`:return`value`;default:return null}}function Jn(e){let{area:t,field:n,index:i,fieldCount:o,info:s,pivotTableId:l,unitId:u,subUnitId:d,refresh:p}=e,m=(0,a.useDependency)(r.ICommandService),h=(0,a.useDependency)(r.LocaleService),g=n.tableFieldId===$t,_={pivotTableInfo:s,pivotTableId:l,commandService:m,unitId:u,subUnitId:d};async function v(e){if(e===`filter`){pn(m,u,d,l,n.tableFieldId);return}if(e===`settings`){mn(m,l,n.tableFieldId,u,d,s);return}if(e===`remove`){await on(_,n.tableFieldId,t),await p();return}let r=qn(e)??t,a=Hn(s,r).length;e===`moveUp`?a=i-1:e===`moveDown`&&(a=i+1),await ln(_,n.tableFieldId,t,r,a),await p()}let y=Bn(t,i,o,g).map(e=>({type:`item`,children:h.t(Kn(e)),variant:e===`remove`?`destructive`:`default`,onSelect:()=>v(e)}));return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-min-h-12 univer-items-center univer-gap-3 univer-rounded-xl univer-px-3`,children:[/* @__PURE__ */ (0,f.jsx)(`bdi`,{className:`univer-min-w-0 univer-flex-1 univer-truncate univer-text-sm`,dir:`auto`,children:g?h.t(`sheets-pivot-ui.multipleValue`):n.displayName}),/* @__PURE__ */ (0,f.jsx)(c.MobileDropdownMenu,{items:y,children:/* @__PURE__ */ (0,f.jsx)(`button`,{type:`button`,className:`univer-flex univer-size-10 univer-shrink-0 univer-items-center univer-justify-center univer-rounded-lg univer-border-0 univer-bg-transparent active:univer-bg-gray-100 dark:active:!univer-bg-gray-700`,children:/* @__PURE__ */ (0,f.jsx)(Rt,{})})})]})}function Yn(e){let t=(0,a.useDependency)(r.LocaleService);return/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,children:Vn.map(n=>{let r=Hn(e.info,n);return/* @__PURE__ */ (0,f.jsxs)(`section`,{children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mb-2 univer-flex univer-items-center univer-gap-2 univer-text-sm univer-font-medium`,children:[/* @__PURE__ */ (0,f.jsx)(Gn,{area:n}),t.t(Un(n))]}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-rounded-xl univer-bg-gray-50 univer-p-1 dark:!univer-bg-gray-800`,children:r.length?r.map((t,i)=>/* @__PURE__ */ (0,f.jsx)(Jn,{...e,area:n,field:t,index:i,fieldCount:r.length},t.tableFieldId)):/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-p-4 univer-text-center univer-text-xs univer-text-gray-500`,children:t.t(Wn(n))})})]},n)})})}function Xn(e,t){switch(t){case`filter`:return e.filterFields.length;case`column`:return e.columnFields.length;case`row`:return e.rowFields.length;case`value`:return e.valueFields.length;default:return 0}}function Zn(e){let n=`univer-size-4 univer-shrink-0 univer-text-gray-500`;switch(e.type){case t.PivotDataFieldDataTypeEnum.number:return/* @__PURE__ */ (0,f.jsx)(Bt,{className:n});case t.PivotDataFieldDataTypeEnum.date:return/* @__PURE__ */ (0,f.jsx)(St,{className:n});default:return/* @__PURE__ */ (0,f.jsx)(Jt,{className:n})}}function Qn(e){let{field:n,info:i,pivotTableId:o,unitId:s,subUnitId:l,refresh:u}=e,d=(0,a.useDependency)(r.ICommandService),p=(0,a.useDependency)(r.LocaleService),m={pivotTableInfo:i,pivotTableId:o,commandService:d,unitId:s,subUnitId:l};async function h(e){if(e){let e=n.type===t.PivotDataFieldDataTypeEnum.number?`value`:`row`;await ln(m,n.dataFieldId,`source`,e,Xn(i,e))}else await on(m,n.dataFieldId,`source`);await u()}async function g(e){await ln(m,n.dataFieldId,`source`,e,Xn(i,e)),await u()}let _=[{type:`item`,children:p.t(`sheets-pivot-ui.addToRow`),onSelect:()=>g(`row`)},{type:`item`,children:p.t(`sheets-pivot-ui.addToColumn`),onSelect:()=>g(`column`)},{type:`item`,children:p.t(`sheets-pivot-ui.addToValue`),onSelect:()=>g(`value`)},{type:`item`,children:p.t(`sheets-pivot-ui.addToFilter`),onSelect:()=>g(`filter`)}];return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-min-h-12 univer-items-center univer-gap-3 univer-rounded-xl univer-px-2`,children:[/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:n.checked,onChange:e=>h(!!e)}),/* @__PURE__ */ (0,f.jsx)(Zn,{type:n.type}),/* @__PURE__ */ (0,f.jsx)(`bdi`,{className:`univer-min-w-0 univer-flex-1 univer-truncate univer-text-sm`,dir:`auto`,children:n.name}),/* @__PURE__ */ (0,f.jsx)(c.MobileDropdownMenu,{items:_,children:/* @__PURE__ */ (0,f.jsx)(`button`,{type:`button`,className:`univer-flex univer-size-10 univer-shrink-0 univer-items-center univer-justify-center univer-rounded-lg univer-border-0 univer-bg-transparent active:univer-bg-gray-100 dark:active:!univer-bg-gray-700`,children:/* @__PURE__ */ (0,f.jsx)(Rt,{})})})]})}function $n(e){let{info:t}=e,n=(0,a.useDependency)(r.LocaleService),[i,o]=(0,d.useState)(``),s=i.trim().toLocaleLowerCase(),l=s?t.sourceList.filter(e=>e.name.toLocaleLowerCase().includes(s)):t.sourceList;return/* @__PURE__ */ (0,f.jsxs)(`section`,{className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.sourceFieldTile`)}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mt-1 univer-text-xs univer-text-gray-500`,children:n.t(`sheets-pivot-ui.mobile.sourceFieldDescription`)})]}),/* @__PURE__ */ (0,f.jsx)(c.Input,{allowClear:!0,value:i,placeholder:n.t(`sheets-pivot-ui.searchFieldPlaceholder`),slot:/* @__PURE__ */ (0,f.jsx)(Kt,{}),onChange:o,size:`small`}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-rounded-xl univer-bg-gray-50 univer-p-1 dark:!univer-bg-gray-800`,children:l.length?l.map(t=>/* @__PURE__ */ (0,f.jsx)(Qn,{...e,field:t},t.id)):/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-p-4 univer-text-center univer-text-sm univer-text-gray-500`,children:n.t(`sheets-pivot-ui.noMatchingFields`)})})]})}function er(e){var t;let{sourceRangeInfo:n,positionInfo:i,pivotTableId:o,refresh:s}=e,c=(0,a.useDependency)(r.ICommandService),l=(0,a.useDependency)(r.ILogService),u=(0,a.useDependency)(r.LocaleService),h=(0,a.useDependency)(r.IUniverInstanceService).getUnit(n.unitId),g=(h==null||(t=h.getSheetBySheetId(n.subUnitId))==null?void 0:t.getName())??n.sheetName,[_,v]=(0,d.useState)(n.range),[y,b]=(0,d.useState)(g),[x,S]=(0,d.useState)(``);(0,d.useEffect)(()=>{v(n.range),b(g)},[g,n]);async function C(e){let t=e.split(`,`).filter(Boolean).map(p.deserializeRangeWithSheet)[0];if(!t||!h){S(u.t(`sheets-pivot-ui.msg.emptySourceRange`));return}let r=t.sheetName||n.sheetName,a=h.getSheetBySheetName(r),l=an(a,t.range);if(l!==2||!a){let e=l===0?`sheets-pivot-ui.msg.emptySourceRange`:`sheets-pivot-ui.msg.invalidSize`;S(u.t(e))}else S(``),v(t.range),b(r),await sn(c,o,{unitId:n.unitId,subUnitId:a.getSheetId(),range:t.range,sheetName:r},i.unitId,i.subUnitId),await s()}return/* @__PURE__ */ (0,f.jsxs)(`section`,{children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:u.t(`sheets-pivot-ui.sourceRangeLabel`)}),/* @__PURE__ */ (0,f.jsx)(m.MobileRangeSelector,{unitId:n.unitId,subUnitId:n.subUnitId,initialValue:(0,p.serializeRangeWithSheet)(y,_),maxRangeCount:1,keepSheetReference:!0,supportAcrossSheet:!0,onChange:(e,t)=>C(t).catch(e=>{l.error(`[MobilePivotSourceRange]`,e)})}),x&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mt-2 univer-text-xs univer-text-red-500`,children:x})]})}function tr(e){let{pivotTableId:t,version:i,unitId:o,subUnitId:c,panelInfo:l}=e,u=(0,a.useDependency)(n.SheetsPivotTableConfigModel),p=(0,a.useDependency)(n.SheetsPivotRPCService),m=(0,a.useDependency)(r.ILogService),h=(0,d.useMemo)(()=>u.watchPivotTableChanges(o,c,t).pipe((0,s.debounceTime)(0)),[u,o,c,t]),g=(0,a.useObservable)(h),[_,v]=(0,d.useState)(l),y=(0,d.useCallback)(async()=>{if(!u.getPivotTableConfig(o,c,t))return;let e=await p.getPivotDisplayConfig({unitId:o,subUnitId:c,pivotTableId:t,params:{type:n.PivotDisplayDataType.Panel,panel:{pivotTableId:t}}});e.result.panel&&v(e.result.panel)},[u,t,p,c,o]);return(0,d.useEffect)(()=>{y().catch(e=>m.error(`[MobilePivotPanel]`,e))},[g,m,y,i]),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-5 univer-py-4`,children:[/* @__PURE__ */ (0,f.jsx)(er,{sourceRangeInfo:_.sourceRange,positionInfo:_.positionInfo,pivotTableId:t,refresh:y}),/* @__PURE__ */ (0,f.jsx)($n,{info:_,pivotTableId:t,unitId:o,subUnitId:c,refresh:y}),/* @__PURE__ */ (0,f.jsx)(Yn,{info:_,pivotTableId:t,unitId:o,subUnitId:c,refresh:y})]})}function nr(e){let{className:t,unitId:n,subUnitId:i,pivotTableId:o}=e,[s,l]=(0,d.useState)(`fields`),u=(0,a.useDependency)(r.LocaleService);return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:(0,c.clsx)(`univer-flex univer-size-full univer-min-h-0 univer-flex-col`,t),dir:u.getDirection(),children:[/* @__PURE__ */ (0,f.jsx)(c.Segmented,{className:`univer-sticky univer-top-0 univer-z-10 univer-my-3 univer-w-full univer-shrink-0`,items:[{label:u.t(`sheets-pivot-ui.fieldPanel`),value:`fields`},{label:u.t(`sheets-pivot-ui.configPanel`),value:`config`}],value:s,onChange:l}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-min-h-0 univer-flex-1 univer-overflow-y-auto`,children:s===`fields`?/* @__PURE__ */ (0,f.jsx)(tr,{...e}):/* @__PURE__ */ (0,f.jsx)(zn,{unitId:n,subUnitId:i,pivotTableId:o})})]})}function rr(e,t){switch(e){case 1:return t.t(`sheets-pivot-ui.msg.invalidSize`);case 0:return t.t(`sheets-pivot-ui.msg.emptySourceRange`);default:return``}}function ir(e){let{unitId:t,subUnitId:i,sourceRange:o,positionRange:s,sourceSheetName:l,positionSheetName:u,onConfirm:h,onCancel:g}=e,_=(0,a.useDependency)(r.LocaleService),v=(0,a.useDependency)(r.IUniverInstanceService).getUnit(t),[y,b]=(0,d.useState)(o),[x,S]=(0,d.useState)(s),[C,w]=(0,d.useState)(l),[T,E]=(0,d.useState)(u),[D,O]=(0,d.useState)(n.PositionType.New),[k,A]=(0,d.useState)(``),[j,M]=(0,d.useState)(!0);(0,d.useEffect)(()=>{let e=an(v.getSheetBySheetName(C),y);A(rr(e,_))},[_,y,C,v]);function N(e){let t=e.split(`,`).filter(Boolean).map(p.deserializeRangeWithSheet)[0];t?(b(t.range),w(t.sheetName||C)):A(_.t(`sheets-pivot-ui.msg.emptySourceRange`))}function P(e){let t=e.split(`,`).filter(Boolean).map(p.deserializeRangeWithSheet)[0];if(!t){S(null);return}let n=t.sheetName||l;S(t.range),E(n),M(n!==C||!r.Rectangle.intersects(t.range,y))}function F(){if(k)return;let e;if(D===n.PositionType.Existing){if(!x||!j)return;e={sourceRange:y,sourceSheetName:C,positionRange:x,positionSheetName:T,positionType:D}}else e={sourceRange:y,sourceSheetName:C,positionType:D};h(e)}return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-5`,dir:_.getDirection(),children:[/* @__PURE__ */ (0,f.jsxs)(`section`,{children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:_.t(`sheets-pivot-ui.dialog.source.sourceData`)}),/* @__PURE__ */ (0,f.jsx)(m.MobileRangeSelector,{unitId:t,subUnitId:i,initialValue:(0,p.serializeRangeWithSheet)(C,y),maxRangeCount:1,supportAcrossSheet:!0,keepSheetReference:!0,onChange:(e,t)=>N(t)}),k&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mt-2 univer-text-xs univer-text-red-500`,children:k})]}),/* @__PURE__ */ (0,f.jsxs)(`section`,{children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:_.t(`sheets-pivot-ui.dialog.source.position`)}),/* @__PURE__ */ (0,f.jsxs)(c.RadioGroup,{className:`univer-flex univer-flex-col univer-gap-3`,value:D,onChange:e=>O(e),children:[/* @__PURE__ */ (0,f.jsx)(c.Radio,{value:n.PositionType.New,children:_.t(`sheets-pivot-ui.dialog.source.newSheet`)}),/* @__PURE__ */ (0,f.jsx)(c.Radio,{value:n.PositionType.Existing,children:_.t(`sheets-pivot-ui.dialog.source.existingSheet`)})]}),D===n.PositionType.Existing&&/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mt-3`,children:[/* @__PURE__ */ (0,f.jsx)(m.MobileRangeSelector,{unitId:t,subUnitId:i,initialValue:x?(0,p.serializeRangeWithSheet)(T,x):``,maxRangeCount:1,supportAcrossSheet:!0,keepSheetReference:!0,onChange:(e,t)=>P(t)}),!j&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mt-2 univer-text-xs univer-text-red-500`,children:_.t(`sheets-pivot-ui.dialog.source.intersect`)})]})]}),/* @__PURE__ */ (0,f.jsxs)(c.MobileActionRowGroup,{children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{onClick:g,size:`middle`,children:_.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`primary`,onClick:F,size:`middle`,children:_.t(`sheets-pivot-ui.dialog.ok`)})]})]})}let ar=class extends r.Disposable{constructor(e,t){super(),[[j,ir],[v,nr],[b,Pn],[S,Nn],[w,Mn],[M,Yt]].forEach(([t,n])=>{this.disposeWithMe(e.register(t,n))}),this.disposeWithMe(t.register({PivotTableIcon:Ht}))}};ar=K([G(0,(0,r.Inject)(a.ComponentManager)),G(1,(0,r.Inject)(a.IconManager))],ar);function or(e){return{id:P.id,commandId:P.id,type:a.MenuItemType.BUTTON,icon:`PivotTableIcon`,title:`sheets-pivot-ui.title`,tooltip:`sheets-pivot-ui.title`,hidden$:(0,a.getMenuHiddenObservable)(e,r.UniverInstanceType.UNIVER_SHEET),disabled$:(0,o.getObservableWithExclusiveRange$)(e,(0,o.getCurrentRangeDisable$)(e,{workbookTypes:[i.WorkbookEditablePermission],worksheetTypes:[i.WorksheetViewPermission,i.WorksheetPivotTablePermission],rangeTypes:[i.RangeProtectionPermissionViewPoint]}))}}let sr={[a.RibbonDataGroup.ORGANIZATION]:{[P.id]:{order:1,gridLayout:{row:2,column:1},menuItemFactory:or}},[a.ContextMenuPosition.MAIN_AREA]:{[a.ContextMenuGroup.DATA]:{[P.id]:{order:1,menuItemFactory:or}}}},cr=class extends r.Disposable{constructor(e){super(),e.mergeMenu(sr)}};cr=K([G(0,a.IMenuManagerService)],cr);let lr=class extends r.Disposable{constructor(e,t,i,a){super(),this._sidebarService=i,this._dialogService=a,W(this,`_pivotTableId`,null),this.disposeWithMe(e.onCommandExecuted(e=>{e.id===at.id?this._pivotTableId=e.params.pivotTableId:e.id===n.RemovePivotTableMutation.id&&e.params.pivotTableId===this._pivotTableId&&this._closePanel()}));let o=t.getCurrentUnitOfType(r.UniverInstanceType.UNIVER_SHEET);o&&(this.disposeWithMe(o.activeSheet$.pipe((0,s.skip)(1)).subscribe(()=>this._closePanel())),this.disposeWithMe(o.sheetDisposed$.subscribe(()=>this._closePanel()))),this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(e=>{e.id===`UNIVER_SHEET_PIVOT_PANEL_ID`&&e.visible===!1&&(this._pivotTableId=null,this._closeChildDialogs())}))}_closePanel(){this._pivotTableId=null,this._sidebarService.close(y),this._closeChildDialogs()}_closeChildDialogs(){this._dialogService.close(x),this._dialogService.close(C),this._dialogService.close(T)}};lr=K([G(0,r.ICommandService),G(1,r.IUniverInstanceService),G(2,a.ISidebarService),G(3,a.IDialogService)],lr);var X=class{static drawExpand(e,t,n,r,i){let a=(i-t)/2;e.save(),e.fillStyle=r,e.strokeStyle=n,e.beginPath(),e.moveTo(6,a),e.lineTo(4+t-2,a),e.arcTo(4+t,a,4+t,a+2,2),e.lineTo(4+t,a+t-2),e.arcTo(4+t,a+t,4+t-2,a+t,2),e.lineTo(6,a+t),e.arcTo(4,a+t,4,a+t-2,2),e.lineTo(4,a+2),e.arcTo(4,a,6,a,2),e.closePath(),e.stroke(),e.fill(),e.beginPath(),e.moveTo(4+t/2,a+2),e.lineTo(4+t/2,a+t-2),e.moveTo(6,a+t/2),e.lineTo(4+t-2,a+t/2),e.stroke(),e.restore()}static drawCollapse(e,t,n,r,i){let a=(i-t)/2;e.save(),e.fillStyle=r,e.strokeStyle=n,e.beginPath(),e.moveTo(6,a),e.lineTo(4+t-2,a),e.arcTo(4+t,a,4+t,a+2,2),e.lineTo(4+t,a+t-2),e.arcTo(4+t,a+t,4+t-2,a+t,2),e.lineTo(6,a+t),e.arcTo(4,a+t,4,a+t-2,2),e.lineTo(4,a+2),e.arcTo(4,a,6,a,2),e.closePath(),e.fill(),e.stroke(),e.beginPath(),e.moveTo(6,a+t/2),e.lineTo(4+t-2,a+t/2),e.stroke(),e.restore()}static drawFilterIcon(e,t,n,r){u.Rect.drawWith(e,{radius:2,width:16,height:16,fill:r}),(0,h.drawCanvasIcon)(e,t,0,0,16,n)}};let ur=/* @__PURE__ */ new Set([t.PivotCellStyleTypeEnum.FilterAll,t.PivotCellStyleTypeEnum.FilterPartial,t.PivotCellStyleTypeEnum.FilterSingle,t.PivotCellStyleTypeEnum.FilterNoneSortNone,t.PivotCellStyleTypeEnum.FilteredSortAsc,t.PivotCellStyleTypeEnum.FilteredSortDesc,t.PivotCellStyleTypeEnum.FilteredSortNone,t.PivotCellStyleTypeEnum.FilterNoneSortAsc,t.PivotCellStyleTypeEnum.FilterNoneSortDesc]),dr=/* @__PURE__ */ new Set([t.PivotCellStyleTypeEnum.Expand,t.PivotCellStyleTypeEnum.Collapse]),fr=class extends u.Shape{constructor(e,t,n,r){super(e,t),this._commandService=n,this._themeService=r,W(this,`_cellWidth`,0),W(this,`_cellHeight`,0),W(this,`_hovered`,!1),W(this,`_pivotParams`,void 0),this.setShapeProps(t),this.onPointerDown$.subscribeEvent(e=>this.onPointerDown(e)),this.onPointerEnter$.subscribeEvent(()=>this.onPointerEnter()),this.onPointerLeave$.subscribeEvent(()=>this.onPointerLeave())}setShapeProps(e){e.cellHeight!==void 0&&(this._cellHeight=e.cellHeight),e.cellWidth!==void 0&&(this._cellWidth=e.cellWidth),e.pivotParams!==void 0&&(this._pivotParams=e.pivotParams),this.transformByState({width:e.width,height:e.height})}onPointerDown(e){if(e.button===2)return;let{col:r,row:i,unitId:a,subUnitId:o,buttonType:s}=this._pivotParams;ur.has(s)?setTimeout(()=>{this._commandService.executeCommand(nt.id,{row:i,col:r,unitId:a,subUnitId:o})},200):this._commandService.executeCommand(n.SetPivotCollapseCommand.id,{row:i,col:r,unitId:a,subUnitId:o,collapse:s===t.PivotCellStyleTypeEnum.Expand})}onPointerEnter(){this._hovered=!0,this.setCursor(u.CURSOR_TYPE.POINTER),this.makeDirty(!0)}onPointerLeave(){this._hovered=!1,this.setCursor(u.CURSOR_TYPE.DEFAULT),this.makeDirty(!0)}_draw(e){var n,r;if(!((n=this._pivotParams)!=null&&n.buttonType))return;let i=this._themeService.getColorFromTheme(`primary.600`),a=this._themeService.getColorFromTheme(`gray.50`);e.save();let o=new Path2D;o.rect(0,0,this._cellWidth,this._cellHeight),e.clip(o),((r=this._pivotParams)==null?void 0:r.buttonType)===t.PivotCellStyleTypeEnum.Collapse?X.drawExpand(e,12,i,a,this._cellHeight):this._pivotParams.buttonType===t.PivotCellStyleTypeEnum.Expand?X.drawCollapse(e,12,i,a,this._cellHeight):this._pivotParams.buttonType===t.PivotCellStyleTypeEnum.FilterAll||this._pivotParams.buttonType===t.PivotCellStyleTypeEnum.FilterNoneSortNone?X.drawFilterIcon(e,`filter-options-icon`,i,a):this._pivotParams.buttonType===t.PivotCellStyleTypeEnum.FilterPartial||this._pivotParams.buttonType===t.PivotCellStyleTypeEnum.FilterSingle||this._pivotParams.buttonType===t.PivotCellStyleTypeEnum.FilteredSortNone?X.drawFilterIcon(e,`filter-applied-icon`,i,a):this._pivotParams.buttonType===t.PivotCellStyleTypeEnum.FilterNoneSortAsc?X.drawFilterIcon(e,`ascending-icon`,i,a):this._pivotParams.buttonType===t.PivotCellStyleTypeEnum.FilterNoneSortDesc?X.drawFilterIcon(e,`descending-icon`,i,a):this._pivotParams.buttonType===t.PivotCellStyleTypeEnum.FilteredSortAsc?X.drawFilterIcon(e,`filter-sort-ascending-icon`,i,a):this._pivotParams.buttonType===t.PivotCellStyleTypeEnum.FilteredSortDesc&&X.drawFilterIcon(e,`filter-sort-descending-icon`,i,a),e.restore()}};fr=K([G(2,r.ICommandService),G(3,(0,r.Inject)(r.ThemeService))],fr);let pr=class extends u.Shape{constructor(e,t,n,r){super(e,t),this._commandService=n,this._themeService=r,W(this,`_cellWidth`,void 0),W(this,`_cellHeight`,void 0),W(this,`_pivotParams`,void 0),this._cellWidth=t.cellWidth,this._cellHeight=t.cellHeight,this._pivotParams=t.pivotParams,this.transformByState({width:t.width,height:t.height}),this.onPointerUp$.subscribeEvent(e=>this._handlePointerUp(e))}_handlePointerUp(e){if(e.button===2)return;let{col:r,row:i,unitId:a,subUnitId:o,buttonType:s}=this._pivotParams;if(ur.has(s))return this._commandService.executeCommand(nt.id,{row:i,col:r,unitId:a,subUnitId:o});if(dr.has(s))return this._commandService.executeCommand(n.SetPivotCollapseCommand.id,{row:i,col:r,unitId:a,subUnitId:o,collapse:s===t.PivotCellStyleTypeEnum.Expand})}_draw(e){let n=this._pivotParams.buttonType,r=this._themeService.getColorFromTheme(`primary.600`),i=this._themeService.getColorFromTheme(`gray.50`);e.save();let a=new Path2D;a.rect(0,0,this._cellWidth,this._cellHeight),e.clip(a),e.translate(6,6),n===t.PivotCellStyleTypeEnum.Collapse?X.drawExpand(e,12,r,i,this._cellHeight):n===t.PivotCellStyleTypeEnum.Expand?X.drawCollapse(e,12,r,i,this._cellHeight):n===t.PivotCellStyleTypeEnum.FilterAll||n===t.PivotCellStyleTypeEnum.FilterNoneSortNone?X.drawFilterIcon(e,`filter-options-icon`,r,i):n===t.PivotCellStyleTypeEnum.FilterPartial||n===t.PivotCellStyleTypeEnum.FilterSingle||n===t.PivotCellStyleTypeEnum.FilteredSortNone?X.drawFilterIcon(e,`filter-applied-icon`,r,i):n===t.PivotCellStyleTypeEnum.FilterNoneSortAsc?X.drawFilterIcon(e,`ascending-icon`,r,i):n===t.PivotCellStyleTypeEnum.FilterNoneSortDesc?X.drawFilterIcon(e,`descending-icon`,r,i):n===t.PivotCellStyleTypeEnum.FilteredSortAsc?X.drawFilterIcon(e,`filter-sort-ascending-icon`,r,i):n===t.PivotCellStyleTypeEnum.FilteredSortDesc&&X.drawFilterIcon(e,`filter-sort-descending-icon`,r,i),e.restore()}};pr=K([G(2,r.ICommandService),G(3,(0,r.Inject)(r.ThemeService))],pr);function mr(e,t,n){let{startX:r,startY:i,endX:a,endY:o}=n;return{left:(t===`filter`?e!==`rtl`:e===`rtl`)?a-16-1:r+1,top:t===`filter`?o-16-1:i+1}}let hr=class extends r.Disposable{constructor(e,t,n,r,i,a,o,s,c,l){super(),this._context=e,this._injector=t,this._adaptorModel=n,this._skeletonManagerService=r,this._configModel=i,this._permissionController=a,this._permissionService=o,this._localeService=s,this._dialogService=c,this._contextMenuController=l,W(this,`_buttonShapes`,[]),this._initContextMenu(),this._initButtonRender(),this._initSkeleton()}dispose(){this._clearButtons(),super.dispose()}_clearButtons(){this._buttonShapes.forEach(e=>e.dispose()),this._buttonShapes.length=0}_initContextMenu(){if(!this._contextMenuController)return;let e=this._contextMenuController.contextMenuInterceptor.intercept(o.MOBILE_CONTEXT_MENU,{handler:(e,t,n)=>{if(e||t.menuPosition!==a.ContextMenuPosition.MAIN_AREA)return n(e);let{col:r,row:i,subUnitId:o,unitId:s}=t;if(r==null||i==null)return n(e);let c=this._adaptorModel.getPivotTableIdByCell(s,o,i,r);return c?(this._openPivotActionPanel(s,o,c,i,r),!0):n(e)}});this.disposeWithMe((0,r.toDisposable)(e))}_openPivotActionPanel(e,t,n,r,a){let o=this._permissionController.permissionCheckWithRanges({workbookTypes:[i.WorkbookEditablePermission],worksheetTypes:[i.WorksheetPivotTablePermission],rangeTypes:[i.RangeProtectionPermissionEditPoint]},[{startRow:r,endRow:r,startColumn:a,endColumn:a}],e,t);this._dialogService.open({id:N,title:{title:this._localeService.t(`sheets-pivot-ui.title`)},children:{label:{name:M,props:{editable:o,pivotTableId:n,subUnitId:t,unitId:e}}},onClose:()=>this._dialogService.close(N)})}_initButtonRender(){this.disposeWithMe((0,s.merge)(this._adaptorModel.viewUpdate$.pipe((0,s.auditTime)(0)),this._skeletonManagerService.currentSkeleton$,this._configModel.pivotConfigChange$,this._permissionService.permissionPointUpdate$.pipe((0,s.auditTime)(100))).subscribe(()=>{let e=this._context.unit,t=this._skeletonManagerService.getCurrentSkeleton();if(!e||!t)return;let n=e.getActiveSheet(),r=e.getUnitId(),a=n.getSheetId(),s=this._localeService.getDirection(),{scene:c}=this._context;this._clearButtons(),this._adaptorModel.getSubUnitPivotMatrix(r,a).forValue((e,n,l)=>{if(!(l!=null&&l.pbt))return;let{startX:u,startY:d,endX:f,endY:p}=(0,o.getCoordByCell)(e,n,c,t),m=f-u,h=p-d;if(h<8||m<8||!this._permissionController.permissionCheckWithRanges({workbookTypes:[i.WorkbookEditablePermission],worksheetTypes:[i.WorksheetViewPermission,i.WorksheetEditPermission,i.WorksheetPivotTablePermission],rangeTypes:[i.RangeProtectionPermissionViewPoint,i.RangeProtectionPermissionEditPoint]},[{startRow:e,endRow:e,startColumn:n,endColumn:n}],r,a))return;let g;if(ur.has(l.pbt))g=`filter`;else if(dr.has(l.pbt))g=`collapse`;else return;let _=mr(s,g,{startX:u,startY:d,endX:f,endY:p}),v={left:_.left-6,top:_.top-6,width:28,height:28,zIndex:5e3,cellWidth:m,cellHeight:h,pivotParams:{row:e,col:n,unitId:r,subUnitId:a,buttonType:l.pbt}},y=`sheets-mobile-pivot-button-${e}-${n}-${r}-${a}`;this._buttonShapes.push(this._injector.createInstance(pr,y,v))}),this._buttonShapes.length&&c.addObjects(this._buttonShapes),c.makeDirty()}))}_initSkeleton(){var e;this.disposeWithMe(this._adaptorModel.markDirty$.subscribe(({unitId:e,subUnitId:t})=>{if(e===this._context.unitId&&(this._skeletonManagerService.makeDirty({sheetId:t}),this._context.unit.getActiveSheet().getSheetId()===t)){var n;this._skeletonManagerService.reCalculate(),(n=this._context.mainComponent)==null||n.makeDirty()}}));let t=this._context.unitId;this._context.unit.getSheets().forEach(e=>{var n;let r=e.getSheetId();(n=this._adaptorModel.getSubUnitPivotRenderCache(t,r))!=null&&n.size&&this._skeletonManagerService.makeDirty({sheetId:r})}),this._skeletonManagerService.reCalculate(),(e=this._context.mainComponent)==null||e.makeDirty()}};hr=K([G(1,(0,r.Inject)(r.Injector)),G(2,(0,r.Inject)(n.SheetsPivotTableAdaptorModel)),G(3,(0,r.Inject)(o.SheetSkeletonManagerService)),G(4,(0,r.Inject)(n.SheetsPivotTableConfigModel)),G(5,(0,r.Inject)(i.SheetPermissionCheckController)),G(6,(0,r.Inject)(r.IPermissionService)),G(7,(0,r.Inject)(r.LocaleService)),G(8,a.IDialogService),G(9,(0,r.Optional)(o.SheetContextMenuMobileRenderController))],hr);let gr=class extends r.Disposable{constructor(e,t,n){super(),this._univerInstanceService=e,this._sheetsPivotTableAdaptorModel=t,this._sheetClipboardService=n,this._initialize()}_initialize(){let e=this,t,i;this.disposeWithMe(this._sheetClipboardService.addClipboardHook({id:n.SHEET_PIVOT_TABLE_PLUGIN,onBeforeCopy(n,a){let o=e._univerInstanceService.getUnit(n,r.UniverInstanceType.UNIVER_SHEET);o&&(t=e._sheetsPivotTableAdaptorModel.getSubUnitPivotMatrix(n,a),i=o.getStyles())},onAfterCopy(){t=null,i=null},getCellValueBySpecialMatrix(e,n){if(!t)return;let r=t==null?void 0:t.getValue(e,n);if(r){var a;return{...r,s:i==null?void 0:i.get(r.s),displayV:((a=r.v)==null?void 0:a.toString())||``}}}}))}};gr=K([G(0,(0,r.Inject)(r.IUniverInstanceService)),G(1,(0,r.Inject)(n.SheetsPivotTableAdaptorModel)),G(2,o.ISheetClipboardService)],gr);let _r=[i.InsertRowCommand.id,i.RemoveColCommand.id,i.RemoveRowCommand.id,i.InsertColCommand.id],vr=class extends r.Disposable{constructor(e,t,r,i,a,o,s,c,l){var u;super(),this._injector=e,this._univerInstanceService=t,this._sheetsPivotTableAdaptorModel=r,this._sheetInterceptorService=i,this._confirmService=a,this._localeService=o,this._sheetsPivotTableConfigModel=s,this._messageService=c,this._configService=l,W(this,`_defaultOverride`,!1),this._initMoveRangeConfirmCheck(),this._initRowColOperationCheck(),this._defaultOverride=((u=this._configService.getConfig(n.SHEETS_PIVOT_PLUGIN_CONFIG_KEY))==null?void 0:u.defaultOverride)??!1}_initMoveRangeConfirmCheck(){this.disposeWithMe(this._sheetInterceptorService.interceptBeforeCommand({performCheck:async e=>{if(e.id===i.MoveRangeCommand.id){let t=(0,i.getSheetCommandTarget)(this._univerInstanceService);if(!t)return Promise.resolve(!1);let{unitId:r,subUnitId:a}=t,{fromRange:o,toRange:s}=e.params,c=this._sheetsPivotTableConfigModel.getSubUnitPivotConfigs(r,a);if(!(c!=null&&c.size))return Promise.resolve(!0);for(let[e,t]of c){let{targetCellInfo:i}=t,{row:c,col:l}=i,u=c-o.startRow,d=l-o.startColumn,f={row:s.startRow+u,col:s.startColumn+d},p=f.row-i.row,m=f.col-i.col,h=this._sheetsPivotTableAdaptorModel.getPivotItemRenderInfoCache(r,a,e),g=h==null?void 0:h.rangesInfo;if(!g)return Promise.resolve(!0);let _=[];Object.keys(g).forEach(e=>{g[e].forEach(e=>{let t={...e};t.startRow=e.startRow+p,t.endRow=e.endRow+p,t.startColumn=e.startColumn+m,t.endColumn=e.endColumn+m,_.push(t)})});let v=this._sheetInterceptorService.generateMutationsByRanges({unitId:r,subUnitId:a,ranges:_}),y=(0,n.generateSetRangeValueMutations)(this._injector,r,a,_);if(v.redos.length||y.shouldClear){if(this._defaultOverride)return Promise.resolve(!0);{let e=await this._confirmService.confirm({id:`sheet-pivot.confirm.add-sheet-pivot`,title:{title:this._localeService.t(`sheets-pivot-ui.perform.tips`)},children:{title:this._localeService.t(`sheets-pivot-ui.perform.info`)},cancelText:this._localeService.t(`sheets-pivot-ui.perform.cancel`),confirmText:this._localeService.t(`sheets-pivot-ui.perform.confirm`)});return Promise.resolve(e)}}}}return Promise.resolve(!0)}}))}_initRowColOperationCheck(){this.disposeWithMe(this._sheetInterceptorService.interceptBeforeCommand({performCheck:async e=>{if(_r.includes(e.id)){let t=e.params,{range:n}=t,a=(0,i.getSheetCommandTarget)(this._univerInstanceService),o=t.unitId||(a==null?void 0:a.unitId),s=t.subUnitId||(a==null?void 0:a.subUnitId);if(!o||!s)return Promise.resolve(!0);let l=this._sheetsPivotTableConfigModel.getSubUnitPivotConfigs(o,s);if(l!=null&&l.size)for(let[e,t]of l){let t=this._sheetsPivotTableAdaptorModel.getPivotItemRenderInfoCache(o,s,e);if(t!=null&&t.rangesInfo){for(let e of Object.keys(t.rangesInfo))if(t.rangesInfo[e].some(e=>r.Rectangle.intersects(e,n)))return this._messageService.show({type:c.MessageType.Error,content:this._localeService.t(`sheets-pivot-ui.perform.rowColError`)}),Promise.resolve(!1)}}}return Promise.resolve(!0)}}))}};vr=K([G(0,(0,r.Inject)(r.Injector)),G(1,(0,r.Inject)(r.IUniverInstanceService)),G(2,(0,r.Inject)(n.SheetsPivotTableAdaptorModel)),G(3,(0,r.Inject)(i.SheetInterceptorService)),G(4,(0,r.Inject)(r.IConfirmService)),G(5,(0,r.Inject)(r.LocaleService)),G(6,(0,r.Inject)(n.SheetsPivotTableConfigModel)),G(7,(0,r.Inject)(a.IMessageService)),G(8,(0,r.Inject)(r.IConfigService))],vr);let yr=[g.InsertTextCommand.id,_.IMEInputCommand.id,o.SetCellEditVisibleOperation.id],br=class extends r.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetsSelectionsService=e,this._univerInstanceService=t,this._sheetsPivotTableAdaptorModel=n,this._commandService=r,this._sheetsPivotTableConfigModel=i,this._localeService=a,this._initEditListener()}_initEditListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(yr.includes(e.id)){var t;let n=(t=this._sheetsSelectionsService.getCurrentLastSelection())==null?void 0:t.primary;if(!n)return;let{actualRow:a,actualColumn:o}=n,s=(0,r.cellToRange)(a,o),c=(0,i.getSheetCommandTarget)(this._univerInstanceService,e.params);if(!c)return;let{unitId:l,subUnitId:u}=c,d=this._sheetsPivotTableConfigModel.getSubUnitPivotConfigs(l,u);if(d!=null&&d.size)for(let[e]of d){let t=this._sheetsPivotTableAdaptorModel.getPivotItemRenderInfoCache(l,u,e);if(t!=null&&t.rangesInfo){for(let e of Object.keys(t.rangesInfo))if(t.rangesInfo[e].some(e=>r.Rectangle.intersects(e,s)))throw new r.CustomCommandExecutionError(this._localeService.t(`sheets-pivot-ui.msg.editCellError`))}}}}))}};br=K([G(0,(0,r.Inject)(i.SheetsSelectionsService)),G(1,(0,r.Inject)(r.IUniverInstanceService)),G(2,(0,r.Inject)(n.SheetsPivotTableAdaptorModel)),G(3,(0,r.Inject)(r.ICommandService)),G(4,(0,r.Inject)(n.SheetsPivotTableConfigModel)),G(5,(0,r.Inject)(r.LocaleService))],br);let xr=class extends r.Disposable{constructor(e,t,n,r){super(),this._sheetsPivotTableAdaptorModel=e,this._formatPainterService=t,this._messageService=n,this._localeService=r,this._initFormatPainterListener()}_initFormatPainterListener(){let e=this._sheetsPivotTableAdaptorModel,t=this._messageService,n=this._localeService;this._formatPainterService.addHook({id:`pivot-format-painter-hook`,onBeforeApply(r){let{redoMutationsInfo:a}=r;for(let r of a)if(r.id===i.AddWorksheetMergeMutation.id){let{unitId:i,subUnitId:a,ranges:o}=r.params;for(let r of o)if(e.getIntersectsPivotTable(i,a,r).length>0)return t.show({type:c.MessageType.Error,content:n.t(`sheets-pivot-ui.msg.mergeCellError`)}),!1}return!0}})}};xr=K([G(0,(0,r.Inject)(n.SheetsPivotTableAdaptorModel)),G(1,(0,r.Inject)(o.IFormatPainterService)),G(2,(0,r.Inject)(a.IMessageService)),G(3,(0,r.Inject)(r.LocaleService))],xr);let Sr=class extends r.Disposable{constructor(e,t,n){super(),this._sheetPrintInterceptorService=e,this._sheetsPivotTableAdaptorModel=t,this._sheetsPivotTableConfigModel=n,this._initPrintArea()}_initPrintArea(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(e,t,n)=>{let{unitId:i,subUnitId:a}=t,o=(e==null?void 0:e.startRow)??1/0,s=(e==null?void 0:e.endRow)??-1/0,c=(e==null?void 0:e.startColumn)??1/0,l=(e==null?void 0:e.endColumn)??-1/0,u=this._sheetsPivotTableConfigModel.getSubUnitPivotConfigs(i,a);if(!u)return n(e);for(let[e,t]of u){var d;let t=(d=this._sheetsPivotTableAdaptorModel.getPivotItemRenderInfoCache(i,a,e))==null?void 0:d.rangesInfo;t&&Object.values(t).forEach(e=>{e.forEach(e=>{let{startRow:t,endRow:n,startColumn:r,endColumn:i}=e;o=Math.min(t,o),s=Math.max(n,s),c=Math.min(r,c),l=Math.max(i,l)})})}let f={startRow:o,endRow:s,startColumn:c,endColumn:l};return(0,r.isValidRange)(f)?n(f):n(e)}}))}};Sr=K([G(0,(0,r.Inject)(o.SheetPrintInterceptorService)),G(1,(0,r.Inject)(n.SheetsPivotTableAdaptorModel)),G(2,(0,r.Inject)(n.SheetsPivotTableConfigModel))],Sr);let Cr=class extends r.Disposable{constructor(e,t,n){super(),this._mergeCellController=e,this._univerInstanceService=t,this._sheetsPivotTableConfigModel=n,this._initMenuInterceptor()}_initMenuInterceptor(){this.disposeWithMe(this._mergeCellController.interceptor.intercept(this._mergeCellController.interceptor.getInterceptPoints().MERGE_CELL_INTERCEPTOR_CHECK,{handler:(e,t)=>{let n=(0,i.getSheetCommandTarget)(this._univerInstanceService);if(!n)return e;let{unitId:a,subUnitId:o}=n,s=this._sheetsPivotTableConfigModel.getSubUnitPivotConfigs(a,o),c=[];return s&&s.forEach((e,t)=>{var n;let r=(n=this._sheetsPivotTableConfigModel.getPivotTableRangeInfo(a,o,t))==null?void 0:n.rangeInfo;r&&Object.keys(r).forEach(e=>{let t=r[e];Array.isArray(t)&&c.push(...t)})}),c.length&&t.some(e=>c.some(t=>r.Rectangle.intersects(t,e)))?!0:e}}))}};Cr=K([G(0,(0,r.Inject)(i.MergeCellController)),G(1,(0,r.Inject)(r.IUniverInstanceService)),G(2,(0,r.Inject)(n.SheetsPivotTableConfigModel))],Cr);let Z=class extends r.Plugin{constructor(e=st,t,n,i,a){super(),this._config=e,this._injector=t,this._commandService=n,this._renderManagerService=i,this._configService=a;let{menu:o,...s}=(0,r.merge)({},st,this._config);o&&this._configService.setConfig(`menu`,o,{merge:!0}),this._configService.setConfig(ot,s),this._registerCommands()}onStarting(){[[ar],[cr],[lr],[Cr],[vr],[Sr],[br],[xr],[q],[gr]].forEach(e=>this._injector.add(e)),(0,r.touchDependencies)(this._injector,[[ar],[cr],[lr],[q]])}onRendered(){this._registerRenderModules(),(0,r.touchDependencies)(this._injector,[[vr],[Sr],[br],[xr],[gr]])}onSteady(){(0,r.touchDependencies)(this._injector,[[Cr]])}_registerCommands(){[at,P,nt,rt,I].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerRenderModules(){this.disposeWithMe(this._renderManagerService.registerRenderModule(r.UniverInstanceType.UNIVER_SHEET,[hr]))}};W(Z,`pluginName`,`${n.SHEET_PIVOT_TABLE_PLUGIN}_UI_PLUGIN`),W(Z,`packageName`,et),W(Z,`version`,tt),W(Z,`type`,r.UniverInstanceType.UNIVER_SHEET),Z=K([(0,r.DependentOn)(l.UniverLicensePlugin,u.UniverRenderEnginePlugin,i.UniverSheetsPlugin,n.UniverSheetsPivotTablePlugin,o.UniverSheetsMobileUIPlugin,a.UniverMobileUIPlugin),G(1,(0,r.Inject)(r.Injector)),G(2,r.ICommandService),G(3,u.IRenderManagerService),G(4,r.IConfigService)],Z);let wr=[t.PivotExcelDateGroupUnit.Year,t.PivotExcelDateGroupUnit.Quarter,t.PivotExcelDateGroupUnit.Month,t.PivotExcelDateGroupUnit.Day,t.PivotExcelDateGroupUnit.Hour,t.PivotExcelDateGroupUnit.Minute,t.PivotExcelDateGroupUnit.Second],Tr={[t.PivotExcelDateGroupUnit.Year]:`sheets-pivot-ui.dateGroup.year`,[t.PivotExcelDateGroupUnit.Quarter]:`sheets-pivot-ui.dateGroup.quarter`,[t.PivotExcelDateGroupUnit.Month]:`sheets-pivot-ui.dateGroup.month`,[t.PivotExcelDateGroupUnit.Day]:`sheets-pivot-ui.dateGroup.day`,[t.PivotExcelDateGroupUnit.Hour]:`sheets-pivot-ui.dateGroup.hour`,[t.PivotExcelDateGroupUnit.Minute]:`sheets-pivot-ui.dateGroup.minute`,[t.PivotExcelDateGroupUnit.Second]:`sheets-pivot-ui.dateGroup.second`},Er=`univer-h-8 univer-rounded-md univer-border univer-border-gray-300 univer-bg-gray-0 univer-px-2 univer-text-sm univer-text-gray-900 dark:univer-bg-gray-700 dark:univer-text-gray-0`;function Dr({targetFieldName:e,dateSystem:n,grouping:i,onConfirm:o,onCancel:s}){let l=(0,a.useDependency)(r.LocaleService),u=(0,a.useObservable)(l.direction$,l.getDirection()),p=(e,t)=>{let i=e===void 0?null:(0,r.excelSerialToDateTimeParts)(e,{dateSystem:n});if(!i)return{date:``,time:t};let a=e=>String(e).padStart(2,`0`);return{date:`${i.year}-${a(i.month)}-${a(i.day)}`,time:`${a(i.hours)}:${a(i.minutes)}:${a(i.seconds)}`}},[m,h]=(0,d.useState)((i==null?void 0:i.units)??[t.PivotExcelDateGroupUnit.Day]),[g,_]=(0,d.useState)((i==null?void 0:i.autoStart)??!0),[v,y]=(0,d.useState)((i==null?void 0:i.autoEnd)??!0),[b,x]=(0,d.useState)(()=>p(i==null?void 0:i.start,`00:00:00`).date),[S,C]=(0,d.useState)(()=>p(i==null?void 0:i.end,`23:59:59`).date),[w,T]=(0,d.useState)(()=>p(i==null?void 0:i.start,`00:00:00`).time),[E,D]=(0,d.useState)(()=>p(i==null?void 0:i.end,`23:59:59`).time),[O,k]=(0,d.useState)((i==null?void 0:i.daysInterval)??1),[A,j]=(0,d.useState)(!1),M=(0,d.useRef)(!1),N=m.some(e=>e===t.PivotExcelDateGroupUnit.Hour||e===t.PivotExcelDateGroupUnit.Minute||e===t.PivotExcelDateGroupUnit.Second),P=m.length===1&&m[0]===t.PivotExcelDateGroupUnit.Day,F=(e,t,i)=>{let a=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e),o=/^(\d{2}):(\d{2})(?::(\d{2}))?$/.exec(t);return!a||!o?null:(0,r.excelDateTimePartsToSerial)({year:Number(a[1]),month:Number(a[2]),day:Number(a[3]),hours:N?Number(o[1]):i?23:0,minutes:N?Number(o[2]):i?59:0,seconds:N?Number(o[3]??0):i?59:0,fractionalSecond:i?.999:0},{dateSystem:n})},I=g?void 0:F(b,w,!1),L=v?void 0:F(S,E,!0),R=m.length>0&&(g||I!==null)&&(v||L!==null)&&(I==null||L==null||I<=L)&&(!P||Number.isInteger(O)&&O>=1);return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,dir:u,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-text-sm univer-font-medium`,children:e}),/* @__PURE__ */ (0,f.jsxs)(`fieldset`,{children:[/* @__PURE__ */ (0,f.jsx)(`legend`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:l.t(`sheets-pivot-ui.dateGroup.groupBy`)}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-grid univer-grid-cols-2 univer-gap-2`,children:wr.map(e=>/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:m.includes(e),onChange:t=>h(n=>t?wr.filter(t=>t===e||n.includes(t)):n.filter(t=>t!==e)),children:l.t(Tr[e])},e))})]}),P&&/* @__PURE__ */ (0,f.jsxs)(`label`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-3 univer-text-sm`,children:[l.t(`sheets-pivot-ui.dateGroup.daysInterval`),/* @__PURE__ */ (0,f.jsx)(c.InputNumber,{className:`univer-w-24`,value:O,min:1,onChange:e=>k(Number(e))})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:g,onChange:e=>_(!!e),children:l.t(`sheets-pivot-ui.dateGroup.autoStart`)}),!g&&/* @__PURE__ */ (0,f.jsxs)(`label`,{className:`univer-flex univer-items-center univer-gap-2 univer-text-sm`,children:[l.t(`sheets-pivot-ui.dateGroup.start`),/* @__PURE__ */ (0,f.jsx)(c.Input,{type:`date`,value:b,onChange:x}),N&&/* @__PURE__ */ (0,f.jsx)(`input`,{className:Er,type:`time`,step:1,value:w,onChange:e=>T(e.target.value)})]}),/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:v,onChange:e=>y(!!e),children:l.t(`sheets-pivot-ui.dateGroup.autoEnd`)}),!v&&/* @__PURE__ */ (0,f.jsxs)(`label`,{className:`univer-flex univer-items-center univer-gap-2 univer-text-sm`,children:[l.t(`sheets-pivot-ui.dateGroup.end`),/* @__PURE__ */ (0,f.jsx)(c.Input,{type:`date`,value:S,onChange:C}),N&&/* @__PURE__ */ (0,f.jsx)(`input`,{className:Er,type:`time`,step:1,value:E,onChange:e=>D(e.target.value)})]})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-justify-end univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{onClick:s,children:l.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`primary`,disabled:!R||A,onClick:async()=>{if(!R||M.current)return;let e={units:wr.filter(e=>m.includes(e)),autoStart:g,autoEnd:v};!g&&I!=null&&(e.start=I),!v&&L!=null&&(e.end=L),P&&O>1&&(e.daysInterval=O),M.current=!0,j(!0);try{await o(e)}catch{}finally{M.current=!1,j(!1)}},children:l.t(`sheets-pivot-ui.dialog.ok`)})]})]})}function Or(e){let n=e.operator===t.ST_PivotFilterOperatorEnum.dateBetween||e.operator===t.ST_PivotFilterOperatorEnum.dateNotBetween,r={type:t.PivotFilterTypeEnum.CustomFilter,operator:e.operator,expected:n?[e.lower,e.upper]:e.lower,useWholeDay:e.useWholeDay};try{return(0,t.compilePivotDateFilter)(r),r}catch{return}}function kr(e,t){let n=(0,r.excelSerialToDateTimeParts)(e,{dateSystem:t});if(!n||n.day===0||n.year===1900&&n.month===2&&n.day===29)return;let i=new Date(2e3,0,1,12);return i.setFullYear(n.year,n.month-1,n.day),i}function Ar(e,t,n){let i=(0,r.excelDateTimePartsToSerial)({year:t.getFullYear(),month:t.getMonth()+1,day:t.getDate(),hours:0,minutes:0,seconds:0,fractionalSecond:0},{dateSystem:n});return i===null?void 0:i+(e===void 0?0:e-Math.floor(e))}function jr(e,t){return e===void 0||!Number.isFinite(t.getTime())?e:Math.floor(e)+(t.getHours()*3600+t.getMinutes()*60+t.getSeconds()+t.getMilliseconds()/1e3)/86400}let Mr=[{value:t.ST_PivotFilterOperatorEnum.dateEqual,label:`sheets-pivot-ui.dateFilter.equal`},{value:t.ST_PivotFilterOperatorEnum.dateNotEqual,label:`sheets-pivot-ui.dateFilter.notEqual`},{value:t.ST_PivotFilterOperatorEnum.dateNewerThan,label:`sheets-pivot-ui.dateFilter.after`},{value:t.ST_PivotFilterOperatorEnum.dateNewerThanOrEqual,label:`sheets-pivot-ui.dateFilter.afterOrEqual`},{value:t.ST_PivotFilterOperatorEnum.dateOlderThan,label:`sheets-pivot-ui.dateFilter.before`},{value:t.ST_PivotFilterOperatorEnum.dateOlderThanOrEqual,label:`sheets-pivot-ui.dateFilter.beforeOrEqual`},{value:t.ST_PivotFilterOperatorEnum.dateBetween,label:`sheets-pivot-ui.dateFilter.between`},{value:t.ST_PivotFilterOperatorEnum.dateNotBetween,label:`sheets-pivot-ui.dateFilter.notBetween`}];function Nr({dateSystem:e,defaultDate:n,currentFilter:i,onConfirm:o,onCancel:s}){let l=(0,a.useDependency)(r.LocaleService);(0,a.useObservable)(l.currentLocale$);let u=(0,a.useObservable)(l.direction$,l.getDirection()),[p,m]=(0,d.useState)((i==null?void 0:i.operator)??t.ST_PivotFilterOperatorEnum.dateEqual),h=Array.isArray(i==null?void 0:i.expected)?i.expected[0]:i==null?void 0:i.expected,g=Array.isArray(i==null?void 0:i.expected)?i.expected[1]:void 0,[_,v]=(0,d.useState)(()=>h??n??Ar(void 0,/* @__PURE__ */ new Date,e)),[y,b]=(0,d.useState)(()=>g??h??n??Ar(void 0,/* @__PURE__ */ new Date,e)),[x,S]=(0,d.useState)((i==null?void 0:i.useWholeDay)===!0),[C,w]=(0,d.useState)(!1),[T,E]=(0,d.useState)(!1),D=(0,d.useRef)(!1),O=P(_),k=P(y),A=p===t.ST_PivotFilterOperatorEnum.dateBetween||p===t.ST_PivotFilterOperatorEnum.dateNotBetween,j=Or({operator:p,lower:O,upper:k,useWholeDay:x}),M=j!==void 0&&i!==void 0&&p===i.operator&&x===(i.useWholeDay===!0)&&r.Tools.diffValue(j.expected,i.expected);async function N(e){if(!D.current){D.current=!0,w(!0),E(!1);try{await o(e)||E(!0)}catch{E(!0)}finally{D.current=!1,w(!1)}}}function P(e){return typeof e==`string`?e.trim()===``?void 0:Number(e):e}function F(e,t){t?b(e):v(e)}function I(t,n){let r=Ar(n?k:O,t,e);n?b(r):v(r)}function L(e,t){let n=t?k:O;if(n===void 0)return;let r=jr(n,e);t?b(r):v(r)}return/* @__PURE__ */ (0,f.jsxs)(`div`,{dir:u,className:`univer-flex univer-min-w-0 univer-flex-col univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-text-sm univer-font-medium`,children:l.t(`sheets-pivot-ui.dateFilter.title`)}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-1`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-xs`,children:l.t(`sheets-pivot-ui.dateFilter.rule`)}),/* @__PURE__ */ (0,f.jsx)(c.Select,{className:`univer-w-full`,value:String(p),options:Mr.map(e=>({value:String(e.value),label:l.t(e.label)})),onChange:e=>m(Number(e))})]}),(A?[!1,!0]:[!1]).map(t=>{let i=t?k:O,a=i===void 0?void 0:kr(i,e),o=(t?g:void 0)??h??n,s=o!==void 0&&!kr(o,e),u=i===void 0?null:(0,r.excelSerialToDateTimeParts)(i,{dateSystem:e}),d=u?new Date(2e3,0,1,u.hours,u.minutes,u.seconds,Math.floor(u.fractionalSecond*1e3)):void 0,p=`sheets-pivot-ui.dateFilter.date`;return A&&(p=t?`sheets-pivot-ui.dateFilter.to`:`sheets-pivot-ui.dateFilter.from`),/* @__PURE__ */ (0,f.jsxs)(`div`,{role:`group`,"aria-label":l.t(p),className:`univer-flex univer-min-w-0 univer-flex-col univer-gap-1`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-xs`,children:l.t(p)}),s?/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-1`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-xs univer-text-gray-500`,children:l.t(`sheets-pivot-ui.dateFilter.serial`)}),/* @__PURE__ */ (0,f.jsx)(c.Input,{value:String((t?y:_)??``),onChange:e=>F(e,t)})]}):/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-wrap univer-items-center univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsx)(c.DatePicker,{value:a,onValueChange:e=>I(e,t)}),!x&&i!==void 0&&/* @__PURE__ */ (0,f.jsx)(c.TimeInput,{value:d,onValueChange:e=>L(e,t)})]})]},String(t))}),/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:x,onChange:e=>S(e===!0),children:l.t(`sheets-pivot-ui.dateFilter.wholeDay`)}),T&&/* @__PURE__ */ (0,f.jsx)(`div`,{role:`alert`,className:`univer-text-xs univer-text-red-500`,children:l.t(`sheets-pivot-ui.dateFilter.failed`)}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-wrap univer-items-center univer-justify-between univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`link`,disabled:C||!i,onClick:()=>N(void 0),children:l.t(`sheets-pivot-ui.dialog.filter.clearFilter`)}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{disabled:C,onClick:s,children:l.t(`sheets-pivot-ui.dialog.filter.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`primary`,disabled:C||!j||M,onClick:()=>N(j),children:l.t(`sheets-pivot-ui.dialog.filter.confirm`)})]})]})]})}function Pr(e){let{dialogId:i=x,filterItemInfo:o,onClose:s,onSetFilter:l,onSetSort:u,onSetDateFilter:p,unitId:m,subUnitId:h}=e,{format:g,filterInfo:_,sortInfo:v}=o,y=o.conditionFilter??_,b=(0,a.useDependency)(r.ICommandService),S=(0,a.useDependency)(r.LocaleService);(0,a.useObservable)(S.currentLocale$);let C=(0,a.useDependency)(a.IDialogService),w=(0,a.useDependency)(r.IUniverInstanceService),T=(0,a.useObservable)(S.direction$,S.getDirection()),E=(0,d.useRef)(!0),[D,O]=(0,d.useState)(!1);(0,d.useEffect)(()=>(E.current=!0,()=>{E.current=!1}),[]);let[k,A]=(0,d.useState)(()=>o?o.checkedItems??(_==null?void 0:_.list)??o.items:[]),[j,M]=(0,d.useState)(()=>o.partialItems??[]),N=j.length===0&&k.length===o.items.length,P=k.length===0&&j.length===0,[F,I]=(0,d.useState)(()=>{if(o)return v==null?void 0:v.type}),L=()=>{E.current&&(E.current=!1,s?s():C.close(i))};if((0,d.useEffect)(()=>{let e=w.getCurrentUnitOfType(r.UniverInstanceType.UNIVER_SHEET);if(!e)return;let t=e.activeSheet$.subscribe(e=>{e&&e.getSheetId()!==h&&E.current&&(E.current=!1,s?s():C.close(i))});return()=>t==null?void 0:t.unsubscribe()},[i,C,s,h,w]),!o)return;let R=()=>{M([]),A(N?[]:o.items)},z=e=>{j.includes(e)?(M(j.filter(t=>t!==e)),A([...k,e])):k.includes(e)?A(k.filter(t=>t!==e)):A([...k,e])},B=async()=>{let{tableFieldId:e,pivotTableId:t}=o;if(e&&t)try{(l?await l(k,N,j):await b.executeCommand(n.SetPivotFilterCommand.id,{unitId:m,subUnitId:h,pivotTableId:t,tableFieldId:e,items:k,partialItems:j,isAll:N}))&&E.current&&L()}catch{}},V=()=>{L()},ee=async()=>{let{tableFieldId:e,pivotTableId:t}=o;if(e&&t){A(o.items),M([]);try{(l?await l(o.items,!0,[],!0):await b.executeCommand(n.SetPivotFilterCommand.id,{unitId:m,subUnitId:h,pivotTableId:t,tableFieldId:e,items:o.items,partialItems:[],isAll:!0,clearAllFilters:!0}))&&E.current&&L()}catch{}}},te=async e=>{let{tableFieldId:t,pivotTableId:r}=o;if(!t||!r)return;let i={type:e};try{(u?await u(i):await b.executeCommand(n.SetPivotSortCommand.id,{unitId:m,subUnitId:h,pivotTableId:r,tableFieldId:t,info:i}))&&E.current&&(I(e),L())}catch{}},ne=kn(_,{items:o.items,conditionFilter:o.conditionFilter});async function H(e){if(!E.current)return!1;let t=p?await p(e):await b.executeCommand(n.SetPivotDateFilterCommand.id,{unitId:m,subUnitId:h,pivotTableId:o.pivotTableId,tableFieldId:o.tableFieldId,filterInfo:e});return t&&E.current&&L(),t}if(D){let e=w.getUnit(m),n=o.itemTypes.findIndex(e=>e===t.PivotDataFieldDataTypeEnum.date),i=Number(o.items[n]);return/* @__PURE__ */ (0,f.jsx)(Nr,{dateSystem:(e==null?void 0:e.getDateSystem())??r.DateSystem.Date1900,defaultDate:Number.isFinite(i)?i:void 0,currentFilter:(0,t.isPivotDateFilter)(y)?y:void 0,onConfirm:H,onCancel:()=>O(!1)})}return/* @__PURE__ */ (0,f.jsxs)(`div`,{dir:T,children:[o.supportsDateFilter&&/* @__PURE__ */ (0,f.jsx)(c.Button,{className:`univer-mb-3 univer-w-full`,onClick:()=>O(!0),children:S.t(`sheets-pivot-ui.dateFilter.title`)}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex`,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:(0,c.clsx)(`univer-flex univer-h-8 univer-w-[140px] univer-flex-1 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-l-md univer-text-center univer-text-sm hover:univer-bg-gray-100 rtl:univer-rounded-l-none rtl:univer-rounded-r-md dark:hover:!univer-bg-gray-700`,c.borderClassName,{"univer-bg-gray-100 dark:!univer-bg-gray-700":F===t.PivotDataFieldSortOperatorEnum.ascending}),onClick:()=>te(t.PivotDataFieldSortOperatorEnum.ascending),children:[/* @__PURE__ */ (0,f.jsx)(bt,{}),S.t(`sheets-pivot-ui.dialog.filter.ascending`)]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:(0,c.clsx)(`univer-flex univer-h-8 univer-w-[140px] univer-flex-1 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-r-md univer-text-center univer-text-sm hover:univer-bg-gray-100 rtl:univer-rounded-l-md rtl:univer-rounded-r-none dark:hover:!univer-bg-gray-700`,c.borderClassName,{"univer-bg-gray-100 dark:!univer-bg-gray-700":F===t.PivotDataFieldSortOperatorEnum.descending}),onClick:()=>te(t.PivotDataFieldSortOperatorEnum.descending),children:[/* @__PURE__ */ (0,f.jsx)(Ot,{}),S.t(`sheets-pivot-ui.dialog.filter.descending`)]})]}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:(0,c.clsx)(`univer-mx-0 univer-mb-4 univer-mt-3 univer-h-[300px] univer-rounded-lg univer-p-2`,c.borderClassName),children:/* @__PURE__ */ (0,f.jsxs)(`div`,{className:(0,c.clsx)(`univer-h-full univer-overflow-y-auto`,c.scrollbarClassName),children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-1 univer-box-border univer-h-7 univer-py-[5px] univer-pl-[22px] univer-pr-1 univer-text-sm rtl:univer-pl-1 rtl:univer-pr-[22px]`,children:/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:N,onChange:R,indeterminate:!N&&(k.length>0||j.length>0),children:S.t(`sheets-pivot-ui.dialog.filter.selectAll`)})}),o.items.map((e,n)=>{var i,a;let s=e,l=(i=o.itemLabels)==null?void 0:i[e],u=(a=o.itemTypes)==null?void 0:a[n],d=en(e,u);return d?s=S.t(d):l===void 0?u===t.PivotDataFieldDataTypeEnum.date&&g&&(s=r.numfmt.format(g,Number(e))):s=l,/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-1 univer-box-border univer-h-7 univer-py-1 univer-pl-[22px] univer-pr-1 univer-text-sm rtl:univer-pl-1 rtl:univer-pr-[22px]`,children:/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:k.includes(e),indeterminate:j.includes(e),onChange:()=>z(e),contentClassName:`univer-max-w-[200px] univer-truncate`,children:s})},e)})]})}),/* @__PURE__ */ (0,f.jsxs)(c.ActionRow,{className:`univer-flex univer-items-center univer-justify-between`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-cursor-pointer univer-text-xs univer-text-primary-600`,children:/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`link`,disabled:ne===`NotFilter`,onClick:ee,children:S.t(`sheets-pivot-ui.dialog.filter.clearFilter`)})}),/* @__PURE__ */ (0,f.jsxs)(c.ActionRow,{className:`univer-flex univer-flex-1 univer-items-center univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{onClick:V,children:S.t(`sheets-pivot-ui.dialog.filter.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`primary`,disabled:P,onClick:B,children:S.t(`sheets-pivot-ui.dialog.filter.confirm`)})]})]})]})}function Fr({name:e,onConfirm:t,onCancel:n}){let i=(0,a.useDependency)(r.LocaleService),o=(0,a.useObservable)(i.direction$,i.getDirection()),[s,l]=(0,d.useState)(e),[u,p]=(0,d.useState)(!1),m=(0,d.useRef)(!1);return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,dir:o,children:[/* @__PURE__ */ (0,f.jsxs)(`label`,{className:`univer-flex univer-flex-col univer-gap-2 univer-text-sm`,children:[i.t(`sheets-pivot-ui.manualGroup.name`),/* @__PURE__ */ (0,f.jsx)(c.Input,{value:s,onChange:l})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-justify-end univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{onClick:n,children:i.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`primary`,disabled:!s.trim()||u,onClick:async()=>{if(s.trim()&&!m.current){m.current=!0,p(!0);try{await t(s)}catch{}finally{m.current=!1,p(!1)}}},children:i.t(`sheets-pivot-ui.dialog.ok`)})]})]})}let Ir=`univer-flex univer-items-center univer-justify-between univer-gap-3 univer-text-sm`;function Lr({targetFieldName:e,grouping:t,defaults$:n,onConfirm:i,onCancel:o}){let s=(0,a.useDependency)(r.LocaleService),l=(0,a.useObservable)(s.direction$,s.getDirection()),u=(0,a.useObservable)(n),[p,m]=(0,d.useState)((t==null?void 0:t.autoStart)??!0),[h,g]=(0,d.useState)((t==null?void 0:t.autoEnd)??!0),[_,v]=(0,d.useState)((t==null?void 0:t.autoStart)===!1?String(t.start):void 0),[y,b]=(0,d.useState)((t==null?void 0:t.autoEnd)===!1?String(t.end):void 0),[x,S]=(0,d.useState)(t?String(t.interval):void 0),[C,w]=(0,d.useState)(!1),T=(0,d.useRef)(!1),E=e=>e===void 0||!/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i.test(e.trim())?NaN:Number(e),D={autoStart:p,autoEnd:h,start:p?u==null?void 0:u.start:E(_),end:h?u==null?void 0:u.end:E(y),interval:x===void 0||x.trim()===``?(u==null?void 0:u.interval)??0:E(x)},O=!!u&&ce(D),k=e=>{!e&&_===void 0&&(u==null?void 0:u.start)!==void 0&&v(String(u.start)),m(e)},A=e=>{!e&&y===void 0&&(u==null?void 0:u.end)!==void 0&&b(String(u.end)),g(e)};return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,dir:l,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-text-sm univer-font-medium`,children:e}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:p,onChange:e=>k(!!e),children:s.t(`sheets-pivot-ui.numberGroup.autoStart`)}),/* @__PURE__ */ (0,f.jsxs)(`label`,{className:Ir,children:[s.t(`sheets-pivot-ui.numberGroup.start`),/* @__PURE__ */ (0,f.jsx)(c.Input,{className:`univer-w-32`,value:p?String((u==null?void 0:u.start)??``):_??``,disabled:p,onChange:v})]}),/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:h,onChange:e=>A(!!e),children:s.t(`sheets-pivot-ui.numberGroup.autoEnd`)}),/* @__PURE__ */ (0,f.jsxs)(`label`,{className:Ir,children:[s.t(`sheets-pivot-ui.numberGroup.end`),/* @__PURE__ */ (0,f.jsx)(c.Input,{className:`univer-w-32`,value:h?String((u==null?void 0:u.end)??``):y??``,disabled:h,onChange:b})]}),/* @__PURE__ */ (0,f.jsxs)(`label`,{className:Ir,children:[s.t(`sheets-pivot-ui.numberGroup.interval`),/* @__PURE__ */ (0,f.jsx)(c.Input,{className:`univer-w-32`,value:x??String((u==null?void 0:u.interval)??``),placeholder:String((u==null?void 0:u.interval)??``),onChange:S})]})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-justify-end univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{onClick:o,children:s.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`primary`,disabled:!O||C,onClick:async()=>{if(O&&!T.current){T.current=!0,w(!0);try{await i(D)}catch{}finally{T.current=!1,w(!1)}}},children:s.t(`sheets-pivot-ui.dialog.ok`)})]})]})}let Rr=({handlePatternChange:e})=>{let t=(0,a.useDependency)(r.LocaleService);return(0,d.useEffect)(()=>{e(``)},[]),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mt-1.5 univer-text-sm univer-leading-5 univer-text-gray-600 dark:!univer-text-gray-200`,children:t.t(`sheets-pivot-ui.dialog.numfmt.generalDesc`)})},zr=({originPattern:e,handlePatternChange:t})=>{let n=(0,a.useDependency)(r.LocaleService),i=r.currencySymbols.map(e=>({label:e,value:e})),[o,s]=(0,d.useState)(()=>gn(e||``,2)),[l,u]=(0,d.useState)(()=>vn(e??``)||i[0].value);return(0,d.useEffect)(()=>{t(Y(`_("${l}"* #,##0${o>0?`.0`:``}_)`,o))},[]),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mt-5`,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-between`,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-w-[136px]`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.decimalPlaces`)}),/* @__PURE__ */ (0,f.jsx)(c.InputNumber,{className:`univer-box-border univer-h-8`,value:o,max:20,min:0,onChange:e=>{let n=e??0;s(n),t(Y(`_("${l}"* #,##0${n>0?`.0`:``}_)`,n))}})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-w-[136px]`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.currencyTypes`)}),/* @__PURE__ */ (0,f.jsx)(c.Select,{options:i,value:l,onChange:e=>{u(e),t(Y(`_("${e}"* #,##0${o>0?`.0`:``}_)`,o))}})]})]}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mt-1.5 univer-text-sm univer-leading-5 univer-text-gray-600 dark:!univer-text-gray-200`,children:n.t(`sheets-pivot-ui.dialog.numfmt.accountingDesc`)})]})},Br=({originPattern:e,handlePatternChange:t})=>{let n=(0,a.useDependency)(r.LocaleService),i=r.currencySymbols.map(e=>({label:e,value:e})),[o,s]=(0,d.useState)(()=>gn(e||``,2)),[l,u]=(0,d.useState)(()=>vn(e??``)||i[0].value),p=Qt.map(e=>({label:e.label(l),value:e.suffix(l),color:e.color})),[m,h]=(0,d.useState)(()=>{var t;return((t=p.find(t=>(0,r.isPatternEqualWithoutDecimal)(t.value,e??``)))==null?void 0:t.value)||p[0].value});return(0,d.useEffect)(()=>{t(Y(m,o))},[]),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mt-5`,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-between`,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-w-[136px]`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.decimalPlaces`)}),/* @__PURE__ */ (0,f.jsx)(c.InputNumber,{className:`univer-box-border univer-h-8`,value:o,max:20,min:0,onChange:e=>{e&&(s(e),t(Y(m,e)))}})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-w-[136px]`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.currencyTypes`)}),/* @__PURE__ */ (0,f.jsx)(c.Select,{options:i,value:l,onChange:e=>{u(e);let n=Qt.map(t=>({label:t.label(e),value:t.suffix(e),color:t.color}));h(n[0].value),t(Y(n[0].value,o))}})]})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mt-4`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.negativeNumberTypes`)}),/* @__PURE__ */ (0,f.jsx)(c.SelectList,{className:`univer-rounded-lg univer-p-2`,options:p,value:m,onChange:e=>{h(e),t(Y(e,o))}}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mt-1.5 univer-text-sm univer-leading-5 univer-text-gray-600 dark:!univer-text-gray-200`,children:n.t(`sheets-pivot-ui.dialog.numfmt.currencyDesc`)})]})]})},Vr=({originPattern:e,handlePatternChange:t})=>{let n=(0,a.useDependency)(r.LocaleService),i=Xt.map(e=>({label:e.label,value:e.suffix})),[o,s]=(0,d.useState)(()=>{if(e){let t=i.find(t=>t.value===e);if(t)return t.value}return i[0].value});return(0,d.useEffect)(()=>{t(o)},[]),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mt-5`,children:/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mt-5`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.dateTypes`)}),/* @__PURE__ */ (0,f.jsx)(`div`,{children:/* @__PURE__ */ (0,f.jsx)(c.SelectList,{className:`univer-rounded-lg univer-p-2`,options:i,value:o,onChange:e=>{s(e),t(e)}})}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mt-1.5 univer-text-sm univer-leading-5 univer-text-gray-600 dark:!univer-text-gray-200`,children:n.t(`sheets-pivot-ui.dialog.numfmt.dateDesc`)})]})})},Hr=({originPattern:e,handlePatternChange:t})=>{let n=(0,a.useDependency)(r.LocaleService),[i,o]=(0,d.useState)(()=>gn(e||``,0)),s=Zt.map(e=>({label:e.label,value:e.suffix,color:e.color})),[l,u]=(0,d.useState)(()=>{let t=s.find(t=>(0,r.isPatternEqualWithoutDecimal)(t.value,e||``));return(t==null?void 0:t.value)||s[0].value});return(0,d.useEffect)(()=>{t(Y(l,Number(i||0)))},[]),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mt-5`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-items-center univer-justify-between`,children:/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-w-[136px]`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.decimalPlaces`)}),/* @__PURE__ */ (0,f.jsx)(c.InputNumber,{className:`univer-box-border univer-h-8`,value:i,max:20,min:0,onChange:e=>{e&&(o(e),t(Y(l,Number(e))))}})]})}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mt-4`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.negativeNumberTypes`)}),/* @__PURE__ */ (0,f.jsx)(c.SelectList,{className:`univer-rounded-lg univer-p-2`,options:s,value:l,onChange:e=>{o(gn(e,0)),u(e),t(e)}}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mt-1.5 univer-text-sm univer-leading-5 univer-text-gray-600 dark:!univer-text-gray-200`,children:n.t(`sheets-pivot-ui.dialog.numfmt.thousandthPercentileDesc`)})]})]})},Ur=({unitId:e,subUnitId:t,pivotTableId:n,tableFieldId:i,originPattern:o,tableFieldInfo:s,dataFieldInfo:l})=>{let u=(0,a.useDependency)(r.LocaleService),p=(0,a.useDependency)(a.IDialogService),m=u.getDirection(),h=(0,d.useMemo)(()=>[{label:`sheets-pivot-ui.dialog.numfmt.general`,component:Rr,key:`sheet.numfmt.general`},{label:`sheets-pivot-ui.dialog.numfmt.accounting`,component:zr,key:`sheet.numfmt.accounting`},{label:`sheets-pivot-ui.dialog.numfmt.currency`,component:Br,key:`sheet.numfmt.currency`},{label:`sheets-pivot-ui.dialog.numfmt.date`,component:Vr,key:`sheet.numfmt.date`},{label:`sheets-pivot-ui.dialog.numfmt.thousandthPercentile`,component:Hr,key:`sheet.numfmt.thousandthPercentile`}].map(e=>({...e,label:u.t(e.label)})),[u]),g=h.map(e=>({label:e.label,value:e.key})),[_,v]=(0,d.useState)(()=>[yn,bn,xn,Cn,Tn].reduce((e,t,n)=>e||(t(o??``)?h[n].key:``),``)||h[0].key),[y,b]=(0,d.useState)(o),x=e=>b(e),w=e=>{v(e)},E=r=>({id:C,title:{title:u.t(`sheets-pivot-ui.fieldSettings`)},draggable:!0,mask:!1,maskClosable:!1,width:400,children:{label:S,tableFieldId:i,pivotTableId:n,unitId:e,subUnitId:t,tableFieldInfo:s,dataFieldInfo:l,key:`field-setting-${i||``}`,closeFn:()=>{p.close(C)},format:r?y:``},onClose:()=>{p.close(C)}}),D=()=>{p.close(T);let e=E(!1);p.open(e)};return/* @__PURE__ */ (0,f.jsxs)(`div`,{dir:m,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex`,children:/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mb-5 univer-flex univer-h-6 univer-cursor-pointer univer-items-center univer-text-base univer-font-medium univer-leading-6`,onClick:D,children:[/* @__PURE__ */ (0,f.jsx)(vt,{}),u.t(`sheets-pivot-ui.dialog.numfmt.fieldSetting`)]})}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-h-5 univer-text-sm univer-font-medium univer-leading-5`,children:u.t(`sheets-pivot-ui.dialog.numfmt.formatTypes`)}),/* @__PURE__ */ (0,f.jsx)(`div`,{children:/* @__PURE__ */ (0,f.jsx)(c.Select,{className:`univer-w-full`,value:_,options:g,onChange:e=>w(e)})}),/* @__PURE__ */ (0,f.jsxs)(`div`,{children:[_===`sheet.numfmt.general`&&/* @__PURE__ */ (0,f.jsx)(Rr,{originPattern:o,handlePatternChange:x}),_===`sheet.numfmt.accounting`&&/* @__PURE__ */ (0,f.jsx)(zr,{originPattern:o,handlePatternChange:x}),_===`sheet.numfmt.currency`&&/* @__PURE__ */ (0,f.jsx)(Br,{originPattern:o,handlePatternChange:x}),_===`sheet.numfmt.date`&&/* @__PURE__ */ (0,f.jsx)(Vr,{originPattern:o,handlePatternChange:x}),_===`sheet.numfmt.thousandthPercentile`&&/* @__PURE__ */ (0,f.jsx)(Hr,{originPattern:o,handlePatternChange:x})]}),/* @__PURE__ */ (0,f.jsxs)(c.ActionRow,{className:`univer-mt-2 univer-flex univer-justify-end`,children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{onClick:D,children:u.t(`sheets-pivot-ui.dialog.numfmt.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{className:`univer-ml-3 rtl:univer-ml-0 rtl:univer-mr-3`,variant:`primary`,onClick:()=>{p.close(T);let e=E(!0);p.open(e)},children:u.t(`sheets-pivot-ui.dialog.numfmt.confirm`)})]})]})};function Wr(e){var o,s;let{scope:l,report:u,getCurrentReport:p,onChange:m}=e,h=(0,a.useDependency)(r.LocaleService),g=(0,a.useDependency)(r.IConfirmService),_=(0,a.useDependency)(n.SheetsPivotTableService),v=(0,a.useDependency)(r.IPermissionService),y=(0,a.useDependency)(r.ILogService);(0,a.useObservable)(v.permissionPointUpdate$);let[b,x]=(0,d.useState)(!1),S=(0,d.useRef)(!1),C=(0,d.useRef)(!0),w=JSON.stringify(l),T=(0,d.useRef)(w);T.current=w,(0,d.useEffect)(()=>(C.current=!0,()=>{C.current=!1}),[]);let E=b||!u||((o=v.getPermissionPoint(new i.WorkbookEditablePermission(l.unitId).id))==null?void 0:o.value)===!1||((s=v.getPermissionPoint(new i.WorksheetFilterPermission(l.unitId,l.subUnitId).id))==null?void 0:s.value)===!1,D=async e=>{if(S.current||E||!u||u.options.allowMultipleFilters===e)return;S.current=!0,x(!0);let i=r.Tools.deepClone(u);try{if(!e&&(0,t.hasPivotMultipleFilters)(u)){let e=await _.asyncInterceptor.fetchThroughAsyncInterceptors(n.PIVOT_OPTION_FILTER_COORDINATION)({redos:[],undos:[],groups:[],validate:()=>void 0},l);if(!C.current||T.current!==w||!await g.confirm({id:`sheet-pivot.confirm.disable-multiple-filters`,title:{title:h.t(`sheets-pivot-ui.config.multipleFiltersTitle`)},children:{title:h.t(`sheets-pivot-ui.config.multipleFiltersClearWarning`)},cancelText:h.t(`sheets-pivot-ui.dialog.cancel`),confirmText:h.t(`sheets-pivot-ui.dialog.ok`)}))return;e==null||e.validate()}if(!C.current||T.current!==w||!r.Tools.diffValue(i,p()))return;await m(e)}catch(e){y.error(`[PivotFilterOptions]`,e)}finally{S.current=!1,C.current&&x(!1)}};return/* @__PURE__ */ (0,f.jsxs)(`section`,{className:`univer-flex univer-flex-col univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-text-sm univer-font-medium univer-text-gray-600`,children:h.t(`sheets-pivot-ui.config.filteringSection`)}),/* @__PURE__ */ (0,f.jsxs)(`label`,{className:`univer-flex univer-items-start univer-gap-2 univer-text-sm`,children:[/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:(u==null?void 0:u.options.allowMultipleFilters)===!0,disabled:E,onChange:e=>D(!!e)}),/* @__PURE__ */ (0,f.jsx)(`span`,{children:h.t(`sheets-pivot-ui.config.allowMultipleFilters`)})]})]})}let Gr=[{label:`sheets-pivot-ui.config.pageDownThenOver`,value:`false`},{label:`sheets-pivot-ui.config.pageOverThenDown`,value:`true`}],Kr=[{label:`sheets-pivot-ui.config.layoutTabular`,value:String(t.PivotLayoutTypeEnum.tabular)},{label:`sheets-pivot-ui.config.layoutCompact`,value:String(t.PivotLayoutTypeEnum.compact)},{label:`sheets-pivot-ui.config.layoutOutline`,value:String(t.PivotLayoutTypeEnum.outline)}],qr=[{label:`sheets-pivot-ui.config.rowSubtotalTop`,value:String(t.PivotSubtotalPositionEnum.top)},{label:`sheets-pivot-ui.config.rowSubtotalBottom`,value:String(t.PivotSubtotalPositionEnum.bottom)}],Jr=[{label:`sheets-pivot-ui.config.dateGroupingLegacy`,value:t.PivotDateGroupingMode.Legacy},{label:`sheets-pivot-ui.config.dateGroupingExcelLike`,value:t.PivotDateGroupingMode.ExcelLike}];function Yr(e){let{unitId:i,subUnitId:o,pivotTableId:l}=e,u=(0,a.useDependency)(r.ICommandService),p=(0,a.useDependency)(r.IConfirmService),m=(0,a.useDependency)(r.ILogService),h=(0,a.useDependency)(r.LocaleService),g=(0,a.useDependency)(n.SheetsPivotTableConfigModel),_=(0,d.useMemo)(()=>g.watchPivotTableChanges(i,o,l).pipe((0,s.debounceTime)(0)),[g,i,o,l]);(0,a.useObservable)(_);let[v,y]=(0,d.useState)(!1),b=(0,d.useRef)(!1),x=g.getPivotTableConfig(i,o,l),S=(0,t.getPivotDateGroupingMode)(x==null?void 0:x.fieldsConfig.options),[C,w]=(0,d.useState)(()=>{var e,n;let r=g.getPivotTableConfig(i,o,l),a=(r==null||(e=r.fieldsConfig)==null?void 0:e.options)??{};return{showRowSubtotal:a.showRowSubtotal??!0,showRowGrandTotal:a.showRowGrandTotal??!0,showColSubtotal:a.showColSubtotal??!0,showColGrandTotal:a.showColGrandTotal??!0,pageWrap:a.pageWrap??1,pageOverThenDown:a.pageOverThenDown??!1,repeatRowLabels:a.repeatRowLabels??!1,repeatColLabels:a.repeatColLabels??!1,layout:(r==null||(n=r.fieldsConfig)==null?void 0:n.layout)??t.PivotLayoutTypeEnum.tabular,rowSubtotalPosition:a.rowSubtotalPosition??t.PivotSubtotalPositionEnum.top}}),T=e=>{let t={unitId:i,subUnitId:o,pivotTableId:l,options:e};u.executeCommand(n.SetPivotOptionCommand.id,t).catch(e=>m.error(`[PivotConfigPanel]`,e)),w(t=>({...t,...e}))},E=e=>{let t={unitId:i,subUnitId:o,pivotTableId:l,layout:e};u.executeCommand(n.SetPivotLayoutCommand.id,t).catch(e=>m.error(`[PivotConfigPanel]`,e)),w(t=>({...t,layout:e}))},D=async e=>{if(!(b.current||e===S)){b.current=!0,y(!0);try{let r=g.getPivotTableConfig(i,o,l),a=g.getCollection(i,l);if(!r||!a||(Object.values(a.fields).some(t.isDateGroupFieldJSON)||a.customFields.some(t.isDateGroupFieldJSON))&&!await p.confirm({id:`sheet-pivot.confirm.change-date-grouping-mode`,title:{title:h.t(`sheets-pivot-ui.config.dateGroupingSwitchTitle`)},children:{title:h.t(`sheets-pivot-ui.config.dateGroupingSwitchMessage`)},cancelText:h.t(`sheets-pivot-ui.dialog.cancel`),confirmText:h.t(`sheets-pivot-ui.dialog.ok`)})||g.getPivotTableConfig(i,o,l)!==r||g.getCollection(i,l)!==a||(0,t.getPivotDateGroupingMode)(r.fieldsConfig.options)===e)return;await u.executeCommand(n.SetPivotOptionCommand.id,{unitId:i,subUnitId:o,pivotTableId:l,options:{dateGroupingMode:e}})}catch(e){m.error(`[PivotConfigPanel]`,e)}finally{b.current=!1,y(!1)}}};return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-4 univer-py-4`,children:[/* @__PURE__ */ (0,f.jsx)(Wr,{scope:{unitId:i,subUnitId:o,pivotTableId:l},report:x==null?void 0:x.fieldsConfig,getCurrentReport:()=>{var e;return(e=g.getPivotTableConfig(i,o,l))==null?void 0:e.fieldsConfig},onChange:e=>u.executeCommand(n.SetPivotOptionCommand.id,{unitId:i,subUnitId:o,pivotTableId:l,options:{allowMultipleFilters:e}})}),/* @__PURE__ */ (0,f.jsxs)(`section`,{children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-600`,children:h.t(`sheets-pivot-ui.config.displaySection`)}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-sm univer-text-gray-600`,children:h.t(`sheets-pivot-ui.config.dateGroupingMode`)}),/* @__PURE__ */ (0,f.jsx)(c.Select,{className:`univer-w-36`,value:S,options:Jr.map(e=>({...e,label:h.t(e.label)})),disabled:v,onChange:e=>D(e)})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-sm univer-text-gray-600`,children:h.t(`sheets-pivot-ui.config.layout`)}),/* @__PURE__ */ (0,f.jsx)(c.Select,{className:`univer-w-36`,value:String(C.layout),options:Kr.map(e=>({...e,label:h.t(e.label)})),onChange:e=>E(Number(e))})]}),/* @__PURE__ */ (0,f.jsxs)(`label`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-text-sm univer-text-gray-600`,children:[/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:C.repeatRowLabels,disabled:C.layout===t.PivotLayoutTypeEnum.compact,onChange:e=>T({repeatRowLabels:!!e})}),h.t(`sheets-pivot-ui.config.repeatRowLabels`)]}),/* @__PURE__ */ (0,f.jsxs)(`label`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-text-sm univer-text-gray-600`,children:[/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:C.repeatColLabels,onChange:e=>T({repeatColLabels:!!e})}),h.t(`sheets-pivot-ui.config.repeatColLabels`)]})]})]}),/* @__PURE__ */ (0,f.jsxs)(`section`,{children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:(0,c.clsx)(`univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-600`),children:h.t(`sheets-pivot-ui.config.totalsSection`)}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsxs)(`label`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-text-sm univer-text-gray-600`,children:[/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:C.showRowSubtotal,onChange:e=>T({showRowSubtotal:!!e})}),h.t(`sheets-pivot-ui.config.showRowSubtotal`)]}),C.layout===t.PivotLayoutTypeEnum.outline&&/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-sm univer-text-gray-600`,children:h.t(`sheets-pivot-ui.config.rowSubtotalPosition`)}),/* @__PURE__ */ (0,f.jsx)(c.Select,{className:`univer-w-36`,value:String(C.rowSubtotalPosition),options:qr.map(e=>({...e,label:h.t(e.label)})),onChange:e=>T({rowSubtotalPosition:Number(e)})})]}),/* @__PURE__ */ (0,f.jsxs)(`label`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-text-sm univer-text-gray-600`,children:[/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:C.showRowGrandTotal,onChange:e=>T({showRowGrandTotal:!!e})}),h.t(`sheets-pivot-ui.config.showRowGrandTotal`)]}),/* @__PURE__ */ (0,f.jsxs)(`label`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-text-sm univer-text-gray-600`,children:[/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:C.showColSubtotal,onChange:e=>T({showColSubtotal:!!e})}),h.t(`sheets-pivot-ui.config.showColSubtotal`)]}),/* @__PURE__ */ (0,f.jsxs)(`label`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-text-sm univer-text-gray-600`,children:[/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{checked:C.showColGrandTotal,onChange:e=>T({showColGrandTotal:!!e})}),h.t(`sheets-pivot-ui.config.showColGrandTotal`)]})]})]}),/* @__PURE__ */ (0,f.jsxs)(`section`,{children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-600`,children:h.t(`sheets-pivot-ui.config.pageSection`)}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-sm univer-text-gray-600`,children:h.t(`sheets-pivot-ui.config.pageWrap`)}),/* @__PURE__ */ (0,f.jsx)(c.InputNumber,{className:`univer-w-24`,value:C.pageWrap,min:1,max:20,onChange:e=>{let t=Number(e);Number.isFinite(t)&&t>=1&&T({pageWrap:t})}})]}),/* @__PURE__ */ (0,f.jsx)(`p`,{className:`univer-text-xs univer-text-gray-600`,children:h.t(C.pageOverThenDown?`sheets-pivot-ui.config.pageWrapOverThenDownHelp`:`sheets-pivot-ui.config.pageWrapDownThenOverHelp`)}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-sm univer-text-gray-600`,children:h.t(`sheets-pivot-ui.config.pageDirection`)}),/* @__PURE__ */ (0,f.jsx)(c.Select,{className:`univer-w-36`,value:String(C.pageOverThenDown),options:Gr.map(e=>({...e,label:h.t(e.label)})),onChange:e=>T({pageOverThenDown:e===`true`})})]})]})]})]})}let Q=class extends r.Disposable{constructor(e,t,n,r,i,a,o,c){super(),this._sheetsSelectionsService=e,this._univerInstanceService=t,this._sheetsPivotTableAdaptorModel=n,this._commandService=r,this._sidebarService=i,this._dialogService=a,this._injector=o,this._permissionService=c,W(this,`_pivotTableId`,void 0),W(this,`_pivotTablePanelVisible$`,new s.Subject),W(this,`pivotTablePanelVisible$`,this._pivotTablePanelVisible$.asObservable()),W(this,`_isRangeSelectorFocus`,!1),W(this,`_isRangeSelector2Focus`,!1),this._initPanelOpen(),this._initSheetChange()}setIsRangeSelectorFocus(e){this._isRangeSelectorFocus=e}setIsRangeSelector2Focus(e){this._isRangeSelector2Focus=e}_setPivotTableId(e){this._pivotTableId=e}_closePivotPanel(){this._isRangeSelectorFocus||this._isRangeSelector2Focus||(this._setPivotTableId(void 0),this._sidebarService.close(y))}_initPanelOpen(){let e=this._univerInstanceService.getCurrentUnitOfType(r.UniverInstanceType.UNIVER_SHEET);if(e){let t=e.activeSheet$;this.disposeWithMe((0,s.merge)(t,this._sheetsSelectionsService.selectionMoveEnd$).subscribe(()=>{let e=this._sheetsSelectionsService.getCurrentSelections();if(!e)return;let t=e[e.length-1];if(!t)return;let a=t.primary;if(!a)return;let o=this._univerInstanceService.getCurrentUnitOfType(r.UniverInstanceType.UNIVER_SHEET),s=o==null?void 0:o.getActiveSheet();if(!o||!s)return;let c=o.getUnitId(),l=s.getSheetId(),u=this._sheetsPivotTableAdaptorModel.getPivotTableIdByCell(c,l,a.startRow,a.startColumn);if(u){var d,f;let e=(d=this._sheetsPivotTableAdaptorModel.getPivotItemRenderInfoCache(c,l,u))==null?void 0:d.rangesInfo,t=(0,n.unionPivotViewRange)(e),r=(0,i.checkRangesEditablePermission)(this._injector,c,l,t),a=(f=this._permissionService.getPermissionPoint(new i.WorksheetPivotTablePermission(c,l).id))==null?void 0:f.value;if(!r||!a)return;this._setPivotTableId(u),this._pivotTablePanelVisible$.next(!0),this._commandService.executeCommand(at.id,{pivotTableId:u})}else this._closePivotPanel()})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{e.id===n.RemovePivotTableMutation.id&&e.params.pivotTableId===this._pivotTableId&&this._sidebarService.close(y)}))}}_initSheetChange(){let e=this._univerInstanceService.getCurrentUnitOfType(r.UniverInstanceType.UNIVER_SHEET);e&&this.disposeWithMe(e.sheetDisposed$.subscribe(()=>{this._sidebarService.close()})),this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(e=>{if(e.id===`UNIVER_SHEET_PIVOT_PANEL_ID`){let t=!!e.visible;this._pivotTablePanelVisible$.next(t),t||this._dialogService.close(C)}})),this.disposeWithMe(this._dialogService.getDialogs$().subscribe(e=>{let t=e.find(e=>e.id===j);t&&t.open===!1&&this._dialogService.close(j)}))}};Q=K([G(0,(0,r.Inject)(i.SheetsSelectionsService)),G(1,(0,r.Inject)(r.IUniverInstanceService)),G(2,(0,r.Inject)(n.SheetsPivotTableAdaptorModel)),G(3,(0,r.Inject)(r.ICommandService)),G(4,(0,r.Inject)(a.ISidebarService)),G(5,(0,r.Inject)(a.IDialogService)),G(6,(0,r.Inject)(r.Injector)),G(7,(0,r.Inject)(r.IPermissionService))],Q);let Xr=(0,d.createContext)(null),Zr=(0,d.createContext)(null);function Qr(e,t){return e===t?!0:!e||!t?!1:e.droppableId===t.droppableId&&e.index===t.index}function $r(e){if(!(e instanceof Element))return null;let t=e.closest(`[data-univer-dnd-droppable-id]`);return t instanceof HTMLElement?t:null}function ei(e,t,n,r){let i=Array.from(e.querySelectorAll(`[data-univer-dnd-item="true"]`)).filter(e=>{let t=e.dataset.univerDndId;return t?t!==n.draggableId||n.source.droppableId!==r:!1});if(!i.length)return 0;for(let e=0;e<i.length-1;e++){let n=i[e].getBoundingClientRect();if(t<n.top+n.height/2)return e}let a=i.length-1,o=i[a].getBoundingClientRect();return t<o.top+o.height*.35?a:i.length}function ti(){let e=(0,d.useContext)(Xr);if(!e)throw Error(`Draggable/Droppable must be used inside DragDropContext`);return e}function ni(e){let{children:t,onDragEnd:n,onDragStart:r,onDragUpdate:i}=e,[a,o]=(0,d.useState)(null),s=(0,d.useRef)(null),c=(0,d.useCallback)((e,t)=>{let n={draggableId:e,source:t,destination:null};s.current=n,o(n),r==null||r({draggableId:e,source:t}),i==null||i({draggableId:e,source:t,destination:null})},[r,i]),l=(0,d.useCallback)(e=>{let t=s.current;if(!t||Qr(t.destination,e))return;let n={...t,destination:e};s.current=n,o(n),i==null||i({draggableId:n.draggableId,source:n.source,destination:n.destination})},[i]),u=(0,d.useCallback)(async(e,t)=>{let r=s.current;r&&(s.current=null,o(null),await(n==null?void 0:n({draggableId:r.draggableId,source:r.source,destination:t===void 0?r.destination:t,reason:e})))},[n]);(0,d.useEffect)(()=>{if(!a)return;let e=e=>{let t=$r(e.target);t&&t.dataset.univerDndDropDisabled!==`true`||l(null)};return window.addEventListener(`dragover`,e,!0),()=>{window.removeEventListener(`dragover`,e,!0)}},[a,l]);let p=(0,d.useMemo)(()=>({activeDrag:a,startDrag:c,updateDestination:l,endDrag:u}),[a,c,l,u]);return/* @__PURE__ */ (0,f.jsx)(Xr.Provider,{value:p,children:t})}function ri(e){var t;let{children:n,droppableId:r,isDropDisabled:i=!1}=e,{activeDrag:a,updateDestination:o,endDrag:s}=ti(),c=(0,d.useRef)(null),l={innerRef:(0,d.useCallback)(e=>{c.current=e},[]),droppableProps:{onDragOver:(0,d.useCallback)(e=>{if(!a||i||!c.current)return;e.preventDefault();let t=ei(c.current,e.clientY,a,r);o({droppableId:r,index:t})},[a,i,r,o]),onDrop:(0,d.useCallback)(e=>{var t;if(!a||i||!c.current)return;e.preventDefault();let n=(((t=a.destination)==null?void 0:t.droppableId)===r?a.destination:null)??{droppableId:r,index:ei(c.current,e.clientY,a,r)};return s(`DROP`,n)},[a,s,i,r]),"data-univer-dnd-droppable-id":r,"data-univer-dnd-drop-disabled":String(i)},placeholder:null},u={isDraggingOver:!!(a&&((t=a.destination)==null?void 0:t.droppableId)===r)};return/* @__PURE__ */ (0,f.jsx)(Zr.Provider,{value:r,children:n(l,u)})}function ii(e){var t;let{children:n,draggableId:r,index:i,isDragDisabled:a=!1}=e,{activeDrag:o,startDrag:s,updateDestination:c,endDrag:l}=ti(),u=(0,d.useContext)(Zr),f=(0,d.useRef)(null),p=(0,d.useRef)(null),m=(0,d.useRef)(!1),h=(0,d.useRef)(null),g=(0,d.useRef)(null),_=(0,d.useRef)(!1),v=(0,d.useRef)(null),y=(0,d.useRef)(null),b=(0,d.useRef)(null),x=(0,d.useCallback)(e=>{f.current=e},[]),S=(o==null?void 0:o.draggableId)===r,C=(0,d.useCallback)(()=>{g.current&&=(window.clearTimeout(g.current),null)},[]),w=(0,d.useCallback)(()=>{C(),b.current=null,h.current&&=(h.current(),null),v.current&&=(v.current.remove(),null),y.current=null,m.current=!1},[C]);(0,d.useEffect)(()=>w,[w]);let T=(0,d.useCallback)((e,t)=>{if(v.current)return;let n=f.current;if(!n)return;let r=n.getBoundingClientRect(),i=e>0?Math.max(0,e-r.left):12,a=t>0?Math.max(0,t-r.top):12,o=n.cloneNode(!0);if(!(o instanceof HTMLDivElement))return;let s=o;s.style.position=`fixed`,s.style.left=`0px`,s.style.top=`0px`,s.style.width=`${r.width}px`,s.style.height=`${r.height}px`,s.style.pointerEvents=`none`,s.style.opacity=`0.9`,s.style.zIndex=`2147483647`,s.style.boxSizing=`border-box`,s.style.transform=`translate(${Math.max(0,e-i)}px, ${Math.max(0,t-a)}px)`,document.body.appendChild(s),v.current=s,y.current={x:i,y:a}},[]),E=(0,d.useCallback)((e,t)=>{let n=v.current,r=y.current;n&&r&&(n.style.transform=`translate(${Math.max(0,e-r.x)}px, ${Math.max(0,t-r.y)}px)`)},[]),D=(0,d.useCallback)((e,t)=>{let n=$r(document.elementFromPoint(e,t));if(!n||n.dataset.univerDndDropDisabled===`true`)return null;let a=n.dataset.univerDndDroppableId;return a?{droppableId:a,index:ei(n,t,{draggableId:r,source:{droppableId:u??``,index:i},destination:null},a)}:null},[r,u,i]),O=(0,d.useCallback)((e,t,n,o)=>{if(m.current||_.current||a||!u)return;m.current=!0,C(),_.current=!1;try{var l;(l=f.current)==null||l.setPointerCapture(t)}catch{}T(n,o),s(r,{droppableId:u,index:i});let d=D(n,o);c(d);try{e.preventDefault()}catch{}},[C,r,u,i,a,T,D,s,c]),k=(0,d.useCallback)(e=>{if(a||!u||e.pointerType===`mouse`&&e.button!==0)return;_.current=!1;let t=e.pointerId;b.current={pointerId:t,pointerType:e.pointerType,startX:e.clientX,startY:e.clientY},C(),e.pointerType!==`mouse`&&(g.current=window.setTimeout(()=>{let n=b.current;n&&n.pointerId===t&&O(e.nativeEvent,n.pointerId,n.startX,n.startY)},150));let n=e=>{let t=b.current;if(!t||e.pointerId!==t.pointerId)return;if(!m.current){if(_.current){w();return}if(t.pointerType===`mouse`){let n=e.clientX-t.startX,r=e.clientY-t.startY;n*n+r*r>=16&&O(e,t.pointerId,e.clientX,e.clientY)}return}E(e.clientX,e.clientY);let n=D(e.clientX,e.clientY);c(n);try{e.preventDefault()}catch{}},r=e=>{let t=b.current;if(!t||e.pointerId!==t.pointerId)return;let n=m.current?D(e.clientX,e.clientY):null,r=m.current?l(n?`DROP`:`CANCEL`,n):Promise.resolve();return w(),r};window.addEventListener(`pointermove`,n,{capture:!0,passive:!1}),window.addEventListener(`pointerup`,r,{capture:!0}),window.addEventListener(`pointercancel`,r,{capture:!0}),h.current=()=>{window.removeEventListener(`pointermove`,n,!0),window.removeEventListener(`pointerup`,r,!0),window.removeEventListener(`pointercancel`,r,!0)}},[w,C,u,l,a,D,O,c,E]),A=(0,d.useCallback)(e=>{let t=e.dataTransfer;if(!t||typeof t.setDragImage!=`function`)return;let n=e.currentTarget,r=n.cloneNode(!0);if(!(r instanceof HTMLDivElement))return;let i=r;i.style.position=`fixed`,i.style.left=`-9999px`,i.style.top=`-9999px`,i.style.width=`${n.getBoundingClientRect().width}px`,i.style.pointerEvents=`none`,i.style.opacity=`0.95`,i.style.zIndex=`2147483647`,document.body.appendChild(i);let a=n.getBoundingClientRect(),o=e.clientX>0?Math.max(0,e.clientX-a.left):12,s=e.clientY>0?Math.max(0,e.clientY-a.top):12;t.setDragImage(i,o,s),p.current&&p.current!==i&&p.current.remove(),p.current=i},[]),j=(0,d.useCallback)(e=>{if(m.current||a||!u){e.preventDefault();return}_.current=!0,C(),b.current=null,h.current&&=(h.current(),null);let t=e.dataTransfer;if(t){try{t.effectAllowed=`move`}catch{}try{t.setData(`text/plain`,r)}catch{}}try{A(e)}catch{}s(r,{droppableId:u,index:i})},[A,C,r,u,i,a,s]),M=(0,d.useCallback)(()=>(p.current&&=(p.current.remove(),null),l(`CANCEL`,null)),[l]);return n({innerRef:x,draggableProps:{draggable:!a,onDragStart:j,onDragEnd:M,style:S?{opacity:1}:void 0,"data-univer-dnd-item":`true`,"data-univer-dnd-id":r,"data-univer-dnd-index":String(i)},dragHandleProps:{onPointerDown:k}},{isDragging:S,draggingOver:o==null||(t=o.destination)==null?void 0:t.droppableId})}function ai(e,t){switch(e){case`filter`:return t.t(`sheets-pivot-ui.filter`);case`row`:return t.t(`sheets-pivot-ui.row`);case`column`:return t.t(`sheets-pivot-ui.column`);case`value`:return t.t(`sheets-pivot-ui.value`)}}function oi(e){switch(e){case`filter`:return/* @__PURE__ */ (0,f.jsx)(At,{className:`univer-flex univer-flex-row univer-gap-4`});case`row`:return/* @__PURE__ */ (0,f.jsx)(Et,{className:`univer-flex univer-flex-row univer-gap-4`});case`column`:return/* @__PURE__ */ (0,f.jsx)(Wt,{className:`univer-flex univer-flex-row univer-gap-4`});case`value`:return/* @__PURE__ */ (0,f.jsx)(Mt,{className:`univer-flex univer-flex-row univer-gap-4`})}}function si(e){switch(e){case`filter`:return/* @__PURE__ */ (0,f.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`32`,height:`32`,viewBox:`0 0 32 32`,fill:`none`,children:[/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M4.99957 1.875C2.84556 1.875 1.67491 4.3932 3.06336 6.04001L11.5946 16.1587V26.4187C11.5946 27.4582 12.2298 28.3922 13.1966 28.7741L16.1601 29.9449C17.8221 30.6015 19.6232 29.3766 19.6232 27.5895V16.1587L28.1544 6.04C29.5428 4.3932 28.3722 1.875 26.2182 1.875H4.99957Z`,fill:`#ECECEC`}),/* @__PURE__ */ (0,f.jsx)(`rect`,{x:`21.9404`,y:`17.8544`,width:`7.59766`,height:`2.2793`,rx:`1.13965`,fill:`#274FEE`}),/* @__PURE__ */ (0,f.jsx)(`rect`,{x:`21.9404`,y:`21.9067`,width:`7.59766`,height:`2.2793`,rx:`1.13965`,fill:`#274FEE`}),/* @__PURE__ */ (0,f.jsx)(`rect`,{x:`21.9404`,y:`25.959`,width:`7.59766`,height:`2.2793`,rx:`1.13965`,fill:`#274FEE`})]});case`row`:return/* @__PURE__ */ (0,f.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`32`,height:`32`,viewBox:`0 0 32 32`,fill:`none`,children:[/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M2 12.3661C2 12.0347 2.26863 11.7661 2.6 11.7661H9.24705C9.57842 11.7661 9.84705 12.0347 9.84705 12.3661V29.278C9.84705 29.6093 9.57842 29.878 9.24705 29.878H4C2.89543 29.878 2 28.9825 2 27.878V12.3661Z`,fill:`#D8D8D8`}),/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M2 4.0863C2 2.98173 2.89543 2.0863 4 2.0863H9.24705C9.57842 2.0863 9.84705 2.35493 9.84705 2.6863V8.73981C9.84705 9.07118 9.57842 9.33981 9.24705 9.33981H2.6C2.26863 9.33981 2 9.07118 2 8.73981V4.0863Z`,fill:`#D8D8D8`}),/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M12.2983 12.4011C12.2982 12.0697 12.5669 11.8009 12.8983 11.8009L29.3931 11.8009C29.7243 11.8009 29.9929 12.0694 29.9931 12.4007L29.9993 27.9129C29.9997 29.0178 29.1042 29.9137 27.9993 29.9137H12.9051C12.5738 29.9137 12.3053 29.6452 12.3051 29.314L12.2983 12.4011Z`,fill:`#ECECEC`}),/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M12.2517 2.6863C12.2517 2.35493 12.5203 2.0863 12.8517 2.0863H27.9582C29.0628 2.0863 29.9582 2.98173 29.9582 4.0863V8.73627C29.9582 9.06764 29.6896 9.33627 29.3582 9.33627H12.8517C12.5203 9.33627 12.2517 9.06764 12.2517 8.73627L12.2517 2.6863Z`,fill:`#274FEE`})]});case`column`:return/* @__PURE__ */ (0,f.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`32`,height:`32`,viewBox:`0 0 32 32`,fill:`none`,children:[/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M2 12.3661C2 12.0347 2.26863 11.7661 2.6 11.7661H9.24705C9.57842 11.7661 9.84705 12.0347 9.84705 12.3661V29.278C9.84705 29.6093 9.57842 29.878 9.24705 29.878H4C2.89543 29.878 2 28.9825 2 27.878V12.3661Z`,fill:`#274FEE`}),/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M2 4.0863C2 2.98173 2.89543 2.0863 4 2.0863H9.24705C9.57842 2.0863 9.84705 2.35493 9.84705 2.6863V8.73981C9.84705 9.07118 9.57842 9.33981 9.24705 9.33981H2.6C2.26863 9.33981 2 9.07118 2 8.73981V4.0863Z`,fill:`#D8D8D8`}),/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M12.2637 2.6863C12.2637 2.35493 12.5323 2.0863 12.8637 2.0863H27.9702C29.0748 2.0863 29.9702 2.98173 29.9702 4.0863V8.73627C29.9702 9.06764 29.7016 9.33627 29.3702 9.33627H12.8637C12.5323 9.33627 12.2637 9.06764 12.2637 8.73627L12.2637 2.6863Z`,fill:`#D8D8D8`}),/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M12.2982 12.4011C12.2981 12.0697 12.5667 11.8009 12.8982 11.8009L29.3929 11.8009C29.7242 11.8009 29.9928 12.0694 29.9929 12.4007L29.9992 27.9129C29.9996 29.0178 29.104 29.9137 27.9992 29.9137H12.905C12.5737 29.9137 12.3051 29.6452 12.305 29.314L12.2982 12.4011Z`,fill:`#ECECEC`})]});case`value`:return/* @__PURE__ */ (0,f.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`32`,height:`32`,viewBox:`0 0 32 32`,fill:`none`,children:[/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M2 12.3661C2 12.0347 2.26863 11.7661 2.6 11.7661H9.24705C9.57842 11.7661 9.84705 12.0347 9.84705 12.3661V29.278C9.84705 29.6093 9.57842 29.878 9.24705 29.878H4C2.89543 29.878 2 28.9825 2 27.878V12.3661Z`,fill:`#D8D8D8`}),/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M2 4.0863C2 2.98173 2.89543 2.0863 4 2.0863H9.24705C9.57842 2.0863 9.84705 2.35493 9.84705 2.6863V8.73981C9.84705 9.07118 9.57842 9.33981 9.24705 9.33981H2.6C2.26863 9.33981 2 9.07118 2 8.73981V4.0863Z`,fill:`#D8D8D8`}),/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M12.2637 2.6863C12.2637 2.35493 12.5323 2.0863 12.8637 2.0863H27.9702C29.0748 2.0863 29.9702 2.98173 29.9702 4.0863V8.73627C29.9702 9.06764 29.7016 9.33627 29.3702 9.33627H12.8637C12.5323 9.33627 12.2637 9.06764 12.2637 8.73627L12.2637 2.6863Z`,fill:`#D8D8D8`}),/* @__PURE__ */ (0,f.jsx)(`path`,{d:`M12.2982 12.4011C12.2981 12.0697 12.5667 11.8009 12.8982 11.8009L29.3929 11.8009C29.7242 11.8009 29.9928 12.0694 29.9929 12.4007L29.9992 27.9129C29.9996 29.0178 29.104 29.9137 27.9992 29.9137H12.905C12.5737 29.9137 12.3051 29.6452 12.305 29.314L12.2982 12.4011Z`,fill:`#274FEE`})]})}}function ci(e,t){switch(e){case`filter`:return t.t(`sheets-pivot-ui.filterDesc`);case`row`:return t.t(`sheets-pivot-ui.rowDesc`);case`column`:return t.t(`sheets-pivot-ui.columnDesc`);case`value`:return t.t(`sheets-pivot-ui.valueDesc`)}}function li(e){let t=(0,a.useDependency)(r.LocaleService),{areaType:n}=e,i=ci(n,t),o=si(n);return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-h-[140px] univer-flex-col univer-items-center univer-justify-center univer-gap-1 univer-self-stretch univer-px-2`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-size-8`,children:o}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-text-center univer-text-xs univer-leading-4 univer-text-gray-600 dark:!univer-text-gray-200`,children:i})]})}function ui(e){let{areaType:t,items:n,positionInfo:i,pivotTableId:o,pivotTableInfo:s}=e,l=(0,a.useDependency)(r.LocaleService);return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-min-h-[200px] univer-flex-1 univer-p-1`,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mb-2 univer-mt-0 univer-flex univer-w-full univer-text-sm univer-leading-4 univer-text-gray-900`,children:[oi(t),/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-inline-block univer-align-top`,children:ai(t,l)})]}),/* @__PURE__ */ (0,f.jsx)(ri,{droppableId:`${t}`,isCombineEnabled:!1,isDropDisabled:!1,ignoreContainerClipping:!1,direction:`vertical`,children:(e,r)=>/* @__PURE__ */ (0,f.jsx)(`div`,{className:(0,c.clsx)(`univer-box-border univer-h-[161px] univer-w-full univer-flex-col univer-items-center univer-justify-center univer-overflow-x-hidden univer-rounded-lg univer-bg-gray-50 univer-py-2 dark:!univer-bg-gray-900`,c.borderClassName,{"univer-border-primary-600":r.isDraggingOver}),children:/* @__PURE__ */ (0,f.jsx)(`div`,{className:(0,c.clsx)(`univer-h-full univer-overflow-y-auto`,c.scrollbarClassName),children:/* @__PURE__ */ (0,f.jsxs)(`div`,{ref:e.innerRef,className:`univer-box-border univer-h-full univer-px-2`,...e.droppableProps,children:[n.length>0&&n.map((e,n)=>/* @__PURE__ */ (0,f.jsx)(`div`,{children:/* @__PURE__ */ (0,f.jsx)(ii,{isDragDisabled:!1,draggableId:e.tableFieldId,index:n,children:(n,r)=>/* @__PURE__ */ (0,f.jsx)(f.Fragment,{children:/* @__PURE__ */ (0,f.jsx)(`div`,{ref:n.innerRef,...n.draggableProps,...n.dragHandleProps,style:n.draggableProps.style,className:(0,c.clsx)(`univer-flex univer-items-center univer-gap-1 univer-self-stretch univer-border univer-border-transparent univer-p-0.5 univer-leading-4 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700`,r.draggingOver&&`univer-border-primary-600`),children:/* @__PURE__ */ (0,f.jsx)(di,{pivotTableId:o,positionInfo:i,item:e,areaType:t,pivotTableInfo:s})})})},e.tableFieldId)},e.tableFieldId)),n.length===0&&/* @__PURE__ */ (0,f.jsx)(li,{areaType:t})]})})})})]})}function di(e){let{areaType:n,item:i,positionInfo:o,pivotTableId:s,pivotTableInfo:l}=e,{unitId:u,subUnitId:d}=o,p=i.tableFieldId===$t,m=(0,a.useDependency)(r.ICommandService),h=(0,a.useDependency)(r.LocaleService),g=()=>{if(p){let e=(l.valueFields||[]).map(e=>e.tableFieldId);un({pivotTableId:s,unitId:u,subUnitId:d,commandService:m},e)}else un({pivotTableId:s,unitId:u,subUnitId:d,commandService:m},[i.tableFieldId])},_=()=>{u&&d&&pn(m,u,d,s,i.tableFieldId)},v=()=>{u&&d&&mn(m,s,i.tableFieldId,u,d,l)},y=e=>{let n=e===`column`?t.PivotTableValuePositionEnum.Row:t.PivotTableValuePositionEnum.Column,r=e===`column`?l.rowFields.length:l.columnFields.length;dn({pivotTableId:s,unitId:u,subUnitId:d,commandService:m},n,r)},b=/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-inline-flex univer-flex-col univer-rounded-lg univer-border univer-border-gray-200 univer-bg-gray-0 univer-p-2 univer-shadow-lg`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-self-stretch univer-px-2 univer-py-1.5 univer-text-sm univer-leading-5 univer-text-gray-900 dark:!univer-text-gray-0`,onClick:()=>{g()},children:h.t(`sheets-pivot-ui.removeField`)}),n!==`value`&&!p&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-self-stretch univer-px-2 univer-py-1.5 univer-text-sm univer-leading-5 univer-text-gray-900 dark:!univer-text-gray-0`,onClick:()=>{_()},children:h.t(`sheets-pivot-ui.filterField`)}),p&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-self-stretch univer-px-2 univer-py-1.5 univer-text-sm univer-leading-5 univer-text-gray-900 dark:!univer-text-gray-0`,onClick:()=>{y(n)},children:n===`column`?h.t(`sheets-pivot-ui.moveToRow`):h.t(`sheets-pivot-ui.moveToColumn`)}),n===`value`&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-self-stretch univer-px-2 univer-py-1.5 univer-text-sm univer-leading-5 univer-text-gray-900 dark:!univer-text-gray-0`,onClick:()=>{v()},children:h.t(`sheets-pivot-ui.fieldSettings`)})]}),x=p?h.t(`sheets-pivot-ui.multipleValue`):i.displayName,S=/* @__PURE__ */ (0,f.jsx)(`bdi`,{dir:`auto`,children:x});return/* @__PURE__ */ (0,f.jsxs)(f.Fragment,{children:[/* @__PURE__ */ (0,f.jsx)(Pt,{}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-max-w-[66px] univer-flex-1 univer-shrink-0 univer-truncate univer-text-xs univer-leading-4 univer-text-gray-800 dark:!univer-text-gray-100`,children:/* @__PURE__ */ (0,f.jsx)(c.Tooltip,{title:S,children:S})}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-cursor-pointer`,children:/* @__PURE__ */ (0,f.jsx)(c.Dropdown,{align:`end`,overlay:b,children:/* @__PURE__ */ (0,f.jsx)(`span`,{children:/* @__PURE__ */ (0,f.jsx)(Rt,{})})})})]})}function fi(e){var t;let n=(0,a.useDependency)(r.IUniverInstanceService),i=(0,a.useDependency)(r.LocaleService),o=(0,a.useDependency)(r.ICommandService),s=(0,a.useDependency)(Q),{sourceRangeInfo:c,refreshHandler:l,pivotTableId:u,positionInfo:h}=e,{unitId:g,range:_,subUnitId:v}=c,y=n.getUnit(g),b=(y==null||(t=y.getSheetBySheetId(v))==null?void 0:t.getName())??``,[x,S]=(0,d.useState)(void 0),C=(0,d.useRef)(x);C.current=x;let[w,T]=(0,d.useState)(_),[E,D]=(0,d.useState)(b),[O,k]=(0,d.useState)(!1);(0,d.useEffect)(()=>{s.setIsRangeSelectorFocus(O)},[O,s]),(0,d.useEffect)(()=>{T(c.range),D(b)},[c,b]);let A=(0,d.useMemo)(()=>(0,r.debounce)(async e=>{let t=e.split(`,`).filter(e=>!!e).map(p.deserializeRangeWithSheet);if(!t[0])return;let n=t[0];if(!y||C.current)return;let r=n.sheetName||c.sheetName;T(n.range),D(r);let i={unitId:g,subUnitId:y.getSheetBySheetName(r).getSheetId(),range:{...n.range},sheetName:r};await sn(o,u,i,h.unitId,h.subUnitId),l()},300,{leading:!1,maxWait:1e3,trailing:!0}),[]);return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mb-4`,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mb-2 univer-flex univer-h-5 univer-justify-between univer-text-sm univer-leading-5`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-justify univer-text-gray-900 dark:!univer-text-gray-0`,children:i.t(`sheets-pivot-ui.sourceRangeLabel`)}),/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-xs univer-text-gray-600 dark:!univer-text-gray-200`,children:i.t(`sheets-pivot-ui.sourceRangePlaceholder`)})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-relative`,children:[/* @__PURE__ */ (0,f.jsx)(m.RangeSelector,{unitId:g,subUnitId:v,initialValue:(0,p.serializeRangeWithSheet)(E,w),onChange:(e,t)=>{(0,p.serializeRangeWithSheet)(E,w)!==t&&A(t)},keepSheetReference:!0,supportAcrossSheet:!0,onVerify:(e,t)=>{let n=t.split(`,`).filter(e=>!!e);if(!n[0]){S(i.t(`sheets-pivot-ui.msg.emptySourceRange`));return}if(!e){S(i.t(`sheets-pivot-ui.msg.invalidSize`));return}let r=(0,p.deserializeRangeWithSheet)(n[0]),a=r.sheetName||c.sheetName;if(y)switch(an(y.getSheetBySheetName(a),r.range)){case 2:S(void 0);break;case 0:S(i.t(`sheets-pivot-ui.msg.emptySourceRange`));break;case 1:S(i.t(`sheets-pivot-ui.msg.invalidSize`))}},maxRangeCount:1,onFocusChange:e=>{k(e)},onRangeSelectorDialogVisibleChange:e=>{k(!!e)}}),x?/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-my-1 univer-text-xs univer-text-red-500`,children:x}):null]})]})}function pi(e){let{type:n}=e;switch(n){case t.PivotDataFieldDataTypeEnum.text:return/* @__PURE__ */ (0,f.jsx)(Jt,{className:`univer-mx-1.5 univer-my-0 univer-h-4 univer-text-xs univer-text-gray-200 dark:!univer-text-gray-600`});case t.PivotDataFieldDataTypeEnum.number:return/* @__PURE__ */ (0,f.jsx)(Bt,{className:`univer-mx-1.5 univer-my-0 univer-h-4 univer-text-xs univer-text-gray-200 dark:!univer-text-gray-600`});case t.PivotDataFieldDataTypeEnum.date:return/* @__PURE__ */ (0,f.jsx)(St,{className:`univer-mx-1.5 univer-my-0 univer-h-4 univer-text-xs univer-text-gray-200 dark:!univer-text-gray-600`})}}function mi(e){if(!e)return!1;if(e.type===t.PivotFilterTypeEnum.RecordFilter){var n;return e.dateRange!==void 0||(((n=e.selection)==null?void 0:n.mode)??r.FilterSelectionMode.All)!==r.FilterSelectionMode.All}return e.type!==t.PivotFilterTypeEnum.ManualFilter||e.isAll!==!0}function hi(e){let{name:i,dataFieldId:o,checked:s,type:l,refreshHandler:u,pivotTableId:p,draggingId:m,pivotTableInfo:h,unitId:g,subUnitId:_}=e,[v,y]=(0,d.useState)(!1),b=(0,a.useDependency)(r.ICommandService),x=(0,a.useDependency)(r.LocaleService);if(!h)return null;let{rowFields:S,columnFields:C,filterFields:w,valueFields:T}=h,E=h.hiddenFields??[],D=[...S,...C,...w,...T,...E],O=E.find(e=>e.dataFieldId===o),k=async e=>{let r=!!e,i=!1;if(r){let e={pivotTableId:p,dataFieldId:o,fieldArea:l===t.PivotDataFieldDataTypeEnum.number?t.PivotTableFiledAreaEnum.Value:t.PivotTableFiledAreaEnum.Row,unitId:g,subUnitId:_,index:l===t.PivotDataFieldDataTypeEnum.number?T.length:S.length};i=await b.executeCommand(n.AddPivotFieldCommand.id,e)}else{let e=[];D.forEach(t=>{t.dataFieldId===o&&e.push(t.tableFieldId)}),i=await b.executeCommand(n.RemovePivotFieldCommand.id,{pivotTableId:p,fieldIds:e,unitId:g,subUnitId:_})}i&&u()},A=async e=>{let r=!1,i=``;if([...S,...C,...w,...E].forEach(e=>{e.dataFieldId===o&&(r=!0,i=e.tableFieldId)}),r&&e!==t.PivotTableFiledAreaEnum.Value){if(p){let t=En(h,e),r={pivotTableId:p,area:e,index:t,fieldId:i,unitId:g,subUnitId:_};await b.executeCommand(n.MovePivotFieldCommand.id,r)&&u()}}else if(p){let t={pivotTableId:p,dataFieldId:o,fieldArea:e,unitId:g,subUnitId:_,index:En(h,e)};await b.executeCommand(n.AddPivotFieldCommand.id,t)&&u()}};return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:(0,c.clsx)(`univer-group univer-relative univer-box-border univer-flex univer-h-8 univer-w-full univer-flex-row univer-items-center univer-rounded-md univer-px-1 univer-py-2 univer-leading-4 univer-transition-all hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700`,{"univer-flex univer-bg-gray-100 dark:!univer-bg-gray-700":m===o}),id:`source-${o}`,onContextMenu:e=>{e.preventDefault(),y(!0)},children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-mr-2 univer-w-4 rtl:univer-ml-2 rtl:univer-mr-0`,children:/* @__PURE__ */ (0,f.jsx)(Pt,{})}),/* @__PURE__ */ (0,f.jsx)(c.Checkbox,{className:`univer-w-[14px] univer-text-sm univer-text-gray-200`,checked:s,onChange:k}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-min-w-0 univer-flex-1 univer-items-center univer-text-xs univer-leading-4 univer-text-gray-900 dark:!univer-text-gray-0`,children:[/* @__PURE__ */ (0,f.jsx)(pi,{type:l}),/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-truncate`,children:i})]}),/* @__PURE__ */ (0,f.jsx)(c.Dropdown,{align:`end`,side:`bottom`,open:v,onOpenChange:y,overlay:/* @__PURE__ */ (0,f.jsxs)(`div`,{children:[mi(O==null?void 0:O.filterInfo)&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-self-stretch univer-px-2 univer-py-1.5 univer-text-sm univer-leading-5 univer-text-gray-900 hover:univer-bg-gray-100 dark:!univer-text-gray-0 dark:hover:!univer-bg-gray-700`,onClick:async()=>{O&&(y(!1),await b.executeCommand(n.SetPivotFilterCommand.id,{unitId:g,subUnitId:_,pivotTableId:p,tableFieldId:O.tableFieldId,items:[],partialItems:[],isAll:!0})&&u())},children:x.t(`sheets-pivot-ui.dialog.filter.clearFilter`)}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-self-stretch univer-px-2 univer-py-1.5 univer-text-sm univer-leading-5 univer-text-gray-900 hover:univer-bg-gray-100 dark:!univer-text-gray-0 dark:hover:!univer-bg-gray-700`,onClick:()=>{y(!1),A(t.PivotTableFiledAreaEnum.Row)},children:x.t(`sheets-pivot-ui.addToRow`)}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-self-stretch univer-px-2 univer-py-1.5 univer-text-sm univer-leading-5 univer-text-gray-900 hover:univer-bg-gray-100 dark:!univer-text-gray-0 dark:hover:!univer-bg-gray-700`,onClick:()=>{y(!1),A(t.PivotTableFiledAreaEnum.Column)},children:x.t(`sheets-pivot-ui.addToColumn`)}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-self-stretch univer-px-2 univer-py-1.5 univer-text-sm univer-leading-5 univer-text-gray-900 hover:univer-bg-gray-100 dark:!univer-text-gray-0 dark:hover:!univer-bg-gray-700`,onClick:()=>{y(!1),A(t.PivotTableFiledAreaEnum.Value)},children:x.t(`sheets-pivot-ui.addToValue`)}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-self-stretch univer-px-2 univer-py-1.5 univer-text-sm univer-leading-5 univer-text-gray-900 hover:univer-bg-gray-100 dark:!univer-text-gray-0 dark:hover:!univer-bg-gray-700`,onClick:()=>{y(!1),A(t.PivotTableFiledAreaEnum.Filter)},children:x.t(`sheets-pivot-ui.addToFilter`)})]}),children:/* @__PURE__ */ (0,f.jsx)(`div`,{className:(0,c.clsx)(`univer-ml-1 univer-flex univer-size-5 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-md univer-transition-opacity hover:univer-bg-gray-200 rtl:univer-ml-0 rtl:univer-mr-1 dark:hover:!univer-bg-gray-700`,{"univer-opacity-100":v,"univer-opacity-0 group-hover:univer-opacity-100":!v}),onMouseDown:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),children:/* @__PURE__ */ (0,f.jsx)(It,{className:`univer-text-gray-400 dark:!univer-text-gray-500`})})})]},o)}function gi(e){let{sourceList:t,refreshHandler:n,pivotTableId:i,pivotTableInfo:o,unitId:s,draggingId:l,subUnitId:u}=e,p=(0,a.useDependency)(r.LocaleService),[m,h]=(0,d.useState)(``),g=m.trim().toLocaleLowerCase(),_=g?t.filter(e=>e.name.toLocaleLowerCase().includes(g)):t;return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mb-4 univer-flex univer-min-h-0 univer-flex-1 univer-flex-col`,children:[/* @__PURE__ */ (0,f.jsx)(`p`,{className:`univer-mb-1 univer-mt-0 univer-text-sm univer-font-medium univer-leading-5 univer-text-gray-900 dark:!univer-text-gray-0`,children:p.t(`sheets-pivot-ui.sourceFieldTile`)}),/* @__PURE__ */ (0,f.jsx)(`p`,{className:`univer-mb-2 univer-mt-0 univer-text-xs univer-leading-4 univer-text-gray-600 dark:!univer-text-gray-200`,children:p.t(`sheets-pivot-ui.sourceFieldDescription`)}),/* @__PURE__ */ (0,f.jsx)(c.Input,{allowClear:!0,className:`univer-mb-2`,placeholder:p.t(`sheets-pivot-ui.searchFieldPlaceholder`),slot:/* @__PURE__ */ (0,f.jsx)(Kt,{}),value:m,onChange:h}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:(0,c.clsx)(`univer-box-border univer-min-h-0 univer-flex-1 univer-rounded-lg univer-bg-gray-0 univer-p-2 dark:!univer-bg-gray-900`,c.borderClassName),children:/* @__PURE__ */ (0,f.jsx)(`div`,{className:(0,c.clsx)(`univer-relative univer-h-full univer-overflow-y-auto`,c.scrollbarClassName),"data-testid":`pivot-source-field-viewport`,children:/* @__PURE__ */ (0,f.jsx)(ri,{droppableId:`source`,direction:`vertical`,isCombineEnabled:!1,ignoreContainerClipping:!1,isDropDisabled:!0,children:e=>/* @__PURE__ */ (0,f.jsxs)(`div`,{ref:e.innerRef,className:`univer-box-border univer-h-full univer-px-2`,...e.droppableProps,children:[_.map((e,t)=>/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-relative univer-flex univer-h-8 univer-w-full univer-items-center univer-gap-1 univer-self-stretch univer-border univer-border-transparent univer-p-0.5 univer-leading-4 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700`,children:/* @__PURE__ */ (0,f.jsx)(ii,{draggableId:e.id,isDragDisabled:!1,index:t,children:({innerRef:t,draggableProps:r,dragHandleProps:a})=>/* @__PURE__ */ (0,f.jsx)(`div`,{ref:t,...r,...a,className:`univer-h-8 univer-w-full`,style:r.style,children:/* @__PURE__ */ (0,f.jsx)(hi,{draggingId:l,unitId:s,subUnitId:u,...e,refreshHandler:n,pivotTableId:i,pivotTableInfo:o})})},e.id)},e.id)),_.length===0&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-py-4 univer-text-center univer-text-xs univer-text-gray-500`,children:p.t(`sheets-pivot-ui.noMatchingFields`)})]})})})})]})}function _i(e){let{pivotTableId:t,version:i,unitId:o,subUnitId:l,panelInfo:u}=e,p=(0,a.useDependency)(n.SheetsPivotTableConfigModel),m=(0,d.useMemo)(()=>p.watchPivotTableChanges(o,l,t).pipe((0,s.debounceTime)(0)),[p,o,l,t]),h=(0,a.useObservable)(m),g=(0,a.useDependency)(n.SheetsPivotRPCService),_=(0,a.useDependency)(Q),v=(0,a.useObservable)(_.pivotTablePanelVisible$,!0),y=(0,a.useDependency)(r.ICommandService),b=(0,a.useDependency)(r.ILogService),[x,S]=(0,d.useState)(u),[C,w]=(0,d.useState)(null),T=(0,d.useCallback)(async()=>{if(!p.getPivotTableConfig(o,l,t))return;let e=await g.getPivotDisplayConfig({unitId:o,subUnitId:l,pivotTableId:t,params:{type:n.PivotDisplayDataType.Panel,panel:{pivotTableId:t}}});e.result.panel&&S(e.result.panel)},[t,g,p,l,o]);(0,d.useEffect)(()=>{T().catch(e=>b.error(`[PivotPanel]`,e))},[b,h,t,T,i]);let E=async e=>{let{source:n,destination:r,draggableId:i}=e;w(null);let a={pivotTableInfo:x,pivotTableId:t,commandService:y,unitId:o,subUnitId:l},s=n.droppableId;if(r&&r.droppableId){let e=r.droppableId;await ln(a,i,s,e,r.index),await T()}r===null&&(await on(a,i,s),await T())},D=e=>{w({draggingId:e.draggableId})},O=e=>{let{draggableId:t,destination:n,source:r}=e;w({draggingId:t,destination:n,source:r})};if(!v||!x)return null;let{sourceList:k,rowFields:A,columnFields:j,filterFields:M,valueFields:N,sourceRange:P,positionInfo:F}=x;return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:(0,c.clsx)(`univer-mt-4 univer-flex univer-h-[calc(100%-16px)] univer-min-h-0 univer-w-full univer-flex-col univer-overflow-y-auto univer-overflow-x-hidden`,c.scrollbarClassName),children:[/* @__PURE__ */ (0,f.jsx)(fi,{sourceRangeInfo:P,pivotTableId:t,refreshHandler:T,positionInfo:F}),/* @__PURE__ */ (0,f.jsxs)(ni,{onDragEnd:E,onDragStart:D,onDragUpdate:O,children:[/* @__PURE__ */ (0,f.jsx)(gi,{draggingId:(C==null?void 0:C.draggingId)??``,sourceList:k,refreshHandler:T,pivotTableId:t,pivotTableInfo:x,unitId:o,subUnitId:l}),/* @__PURE__ */ (0,f.jsx)(vi,{rowFields:A,columnFields:j,filterFields:M,valueFields:N,refreshHandler:T,positionInfo:F,pivotTableId:t,pivotTableInfo:x})]})]})}function vi(e){let{rowFields:t,columnFields:n,filterFields:r,valueFields:i,refreshHandler:a,pivotTableInfo:o,positionInfo:s,pivotTableId:c}=e;return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-shrink-0`,"data-testid":`pivot-field-areas`,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-row univer-gap-4`,children:[/* @__PURE__ */ (0,f.jsx)(ui,{areaType:`filter`,items:r,positionInfo:s,pivotTableId:c,pivotTableInfo:o,refreshHandler:a}),/* @__PURE__ */ (0,f.jsx)(ui,{areaType:`column`,items:n,positionInfo:s,pivotTableId:c,pivotTableInfo:o,refreshHandler:a})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-row univer-gap-4`,children:[/* @__PURE__ */ (0,f.jsx)(ui,{areaType:`row`,items:t,positionInfo:s,pivotTableId:c,pivotTableInfo:o,refreshHandler:a}),/* @__PURE__ */ (0,f.jsx)(ui,{areaType:`value`,items:i,positionInfo:s,pivotTableId:c,pivotTableInfo:o,refreshHandler:a})]})]})}function yi(e){let{className:t,unitId:n,subUnitId:i,pivotTableId:o}=e,[s,l]=(0,d.useState)(0),u=(0,a.useDependency)(r.LocaleService),p=u.getDirection();return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:(0,c.clsx)(`univer-flex univer-size-full univer-min-h-0 univer-flex-col`,t),dir:p,children:[/* @__PURE__ */ (0,f.jsx)(c.Segmented,{className:`univer-my-3 univer-w-full univer-shrink-0`,items:[{label:u.t(`sheets-pivot-ui.fieldPanel`),value:0},{label:u.t(`sheets-pivot-ui.configPanel`),value:1}],value:s,onChange:l}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:(0,c.clsx)(`univer-min-h-0 univer-flex-1`,s===0?`univer-overflow-hidden`:`univer-overflow-auto`),children:s===0?/* @__PURE__ */ (0,f.jsx)(_i,{...e}):/* @__PURE__ */ (0,f.jsx)(Yr,{unitId:n,subUnitId:i,pivotTableId:o})})]})}function bi(e){let{unitId:t,subUnitId:n,pivotTableId:r,tableFieldId:i,type:a}=e,o=JSON.stringify([t,n,r,i,a]);return/* @__PURE__ */ (0,f.jsx)(xi,{...e},o)}function xi({unitId:e,subUnitId:i,pivotTableId:o,tableFieldId:s,type:l,baseItems:u,onConfirm:p,onCancel:m}){var h;let g=(0,a.useDependency)(n.SheetsPivotTableConfigModel),_=(0,a.useDependency)(r.LocaleService),v=(0,a.useObservable)(_.direction$,_.getDirection()),y=fe.find(e=>e.type===l),b=g.getPivotTableConfig(e,i,o),x=b==null||(h=b.fieldsConfig.measure[s])==null?void 0:h.showDataAs,S=()=>{var e;if((x==null?void 0:x.type)!==l||!x.baseFieldId)return``;if(x.baseItemType===t.PivotShowAsBaseItemTypeEnum.previous)return`relative:previous`;if(x.baseItemType===t.PivotShowAsBaseItemTypeEnum.next)return`relative:next`;let n=((e=u[x.baseFieldId])==null?void 0:e.items.indexOf(x.baseItem))??-1;return n<0?``:`item:${n}`},[C,w]=(0,d.useState)((x==null?void 0:x.type)===l?x.baseFieldId:``),[T,E]=(0,d.useState)(S),D=(0,d.useRef)(!1),[O,k]=(0,d.useState)(!1),A=g.getPivotTableConfig(e,i,o),j=g.getCollection(e,o),M=A==null?void 0:A.fieldsConfig.measure[s],N=!!(M&&j&&(j.fields[M.dataFieldId]||j.customFields.find(e=>e.id===M.dataFieldId))),P=(A&&j&&y?me(A,j,y):[]).filter(e=>{let t=u[e];return(y==null?void 0:y.baseItemMode)===`none`||!!(t&&((y==null?void 0:y.baseItemMode)===`item-or-relative`||t.items.length>0))}),F=P.map(e=>({label:A.fieldsConfig.dimension[e].displayName,value:e})),I=A==null?void 0:A.fieldsConfig.dimension[C],L=I&&j&&(j.fields[I.dataFieldId]??j.customFields.find(e=>e.id===I.dataFieldId)),R=u[C],z=(R==null?void 0:R.items.map((e,n)=>{var i;let a=R.itemTypes[n],o=(i=R.itemLabels)==null?void 0:i[e],s=en(e,a),c=e;return s?c=_.t(s):o===void 0?a===t.PivotDataFieldDataTypeEnum.other?c=_.t(`sheets-pivot-ui.showValuesAs.other`):(a===t.PivotDataFieldDataTypeEnum.date||a===t.PivotDataFieldDataTypeEnum.number)&&R.format&&(c=r.numfmt.format(R.format,Number(e))):c=o,{label:c,value:`item:${n}`,itemKey:e}}))??[];(y==null?void 0:y.baseItemMode)===`item-or-relative`&&z.push({label:_.t(`sheets-pivot-ui.showValuesAs.previous`),value:`relative:previous`,itemKey:``,itemType:t.PivotShowAsBaseItemTypeEnum.previous},{label:_.t(`sheets-pivot-ui.showValuesAs.next`),value:`relative:next`,itemKey:``,itemType:t.PivotShowAsBaseItemTypeEnum.next});let B=z.find(e=>e.value===T),V=!!(y!=null&&y.baseItemMode&&y.baseItemMode!==`none`),ee=!!(y&&A&&j&&N&&A.fieldsConfig.valueFields.includes(s)&&P.includes(C)&&L&&(!V||B));return/* @__PURE__ */ (0,f.jsxs)(`div`,{dir:v,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mb-4`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:_.t(`sheets-pivot-ui.showValuesAs.baseField`)}),/* @__PURE__ */ (0,f.jsx)(c.Select,{className:`univer-w-full`,value:C,options:F,onChange:e=>{w(e),E(``)}})]}),V&&/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-mb-4`,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:_.t(`sheets-pivot-ui.showValuesAs.baseItem`)}),/* @__PURE__ */ (0,f.jsx)(c.Select,{className:`univer-w-full`,value:T,options:z,disabled:!C,onChange:E})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-justify-end univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{onClick:m,children:_.t(`sheets-pivot-ui.showValuesAs.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`primary`,disabled:!ee||O,onClick:async()=>{let t=g.getPivotTableConfig(e,i,o),n=g.getCollection(e,o),r=t==null?void 0:t.fieldsConfig.measure[s];if(!y||!t||!n||!r||D.current||!t.fieldsConfig.valueFields.includes(s)||!(n.fields[r.dataFieldId]||n.customFields.find(e=>e.id===r.dataFieldId))||!me(t,n,y).includes(C)||V&&!B)return;let a={type:l,baseFieldId:C,baseItem:(B==null?void 0:B.itemKey)??``};(B==null?void 0:B.itemType)!==void 0&&(a.baseItemType=B.itemType),D.current=!0,k(!0);try{await p(a)}catch{}finally{D.current=!1,k(!1)}},children:_.t(`sheets-pivot-ui.showValuesAs.ok`)})]})]})}let Si=e=>{let[t,n]=(0,d.useState)(!1),r=(0,a.useDependency)(Q);return(0,d.useEffect)(()=>{r.setIsRangeSelector2Focus(t)},[t,r]),/* @__PURE__ */ (0,f.jsx)(m.RangeSelector,{...e,onFocusChange:t=>{var r;(r=e.onFocusChange)==null||r.call(e,t),n(t)}})},Ci=(e,t,n,r,i,a)=>/* @__PURE__ */ (0,f.jsx)(Si,{unitId:e,subUnitId:t,initialValue:r,onChange:(e,t)=>n(t),maxRangeCount:1,supportAcrossSheet:!0,keepSheetReference:!0}),wi=(e,t)=>{switch(e){case 1:return t.t(`sheets-pivot-ui.msg.invalidSize`);case 0:return t.t(`sheets-pivot-ui.msg.emptySourceRange`);default:return``}};function Ti(e){let{unitId:t,sourceRange:i,positionRange:o,sourceSheetName:s,positionSheetName:l,onConfirm:u,onCancel:m}=e,h=(0,a.useDependency)(r.LocaleService),g=(0,a.useDependency)(r.IUniverInstanceService),_=h.getDirection(),v=g.getUnit(t),y=(0,d.useMemo)(()=>v.getActiveSheet().getSheetId(),[v]),[b,x]=(0,d.useState)(i),[S,C]=(0,d.useState)(o),[w,T]=(0,d.useState)(s),[E,D]=(0,d.useState)(l),O=(0,d.useRef)(void 0),[k,A]=(0,d.useState)(),[j,M]=(0,d.useState)(n.PositionType.New),[N,P]=(0,d.useState)(!0),[F,I]=(0,d.useState)(!0),[L,R]=(0,d.useState)(void 0);(0,d.useEffect)(()=>{let e=an(v.getSheetBySheetName(w),b);I(e===2),R(wi(e,h))},[b,w,v,h]);let z=e=>{if((0,p.serializeRangeWithSheet)(w,b)===e)return;let t=e.split(`,`).filter(e=>!!e).map(p.deserializeRangeWithSheet);if(Array.isArray(t)&&t.length>0){let{range:e,sheetName:n}=t[0];x(e),T(n)}t[0]||R(h.t(`sheets-pivot-ui.msg.emptySourceRange`))},B=Ci(t,y,e=>{if(S&&(0,p.serializeRangeWithSheet)(E,S)===e)return;let t=e.split(`,`).filter(e=>!!e).map(p.deserializeRangeWithSheet);if(t.length===0){C(null);return}let n=t[0];C(n.range),D(n.sheetName||s),n.sheetName===s&&r.Rectangle.intersects(n.range,b)?P(!1):P(!0)},S?(0,p.serializeRangeWithSheet)(E,S):``,!1,k),V=()=>!!(b&&S&&w&&E&&j===n.PositionType.Existing&&N&&F)||!!(b&&w&&j===n.PositionType.New&&F);return(0,d.useEffect)(()=>{A(O.current)},[]),/* @__PURE__ */ (0,f.jsxs)(`div`,{ref:O,dir:_,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-h-5 univer-text-sm univer-font-medium`,children:h.t(`sheets-pivot-ui.dialog.source.sourceData`)}),Ci(t,y,z,(0,p.serializeRangeWithSheet)(w,b),!0,k),L&&/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mt-2 univer-h-5 univer-text-xs univer-text-red-400`,children:L}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-mb-2 univer-mt-5 univer-h-5 univer-text-sm univer-font-medium`,children:h.t(`sheets-pivot-ui.dialog.source.position`)}),/* @__PURE__ */ (0,f.jsxs)(c.RadioGroup,{value:j,onChange:e=>M(e),className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsx)(c.Radio,{value:n.PositionType.New,children:h.t(`sheets-pivot-ui.dialog.source.newSheet`)}),/* @__PURE__ */ (0,f.jsx)(c.Radio,{value:n.PositionType.Existing,children:h.t(`sheets-pivot-ui.dialog.source.existingSheet`)})]}),j===n.PositionType.Existing&&/* @__PURE__ */ (0,f.jsxs)(f.Fragment,{children:[B,!N&&/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-h-5 univer-text-sm univer-text-red-400`,children:h.t(`sheets-pivot-ui.dialog.source.intersect`)})]}),/* @__PURE__ */ (0,f.jsx)(`footer`,{className:`univer-mt-5`,children:/* @__PURE__ */ (0,f.jsxs)(c.ActionRow,{className:`univer-flex univer-justify-end univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{onClick:()=>m(),children:h.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`primary`,onClick:()=>{V()&&(j===n.PositionType.Existing?u({sourceRange:b,sourceSheetName:w,positionRange:S,positionSheetName:E,positionType:j}):u({sourceRange:b,sourceSheetName:w,positionType:j}))},children:h.t(`sheets-pivot-ui.dialog.ok`)})]})})]})}Ti.componentKey=j;let Ei=[{id:`equal`,localeKey:`sheets-pivot-ui.valueFilter.equal`,operator:t.ST_PivotFilterOperatorEnum.valueEqual},{id:`notEqual`,localeKey:`sheets-pivot-ui.valueFilter.notEqual`,operator:t.ST_PivotFilterOperatorEnum.valueNotEqual},{id:`greaterThan`,localeKey:`sheets-pivot-ui.valueFilter.greaterThan`,operator:t.ST_PivotFilterOperatorEnum.valueGreaterThan},{id:`greaterThanOrEqual`,localeKey:`sheets-pivot-ui.valueFilter.greaterThanOrEqual`,operator:t.ST_PivotFilterOperatorEnum.valueGreaterThanOrEqual},{id:`lessThan`,localeKey:`sheets-pivot-ui.valueFilter.lessThan`,operator:t.ST_PivotFilterOperatorEnum.valueLessThan},{id:`lessThanOrEqual`,localeKey:`sheets-pivot-ui.valueFilter.lessThanOrEqual`,operator:t.ST_PivotFilterOperatorEnum.valueLessThanOrEqual},{id:`between`,localeKey:`sheets-pivot-ui.valueFilter.between`,operator:t.ST_PivotFilterOperatorEnum.valueBetween,isBetween:!0},{id:`notBetween`,localeKey:`sheets-pivot-ui.valueFilter.notBetween`,operator:t.ST_PivotFilterOperatorEnum.valueNotBetween,isBetween:!0},{id:`topCount`,localeKey:`sheets-pivot-ui.valueFilter.topCount`,operator:t.ST_PivotFilterOperatorEnum.count,isCount:!0},{id:`bottomCount`,localeKey:`sheets-pivot-ui.valueFilter.bottomCount`,operator:t.ST_PivotFilterOperatorEnum.count,isBottom:!0,isCount:!0},{id:`topPercent`,localeKey:`sheets-pivot-ui.valueFilter.topPercent`,operator:t.ST_PivotFilterOperatorEnum.percent,isPercent:!0},{id:`bottomPercent`,localeKey:`sheets-pivot-ui.valueFilter.bottomPercent`,operator:t.ST_PivotFilterOperatorEnum.percent,isBottom:!0,isPercent:!0}];function Di({targetFieldId:e,targetFieldName:n,valueFields:i,defaultValueFieldId:o,currentFilter:s,onConfirm:l,onClear:u,onCancel:p}){function m(e){var n;return(e==null?void 0:e.operator)===t.ST_PivotFilterOperatorEnum.count?e.isBottom?`bottomCount`:`topCount`:(e==null?void 0:e.operator)===t.ST_PivotFilterOperatorEnum.percent?e.isBottom?`bottomPercent`:`topPercent`:((n=Ei.find(t=>t.operator===(e==null?void 0:e.operator)))==null?void 0:n.id)??`greaterThan`}let h=(0,a.useDependency)(r.LocaleService),g=(0,a.useObservable)(h.direction$,h.getDirection()),_=s==null?void 0:s.expected,[v,y]=(0,d.useState)(()=>{let e=s==null?void 0:s.valueFieldId;return e&&i.some(t=>t.id===e)?e:o&&i.some(e=>e.id===o)?o:i.length===1?i[0].id:``}),[b,x]=(0,d.useState)(()=>m(s)),[S,C]=(0,d.useState)(()=>String(Array.isArray(_)?_[0]:_??0)),[w,T]=(0,d.useState)(()=>String(Array.isArray(_)?_[1]:0)),E=(0,d.useRef)(!1),[D,O]=(0,d.useState)(!1),k=Ei.find(e=>e.id===b),A=S.trim()!==``&&Number.isFinite(Number(S)),j=!k.isBetween||w.trim()!==``&&Number.isFinite(Number(w)),M=!k.isCount||Number.isInteger(Number(S))&&Number(S)>=1,N=!k.isPercent||Number(S)>=0&&Number(S)<=100,P=!!(i.some(e=>e.id===v)&&A&&j&&M&&N),F=async e=>{if(!E.current){E.current=!0,O(!0);try{await e()}catch{}finally{E.current=!1,O(!1)}}},I=()=>F(async()=>{if(!P)return;let e={operator:k.operator,expected:k.isBetween?[Number(S),Number(w)]:Number(S),valueFieldId:v};k.isBottom&&(e.isBottom=!0),await l(e)}),L=()=>F(u);return/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,"data-target-field-id":e,dir:g,children:[/* @__PURE__ */ (0,f.jsx)(`div`,{className:`univer-text-sm univer-font-medium`,children:/* @__PURE__ */ (0,f.jsx)(`bdi`,{dir:`auto`,children:n})}),/* @__PURE__ */ (0,f.jsxs)(`label`,{className:`univer-flex univer-flex-col univer-gap-2 univer-text-sm`,children:[h.t(`sheets-pivot-ui.valueFilter.valueField`),/* @__PURE__ */ (0,f.jsx)(c.Select,{"aria-label":h.t(`sheets-pivot-ui.valueFilter.valueField`),"data-testid":`pivot-value-filter-value-field`,value:v,options:[{value:``,label:h.t(`sheets-pivot-ui.valueFilter.selectValueField`)},...i.map(e=>({value:e.id,label:e.label}))],onChange:y})]}),/* @__PURE__ */ (0,f.jsxs)(`label`,{className:`univer-flex univer-flex-col univer-gap-2 univer-text-sm`,children:[h.t(`sheets-pivot-ui.valueFilter.condition`),/* @__PURE__ */ (0,f.jsx)(c.Select,{"aria-label":h.t(`sheets-pivot-ui.valueFilter.condition`),"data-testid":`pivot-value-filter-rule`,value:b,options:Ei.map(e=>({value:e.id,label:h.t(e.localeKey)})),onChange:e=>x(e)})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-gap-2`,children:[/* @__PURE__ */ (0,f.jsx)(c.Input,{"aria-label":h.t(`sheets-pivot-ui.valueFilter.condition`),"aria-invalid":!A||!M||!N,className:`univer-min-w-0 univer-flex-1`,"data-testid":`pivot-value-filter-expected`,inputMode:`decimal`,value:S,onChange:C}),k.isBetween&&/* @__PURE__ */ (0,f.jsx)(c.Input,{"aria-label":h.t(`sheets-pivot-ui.valueFilter.condition`),"aria-invalid":!j,className:`univer-min-w-0 univer-flex-1`,"data-testid":`pivot-value-filter-expected`,inputMode:`decimal`,value:w,onChange:T})]}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{"data-testid":`pivot-value-filter-clear`,disabled:D,onClick:L,children:h.t(`sheets-pivot-ui.valueFilter.clear`)}),/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-gap-3`,children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{disabled:D,onClick:p,children:h.t(`sheets-pivot-ui.valueFilter.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{"data-testid":`pivot-value-filter-confirm`,variant:`primary`,disabled:!P||D,onClick:I,children:h.t(`sheets-pivot-ui.valueFilter.ok`)})]})]})]})}function Oi(e){let{pivotTableId:t,tableFieldId:i,closeFn:o,unitId:s,subUnitId:l,format:u,tableFieldInfo:p,dataFieldInfo:m,version:h}=e,[g,_]=(0,d.useState)(p.displayName),[v,y]=(0,d.useState)(p.subTotalType),b=(0,a.useDependency)(r.LocaleService),x=(0,a.useDependency)(r.ICommandService),S=(0,a.useDependency)(a.IDialogService),T={...(0,a.useDependency)(n.SheetsPivotTableConfigModel).getTextInfo()};for(let e of[`sheets-pivot-ui.averageName`,`sheets-pivot-ui.countName`,`sheets-pivot-ui.countNumsName`,`sheets-pivot-ui.maxName`,`sheets-pivot-ui.minName`,`sheets-pivot-ui.productName`,`sheets-pivot-ui.stdDevName`,`sheets-pivot-ui.stdDevpName`,`sheets-pivot-ui.sumName`,`sheets-pivot-ui.varName`,`sheets-pivot-ui.varpName`])T[e]=b.t(e);if((0,d.useEffect)(()=>{_(p.displayName),y(p.subTotalType)},[h]),!p||!m)return;let E=m.name,D=b.getDirection(),O=u??p.format,k=hn.map(e=>({value:`${e.type}`,type:e.type,label:b.t(e.textKey)})),A=e=>{let t=e;if(Array.isArray(e)&&(t=e[0]),t!==void 0){let e=Number(t);y(e),Dn(E,g,T)&&_(On(E,T,e))}};return/* @__PURE__ */ (0,f.jsxs)(`div`,{dir:D,children:[/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-self-stretch univer-leading-5`,children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-sm univer-font-medium univer-leading-5 univer-text-gray-900`,children:b.t(`sheets-pivot-ui.dialog.fieldName`)}),/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-text-xs univer-leading-4 univer-text-gray-600`,children:tn(b.t(`sheets-pivot-ui.dialog.sourceName`),E)})]}),/* @__PURE__ */ (0,f.jsx)(`div`,{children:/* @__PURE__ */ (0,f.jsx)(c.Input,{className:`univer-mb-5 univer-mt-2 univer-box-border univer-h-8 univer-w-full univer-rounded-md univer-py-1.5 univer-text-sm univer-leading-5`,value:g,onChange:e=>_(e)})}),/* @__PURE__ */ (0,f.jsx)(`label`,{className:`univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-gray-0`,children:b.t(`sheets-pivot-ui.dialog.summarizeBy`)}),/* @__PURE__ */ (0,f.jsx)(`div`,{className:(0,c.clsx)(`univer-h-40 univer-flex-1 univer-overflow-y-auto univer-rounded-lg`,c.borderClassName,c.scrollbarClassName),children:k.map(e=>/* @__PURE__ */ (0,f.jsxs)(`div`,{className:`univer-flex univer-items-center univer-gap-1.5 univer-self-stretch univer-rounded-md univer-px-2 univer-py-1.5 univer-text-sm univer-capitalize univer-leading-5`,onClick:()=>A(e.value),children:[/* @__PURE__ */ (0,f.jsx)(`span`,{className:`univer-w-4 univer-text-base univer-text-primary-600`,children:/* @__PURE__ */ (0,f.jsx)(wt,{className:(0,c.clsx)({"univer-hidden":v!==e.type})})}),/* @__PURE__ */ (0,f.jsx)(`span`,{children:e.label})]},e.type))}),/* @__PURE__ */ (0,f.jsx)(`footer`,{className:`univer-mt-5`,children:/* @__PURE__ */ (0,f.jsxs)(c.ActionRow,{className:`univer-flex univer-items-center univer-justify-between univer-self-stretch`,children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{className:`univer-flex univer-h-8 univer-cursor-pointer univer-items-center univer-justify-center univer-gap-1.5 univer-rounded univer-border-none univer-bg-gray-0 univer-px-3 univer-text-primary-600`,onClick:()=>{let e={id:C,draggable:!0,mask:!1,maskClosable:!1,width:400,children:{label:w,unitId:s,subUnitId:l,pivotTableId:t,tableFieldId:i,originPattern:O,tableFieldInfo:p,dataFieldInfo:m},dialogStyles:{header:{padding:`20px 24px 0`,height:0},body:{padding:`0 24px 20px`}},closable:!1,onClose:()=>{S.close(C)}};S.open(e)},children:b.t(`sheets-pivot-ui.dialog.format`)}),/* @__PURE__ */ (0,f.jsxs)(c.ActionRow,{className:`univer-flex univer-flex-1 univer-gap-2 univer-text-sm rtl:univer-flex-row-reverse`,children:[/* @__PURE__ */ (0,f.jsx)(c.Button,{onClick:()=>{o&&o()},children:b.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ (0,f.jsx)(c.Button,{variant:`primary`,disabled:g===``,onClick:()=>{let e=p.displayName,r=p.subTotalType,a=p.format,c=e===g?void 0:g,u=r===v?void 0:v,d=a===O?void 0:O;if(e!==g||r!==v||a!==d){let e={displayName:c,subtotalType:u,format:d,tableFieldId:i,pivotTableId:t,unitId:s,subUnitId:l,tableFieldInfo:p,dataFieldInfo:m};x.executeCommand(n.UpdatePivotFieldSettingCommand.id,e)}o&&o()},children:b.t(`sheets-pivot-ui.dialog.ok`)})]})]})})]})}let ki=class extends r.Disposable{constructor(e,t){super(),this._componentManager=e,this._iconManager=t,this._registerComponents(),this._registerIcons()}_registerComponents(){[[j,Ti],[v,yi],[b,Pr],[S,Oi],[w,Ur],[E,bi],[D,Di],[O,Dr],[k,Lr],[A,Fr]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_registerIcons(){this.disposeWithMe(this._iconManager.register({PivotTableIcon:Ht}))}};ki=K([G(0,(0,r.Inject)(a.ComponentManager)),G(1,(0,r.Inject)(a.IconManager))],ki);let Ai=class extends r.Disposable{constructor(e){super(),this._menuManagerService=e,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu($e)}};Ai=K([G(0,a.IMenuManagerService)],Ai);let ji=class extends r.Disposable{constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._context=e,this._injector=t,this._sheetsPivotTableAdaptorModel=n,this._sheetSkeletonManagerService=r,this._sheetsPivotTableConfigModel=i,this._commandService=a,this._sheetPermissionCheckController=o,this._permissionService=s,this._localeService=c,this._selectionsService=l,this._cellAlerts=u,W(this,`_pivotButtonShapesArr`,[]),this._initButtonRender(),this._initSkeleton(),this._initListener(),this._initBlockedPivotAlert()}_initBlockedPivotAlert(){let e=`SHEET_PIVOT_BLOCKED:${this._context.unitId}`;this.disposeWithMe((0,s.merge)(this._selectionsService.selectionChanged$,this._context.unit.activeSheet$,this._sheetsPivotTableAdaptorModel.viewUpdate$).pipe((0,s.auditTime)(0)).subscribe(()=>{var t,n,r;let{unitId:i,unit:a}=this._context,s=this._selectionsService.currentSelectionParam,c=(t=a.getActiveSheet())==null?void 0:t.getSheetId(),l=(n=this._selectionsService.getCurrentSelections())==null||(n=n.slice(-1)[0])==null?void 0:n.primary;if(!c||!l||(s==null?void 0:s.unitId)!==i||s.sheetId!==c){this._cellAlerts.removeAlert(e);return}let{actualRow:u,actualColumn:d}=l,f=this._sheetsPivotTableAdaptorModel,m=f.getPivotTableIdByCell(i,c,u,d),h=m&&((r=f.getPivotItemRenderInfoCache(i,c,m))==null?void 0:r.blockedRange);if(!h){this._cellAlerts.removeAlert(e);return}let g=`sheets-pivot-ui.perform.blocked`;h.reason===`pivot`?g=`sheets-pivot-ui.perform.blockedByPivot`:h.reason===`merge`&&(g=`sheets-pivot-ui.perform.blockedByMerge`),this._cellAlerts.showAlert({key:e,type:o.CellAlertType.ERROR,title:this._localeService.t(`sheets-pivot-ui.perform.tips`),message:this._localeService.t(g,(0,p.serializeRange)(h)),location:{unitId:i,subUnitId:c,row:u,col:d},width:260,height:96})})),this.disposeWithMe(()=>this._cellAlerts.removeAlert(e))}_initButtonRender(){this.disposeWithMe((0,s.merge)(this._sheetsPivotTableAdaptorModel.viewUpdate$.pipe((0,s.auditTime)(0)),this._sheetSkeletonManagerService.currentSkeleton$,this._sheetsPivotTableConfigModel.pivotConfigChange$,this._permissionService.permissionPointUpdate$.pipe((0,s.auditTime)(100))).subscribe(()=>{if(!this._context.unit)return;let e=this._context.unitId,t=this._context.unit.getActiveSheet().getSheetId(),{scene:n}=this._context,r=this._localeService.getDirection(),a=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!a)return;let s=this._pivotButtonShapesArr;s.forEach(e=>e.dispose()),s.splice(0,s.length),this._sheetsPivotTableAdaptorModel.getSubUnitPivotMatrix(e,t).forValue((c,l,u)=>{if(u!=null&&u.pbt){let d=`sheets-pivot-button-${c}-${l}-${e}-${t}`,{startX:f,startY:p,endX:m,endY:h}=(0,o.getCoordByCell)(c,l,n,a),g=m-f,_=h-p;if(_<8||g<8||this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[i.WorkbookEditablePermission],worksheetTypes:[i.WorksheetViewPermission,i.WorksheetEditPermission,i.WorksheetPivotTablePermission],rangeTypes:[i.RangeProtectionPermissionViewPoint,i.RangeProtectionPermissionEditPoint]},[{startRow:c,endRow:c,startColumn:l,endColumn:l}],e,t)===!1)return;let v;if(ur.has(u.pbt)){let{left:n,top:i}=mr(r,`filter`,{startX:f,startY:p,endX:m,endY:h});v={left:n,top:i,height:16,width:16,zIndex:5e3,cellWidth:g,cellHeight:_,pivotParams:{col:l,row:c,unitId:e,subUnitId:t,buttonType:u.pbt}}}else if(dr.has(u.pbt)){let{left:n,top:i}=mr(r,`collapse`,{startX:f,startY:p,endX:m,endY:h});v={left:n,top:i,height:16,width:16,zIndex:5e3,cellWidth:g,cellHeight:_,pivotParams:{col:l,row:c,unitId:e,subUnitId:t,buttonType:u.pbt}}}else return;let y=this._injector.createInstance(fr,d,v);s.push(y)}}),s.length&&n.addObjects(s),n.makeDirty()}))}_initSkeleton(){var e;this.disposeWithMe(this._sheetsPivotTableAdaptorModel.markDirty$.subscribe(({unitId:e,subUnitId:t})=>{if(e===this._context.unitId&&(this._sheetSkeletonManagerService.makeDirty({sheetId:t}),this._context.unit.getActiveSheet().getSheetId()===t)){var n;this._sheetSkeletonManagerService.reCalculate(),(n=this._context.mainComponent)==null||n.makeDirty()}}));let t=this._context.unitId;this._context.unit.getSheets().forEach(e=>{var n;let r=e.getSheetId();(n=this._sheetsPivotTableAdaptorModel.getSubUnitPivotRenderCache(t,r))!=null&&n.size&&this._sheetSkeletonManagerService.makeDirty({sheetId:r})}),this._sheetSkeletonManagerService.reCalculate(),(e=this._context.mainComponent)==null||e.makeDirty()}_initListener(){let e=new r.DisposableCollection,{spreadsheet:t}=(0,o.getSheetObject)(this._context.unit,this._context);e.add(t.onDblclick$.subscribeEvent(e=>{if(e.button===2)return;let t=this._sheetSkeletonManagerService.getCurrentSkeleton();if(t==null)return;let r=this._context.scene,{row:i,column:a}=(0,o.getCoordByOffset)(e.offsetX,e.offsetY,r,t);this._commandService.executeCommand(n.PivotDrillDownCommand.id,{row:i,col:a})}))}};ji=K([G(1,(0,r.Inject)(r.Injector)),G(2,(0,r.Inject)(n.SheetsPivotTableAdaptorModel)),G(3,(0,r.Inject)(o.SheetSkeletonManagerService)),G(4,(0,r.Inject)(n.SheetsPivotTableConfigModel)),G(5,(0,r.Inject)(r.ICommandService)),G(6,(0,r.Inject)(i.SheetPermissionCheckController)),G(7,(0,r.Inject)(r.IPermissionService)),G(8,(0,r.Inject)(r.LocaleService)),G(9,(0,r.Inject)(i.SheetsSelectionsService)),G(10,(0,r.Inject)(o.CellAlertManagerService))],ji);var Mi=class e extends u.Shape{constructor(e){super(`SHEET_PIVOT_MOVE_KEY`),W(this,`_moveType`,void 0),this._moveType=e}_draw(t){this.width!==0&&this.height!==0&&e.drawWith(t,this)}static drawWith(e,t){let n=t._moveType;if(e.save(),e.strokeStyle=`#8bc34a`,e.lineWidth=2,n===`row`){let n=t.width;if(!n)return;e.beginPath(),e.moveTo(0,0),e.lineTo(0+n,0),e.moveTo(0,-10),e.lineTo(0,10),e.moveTo(0+n,-10),e.lineTo(0+n,10)}else{let n=t.height;if(!n)return;e.moveTo(0,0),e.lineTo(0,0+n),e.moveTo(-10,0),e.lineTo(10,0),e.moveTo(-10,0+n),e.lineTo(10,0+n)}e.stroke(),e.restore()}};let Ni=class extends r.Disposable{constructor(e,t,n,r,i,a){super(),this._context=e,this._sheetsPivotTableAdaptorModel=t,this._sheetSkeletonManagerService=n,this._commandService=r,this._selectionRenderService=i,this._sheetsSelectionsService=a,W(this,`_pivotSelectionMoveShape`,void 0),W(this,`_scenePointerMoveSubscribe`,void 0),W(this,`_scenePointerUpSubscribe`,void 0),W(this,`_selectionControl`,void 0),W(this,`_moveStartRange`,void 0),W(this,`_moveStartCellIndex`,void 0),W(this,`_moveRowOrCol`,`row`),W(this,`_targetRange`,void 0),W(this,`_movePivotId`,void 0),this._initControl()}_controlMoving(e,t){let n=this._context.scene,r=n.getScrollXYInfoByViewport(u.Vector2.FromArray([e,t])),{scaleX:i,scaleY:a}=n.getAncestorScale(),o=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!o||!this._moveStartRange||!this._moveStartCellIndex)return;let{row:s,column:c}=o.getCellIndexByOffset(e,t,i,a,r);if(this._moveRowOrCol===`row`){var l;let e=0,t=0,n=this._moveStartRange.endColumn-this._moveStartRange.startColumn+1;if(this._moveStartCellIndex.column===this._moveStartRange.startColumn)e=c,t=c+n-1;else if(this._moveStartCellIndex.column===this._moveStartRange.endColumn)t=c,e=c-n+1;else{let r=this._moveStartCellIndex.column-this._moveStartRange.startColumn;e=c-r,t=c-r+n-1}let r=o.getCellWithCoordByIndex(s,e),i=o.getCellWithCoordByIndex(s,t),{startX:a,endY:u}=r,{endX:d}=i;this._targetRange={startRow:s,endRow:s,startColumn:e,endColumn:t},(l=this._pivotSelectionMoveShape)==null||l.transformByState({left:a,top:u,width:d-a,height:20})}else{var d;let e=0,t=0,n=this._moveStartRange.endRow-this._moveStartRange.startRow+1;if(this._moveStartCellIndex.row===this._moveStartRange.startRow)e=s,t=s+n-1;else if(this._moveStartCellIndex.row===this._moveStartRange.endRow)t=s,e=s-n+1;else{let r=this._moveStartCellIndex.row-this._moveStartRange.startRow;e=s-r,t=s-r+n-1}let r=o.getCellWithCoordByIndex(e,c),i=o.getCellWithCoordByIndex(t,c),{startX:a,startY:l}=r,{endY:u}=i;this._targetRange={startColumn:c,endColumn:c,startRow:e,endRow:t},(d=this._pivotSelectionMoveShape)==null||d.transformByState({left:a,top:l,width:20,height:u-l})}}_controlPointerDownHandler(e){var t,n,i;(t=this._selectionControl)==null||t.setControlExtensionDisable(!1),this._context.scene.setCursor(u.CURSOR_TYPE.DEFAULT);let a=this._sheetsSelectionsService.getCurrentSelections();if(!a.length||a.length>1)return;let o=a[0].range,s=this._context.unit,c=s.getActiveSheet(),l=s.getUnitId(),d=c.getSheetId(),f=this._sheetsPivotTableAdaptorModel.getSubUnitPivotRenderCache(l,d);if(!(f!=null&&f.size))return;let p=Array.from(f).find(([e,t])=>{let{rangesInfo:n}=t;if(!n)return!1;let{rowRanges:i,colRanges:a}=n,s=i[0],c=a[0],l=!1;return s&&(l=r.Rectangle.realContain(s,o),this._moveRowOrCol=`row`),!l&&c&&(l=r.Rectangle.realContain(c,o),this._moveRowOrCol=`col`),l});if(!p)return;this._movePivotId=p[0],this._pivotSelectionMoveShape||(this._pivotSelectionMoveShape=new Mi(this._moveRowOrCol),this._context.scene.addObject(this._pivotSelectionMoveShape));let m=this._context.scene,h=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!h)return;let{offsetX:g,offsetY:_}=e,v=m.getCoordRelativeToViewport(u.Vector2.FromArray([g,_])),{x:y,y:b}=v,x=m.getScrollXYInfoByViewport(v),{scaleX:S,scaleY:C}=m.getAncestorScale(),{row:w,column:T}=h.getCellIndexByOffset(y,b,S,C,x),E=(n=this._selectionControl)==null?void 0:n.model.getRange();if(this._moveStartRange=E,!E)return;let D=0;D=w<E.startRow?E.startRow:w>E.endRow?E.endRow:w;let O=0;O=T<E.startColumn?E.startColumn:T>E.endColumn?E.endColumn:T,this._moveStartCellIndex={row:D,column:O},(i=this._selectionControl)==null||i.setControlExtensionDisable(!0),this._scenePointerMoveSubscribe=m.onPointerMove$.subscribeEvent(e=>{let{offsetX:t,offsetY:n}=e,{x:r,y:i}=m.getCoordRelativeToViewport(u.Vector2.FromArray([t,n]));this._controlMoving(r,i),m.setCursor(u.CURSOR_TYPE.MOVE)}),this._scenePointerUpSubscribe=m.onPointerUp$.subscribeEvent(e=>{var t,n,r;(t=this._scenePointerMoveSubscribe)==null||t.unsubscribe(),this._scenePointerMoveSubscribe=null,(n=this._selectionControl)==null||n.setControlExtensionDisable(!1),this._selectionControl=null,m.setCursor(u.CURSOR_TYPE.DEFAULT),m.removeObject(this._pivotSelectionMoveShape),this._pivotSelectionMoveShape=null,this._updatePivotSort(),(r=this._scenePointerUpSubscribe)==null||r.unsubscribe(),this._scenePointerUpSubscribe=null})}_updatePivotSort(){if(!this._moveStartRange||!this._targetRange||!this._movePivotId)return;let e=this._context.unit.getUnitId(),r=this._context.unit.getActiveSheet().getSheetId();if(this._moveRowOrCol===`row`){var i;let o=(i=this._sheetsPivotTableAdaptorModel.getSubUnitPivotRenderCache(e,r))==null?void 0:i.get(this._movePivotId);if(!o)return;let s=this._sheetsPivotTableAdaptorModel.getSubUnitPivotMatrix(e,r);if(!s)return;let c=[],l=``,{headerMap:u,rangesInfo:d}=o;for(let e=this._moveStartRange.startColumn;e<=this._moveStartRange.endColumn;e++){var a;let n=u==null||(a=u.rowHeaderMap)==null?void 0:a[e];if(!n)continue;l=n.tableFieldId;let r=d==null?void 0:d.rowRanges,i=r==null?void 0:r[0];if(!i)continue;let o={...i,startColumn:e,endColumn:e};for(let n=o.startRow;n<=o.endRow;n++){let r=s.getValue(n,e);if(!r)continue;let{v:i,pbt:a}=r;i&&a!==t.PivotCellStyleTypeEnum.Subtotal&&a!==t.PivotCellStyleTypeEnum.GrandTotal&&(typeof i==`string`?c[n]=i:typeof i==`number`&&(c[n]=i.toString()))}break}if(!l)return;let f=this._moveStartRange.startRow,p=this._moveStartRange.endRow-this._moveStartRange.startRow+1,m=this._targetRange.startRow;if(f<m){let e=c.splice(f,p);c.splice(m-p,0,...e)}else{let e=c.splice(f,p);c.splice(m,0,...e)}let h=c.filter(e=>e!==void 0);this._commandService.executeCommand(n.SetPivotSortCommand.id,{unitId:e,subUnitId:r,pivotTableId:this._movePivotId,tableFieldId:l,info:{type:t.PivotDataFieldSortOperatorEnum.custom,customOrder:h}})}else{var o;let i=(o=this._sheetsPivotTableAdaptorModel.getSubUnitPivotRenderCache(e,r))==null?void 0:o.get(this._movePivotId);if(!i)return;let a=this._sheetsPivotTableAdaptorModel.getSubUnitPivotMatrix(e,r);if(!a)return;let c=[],l=``,{headerMap:u,rangesInfo:d}=i;for(let e=this._moveStartRange.startRow;e<=this._moveStartRange.endRow;e++){var s;let r=u==null||(s=u.colHeaderMap)==null?void 0:s[e];if(!r)continue;l=r.tableFieldId;let o=d==null?void 0:d.colRanges,f=o==null?void 0:o[0];if(!f)continue;let p={...f,startRow:e,endRow:e};for(let r=p.startColumn;r<=p.endColumn;r++){let o=a.getValue(e,r);if(!o)continue;let{v:s,pbt:l}=o;if(s&&l!==t.PivotCellStyleTypeEnum.Subtotal&&l!==t.PivotCellStyleTypeEnum.GrandTotal){if(typeof s==`string`){let e=i.projection?(0,n.mapPivotSheetColumn)(i.projection,r):r;c[e]=s}else if(typeof s==`number`){let e=i.projection?(0,n.mapPivotSheetColumn)(i.projection,r):r;c[e]=s.toString()}}}break}if(!l)return;let f=i.projection?(0,n.mapPivotSheetRange)(i.projection,this._moveStartRange):this._moveStartRange,p=i.projection?(0,n.mapPivotSheetRange)(i.projection,this._targetRange):this._targetRange,m=f.startColumn,h=this._moveStartRange.endColumn-this._moveStartRange.startColumn+1,g=p.startColumn;if(m<g){let e=c.splice(m,h);c.splice(g-h,0,...e)}else{let e=c.splice(m,h);c.splice(g,0,...e)}let _=c.filter(e=>e!==void 0);this._commandService.executeCommand(n.SetPivotSortCommand.id,{unitId:e,subUnitId:r,pivotTableId:this._movePivotId,tableFieldId:l,info:{type:t.PivotDataFieldSortOperatorEnum.custom,customOrder:_}})}}_initControl(){this.disposeWithMe(this._sheetsSelectionsService.selectionMoveEnd$.subscribe(()=>{let e=this._selectionRenderService.getSelectionControls();if(this._selectionControl=e[e.length-1],this._selectionControl&&this._selectionControl.setControlExtensionDisable(!1),!this._selectionControl)return;let{leftControl:t,rightControl:n,topControl:r,bottomControl:i}=this._selectionControl;[t,n,r,i].forEach(e=>{e.onPointerDown$.subscribeEvent(this._controlPointerDownHandler.bind(this))})}))}dispose(){var e,t;(e=this._scenePointerMoveSubscribe)==null||e.unsubscribe(),this._scenePointerMoveSubscribe=null,(t=this._scenePointerUpSubscribe)==null||t.unsubscribe(),this._scenePointerUpSubscribe=null,this._selectionControl=null,this._moveStartRange=null,this._moveStartCellIndex=null,this._targetRange=null,super.dispose()}};Ni=K([G(1,(0,r.Inject)(n.SheetsPivotTableAdaptorModel)),G(2,(0,r.Inject)(o.SheetSkeletonManagerService)),G(3,(0,r.Inject)(r.ICommandService)),G(4,o.ISheetSelectionRenderService),G(5,(0,r.Inject)(i.SheetsSelectionsService))],Ni);let $=class extends r.Plugin{constructor(e=st,t,n,i,a){super(),this._config=e,this._injector=t,this._commandService=n,this._renderManagerService=i,this._configService=a;let{menu:o,...s}=(0,r.merge)({},st,this._config);o&&this._configService.setConfig(`menu`,o,{merge:!0}),this._configService.setConfig(ot,s),this._initRegisterCommand()}onStarting(){this._injector.add([ki]),this._injector.get(ki),[[Ai],[Cr],[vr],[Q],[Sr],[br],[xr],[q],[gr]].forEach(e=>this._injector.add(e)),this._injector.get(q)}onReady(){this._registerRenderModules(),this._injector.get(Ai)}onRendered(){this._injector.get(vr),this._injector.get(Q),this._injector.get(Sr),this._injector.get(br),this._injector.get(xr),this._injector.get(gr)}onSteady(){this._injector.get(Cr)}_registerRenderModules(){[[ji],[Ni]].forEach(e=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(r.UniverInstanceType.UNIVER_SHEET,e))})}_initRegisterCommand(){[at,P,nt,rt,I,B,ae,oe,se,de,pe,Se].forEach(e=>this._commandService.registerCommand(e))}};W($,`pluginName`,`${n.SHEET_PIVOT_TABLE_PLUGIN}_UI_PLUGIN`),W($,`packageName`,et),W($,`version`,tt),W($,`type`,r.UniverInstanceType.UNIVER_SHEET),$=K([(0,r.DependentOn)(l.UniverLicensePlugin,u.UniverRenderEnginePlugin,i.UniverSheetsPlugin,n.UniverSheetsPivotTablePlugin,o.UniverSheetsUIPlugin),G(1,(0,r.Inject)(r.Injector)),G(2,(0,r.Inject)(r.ICommandService)),G(3,u.IRenderManagerService),G(4,r.IConfigService)],$),e.DragDropContext=ni,e.Draggable=ii,e.Droppable=ri,e.OpenPivotTableRangeSelectorPanelOperation=P,e.PivotFilterOptions=Wr,e.PivotFilterPanel=Pr,e.SheetsPivotTableUIMenuSchema=$e,Object.defineProperty(e,"UniverSheetsPivotTableMobileUIPlugin",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(e,"UniverSheetsPivotTableUIPlugin",{enumerable:!0,get:function(){return $}})});
|