@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/es/index.js CHANGED
@@ -1 +1 @@
1
- import{GlobalConfig as e,PivotCellStyleTypeEnum as t,PivotDataFieldDataTypeEnum as n,PivotDataFieldSortOperatorEnum as r,PivotDataFieldTypeEnum as i,PivotDateGroupingMode as a,PivotExcelDateGroupUnit as o,PivotFilterTypeEnum as s,PivotLayoutTypeEnum as c,PivotShowAsBaseItemTypeEnum as l,PivotShowAsTypeEnum as u,PivotSubtotalPositionEnum as d,PivotSubtotalTypeEnum as f,PivotTableFiledAreaEnum as p,PivotTableValuePositionEnum as m,ST_PivotFilterOperatorEnum as h,compilePivotDateFilter as g,generateHexNumber as _,getPivotDateGroupingMode as v,hasPivotMultipleFilters as y,isDateGroupFieldJSON as b,isManualPivotFilter as x,isPivotDateFilter as S,isPivotTableFilterRestrictive as C,isValueFilterOperator as w}from"@univerjs-pro/engine-pivot";import{AddPivotFieldCommand as T,AddPivotTableCommand as E,InitializePivotRuntimeLocalMutation as D,MovePivotFieldCommand as O,PIVOT_DATE_GROUP_TYPES as ee,PIVOT_OPTION_FILTER_COORDINATION as te,PivotDisplayDataType as k,PivotDrillDownCommand as ne,PositionType as A,RemovePivotFieldCommand as re,RemovePivotTableCommand as ie,RemovePivotTableMutation as ae,SHEETS_PIVOT_PLUGIN_CONFIG_KEY as oe,SHEET_PIVOT_TABLE_PLUGIN as se,SetPivotCollapseCommand as ce,SetPivotDateFilterCommand as le,SetPivotDateGroupCommand as ue,SetPivotExcelDateGroupCommand as de,SetPivotFilterCommand as fe,SetPivotLayoutCommand as pe,SetPivotManualGroupsCommand as me,SetPivotNumberGroupCommand as he,SetPivotOptionCommand as ge,SetPivotSortCommand as _e,SetPivotValueFilterCommand as ve,SheetsPivotRPCService as ye,SheetsPivotTableAdaptorModel as j,SheetsPivotTableConfigModel as M,SheetsPivotTableService as be,UniverSheetsPivotTablePlugin as xe,UpdatePivotFieldSettingCommand as Se,UpdatePivotTableSourceRangeCommand as Ce,UpdatePivotValuePositionCommand as we,generateSetRangeValueMutations as Te,getPivotAppliedRanges as Ee,getPivotDateGroupContext as De,isPivotDateGroupTypeDisabled as Oe,isolateTextForBidiContext as ke,mapPivotSheetColumn as Ae,mapPivotSheetRange as je,resolvePivotSheetCell as Me,resolvePivotValueFieldId as Ne,resolvePivotValueFilterTarget as Pe,unionPivotViewRange as Fe}from"@univerjs-pro/sheets-pivot";import{CommandType as Ie,CustomCommandExecutionError as Le,DateSystem as Re,DependentOn as ze,Disposable as N,DisposableCollection as Be,FilterSelectionMode as Ve,ICommandService as P,IConfigService as He,IConfirmService as Ue,ILogService as We,IPermissionService as Ge,IUniverInstanceService as F,Inject as I,Injector as Ke,LocaleService as L,Optional as qe,Plugin as Je,RANGE_TYPE as Ye,RecordValueType as Xe,Rectangle as Ze,ThemeService as Qe,Tools as $e,UniverInstanceType as et,cellToRange as tt,currencySymbols as nt,debounce as rt,excelDateTimePartsToSerial as it,excelSerialToDateTimeParts as at,generateRandomId as ot,isPatternEqualWithoutDecimal as st,isValidRange as ct,merge as lt,numfmt as ut,toDisposable as dt,touchDependencies as ft}from"@univerjs/core";import{AddWorksheetMergeMutation as pt,InsertColCommand as mt,InsertRowCommand as ht,MergeCellController as gt,MoveRangeCommand as _t,RangeProtectionPermissionEditPoint as vt,RangeProtectionPermissionViewPoint as yt,RemoveColCommand as bt,RemoveRowCommand as xt,SheetInterceptorService as St,SheetPermissionCheckController as Ct,SheetsSelectionsService as wt,UniverSheetsPlugin as Tt,WorkbookEditablePermission as Et,WorksheetEditPermission as Dt,WorksheetFilterPermission as Ot,WorksheetPivotTablePermission as kt,WorksheetViewPermission as At,checkRangesEditablePermission as jt,expandToContinuousRange as Mt,getSheetCommandTarget as Nt,isSingleCellSelection as Pt}from"@univerjs/sheets";import{ComponentManager as Ft,ContextMenuGroup as It,ContextMenuPosition as Lt,IDialogService as R,IMenuManagerService as Rt,IMessageService as zt,ISidebarService as Bt,IconManager as Vt,MenuItemType as Ht,RibbonDataGroup as Ut,UniverMobileUIPlugin as Wt,getMenuHiddenObservable as Gt,useDependency as z,useObservable as B}from"@univerjs/ui";import{CellAlertManagerService as Kt,CellAlertType as qt,IFormatPainterService as Jt,ISheetClipboardService as Yt,ISheetSelectionRenderService as Xt,MOBILE_CONTEXT_MENU as Zt,SetCellEditVisibleOperation as Qt,SheetContextMenuMobileRenderController as $t,SheetPrintInterceptorService as en,SheetSkeletonManagerService as tn,SheetsRenderService as nn,UniverSheetsMobileUIPlugin as rn,UniverSheetsUIPlugin as an,getCoordByCell as on,getCoordByOffset as sn,getCurrentRangeDisable$ as cn,getObservableWithExclusiveRange$ as ln,getSheetObject as un}from"@univerjs/sheets-ui";import{EMPTY as dn,Subject as fn,auditTime as pn,concat as mn,debounceTime as hn,defer as gn,filter as _n,map as vn,merge as yn,of as bn,skip as xn,startWith as Sn,switchMap as Cn,takeUntil as wn,tap as Tn}from"rxjs";import{ActionRow as En,Button as V,Checkbox as H,DatePicker as Dn,Dropdown as On,Input as kn,InputNumber as An,MessageType as jn,MobileActionRow as Mn,MobileActionRowGroup as Nn,MobileDropdownMenu as Pn,MobileSelect as Fn,Radio as In,RadioGroup as Ln,Segmented as Rn,Select as zn,SelectList as Bn,TimeInput as Vn,Tooltip as Hn,borderClassName as Un,clsx as U,scrollbarClassName as Wn}from"@univerjs/design";import{UniverLicensePlugin as Gn}from"@univerjs-pro/license";import{CURSOR_TYPE as Kn,IRenderManagerService as qn,Rect as Jn,Shape as Yn,UniverRenderEnginePlugin as Xn,Vector2 as Zn}from"@univerjs/engine-render";import{ArrowLeftIcon as Qn,AscendingIcon as $n,CalendarIcon as er,CheckMarkIcon as tr,ColumnIcon as nr,DescendingIcon as rr,FilterIcon as ir,FunctionIcon as ar,GripVerticalIcon as or,MoreDownIcon as sr,MoreHorizontalIcon as cr,NumberIcon as lr,PivotTableIcon as ur,RowIcon as dr,SearchIcon as fr,TextIcon as pr}from"@univerjs/icons";import{Fragment as mr,jsx as W,jsxs as G}from"react/jsx-runtime";import{createContext as hr,useCallback as K,useContext as gr,useEffect as q,useMemo as _r,useRef as J,useState as Y}from"react";import{deserializeRangeWithSheet as vr,serializeRange as yr,serializeRangeWithSheet as br}from"@univerjs/engine-formula";import{MobileRangeSelector as xr,RangeSelector as Sr}from"@univerjs/sheets-formula-ui";import{InsertTextCommand as Cr}from"@univerjs/docs";import{IMEInputCommand as wr}from"@univerjs/docs-ui";const Tr=`UNIVER_SHEET_PIVOT_PANEL`,Er=`UNIVER_SHEET_PIVOT_PANEL_ID`,Dr=`UNIVER_SHEET_PIVOT_FILTER_PANEL`,Or=`UNIVER_SHEET_PIVOT_FILTER_PANEL_ID`,kr=`UNIVER_SHEET_PIVOT_FIELD_SETTING`,Ar=`UNIVER_SHEET_PIVOT_FIELD_SETTING_ID`,jr=`UNIVER_SHEET_PIVOT_FIELD_NUMFMT`,Mr=`UNIVER_SHEET_PIVOT_FIELD_NUMFMT_ID`,Nr=`UNIVER_SHEET_PIVOT_SHOW_DATA_AS_DIALOG`,Pr=`UNIVER_SHEET_PIVOT_VALUE_FILTER_DIALOG`,Fr=`UNIVER_SHEET_PIVOT_EXCEL_DATE_GROUP_DIALOG`,Ir=`UNIVER_SHEET_PIVOT_NUMBER_GROUP_DIALOG`,Lr=`UNIVER_SHEET_PIVOT_MANUAL_GROUP_DIALOG`,Rr=`univer.sheet.pivot-table-range-selector`,zr=`UNIVER_SHEET_PIVOT_MOBILE_ACTION_PANEL`,Br=`UNIVER_SHEET_PIVOT_MOBILE_ACTION_PANEL_ID`,Vr={type:Ie.OPERATION,id:`sheet.operation.open-pivot-table-range-selector-panel`,async handler(e){let t=e.get(F),n=e.get(P),r=Nt(t),i=e.get(L);if(!r)return!1;let{unitId:a,subUnitId:o,worksheet:s,workbook:c}=r,l=e.get(wt).getCurrentLastSelection(),u=(l==null?void 0:l.range)??{startRow:0,endRow:0,startColumn:0,endColumn:0,rangeType:Ye.NORMAL},d=await Hr(e,a,o,Pt(l)?Mt(u,{up:!0,left:!0,right:!0,down:!0},s):u,s.getName());if(!d)return!1;let f=c.getSheets().find(e=>e.getName()===d.sourceSheetName);if(!f)return!1;let p;if(d.positionType===A.New)p={row:0,col:0,unitId:a,subUnitId:ot(),sheetName:c.generateNewSheetName(`${i.t(`sheets-pivot-ui.sheet`)}`)};else{if(!d.positionRange||!d.positionSheetName)return!1;let e=c.getSheets().find(e=>e.getName()===d.positionSheetName);if(!e)return!1;p={row:d.positionRange.startRow,col:d.positionRange.startColumn,unitId:a,subUnitId:e.getSheetId(),sheetName:e.getName()}}let m=_(8);return await n.executeCommand(E.id,{pivotTableId:m,pivotTableConfig:{targetCellInfo:p,sourceRangeInfo:{range:d.sourceRange,unitId:a,sheetName:d.sourceSheetName,subUnitId:f.getSheetId()}},positionType:d.positionType})?{unitId:p.unitId,subUnitId:p.subUnitId,pivotTableId:m}:!1}};async function Hr(e,t,n,r,i){let a=e.get(R),o=e.get(L);return new Promise(e=>{let s,c={unitId:t,subUnitId:n,sourceRange:r,positionRange:null,sourceSheetName:i,positionSheetName:i,onConfirm:t=>{e(t),s==null||s.dispose()},onCancel:()=>{e(null),s==null||s.dispose()}};s=a.open({id:Rr,title:{title:o.t(`sheets-pivot-ui.dialog.source.insertPivotTable`)},draggable:!0,mask:!1,maskClosable:!1,children:{label:{name:Rr,props:c}},width:400,onClose:()=>{s.dispose()}})})}const Ur={type:Ie.OPERATION,id:`sheet.operation.set-pivot-date-group`,async handler(e,t){if(!t)return!1;let n=Wr(e);return n?e.get(P).executeCommand(ue.id,{unitId:n.unitId,subUnitId:n.subUnitId,pivotTableId:n.pivotTableId,tableFieldId:n.tableFieldId,dateType:t.dateType}):!1}};function Wr(e,t=a.Legacy){let n=e.get(F),r=Nt(n);if(!r)return;let i=e.get(wt).getCurrentLastSelection(),o=i==null?void 0:i.primary;if(!o)return;let{unitId:s,subUnitId:c}=r,l=o.startRow,u=o.startColumn,d=e.get(j).getPivotTableIdByCell(s,c,l,u);if(!d)return;let f=Gr(e,s,c,d,l,u);if(!f)return;let p=e.get(M),m=p.getPivotTableConfig(s,c,d);if(v(m==null?void 0:m.fieldsConfig.options)!==t)return;let h=p.getCollection(s,d),g=De(m==null?void 0:m.fieldsConfig,h,f);if(g)return{unitId:s,subUnitId:c,pivotTableId:d,tableFieldId:f,row:l,col:u,dateGroupContext:g}}function Gr(e,t,n,r,i,a){let o=e.get(j).getPivotItemRenderInfoCache(t,n,r);if(!o)return;let s=e.get(j).getPivotTableCellData(t,n,i,a),c=Me(i,a,s,o);return c==null?void 0:c.tableFieldId}function Kr(e){let t=Wr(e,a.ExcelLike);if(!t)return;let n=e.get(M),r=n.getPivotTableConfig(t.unitId,t.subUnitId,t.pivotTableId),i=r==null?void 0:r.fieldsConfig.dimension[t.tableFieldId];if(!i)return;let o=n.getCollection(t.unitId,t.pivotTableId),s=(t.dateGroupContext.area===p.Row?r.fieldsConfig.rowFields:r.fieldsConfig.columnFields).flatMap(e=>{let n=r.fieldsConfig.dimension[e],i=n?o==null?void 0:o.fields[n.dataFieldId]:void 0;return i&&b(i)&&i.originalFieldId===t.dateGroupContext.originalDataFieldId&&i.excelLike?[i.excelLike]:[]}),c=s[0],l=c?{units:s.map(e=>e.unit),autoStart:c.autoStart,autoEnd:c.autoEnd,...c.start===void 0?{}:{start:c.start},...c.end===void 0?{}:{end:c.end},...c.daysInterval===void 0?{}:{daysInterval:c.daysInterval}}:void 0;return{...t,targetFieldName:i.displayName,grouping:l}}const qr={id:`sheet.operation.set-pivot-excel-date-group`,type:Ie.OPERATION,async handler(e){let t=Kr(e);if(!t)return!1;let n=e.get(M),r=n.getPivotTableConfig(t.unitId,t.subUnitId,t.pivotTableId),i=n.getCollection(t.unitId,t.pivotTableId),a=e.get(R),o=e.get(L),s=e.get(F).getUnit(t.unitId),c=(s==null?void 0:s.getDateSystem())??Re.Date1900,l=null,u=!1,d=!1,f=()=>{u||(u=!0,l==null||l.dispose(),l=null)},p=async a=>{if(!(d||u)){d=!0;try{let o=Kr(e);if(!o||o.unitId!==t.unitId||o.subUnitId!==t.subUnitId||o.pivotTableId!==t.pivotTableId||o.tableFieldId!==t.tableFieldId||n.getPivotTableConfig(t.unitId,t.subUnitId,t.pivotTableId)!==r||n.getCollection(t.unitId,t.pivotTableId)!==i)return;await e.get(P).executeCommand(de.id,{unitId:t.unitId,subUnitId:t.subUnitId,pivotTableId:t.pivotTableId,tableFieldId:t.tableFieldId,grouping:{...a,units:a.units.concat()}})}catch{}finally{f()}}};try{l=a.open({id:`UNIVER_SHEET_PIVOT_EXCEL_DATE_GROUP_DIALOG_ID`,title:{title:o.t(`sheets-pivot-ui.dateGroup.excelLikeTitle`)},draggable:!0,mask:!0,maskClosable:!1,width:440,children:{label:{name:Fr,props:{targetFieldName:t.targetFieldName,dateSystem:c,grouping:t.grouping,onConfirm:p,onCancel:f}}},onClose:f})}catch{return f(),!1}return!0}};function Jr(e){return e.map(e=>({...e,members:e.members.map(e=>({...e}))}))}function Yr(t){let n;try{n=JSON.parse(t)}catch{return}if(!(!Array.isArray(n)||n.length<1||typeof n[0]!=`string`))return n[0]===Xe.Blank?e.BLANK_PLACEHOLDER:String(n[1])}function Xr(t,n){var r;let a=()=>({error:`invalidSelection`}),o=Nt(t.get(F)),s=t.get(wt).getCurrentSelections();if(!o||!s.length)return a();let{unitId:c,subUnitId:l}=o,u=s[0].primary;if(!u)return a();let d=t.get(j),f=d.getPivotTableIdByCell(c,l,u.startRow,u.startColumn),p=t.get(M),m=f&&p.getPivotTableConfig(c,l,f),h=f&&p.getCollection(c,f),g=f&&d.getPivotItemRenderInfoCache(c,l,f);if(!f||!m||!h||!g)return a();let _=Me(u.startRow,u.startColumn,d.getPivotTableCellData(c,l,u.startRow,u.startColumn),g),v=_==null?void 0:_.tableFieldId,y=v&&m.fieldsConfig.dimension[v];if(!v||!y||!(m.fieldsConfig.rowFields.includes(v)||m.fieldsConfig.columnFields.includes(v)))return a();let b=h.fields[y.dataFieldId];if(!b)return a();let x=b.dataFieldType===i.textGroupField?b:void 0;if(!x&&b.dataFieldType!==i.defaultNormalField)return a();let S=(x==null?void 0:x.originalFieldId)??b.id;if(((r=h.fields[S])==null?void 0:r.dataFieldType)!==i.defaultNormalField)return a();let C=Jr((x==null?void 0:x.grouping.groups)??[]),w=/* @__PURE__ */ new Map,T=/* @__PURE__ */ new Set,E=0;for(let t of s){let{startRow:n,endRow:r,startColumn:i,endColumn:o}=t.range;if(E+=(r-n+1)*(o-i+1),E>512)return a();for(let t=n;t<=r;t++)for(let n=i;n<=o;n++){if(d.getPivotTableIdByCell(c,l,t,n)!==f)return a();let r=Me(t,n,d.getPivotTableCellData(c,l,t,n),g),i=r==null?void 0:r.info;if(!r||r.area!==`rowRanges`&&r.area!==`colRanges`||r.tableFieldId!==v||!i||i.isValue||i.isSubtotal||i.isBottomTotal||i.isTopTotal||i.rowType&&i.rowType!==`item`||i.level<1)return a();let o=i.paths[i.level-1];if(o===void 0)return a();if(x){let e;try{e=JSON.parse(o)}catch{return a()}if(!Array.isArray(e)||e.length!==2||typeof e[1]!=`string`)return a();if(e[0]===`group`){if(!C.some(t=>t.id===e[1]))return a();T.add(e[1]);continue}if(e[0]!==`member`)return a();let t=Yr(e[1]);if(t===void 0)return a();w.set(e[1],{path:t,memberKey:e[1]})}else{var D;let r=(D=d.getPivotTableCellData(c,l,t,n))==null?void 0:D.v,i=r==null||r===``?e.BLANK_PLACEHOLDER:String(r);w.set(o,{path:i,tupleKey:o})}}}return n===`group`&&(w.size<2||T.size>0)||n!==`group`&&(w.size>0||T.size!==1)?a():{context:{unitId:c,subUnitId:l,pivotTableId:f,tableFieldId:v,sourceFieldId:S,targetFieldName:y.displayName,groups:C,memberPaths:Array.from(w.values()),selectedGroupId:Array.from(T)[0]}}}function Zr(e,t){return Xr(e,t).context}function Qr(e,t){e.get(zt).show({type:jn.Error,content:e.get(L).t(`sheets-pivot-ui.manualGroup.${t}`)})}function $r(e,t,n){let r=Zr(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 ei(e,t){let n=Xr(e,t),r=n.context;if(!r)return Qr(e,n.error),!1;let i=e.get(M),a=i.getPivotTableConfig(r.unitId,r.subUnitId,r.pivotTableId),o=i.getCollection(r.unitId,r.pivotTableId),s=[];if(t===`group`){try{let t=(await e.get(ye).getPivotDisplayConfig({unitId:r.unitId,subUnitId:r.subUnitId,pivotTableId:r.pivotTableId,params:{type:k.ManualGroupMembers,manualGroupMembers:{sourceFieldId:r.sourceFieldId,paths:r.memberPaths}}})).result.manualGroupMembers;if(!t||t.error||t.members.length<2)return Qr(e,(t==null?void 0:t.error)??`invalidSelection`),!1;s=t.members}catch{return Qr(e,`invalidSelection`),!1}if(!$r(e,t,r)||i.getPivotTableConfig(r.unitId,r.subUnitId,r.pivotTableId)!==a||i.getCollection(r.unitId,r.pivotTableId)!==o)return!1}let c=e.get(R),l=e.get(L),u=r.groups.find(e=>e.id===r.selectedGroupId),d=(u==null?void 0:u.name)??l.t(`sheets-pivot-ui.manualGroup.defaultName`,String(r.groups.length+1));if(!u){let e=r.groups.length+1;for(;r.groups.some(e=>e.name===d);)e++,d=l.t(`sheets-pivot-ui.manualGroup.defaultName`,String(e))}let f=null,p=!1,m=!1,h=()=>{p||(p=!0,f==null||f.dispose(),f=null)},g=async n=>{if(m||p)return;let c=n.trim();if(!c||r.groups.some(e=>e.name===c&&e.id!==r.selectedGroupId))Qr(e,`invalidSelection`);else{m=!0;try{if(!$r(e,t,r)||i.getPivotTableConfig(r.unitId,r.subUnitId,r.pivotTableId)!==a||i.getCollection(r.unitId,r.pivotTableId)!==o)return;let n=t===`group`?r.groups.concat({id:ot(),name:c,members:s.map(e=>({...e}))}):r.groups.map(e=>e.id===r.selectedGroupId?{...e,name:c}:e);await e.get(P).executeCommand(me.id,{unitId:r.unitId,subUnitId:r.subUnitId,pivotTableId:r.pivotTableId,sourceFieldId:r.sourceFieldId,groups:n})}catch{}finally{h()}}};try{f=c.open({id:`UNIVER_SHEET_PIVOT_MANUAL_GROUP_DIALOG_ID`,title:{title:l.t(t===`group`?`sheets-pivot-ui.manualGroup.groupTitle`:`sheets-pivot-ui.manualGroup.renameTitle`)},draggable:!0,mask:!0,maskClosable:!1,width:400,children:{label:{name:Lr,props:{name:d,onConfirm:g,onCancel:h}}},onClose:h})}catch{return h(),!1}return!0}const ti={id:`sheet.operation.set-pivot-manual-group`,type:Ie.OPERATION,handler:e=>ei(e,`group`)},ni={id:`sheet.operation.rename-pivot-manual-group`,type:Ie.OPERATION,handler:e=>ei(e,`rename`)},ri={id:`sheet.operation.ungroup-pivot-manual-group`,type:Ie.OPERATION,async handler(e){let t=Xr(e,`ungroup`),n=t.context;if(!n)return Qr(e,t.error),!1;let r=e.get(M),i=r.getPivotTableConfig(n.unitId,n.subUnitId,n.pivotTableId),a=r.getCollection(n.unitId,n.pivotTableId);return!$r(e,`ungroup`,n)||r.getPivotTableConfig(n.unitId,n.subUnitId,n.pivotTableId)!==i||r.getCollection(n.unitId,n.pivotTableId)!==a?!1:e.get(P).executeCommand(me.id,{unitId:n.unitId,subUnitId:n.subUnitId,pivotTableId:n.pivotTableId,sourceFieldId:n.sourceFieldId,groups:n.groups.filter(e=>e.id!==n.selectedGroupId)})}};function ii(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 ai(e,t){if(e.dataFieldType===i.numberGroupField){let r=e,a=t.fields[r.originalFieldId];return!a||a.dataFieldType!==i.defaultNormalField||a.fieldDataType!==n.number?void 0:{sourceFieldId:r.originalFieldId,grouping:{...r.grouping}}}if(e.dataFieldType===i.defaultNormalField&&e.fieldDataType===n.number)return{sourceFieldId:e.id}}function oi(e){var t;let n=Nt(e.get(F)),r=(t=e.get(wt).getCurrentLastSelection())==null?void 0:t.primary;if(!n||!r)return;let{unitId:i,subUnitId:a}=n,o=r.startRow,s=r.startColumn,c=e.get(j),l=c.getPivotTableIdByCell(i,a,o,s);if(!l)return;let u=c.getPivotItemRenderInfoCache(i,a,l);if(!u)return;let d=Me(o,s,c.getPivotTableCellData(i,a,o,s),u),f=d==null?void 0:d.tableFieldId;if(!f||d.area!==`rowRanges`&&d.area!==`colRanges`)return;let p=e.get(M),m=p.getPivotTableConfig(i,a,l),h=p.getCollection(i,l),g=m==null?void 0:m.fieldsConfig.dimension[f];if(!g||!h||!(m.fieldsConfig.rowFields.includes(f)||m.fieldsConfig.columnFields.includes(f)))return;let _=h.fields[g.dataFieldId];if(!_)return;let v=ai(_,h);if(v)return{unitId:i,subUnitId:a,pivotTableId:l,tableFieldId:f,targetFieldName:g.displayName,...v}}const si={id:`sheet.operation.set-pivot-number-group`,type:Ie.OPERATION,async handler(e){let t=oi(e);if(!t)return!1;let n=e.get(M),r=n.getCollection(t.unitId,t.pivotTableId),i=n.getPivotTableConfig(t.unitId,t.subUnitId,t.pivotTableId),a=e.get(F),o=()=>{let n=oi(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)},s=e.get(R),c=e.get(L),l=null,u=!1,d=!1,f=new fn,p=async()=>{if(!u&&o())try{let n=(await e.get(ye).getPivotDisplayConfig({unitId:t.unitId,subUnitId:t.subUnitId,pivotTableId:t.pivotTableId,params:{type:k.NumberGroupDefaults,numberGroupDefaults:{tableFieldId:t.tableFieldId}}})).result.numberGroupDefaults;return!u&&o()&&n&&ii(n)?n:void 0}catch{return}},m=()=>{u||(u=!0,f.next(),f.complete(),l==null||l.dispose(),l=null)},h=await p();if(!h)return m(),!1;let g=a.unitDisposed$.pipe(_n(e=>e.getUnitId()===t.unitId),Tn(m)),_=gn(()=>{if(u||!a.getUnit(t.unitId))return m(),dn;let e=n.watchPivotTableChanges(t.unitId,t.subUnitId,t.pivotTableId).pipe(hn(0),vn(()=>void 0));return yn(bn(h),e).pipe(Cn(e=>e&&n.getCollection(t.unitId,t.pivotTableId)===r&&n.getPivotTableConfig(t.unitId,t.subUnitId,t.pivotTableId)===i?bn(e):mn(bn(void 0),p())),wn(yn(f,g)))}),v=async n=>{if(!(d||u)){d=!0;try{if(!ii(n)||!o())return;await e.get(P).executeCommand(he.id,{unitId:t.unitId,subUnitId:t.subUnitId,pivotTableId:t.pivotTableId,tableFieldId:t.tableFieldId,grouping:{...n}})}catch{}finally{m()}}};try{l=s.open({id:`UNIVER_SHEET_PIVOT_NUMBER_GROUP_DIALOG_ID`,title:{title:c.t(`sheets-pivot-ui.numberGroup.title`)},draggable:!0,mask:!0,maskClosable:!1,width:400,children:{label:{name:Ir,props:{targetFieldName:t.targetFieldName,grouping:t.grouping,defaults$:_,onConfirm:v,onCancel:m}}},onClose:m})}catch{return m(),!1}return!0}},ci=[{type:u.normal,localeKey:`sheets-pivot-ui.showValuesAs.normal`,requiresParameters:!1,baseItemMode:`none`},{type:u.percentOfGrandTotal,localeKey:`sheets-pivot-ui.showValuesAs.percentOfGrandTotal`,requiresParameters:!1,baseItemMode:`none`},{type:u.percentOfRowTotal,localeKey:`sheets-pivot-ui.showValuesAs.percentOfRowTotal`,requiresParameters:!1,baseItemMode:`none`},{type:u.percentOfColumnTotal,localeKey:`sheets-pivot-ui.showValuesAs.percentOfColumnTotal`,requiresParameters:!1,baseItemMode:`none`},{type:u.percentOfParentRowTotal,localeKey:`sheets-pivot-ui.showValuesAs.percentOfParentRowTotal`,requiresParameters:!1,baseItemMode:`none`},{type:u.percentOfParentColumnTotal,localeKey:`sheets-pivot-ui.showValuesAs.percentOfParentColumnTotal`,requiresParameters:!1,baseItemMode:`none`},{type:u.index,localeKey:`sheets-pivot-ui.showValuesAs.index`,requiresParameters:!1,baseItemMode:`none`},{type:u.percentOfParent,localeKey:`sheets-pivot-ui.showValuesAs.percentOfParent`,requiresParameters:!0,baseItemMode:`none`,parentFieldOnly:!0},{type:u.percentOf,localeKey:`sheets-pivot-ui.showValuesAs.percentOf`,requiresParameters:!0,baseItemMode:`item`},{type:u.differenceFrom,localeKey:`sheets-pivot-ui.showValuesAs.differenceFrom`,requiresParameters:!0,baseItemMode:`item-or-relative`},{type:u.percentDifferenceFrom,localeKey:`sheets-pivot-ui.showValuesAs.percentDifferenceFrom`,requiresParameters:!0,baseItemMode:`item-or-relative`},{type:u.runningTotal,localeKey:`sheets-pivot-ui.showValuesAs.runningTotal`,requiresParameters:!0,baseItemMode:`none`},{type:u.percentRunningTotal,localeKey:`sheets-pivot-ui.showValuesAs.percentRunningTotal`,requiresParameters:!0,baseItemMode:`none`},{type:u.rankAscending,localeKey:`sheets-pivot-ui.showValuesAs.rankAscending`,requiresParameters:!0,baseItemMode:`none`},{type:u.rankDescending,localeKey:`sheets-pivot-ui.showValuesAs.rankDescending`,requiresParameters:!0,baseItemMode:`none`}],li={type:Ie.OPERATION,id:`sheet.operation.set-pivot-show-data-as`,async handler(e,t){let n=t&&ci.find(e=>e.type===t.type);if(!n)return!1;let r=di(e);if(!r)return!1;if(!n.requiresParameters)return e.get(P).executeCommand(Se.id,{unitId:r.unitId,subUnitId:r.subUnitId,pivotTableId:r.pivotTableId,tableFieldId:r.tableFieldId,showDataAs:{type:n.type,baseFieldId:``,baseItem:``},tableFieldInfo:r.tableFieldInfo,dataFieldInfo:r.dataFieldInfo});let i=fi(e,r);if(!i)return!1;let a=ui(i.config,i.collection,n);if(a.length===0)return!1;let o={};if(n.baseItemMode!==`none`){try{o=await pi(e,i.config,r.pivotTableId,a)}catch{return!1}if(!a.some(e=>o[e]&&(n.baseItemMode===`item-or-relative`||o[e].items.length>0)))return!1}let s=e.get(R),c=e.get(L),l=null,u=!1,d=!1,f=()=>{u||(u=!0,l==null||l.dispose(),l=null)};try{l=s.open({id:`UNIVER_SHEET_PIVOT_SHOW_DATA_AS_DIALOG_ID`,title:{title:c.t(`sheets-pivot-ui.showValuesAs.dialogTitle`)},draggable:!0,mask:!0,maskClosable:!1,width:400,children:{label:{name:Nr,props:{unitId:r.unitId,subUnitId:r.subUnitId,pivotTableId:r.pivotTableId,tableFieldId:r.tableFieldId,type:n.type,baseItems:o,onCancel:f,onConfirm:async t=>{if(!d){d=!0;try{let a=fi(e,r);if(!a||!mi(a.config,a.collection,n,t))return;if(n.baseItemMode!==`none`&&t.baseItemType===void 0){var i;if(!((i=(await pi(e,a.config,a.context.pivotTableId,[t.baseFieldId]))[t.baseFieldId])!=null&&i.items.includes(t.baseItem)))return}await e.get(P).executeCommand(Se.id,{unitId:a.context.unitId,subUnitId:a.context.subUnitId,pivotTableId:a.context.pivotTableId,tableFieldId:a.context.tableFieldId,showDataAs:t,tableFieldInfo:a.context.tableFieldInfo,dataFieldInfo:a.context.dataFieldInfo})}catch{}finally{f()}}}}}},onClose:f})}catch{return f(),!1}return!0}};function ui(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 di(e){var t,n;let r=Nt(e.get(F)),i=(t=e.get(wt).getCurrentLastSelection())==null?void 0:t.primary;if(!r||!i)return;let{unitId:a,subUnitId:o}=r,s=i.startRow,c=i.startColumn,l=e.get(j),u=l.getPivotTableIdByCell(a,o,s,c);if(!u)return;let d=e.get(M).getPivotTableConfig(a,o,u),f=l.getPivotItemRenderInfoCache(a,o,u),p=l.getPivotTableCellData(a,o,s,c);if(!d||!f)return;let m=Me(s,c,p,f);if(!m)return;let h=Ne(m,d.fieldsConfig.valueFields);if(h)return(n=fi(e,{unitId:a,subUnitId:o,pivotTableId:u,tableFieldId:h}))==null?void 0:n.context}function fi(e,t){let{unitId:n,subUnitId:r,pivotTableId:i,tableFieldId:a}=t,o=e.get(M),s=o.getPivotTableConfig(n,r,i),c=o.getCollection(n,i),l=s==null?void 0:s.fieldsConfig.measure[a];if(!s||!c||!l||!s.fieldsConfig.valueFields.includes(l.id))return;let u=c.fields[l.dataFieldId]??c.customFields.find(e=>e.id===l.dataFieldId);if(!u)return;let d={...l.showDataAs};return{config:s,collection:c,context:{unitId:n,subUnitId:r,pivotTableId:i,tableFieldId:l.id,currentShowDataAs:d,tableFieldInfo:{tableFieldId:l.id,displayName:l.displayName,dataFieldId:l.dataFieldId,format:l.format,subTotalType:l.subtotal,showDataAs:{...d}},dataFieldInfo:{id:u.id,dataFieldId:u.id,name:u.name,type:u.fieldDataType,checked:!0,pivotTableId:i}}}}async function pi(e,t,n,r){let{unitId:i,subUnitId:a}=t.targetCellInfo,o=t.targetCellInfo,s=e.get(j).getPivotItemRenderInfoCache(i,a,n);if(!s)throw Error(`[sheets-pivot-ui]: Pivot render cache is unavailable`);return(await Promise.all(r.map(async t=>{try{return[t,(await e.get(ye).getPivotDisplayConfig({unitId:i,subUnitId:a,pivotTableId:n,params:{type:k.Filter,filter:{row:o.row,col:o.col,tableFieldId:t,pivotItemRenderInfoCache:s}}})).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 mi(e,t,n,r){return r.type!==n.type||!ui(e,t,n).includes(r.baseFieldId)?!1:n.baseItemMode===`none`?r.baseItem===``&&r.baseItemType===void 0:r.baseItemType===void 0?r.baseItem!==``:n.baseItemMode===`item-or-relative`&&r.baseItem===``&&(r.baseItemType===l.previous||r.baseItemType===l.next)}function hi(e){return{...e,expected:Array.isArray(e.expected)?e.expected.concat():e.expected}}function gi(e,t){let n=e.get(M).getPivotTableConfig(t.unitId,t.subUnitId,t.pivotTableId);if(n&&n.fieldsConfig.dimension[t.targetFieldId]&&(n.fieldsConfig.rowFields.includes(t.targetFieldId)||n.fieldsConfig.columnFields.includes(t.targetFieldId)))return n}function _i(e){var t,n;let r=Nt(e.get(F)),i=(t=e.get(wt).getCurrentLastSelection())==null?void 0:t.primary;if(!r||!i)return;let{unitId:a,subUnitId:o}=r,s=i.startRow,c=i.startColumn,l=e.get(j),u=l.getPivotTableIdByCell(a,o,s,c);if(!u)return;let d=e.get(M).getPivotTableConfig(a,o,u),f=l.getPivotItemRenderInfoCache(a,o,u);if(!d||!f)return;let p=Me(s,c,l.getPivotTableCellData(a,o,s,c),f),m=p&&Pe(p,d.fieldsConfig);if(!m)return;let h=d.fieldsConfig.dimension[m.targetFieldId],g=d.fieldsConfig.valueFields.flatMap(e=>{let t=d.fieldsConfig.measure[e];return t?[{id:t.id,label:t.displayName}]:[]});if(!h||g.length===0)return;let _=(n=d.fieldsConfig.valueFilter)==null||(n=n.find(e=>e.fieldId===m.targetFieldId))==null?void 0:n.filterInfo;return{unitId:a,subUnitId:o,pivotTableId:u,targetFieldId:m.targetFieldId,targetFieldName:h.displayName,valueFields:g,defaultValueFieldId:m.defaultValueFieldId,..._?{currentFilter:hi(_)}:{}}}const vi={type:Ie.OPERATION,id:`sheet.operation.set-pivot-value-filter`,async handler(e){let t=_i(e);if(!t)return!1;let n=e.get(R),r=e.get(L),i=null,a=!1,o=!1,c=()=>{a||(a=!0,i==null||i.dispose(),i=null)},l=async n=>{if(!o){o=!0;try{let r=gi(e,t);if(!r||n&&(!r.fieldsConfig.measure[n.valueFieldId]||!r.fieldsConfig.valueFields.includes(n.valueFieldId)||!w(n.operator)))return;await e.get(P).executeCommand(ve.id,{unitId:t.unitId,subUnitId:t.subUnitId,pivotTableId:t.pivotTableId,fieldId:t.targetFieldId,valueFilterInfo:n?{...n,type:s.ValueFilter,expected:Array.isArray(n.expected)?n.expected.concat():n.expected}:void 0})}catch{}finally{c()}}};try{i=n.open({id:`UNIVER_SHEET_PIVOT_VALUE_FILTER_DIALOG_ID`,title:{title:r.t(`sheets-pivot-ui.valueFilter.dialogTitle`)},draggable:!0,mask:!0,maskClosable:!1,width:420,children:{label:{name:Pr,props:{targetFieldId:t.targetFieldId,targetFieldName:t.targetFieldName,valueFields:t.valueFields,defaultValueFieldId:t.defaultValueFieldId,currentFilter:t.currentFilter,onConfirm:e=>l(e),onClear:()=>l(void 0),onCancel:c}}},onClose:c})}catch{return c(),!1}return!0}},yi=`sheet.pivot.context-menu.date-group`,bi=`sheet.pivot.context-menu.excel-date-group`,xi=`sheet.pivot.context-menu.number-group`,Si=`sheet.pivot.context-menu.manual-group`,Ci=`sheet.pivot.context-menu.manual-rename`,wi=`sheet.pivot.context-menu.manual-ungroup`,Ti=`sheet.pivot.context-menu.show-data-as`,Ei=`sheet.pivot.context-menu.value-filter`,Di={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 Oi(e){return{id:Vr.id,type:Ht.BUTTON,icon:`PivotTableIcon`,hidden$:Gt(e,et.UNIVER_SHEET),disabled$:ln(e,cn(e,{workbookTypes:[Et],worksheetTypes:[At,kt],rangeTypes:[yt]})),tooltip:`sheets-pivot-ui.title`,title:`sheets-pivot-ui.title`}}function ki(e){return{id:yi,type:Ht.SUBITEMS,title:`sheets-pivot-ui.dateGroup.title`,hidden$:Li(e)}}function Ai(e){return{id:bi,commandId:qr.id,type:Ht.BUTTON,title:`sheets-pivot-ui.dateGroup.excelLikeTitle`,hidden$:Bi(e).pipe(vn(()=>!Kr(e)))}}function ji(e){return{id:xi,commandId:si.id,type:Ht.BUTTON,title:`sheets-pivot-ui.numberGroup.title`,hidden$:Bi(e).pipe(vn(()=>!oi(e)))}}function Mi(e){return{id:Si,commandId:ti.id,type:Ht.BUTTON,title:`sheets-pivot-ui.manualGroup.groupTitle`,hidden$:Bi(e).pipe(vn(()=>!Zr(e,`group`)))}}function Ni(e){return{id:Ci,commandId:ni.id,type:Ht.BUTTON,title:`sheets-pivot-ui.manualGroup.renameTitle`,hidden$:Bi(e).pipe(vn(()=>!Zr(e,`rename`)))}}function Pi(e){return{id:wi,commandId:ri.id,type:Ht.BUTTON,title:`sheets-pivot-ui.manualGroup.ungroupTitle`,hidden$:Bi(e).pipe(vn(()=>!Zr(e,`ungroup`)))}}function Fi(e){return t=>({id:Ii(e),commandId:Ur.id,type:Ht.BUTTON,title:Di[e],params:{dateType:e},disabled$:Ri(t,e),activated$:zi(t,e)})}function Ii(e){return`sheet.pivot.context-menu.date-group.${e}`}function Li(e){return Bi(e).pipe(vn(()=>!Wr(e)))}function Ri(e,t){return Bi(e).pipe(vn(()=>{let n=Wr(e);return!n||Oe(n.dateGroupContext,t)}))}function zi(e,t){return Bi(e).pipe(vn(()=>{let n=Wr(e);return(n==null?void 0:n.dateGroupContext.currentDateType)===t}))}function Bi(e){let t=e.get(M),n=()=>{var t;let n=Nt(e.get(F)),r=(t=e.get(wt).getCurrentLastSelection())==null?void 0:t.primary;if(!n||!r)return;let{unitId:i,subUnitId:a}=n,o=e.get(j).getPivotTableIdByCell(i,a,r.startRow,r.startColumn);return o?{unitId:i,subUnitId:a,pivotTableId:o}:void 0};return yn(e.get(wt).selectionMoveEnd$,t.pivotConfigChange$.pipe(_n(e=>{let t=n();return(t==null?void 0:t.unitId)===e.unitId&&t.subUnitId===e.subUnitId&&t.pivotTableId===e.pivotTableId})),t.collectionChange$.pipe(_n(e=>{let r=n();if(!r||!e.pivotTableIds.includes(r.pivotTableId))return!1;let i=t.getPivotTableConfig(r.unitId,r.subUnitId,r.pivotTableId);return e.unitId===((i==null?void 0:i.sourceRangeInfo.unitId)??r.unitId)}))).pipe(Sn(null))}const Vi=ee.map(e=>({dateType:e,id:Ii(e),menuItemFactory:Fi(e)}));function Hi(e){return{id:Ti,type:Ht.SUBITEMS,title:`sheets-pivot-ui.showValuesAs.title`,hidden$:Gi(e).pipe(vn(()=>!di(e)))}}function Ui(e){return t=>({id:Wi(e.type),commandId:li.id,type:Ht.BUTTON,title:e.localeKey,params:{type:e.type},activated$:Gi(t).pipe(vn(()=>{let n=di(t);return!!(n&&(n.currentShowDataAs.type??u.normal)===e.type)}))})}function Wi(e){return`sheet.pivot.context-menu.show-data-as.${e}`}function Gi(e){return e.get(wt).selectionMoveEnd$.pipe(Sn(null))}const Ki=ci.map(e=>({rule:e,id:Wi(e.type),menuItemFactory:Ui(e)}));function qi(e){return{id:Ei,commandId:vi.id,type:Ht.BUTTON,title:`sheets-pivot-ui.valueFilter.title`,hidden$:e.get(wt).selectionMoveEnd$.pipe(Sn(null),vn(()=>!_i(e)))}}const Ji=Vi.reduce((e,t,n)=>(e[t.id]={order:n+1,menuItemFactory:t.menuItemFactory},e),{}),Yi=Ki.reduce((e,t,n)=>(e[t.id]={order:n+1,menuItemFactory:t.menuItemFactory},e),{}),Xi={[Ut.ORGANIZATION]:{[Vr.id]:{order:1,gridLayout:{row:2,column:1},menuItemFactory:Oi}},[Lt.MAIN_AREA]:{[It.DATA]:{[Vr.id]:{order:1,menuItemFactory:Oi},[yi]:{order:2,menuItemFactory:ki,...Ji},[bi]:{order:3,menuItemFactory:Ai},[xi]:{order:4,menuItemFactory:ji},[Si]:{order:5,menuItemFactory:Mi},[Ci]:{order:6,menuItemFactory:Ni},[wi]:{order:7,menuItemFactory:Pi},[Ti]:{order:8,menuItemFactory:Hi,...Yi},[Ei]:{order:9,menuItemFactory:qi}}},[Lt.COL_HEADER]:{[It.DATA]:{[Vr.id]:{order:1,menuItemFactory:Oi},[yi]:{order:2,menuItemFactory:ki,...Ji},[bi]:{order:3,menuItemFactory:Ai},[xi]:{order:4,menuItemFactory:ji},[Si]:{order:5,menuItemFactory:Mi},[Ci]:{order:6,menuItemFactory:Ni},[wi]:{order:7,menuItemFactory:Pi}}}};var Zi=`@univerjs-pro/sheets-pivot-ui`,Qi=`1.5.2`;const $i={type:Ie.OPERATION,id:`sheet.operation.open-pivot-table-filter-panel`,async handler(e,t){if(!t)return!1;let{row:n,col:r,unitId:i,subUnitId:a,tableFieldId:o,pivotTableId:s}=t,c=e.get(j),l=s||c.getPivotTableIdByCell(i,a,n,r);if(!l)return!1;let u=e.get(ye),d=c.getPivotItemRenderInfoCache(i,a,l);if(!(d!=null&&d.rangesInfo))return!1;let f=c.getPivotTableCellData(i,a,n,r),p=(await u.getPivotDisplayConfig({unitId:i,subUnitId:a,pivotTableId:l,params:{type:k.Filter,filter:{row:n,col:r,tableFieldId:o,cellData:f,pivotItemRenderInfoCache:d}}})).result.filter;if(!p)return!1;let m=e.get(R),h={id:Or,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:Dr,unitId:i,subUnitId:a,key:`${n}-${r}-${o||``}`,filterItemInfo:p},onClose:()=>{m.close(Or)}};return m.open(h),!0}},ea={type:Ie.OPERATION,id:`sheet.operation.open-pivot-table-field-setting-panel`,handler(e,t){if(!t)return!1;let n=e.get(L),{tableFieldId:r,pivotTableId:i,unitId:a,subUnitId:o,tableFieldInfo:s,dataFieldInfo:c}=t,l=e.get(R),u={id:Ar,title:{title:n.t(`sheets-pivot-ui.fieldSettings`)},draggable:!0,mask:!1,maskClosable:!1,width:400,children:{label:kr,tableFieldId:r,pivotTableId:i,tableFieldInfo:s,dataFieldInfo:c,unitId:a,subUnitId:o,version:Math.random(),key:`field-setting-${r||``}`,closeFn:()=>{l.close(Ar)}},onClose:()=>{l.close(Ar)}};return l.open(u),!0}};function ta(e,t,n){let r=n.fieldIds,{fieldsConfig:i}=t,{rowFields:a,columnFields:o,valueFields:s,filterFields:c,hiddenFields:l,dimension:u,measure:d,valueIndex:f,valuePosition:p}=i,h=/* @__PURE__ */ new Set;[...a,...o,...s,...c,...l].forEach(e=>{let t=u[e]||d[e];t&&h.add(t.dataFieldId)});let g=r.map(t=>{let r=n.fields[t];return{checked:h.has(t),dataFieldId:r.id,id:r.id,name:r.name,type:r.fieldDataType,pivotTableId:e}}),_=a.flatMap(e=>{let t=u[e];return t?[{dataFieldId:t.dataFieldId,tableFieldId:t.id,displayName:t.displayName}]:[]}),v=o.flatMap(e=>{let t=u[e];return t?[{dataFieldId:t.dataFieldId,tableFieldId:t.id,displayName:t.displayName}]:[]}),y=s.flatMap(e=>{let t=d[e];return t?[{dataFieldId:t.dataFieldId,tableFieldId:t.id,displayName:t.displayName,format:t.format,subTotalType:t.subtotal}]:[]}),b=c.flatMap(e=>{let t=u[e];return t?[{dataFieldId:t.dataFieldId,tableFieldId:t.id,displayName:t.displayName}]:[]}),x=l.flatMap(e=>{let t=u[e];return t?[{dataFieldId:t.dataFieldId,tableFieldId:t.id,displayName:t.displayName,filterInfo:t.filterInfo}]:[]});return y.length>1&&(p===m.Row?_:v).splice(f,0,{dataFieldId:``,tableFieldId:`PivotMultipleValueId`,displayName:`ΣValue`}),{sourceList:g,sourceRange:t.sourceRangeInfo,rowFields:_,columnFields:v,valueFields:y,filterFields:b,hiddenFields:x,positionInfo:t.targetCellInfo}}const na={type:Ie.OPERATION,id:`sheet.operation.open-pivot-table-panel`,async handler(e,t){let n=t==null?void 0:t.pivotTableId;if(!n)return!1;let r=e.get(Bt),i=e.get(F),a=e.get(L),o=e.get(M),s=Nt(i);if(!s)return!1;let{unitId:c,subUnitId:l}=s,u=o.getPivotTableConfig(c,l,n),d=o.getCollection(c,n);if(!u||!d)return!1;let f=ta(n,u,d),p={header:{title:a.t(`sheets-pivot-ui.title`)},id:Er,children:{label:Tr,panelInfo:f,version:Math.random(),setVersion:()=>Math.random(),pivotTableId:n,unitId:c,subUnitId:l},width:346};return r.open(p),!0}},ra=`sheets-pivot-ui.config`,ia={};function aa(e){"@babel/helpers - typeof";return aa=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},aa(e)}function oa(e,t){if(aa(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(aa(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function sa(e){var t=oa(e,`string`);return aa(t)==`symbol`?t:t+``}function X(e,t,n){return(t=sa(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Z(e,t){return function(n,r){t(n,r,e)}}function Q(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 ca=class extends N{constructor(e,t,n,r,i,a,o,s){var c;super(),this._localeService=e,this._sheetInterceptorService=t,this._injector=n,this._confirmService=r,this._sheetsPivotTableService=i,this._configService=a,this._sheetPermissionCheckController=o,this._sheetsRenderService=s,X(this,`_defaultOverride`,!1),this.disposeWithMe(this._sheetsRenderService.registerSelfRenderingMutations(D.id)),this._initUIInterceptListener(),this._defaultOverride=((c=this._configService.getConfig(oe))==null?void 0:c.defaultOverride)??!1}_getPivotAppliedRanges(e,t,n){return Ee(e,t,n,this._localeService.getDirection())}_initUIInterceptListener(){this._sheetsPivotTableService.asyncInterceptor.interceptAsync(this._sheetsPivotTableService.asyncInterceptor.getInterceptPoints().PIVOT_PERFORM_CHECK,{handler:async(e,t)=>{let{cellInfo:n,view:r,isEmpty:i}=t,{unitId:a,subUnitId:o}=n,s=this._getPivotAppliedRanges(n,r,i);if(!jt(this._injector,a,o,s)){let e=this._localeService.t(`sheets-pivot-ui.msg.permissionError`);this._sheetPermissionCheckController.blockExecuteWithoutPermission(e)}let c=this._sheetInterceptorService.generateMutationsByRanges({unitId:a,subUnitId:o,ranges:s}),l=Te(this._injector,a,o,s);if(c.redos.length||l.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)}})}};ca=Q([Z(0,I(L)),Z(1,I(St)),Z(2,I(Ke)),Z(3,I(Ue)),Z(4,I(be)),Z(5,I(He)),Z(6,I(Ct)),Z(7,I(nn))],ca);function la(e){let{editable:t,pivotTableId:n,subUnitId:r,unitId:i}=e,a=z(P),o=z(R),s=z(L),c=[{command:{id:na.id,params:{pivotTableId:n}},disabled:!t,label:`sheets-pivot-ui.mobile.edit`},{command:{id:ie.id,params:{unitId:i,subUnitId:r,pivotTableId:n}},disabled:!t,label:`sheets-pivot-ui.mobile.delete`}];async function l(e){await a.executeCommand(e.id,e.params),o.close(Br)}return/* @__PURE__ */ W(`div`,{className:`univer-flex univer-flex-col univer-gap-2`,children:c.map(e=>{let t=s.t(e.label);return/* @__PURE__ */ W(Mn,{title:t,"aria-label":t,variant:`subtle`,disabled:e.disabled,onClick:()=>l(e.command)},e.command.id)})})}const ua=[{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`}],da=[{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`}],fa=[{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`}],pa=`PivotMultipleValueId`;function ma(t,r){if(r===n.blank)return`sheets-pivot-ui.dialog.filter.blank`;if(r===n.other&&t===e.otherDataKey)return`sheets-pivot-ui.showValuesAs.other`}function ha(e,t){let n=ke(t,e);return e.includes(`{0}`)?e.replace(`{0}`,n):`${e}${n}`}const ga=e=>{switch(e){case`filter`:return p.Filter;case`row`:return p.Row;case`column`:return p.Column;case`value`:return p.Value;default:return p.Row}};function _a(e,t){switch(t.rangeType||Ye.NORMAL){case Ye.NORMAL:return{startRow:t.startRow,startColumn:t.startColumn,endRow:t.endRow,endColumn:t.endColumn};case Ye.ROW:return{startRow:t.startRow,startColumn:0,endRow:t.endRow,endColumn:e.getColumnCount()-1};case Ye.COLUMN:return{startRow:0,startColumn:t.startColumn,endRow:e.getRowCount()-1,endColumn:t.endColumn};case Ye.ALL:return{startRow:0,startColumn:0,endRow:e.getRowCount()-1,endColumn:e.getColumnCount()-1}}}function va(e,t){if(!t||!e||t.endRow-t.startRow<=0)return 1;let{startRow:n,startColumn:r,endRow:i,endColumn:a}=_a(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 ya(e,t,n){let{commandService:r,pivotTableInfo:i,pivotTableId:a,unitId:o,subUnitId:s}=e,c=[],{rowFields:l,columnFields:u,filterFields:d,valueFields:f}=i,p=[...l,...u,...d,...f];t===`PivotMultipleValueId`&&f.forEach(e=>{c.push(e.tableFieldId)}),n===`source`&&p.forEach(e=>{e.dataFieldId===t&&c.push(e.tableFieldId)}),n!==`source`&&p.find(e=>e.tableFieldId===t)&&c.push(t),await r.executeCommand(re.id,{pivotTableId:a,fieldIds:c,unitId:o,subUnitId:s})}async function ba(e,t,n,r,i){let a={unitId:r,subUnitId:i,token:t,dataRangeInfo:n};await e.executeCommand(Ce.id,a)}const xa=(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 Sa(e,t,n,r,i){if(n===`source`&&r===`source`)return;let a=t===pa,{commandService:o,pivotTableInfo:s,pivotTableId:c,unitId:l,subUnitId:u}=e;if(n===`source`&&r!==`source`){let{sourceList:e}=s,n=e.find(e=>e.id===t);if(n){let e=xa(s,t);if(r!==`value`&&e.length>0){let t=e[0];await o.executeCommand(O.id,{pivotTableId:c,fieldId:t,area:ga(r),index:i,unitId:l,subUnitId:u})}else await o.executeCommand(T.id,{pivotTableId:c,dataFieldId:n.dataFieldId,fieldArea:ga(r),index:i,unitId:l,subUnitId:u})}}if(n!==`source`&&r===`source`){let{rowFields:n,columnFields:r,filterFields:i,valueFields:o}=s,c=[...n,...r,...i,...o],l=[];a?o.forEach(e=>{l.push(e.tableFieldId)}):c.find(e=>e.tableFieldId===t)&&l.push(t),await Ca(e,l)}else n!==`source`&&r!==`source`&&await Ta(e,t,n,r,i)}async function Ca(e,t){let{commandService:n,pivotTableId:r,unitId:i,subUnitId:a}=e;await n.executeCommand(re.id,{pivotTableId:r,fieldIds:t,unitId:i,subUnitId:a})}async function wa(e,t,n){let{commandService:r,pivotTableId:i,unitId:a,subUnitId:o}=e;await r.executeCommand(we.id,{pivotTableId:i,position:t,index:n,unitId:a,subUnitId:o})}async function Ta(e,t,n,r,i){let a=t===pa,{commandService:o,pivotTableInfo:s,pivotTableId:c,unitId:l,subUnitId:u}=e;if(a){let e=ga(r);(e===p.Row||e===p.Column)&&await o.executeCommand(we.id,{pivotTableId:c,position:e===p.Row?m.Row:m.Column,index:i,unitId:l,subUnitId:u});return}let{rowFields:d,columnFields:f,filterFields:h,valueFields:g}=s,_=[...d,...f,...h,...g].find(e=>e.tableFieldId===t);if(_){let a=[...d,...f,...h];if(n===`value`&&r!==`value`&&a.find(e=>e.dataFieldId===_.dataFieldId)){await Ca(e,[t]);return}await o.executeCommand(O.id,{pivotTableId:c,fieldId:t,area:ga(r),index:i,unitId:l,subUnitId:u})}}function Ea(e,t,n,r,i){e.executeCommand($i.id,{row:-1,col:-1,unitId:t,subUnitId:n,tableFieldId:i,pivotTableId:r})}function Da(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(ea.id,a)}}const Oa=[{type:f.average,textKey:`sheets-pivot-ui.subtotal.average`},{type:f.count,textKey:`sheets-pivot-ui.subtotal.count`},{type:f.countNums,textKey:`sheets-pivot-ui.subtotal.countNums`},{type:f.max,textKey:`sheets-pivot-ui.subtotal.max`},{type:f.min,textKey:`sheets-pivot-ui.subtotal.min`},{type:f.product,textKey:`sheets-pivot-ui.subtotal.product`},{type:f.stdDev,textKey:`sheets-pivot-ui.subtotal.stdDev`},{type:f.stdDevp,textKey:`sheets-pivot-ui.subtotal.stdDevp`},{type:f.sum,textKey:`sheets-pivot-ui.subtotal.sum`},{type:f.var,textKey:`sheets-pivot-ui.subtotal.var`},{type:f.varp,textKey:`sheets-pivot-ui.subtotal.varp`}],ka=(e,t=0)=>e?ut.getFormatInfo(e).maxDecimals??t:t,Aa=e=>Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(``),$=(e,t)=>e.split(`;`).map(e=>/\.0?/.test(e)?e.replace(/\.0*/g,`${t>0?`.`:``}${Aa(Number(t||0))}`):/0[^0]?/.test(e)?e.replace(/0[^0]+|0$/,`0${t>0?`.`:``}${Aa(Number(t||0))}`):e).join(`;`),ja=e=>nt.find(t=>e.includes(t)),Ma=e=>!e,Na=e=>!!ja(e)&&e.startsWith(`_(`),Pa=e=>!!ja(e)&&!e.startsWith(`_(`),Fa=()=>ua.map(e=>({label:e.label,value:e.suffix})),Ia=e=>{let t=ut.getFormatInfo(e);return Fa().map(e=>e.value).includes(e)||[`date`,`datetime`,`time`].includes(t.type)},La=()=>da.map(e=>({label:e.label,value:e.suffix,color:e.color})),Ra=e=>La().some(t=>st(t.value,e)),za=(e,t)=>{switch(t){case p.Row:return e.rowFields.length;case p.Column:return e.columnFields.length;case p.Filter:return e.filterFields.length;case p.Value:return e.valueFields.length;default:return 0}},Ba=(e,t,n)=>{for(let r 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 i=n[r];if(i+ke(e,i)===t||i+e===t)return!0}return!1},Va=(e,t,n)=>{let r=``;switch(n){case f.average:r=t[`sheets-pivot-ui.averageName`];break;case f.count:r=t[`sheets-pivot-ui.countName`];break;case f.countNums:r=t[`sheets-pivot-ui.countNumsName`];break;case f.max:r=t[`sheets-pivot-ui.maxName`];break;case f.min:r=t[`sheets-pivot-ui.minName`];break;case f.product:r=t[`sheets-pivot-ui.productName`];break;case f.stdDev:r=t[`sheets-pivot-ui.stdDevName`];break;case f.stdDevp:r=t[`sheets-pivot-ui.stdDevpName`];break;case f.sum:r=t[`sheets-pivot-ui.sumName`];break;case f.var:r=t[`sheets-pivot-ui.varName`];break;case f.varp:r=t[`sheets-pivot-ui.varpName`];break;default:return e}return r+ke(e,r)};function Ha(e,t){if(t.conditionFilter&&C(t.conditionFilter))return`HasFilter`;if(!e)return`NotFilter`;if(S(e))return`HasFilter`;if(x(e)){var n;return e.isAll||((n=t.items)==null?void 0:n.length)===e.list.length?`NotFilter`:`HasFilter`}return C(e)?`HasFilter`:`NotFilter`}function Ua(e){return Na(e)?`accounting`:Pa(e)?`currency`:Ia(e)?`date`:Ra(e)?`thousandthPercentile`:`general`}function Wa(e){let{originPattern:t=``,onChange:n}=e,r=z(L),[i,a]=Y(()=>Ua(t)),[o,s]=Y(()=>ka(t,2)),[c,l]=Y(()=>ja(t)||nt[0]),[u,d]=Y(t),f=_r(()=>[{value:`general`,label:r.t(`sheets-pivot-ui.dialog.numfmt.general`)},{value:`accounting`,label:r.t(`sheets-pivot-ui.dialog.numfmt.accounting`)},{value:`currency`,label:r.t(`sheets-pivot-ui.dialog.numfmt.currency`)},{value:`date`,label:r.t(`sheets-pivot-ui.dialog.numfmt.date`)},{value:`thousandthPercentile`,label:r.t(`sheets-pivot-ui.dialog.numfmt.thousandthPercentile`)}],[r]),p=nt.map(e=>({label:e,value:e}));function m(e){d(e),n(e)}function h(e,t){return $(`_("${e}"* #,##0${t>0?`.0`:``}_)`,t)}function g(e){a(e),m(e===`general`?``:e===`accounting`?h(c,o):e===`currency`?$(fa[0].suffix(c),o):e===`date`?ua[0].suffix:$(da[0].suffix,o))}function _(e){l(e),m(i===`accounting`?h(e,o):$(fa[0].suffix(e),o))}function v(e){let t=e??0;s(t),m(i===`accounting`?h(c,t):$(u,t))}let y=fa.map(e=>({label:e.label(c),value:e.suffix(c),color:e.color})),b=da.map(e=>({label:e.label,value:e.suffix,color:e.color})),x=ua.map(e=>({label:e.label,value:e.suffix}));return/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,children:[/* @__PURE__ */ G(`div`,{children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:r.t(`sheets-pivot-ui.dialog.numfmt.formatTypes`)}),/* @__PURE__ */ W(Fn,{className:`univer-w-full`,value:i,options:f,onChange:e=>g(e),size:`small`})]}),(i===`accounting`||i===`currency`)&&/* @__PURE__ */ G(`div`,{className:`univer-grid univer-grid-cols-2 univer-gap-3`,children:[/* @__PURE__ */ G(`div`,{children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:r.t(`sheets-pivot-ui.dialog.numfmt.decimalPlaces`)}),/* @__PURE__ */ W(An,{className:`univer-w-full`,value:o,min:0,max:20,onChange:v,size:`small`,controls:!1})]}),/* @__PURE__ */ G(`div`,{children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:r.t(`sheets-pivot-ui.dialog.numfmt.currencyTypes`)}),/* @__PURE__ */ W(Fn,{className:`univer-w-full`,value:c,options:p,onChange:_,size:`small`})]})]}),i===`thousandthPercentile`&&/* @__PURE__ */ G(`div`,{children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:r.t(`sheets-pivot-ui.dialog.numfmt.decimalPlaces`)}),/* @__PURE__ */ W(An,{className:`univer-w-full`,value:o,min:0,max:20,onChange:v,size:`small`,controls:!1})]}),i===`currency`&&/* @__PURE__ */ W(Bn,{className:`univer-rounded-xl univer-p-2`,options:y,value:u,onChange:e=>m($(e,o))}),i===`date`&&/* @__PURE__ */ W(Bn,{className:`univer-rounded-xl univer-p-2`,options:x,value:u,onChange:e=>m(e)}),i===`thousandthPercentile`&&/* @__PURE__ */ W(Bn,{className:`univer-rounded-xl univer-p-2`,options:b,value:u,onChange:e=>m($(e,o))}),/* @__PURE__ */ W(`div`,{className:`univer-text-sm univer-text-gray-500`,children:r.t(`sheets-pivot-ui.dialog.numfmt.${i}Desc`)})]})}function Ga(e){let{unitId:t,subUnitId:n,pivotTableId:r,tableFieldId:i,originPattern:a,tableFieldInfo:o,dataFieldInfo:s}=e,c=z(P),l=z(R),u=z(L),[d,f]=Y(a??``);async function p(){let e={format:d,tableFieldId:i,pivotTableId:r,unitId:t,subUnitId:n,tableFieldInfo:o,dataFieldInfo:s};await c.executeCommand(Se.id,e),l.close(Mr)}return/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-5`,dir:u.getDirection(),children:[/* @__PURE__ */ W(Wa,{originPattern:a,onChange:f}),/* @__PURE__ */ G(Nn,{children:[/* @__PURE__ */ W(V,{onClick:()=>l.close(Mr),size:`middle`,children:u.t(`sheets-pivot-ui.dialog.numfmt.cancel`)}),/* @__PURE__ */ W(V,{variant:`primary`,onClick:p,size:`middle`,children:u.t(`sheets-pivot-ui.dialog.numfmt.confirm`)})]})]})}function Ka(e){let{unitId:t,subUnitId:n,pivotTableId:r,tableFieldId:i,tableFieldInfo:a,dataFieldInfo:o,closeFn:s,format:c,version:l}=e,u=z(P),d=z(M),f=z(L),[p,m]=Y(`field`),[h,g]=Y(a.displayName),[_,v]=Y(a.subTotalType),[y,b]=Y(c??a.format??``),[x,S]=Y(y);q(()=>{m(`field`),g(a.displayName),v(a.subTotalType),b(c??a.format??``),S(c??a.format??``)},[c,a,l]);let C={...d.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=>{C[e]=f.t(e)});function w(e){v(e),Ba(o.name,h,C)&&g(Va(o.name,C,e))}async function T(){let e={displayName:a.displayName===h?void 0:h,subtotalType:a.subTotalType===_?void 0:_,format:a.format===y?void 0:y,tableFieldId:i,pivotTableId:r,unitId:t,subUnitId:n,tableFieldInfo:a,dataFieldInfo:o};await u.executeCommand(Se.id,e),s()}return p===`format`?/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-5`,dir:f.getDirection(),children:[/* @__PURE__ */ G(`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:()=>m(`field`),children:[/* @__PURE__ */ W(Qn,{}),f.t(`sheets-pivot-ui.dialog.numfmt.fieldSetting`)]}),/* @__PURE__ */ W(Wa,{originPattern:y,onChange:S}),/* @__PURE__ */ G(Nn,{children:[/* @__PURE__ */ W(V,{onClick:()=>m(`field`),size:`middle`,children:f.t(`sheets-pivot-ui.dialog.numfmt.cancel`)}),/* @__PURE__ */ W(V,{variant:`primary`,onClick:()=>{b(x),m(`field`)},size:`middle`,children:f.t(`sheets-pivot-ui.dialog.numfmt.confirm`)})]})]}):/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,dir:f.getDirection(),children:[/* @__PURE__ */ G(`div`,{children:[/* @__PURE__ */ G(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-sm univer-font-medium`,children:f.t(`sheets-pivot-ui.dialog.fieldName`)}),/* @__PURE__ */ W(`span`,{className:`univer-truncate univer-text-xs univer-text-gray-500`,children:ha(f.t(`sheets-pivot-ui.dialog.sourceName`),o.name)})]}),/* @__PURE__ */ W(kn,{className:`univer-mt-2 univer-w-full`,value:h,onChange:g,size:`small`})]}),/* @__PURE__ */ G(`div`,{children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:f.t(`sheets-pivot-ui.dialog.summarizeBy`)}),/* @__PURE__ */ W(`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:Oa.map(e=>/* @__PURE__ */ G(`button`,{type:`button`,className:U(`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":_===e.type}),onClick:()=>w(e.type),children:[/* @__PURE__ */ W(tr,{className:U(`univer-text-primary-600`,{"univer-invisible":_!==e.type})}),f.t(e.textKey)]},e.type))})]}),/* @__PURE__ */ W(V,{className:`univer-w-full`,onClick:()=>{S(y),m(`format`)},size:`middle`,children:f.t(`sheets-pivot-ui.dialog.format`)}),/* @__PURE__ */ G(Nn,{children:[/* @__PURE__ */ W(V,{onClick:s,size:`middle`,children:f.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ W(V,{variant:`primary`,disabled:!h,onClick:T,size:`middle`,children:f.t(`sheets-pivot-ui.dialog.ok`)})]})]})}function qa(e){var t;let{filterItemInfo:i,unitId:a,subUnitId:o}=e,s=z(P),c=z(R),l=z(L),u=z(F),d=B(l.direction$,l.getDirection()),[f,p]=Y(()=>{var e;return i.checkedItems??((e=i.filterInfo)==null?void 0:e.list)??i.items}),[m,h]=Y(()=>i.partialItems??[]),[g,_]=Y((t=i.sortInfo)==null?void 0:t.type),v=m.length===0&&f.length===i.items.length,y=Ha(i.filterInfo,{items:i.items,conditionFilter:i.conditionFilter});q(()=>{let e=u.getCurrentUnitOfType(et.UNIVER_SHEET);if(!e)return;let t=e.activeSheet$.subscribe(e=>{(e==null?void 0:e.getSheetId())!==o&&c.close(Or)});return()=>t.unsubscribe()},[c,o,u]);function b(){c.close(Or)}function x(e){m.includes(e)?(h(t=>t.filter(t=>t!==e)),p(t=>[...t,e])):p(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])}async function S(e,t,n,r=!1){await s.executeCommand(fe.id,{unitId:a,subUnitId:o,pivotTableId:i.pivotTableId,tableFieldId:i.tableFieldId,items:e,partialItems:n,isAll:t,clearAllFilters:r}),b()}async function C(e){await s.executeCommand(_e.id,{unitId:a,subUnitId:o,pivotTableId:i.pivotTableId,tableFieldId:i.tableFieldId,info:{type:e}}),_(e),b()}return/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,dir:d,children:[/* @__PURE__ */ W(`div`,{className:`univer-text-base univer-font-semibold`,children:l.t(`sheets-pivot-ui.filterField`)}),/* @__PURE__ */ G(`div`,{className:`univer-grid univer-grid-cols-2 univer-gap-2`,children:[/* @__PURE__ */ G(V,{className:U(``,{"univer-bg-gray-100 dark:!univer-bg-gray-700":g===r.ascending}),onClick:()=>C(r.ascending),size:`middle`,children:[/* @__PURE__ */ W($n,{}),l.t(`sheets-pivot-ui.dialog.filter.ascending`)]}),/* @__PURE__ */ G(V,{className:U(``,{"univer-bg-gray-100 dark:!univer-bg-gray-700":g===r.descending}),onClick:()=>C(r.descending),size:`middle`,children:[/* @__PURE__ */ W(rr,{}),l.t(`sheets-pivot-ui.dialog.filter.descending`)]})]}),/* @__PURE__ */ G(`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__ */ W(`div`,{className:`univer-flex univer-min-h-12 univer-items-center univer-px-2`,children:/* @__PURE__ */ W(H,{checked:v,indeterminate:!v&&(f.length>0||m.length>0),onChange:()=>{h([]),p(v?[]:i.items)},children:l.t(`sheets-pivot-ui.dialog.filter.selectAll`)})}),i.items.map((e,t)=>{var r;let a=i.itemTypes[t],o=(r=i.itemLabels)==null?void 0:r[e],s=ma(e,a),c=e;return s?c=l.t(s):o===void 0?a===n.date&&i.format&&(c=ut.format(i.format,Number(e))):c=o,/* @__PURE__ */ W(`div`,{className:`univer-flex univer-min-h-12 univer-items-center univer-px-2`,children:/* @__PURE__ */ W(H,{checked:f.includes(e),indeterminate:m.includes(e),contentClassName:`univer-max-w-[70vw] univer-truncate`,onChange:()=>x(e),children:c})},e)})]}),/* @__PURE__ */ W(V,{className:`univer-w-full`,variant:`link`,disabled:y===`NotFilter`,onClick:()=>S(i.items,!0,[],!0),size:`middle`,children:l.t(`sheets-pivot-ui.dialog.filter.clearFilter`)}),/* @__PURE__ */ G(Nn,{children:[/* @__PURE__ */ W(V,{onClick:b,size:`middle`,children:l.t(`sheets-pivot-ui.dialog.filter.cancel`)}),/* @__PURE__ */ W(V,{variant:`primary`,disabled:!f.length&&!m.length,onClick:()=>S(f,v,m),size:`middle`,children:l.t(`sheets-pivot-ui.dialog.filter.confirm`)})]})]})}const Ja=[{label:`sheets-pivot-ui.config.pageDownThenOver`,value:`false`},{label:`sheets-pivot-ui.config.pageOverThenDown`,value:`true`}],Ya=[{label:`sheets-pivot-ui.config.layoutTabular`,value:String(c.tabular)},{label:`sheets-pivot-ui.config.layoutCompact`,value:String(c.compact)},{label:`sheets-pivot-ui.config.layoutOutline`,value:String(c.outline)}],Xa=[{label:`sheets-pivot-ui.config.rowSubtotalTop`,value:String(d.top)},{label:`sheets-pivot-ui.config.rowSubtotalBottom`,value:String(d.bottom)}],Za=[{label:`sheets-pivot-ui.config.dateGroupingLegacy`,value:a.Legacy},{label:`sheets-pivot-ui.config.dateGroupingExcelLike`,value:a.ExcelLike}];function Qa(e){let{unitId:t,subUnitId:n,pivotTableId:r}=e,i=z(P),a=z(Ue),o=z(We),s=z(L),l=z(M),u=_r(()=>l.watchPivotTableChanges(t,n,r).pipe(hn(0)),[l,t,n,r]);B(u);let[f,p]=Y(!1),m=J(!1),h=l.getPivotTableConfig(t,n,r),g=v(h==null?void 0:h.fieldsConfig.options),[_,y]=Y(()=>{var e,i;let a=l.getPivotTableConfig(t,n,r),o=(a==null||(e=a.fieldsConfig)==null?void 0:e.options)??{};return{showRowSubtotal:o.showRowSubtotal??!0,showRowGrandTotal:o.showRowGrandTotal??!0,showColSubtotal:o.showColSubtotal??!0,showColGrandTotal:o.showColGrandTotal??!0,pageWrap:o.pageWrap??1,pageOverThenDown:o.pageOverThenDown??!1,repeatRowLabels:o.repeatRowLabels??!1,repeatColLabels:o.repeatColLabels??!1,layout:(a==null||(i=a.fieldsConfig)==null?void 0:i.layout)??c.tabular,rowSubtotalPosition:o.rowSubtotalPosition??d.top}});function x(e){let a={unitId:t,subUnitId:n,pivotTableId:r,options:e};return y(t=>({...t,...e})),i.executeCommand(ge.id,a).catch(e=>o.error(`[MobilePivotConfigPanel]`,e))}function S(e){let a={unitId:t,subUnitId:n,pivotTableId:r,layout:e};return y(t=>({...t,layout:e})),i.executeCommand(pe.id,a).catch(e=>o.error(`[MobilePivotConfigPanel]`,e))}async function C(e){if(!(m.current||e===g)){m.current=!0,p(!0);try{let o=l.getPivotTableConfig(t,n,r),c=l.getCollection(t,r);if(!o||!c||(Object.values(c.fields).some(b)||c.customFields.some(b))&&!await a.confirm({id:`sheet-pivot.confirm.change-date-grouping-mode`,title:{title:s.t(`sheets-pivot-ui.config.dateGroupingSwitchTitle`)},children:{title:s.t(`sheets-pivot-ui.config.dateGroupingSwitchMessage`)},cancelText:s.t(`sheets-pivot-ui.dialog.cancel`),confirmText:s.t(`sheets-pivot-ui.dialog.ok`)})||l.getPivotTableConfig(t,n,r)!==o||l.getCollection(t,r)!==c||v(o.fieldsConfig.options)===e)return;await i.executeCommand(ge.id,{unitId:t,subUnitId:n,pivotTableId:r,options:{dateGroupingMode:e}})}catch(e){o.error(`[MobilePivotConfigPanel]`,e)}finally{m.current=!1,p(!1)}}}let w=e=>e.map(e=>({...e,label:s.t(e.label)}));return/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-5 univer-py-4`,children:[/* @__PURE__ */ G(`section`,{className:`univer-flex univer-flex-col univer-gap-3`,children:[/* @__PURE__ */ W(`div`,{className:`univer-text-sm univer-font-medium univer-text-gray-600`,children:s.t(`sheets-pivot-ui.config.displaySection`)}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-min-h-10 univer-items-center univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-sm`,children:s.t(`sheets-pivot-ui.config.dateGroupingMode`)}),/* @__PURE__ */ W(Fn,{className:`univer-w-40`,value:g,options:w(Za),disabled:f,onChange:e=>C(e),size:`small`})]}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-min-h-10 univer-items-center univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-sm`,children:s.t(`sheets-pivot-ui.config.layout`)}),/* @__PURE__ */ W(Fn,{className:`univer-w-40`,value:String(_.layout),options:w(Ya),onChange:e=>S(Number(e)),size:`small`})]}),/* @__PURE__ */ W(H,{checked:_.repeatRowLabels,disabled:_.layout===c.compact,onChange:e=>x({repeatRowLabels:!!e}),children:s.t(`sheets-pivot-ui.config.repeatRowLabels`)}),/* @__PURE__ */ W(H,{checked:_.repeatColLabels,onChange:e=>x({repeatColLabels:!!e}),children:s.t(`sheets-pivot-ui.config.repeatColLabels`)})]}),/* @__PURE__ */ G(`section`,{className:`univer-flex univer-flex-col univer-gap-3`,children:[/* @__PURE__ */ W(`div`,{className:`univer-text-sm univer-font-medium univer-text-gray-600`,children:s.t(`sheets-pivot-ui.config.totalsSection`)}),/* @__PURE__ */ W(H,{checked:_.showRowSubtotal,onChange:e=>x({showRowSubtotal:!!e}),children:s.t(`sheets-pivot-ui.config.showRowSubtotal`)}),_.layout===c.outline&&/* @__PURE__ */ G(`div`,{className:`univer-flex univer-min-h-10 univer-items-center univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-sm`,children:s.t(`sheets-pivot-ui.config.rowSubtotalPosition`)}),/* @__PURE__ */ W(Fn,{className:`univer-w-40`,value:String(_.rowSubtotalPosition),options:w(Xa),onChange:e=>x({rowSubtotalPosition:Number(e)}),size:`small`})]}),/* @__PURE__ */ W(H,{checked:_.showRowGrandTotal,onChange:e=>x({showRowGrandTotal:!!e}),children:s.t(`sheets-pivot-ui.config.showRowGrandTotal`)}),/* @__PURE__ */ W(H,{checked:_.showColSubtotal,onChange:e=>x({showColSubtotal:!!e}),children:s.t(`sheets-pivot-ui.config.showColSubtotal`)}),/* @__PURE__ */ W(H,{checked:_.showColGrandTotal,onChange:e=>x({showColGrandTotal:!!e}),children:s.t(`sheets-pivot-ui.config.showColGrandTotal`)})]}),/* @__PURE__ */ G(`section`,{className:`univer-flex univer-flex-col univer-gap-3`,children:[/* @__PURE__ */ W(`div`,{className:`univer-text-sm univer-font-medium univer-text-gray-600`,children:s.t(`sheets-pivot-ui.config.pageSection`)}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-min-h-10 univer-items-center univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-sm`,children:s.t(`sheets-pivot-ui.config.pageWrap`)}),/* @__PURE__ */ W(An,{className:`univer-w-24`,value:_.pageWrap,min:1,max:20,onChange:e=>{let t=Number(e);return Number.isFinite(t)&&t>=1?x({pageWrap:t}):void 0},size:`small`,controls:!1})]}),/* @__PURE__ */ W(`p`,{className:`univer-text-xs univer-text-gray-600`,children:s.t(_.pageOverThenDown?`sheets-pivot-ui.config.pageWrapOverThenDownHelp`:`sheets-pivot-ui.config.pageWrapDownThenOverHelp`)}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-min-h-10 univer-items-center univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-sm`,children:s.t(`sheets-pivot-ui.config.pageDirection`)}),/* @__PURE__ */ W(Fn,{className:`univer-w-40`,value:String(_.pageOverThenDown),options:w(Ja),onChange:e=>x({pageOverThenDown:e===`true`}),size:`small`})]})]})]})}function $a(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)}const eo=[`filter`,`column`,`row`,`value`];function to(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 no(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 ro(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 io(e){switch(e.area){case`filter`:return/* @__PURE__ */ W(ir,{});case`column`:return/* @__PURE__ */ W(dr,{});case`row`:return/* @__PURE__ */ W(nr,{});default:return/* @__PURE__ */ W(ar,{})}}function ao(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 oo(e){switch(e){case`moveToFilter`:return`filter`;case`moveToColumn`:return`column`;case`moveToRow`:return`row`;case`moveToValue`:return`value`;default:return null}}function so(e){let{area:t,field:n,index:r,fieldCount:i,info:a,pivotTableId:o,unitId:s,subUnitId:c,refresh:l}=e,u=z(P),d=z(L),f=n.tableFieldId===pa,p={pivotTableInfo:a,pivotTableId:o,commandService:u,unitId:s,subUnitId:c};async function m(e){if(e===`filter`){Ea(u,s,c,o,n.tableFieldId);return}if(e===`settings`){Da(u,o,n.tableFieldId,s,c,a);return}if(e===`remove`){await ya(p,n.tableFieldId,t),await l();return}let i=oo(e)??t,d=to(a,i).length;e===`moveUp`?d=r-1:e===`moveDown`&&(d=r+1),await Sa(p,n.tableFieldId,t,i,d),await l()}let h=$a(t,r,i,f).map(e=>({type:`item`,children:d.t(ao(e)),variant:e===`remove`?`destructive`:`default`,onSelect:()=>m(e)}));return/* @__PURE__ */ G(`div`,{className:`univer-flex univer-min-h-12 univer-items-center univer-gap-3 univer-rounded-xl univer-px-3`,children:[/* @__PURE__ */ W(`bdi`,{className:`univer-min-w-0 univer-flex-1 univer-truncate univer-text-sm`,dir:`auto`,children:f?d.t(`sheets-pivot-ui.multipleValue`):n.displayName}),/* @__PURE__ */ W(Pn,{items:h,children:/* @__PURE__ */ W(`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__ */ W(cr,{})})})]})}function co(e){let t=z(L);return/* @__PURE__ */ W(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,children:eo.map(n=>{let r=to(e.info,n);return/* @__PURE__ */ G(`section`,{children:[/* @__PURE__ */ G(`div`,{className:`univer-mb-2 univer-flex univer-items-center univer-gap-2 univer-text-sm univer-font-medium`,children:[/* @__PURE__ */ W(io,{area:n}),t.t(no(n))]}),/* @__PURE__ */ W(`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__ */ W(so,{...e,area:n,field:t,index:i,fieldCount:r.length},t.tableFieldId)):/* @__PURE__ */ W(`div`,{className:`univer-p-4 univer-text-center univer-text-xs univer-text-gray-500`,children:t.t(ro(n))})})]},n)})})}function lo(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 uo(e){let t=`univer-size-4 univer-shrink-0 univer-text-gray-500`;switch(e.type){case n.number:return/* @__PURE__ */ W(lr,{className:t});case n.date:return/* @__PURE__ */ W(er,{className:t});default:return/* @__PURE__ */ W(pr,{className:t})}}function fo(e){let{field:t,info:r,pivotTableId:i,unitId:a,subUnitId:o,refresh:s}=e,c=z(P),l=z(L),u={pivotTableInfo:r,pivotTableId:i,commandService:c,unitId:a,subUnitId:o};async function d(e){if(e){let e=t.type===n.number?`value`:`row`;await Sa(u,t.dataFieldId,`source`,e,lo(r,e))}else await ya(u,t.dataFieldId,`source`);await s()}async function f(e){await Sa(u,t.dataFieldId,`source`,e,lo(r,e)),await s()}let p=[{type:`item`,children:l.t(`sheets-pivot-ui.addToRow`),onSelect:()=>f(`row`)},{type:`item`,children:l.t(`sheets-pivot-ui.addToColumn`),onSelect:()=>f(`column`)},{type:`item`,children:l.t(`sheets-pivot-ui.addToValue`),onSelect:()=>f(`value`)},{type:`item`,children:l.t(`sheets-pivot-ui.addToFilter`),onSelect:()=>f(`filter`)}];return/* @__PURE__ */ G(`div`,{className:`univer-flex univer-min-h-12 univer-items-center univer-gap-3 univer-rounded-xl univer-px-2`,children:[/* @__PURE__ */ W(H,{checked:t.checked,onChange:e=>d(!!e)}),/* @__PURE__ */ W(uo,{type:t.type}),/* @__PURE__ */ W(`bdi`,{className:`univer-min-w-0 univer-flex-1 univer-truncate univer-text-sm`,dir:`auto`,children:t.name}),/* @__PURE__ */ W(Pn,{items:p,children:/* @__PURE__ */ W(`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__ */ W(cr,{})})})]})}function po(e){let{info:t}=e,n=z(L),[r,i]=Y(``),a=r.trim().toLocaleLowerCase(),o=a?t.sourceList.filter(e=>e.name.toLocaleLowerCase().includes(a)):t.sourceList;return/* @__PURE__ */ G(`section`,{className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ G(`div`,{children:[/* @__PURE__ */ W(`div`,{className:`univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.sourceFieldTile`)}),/* @__PURE__ */ W(`div`,{className:`univer-mt-1 univer-text-xs univer-text-gray-500`,children:n.t(`sheets-pivot-ui.mobile.sourceFieldDescription`)})]}),/* @__PURE__ */ W(kn,{allowClear:!0,value:r,placeholder:n.t(`sheets-pivot-ui.searchFieldPlaceholder`),slot:/* @__PURE__ */ W(fr,{}),onChange:i,size:`small`}),/* @__PURE__ */ W(`div`,{className:`univer-rounded-xl univer-bg-gray-50 univer-p-1 dark:!univer-bg-gray-800`,children:o.length?o.map(t=>/* @__PURE__ */ W(fo,{...e,field:t},t.id)):/* @__PURE__ */ W(`div`,{className:`univer-p-4 univer-text-center univer-text-sm univer-text-gray-500`,children:n.t(`sheets-pivot-ui.noMatchingFields`)})})]})}function mo(e){var t;let{sourceRangeInfo:n,positionInfo:r,pivotTableId:i,refresh:a}=e,o=z(P),s=z(We),c=z(L),l=z(F).getUnit(n.unitId),u=(l==null||(t=l.getSheetBySheetId(n.subUnitId))==null?void 0:t.getName())??n.sheetName,[d,f]=Y(n.range),[p,m]=Y(u),[h,g]=Y(``);q(()=>{f(n.range),m(u)},[u,n]);async function _(e){let t=e.split(`,`).filter(Boolean).map(vr)[0];if(!t||!l){g(c.t(`sheets-pivot-ui.msg.emptySourceRange`));return}let s=t.sheetName||n.sheetName,u=l.getSheetBySheetName(s),d=va(u,t.range);if(d!==2||!u){let e=d===0?`sheets-pivot-ui.msg.emptySourceRange`:`sheets-pivot-ui.msg.invalidSize`;g(c.t(e))}else g(``),f(t.range),m(s),await ba(o,i,{unitId:n.unitId,subUnitId:u.getSheetId(),range:t.range,sheetName:s},r.unitId,r.subUnitId),await a()}return/* @__PURE__ */ G(`section`,{children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:c.t(`sheets-pivot-ui.sourceRangeLabel`)}),/* @__PURE__ */ W(xr,{unitId:n.unitId,subUnitId:n.subUnitId,initialValue:br(p,d),maxRangeCount:1,keepSheetReference:!0,supportAcrossSheet:!0,onChange:(e,t)=>_(t).catch(e=>{s.error(`[MobilePivotSourceRange]`,e)})}),h&&/* @__PURE__ */ W(`div`,{className:`univer-mt-2 univer-text-xs univer-text-red-500`,children:h})]})}function ho(e){let{pivotTableId:t,version:n,unitId:r,subUnitId:i,panelInfo:a}=e,o=z(M),s=z(ye),c=z(We),l=_r(()=>o.watchPivotTableChanges(r,i,t).pipe(hn(0)),[o,r,i,t]),u=B(l),[d,f]=Y(a),p=K(async()=>{if(!o.getPivotTableConfig(r,i,t))return;let e=await s.getPivotDisplayConfig({unitId:r,subUnitId:i,pivotTableId:t,params:{type:k.Panel,panel:{pivotTableId:t}}});e.result.panel&&f(e.result.panel)},[o,t,s,i,r]);return q(()=>{p().catch(e=>c.error(`[MobilePivotPanel]`,e))},[u,c,p,n]),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-5 univer-py-4`,children:[/* @__PURE__ */ W(mo,{sourceRangeInfo:d.sourceRange,positionInfo:d.positionInfo,pivotTableId:t,refresh:p}),/* @__PURE__ */ W(po,{info:d,pivotTableId:t,unitId:r,subUnitId:i,refresh:p}),/* @__PURE__ */ W(co,{info:d,pivotTableId:t,unitId:r,subUnitId:i,refresh:p})]})}function go(e){let{className:t,unitId:n,subUnitId:r,pivotTableId:i}=e,[a,o]=Y(`fields`),s=z(L);return/* @__PURE__ */ G(`div`,{className:U(`univer-flex univer-size-full univer-min-h-0 univer-flex-col`,t),dir:s.getDirection(),children:[/* @__PURE__ */ W(Rn,{className:`univer-sticky univer-top-0 univer-z-10 univer-my-3 univer-w-full univer-shrink-0`,items:[{label:s.t(`sheets-pivot-ui.fieldPanel`),value:`fields`},{label:s.t(`sheets-pivot-ui.configPanel`),value:`config`}],value:a,onChange:o}),/* @__PURE__ */ W(`div`,{className:`univer-min-h-0 univer-flex-1 univer-overflow-y-auto`,children:a===`fields`?/* @__PURE__ */ W(ho,{...e}):/* @__PURE__ */ W(Qa,{unitId:n,subUnitId:r,pivotTableId:i})})]})}function _o(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 vo(e){let{unitId:t,subUnitId:n,sourceRange:r,positionRange:i,sourceSheetName:a,positionSheetName:o,onConfirm:s,onCancel:c}=e,l=z(L),u=z(F).getUnit(t),[d,f]=Y(r),[p,m]=Y(i),[h,g]=Y(a),[_,v]=Y(o),[y,b]=Y(A.New),[x,S]=Y(``),[C,w]=Y(!0);q(()=>{let e=va(u.getSheetBySheetName(h),d);S(_o(e,l))},[l,d,h,u]);function T(e){let t=e.split(`,`).filter(Boolean).map(vr)[0];t?(f(t.range),g(t.sheetName||h)):S(l.t(`sheets-pivot-ui.msg.emptySourceRange`))}function E(e){let t=e.split(`,`).filter(Boolean).map(vr)[0];if(!t){m(null);return}let n=t.sheetName||a;m(t.range),v(n),w(n!==h||!Ze.intersects(t.range,d))}function D(){if(x)return;let e;if(y===A.Existing){if(!p||!C)return;e={sourceRange:d,sourceSheetName:h,positionRange:p,positionSheetName:_,positionType:y}}else e={sourceRange:d,sourceSheetName:h,positionType:y};s(e)}return/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-5`,dir:l.getDirection(),children:[/* @__PURE__ */ G(`section`,{children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:l.t(`sheets-pivot-ui.dialog.source.sourceData`)}),/* @__PURE__ */ W(xr,{unitId:t,subUnitId:n,initialValue:br(h,d),maxRangeCount:1,supportAcrossSheet:!0,keepSheetReference:!0,onChange:(e,t)=>T(t)}),x&&/* @__PURE__ */ W(`div`,{className:`univer-mt-2 univer-text-xs univer-text-red-500`,children:x})]}),/* @__PURE__ */ G(`section`,{children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:l.t(`sheets-pivot-ui.dialog.source.position`)}),/* @__PURE__ */ G(Ln,{className:`univer-flex univer-flex-col univer-gap-3`,value:y,onChange:e=>b(e),children:[/* @__PURE__ */ W(In,{value:A.New,children:l.t(`sheets-pivot-ui.dialog.source.newSheet`)}),/* @__PURE__ */ W(In,{value:A.Existing,children:l.t(`sheets-pivot-ui.dialog.source.existingSheet`)})]}),y===A.Existing&&/* @__PURE__ */ G(`div`,{className:`univer-mt-3`,children:[/* @__PURE__ */ W(xr,{unitId:t,subUnitId:n,initialValue:p?br(_,p):``,maxRangeCount:1,supportAcrossSheet:!0,keepSheetReference:!0,onChange:(e,t)=>E(t)}),!C&&/* @__PURE__ */ W(`div`,{className:`univer-mt-2 univer-text-xs univer-text-red-500`,children:l.t(`sheets-pivot-ui.dialog.source.intersect`)})]})]}),/* @__PURE__ */ G(Nn,{children:[/* @__PURE__ */ W(V,{onClick:c,size:`middle`,children:l.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ W(V,{variant:`primary`,onClick:D,size:`middle`,children:l.t(`sheets-pivot-ui.dialog.ok`)})]})]})}let yo=class extends N{constructor(e,t){super(),[[Rr,vo],[Tr,go],[Dr,qa],[kr,Ka],[jr,Ga],[zr,la]].forEach(([t,n])=>{this.disposeWithMe(e.register(t,n))}),this.disposeWithMe(t.register({PivotTableIcon:ur}))}};yo=Q([Z(0,I(Ft)),Z(1,I(Vt))],yo);function bo(e){return{id:Vr.id,commandId:Vr.id,type:Ht.BUTTON,icon:`PivotTableIcon`,title:`sheets-pivot-ui.title`,tooltip:`sheets-pivot-ui.title`,hidden$:Gt(e,et.UNIVER_SHEET),disabled$:ln(e,cn(e,{workbookTypes:[Et],worksheetTypes:[At,kt],rangeTypes:[yt]}))}}const xo={[Ut.ORGANIZATION]:{[Vr.id]:{order:1,gridLayout:{row:2,column:1},menuItemFactory:bo}},[Lt.MAIN_AREA]:{[It.DATA]:{[Vr.id]:{order:1,menuItemFactory:bo}}}};let So=class extends N{constructor(e){super(),e.mergeMenu(xo)}};So=Q([Z(0,Rt)],So);let Co=class extends N{constructor(e,t,n,r){super(),this._sidebarService=n,this._dialogService=r,X(this,`_pivotTableId`,null),this.disposeWithMe(e.onCommandExecuted(e=>{e.id===na.id?this._pivotTableId=e.params.pivotTableId:e.id===ae.id&&e.params.pivotTableId===this._pivotTableId&&this._closePanel()}));let i=t.getCurrentUnitOfType(et.UNIVER_SHEET);i&&(this.disposeWithMe(i.activeSheet$.pipe(xn(1)).subscribe(()=>this._closePanel())),this.disposeWithMe(i.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(Er),this._closeChildDialogs()}_closeChildDialogs(){this._dialogService.close(Or),this._dialogService.close(Ar),this._dialogService.close(Mr)}};Co=Q([Z(0,P),Z(1,F),Z(2,Bt),Z(3,R)],Co),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 wo=class{static drawNoSetting(e,t,n,r){e.save(),Jn.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,Jn.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()}};const To=[`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`],Eo=[`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`],Do=[`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`],Oo=[`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`],ko=[`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`],Ao=/* @__PURE__ */ new Set([t.FilterAll,t.FilterPartial,t.FilterSingle,t.FilterNoneSortNone,t.FilteredSortAsc,t.FilteredSortDesc,t.FilteredSortNone,t.FilterNoneSortAsc,t.FilterNoneSortDesc]),jo=/* @__PURE__ */ new Set([t.Expand,t.Collapse]);let Mo=class extends Yn{constructor(e,t,n,r){super(e,t),this._commandService=n,this._themeService=r,X(this,`_cellWidth`,0),X(this,`_cellHeight`,0),X(this,`_hovered`,!1),X(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:n,row:r,unitId:i,subUnitId:a,buttonType:o}=this._pivotParams;Ao.has(o)?setTimeout(()=>{this._commandService.executeCommand($i.id,{row:r,col:n,unitId:i,subUnitId:a})},200):this._commandService.executeCommand(ce.id,{row:r,col:n,unitId:i,subUnitId:a,collapse:o===t.Expand})}onPointerEnter(){this._hovered=!0,this.setCursor(Kn.POINTER),this.makeDirty(!0)}onPointerLeave(){this._hovered=!1,this.setCursor(Kn.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.Collapse?wo.drawExpand(e,12,i,a,this._cellHeight):this._pivotParams.buttonType===t.Expand?wo.drawCollapse(e,12,i,a,this._cellHeight):this._pivotParams.buttonType===t.FilterAll||this._pivotParams.buttonType===t.FilterNoneSortNone?wo.drawNoSetting(e,16,i,a):this._pivotParams.buttonType===t.FilterPartial||this._pivotParams.buttonType===t.FilterSingle||this._pivotParams.buttonType===t.FilteredSortNone?wo.drawIconByPath(e,To,i,a):this._pivotParams.buttonType===t.FilterNoneSortAsc?wo.drawIconByPath(e,Oo,i,a):this._pivotParams.buttonType===t.FilterNoneSortDesc?wo.drawIconByPath(e,ko,i,a):this._pivotParams.buttonType===t.FilteredSortAsc?wo.drawIconByPath(e,Eo,i,a):this._pivotParams.buttonType===t.FilteredSortDesc&&wo.drawIconByPath(e,Do,i,a),e.restore()}};Mo=Q([Z(2,P),Z(3,I(Qe))],Mo);let No=class extends Yn{constructor(e,t,n,r){super(e,t),this._commandService=n,this._themeService=r,X(this,`_cellWidth`,void 0),X(this,`_cellHeight`,void 0),X(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:n,row:r,unitId:i,subUnitId:a,buttonType:o}=this._pivotParams;if(Ao.has(o))return this._commandService.executeCommand($i.id,{row:r,col:n,unitId:i,subUnitId:a});if(jo.has(o))return this._commandService.executeCommand(ce.id,{row:r,col:n,unitId:i,subUnitId:a,collapse:o===t.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.Collapse?wo.drawExpand(e,12,r,i,this._cellHeight):n===t.Expand?wo.drawCollapse(e,12,r,i,this._cellHeight):n===t.FilterAll||n===t.FilterNoneSortNone?wo.drawNoSetting(e,16,r,i):n===t.FilterPartial||n===t.FilterSingle||n===t.FilteredSortNone?wo.drawIconByPath(e,To,r,i):n===t.FilterNoneSortAsc?wo.drawIconByPath(e,Oo,r,i):n===t.FilterNoneSortDesc?wo.drawIconByPath(e,ko,r,i):n===t.FilteredSortAsc?wo.drawIconByPath(e,Eo,r,i):n===t.FilteredSortDesc&&wo.drawIconByPath(e,Do,r,i),e.restore()}};No=Q([Z(2,P),Z(3,I(Qe))],No);function Po(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 Fo=class extends N{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,X(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(Zt,{handler:(e,t,n)=>{if(e||t.menuPosition!==Lt.MAIN_AREA)return n(e);let{col:r,row:i,subUnitId:a,unitId:o}=t;if(r==null||i==null)return n(e);let s=this._adaptorModel.getPivotTableIdByCell(o,a,i,r);return s?(this._openPivotActionPanel(o,a,s,i,r),!0):n(e)}});this.disposeWithMe(dt(e))}_openPivotActionPanel(e,t,n,r,i){let a=this._permissionController.permissionCheckWithRanges({workbookTypes:[Et],worksheetTypes:[kt],rangeTypes:[vt]},[{startRow:r,endRow:r,startColumn:i,endColumn:i}],e,t);this._dialogService.open({id:Br,title:{title:this._localeService.t(`sheets-pivot-ui.title`)},children:{label:{name:zr,props:{editable:a,pivotTableId:n,subUnitId:t,unitId:e}}},onClose:()=>this._dialogService.close(Br)})}_initButtonRender(){this.disposeWithMe(yn(this._adaptorModel.viewUpdate$.pipe(pn(0)),this._skeletonManagerService.currentSkeleton$,this._configModel.pivotConfigChange$,this._permissionService.permissionPointUpdate$.pipe(pn(100))).subscribe(()=>{let e=this._context.unit,t=this._skeletonManagerService.getCurrentSkeleton();if(!e||!t)return;let n=e.getActiveSheet(),r=e.getUnitId(),i=n.getSheetId(),a=this._localeService.getDirection(),{scene:o}=this._context;this._clearButtons(),this._adaptorModel.getSubUnitPivotMatrix(r,i).forValue((e,n,s)=>{if(!(s!=null&&s.pbt))return;let{startX:c,startY:l,endX:u,endY:d}=on(e,n,o,t),f=u-c,p=d-l;if(p<8||f<8||!this._permissionController.permissionCheckWithRanges({workbookTypes:[Et],worksheetTypes:[At,Dt,kt],rangeTypes:[yt,vt]},[{startRow:e,endRow:e,startColumn:n,endColumn:n}],r,i))return;let m;if(Ao.has(s.pbt))m=`filter`;else if(jo.has(s.pbt))m=`collapse`;else return;let h=Po(a,m,{startX:c,startY:l,endX:u,endY:d}),g={left:h.left-6,top:h.top-6,width:28,height:28,zIndex:5e3,cellWidth:f,cellHeight:p,pivotParams:{row:e,col:n,unitId:r,subUnitId:i,buttonType:s.pbt}},_=`sheets-mobile-pivot-button-${e}-${n}-${r}-${i}`;this._buttonShapes.push(this._injector.createInstance(No,_,g))}),this._buttonShapes.length&&o.addObjects(this._buttonShapes),o.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()}};Fo=Q([Z(1,I(Ke)),Z(2,I(j)),Z(3,I(tn)),Z(4,I(M)),Z(5,I(Ct)),Z(6,I(Ge)),Z(7,I(L)),Z(8,R),Z(9,qe($t))],Fo);let Io=class extends N{constructor(e,t,n){super(),this._univerInstanceService=e,this._sheetsPivotTableAdaptorModel=t,this._sheetClipboardService=n,this._initialize()}_initialize(){let e=this,t,n;this.disposeWithMe(this._sheetClipboardService.addClipboardHook({id:se,onBeforeCopy(r,i){let a=e._univerInstanceService.getUnit(r,et.UNIVER_SHEET);a&&(t=e._sheetsPivotTableAdaptorModel.getSubUnitPivotMatrix(r,i),n=a.getStyles())},onAfterCopy(){t=null,n=null},getCellValueBySpecialMatrix(e,r){if(!t)return;let i=t==null?void 0:t.getValue(e,r);if(i){var a;return{...i,s:n==null?void 0:n.get(i.s),displayV:((a=i.v)==null?void 0:a.toString())||``}}}}))}};Io=Q([Z(0,I(F)),Z(1,I(j)),Z(2,Yt)],Io);const Lo=[ht.id,bt.id,xt.id,mt.id];let Ro=class extends N{constructor(e,t,n,r,i,a,o,s,c){var l;super(),this._injector=e,this._univerInstanceService=t,this._sheetsPivotTableAdaptorModel=n,this._sheetInterceptorService=r,this._confirmService=i,this._localeService=a,this._sheetsPivotTableConfigModel=o,this._messageService=s,this._configService=c,X(this,`_defaultOverride`,!1),this._initMoveRangeConfirmCheck(),this._initRowColOperationCheck(),this._defaultOverride=((l=this._configService.getConfig(oe))==null?void 0:l.defaultOverride)??!1}_initMoveRangeConfirmCheck(){this.disposeWithMe(this._sheetInterceptorService.interceptBeforeCommand({performCheck:async e=>{if(e.id===_t.id){let t=Nt(this._univerInstanceService);if(!t)return Promise.resolve(!1);let{unitId:n,subUnitId:r}=t,{fromRange:i,toRange:a}=e.params,o=this._sheetsPivotTableConfigModel.getSubUnitPivotConfigs(n,r);if(!(o!=null&&o.size))return Promise.resolve(!0);for(let[e,t]of o){let{targetCellInfo:o}=t,{row:s,col:c}=o,l=s-i.startRow,u=c-i.startColumn,d={row:a.startRow+l,col:a.startColumn+u},f=d.row-o.row,p=d.col-o.col,m=this._sheetsPivotTableAdaptorModel.getPivotItemRenderInfoCache(n,r,e),h=m==null?void 0:m.rangesInfo;if(!h)return Promise.resolve(!0);let g=[];Object.keys(h).forEach(e=>{h[e].forEach(e=>{let t={...e};t.startRow=e.startRow+f,t.endRow=e.endRow+f,t.startColumn=e.startColumn+p,t.endColumn=e.endColumn+p,g.push(t)})});let _=this._sheetInterceptorService.generateMutationsByRanges({unitId:n,subUnitId:r,ranges:g}),v=Te(this._injector,n,r,g);if(_.redos.length||v.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(Lo.includes(e.id)){let t=e.params,{range:n}=t,r=Nt(this._univerInstanceService),i=t.unitId||(r==null?void 0:r.unitId),a=t.subUnitId||(r==null?void 0:r.subUnitId);if(!i||!a)return Promise.resolve(!0);let o=this._sheetsPivotTableConfigModel.getSubUnitPivotConfigs(i,a);if(o!=null&&o.size)for(let[e,t]of o){let t=this._sheetsPivotTableAdaptorModel.getPivotItemRenderInfoCache(i,a,e);if(t!=null&&t.rangesInfo){for(let e of Object.keys(t.rangesInfo))if(t.rangesInfo[e].some(e=>Ze.intersects(e,n)))return this._messageService.show({type:jn.Error,content:this._localeService.t(`sheets-pivot-ui.perform.rowColError`)}),Promise.resolve(!1)}}}return Promise.resolve(!0)}}))}};Ro=Q([Z(0,I(Ke)),Z(1,I(F)),Z(2,I(j)),Z(3,I(St)),Z(4,I(Ue)),Z(5,I(L)),Z(6,I(M)),Z(7,I(zt)),Z(8,I(He))],Ro);const zo=[Cr.id,wr.id,Qt.id];let Bo=class extends N{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(zo.includes(e.id)){var t;let n=(t=this._sheetsSelectionsService.getCurrentLastSelection())==null?void 0:t.primary;if(!n)return;let{actualRow:r,actualColumn:i}=n,a=tt(r,i),o=Nt(this._univerInstanceService,e.params);if(!o)return;let{unitId:s,subUnitId:c}=o,l=this._sheetsPivotTableConfigModel.getSubUnitPivotConfigs(s,c);if(l!=null&&l.size)for(let[e]of l){let t=this._sheetsPivotTableAdaptorModel.getPivotItemRenderInfoCache(s,c,e);if(t!=null&&t.rangesInfo){for(let e of Object.keys(t.rangesInfo))if(t.rangesInfo[e].some(e=>Ze.intersects(e,a)))throw new Le(this._localeService.t(`sheets-pivot-ui.msg.editCellError`))}}}}))}};Bo=Q([Z(0,I(wt)),Z(1,I(F)),Z(2,I(j)),Z(3,I(P)),Z(4,I(M)),Z(5,I(L))],Bo);let Vo=class extends N{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:i}=r;for(let r of i)if(r.id===pt.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:jn.Error,content:n.t(`sheets-pivot-ui.msg.mergeCellError`)}),!1}return!0}})}};Vo=Q([Z(0,I(j)),Z(1,I(Jt)),Z(2,I(zt)),Z(3,I(L))],Vo);let Ho=class extends N{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:r,subUnitId:i}=t,a=(e==null?void 0:e.startRow)??1/0,o=(e==null?void 0:e.endRow)??-1/0,s=(e==null?void 0:e.startColumn)??1/0,c=(e==null?void 0:e.endColumn)??-1/0,l=this._sheetsPivotTableConfigModel.getSubUnitPivotConfigs(r,i);if(!l)return n(e);for(let[e,t]of l){var u;let t=(u=this._sheetsPivotTableAdaptorModel.getPivotItemRenderInfoCache(r,i,e))==null?void 0:u.rangesInfo;t&&Object.values(t).forEach(e=>{e.forEach(e=>{let{startRow:t,endRow:n,startColumn:r,endColumn:i}=e;a=Math.min(t,a),o=Math.max(n,o),s=Math.min(r,s),c=Math.max(i,c)})})}let d={startRow:a,endRow:o,startColumn:s,endColumn:c};return ct(d)?n(d):n(e)}}))}};Ho=Q([Z(0,I(en)),Z(1,I(j)),Z(2,I(M))],Ho);let Uo=class extends N{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=Nt(this._univerInstanceService);if(!n)return e;let{unitId:r,subUnitId:i}=n,a=this._sheetsPivotTableConfigModel.getSubUnitPivotConfigs(r,i),o=[];return a&&a.forEach((e,t)=>{var n;let a=(n=this._sheetsPivotTableConfigModel.getPivotTableRangeInfo(r,i,t))==null?void 0:n.rangeInfo;a&&Object.keys(a).forEach(e=>{let t=a[e];Array.isArray(t)&&o.push(...t)})}),o.length&&t.some(e=>o.some(t=>Ze.intersects(t,e)))?!0:e}}))}};Uo=Q([Z(0,I(gt)),Z(1,I(F)),Z(2,I(M))],Uo);let Wo=class extends Je{constructor(e=ia,t,n,r,i){super(),this._config=e,this._injector=t,this._commandService=n,this._renderManagerService=r,this._configService=i;let{menu:a,...o}=lt({},ia,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(ra,o),this._registerCommands()}onStarting(){[[yo],[So],[Co],[Uo],[Ro],[Ho],[Bo],[Vo],[ca],[Io]].forEach(e=>this._injector.add(e)),ft(this._injector,[[yo],[So],[Co],[ca]])}onRendered(){this._registerRenderModules(),ft(this._injector,[[Ro],[Ho],[Bo],[Vo],[Io]])}onSteady(){ft(this._injector,[[Uo]])}_registerCommands(){[na,Vr,$i,ea,Ur].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerRenderModules(){this.disposeWithMe(this._renderManagerService.registerRenderModule(et.UNIVER_SHEET,[Fo]))}};X(Wo,`pluginName`,`${se}_UI_PLUGIN`),X(Wo,`packageName`,Zi),X(Wo,`version`,Qi),X(Wo,`type`,et.UNIVER_SHEET),Wo=Q([ze(Gn,Xn,Tt,xe,rn,Wt),Z(1,I(Ke)),Z(2,P),Z(3,qn),Z(4,He)],Wo);const Go=[o.Year,o.Quarter,o.Month,o.Day,o.Hour,o.Minute,o.Second],Ko={[o.Year]:`sheets-pivot-ui.dateGroup.year`,[o.Quarter]:`sheets-pivot-ui.dateGroup.quarter`,[o.Month]:`sheets-pivot-ui.dateGroup.month`,[o.Day]:`sheets-pivot-ui.dateGroup.day`,[o.Hour]:`sheets-pivot-ui.dateGroup.hour`,[o.Minute]:`sheets-pivot-ui.dateGroup.minute`,[o.Second]:`sheets-pivot-ui.dateGroup.second`},qo=`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 Jo({targetFieldName:e,dateSystem:t,grouping:n,onConfirm:r,onCancel:i}){let a=z(L),s=B(a.direction$,a.getDirection()),c=(e,n)=>{let r=e===void 0?null:at(e,{dateSystem:t});if(!r)return{date:``,time:n};let i=e=>String(e).padStart(2,`0`);return{date:`${r.year}-${i(r.month)}-${i(r.day)}`,time:`${i(r.hours)}:${i(r.minutes)}:${i(r.seconds)}`}},[l,u]=Y((n==null?void 0:n.units)??[o.Day]),[d,f]=Y((n==null?void 0:n.autoStart)??!0),[p,m]=Y((n==null?void 0:n.autoEnd)??!0),[h,g]=Y(()=>c(n==null?void 0:n.start,`00:00:00`).date),[_,v]=Y(()=>c(n==null?void 0:n.end,`23:59:59`).date),[y,b]=Y(()=>c(n==null?void 0:n.start,`00:00:00`).time),[x,S]=Y(()=>c(n==null?void 0:n.end,`23:59:59`).time),[C,w]=Y((n==null?void 0:n.daysInterval)??1),[T,E]=Y(!1),D=J(!1),O=l.some(e=>e===o.Hour||e===o.Minute||e===o.Second),ee=l.length===1&&l[0]===o.Day,te=(e,n,r)=>{let i=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e),a=/^(\d{2}):(\d{2})(?::(\d{2}))?$/.exec(n);return!i||!a?null:it({year:Number(i[1]),month:Number(i[2]),day:Number(i[3]),hours:O?Number(a[1]):r?23:0,minutes:O?Number(a[2]):r?59:0,seconds:O?Number(a[3]??0):r?59:0,fractionalSecond:r?.999:0},{dateSystem:t})},k=d?void 0:te(h,y,!1),ne=p?void 0:te(_,x,!0),A=l.length>0&&(d||k!==null)&&(p||ne!==null)&&(k==null||ne==null||k<=ne)&&(!ee||Number.isInteger(C)&&C>=1);return/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,dir:s,children:[/* @__PURE__ */ W(`div`,{className:`univer-text-sm univer-font-medium`,children:e}),/* @__PURE__ */ G(`fieldset`,{children:[/* @__PURE__ */ W(`legend`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:a.t(`sheets-pivot-ui.dateGroup.groupBy`)}),/* @__PURE__ */ W(`div`,{className:`univer-grid univer-grid-cols-2 univer-gap-2`,children:Go.map(e=>/* @__PURE__ */ W(H,{checked:l.includes(e),onChange:t=>u(n=>t?Go.filter(t=>t===e||n.includes(t)):n.filter(t=>t!==e)),children:a.t(Ko[e])},e))})]}),ee&&/* @__PURE__ */ G(`label`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-3 univer-text-sm`,children:[a.t(`sheets-pivot-ui.dateGroup.daysInterval`),/* @__PURE__ */ W(An,{className:`univer-w-24`,value:C,min:1,onChange:e=>w(Number(e))})]}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ W(H,{checked:d,onChange:e=>f(!!e),children:a.t(`sheets-pivot-ui.dateGroup.autoStart`)}),!d&&/* @__PURE__ */ G(`label`,{className:`univer-flex univer-items-center univer-gap-2 univer-text-sm`,children:[a.t(`sheets-pivot-ui.dateGroup.start`),/* @__PURE__ */ W(kn,{type:`date`,value:h,onChange:g}),O&&/* @__PURE__ */ W(`input`,{className:qo,type:`time`,step:1,value:y,onChange:e=>b(e.target.value)})]}),/* @__PURE__ */ W(H,{checked:p,onChange:e=>m(!!e),children:a.t(`sheets-pivot-ui.dateGroup.autoEnd`)}),!p&&/* @__PURE__ */ G(`label`,{className:`univer-flex univer-items-center univer-gap-2 univer-text-sm`,children:[a.t(`sheets-pivot-ui.dateGroup.end`),/* @__PURE__ */ W(kn,{type:`date`,value:_,onChange:v}),O&&/* @__PURE__ */ W(`input`,{className:qo,type:`time`,step:1,value:x,onChange:e=>S(e.target.value)})]})]}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-justify-end univer-gap-3`,children:[/* @__PURE__ */ W(V,{onClick:i,children:a.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ W(V,{variant:`primary`,disabled:!A||T,onClick:async()=>{if(!A||D.current)return;let e={units:Go.filter(e=>l.includes(e)),autoStart:d,autoEnd:p};!d&&k!=null&&(e.start=k),!p&&ne!=null&&(e.end=ne),ee&&C>1&&(e.daysInterval=C),D.current=!0,E(!0);try{await r(e)}catch{}finally{D.current=!1,E(!1)}},children:a.t(`sheets-pivot-ui.dialog.ok`)})]})]})}function Yo(e){let t=e.operator===h.dateBetween||e.operator===h.dateNotBetween,n={type:s.CustomFilter,operator:e.operator,expected:t?[e.lower,e.upper]:e.lower,useWholeDay:e.useWholeDay};try{return g(n),n}catch{return}}function Xo(e,t){let n=at(e,{dateSystem:t});if(!n||n.day===0||n.year===1900&&n.month===2&&n.day===29)return;let r=new Date(2e3,0,1,12);return r.setFullYear(n.year,n.month-1,n.day),r}function Zo(e,t,n){let r=it({year:t.getFullYear(),month:t.getMonth()+1,day:t.getDate(),hours:0,minutes:0,seconds:0,fractionalSecond:0},{dateSystem:n});return r===null?void 0:r+(e===void 0?0:e-Math.floor(e))}function Qo(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}const $o=[{value:h.dateEqual,label:`sheets-pivot-ui.dateFilter.equal`},{value:h.dateNotEqual,label:`sheets-pivot-ui.dateFilter.notEqual`},{value:h.dateNewerThan,label:`sheets-pivot-ui.dateFilter.after`},{value:h.dateNewerThanOrEqual,label:`sheets-pivot-ui.dateFilter.afterOrEqual`},{value:h.dateOlderThan,label:`sheets-pivot-ui.dateFilter.before`},{value:h.dateOlderThanOrEqual,label:`sheets-pivot-ui.dateFilter.beforeOrEqual`},{value:h.dateBetween,label:`sheets-pivot-ui.dateFilter.between`},{value:h.dateNotBetween,label:`sheets-pivot-ui.dateFilter.notBetween`}];function es({dateSystem:e,defaultDate:t,currentFilter:n,onConfirm:r,onCancel:i}){let a=z(L);B(a.currentLocale$);let o=B(a.direction$,a.getDirection()),[s,c]=Y((n==null?void 0:n.operator)??h.dateEqual),l=Array.isArray(n==null?void 0:n.expected)?n.expected[0]:n==null?void 0:n.expected,u=Array.isArray(n==null?void 0:n.expected)?n.expected[1]:void 0,[d,f]=Y(()=>l??t??Zo(void 0,/* @__PURE__ */ new Date,e)),[p,m]=Y(()=>u??l??t??Zo(void 0,/* @__PURE__ */ new Date,e)),[g,_]=Y((n==null?void 0:n.useWholeDay)===!0),[v,y]=Y(!1),[b,x]=Y(!1),S=J(!1),C=ee(d),w=ee(p),T=s===h.dateBetween||s===h.dateNotBetween,E=Yo({operator:s,lower:C,upper:w,useWholeDay:g}),D=E!==void 0&&n!==void 0&&s===n.operator&&g===(n.useWholeDay===!0)&&$e.diffValue(E.expected,n.expected);async function O(e){if(!S.current){S.current=!0,y(!0),x(!1);try{await r(e)||x(!0)}catch{x(!0)}finally{S.current=!1,y(!1)}}}function ee(e){return typeof e==`string`?e.trim()===``?void 0:Number(e):e}function te(e,t){t?m(e):f(e)}function k(t,n){let r=Zo(n?w:C,t,e);n?m(r):f(r)}function ne(e,t){let n=t?w:C;if(n===void 0)return;let r=Qo(n,e);t?m(r):f(r)}return/* @__PURE__ */ G(`div`,{dir:o,className:`univer-flex univer-min-w-0 univer-flex-col univer-gap-3`,children:[/* @__PURE__ */ W(`div`,{className:`univer-text-sm univer-font-medium`,children:a.t(`sheets-pivot-ui.dateFilter.title`)}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-1`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-xs`,children:a.t(`sheets-pivot-ui.dateFilter.rule`)}),/* @__PURE__ */ W(zn,{className:`univer-w-full`,value:String(s),options:$o.map(e=>({value:String(e.value),label:a.t(e.label)})),onChange:e=>c(Number(e))})]}),(T?[!1,!0]:[!1]).map(n=>{let r=n?w:C,i=r===void 0?void 0:Xo(r,e),o=(n?u:void 0)??l??t,s=o!==void 0&&!Xo(o,e),c=r===void 0?null:at(r,{dateSystem:e}),f=c?new Date(2e3,0,1,c.hours,c.minutes,c.seconds,Math.floor(c.fractionalSecond*1e3)):void 0,m=`sheets-pivot-ui.dateFilter.date`;return T&&(m=n?`sheets-pivot-ui.dateFilter.to`:`sheets-pivot-ui.dateFilter.from`),/* @__PURE__ */ G(`div`,{role:`group`,"aria-label":a.t(m),className:`univer-flex univer-min-w-0 univer-flex-col univer-gap-1`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-xs`,children:a.t(m)}),s?/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-1`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-xs univer-text-gray-500`,children:a.t(`sheets-pivot-ui.dateFilter.serial`)}),/* @__PURE__ */ W(kn,{value:String((n?p:d)??``),onChange:e=>te(e,n)})]}):/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-wrap univer-items-center univer-gap-2`,children:[/* @__PURE__ */ W(Dn,{value:i,onValueChange:e=>k(e,n)}),!g&&r!==void 0&&/* @__PURE__ */ W(Vn,{value:f,onValueChange:e=>ne(e,n)})]})]},String(n))}),/* @__PURE__ */ W(H,{checked:g,onChange:e=>_(e===!0),children:a.t(`sheets-pivot-ui.dateFilter.wholeDay`)}),b&&/* @__PURE__ */ W(`div`,{role:`alert`,className:`univer-text-xs univer-text-red-500`,children:a.t(`sheets-pivot-ui.dateFilter.failed`)}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-wrap univer-items-center univer-justify-between univer-gap-2`,children:[/* @__PURE__ */ W(V,{variant:`link`,disabled:v||!n,onClick:()=>O(void 0),children:a.t(`sheets-pivot-ui.dialog.filter.clearFilter`)}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-gap-2`,children:[/* @__PURE__ */ W(V,{disabled:v,onClick:i,children:a.t(`sheets-pivot-ui.dialog.filter.cancel`)}),/* @__PURE__ */ W(V,{variant:`primary`,disabled:v||!E||D,onClick:()=>O(E),children:a.t(`sheets-pivot-ui.dialog.filter.confirm`)})]})]})]})}function ts(e){let{dialogId:t=Or,filterItemInfo:i,onClose:a,onSetFilter:o,onSetSort:s,onSetDateFilter:c,unitId:l,subUnitId:u}=e,{format:d,filterInfo:f,sortInfo:p}=i,m=i.conditionFilter??f,h=z(P),g=z(L);B(g.currentLocale$);let _=z(R),v=z(F),y=B(g.direction$,g.getDirection()),b=J(!0),[x,C]=Y(!1);q(()=>(b.current=!0,()=>{b.current=!1}),[]);let[w,T]=Y(()=>i?i.checkedItems??(f==null?void 0:f.list)??i.items:[]),[E,D]=Y(()=>i.partialItems??[]),O=E.length===0&&w.length===i.items.length,ee=w.length===0&&E.length===0,[te,k]=Y(()=>{if(i)return p==null?void 0:p.type}),ne=()=>{b.current&&(b.current=!1,a?a():_.close(t))};if(q(()=>{let e=v.getCurrentUnitOfType(et.UNIVER_SHEET);if(!e)return;let n=e.activeSheet$.subscribe(e=>{e&&e.getSheetId()!==u&&b.current&&(b.current=!1,a?a():_.close(t))});return()=>n==null?void 0:n.unsubscribe()},[t,_,a,u,v]),!i)return;let A=()=>{D([]),T(O?[]:i.items)},re=e=>{E.includes(e)?(D(E.filter(t=>t!==e)),T([...w,e])):w.includes(e)?T(w.filter(t=>t!==e)):T([...w,e])},ie=async()=>{let{tableFieldId:e,pivotTableId:t}=i;if(e&&t)try{(o?await o(w,O,E):await h.executeCommand(fe.id,{unitId:l,subUnitId:u,pivotTableId:t,tableFieldId:e,items:w,partialItems:E,isAll:O}))&&b.current&&ne()}catch{}},ae=()=>{ne()},oe=async()=>{let{tableFieldId:e,pivotTableId:t}=i;if(e&&t){T(i.items),D([]);try{(o?await o(i.items,!0,[],!0):await h.executeCommand(fe.id,{unitId:l,subUnitId:u,pivotTableId:t,tableFieldId:e,items:i.items,partialItems:[],isAll:!0,clearAllFilters:!0}))&&b.current&&ne()}catch{}}},se=async e=>{let{tableFieldId:t,pivotTableId:n}=i;if(!t||!n)return;let r={type:e};try{(s?await s(r):await h.executeCommand(_e.id,{unitId:l,subUnitId:u,pivotTableId:n,tableFieldId:t,info:r}))&&b.current&&(k(e),ne())}catch{}},ce=Ha(f,{items:i.items,conditionFilter:i.conditionFilter});async function ue(e){if(!b.current)return!1;let t=c?await c(e):await h.executeCommand(le.id,{unitId:l,subUnitId:u,pivotTableId:i.pivotTableId,tableFieldId:i.tableFieldId,filterInfo:e});return t&&b.current&&ne(),t}if(x){let e=v.getUnit(l),t=i.itemTypes.findIndex(e=>e===n.date),r=Number(i.items[t]);return/* @__PURE__ */ W(es,{dateSystem:(e==null?void 0:e.getDateSystem())??Re.Date1900,defaultDate:Number.isFinite(r)?r:void 0,currentFilter:S(m)?m:void 0,onConfirm:ue,onCancel:()=>C(!1)})}return/* @__PURE__ */ G(`div`,{dir:y,children:[i.supportsDateFilter&&/* @__PURE__ */ W(V,{className:`univer-mb-3 univer-w-full`,onClick:()=>C(!0),children:g.t(`sheets-pivot-ui.dateFilter.title`)}),/* @__PURE__ */ G(`div`,{className:`univer-flex`,children:[/* @__PURE__ */ G(`div`,{className:U(`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`,Un,{"univer-bg-gray-100 dark:!univer-bg-gray-700":te===r.ascending}),onClick:()=>se(r.ascending),children:[/* @__PURE__ */ W($n,{}),g.t(`sheets-pivot-ui.dialog.filter.ascending`)]}),/* @__PURE__ */ G(`div`,{className:U(`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`,Un,{"univer-bg-gray-100 dark:!univer-bg-gray-700":te===r.descending}),onClick:()=>se(r.descending),children:[/* @__PURE__ */ W(rr,{}),g.t(`sheets-pivot-ui.dialog.filter.descending`)]})]}),/* @__PURE__ */ W(`div`,{className:U(`univer-mx-0 univer-mb-4 univer-mt-3 univer-h-[300px] univer-rounded-lg univer-p-2`,Un),children:/* @__PURE__ */ G(`div`,{className:U(`univer-h-full univer-overflow-y-auto`,Wn),children:[/* @__PURE__ */ W(`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__ */ W(H,{checked:O,onChange:A,indeterminate:!O&&(w.length>0||E.length>0),children:g.t(`sheets-pivot-ui.dialog.filter.selectAll`)})}),i.items.map((e,t)=>{var r,a;let o=e,s=(r=i.itemLabels)==null?void 0:r[e],c=(a=i.itemTypes)==null?void 0:a[t],l=ma(e,c);return l?o=g.t(l):s===void 0?c===n.date&&d&&(o=ut.format(d,Number(e))):o=s,/* @__PURE__ */ W(`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__ */ W(H,{checked:w.includes(e),indeterminate:E.includes(e),onChange:()=>re(e),contentClassName:`univer-max-w-[200px] univer-truncate`,children:o})},e)})]})}),/* @__PURE__ */ G(En,{className:`univer-flex univer-items-center univer-justify-between`,children:[/* @__PURE__ */ W(`div`,{className:`univer-cursor-pointer univer-text-xs univer-text-primary-600`,children:/* @__PURE__ */ W(V,{variant:`link`,disabled:ce===`NotFilter`,onClick:oe,children:g.t(`sheets-pivot-ui.dialog.filter.clearFilter`)})}),/* @__PURE__ */ G(En,{className:`univer-flex univer-flex-1 univer-items-center univer-gap-3`,children:[/* @__PURE__ */ W(V,{onClick:ae,children:g.t(`sheets-pivot-ui.dialog.filter.cancel`)}),/* @__PURE__ */ W(V,{variant:`primary`,disabled:ee,onClick:ie,children:g.t(`sheets-pivot-ui.dialog.filter.confirm`)})]})]})]})}function ns({name:e,onConfirm:t,onCancel:n}){let r=z(L),i=B(r.direction$,r.getDirection()),[a,o]=Y(e),[s,c]=Y(!1),l=J(!1);return/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,dir:i,children:[/* @__PURE__ */ G(`label`,{className:`univer-flex univer-flex-col univer-gap-2 univer-text-sm`,children:[r.t(`sheets-pivot-ui.manualGroup.name`),/* @__PURE__ */ W(kn,{value:a,onChange:o})]}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-justify-end univer-gap-3`,children:[/* @__PURE__ */ W(V,{onClick:n,children:r.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ W(V,{variant:`primary`,disabled:!a.trim()||s,onClick:async()=>{if(a.trim()&&!l.current){l.current=!0,c(!0);try{await t(a)}catch{}finally{l.current=!1,c(!1)}}},children:r.t(`sheets-pivot-ui.dialog.ok`)})]})]})}const rs=`univer-flex univer-items-center univer-justify-between univer-gap-3 univer-text-sm`;function is({targetFieldName:e,grouping:t,defaults$:n,onConfirm:r,onCancel:i}){let a=z(L),o=B(a.direction$,a.getDirection()),s=B(n),[c,l]=Y((t==null?void 0:t.autoStart)??!0),[u,d]=Y((t==null?void 0:t.autoEnd)??!0),[f,p]=Y((t==null?void 0:t.autoStart)===!1?String(t.start):void 0),[m,h]=Y((t==null?void 0:t.autoEnd)===!1?String(t.end):void 0),[g,_]=Y(t?String(t.interval):void 0),[v,y]=Y(!1),b=J(!1),x=e=>e===void 0||!/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i.test(e.trim())?NaN:Number(e),S={autoStart:c,autoEnd:u,start:c?s==null?void 0:s.start:x(f),end:u?s==null?void 0:s.end:x(m),interval:g===void 0||g.trim()===``?(s==null?void 0:s.interval)??0:x(g)},C=!!s&&ii(S),w=e=>{!e&&f===void 0&&(s==null?void 0:s.start)!==void 0&&p(String(s.start)),l(e)},T=e=>{!e&&m===void 0&&(s==null?void 0:s.end)!==void 0&&h(String(s.end)),d(e)};return/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,dir:o,children:[/* @__PURE__ */ W(`div`,{className:`univer-text-sm univer-font-medium`,children:e}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ W(H,{checked:c,onChange:e=>w(!!e),children:a.t(`sheets-pivot-ui.numberGroup.autoStart`)}),/* @__PURE__ */ G(`label`,{className:rs,children:[a.t(`sheets-pivot-ui.numberGroup.start`),/* @__PURE__ */ W(kn,{className:`univer-w-32`,value:c?String((s==null?void 0:s.start)??``):f??``,disabled:c,onChange:p})]}),/* @__PURE__ */ W(H,{checked:u,onChange:e=>T(!!e),children:a.t(`sheets-pivot-ui.numberGroup.autoEnd`)}),/* @__PURE__ */ G(`label`,{className:rs,children:[a.t(`sheets-pivot-ui.numberGroup.end`),/* @__PURE__ */ W(kn,{className:`univer-w-32`,value:u?String((s==null?void 0:s.end)??``):m??``,disabled:u,onChange:h})]}),/* @__PURE__ */ G(`label`,{className:rs,children:[a.t(`sheets-pivot-ui.numberGroup.interval`),/* @__PURE__ */ W(kn,{className:`univer-w-32`,value:g??String((s==null?void 0:s.interval)??``),placeholder:String((s==null?void 0:s.interval)??``),onChange:_})]})]}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-justify-end univer-gap-3`,children:[/* @__PURE__ */ W(V,{onClick:i,children:a.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ W(V,{variant:`primary`,disabled:!C||v,onClick:async()=>{if(C&&!b.current){b.current=!0,y(!0);try{await r(S)}catch{}finally{b.current=!1,y(!1)}}},children:a.t(`sheets-pivot-ui.dialog.ok`)})]})]})}const as=({handlePatternChange:e})=>{let t=z(L);return q(()=>{e(``)},[]),/* @__PURE__ */ W(`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`)})},os=({originPattern:e,handlePatternChange:t})=>{let n=z(L),r=nt.map(e=>({label:e,value:e})),[i,a]=Y(()=>ka(e||``,2)),[o,s]=Y(()=>ja(e??``)||r[0].value);return q(()=>{t($(`_("${o}"* #,##0${i>0?`.0`:``}_)`,i))},[]),/* @__PURE__ */ G(`div`,{className:`univer-mt-5`,children:[/* @__PURE__ */ G(`div`,{className:`univer-flex univer-items-center univer-justify-between`,children:[/* @__PURE__ */ G(`div`,{className:`univer-w-[136px]`,children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.decimalPlaces`)}),/* @__PURE__ */ W(An,{className:`univer-box-border univer-h-8`,value:i,max:20,min:0,onChange:e=>{let n=e??0;a(n),t($(`_("${o}"* #,##0${n>0?`.0`:``}_)`,n))}})]}),/* @__PURE__ */ G(`div`,{className:`univer-w-[136px]`,children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.currencyTypes`)}),/* @__PURE__ */ W(zn,{options:r,value:o,onChange:e=>{s(e),t($(`_("${e}"* #,##0${i>0?`.0`:``}_)`,i))}})]})]}),/* @__PURE__ */ W(`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`)})]})},ss=({originPattern:e,handlePatternChange:t})=>{let n=z(L),r=nt.map(e=>({label:e,value:e})),[i,a]=Y(()=>ka(e||``,2)),[o,s]=Y(()=>ja(e??``)||r[0].value),c=fa.map(e=>({label:e.label(o),value:e.suffix(o),color:e.color})),[l,u]=Y(()=>{var t;return((t=c.find(t=>st(t.value,e??``)))==null?void 0:t.value)||c[0].value});return q(()=>{t($(l,i))},[]),/* @__PURE__ */ G(`div`,{className:`univer-mt-5`,children:[/* @__PURE__ */ G(`div`,{className:`univer-flex univer-items-center univer-justify-between`,children:[/* @__PURE__ */ G(`div`,{className:`univer-w-[136px]`,children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.decimalPlaces`)}),/* @__PURE__ */ W(An,{className:`univer-box-border univer-h-8`,value:i,max:20,min:0,onChange:e=>{e&&(a(e),t($(l,e)))}})]}),/* @__PURE__ */ G(`div`,{className:`univer-w-[136px]`,children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.currencyTypes`)}),/* @__PURE__ */ W(zn,{options:r,value:o,onChange:e=>{s(e);let n=fa.map(t=>({label:t.label(e),value:t.suffix(e),color:t.color}));u(n[0].value),t($(n[0].value,i))}})]})]}),/* @__PURE__ */ G(`div`,{className:`univer-mt-4`,children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.negativeNumberTypes`)}),/* @__PURE__ */ W(Bn,{className:`univer-rounded-lg univer-p-2`,options:c,value:l,onChange:e=>{u(e),t($(e,i))}}),/* @__PURE__ */ W(`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`)})]})]})},cs=({originPattern:e,handlePatternChange:t})=>{let n=z(L),r=ua.map(e=>({label:e.label,value:e.suffix})),[i,a]=Y(()=>{if(e){let t=r.find(t=>t.value===e);if(t)return t.value}return r[0].value});return q(()=>{t(i)},[]),/* @__PURE__ */ W(`div`,{className:`univer-mt-5`,children:/* @__PURE__ */ G(`div`,{className:`univer-mt-5`,children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.dateTypes`)}),/* @__PURE__ */ W(`div`,{children:/* @__PURE__ */ W(Bn,{className:`univer-rounded-lg univer-p-2`,options:r,value:i,onChange:e=>{a(e),t(e)}})}),/* @__PURE__ */ W(`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`)})]})})},ls=({originPattern:e,handlePatternChange:t})=>{let n=z(L),[r,i]=Y(()=>ka(e||``,0)),a=da.map(e=>({label:e.label,value:e.suffix,color:e.color})),[o,s]=Y(()=>{let t=a.find(t=>st(t.value,e||``));return(t==null?void 0:t.value)||a[0].value});return q(()=>{t($(o,Number(r||0)))},[]),/* @__PURE__ */ G(`div`,{className:`univer-mt-5`,children:[/* @__PURE__ */ W(`div`,{className:`univer-flex univer-items-center univer-justify-between`,children:/* @__PURE__ */ G(`div`,{className:`univer-w-[136px]`,children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.decimalPlaces`)}),/* @__PURE__ */ W(An,{className:`univer-box-border univer-h-8`,value:r,max:20,min:0,onChange:e=>{e&&(i(e),t($(o,Number(e))))}})]})}),/* @__PURE__ */ G(`div`,{className:`univer-mt-4`,children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.negativeNumberTypes`)}),/* @__PURE__ */ W(Bn,{className:`univer-rounded-lg univer-p-2`,options:a,value:o,onChange:e=>{i(ka(e,0)),s(e),t(e)}}),/* @__PURE__ */ W(`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`)})]})]})},us=({unitId:e,subUnitId:t,pivotTableId:n,tableFieldId:r,originPattern:i,tableFieldInfo:a,dataFieldInfo:o})=>{let s=z(L),c=z(R),l=s.getDirection(),u=_r(()=>[{label:`sheets-pivot-ui.dialog.numfmt.general`,component:as,key:`sheet.numfmt.general`},{label:`sheets-pivot-ui.dialog.numfmt.accounting`,component:os,key:`sheet.numfmt.accounting`},{label:`sheets-pivot-ui.dialog.numfmt.currency`,component:ss,key:`sheet.numfmt.currency`},{label:`sheets-pivot-ui.dialog.numfmt.date`,component:cs,key:`sheet.numfmt.date`},{label:`sheets-pivot-ui.dialog.numfmt.thousandthPercentile`,component:ls,key:`sheet.numfmt.thousandthPercentile`}].map(e=>({...e,label:s.t(e.label)})),[s]),d=u.map(e=>({label:e.label,value:e.key})),[f,p]=Y(()=>[Ma,Na,Pa,Ia,Ra].reduce((e,t,n)=>e||(t(i??``)?u[n].key:``),``)||u[0].key),[m,h]=Y(i),g=e=>h(e),_=e=>{p(e)},v=i=>({id:Ar,title:{title:s.t(`sheets-pivot-ui.fieldSettings`)},draggable:!0,mask:!1,maskClosable:!1,width:400,children:{label:kr,tableFieldId:r,pivotTableId:n,unitId:e,subUnitId:t,tableFieldInfo:a,dataFieldInfo:o,key:`field-setting-${r||``}`,closeFn:()=>{c.close(Ar)},format:i?m:``},onClose:()=>{c.close(Ar)}}),y=()=>{c.close(Mr);let e=v(!1);c.open(e)};return/* @__PURE__ */ G(`div`,{dir:l,children:[/* @__PURE__ */ W(`div`,{className:`univer-flex`,children:/* @__PURE__ */ G(`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:y,children:[/* @__PURE__ */ W(Qn,{}),s.t(`sheets-pivot-ui.dialog.numfmt.fieldSetting`)]})}),/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-h-5 univer-text-sm univer-font-medium univer-leading-5`,children:s.t(`sheets-pivot-ui.dialog.numfmt.formatTypes`)}),/* @__PURE__ */ W(`div`,{children:/* @__PURE__ */ W(zn,{className:`univer-w-full`,value:f,options:d,onChange:e=>_(e)})}),/* @__PURE__ */ G(`div`,{children:[f===`sheet.numfmt.general`&&/* @__PURE__ */ W(as,{originPattern:i,handlePatternChange:g}),f===`sheet.numfmt.accounting`&&/* @__PURE__ */ W(os,{originPattern:i,handlePatternChange:g}),f===`sheet.numfmt.currency`&&/* @__PURE__ */ W(ss,{originPattern:i,handlePatternChange:g}),f===`sheet.numfmt.date`&&/* @__PURE__ */ W(cs,{originPattern:i,handlePatternChange:g}),f===`sheet.numfmt.thousandthPercentile`&&/* @__PURE__ */ W(ls,{originPattern:i,handlePatternChange:g})]}),/* @__PURE__ */ G(En,{className:`univer-mt-2 univer-flex univer-justify-end`,children:[/* @__PURE__ */ W(V,{onClick:y,children:s.t(`sheets-pivot-ui.dialog.numfmt.cancel`)}),/* @__PURE__ */ W(V,{className:`univer-ml-3 rtl:univer-ml-0 rtl:univer-mr-3`,variant:`primary`,onClick:()=>{c.close(Mr);let e=v(!0);c.open(e)},children:s.t(`sheets-pivot-ui.dialog.numfmt.confirm`)})]})]})};function ds(e){var t,n;let{scope:r,report:i,getCurrentReport:a,onChange:o}=e,s=z(L),c=z(Ue),l=z(be),u=z(Ge),d=z(We);B(u.permissionPointUpdate$);let[f,p]=Y(!1),m=J(!1),h=J(!0),g=JSON.stringify(r),_=J(g);_.current=g,q(()=>(h.current=!0,()=>{h.current=!1}),[]);let v=f||!i||((t=u.getPermissionPoint(new Et(r.unitId).id))==null?void 0:t.value)===!1||((n=u.getPermissionPoint(new Ot(r.unitId,r.subUnitId).id))==null?void 0:n.value)===!1,b=async e=>{if(m.current||v||!i||i.options.allowMultipleFilters===e)return;m.current=!0,p(!0);let t=$e.deepClone(i);try{if(!e&&y(i)){let e=await l.asyncInterceptor.fetchThroughAsyncInterceptors(te)({redos:[],undos:[],groups:[],validate:()=>void 0},r);if(!h.current||_.current!==g||!await c.confirm({id:`sheet-pivot.confirm.disable-multiple-filters`,title:{title:s.t(`sheets-pivot-ui.config.multipleFiltersTitle`)},children:{title:s.t(`sheets-pivot-ui.config.multipleFiltersClearWarning`)},cancelText:s.t(`sheets-pivot-ui.dialog.cancel`),confirmText:s.t(`sheets-pivot-ui.dialog.ok`)}))return;e==null||e.validate()}if(!h.current||_.current!==g||!$e.diffValue(t,a()))return;await o(e)}catch(e){d.error(`[PivotFilterOptions]`,e)}finally{m.current=!1,h.current&&p(!1)}};return/* @__PURE__ */ G(`section`,{className:`univer-flex univer-flex-col univer-gap-3`,children:[/* @__PURE__ */ W(`div`,{className:`univer-text-sm univer-font-medium univer-text-gray-600`,children:s.t(`sheets-pivot-ui.config.filteringSection`)}),/* @__PURE__ */ G(`label`,{className:`univer-flex univer-items-start univer-gap-2 univer-text-sm`,children:[/* @__PURE__ */ W(H,{checked:(i==null?void 0:i.options.allowMultipleFilters)===!0,disabled:v,onChange:e=>b(!!e)}),/* @__PURE__ */ W(`span`,{children:s.t(`sheets-pivot-ui.config.allowMultipleFilters`)})]})]})}const fs=[{label:`sheets-pivot-ui.config.pageDownThenOver`,value:`false`},{label:`sheets-pivot-ui.config.pageOverThenDown`,value:`true`}],ps=[{label:`sheets-pivot-ui.config.layoutTabular`,value:String(c.tabular)},{label:`sheets-pivot-ui.config.layoutCompact`,value:String(c.compact)},{label:`sheets-pivot-ui.config.layoutOutline`,value:String(c.outline)}],ms=[{label:`sheets-pivot-ui.config.rowSubtotalTop`,value:String(d.top)},{label:`sheets-pivot-ui.config.rowSubtotalBottom`,value:String(d.bottom)}],hs=[{label:`sheets-pivot-ui.config.dateGroupingLegacy`,value:a.Legacy},{label:`sheets-pivot-ui.config.dateGroupingExcelLike`,value:a.ExcelLike}];function gs(e){let{unitId:t,subUnitId:n,pivotTableId:r}=e,i=z(P),a=z(Ue),o=z(We),s=z(L),l=z(M),u=_r(()=>l.watchPivotTableChanges(t,n,r).pipe(hn(0)),[l,t,n,r]);B(u);let[f,p]=Y(!1),m=J(!1),h=l.getPivotTableConfig(t,n,r),g=v(h==null?void 0:h.fieldsConfig.options),[_,y]=Y(()=>{var e,i;let a=l.getPivotTableConfig(t,n,r),o=(a==null||(e=a.fieldsConfig)==null?void 0:e.options)??{};return{showRowSubtotal:o.showRowSubtotal??!0,showRowGrandTotal:o.showRowGrandTotal??!0,showColSubtotal:o.showColSubtotal??!0,showColGrandTotal:o.showColGrandTotal??!0,pageWrap:o.pageWrap??1,pageOverThenDown:o.pageOverThenDown??!1,repeatRowLabels:o.repeatRowLabels??!1,repeatColLabels:o.repeatColLabels??!1,layout:(a==null||(i=a.fieldsConfig)==null?void 0:i.layout)??c.tabular,rowSubtotalPosition:o.rowSubtotalPosition??d.top}}),x=e=>{let a={unitId:t,subUnitId:n,pivotTableId:r,options:e};i.executeCommand(ge.id,a).catch(e=>o.error(`[PivotConfigPanel]`,e)),y(t=>({...t,...e}))},S=e=>{let a={unitId:t,subUnitId:n,pivotTableId:r,layout:e};i.executeCommand(pe.id,a).catch(e=>o.error(`[PivotConfigPanel]`,e)),y(t=>({...t,layout:e}))},C=async e=>{if(!(m.current||e===g)){m.current=!0,p(!0);try{let o=l.getPivotTableConfig(t,n,r),c=l.getCollection(t,r);if(!o||!c||(Object.values(c.fields).some(b)||c.customFields.some(b))&&!await a.confirm({id:`sheet-pivot.confirm.change-date-grouping-mode`,title:{title:s.t(`sheets-pivot-ui.config.dateGroupingSwitchTitle`)},children:{title:s.t(`sheets-pivot-ui.config.dateGroupingSwitchMessage`)},cancelText:s.t(`sheets-pivot-ui.dialog.cancel`),confirmText:s.t(`sheets-pivot-ui.dialog.ok`)})||l.getPivotTableConfig(t,n,r)!==o||l.getCollection(t,r)!==c||v(o.fieldsConfig.options)===e)return;await i.executeCommand(ge.id,{unitId:t,subUnitId:n,pivotTableId:r,options:{dateGroupingMode:e}})}catch(e){o.error(`[PivotConfigPanel]`,e)}finally{m.current=!1,p(!1)}}};return/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-4 univer-py-4`,children:[/* @__PURE__ */ W(ds,{scope:{unitId:t,subUnitId:n,pivotTableId:r},report:h==null?void 0:h.fieldsConfig,getCurrentReport:()=>{var e;return(e=l.getPivotTableConfig(t,n,r))==null?void 0:e.fieldsConfig},onChange:e=>i.executeCommand(ge.id,{unitId:t,subUnitId:n,pivotTableId:r,options:{allowMultipleFilters:e}})}),/* @__PURE__ */ G(`section`,{children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-600`,children:s.t(`sheets-pivot-ui.config.displaySection`)}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ G(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-2`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-sm univer-text-gray-600`,children:s.t(`sheets-pivot-ui.config.dateGroupingMode`)}),/* @__PURE__ */ W(zn,{className:`univer-w-36`,value:g,options:hs.map(e=>({...e,label:s.t(e.label)})),disabled:f,onChange:e=>C(e)})]}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-2`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-sm univer-text-gray-600`,children:s.t(`sheets-pivot-ui.config.layout`)}),/* @__PURE__ */ W(zn,{className:`univer-w-36`,value:String(_.layout),options:ps.map(e=>({...e,label:s.t(e.label)})),onChange:e=>S(Number(e))})]}),/* @__PURE__ */ G(`label`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-text-sm univer-text-gray-600`,children:[/* @__PURE__ */ W(H,{checked:_.repeatRowLabels,disabled:_.layout===c.compact,onChange:e=>x({repeatRowLabels:!!e})}),s.t(`sheets-pivot-ui.config.repeatRowLabels`)]}),/* @__PURE__ */ G(`label`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-text-sm univer-text-gray-600`,children:[/* @__PURE__ */ W(H,{checked:_.repeatColLabels,onChange:e=>x({repeatColLabels:!!e})}),s.t(`sheets-pivot-ui.config.repeatColLabels`)]})]})]}),/* @__PURE__ */ G(`section`,{children:[/* @__PURE__ */ W(`div`,{className:U(`univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-600`),children:s.t(`sheets-pivot-ui.config.totalsSection`)}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ G(`label`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-text-sm univer-text-gray-600`,children:[/* @__PURE__ */ W(H,{checked:_.showRowSubtotal,onChange:e=>x({showRowSubtotal:!!e})}),s.t(`sheets-pivot-ui.config.showRowSubtotal`)]}),_.layout===c.outline&&/* @__PURE__ */ G(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-2`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-sm univer-text-gray-600`,children:s.t(`sheets-pivot-ui.config.rowSubtotalPosition`)}),/* @__PURE__ */ W(zn,{className:`univer-w-36`,value:String(_.rowSubtotalPosition),options:ms.map(e=>({...e,label:s.t(e.label)})),onChange:e=>x({rowSubtotalPosition:Number(e)})})]}),/* @__PURE__ */ G(`label`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-text-sm univer-text-gray-600`,children:[/* @__PURE__ */ W(H,{checked:_.showRowGrandTotal,onChange:e=>x({showRowGrandTotal:!!e})}),s.t(`sheets-pivot-ui.config.showRowGrandTotal`)]}),/* @__PURE__ */ G(`label`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-text-sm univer-text-gray-600`,children:[/* @__PURE__ */ W(H,{checked:_.showColSubtotal,onChange:e=>x({showColSubtotal:!!e})}),s.t(`sheets-pivot-ui.config.showColSubtotal`)]}),/* @__PURE__ */ G(`label`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-text-sm univer-text-gray-600`,children:[/* @__PURE__ */ W(H,{checked:_.showColGrandTotal,onChange:e=>x({showColGrandTotal:!!e})}),s.t(`sheets-pivot-ui.config.showColGrandTotal`)]})]})]}),/* @__PURE__ */ G(`section`,{children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-600`,children:s.t(`sheets-pivot-ui.config.pageSection`)}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-3`,children:[/* @__PURE__ */ G(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-2`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-sm univer-text-gray-600`,children:s.t(`sheets-pivot-ui.config.pageWrap`)}),/* @__PURE__ */ W(An,{className:`univer-w-24`,value:_.pageWrap,min:1,max:20,onChange:e=>{let t=Number(e);Number.isFinite(t)&&t>=1&&x({pageWrap:t})}})]}),/* @__PURE__ */ W(`p`,{className:`univer-text-xs univer-text-gray-600`,children:s.t(_.pageOverThenDown?`sheets-pivot-ui.config.pageWrapOverThenDownHelp`:`sheets-pivot-ui.config.pageWrapDownThenOverHelp`)}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-2`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-sm univer-text-gray-600`,children:s.t(`sheets-pivot-ui.config.pageDirection`)}),/* @__PURE__ */ W(zn,{className:`univer-w-36`,value:String(_.pageOverThenDown),options:fs.map(e=>({...e,label:s.t(e.label)})),onChange:e=>x({pageOverThenDown:e===`true`})})]})]})]})]})}let _s=class extends N{constructor(e,t,n,r,i,a,o,s){super(),this._sheetsSelectionsService=e,this._univerInstanceService=t,this._sheetsPivotTableAdaptorModel=n,this._commandService=r,this._sidebarService=i,this._dialogService=a,this._injector=o,this._permissionService=s,X(this,`_pivotTableId`,void 0),X(this,`_pivotTablePanelVisible$`,new fn),X(this,`pivotTablePanelVisible$`,this._pivotTablePanelVisible$.asObservable()),X(this,`_isRangeSelectorFocus`,!1),X(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(Er))}_initPanelOpen(){let e=this._univerInstanceService.getCurrentUnitOfType(et.UNIVER_SHEET);if(e){let t=e.activeSheet$;this.disposeWithMe(yn(t,this._sheetsSelectionsService.selectionMoveEnd$).subscribe(()=>{let e=this._sheetsSelectionsService.getCurrentSelections();if(!e)return;let t=e[e.length-1];if(!t)return;let n=t.primary;if(!n)return;let r=this._univerInstanceService.getCurrentUnitOfType(et.UNIVER_SHEET),i=r==null?void 0:r.getActiveSheet();if(!r||!i)return;let a=r.getUnitId(),o=i.getSheetId(),s=this._sheetsPivotTableAdaptorModel.getPivotTableIdByCell(a,o,n.startRow,n.startColumn);if(s){var c,l;let e=(c=this._sheetsPivotTableAdaptorModel.getPivotItemRenderInfoCache(a,o,s))==null?void 0:c.rangesInfo,t=Fe(e),n=jt(this._injector,a,o,t),r=(l=this._permissionService.getPermissionPoint(new kt(a,o).id))==null?void 0:l.value;if(!n||!r)return;this._setPivotTableId(s),this._pivotTablePanelVisible$.next(!0),this._commandService.executeCommand(na.id,{pivotTableId:s})}else this._closePivotPanel()})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{e.id===ae.id&&e.params.pivotTableId===this._pivotTableId&&this._sidebarService.close(Er)}))}}_initSheetChange(){let e=this._univerInstanceService.getCurrentUnitOfType(et.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(Ar)}})),this.disposeWithMe(this._dialogService.getDialogs$().subscribe(e=>{let t=e.find(e=>e.id===Rr);t&&t.open===!1&&this._dialogService.close(Rr)}))}};_s=Q([Z(0,I(wt)),Z(1,I(F)),Z(2,I(j)),Z(3,I(P)),Z(4,I(Bt)),Z(5,I(R)),Z(6,I(Ke)),Z(7,I(Ge))],_s);const vs=hr(null),ys=hr(null);function bs(e,t){return e===t?!0:!e||!t?!1:e.droppableId===t.droppableId&&e.index===t.index}function xs(e){if(!(e instanceof Element))return null;let t=e.closest(`[data-univer-dnd-droppable-id]`);return t instanceof HTMLElement?t:null}function Ss(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 Cs(){let e=gr(vs);if(!e)throw Error(`Draggable/Droppable must be used inside DragDropContext`);return e}function ws(e){let{children:t,onDragEnd:n,onDragStart:r,onDragUpdate:i}=e,[a,o]=Y(null),s=J(null),c=K((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=K(e=>{let t=s.current;if(!t||bs(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=K(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]);q(()=>{if(!a)return;let e=e=>{let t=xs(e.target);t&&t.dataset.univerDndDropDisabled!==`true`||l(null)};return window.addEventListener(`dragover`,e,!0),()=>{window.removeEventListener(`dragover`,e,!0)}},[a,l]);let d=_r(()=>({activeDrag:a,startDrag:c,updateDestination:l,endDrag:u}),[a,c,l,u]);return/* @__PURE__ */ W(vs.Provider,{value:d,children:t})}function Ts(e){var t;let{children:n,droppableId:r,isDropDisabled:i=!1}=e,{activeDrag:a,updateDestination:o,endDrag:s}=Cs(),c=J(null),l={innerRef:K(e=>{c.current=e},[]),droppableProps:{onDragOver:K(e=>{if(!a||i||!c.current)return;e.preventDefault();let t=Ss(c.current,e.clientY,a,r);o({droppableId:r,index:t})},[a,i,r,o]),onDrop:K(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:Ss(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__ */ W(ys.Provider,{value:r,children:n(l,u)})}function Es(e){var t;let{children:n,draggableId:r,index:i,isDragDisabled:a=!1}=e,{activeDrag:o,startDrag:s,updateDestination:c,endDrag:l}=Cs(),u=gr(ys),d=J(null),f=J(null),p=J(!1),m=J(null),h=J(null),g=J(!1),_=J(null),v=J(null),y=J(null),b=K(e=>{d.current=e},[]),x=(o==null?void 0:o.draggableId)===r,S=K(()=>{h.current&&=(window.clearTimeout(h.current),null)},[]),C=K(()=>{S(),y.current=null,m.current&&=(m.current(),null),_.current&&=(_.current.remove(),null),v.current=null,p.current=!1},[S]);q(()=>C,[C]);let w=K((e,t)=>{if(_.current)return;let n=d.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),_.current=s,v.current={x:i,y:a}},[]),T=K((e,t)=>{let n=_.current,r=v.current;n&&r&&(n.style.transform=`translate(${Math.max(0,e-r.x)}px, ${Math.max(0,t-r.y)}px)`)},[]),E=K((e,t)=>{let n=xs(document.elementFromPoint(e,t));if(!n||n.dataset.univerDndDropDisabled===`true`)return null;let a=n.dataset.univerDndDroppableId;return a?{droppableId:a,index:Ss(n,t,{draggableId:r,source:{droppableId:u??``,index:i},destination:null},a)}:null},[r,u,i]),D=K((e,t,n,o)=>{if(p.current||g.current||a||!u)return;p.current=!0,S(),g.current=!1;try{var l;(l=d.current)==null||l.setPointerCapture(t)}catch{}w(n,o),s(r,{droppableId:u,index:i});let f=E(n,o);c(f);try{e.preventDefault()}catch{}},[S,r,u,i,a,w,E,s,c]),O=K(e=>{if(a||!u||e.pointerType===`mouse`&&e.button!==0)return;g.current=!1;let t=e.pointerId;y.current={pointerId:t,pointerType:e.pointerType,startX:e.clientX,startY:e.clientY},S(),e.pointerType!==`mouse`&&(h.current=window.setTimeout(()=>{let n=y.current;n&&n.pointerId===t&&D(e.nativeEvent,n.pointerId,n.startX,n.startY)},150));let n=e=>{let t=y.current;if(!t||e.pointerId!==t.pointerId)return;if(!p.current){if(g.current){C();return}if(t.pointerType===`mouse`){let n=e.clientX-t.startX,r=e.clientY-t.startY;n*n+r*r>=16&&D(e,t.pointerId,e.clientX,e.clientY)}return}T(e.clientX,e.clientY);let n=E(e.clientX,e.clientY);c(n);try{e.preventDefault()}catch{}},r=e=>{let t=y.current;if(!t||e.pointerId!==t.pointerId)return;let n=p.current?E(e.clientX,e.clientY):null,r=p.current?l(n?`DROP`:`CANCEL`,n):Promise.resolve();return C(),r};window.addEventListener(`pointermove`,n,{capture:!0,passive:!1}),window.addEventListener(`pointerup`,r,{capture:!0}),window.addEventListener(`pointercancel`,r,{capture:!0}),m.current=()=>{window.removeEventListener(`pointermove`,n,!0),window.removeEventListener(`pointerup`,r,!0),window.removeEventListener(`pointercancel`,r,!0)}},[C,S,u,l,a,E,D,c,T]),ee=K(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),f.current&&f.current!==i&&f.current.remove(),f.current=i},[]),te=K(e=>{if(p.current||a||!u){e.preventDefault();return}g.current=!0,S(),y.current=null,m.current&&=(m.current(),null);let t=e.dataTransfer;if(t){try{t.effectAllowed=`move`}catch{}try{t.setData(`text/plain`,r)}catch{}}try{ee(e)}catch{}s(r,{droppableId:u,index:i})},[ee,S,r,u,i,a,s]),k=K(()=>(f.current&&=(f.current.remove(),null),l(`CANCEL`,null)),[l]);return n({innerRef:b,draggableProps:{draggable:!a,onDragStart:te,onDragEnd:k,style:x?{opacity:1}:void 0,"data-univer-dnd-item":`true`,"data-univer-dnd-id":r,"data-univer-dnd-index":String(i)},dragHandleProps:{onPointerDown:O}},{isDragging:x,draggingOver:o==null||(t=o.destination)==null?void 0:t.droppableId})}function Ds(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 Os(e){switch(e){case`filter`:return/* @__PURE__ */ W(ir,{className:`univer-flex univer-flex-row univer-gap-4`});case`row`:return/* @__PURE__ */ W(nr,{className:`univer-flex univer-flex-row univer-gap-4`});case`column`:return/* @__PURE__ */ W(dr,{className:`univer-flex univer-flex-row univer-gap-4`});case`value`:return/* @__PURE__ */ W(ar,{className:`univer-flex univer-flex-row univer-gap-4`})}}function ks(e){switch(e){case`filter`:return/* @__PURE__ */ G(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`32`,height:`32`,viewBox:`0 0 32 32`,fill:`none`,children:[/* @__PURE__ */ W(`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__ */ W(`rect`,{x:`21.9404`,y:`17.8544`,width:`7.59766`,height:`2.2793`,rx:`1.13965`,fill:`#274FEE`}),/* @__PURE__ */ W(`rect`,{x:`21.9404`,y:`21.9067`,width:`7.59766`,height:`2.2793`,rx:`1.13965`,fill:`#274FEE`}),/* @__PURE__ */ W(`rect`,{x:`21.9404`,y:`25.959`,width:`7.59766`,height:`2.2793`,rx:`1.13965`,fill:`#274FEE`})]});case`row`:return/* @__PURE__ */ G(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`32`,height:`32`,viewBox:`0 0 32 32`,fill:`none`,children:[/* @__PURE__ */ W(`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__ */ W(`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__ */ W(`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__ */ W(`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__ */ G(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`32`,height:`32`,viewBox:`0 0 32 32`,fill:`none`,children:[/* @__PURE__ */ W(`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__ */ W(`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__ */ W(`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__ */ W(`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__ */ G(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`32`,height:`32`,viewBox:`0 0 32 32`,fill:`none`,children:[/* @__PURE__ */ W(`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__ */ W(`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__ */ W(`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__ */ W(`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 As(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 js(e){let t=z(L),{areaType:n}=e,r=As(n,t),i=ks(n);return/* @__PURE__ */ G(`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__ */ W(`div`,{className:`univer-size-8`,children:i}),/* @__PURE__ */ W(`div`,{className:`univer-text-center univer-text-xs univer-leading-4 univer-text-gray-600 dark:!univer-text-gray-200`,children:r})]})}function Ms(e){let{areaType:t,items:n,positionInfo:r,pivotTableId:i,pivotTableInfo:a}=e,o=z(L);return/* @__PURE__ */ G(`div`,{className:`univer-min-h-[200px] univer-flex-1 univer-p-1`,children:[/* @__PURE__ */ G(`div`,{className:`univer-mb-2 univer-mt-0 univer-flex univer-w-full univer-text-sm univer-leading-4 univer-text-gray-900`,children:[Os(t),/* @__PURE__ */ W(`span`,{className:`univer-inline-block univer-align-top`,children:Ds(t,o)})]}),/* @__PURE__ */ W(Ts,{droppableId:`${t}`,isCombineEnabled:!1,isDropDisabled:!1,ignoreContainerClipping:!1,direction:`vertical`,children:(e,o)=>/* @__PURE__ */ W(`div`,{className:U(`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`,Un,{"univer-border-primary-600":o.isDraggingOver}),children:/* @__PURE__ */ W(`div`,{className:U(`univer-h-full univer-overflow-y-auto`,Wn),children:/* @__PURE__ */ G(`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__ */ W(`div`,{children:/* @__PURE__ */ W(Es,{isDragDisabled:!1,draggableId:e.tableFieldId,index:n,children:(n,o)=>/* @__PURE__ */ W(mr,{children:/* @__PURE__ */ W(`div`,{ref:n.innerRef,...n.draggableProps,...n.dragHandleProps,style:n.draggableProps.style,className:U(`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`,o.draggingOver&&`univer-border-primary-600`),children:/* @__PURE__ */ W(Ns,{pivotTableId:i,positionInfo:r,item:e,areaType:t,pivotTableInfo:a})})})},e.tableFieldId)},e.tableFieldId)),n.length===0&&/* @__PURE__ */ W(js,{areaType:t})]})})})})]})}function Ns(e){let{areaType:t,item:n,positionInfo:r,pivotTableId:i,pivotTableInfo:a}=e,{unitId:o,subUnitId:s}=r,c=n.tableFieldId===pa,l=z(P),u=z(L),d=()=>{if(c){let e=(a.valueFields||[]).map(e=>e.tableFieldId);Ca({pivotTableId:i,unitId:o,subUnitId:s,commandService:l},e)}else Ca({pivotTableId:i,unitId:o,subUnitId:s,commandService:l},[n.tableFieldId])},f=()=>{o&&s&&Ea(l,o,s,i,n.tableFieldId)},p=()=>{o&&s&&Da(l,i,n.tableFieldId,o,s,a)},h=e=>{let t=e===`column`?m.Row:m.Column,n=e===`column`?a.rowFields.length:a.columnFields.length;wa({pivotTableId:i,unitId:o,subUnitId:s,commandService:l},t,n)},g=/* @__PURE__ */ G(`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__ */ W(`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:()=>{d()},children:u.t(`sheets-pivot-ui.removeField`)}),t!==`value`&&!c&&/* @__PURE__ */ W(`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:()=>{f()},children:u.t(`sheets-pivot-ui.filterField`)}),c&&/* @__PURE__ */ W(`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:()=>{h(t)},children:t===`column`?u.t(`sheets-pivot-ui.moveToRow`):u.t(`sheets-pivot-ui.moveToColumn`)}),t===`value`&&/* @__PURE__ */ W(`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:()=>{p()},children:u.t(`sheets-pivot-ui.fieldSettings`)})]}),_=c?u.t(`sheets-pivot-ui.multipleValue`):n.displayName,v=/* @__PURE__ */ W(`bdi`,{dir:`auto`,children:_});return/* @__PURE__ */ G(mr,{children:[/* @__PURE__ */ W(or,{}),/* @__PURE__ */ W(`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__ */ W(Hn,{title:v,children:v})}),/* @__PURE__ */ W(`div`,{className:`univer-cursor-pointer`,children:/* @__PURE__ */ W(On,{align:`end`,overlay:g,children:/* @__PURE__ */ W(`span`,{children:/* @__PURE__ */ W(cr,{})})})})]})}function Ps(e){var t;let n=z(F),r=z(L),i=z(P),a=z(_s),{sourceRangeInfo:o,refreshHandler:s,pivotTableId:c,positionInfo:l}=e,{unitId:u,range:d,subUnitId:f}=o,p=n.getUnit(u),m=(p==null||(t=p.getSheetBySheetId(f))==null?void 0:t.getName())??``,[h,g]=Y(void 0),_=J(h);_.current=h;let[v,y]=Y(d),[b,x]=Y(m),[S,C]=Y(!1);q(()=>{a.setIsRangeSelectorFocus(S)},[S,a]),q(()=>{y(o.range),x(m)},[o,m]);let w=_r(()=>rt(async e=>{let t=e.split(`,`).filter(e=>!!e).map(vr);if(!t[0])return;let n=t[0];if(!p||_.current)return;let r=n.sheetName||o.sheetName;y(n.range),x(r);let a={unitId:u,subUnitId:p.getSheetBySheetName(r).getSheetId(),range:{...n.range},sheetName:r};await ba(i,c,a,l.unitId,l.subUnitId),s()},300,{leading:!1,maxWait:1e3,trailing:!0}),[]);return/* @__PURE__ */ G(`div`,{className:`univer-mb-4`,children:[/* @__PURE__ */ G(`div`,{className:`univer-mb-2 univer-flex univer-h-5 univer-justify-between univer-text-sm univer-leading-5`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-justify univer-text-gray-900 dark:!univer-text-gray-0`,children:r.t(`sheets-pivot-ui.sourceRangeLabel`)}),/* @__PURE__ */ W(`span`,{className:`univer-text-xs univer-text-gray-600 dark:!univer-text-gray-200`,children:r.t(`sheets-pivot-ui.sourceRangePlaceholder`)})]}),/* @__PURE__ */ G(`div`,{className:`univer-relative`,children:[/* @__PURE__ */ W(Sr,{unitId:u,subUnitId:f,initialValue:br(b,v),onChange:(e,t)=>{br(b,v)!==t&&w(t)},keepSheetReference:!0,supportAcrossSheet:!0,onVerify:(e,t)=>{let n=t.split(`,`).filter(e=>!!e);if(!n[0]){g(r.t(`sheets-pivot-ui.msg.emptySourceRange`));return}if(!e){g(r.t(`sheets-pivot-ui.msg.invalidSize`));return}let i=vr(n[0]),a=i.sheetName||o.sheetName;if(p)switch(va(p.getSheetBySheetName(a),i.range)){case 2:g(void 0);break;case 0:g(r.t(`sheets-pivot-ui.msg.emptySourceRange`));break;case 1:g(r.t(`sheets-pivot-ui.msg.invalidSize`))}},maxRangeCount:1,onFocusChange:e=>{C(e)},onRangeSelectorDialogVisibleChange:e=>{C(!!e)}}),h?/* @__PURE__ */ W(`div`,{className:`univer-my-1 univer-text-xs univer-text-red-500`,children:h}):null]})]})}function Fs(e){let{type:t}=e;switch(t){case n.text:return/* @__PURE__ */ W(pr,{className:`univer-mx-1.5 univer-my-0 univer-h-4 univer-text-xs univer-text-gray-200 dark:!univer-text-gray-600`});case n.number:return/* @__PURE__ */ W(lr,{className:`univer-mx-1.5 univer-my-0 univer-h-4 univer-text-xs univer-text-gray-200 dark:!univer-text-gray-600`});case n.date:return/* @__PURE__ */ W(er,{className:`univer-mx-1.5 univer-my-0 univer-h-4 univer-text-xs univer-text-gray-200 dark:!univer-text-gray-600`})}}function Is(e){if(!e)return!1;if(e.type===s.RecordFilter){var t;return e.dateRange!==void 0||(((t=e.selection)==null?void 0:t.mode)??Ve.All)!==Ve.All}return e.type!==s.ManualFilter||e.isAll!==!0}function Ls(e){let{name:t,dataFieldId:r,checked:i,type:a,refreshHandler:o,pivotTableId:s,draggingId:c,pivotTableInfo:l,unitId:u,subUnitId:d}=e,[f,m]=Y(!1),h=z(P),g=z(L);if(!l)return null;let{rowFields:_,columnFields:v,filterFields:y,valueFields:b}=l,x=l.hiddenFields??[],S=[..._,...v,...y,...b,...x],C=x.find(e=>e.dataFieldId===r),w=async e=>{let t=!!e,i=!1;if(t){let e={pivotTableId:s,dataFieldId:r,fieldArea:a===n.number?p.Value:p.Row,unitId:u,subUnitId:d,index:a===n.number?b.length:_.length};i=await h.executeCommand(T.id,e)}else{let e=[];S.forEach(t=>{t.dataFieldId===r&&e.push(t.tableFieldId)}),i=await h.executeCommand(re.id,{pivotTableId:s,fieldIds:e,unitId:u,subUnitId:d})}i&&o()},E=async e=>{let t=!1,n=``;if([..._,...v,...y,...x].forEach(e=>{e.dataFieldId===r&&(t=!0,n=e.tableFieldId)}),t&&e!==p.Value){if(s){let t=za(l,e),r={pivotTableId:s,area:e,index:t,fieldId:n,unitId:u,subUnitId:d};await h.executeCommand(O.id,r)&&o()}}else if(s){let t={pivotTableId:s,dataFieldId:r,fieldArea:e,unitId:u,subUnitId:d,index:za(l,e)};await h.executeCommand(T.id,t)&&o()}};return/* @__PURE__ */ G(`div`,{className:U(`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":c===r}),id:`source-${r}`,onContextMenu:e=>{e.preventDefault(),m(!0)},children:[/* @__PURE__ */ W(`span`,{className:`univer-mr-2 univer-w-4 rtl:univer-ml-2 rtl:univer-mr-0`,children:/* @__PURE__ */ W(or,{})}),/* @__PURE__ */ W(H,{className:`univer-w-[14px] univer-text-sm univer-text-gray-200`,checked:i,onChange:w}),/* @__PURE__ */ G(`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__ */ W(Fs,{type:a}),/* @__PURE__ */ W(`span`,{className:`univer-truncate`,children:t})]}),/* @__PURE__ */ W(On,{align:`end`,side:`bottom`,open:f,onOpenChange:m,overlay:/* @__PURE__ */ G(`div`,{children:[Is(C==null?void 0:C.filterInfo)&&/* @__PURE__ */ W(`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()=>{C&&(m(!1),await h.executeCommand(fe.id,{unitId:u,subUnitId:d,pivotTableId:s,tableFieldId:C.tableFieldId,items:[],partialItems:[],isAll:!0})&&o())},children:g.t(`sheets-pivot-ui.dialog.filter.clearFilter`)}),/* @__PURE__ */ W(`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:()=>{m(!1),E(p.Row)},children:g.t(`sheets-pivot-ui.addToRow`)}),/* @__PURE__ */ W(`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:()=>{m(!1),E(p.Column)},children:g.t(`sheets-pivot-ui.addToColumn`)}),/* @__PURE__ */ W(`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:()=>{m(!1),E(p.Value)},children:g.t(`sheets-pivot-ui.addToValue`)}),/* @__PURE__ */ W(`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:()=>{m(!1),E(p.Filter)},children:g.t(`sheets-pivot-ui.addToFilter`)})]}),children:/* @__PURE__ */ W(`div`,{className:U(`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":f,"univer-opacity-0 group-hover:univer-opacity-100":!f}),onMouseDown:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),children:/* @__PURE__ */ W(sr,{className:`univer-text-gray-400 dark:!univer-text-gray-500`})})})]},r)}function Rs(e){let{sourceList:t,refreshHandler:n,pivotTableId:r,pivotTableInfo:i,unitId:a,draggingId:o,subUnitId:s}=e,c=z(L),[l,u]=Y(``),d=l.trim().toLocaleLowerCase(),f=d?t.filter(e=>e.name.toLocaleLowerCase().includes(d)):t;return/* @__PURE__ */ G(`div`,{className:`univer-mb-4 univer-flex univer-min-h-0 univer-flex-1 univer-flex-col`,children:[/* @__PURE__ */ W(`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:c.t(`sheets-pivot-ui.sourceFieldTile`)}),/* @__PURE__ */ W(`p`,{className:`univer-mb-2 univer-mt-0 univer-text-xs univer-leading-4 univer-text-gray-600 dark:!univer-text-gray-200`,children:c.t(`sheets-pivot-ui.sourceFieldDescription`)}),/* @__PURE__ */ W(kn,{allowClear:!0,className:`univer-mb-2`,placeholder:c.t(`sheets-pivot-ui.searchFieldPlaceholder`),slot:/* @__PURE__ */ W(fr,{}),value:l,onChange:u}),/* @__PURE__ */ W(`div`,{className:U(`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`,Un),children:/* @__PURE__ */ W(`div`,{className:U(`univer-relative univer-h-full univer-overflow-y-auto`,Wn),"data-testid":`pivot-source-field-viewport`,children:/* @__PURE__ */ W(Ts,{droppableId:`source`,direction:`vertical`,isCombineEnabled:!1,ignoreContainerClipping:!1,isDropDisabled:!0,children:e=>/* @__PURE__ */ G(`div`,{ref:e.innerRef,className:`univer-box-border univer-h-full univer-px-2`,...e.droppableProps,children:[f.map((e,t)=>/* @__PURE__ */ W(`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__ */ W(Es,{draggableId:e.id,isDragDisabled:!1,index:t,children:({innerRef:t,draggableProps:c,dragHandleProps:l})=>/* @__PURE__ */ W(`div`,{ref:t,...c,...l,className:`univer-h-8 univer-w-full`,style:c.style,children:/* @__PURE__ */ W(Ls,{draggingId:o,unitId:a,subUnitId:s,...e,refreshHandler:n,pivotTableId:r,pivotTableInfo:i})})},e.id)},e.id)),f.length===0&&/* @__PURE__ */ W(`div`,{className:`univer-py-4 univer-text-center univer-text-xs univer-text-gray-500`,children:c.t(`sheets-pivot-ui.noMatchingFields`)})]})})})})]})}function zs(e){let{pivotTableId:t,version:n,unitId:r,subUnitId:i,panelInfo:a}=e,o=z(M),s=_r(()=>o.watchPivotTableChanges(r,i,t).pipe(hn(0)),[o,r,i,t]),c=B(s),l=z(ye),u=z(_s),d=B(u.pivotTablePanelVisible$,!0),f=z(P),p=z(We),[m,h]=Y(a),[g,_]=Y(null),v=K(async()=>{if(!o.getPivotTableConfig(r,i,t))return;let e=await l.getPivotDisplayConfig({unitId:r,subUnitId:i,pivotTableId:t,params:{type:k.Panel,panel:{pivotTableId:t}}});e.result.panel&&h(e.result.panel)},[t,l,o,i,r]);q(()=>{v().catch(e=>p.error(`[PivotPanel]`,e))},[p,c,t,v,n]);let y=async e=>{let{source:n,destination:a,draggableId:o}=e;_(null);let s={pivotTableInfo:m,pivotTableId:t,commandService:f,unitId:r,subUnitId:i},c=n.droppableId;if(a&&a.droppableId){let e=a.droppableId;await Sa(s,o,c,e,a.index),await v()}a===null&&(await ya(s,o,c),await v())},b=e=>{_({draggingId:e.draggableId})},x=e=>{let{draggableId:t,destination:n,source:r}=e;_({draggingId:t,destination:n,source:r})};if(!d||!m)return null;let{sourceList:S,rowFields:C,columnFields:w,filterFields:T,valueFields:E,sourceRange:D,positionInfo:O}=m;return/* @__PURE__ */ G(`div`,{className:U(`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`,Wn),children:[/* @__PURE__ */ W(Ps,{sourceRangeInfo:D,pivotTableId:t,refreshHandler:v,positionInfo:O}),/* @__PURE__ */ G(ws,{onDragEnd:y,onDragStart:b,onDragUpdate:x,children:[/* @__PURE__ */ W(Rs,{draggingId:(g==null?void 0:g.draggingId)??``,sourceList:S,refreshHandler:v,pivotTableId:t,pivotTableInfo:m,unitId:r,subUnitId:i}),/* @__PURE__ */ W(Bs,{rowFields:C,columnFields:w,filterFields:T,valueFields:E,refreshHandler:v,positionInfo:O,pivotTableId:t,pivotTableInfo:m})]})]})}function Bs(e){let{rowFields:t,columnFields:n,filterFields:r,valueFields:i,refreshHandler:a,pivotTableInfo:o,positionInfo:s,pivotTableId:c}=e;return/* @__PURE__ */ G(`div`,{className:`univer-shrink-0`,"data-testid":`pivot-field-areas`,children:[/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-row univer-gap-4`,children:[/* @__PURE__ */ W(Ms,{areaType:`filter`,items:r,positionInfo:s,pivotTableId:c,pivotTableInfo:o,refreshHandler:a}),/* @__PURE__ */ W(Ms,{areaType:`column`,items:n,positionInfo:s,pivotTableId:c,pivotTableInfo:o,refreshHandler:a})]}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-row univer-gap-4`,children:[/* @__PURE__ */ W(Ms,{areaType:`row`,items:t,positionInfo:s,pivotTableId:c,pivotTableInfo:o,refreshHandler:a}),/* @__PURE__ */ W(Ms,{areaType:`value`,items:i,positionInfo:s,pivotTableId:c,pivotTableInfo:o,refreshHandler:a})]})]})}function Vs(e){let{className:t,unitId:n,subUnitId:r,pivotTableId:i}=e,[a,o]=Y(0),s=z(L),c=s.getDirection();return/* @__PURE__ */ G(`div`,{className:U(`univer-flex univer-size-full univer-min-h-0 univer-flex-col`,t),dir:c,children:[/* @__PURE__ */ W(Rn,{className:`univer-my-3 univer-w-full univer-shrink-0`,items:[{label:s.t(`sheets-pivot-ui.fieldPanel`),value:0},{label:s.t(`sheets-pivot-ui.configPanel`),value:1}],value:a,onChange:o}),/* @__PURE__ */ W(`div`,{className:U(`univer-min-h-0 univer-flex-1`,a===0?`univer-overflow-hidden`:`univer-overflow-auto`),children:a===0?/* @__PURE__ */ W(zs,{...e}):/* @__PURE__ */ W(gs,{unitId:n,subUnitId:r,pivotTableId:i})})]})}function Hs(e){let{unitId:t,subUnitId:n,pivotTableId:r,tableFieldId:i,type:a}=e,o=JSON.stringify([t,n,r,i,a]);return/* @__PURE__ */ W(Us,{...e},o)}function Us({unitId:e,subUnitId:t,pivotTableId:r,tableFieldId:i,type:a,baseItems:o,onConfirm:s,onCancel:c}){var u;let d=z(M),f=z(L),p=B(f.direction$,f.getDirection()),m=ci.find(e=>e.type===a),h=d.getPivotTableConfig(e,t,r),g=h==null||(u=h.fieldsConfig.measure[i])==null?void 0:u.showDataAs,_=()=>{var e;if((g==null?void 0:g.type)!==a||!g.baseFieldId)return``;if(g.baseItemType===l.previous)return`relative:previous`;if(g.baseItemType===l.next)return`relative:next`;let t=((e=o[g.baseFieldId])==null?void 0:e.items.indexOf(g.baseItem))??-1;return t<0?``:`item:${t}`},[v,y]=Y((g==null?void 0:g.type)===a?g.baseFieldId:``),[b,x]=Y(_),S=J(!1),[C,w]=Y(!1),T=d.getPivotTableConfig(e,t,r),E=d.getCollection(e,r),D=T==null?void 0:T.fieldsConfig.measure[i],O=!!(D&&E&&(E.fields[D.dataFieldId]||E.customFields.find(e=>e.id===D.dataFieldId))),ee=(T&&E&&m?ui(T,E,m):[]).filter(e=>{let t=o[e];return(m==null?void 0:m.baseItemMode)===`none`||!!(t&&((m==null?void 0:m.baseItemMode)===`item-or-relative`||t.items.length>0))}),te=ee.map(e=>({label:T.fieldsConfig.dimension[e].displayName,value:e})),k=T==null?void 0:T.fieldsConfig.dimension[v],ne=k&&E&&(E.fields[k.dataFieldId]??E.customFields.find(e=>e.id===k.dataFieldId)),A=o[v],re=(A==null?void 0:A.items.map((e,t)=>{var r;let i=A.itemTypes[t],a=(r=A.itemLabels)==null?void 0:r[e],o=ma(e,i),s=e;return o?s=f.t(o):a===void 0?i===n.other?s=f.t(`sheets-pivot-ui.showValuesAs.other`):(i===n.date||i===n.number)&&A.format&&(s=ut.format(A.format,Number(e))):s=a,{label:s,value:`item:${t}`,itemKey:e}}))??[];(m==null?void 0:m.baseItemMode)===`item-or-relative`&&re.push({label:f.t(`sheets-pivot-ui.showValuesAs.previous`),value:`relative:previous`,itemKey:``,itemType:l.previous},{label:f.t(`sheets-pivot-ui.showValuesAs.next`),value:`relative:next`,itemKey:``,itemType:l.next});let ie=re.find(e=>e.value===b),ae=!!(m!=null&&m.baseItemMode&&m.baseItemMode!==`none`),oe=!!(m&&T&&E&&O&&T.fieldsConfig.valueFields.includes(i)&&ee.includes(v)&&ne&&(!ae||ie));return/* @__PURE__ */ G(`div`,{dir:p,children:[/* @__PURE__ */ G(`div`,{className:`univer-mb-4`,children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:f.t(`sheets-pivot-ui.showValuesAs.baseField`)}),/* @__PURE__ */ W(zn,{className:`univer-w-full`,value:v,options:te,onChange:e=>{y(e),x(``)}})]}),ae&&/* @__PURE__ */ G(`div`,{className:`univer-mb-4`,children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:f.t(`sheets-pivot-ui.showValuesAs.baseItem`)}),/* @__PURE__ */ W(zn,{className:`univer-w-full`,value:b,options:re,disabled:!v,onChange:x})]}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-justify-end univer-gap-3`,children:[/* @__PURE__ */ W(V,{onClick:c,children:f.t(`sheets-pivot-ui.showValuesAs.cancel`)}),/* @__PURE__ */ W(V,{variant:`primary`,disabled:!oe||C,onClick:async()=>{let n=d.getPivotTableConfig(e,t,r),o=d.getCollection(e,r),c=n==null?void 0:n.fieldsConfig.measure[i];if(!m||!n||!o||!c||S.current||!n.fieldsConfig.valueFields.includes(i)||!(o.fields[c.dataFieldId]||o.customFields.find(e=>e.id===c.dataFieldId))||!ui(n,o,m).includes(v)||ae&&!ie)return;let l={type:a,baseFieldId:v,baseItem:(ie==null?void 0:ie.itemKey)??``};(ie==null?void 0:ie.itemType)!==void 0&&(l.baseItemType=ie.itemType),S.current=!0,w(!0);try{await s(l)}catch{}finally{S.current=!1,w(!1)}},children:f.t(`sheets-pivot-ui.showValuesAs.ok`)})]})]})}const Ws=e=>{let[t,n]=Y(!1),r=z(_s);return q(()=>{r.setIsRangeSelector2Focus(t)},[t,r]),/* @__PURE__ */ W(Sr,{...e,onFocusChange:t=>{var r;(r=e.onFocusChange)==null||r.call(e,t),n(t)}})},Gs=(e,t,n,r,i,a)=>/* @__PURE__ */ W(Ws,{unitId:e,subUnitId:t,initialValue:r,onChange:(e,t)=>n(t),maxRangeCount:1,supportAcrossSheet:!0,keepSheetReference:!0}),Ks=(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 qs(e){let{unitId:t,sourceRange:n,positionRange:r,sourceSheetName:i,positionSheetName:a,onConfirm:o,onCancel:s}=e,c=z(L),l=z(F),u=c.getDirection(),d=l.getUnit(t),f=_r(()=>d.getActiveSheet().getSheetId(),[d]),[p,m]=Y(n),[h,g]=Y(r),[_,v]=Y(i),[y,b]=Y(a),x=J(void 0),[S,C]=Y(),[w,T]=Y(A.New),[E,D]=Y(!0),[O,ee]=Y(!0),[te,k]=Y(void 0);q(()=>{let e=va(d.getSheetBySheetName(_),p);ee(e===2),k(Ks(e,c))},[p,_,d,c]);let ne=e=>{if(br(_,p)===e)return;let t=e.split(`,`).filter(e=>!!e).map(vr);if(Array.isArray(t)&&t.length>0){let{range:e,sheetName:n}=t[0];m(e),v(n)}t[0]||k(c.t(`sheets-pivot-ui.msg.emptySourceRange`))},re=Gs(t,f,e=>{if(h&&br(y,h)===e)return;let t=e.split(`,`).filter(e=>!!e).map(vr);if(t.length===0){g(null);return}let n=t[0];g(n.range),b(n.sheetName||i),n.sheetName===i&&Ze.intersects(n.range,p)?D(!1):D(!0)},h?br(y,h):``,!1,S),ie=()=>!!(p&&h&&_&&y&&w===A.Existing&&E&&O)||!!(p&&_&&w===A.New&&O);return q(()=>{C(x.current)},[]),/* @__PURE__ */ G(`div`,{ref:x,dir:u,children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-h-5 univer-text-sm univer-font-medium`,children:c.t(`sheets-pivot-ui.dialog.source.sourceData`)}),Gs(t,f,ne,br(_,p),!0,S),te&&/* @__PURE__ */ W(`div`,{className:`univer-mt-2 univer-h-5 univer-text-xs univer-text-red-400`,children:te}),/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-mt-5 univer-h-5 univer-text-sm univer-font-medium`,children:c.t(`sheets-pivot-ui.dialog.source.position`)}),/* @__PURE__ */ G(Ln,{value:w,onChange:e=>T(e),className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ W(In,{value:A.New,children:c.t(`sheets-pivot-ui.dialog.source.newSheet`)}),/* @__PURE__ */ W(In,{value:A.Existing,children:c.t(`sheets-pivot-ui.dialog.source.existingSheet`)})]}),w===A.Existing&&/* @__PURE__ */ G(mr,{children:[re,!E&&/* @__PURE__ */ W(`span`,{className:`univer-h-5 univer-text-sm univer-text-red-400`,children:c.t(`sheets-pivot-ui.dialog.source.intersect`)})]}),/* @__PURE__ */ W(`footer`,{className:`univer-mt-5`,children:/* @__PURE__ */ G(En,{className:`univer-flex univer-justify-end univer-gap-2`,children:[/* @__PURE__ */ W(V,{onClick:()=>s(),children:c.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ W(V,{variant:`primary`,onClick:()=>{ie()&&(w===A.Existing?o({sourceRange:p,sourceSheetName:_,positionRange:h,positionSheetName:y,positionType:w}):o({sourceRange:p,sourceSheetName:_,positionType:w}))},children:c.t(`sheets-pivot-ui.dialog.ok`)})]})})]})}qs.componentKey=Rr;const Js=[{id:`equal`,localeKey:`sheets-pivot-ui.valueFilter.equal`,operator:h.valueEqual},{id:`notEqual`,localeKey:`sheets-pivot-ui.valueFilter.notEqual`,operator:h.valueNotEqual},{id:`greaterThan`,localeKey:`sheets-pivot-ui.valueFilter.greaterThan`,operator:h.valueGreaterThan},{id:`greaterThanOrEqual`,localeKey:`sheets-pivot-ui.valueFilter.greaterThanOrEqual`,operator:h.valueGreaterThanOrEqual},{id:`lessThan`,localeKey:`sheets-pivot-ui.valueFilter.lessThan`,operator:h.valueLessThan},{id:`lessThanOrEqual`,localeKey:`sheets-pivot-ui.valueFilter.lessThanOrEqual`,operator:h.valueLessThanOrEqual},{id:`between`,localeKey:`sheets-pivot-ui.valueFilter.between`,operator:h.valueBetween,isBetween:!0},{id:`notBetween`,localeKey:`sheets-pivot-ui.valueFilter.notBetween`,operator:h.valueNotBetween,isBetween:!0},{id:`topCount`,localeKey:`sheets-pivot-ui.valueFilter.topCount`,operator:h.count,isCount:!0},{id:`bottomCount`,localeKey:`sheets-pivot-ui.valueFilter.bottomCount`,operator:h.count,isBottom:!0,isCount:!0},{id:`topPercent`,localeKey:`sheets-pivot-ui.valueFilter.topPercent`,operator:h.percent,isPercent:!0},{id:`bottomPercent`,localeKey:`sheets-pivot-ui.valueFilter.bottomPercent`,operator:h.percent,isBottom:!0,isPercent:!0}];function Ys({targetFieldId:e,targetFieldName:t,valueFields:n,defaultValueFieldId:r,currentFilter:i,onConfirm:a,onClear:o,onCancel:s}){function c(e){var t;return(e==null?void 0:e.operator)===h.count?e.isBottom?`bottomCount`:`topCount`:(e==null?void 0:e.operator)===h.percent?e.isBottom?`bottomPercent`:`topPercent`:((t=Js.find(t=>t.operator===(e==null?void 0:e.operator)))==null?void 0:t.id)??`greaterThan`}let l=z(L),u=B(l.direction$,l.getDirection()),d=i==null?void 0:i.expected,[f,p]=Y(()=>{let e=i==null?void 0:i.valueFieldId;return e&&n.some(t=>t.id===e)?e:r&&n.some(e=>e.id===r)?r:n.length===1?n[0].id:``}),[m,g]=Y(()=>c(i)),[_,v]=Y(()=>String(Array.isArray(d)?d[0]:d??0)),[y,b]=Y(()=>String(Array.isArray(d)?d[1]:0)),x=J(!1),[S,C]=Y(!1),w=Js.find(e=>e.id===m),T=_.trim()!==``&&Number.isFinite(Number(_)),E=!w.isBetween||y.trim()!==``&&Number.isFinite(Number(y)),D=!w.isCount||Number.isInteger(Number(_))&&Number(_)>=1,O=!w.isPercent||Number(_)>=0&&Number(_)<=100,ee=!!(n.some(e=>e.id===f)&&T&&E&&D&&O),te=async e=>{if(!x.current){x.current=!0,C(!0);try{await e()}catch{}finally{x.current=!1,C(!1)}}},k=()=>te(async()=>{if(!ee)return;let e={operator:w.operator,expected:w.isBetween?[Number(_),Number(y)]:Number(_),valueFieldId:f};w.isBottom&&(e.isBottom=!0),await a(e)}),ne=()=>te(o);return/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,"data-target-field-id":e,dir:u,children:[/* @__PURE__ */ W(`div`,{className:`univer-text-sm univer-font-medium`,children:/* @__PURE__ */ W(`bdi`,{dir:`auto`,children:t})}),/* @__PURE__ */ G(`label`,{className:`univer-flex univer-flex-col univer-gap-2 univer-text-sm`,children:[l.t(`sheets-pivot-ui.valueFilter.valueField`),/* @__PURE__ */ W(zn,{"aria-label":l.t(`sheets-pivot-ui.valueFilter.valueField`),"data-testid":`pivot-value-filter-value-field`,value:f,options:[{value:``,label:l.t(`sheets-pivot-ui.valueFilter.selectValueField`)},...n.map(e=>({value:e.id,label:e.label}))],onChange:p})]}),/* @__PURE__ */ G(`label`,{className:`univer-flex univer-flex-col univer-gap-2 univer-text-sm`,children:[l.t(`sheets-pivot-ui.valueFilter.condition`),/* @__PURE__ */ W(zn,{"aria-label":l.t(`sheets-pivot-ui.valueFilter.condition`),"data-testid":`pivot-value-filter-rule`,value:m,options:Js.map(e=>({value:e.id,label:l.t(e.localeKey)})),onChange:e=>g(e)})]}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-gap-2`,children:[/* @__PURE__ */ W(kn,{"aria-label":l.t(`sheets-pivot-ui.valueFilter.condition`),"aria-invalid":!T||!D||!O,className:`univer-min-w-0 univer-flex-1`,"data-testid":`pivot-value-filter-expected`,inputMode:`decimal`,value:_,onChange:v}),w.isBetween&&/* @__PURE__ */ W(kn,{"aria-label":l.t(`sheets-pivot-ui.valueFilter.condition`),"aria-invalid":!E,className:`univer-min-w-0 univer-flex-1`,"data-testid":`pivot-value-filter-expected`,inputMode:`decimal`,value:y,onChange:b})]}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ W(V,{"data-testid":`pivot-value-filter-clear`,disabled:S,onClick:ne,children:l.t(`sheets-pivot-ui.valueFilter.clear`)}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-gap-3`,children:[/* @__PURE__ */ W(V,{disabled:S,onClick:s,children:l.t(`sheets-pivot-ui.valueFilter.cancel`)}),/* @__PURE__ */ W(V,{"data-testid":`pivot-value-filter-confirm`,variant:`primary`,disabled:!ee||S,onClick:k,children:l.t(`sheets-pivot-ui.valueFilter.ok`)})]})]})]})}function Xs(e){let{pivotTableId:t,tableFieldId:n,closeFn:r,unitId:i,subUnitId:a,format:o,tableFieldInfo:s,dataFieldInfo:c,version:l}=e,[u,d]=Y(s.displayName),[f,p]=Y(s.subTotalType),m=z(L),h=z(P),g=z(R),_={...z(M).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`])_[e]=m.t(e);if(q(()=>{d(s.displayName),p(s.subTotalType)},[l]),!s||!c)return;let v=c.name,y=m.getDirection(),b=o??s.format,x=Oa.map(e=>({value:`${e.type}`,type:e.type,label:m.t(e.textKey)})),S=e=>{let t=e;if(Array.isArray(e)&&(t=e[0]),t!==void 0){let e=Number(t);p(e),Ba(v,u,_)&&d(Va(v,_,e))}};return/* @__PURE__ */ G(`div`,{dir:y,children:[/* @__PURE__ */ G(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-self-stretch univer-leading-5`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-sm univer-font-medium univer-leading-5 univer-text-gray-900`,children:m.t(`sheets-pivot-ui.dialog.fieldName`)}),/* @__PURE__ */ W(`span`,{className:`univer-text-xs univer-leading-4 univer-text-gray-600`,children:ha(m.t(`sheets-pivot-ui.dialog.sourceName`),v)})]}),/* @__PURE__ */ W(`div`,{children:/* @__PURE__ */ W(kn,{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:u,onChange:e=>d(e)})}),/* @__PURE__ */ W(`label`,{className:`univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-gray-0`,children:m.t(`sheets-pivot-ui.dialog.summarizeBy`)}),/* @__PURE__ */ W(`div`,{className:U(`univer-h-40 univer-flex-1 univer-overflow-y-auto univer-rounded-lg`,Un,Wn),children:x.map(e=>/* @__PURE__ */ G(`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:()=>S(e.value),children:[/* @__PURE__ */ W(`span`,{className:`univer-w-4 univer-text-base univer-text-primary-600`,children:/* @__PURE__ */ W(tr,{className:U({"univer-hidden":f!==e.type})})}),/* @__PURE__ */ W(`span`,{children:e.label})]},e.type))}),/* @__PURE__ */ W(`footer`,{className:`univer-mt-5`,children:/* @__PURE__ */ G(En,{className:`univer-flex univer-items-center univer-justify-between univer-self-stretch`,children:[/* @__PURE__ */ W(V,{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:Ar,draggable:!0,mask:!1,maskClosable:!1,width:400,children:{label:jr,unitId:i,subUnitId:a,pivotTableId:t,tableFieldId:n,originPattern:b,tableFieldInfo:s,dataFieldInfo:c},dialogStyles:{header:{padding:`20px 24px 0`,height:0},body:{padding:`0 24px 20px`}},closable:!1,onClose:()=>{g.close(Ar)}};g.open(e)},children:m.t(`sheets-pivot-ui.dialog.format`)}),/* @__PURE__ */ G(En,{className:`univer-flex univer-flex-1 univer-gap-2 univer-text-sm rtl:univer-flex-row-reverse`,children:[/* @__PURE__ */ W(V,{onClick:()=>{r&&r()},children:m.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ W(V,{variant:`primary`,disabled:u===``,onClick:()=>{let e=s.displayName,o=s.subTotalType,l=s.format,d=e===u?void 0:u,p=o===f?void 0:f,m=l===b?void 0:b;if(e!==u||o!==f||l!==m){let e={displayName:d,subtotalType:p,format:m,tableFieldId:n,pivotTableId:t,unitId:i,subUnitId:a,tableFieldInfo:s,dataFieldInfo:c};h.executeCommand(Se.id,e)}r&&r()},children:m.t(`sheets-pivot-ui.dialog.ok`)})]})]})})]})}let Zs=class extends N{constructor(e,t){super(),this._componentManager=e,this._iconManager=t,this._registerComponents(),this._registerIcons()}_registerComponents(){[[Rr,qs],[Tr,Vs],[Dr,ts],[kr,Xs],[jr,us],[Nr,Hs],[Pr,Ys],[Fr,Jo],[Ir,is],[Lr,ns]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_registerIcons(){this.disposeWithMe(this._iconManager.register({PivotTableIcon:ur}))}};Zs=Q([Z(0,I(Ft)),Z(1,I(Vt))],Zs);let Qs=class extends N{constructor(e){super(),this._menuManagerService=e,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(Xi)}};Qs=Q([Z(0,Rt)],Qs);let $s=class extends N{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,X(this,`_pivotButtonShapesArr`,[]),this._initButtonRender(),this._initSkeleton(),this._initListener(),this._initBlockedPivotAlert()}_initBlockedPivotAlert(){let e=`SHEET_PIVOT_BLOCKED:${this._context.unitId}`;this.disposeWithMe(yn(this._selectionsService.selectionChanged$,this._context.unit.activeSheet$,this._sheetsPivotTableAdaptorModel.viewUpdate$).pipe(pn(0)).subscribe(()=>{var t,n,r;let{unitId:i,unit:a}=this._context,o=this._selectionsService.currentSelectionParam,s=(t=a.getActiveSheet())==null?void 0:t.getSheetId(),c=(n=this._selectionsService.getCurrentSelections())==null||(n=n.slice(-1)[0])==null?void 0:n.primary;if(!s||!c||(o==null?void 0:o.unitId)!==i||o.sheetId!==s){this._cellAlerts.removeAlert(e);return}let{actualRow:l,actualColumn:u}=c,d=this._sheetsPivotTableAdaptorModel,f=d.getPivotTableIdByCell(i,s,l,u),p=f&&((r=d.getPivotItemRenderInfoCache(i,s,f))==null?void 0:r.blockedRange);if(!p){this._cellAlerts.removeAlert(e);return}let m=`sheets-pivot-ui.perform.blocked`;p.reason===`pivot`?m=`sheets-pivot-ui.perform.blockedByPivot`:p.reason===`merge`&&(m=`sheets-pivot-ui.perform.blockedByMerge`),this._cellAlerts.showAlert({key:e,type:qt.ERROR,title:this._localeService.t(`sheets-pivot-ui.perform.tips`),message:this._localeService.t(m,yr(p)),location:{unitId:i,subUnitId:s,row:l,col:u},width:260,height:96})})),this.disposeWithMe(()=>this._cellAlerts.removeAlert(e))}_initButtonRender(){this.disposeWithMe(yn(this._sheetsPivotTableAdaptorModel.viewUpdate$.pipe(pn(0)),this._sheetSkeletonManagerService.currentSkeleton$,this._sheetsPivotTableConfigModel.pivotConfigChange$,this._permissionService.permissionPointUpdate$.pipe(pn(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(),i=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!i)return;let a=this._pivotButtonShapesArr;a.forEach(e=>e.dispose()),a.splice(0,a.length),this._sheetsPivotTableAdaptorModel.getSubUnitPivotMatrix(e,t).forValue((o,s,c)=>{if(c!=null&&c.pbt){let l=`sheets-pivot-button-${o}-${s}-${e}-${t}`,{startX:u,startY:d,endX:f,endY:p}=on(o,s,n,i),m=f-u,h=p-d;if(h<8||m<8||this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[Et],worksheetTypes:[At,Dt,kt],rangeTypes:[yt,vt]},[{startRow:o,endRow:o,startColumn:s,endColumn:s}],e,t)===!1)return;let g;if(Ao.has(c.pbt)){let{left:n,top:i}=Po(r,`filter`,{startX:u,startY:d,endX:f,endY:p});g={left:n,top:i,height:16,width:16,zIndex:5e3,cellWidth:m,cellHeight:h,pivotParams:{col:s,row:o,unitId:e,subUnitId:t,buttonType:c.pbt}}}else if(jo.has(c.pbt)){let{left:n,top:i}=Po(r,`collapse`,{startX:u,startY:d,endX:f,endY:p});g={left:n,top:i,height:16,width:16,zIndex:5e3,cellWidth:m,cellHeight:h,pivotParams:{col:s,row:o,unitId:e,subUnitId:t,buttonType:c.pbt}}}else return;let _=this._injector.createInstance(Mo,l,g);a.push(_)}}),a.length&&n.addObjects(a),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 Be,{spreadsheet:t}=un(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 n=this._context.scene,{row:r,column:i}=sn(e.offsetX,e.offsetY,n,t);this._commandService.executeCommand(ne.id,{row:r,col:i})}))}};$s=Q([Z(1,I(Ke)),Z(2,I(j)),Z(3,I(tn)),Z(4,I(M)),Z(5,I(P)),Z(6,I(Ct)),Z(7,I(Ge)),Z(8,I(L)),Z(9,I(wt)),Z(10,I(Kt))],$s);var ec=class e extends Yn{constructor(e){super(`SHEET_PIVOT_MOVE_KEY`),X(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 tc=class extends N{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,X(this,`_pivotSelectionMoveShape`,void 0),X(this,`_scenePointerMoveSubscribe`,void 0),X(this,`_scenePointerUpSubscribe`,void 0),X(this,`_selectionControl`,void 0),X(this,`_moveStartRange`,void 0),X(this,`_moveStartCellIndex`,void 0),X(this,`_moveRowOrCol`,`row`),X(this,`_targetRange`,void 0),X(this,`_movePivotId`,void 0),this._initControl()}_controlMoving(e,t){let n=this._context.scene,r=n.getScrollXYInfoByViewport(Zn.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 u;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:d}=i;this._targetRange={startColumn:c,endColumn:c,startRow:e,endRow:t},(u=this._pivotSelectionMoveShape)==null||u.transformByState({left:a,top:l,width:20,height:d-l})}}_controlPointerDownHandler(e){var t,n,r;(t=this._selectionControl)==null||t.setControlExtensionDisable(!1),this._context.scene.setCursor(Kn.DEFAULT);let i=this._sheetsSelectionsService.getCurrentSelections();if(!i.length||i.length>1)return;let a=i[0].range,o=this._context.unit,s=o.getActiveSheet(),c=o.getUnitId(),l=s.getSheetId(),u=this._sheetsPivotTableAdaptorModel.getSubUnitPivotRenderCache(c,l);if(!(u!=null&&u.size))return;let d=Array.from(u).find(([e,t])=>{let{rangesInfo:n}=t;if(!n)return!1;let{rowRanges:r,colRanges:i}=n,o=r[0],s=i[0],c=!1;return o&&(c=Ze.realContain(o,a),this._moveRowOrCol=`row`),!c&&s&&(c=Ze.realContain(s,a),this._moveRowOrCol=`col`),c});if(!d)return;this._movePivotId=d[0],this._pivotSelectionMoveShape||(this._pivotSelectionMoveShape=new ec(this._moveRowOrCol),this._context.scene.addObject(this._pivotSelectionMoveShape));let f=this._context.scene,p=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!p)return;let{offsetX:m,offsetY:h}=e,g=f.getCoordRelativeToViewport(Zn.FromArray([m,h])),{x:_,y:v}=g,y=f.getScrollXYInfoByViewport(g),{scaleX:b,scaleY:x}=f.getAncestorScale(),{row:S,column:C}=p.getCellIndexByOffset(_,v,b,x,y),w=(n=this._selectionControl)==null?void 0:n.model.getRange();if(this._moveStartRange=w,!w)return;let T=0;T=S<w.startRow?w.startRow:S>w.endRow?w.endRow:S;let E=0;E=C<w.startColumn?w.startColumn:C>w.endColumn?w.endColumn:C,this._moveStartCellIndex={row:T,column:E},(r=this._selectionControl)==null||r.setControlExtensionDisable(!0),this._scenePointerMoveSubscribe=f.onPointerMove$.subscribeEvent(e=>{let{offsetX:t,offsetY:n}=e,{x:r,y:i}=f.getCoordRelativeToViewport(Zn.FromArray([t,n]));this._controlMoving(r,i),f.setCursor(Kn.MOVE)}),this._scenePointerUpSubscribe=f.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,f.setCursor(Kn.DEFAULT),f.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(),n=this._context.unit.getActiveSheet().getSheetId();if(this._moveRowOrCol===`row`){var i;let o=(i=this._sheetsPivotTableAdaptorModel.getSubUnitPivotRenderCache(e,n))==null?void 0:i.get(this._movePivotId);if(!o)return;let s=this._sheetsPivotTableAdaptorModel.getSubUnitPivotMatrix(e,n);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.Subtotal&&a!==t.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(_e.id,{unitId:e,subUnitId:n,pivotTableId:this._movePivotId,tableFieldId:l,info:{type:r.custom,customOrder:h}})}else{var o;let i=(o=this._sheetsPivotTableAdaptorModel.getSubUnitPivotRenderCache(e,n))==null?void 0:o.get(this._movePivotId);if(!i)return;let a=this._sheetsPivotTableAdaptorModel.getSubUnitPivotMatrix(e,n);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 n=u==null||(s=u.colHeaderMap)==null?void 0:s[e];if(!n)continue;l=n.tableFieldId;let r=d==null?void 0:d.colRanges,o=r==null?void 0:r[0];if(!o)continue;let f={...o,startRow:e,endRow:e};for(let n=f.startColumn;n<=f.endColumn;n++){let r=a.getValue(e,n);if(!r)continue;let{v:o,pbt:s}=r;if(o&&s!==t.Subtotal&&s!==t.GrandTotal){if(typeof o==`string`){let e=i.projection?Ae(i.projection,n):n;c[e]=o}else if(typeof o==`number`){let e=i.projection?Ae(i.projection,n):n;c[e]=o.toString()}}}break}if(!l)return;let f=i.projection?je(i.projection,this._moveStartRange):this._moveStartRange,p=i.projection?je(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(_e.id,{unitId:e,subUnitId:n,pivotTableId:this._movePivotId,tableFieldId:l,info:{type:r.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()}};tc=Q([Z(1,I(j)),Z(2,I(tn)),Z(3,I(P)),Z(4,Xt),Z(5,I(wt))],tc);let nc=class extends Je{constructor(e=ia,t,n,r,i){super(),this._config=e,this._injector=t,this._commandService=n,this._renderManagerService=r,this._configService=i;let{menu:a,...o}=lt({},ia,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(ra,o),this._initRegisterCommand()}onStarting(){this._injector.add([Zs]),this._injector.get(Zs),[[Qs],[Uo],[Ro],[_s],[Ho],[Bo],[Vo],[ca],[Io]].forEach(e=>this._injector.add(e)),this._injector.get(ca)}onReady(){this._registerRenderModules(),this._injector.get(Qs)}onRendered(){this._injector.get(Ro),this._injector.get(_s),this._injector.get(Ho),this._injector.get(Bo),this._injector.get(Vo),this._injector.get(Io)}onSteady(){this._injector.get(Uo)}_registerRenderModules(){[[$s],[tc]].forEach(e=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(et.UNIVER_SHEET,e))})}_initRegisterCommand(){[na,Vr,$i,ea,Ur,qr,ti,ni,ri,si,li,vi].forEach(e=>this._commandService.registerCommand(e))}};X(nc,`pluginName`,`${se}_UI_PLUGIN`),X(nc,`packageName`,Zi),X(nc,`version`,Qi),X(nc,`type`,et.UNIVER_SHEET),nc=Q([ze(Gn,Xn,Tt,xe,an),Z(1,I(Ke)),Z(2,I(P)),Z(3,qn),Z(4,He)],nc);export{ws as DragDropContext,Es as Draggable,Ts as Droppable,Vr as OpenPivotTableRangeSelectorPanelOperation,ds as PivotFilterOptions,ts as PivotFilterPanel,Xi as SheetsPivotTableUIMenuSchema,Wo as UniverSheetsPivotTableMobileUIPlugin,nc as UniverSheetsPivotTableUIPlugin};
1
+ import{GlobalConfig as e,PivotCellStyleTypeEnum as t,PivotDataFieldDataTypeEnum as n,PivotDataFieldSortOperatorEnum as r,PivotDataFieldTypeEnum as i,PivotDateGroupingMode as a,PivotExcelDateGroupUnit as o,PivotFilterTypeEnum as s,PivotLayoutTypeEnum as c,PivotShowAsBaseItemTypeEnum as l,PivotShowAsTypeEnum as u,PivotSubtotalPositionEnum as d,PivotSubtotalTypeEnum as f,PivotTableFiledAreaEnum as p,PivotTableValuePositionEnum as m,ST_PivotFilterOperatorEnum as h,compilePivotDateFilter as g,generateHexNumber as _,getPivotDateGroupingMode as v,hasPivotMultipleFilters as y,isDateGroupFieldJSON as b,isManualPivotFilter as x,isPivotDateFilter as S,isPivotTableFilterRestrictive as C,isValueFilterOperator as w}from"@univerjs-pro/engine-pivot";import{AddPivotFieldCommand as T,AddPivotTableCommand as E,InitializePivotRuntimeLocalMutation as D,MovePivotFieldCommand as O,PIVOT_DATE_GROUP_TYPES as ee,PIVOT_OPTION_FILTER_COORDINATION as te,PivotDisplayDataType as k,PivotDrillDownCommand as ne,PositionType as A,RemovePivotFieldCommand as re,RemovePivotTableCommand as ie,RemovePivotTableMutation as ae,SHEETS_PIVOT_PLUGIN_CONFIG_KEY as oe,SHEET_PIVOT_TABLE_PLUGIN as se,SetPivotCollapseCommand as ce,SetPivotDateFilterCommand as le,SetPivotDateGroupCommand as ue,SetPivotExcelDateGroupCommand as de,SetPivotFilterCommand as fe,SetPivotLayoutCommand as pe,SetPivotManualGroupsCommand as me,SetPivotNumberGroupCommand as he,SetPivotOptionCommand as ge,SetPivotSortCommand as _e,SetPivotValueFilterCommand as ve,SheetsPivotRPCService as ye,SheetsPivotTableAdaptorModel as j,SheetsPivotTableConfigModel as M,SheetsPivotTableService as be,UniverSheetsPivotTablePlugin as xe,UpdatePivotFieldSettingCommand as Se,UpdatePivotTableSourceRangeCommand as Ce,UpdatePivotValuePositionCommand as we,generateSetRangeValueMutations as Te,getPivotAppliedRanges as Ee,getPivotDateGroupContext as De,isPivotDateGroupTypeDisabled as Oe,isolateTextForBidiContext as ke,mapPivotSheetColumn as Ae,mapPivotSheetRange as je,resolvePivotSheetCell as Me,resolvePivotValueFieldId as Ne,resolvePivotValueFilterTarget as Pe,unionPivotViewRange as Fe}from"@univerjs-pro/sheets-pivot";import{CommandType as Ie,CustomCommandExecutionError as Le,DateSystem as Re,DependentOn as ze,Disposable as N,DisposableCollection as Be,FilterSelectionMode as Ve,ICommandService as P,IConfigService as He,IConfirmService as Ue,ILogService as We,IPermissionService as Ge,IUniverInstanceService as F,Inject as I,Injector as Ke,LocaleService as L,Optional as qe,Plugin as Je,RANGE_TYPE as Ye,RecordValueType as Xe,Rectangle as Ze,ThemeService as Qe,Tools as $e,UniverInstanceType as et,cellToRange as tt,currencySymbols as nt,debounce as rt,excelDateTimePartsToSerial as it,excelSerialToDateTimeParts as at,generateRandomId as ot,isPatternEqualWithoutDecimal as st,isValidRange as ct,merge as lt,numfmt as ut,toDisposable as dt,touchDependencies as ft}from"@univerjs/core";import{AddWorksheetMergeMutation as pt,InsertColCommand as mt,InsertRowCommand as ht,MergeCellController as gt,MoveRangeCommand as _t,RangeProtectionPermissionEditPoint as vt,RangeProtectionPermissionViewPoint as yt,RemoveColCommand as bt,RemoveRowCommand as xt,SheetInterceptorService as St,SheetPermissionCheckController as Ct,SheetsSelectionsService as wt,UniverSheetsPlugin as Tt,WorkbookEditablePermission as Et,WorksheetEditPermission as Dt,WorksheetFilterPermission as Ot,WorksheetPivotTablePermission as kt,WorksheetViewPermission as At,checkRangesEditablePermission as jt,expandToContinuousRange as Mt,getSheetCommandTarget as Nt,isSingleCellSelection as Pt}from"@univerjs/sheets";import{ComponentManager as Ft,ContextMenuGroup as It,ContextMenuPosition as Lt,IDialogService as R,IMenuManagerService as Rt,IMessageService as zt,ISidebarService as Bt,IconManager as Vt,MenuItemType as Ht,RibbonDataGroup as Ut,UniverMobileUIPlugin as Wt,getMenuHiddenObservable as Gt,useDependency as z,useObservable as B}from"@univerjs/ui";import{CellAlertManagerService as Kt,CellAlertType as qt,IFormatPainterService as Jt,ISheetClipboardService as Yt,ISheetSelectionRenderService as Xt,MOBILE_CONTEXT_MENU as Zt,SetCellEditVisibleOperation as Qt,SheetContextMenuMobileRenderController as $t,SheetPrintInterceptorService as en,SheetSkeletonManagerService as tn,SheetsRenderService as nn,UniverSheetsMobileUIPlugin as rn,UniverSheetsUIPlugin as an,getCoordByCell as on,getCoordByOffset as sn,getCurrentRangeDisable$ as cn,getObservableWithExclusiveRange$ as ln,getSheetObject as un}from"@univerjs/sheets-ui";import{EMPTY as dn,Subject as fn,auditTime as pn,concat as mn,debounceTime as hn,defer as gn,filter as _n,map as vn,merge as yn,of as bn,skip as xn,startWith as Sn,switchMap as Cn,takeUntil as wn,tap as Tn}from"rxjs";import{ActionRow as En,Button as V,Checkbox as H,DatePicker as Dn,Dropdown as On,Input as kn,InputNumber as An,MessageType as jn,MobileActionRow as Mn,MobileActionRowGroup as Nn,MobileDropdownMenu as Pn,MobileSelect as Fn,Radio as In,RadioGroup as Ln,Segmented as Rn,Select as zn,SelectList as Bn,TimeInput as Vn,Tooltip as Hn,borderClassName as Un,clsx as U,scrollbarClassName as Wn}from"@univerjs/design";import{UniverLicensePlugin as Gn}from"@univerjs-pro/license";import{CURSOR_TYPE as Kn,IRenderManagerService as qn,Rect as Jn,Shape as Yn,UniverRenderEnginePlugin as Xn,Vector2 as Zn}from"@univerjs/engine-render";import{ArrowLeftIcon as Qn,AscendingIcon as $n,CalendarIcon as er,CheckMarkIcon as tr,ColumnIcon as nr,DescendingIcon as rr,FilterIcon as ir,FunctionIcon as ar,GripVerticalIcon as or,MoreDownIcon as sr,MoreHorizontalIcon as cr,NumberIcon as lr,PivotTableIcon as ur,RowIcon as dr,SearchIcon as fr,TextIcon as pr}from"@univerjs/icons";import{Fragment as mr,jsx as W,jsxs as G}from"react/jsx-runtime";import{createContext as hr,useCallback as K,useContext as gr,useEffect as q,useMemo as _r,useRef as J,useState as Y}from"react";import{deserializeRangeWithSheet as vr,serializeRange as yr,serializeRangeWithSheet as br}from"@univerjs/engine-formula";import{MobileRangeSelector as xr,RangeSelector as Sr}from"@univerjs/sheets-formula-ui";import{drawCanvasIcon as Cr}from"@univerjs/icons-svg";import{InsertTextCommand as wr}from"@univerjs/docs";import{IMEInputCommand as Tr}from"@univerjs/docs-ui";const Er=`UNIVER_SHEET_PIVOT_PANEL`,Dr=`UNIVER_SHEET_PIVOT_PANEL_ID`,Or=`UNIVER_SHEET_PIVOT_FILTER_PANEL`,kr=`UNIVER_SHEET_PIVOT_FILTER_PANEL_ID`,Ar=`UNIVER_SHEET_PIVOT_FIELD_SETTING`,jr=`UNIVER_SHEET_PIVOT_FIELD_SETTING_ID`,Mr=`UNIVER_SHEET_PIVOT_FIELD_NUMFMT`,Nr=`UNIVER_SHEET_PIVOT_FIELD_NUMFMT_ID`,Pr=`UNIVER_SHEET_PIVOT_SHOW_DATA_AS_DIALOG`,Fr=`UNIVER_SHEET_PIVOT_VALUE_FILTER_DIALOG`,Ir=`UNIVER_SHEET_PIVOT_EXCEL_DATE_GROUP_DIALOG`,Lr=`UNIVER_SHEET_PIVOT_NUMBER_GROUP_DIALOG`,Rr=`UNIVER_SHEET_PIVOT_MANUAL_GROUP_DIALOG`,zr=`univer.sheet.pivot-table-range-selector`,Br=`UNIVER_SHEET_PIVOT_MOBILE_ACTION_PANEL`,Vr=`UNIVER_SHEET_PIVOT_MOBILE_ACTION_PANEL_ID`,Hr={type:Ie.OPERATION,id:`sheet.operation.open-pivot-table-range-selector-panel`,async handler(e){let t=e.get(F),n=e.get(P),r=Nt(t),i=e.get(L);if(!r)return!1;let{unitId:a,subUnitId:o,worksheet:s,workbook:c}=r,l=e.get(wt).getCurrentLastSelection(),u=(l==null?void 0:l.range)??{startRow:0,endRow:0,startColumn:0,endColumn:0,rangeType:Ye.NORMAL},d=await Ur(e,a,o,Pt(l)?Mt(u,{up:!0,left:!0,right:!0,down:!0},s):u,s.getName());if(!d)return!1;let f=c.getSheets().find(e=>e.getName()===d.sourceSheetName);if(!f)return!1;let p;if(d.positionType===A.New)p={row:0,col:0,unitId:a,subUnitId:ot(),sheetName:c.generateNewSheetName(`${i.t(`sheets-pivot-ui.sheet`)}`)};else{if(!d.positionRange||!d.positionSheetName)return!1;let e=c.getSheets().find(e=>e.getName()===d.positionSheetName);if(!e)return!1;p={row:d.positionRange.startRow,col:d.positionRange.startColumn,unitId:a,subUnitId:e.getSheetId(),sheetName:e.getName()}}let m=_(8);return await n.executeCommand(E.id,{pivotTableId:m,pivotTableConfig:{targetCellInfo:p,sourceRangeInfo:{range:d.sourceRange,unitId:a,sheetName:d.sourceSheetName,subUnitId:f.getSheetId()}},positionType:d.positionType})?{unitId:p.unitId,subUnitId:p.subUnitId,pivotTableId:m}:!1}};async function Ur(e,t,n,r,i){let a=e.get(R),o=e.get(L);return new Promise(e=>{let s,c={unitId:t,subUnitId:n,sourceRange:r,positionRange:null,sourceSheetName:i,positionSheetName:i,onConfirm:t=>{e(t),s==null||s.dispose()},onCancel:()=>{e(null),s==null||s.dispose()}};s=a.open({id:zr,title:{title:o.t(`sheets-pivot-ui.dialog.source.insertPivotTable`)},draggable:!0,mask:!1,maskClosable:!1,children:{label:{name:zr,props:c}},width:400,onClose:()=>{s.dispose()}})})}const Wr={type:Ie.OPERATION,id:`sheet.operation.set-pivot-date-group`,async handler(e,t){if(!t)return!1;let n=Gr(e);return n?e.get(P).executeCommand(ue.id,{unitId:n.unitId,subUnitId:n.subUnitId,pivotTableId:n.pivotTableId,tableFieldId:n.tableFieldId,dateType:t.dateType}):!1}};function Gr(e,t=a.Legacy){let n=e.get(F),r=Nt(n);if(!r)return;let i=e.get(wt).getCurrentLastSelection(),o=i==null?void 0:i.primary;if(!o)return;let{unitId:s,subUnitId:c}=r,l=o.startRow,u=o.startColumn,d=e.get(j).getPivotTableIdByCell(s,c,l,u);if(!d)return;let f=Kr(e,s,c,d,l,u);if(!f)return;let p=e.get(M),m=p.getPivotTableConfig(s,c,d);if(v(m==null?void 0:m.fieldsConfig.options)!==t)return;let h=p.getCollection(s,d),g=De(m==null?void 0:m.fieldsConfig,h,f);if(g)return{unitId:s,subUnitId:c,pivotTableId:d,tableFieldId:f,row:l,col:u,dateGroupContext:g}}function Kr(e,t,n,r,i,a){let o=e.get(j).getPivotItemRenderInfoCache(t,n,r);if(!o)return;let s=e.get(j).getPivotTableCellData(t,n,i,a),c=Me(i,a,s,o);return c==null?void 0:c.tableFieldId}function qr(e){let t=Gr(e,a.ExcelLike);if(!t)return;let n=e.get(M),r=n.getPivotTableConfig(t.unitId,t.subUnitId,t.pivotTableId),i=r==null?void 0:r.fieldsConfig.dimension[t.tableFieldId];if(!i)return;let o=n.getCollection(t.unitId,t.pivotTableId),s=(t.dateGroupContext.area===p.Row?r.fieldsConfig.rowFields:r.fieldsConfig.columnFields).flatMap(e=>{let n=r.fieldsConfig.dimension[e],i=n?o==null?void 0:o.fields[n.dataFieldId]:void 0;return i&&b(i)&&i.originalFieldId===t.dateGroupContext.originalDataFieldId&&i.excelLike?[i.excelLike]:[]}),c=s[0],l=c?{units:s.map(e=>e.unit),autoStart:c.autoStart,autoEnd:c.autoEnd,...c.start===void 0?{}:{start:c.start},...c.end===void 0?{}:{end:c.end},...c.daysInterval===void 0?{}:{daysInterval:c.daysInterval}}:void 0;return{...t,targetFieldName:i.displayName,grouping:l}}const Jr={id:`sheet.operation.set-pivot-excel-date-group`,type:Ie.OPERATION,async handler(e){let t=qr(e);if(!t)return!1;let n=e.get(M),r=n.getPivotTableConfig(t.unitId,t.subUnitId,t.pivotTableId),i=n.getCollection(t.unitId,t.pivotTableId),a=e.get(R),o=e.get(L),s=e.get(F).getUnit(t.unitId),c=(s==null?void 0:s.getDateSystem())??Re.Date1900,l=null,u=!1,d=!1,f=()=>{u||(u=!0,l==null||l.dispose(),l=null)},p=async a=>{if(!(d||u)){d=!0;try{let o=qr(e);if(!o||o.unitId!==t.unitId||o.subUnitId!==t.subUnitId||o.pivotTableId!==t.pivotTableId||o.tableFieldId!==t.tableFieldId||n.getPivotTableConfig(t.unitId,t.subUnitId,t.pivotTableId)!==r||n.getCollection(t.unitId,t.pivotTableId)!==i)return;await e.get(P).executeCommand(de.id,{unitId:t.unitId,subUnitId:t.subUnitId,pivotTableId:t.pivotTableId,tableFieldId:t.tableFieldId,grouping:{...a,units:a.units.concat()}})}catch{}finally{f()}}};try{l=a.open({id:`UNIVER_SHEET_PIVOT_EXCEL_DATE_GROUP_DIALOG_ID`,title:{title:o.t(`sheets-pivot-ui.dateGroup.excelLikeTitle`)},draggable:!0,mask:!0,maskClosable:!1,width:440,children:{label:{name:Ir,props:{targetFieldName:t.targetFieldName,dateSystem:c,grouping:t.grouping,onConfirm:p,onCancel:f}}},onClose:f})}catch{return f(),!1}return!0}};function Yr(e){return e.map(e=>({...e,members:e.members.map(e=>({...e}))}))}function Xr(t){let n;try{n=JSON.parse(t)}catch{return}if(!(!Array.isArray(n)||n.length<1||typeof n[0]!=`string`))return n[0]===Xe.Blank?e.BLANK_PLACEHOLDER:String(n[1])}function Zr(t,n){var r;let a=()=>({error:`invalidSelection`}),o=Nt(t.get(F)),s=t.get(wt).getCurrentSelections();if(!o||!s.length)return a();let{unitId:c,subUnitId:l}=o,u=s[0].primary;if(!u)return a();let d=t.get(j),f=d.getPivotTableIdByCell(c,l,u.startRow,u.startColumn),p=t.get(M),m=f&&p.getPivotTableConfig(c,l,f),h=f&&p.getCollection(c,f),g=f&&d.getPivotItemRenderInfoCache(c,l,f);if(!f||!m||!h||!g)return a();let _=Me(u.startRow,u.startColumn,d.getPivotTableCellData(c,l,u.startRow,u.startColumn),g),v=_==null?void 0:_.tableFieldId,y=v&&m.fieldsConfig.dimension[v];if(!v||!y||!(m.fieldsConfig.rowFields.includes(v)||m.fieldsConfig.columnFields.includes(v)))return a();let b=h.fields[y.dataFieldId];if(!b)return a();let x=b.dataFieldType===i.textGroupField?b:void 0;if(!x&&b.dataFieldType!==i.defaultNormalField)return a();let S=(x==null?void 0:x.originalFieldId)??b.id;if(((r=h.fields[S])==null?void 0:r.dataFieldType)!==i.defaultNormalField)return a();let C=Yr((x==null?void 0:x.grouping.groups)??[]),w=/* @__PURE__ */ new Map,T=/* @__PURE__ */ new Set,E=0;for(let t of s){let{startRow:n,endRow:r,startColumn:i,endColumn:o}=t.range;if(E+=(r-n+1)*(o-i+1),E>512)return a();for(let t=n;t<=r;t++)for(let n=i;n<=o;n++){if(d.getPivotTableIdByCell(c,l,t,n)!==f)return a();let r=Me(t,n,d.getPivotTableCellData(c,l,t,n),g),i=r==null?void 0:r.info;if(!r||r.area!==`rowRanges`&&r.area!==`colRanges`||r.tableFieldId!==v||!i||i.isValue||i.isSubtotal||i.isBottomTotal||i.isTopTotal||i.rowType&&i.rowType!==`item`||i.level<1)return a();let o=i.paths[i.level-1];if(o===void 0)return a();if(x){let e;try{e=JSON.parse(o)}catch{return a()}if(!Array.isArray(e)||e.length!==2||typeof e[1]!=`string`)return a();if(e[0]===`group`){if(!C.some(t=>t.id===e[1]))return a();T.add(e[1]);continue}if(e[0]!==`member`)return a();let t=Xr(e[1]);if(t===void 0)return a();w.set(e[1],{path:t,memberKey:e[1]})}else{var D;let r=(D=d.getPivotTableCellData(c,l,t,n))==null?void 0:D.v,i=r==null||r===``?e.BLANK_PLACEHOLDER:String(r);w.set(o,{path:i,tupleKey:o})}}}return n===`group`&&(w.size<2||T.size>0)||n!==`group`&&(w.size>0||T.size!==1)?a():{context:{unitId:c,subUnitId:l,pivotTableId:f,tableFieldId:v,sourceFieldId:S,targetFieldName:y.displayName,groups:C,memberPaths:Array.from(w.values()),selectedGroupId:Array.from(T)[0]}}}function Qr(e,t){return Zr(e,t).context}function $r(e,t){e.get(zt).show({type:jn.Error,content:e.get(L).t(`sheets-pivot-ui.manualGroup.${t}`)})}function ei(e,t,n){let r=Qr(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 ti(e,t){let n=Zr(e,t),r=n.context;if(!r)return $r(e,n.error),!1;let i=e.get(M),a=i.getPivotTableConfig(r.unitId,r.subUnitId,r.pivotTableId),o=i.getCollection(r.unitId,r.pivotTableId),s=[];if(t===`group`){try{let t=(await e.get(ye).getPivotDisplayConfig({unitId:r.unitId,subUnitId:r.subUnitId,pivotTableId:r.pivotTableId,params:{type:k.ManualGroupMembers,manualGroupMembers:{sourceFieldId:r.sourceFieldId,paths:r.memberPaths}}})).result.manualGroupMembers;if(!t||t.error||t.members.length<2)return $r(e,(t==null?void 0:t.error)??`invalidSelection`),!1;s=t.members}catch{return $r(e,`invalidSelection`),!1}if(!ei(e,t,r)||i.getPivotTableConfig(r.unitId,r.subUnitId,r.pivotTableId)!==a||i.getCollection(r.unitId,r.pivotTableId)!==o)return!1}let c=e.get(R),l=e.get(L),u=r.groups.find(e=>e.id===r.selectedGroupId),d=(u==null?void 0:u.name)??l.t(`sheets-pivot-ui.manualGroup.defaultName`,String(r.groups.length+1));if(!u){let e=r.groups.length+1;for(;r.groups.some(e=>e.name===d);)e++,d=l.t(`sheets-pivot-ui.manualGroup.defaultName`,String(e))}let f=null,p=!1,m=!1,h=()=>{p||(p=!0,f==null||f.dispose(),f=null)},g=async n=>{if(m||p)return;let c=n.trim();if(!c||r.groups.some(e=>e.name===c&&e.id!==r.selectedGroupId))$r(e,`invalidSelection`);else{m=!0;try{if(!ei(e,t,r)||i.getPivotTableConfig(r.unitId,r.subUnitId,r.pivotTableId)!==a||i.getCollection(r.unitId,r.pivotTableId)!==o)return;let n=t===`group`?r.groups.concat({id:ot(),name:c,members:s.map(e=>({...e}))}):r.groups.map(e=>e.id===r.selectedGroupId?{...e,name:c}:e);await e.get(P).executeCommand(me.id,{unitId:r.unitId,subUnitId:r.subUnitId,pivotTableId:r.pivotTableId,sourceFieldId:r.sourceFieldId,groups:n})}catch{}finally{h()}}};try{f=c.open({id:`UNIVER_SHEET_PIVOT_MANUAL_GROUP_DIALOG_ID`,title:{title:l.t(t===`group`?`sheets-pivot-ui.manualGroup.groupTitle`:`sheets-pivot-ui.manualGroup.renameTitle`)},draggable:!0,mask:!0,maskClosable:!1,width:400,children:{label:{name:Rr,props:{name:d,onConfirm:g,onCancel:h}}},onClose:h})}catch{return h(),!1}return!0}const ni={id:`sheet.operation.set-pivot-manual-group`,type:Ie.OPERATION,handler:e=>ti(e,`group`)},ri={id:`sheet.operation.rename-pivot-manual-group`,type:Ie.OPERATION,handler:e=>ti(e,`rename`)},ii={id:`sheet.operation.ungroup-pivot-manual-group`,type:Ie.OPERATION,async handler(e){let t=Zr(e,`ungroup`),n=t.context;if(!n)return $r(e,t.error),!1;let r=e.get(M),i=r.getPivotTableConfig(n.unitId,n.subUnitId,n.pivotTableId),a=r.getCollection(n.unitId,n.pivotTableId);return!ei(e,`ungroup`,n)||r.getPivotTableConfig(n.unitId,n.subUnitId,n.pivotTableId)!==i||r.getCollection(n.unitId,n.pivotTableId)!==a?!1:e.get(P).executeCommand(me.id,{unitId:n.unitId,subUnitId:n.subUnitId,pivotTableId:n.pivotTableId,sourceFieldId:n.sourceFieldId,groups:n.groups.filter(e=>e.id!==n.selectedGroupId)})}};function ai(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 oi(e,t){if(e.dataFieldType===i.numberGroupField){let r=e,a=t.fields[r.originalFieldId];return!a||a.dataFieldType!==i.defaultNormalField||a.fieldDataType!==n.number?void 0:{sourceFieldId:r.originalFieldId,grouping:{...r.grouping}}}if(e.dataFieldType===i.defaultNormalField&&e.fieldDataType===n.number)return{sourceFieldId:e.id}}function si(e){var t;let n=Nt(e.get(F)),r=(t=e.get(wt).getCurrentLastSelection())==null?void 0:t.primary;if(!n||!r)return;let{unitId:i,subUnitId:a}=n,o=r.startRow,s=r.startColumn,c=e.get(j),l=c.getPivotTableIdByCell(i,a,o,s);if(!l)return;let u=c.getPivotItemRenderInfoCache(i,a,l);if(!u)return;let d=Me(o,s,c.getPivotTableCellData(i,a,o,s),u),f=d==null?void 0:d.tableFieldId;if(!f||d.area!==`rowRanges`&&d.area!==`colRanges`)return;let p=e.get(M),m=p.getPivotTableConfig(i,a,l),h=p.getCollection(i,l),g=m==null?void 0:m.fieldsConfig.dimension[f];if(!g||!h||!(m.fieldsConfig.rowFields.includes(f)||m.fieldsConfig.columnFields.includes(f)))return;let _=h.fields[g.dataFieldId];if(!_)return;let v=oi(_,h);if(v)return{unitId:i,subUnitId:a,pivotTableId:l,tableFieldId:f,targetFieldName:g.displayName,...v}}const ci={id:`sheet.operation.set-pivot-number-group`,type:Ie.OPERATION,async handler(e){let t=si(e);if(!t)return!1;let n=e.get(M),r=n.getCollection(t.unitId,t.pivotTableId),i=n.getPivotTableConfig(t.unitId,t.subUnitId,t.pivotTableId),a=e.get(F),o=()=>{let n=si(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)},s=e.get(R),c=e.get(L),l=null,u=!1,d=!1,f=new fn,p=async()=>{if(!u&&o())try{let n=(await e.get(ye).getPivotDisplayConfig({unitId:t.unitId,subUnitId:t.subUnitId,pivotTableId:t.pivotTableId,params:{type:k.NumberGroupDefaults,numberGroupDefaults:{tableFieldId:t.tableFieldId}}})).result.numberGroupDefaults;return!u&&o()&&n&&ai(n)?n:void 0}catch{return}},m=()=>{u||(u=!0,f.next(),f.complete(),l==null||l.dispose(),l=null)},h=await p();if(!h)return m(),!1;let g=a.unitDisposed$.pipe(_n(e=>e.getUnitId()===t.unitId),Tn(m)),_=gn(()=>{if(u||!a.getUnit(t.unitId))return m(),dn;let e=n.watchPivotTableChanges(t.unitId,t.subUnitId,t.pivotTableId).pipe(hn(0),vn(()=>void 0));return yn(bn(h),e).pipe(Cn(e=>e&&n.getCollection(t.unitId,t.pivotTableId)===r&&n.getPivotTableConfig(t.unitId,t.subUnitId,t.pivotTableId)===i?bn(e):mn(bn(void 0),p())),wn(yn(f,g)))}),v=async n=>{if(!(d||u)){d=!0;try{if(!ai(n)||!o())return;await e.get(P).executeCommand(he.id,{unitId:t.unitId,subUnitId:t.subUnitId,pivotTableId:t.pivotTableId,tableFieldId:t.tableFieldId,grouping:{...n}})}catch{}finally{m()}}};try{l=s.open({id:`UNIVER_SHEET_PIVOT_NUMBER_GROUP_DIALOG_ID`,title:{title:c.t(`sheets-pivot-ui.numberGroup.title`)},draggable:!0,mask:!0,maskClosable:!1,width:400,children:{label:{name:Lr,props:{targetFieldName:t.targetFieldName,grouping:t.grouping,defaults$:_,onConfirm:v,onCancel:m}}},onClose:m})}catch{return m(),!1}return!0}},li=[{type:u.normal,localeKey:`sheets-pivot-ui.showValuesAs.normal`,requiresParameters:!1,baseItemMode:`none`},{type:u.percentOfGrandTotal,localeKey:`sheets-pivot-ui.showValuesAs.percentOfGrandTotal`,requiresParameters:!1,baseItemMode:`none`},{type:u.percentOfRowTotal,localeKey:`sheets-pivot-ui.showValuesAs.percentOfRowTotal`,requiresParameters:!1,baseItemMode:`none`},{type:u.percentOfColumnTotal,localeKey:`sheets-pivot-ui.showValuesAs.percentOfColumnTotal`,requiresParameters:!1,baseItemMode:`none`},{type:u.percentOfParentRowTotal,localeKey:`sheets-pivot-ui.showValuesAs.percentOfParentRowTotal`,requiresParameters:!1,baseItemMode:`none`},{type:u.percentOfParentColumnTotal,localeKey:`sheets-pivot-ui.showValuesAs.percentOfParentColumnTotal`,requiresParameters:!1,baseItemMode:`none`},{type:u.index,localeKey:`sheets-pivot-ui.showValuesAs.index`,requiresParameters:!1,baseItemMode:`none`},{type:u.percentOfParent,localeKey:`sheets-pivot-ui.showValuesAs.percentOfParent`,requiresParameters:!0,baseItemMode:`none`,parentFieldOnly:!0},{type:u.percentOf,localeKey:`sheets-pivot-ui.showValuesAs.percentOf`,requiresParameters:!0,baseItemMode:`item`},{type:u.differenceFrom,localeKey:`sheets-pivot-ui.showValuesAs.differenceFrom`,requiresParameters:!0,baseItemMode:`item-or-relative`},{type:u.percentDifferenceFrom,localeKey:`sheets-pivot-ui.showValuesAs.percentDifferenceFrom`,requiresParameters:!0,baseItemMode:`item-or-relative`},{type:u.runningTotal,localeKey:`sheets-pivot-ui.showValuesAs.runningTotal`,requiresParameters:!0,baseItemMode:`none`},{type:u.percentRunningTotal,localeKey:`sheets-pivot-ui.showValuesAs.percentRunningTotal`,requiresParameters:!0,baseItemMode:`none`},{type:u.rankAscending,localeKey:`sheets-pivot-ui.showValuesAs.rankAscending`,requiresParameters:!0,baseItemMode:`none`},{type:u.rankDescending,localeKey:`sheets-pivot-ui.showValuesAs.rankDescending`,requiresParameters:!0,baseItemMode:`none`}],ui={type:Ie.OPERATION,id:`sheet.operation.set-pivot-show-data-as`,async handler(e,t){let n=t&&li.find(e=>e.type===t.type);if(!n)return!1;let r=fi(e);if(!r)return!1;if(!n.requiresParameters)return e.get(P).executeCommand(Se.id,{unitId:r.unitId,subUnitId:r.subUnitId,pivotTableId:r.pivotTableId,tableFieldId:r.tableFieldId,showDataAs:{type:n.type,baseFieldId:``,baseItem:``},tableFieldInfo:r.tableFieldInfo,dataFieldInfo:r.dataFieldInfo});let i=pi(e,r);if(!i)return!1;let a=di(i.config,i.collection,n);if(a.length===0)return!1;let o={};if(n.baseItemMode!==`none`){try{o=await mi(e,i.config,r.pivotTableId,a)}catch{return!1}if(!a.some(e=>o[e]&&(n.baseItemMode===`item-or-relative`||o[e].items.length>0)))return!1}let s=e.get(R),c=e.get(L),l=null,u=!1,d=!1,f=()=>{u||(u=!0,l==null||l.dispose(),l=null)};try{l=s.open({id:`UNIVER_SHEET_PIVOT_SHOW_DATA_AS_DIALOG_ID`,title:{title:c.t(`sheets-pivot-ui.showValuesAs.dialogTitle`)},draggable:!0,mask:!0,maskClosable:!1,width:400,children:{label:{name:Pr,props:{unitId:r.unitId,subUnitId:r.subUnitId,pivotTableId:r.pivotTableId,tableFieldId:r.tableFieldId,type:n.type,baseItems:o,onCancel:f,onConfirm:async t=>{if(!d){d=!0;try{let a=pi(e,r);if(!a||!hi(a.config,a.collection,n,t))return;if(n.baseItemMode!==`none`&&t.baseItemType===void 0){var i;if(!((i=(await mi(e,a.config,a.context.pivotTableId,[t.baseFieldId]))[t.baseFieldId])!=null&&i.items.includes(t.baseItem)))return}await e.get(P).executeCommand(Se.id,{unitId:a.context.unitId,subUnitId:a.context.subUnitId,pivotTableId:a.context.pivotTableId,tableFieldId:a.context.tableFieldId,showDataAs:t,tableFieldInfo:a.context.tableFieldInfo,dataFieldInfo:a.context.dataFieldInfo})}catch{}finally{f()}}}}}},onClose:f})}catch{return f(),!1}return!0}};function di(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 fi(e){var t,n;let r=Nt(e.get(F)),i=(t=e.get(wt).getCurrentLastSelection())==null?void 0:t.primary;if(!r||!i)return;let{unitId:a,subUnitId:o}=r,s=i.startRow,c=i.startColumn,l=e.get(j),u=l.getPivotTableIdByCell(a,o,s,c);if(!u)return;let d=e.get(M).getPivotTableConfig(a,o,u),f=l.getPivotItemRenderInfoCache(a,o,u),p=l.getPivotTableCellData(a,o,s,c);if(!d||!f)return;let m=Me(s,c,p,f);if(!m)return;let h=Ne(m,d.fieldsConfig.valueFields);if(h)return(n=pi(e,{unitId:a,subUnitId:o,pivotTableId:u,tableFieldId:h}))==null?void 0:n.context}function pi(e,t){let{unitId:n,subUnitId:r,pivotTableId:i,tableFieldId:a}=t,o=e.get(M),s=o.getPivotTableConfig(n,r,i),c=o.getCollection(n,i),l=s==null?void 0:s.fieldsConfig.measure[a];if(!s||!c||!l||!s.fieldsConfig.valueFields.includes(l.id))return;let u=c.fields[l.dataFieldId]??c.customFields.find(e=>e.id===l.dataFieldId);if(!u)return;let d={...l.showDataAs};return{config:s,collection:c,context:{unitId:n,subUnitId:r,pivotTableId:i,tableFieldId:l.id,currentShowDataAs:d,tableFieldInfo:{tableFieldId:l.id,displayName:l.displayName,dataFieldId:l.dataFieldId,format:l.format,subTotalType:l.subtotal,showDataAs:{...d}},dataFieldInfo:{id:u.id,dataFieldId:u.id,name:u.name,type:u.fieldDataType,checked:!0,pivotTableId:i}}}}async function mi(e,t,n,r){let{unitId:i,subUnitId:a}=t.targetCellInfo,o=t.targetCellInfo,s=e.get(j).getPivotItemRenderInfoCache(i,a,n);if(!s)throw Error(`[sheets-pivot-ui]: Pivot render cache is unavailable`);return(await Promise.all(r.map(async t=>{try{return[t,(await e.get(ye).getPivotDisplayConfig({unitId:i,subUnitId:a,pivotTableId:n,params:{type:k.Filter,filter:{row:o.row,col:o.col,tableFieldId:t,pivotItemRenderInfoCache:s}}})).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 hi(e,t,n,r){return r.type!==n.type||!di(e,t,n).includes(r.baseFieldId)?!1:n.baseItemMode===`none`?r.baseItem===``&&r.baseItemType===void 0:r.baseItemType===void 0?r.baseItem!==``:n.baseItemMode===`item-or-relative`&&r.baseItem===``&&(r.baseItemType===l.previous||r.baseItemType===l.next)}function gi(e){return{...e,expected:Array.isArray(e.expected)?e.expected.concat():e.expected}}function _i(e,t){let n=e.get(M).getPivotTableConfig(t.unitId,t.subUnitId,t.pivotTableId);if(n&&n.fieldsConfig.dimension[t.targetFieldId]&&(n.fieldsConfig.rowFields.includes(t.targetFieldId)||n.fieldsConfig.columnFields.includes(t.targetFieldId)))return n}function vi(e){var t,n;let r=Nt(e.get(F)),i=(t=e.get(wt).getCurrentLastSelection())==null?void 0:t.primary;if(!r||!i)return;let{unitId:a,subUnitId:o}=r,s=i.startRow,c=i.startColumn,l=e.get(j),u=l.getPivotTableIdByCell(a,o,s,c);if(!u)return;let d=e.get(M).getPivotTableConfig(a,o,u),f=l.getPivotItemRenderInfoCache(a,o,u);if(!d||!f)return;let p=Me(s,c,l.getPivotTableCellData(a,o,s,c),f),m=p&&Pe(p,d.fieldsConfig);if(!m)return;let h=d.fieldsConfig.dimension[m.targetFieldId],g=d.fieldsConfig.valueFields.flatMap(e=>{let t=d.fieldsConfig.measure[e];return t?[{id:t.id,label:t.displayName}]:[]});if(!h||g.length===0)return;let _=(n=d.fieldsConfig.valueFilter)==null||(n=n.find(e=>e.fieldId===m.targetFieldId))==null?void 0:n.filterInfo;return{unitId:a,subUnitId:o,pivotTableId:u,targetFieldId:m.targetFieldId,targetFieldName:h.displayName,valueFields:g,defaultValueFieldId:m.defaultValueFieldId,..._?{currentFilter:gi(_)}:{}}}const yi={type:Ie.OPERATION,id:`sheet.operation.set-pivot-value-filter`,async handler(e){let t=vi(e);if(!t)return!1;let n=e.get(R),r=e.get(L),i=null,a=!1,o=!1,c=()=>{a||(a=!0,i==null||i.dispose(),i=null)},l=async n=>{if(!o){o=!0;try{let r=_i(e,t);if(!r||n&&(!r.fieldsConfig.measure[n.valueFieldId]||!r.fieldsConfig.valueFields.includes(n.valueFieldId)||!w(n.operator)))return;await e.get(P).executeCommand(ve.id,{unitId:t.unitId,subUnitId:t.subUnitId,pivotTableId:t.pivotTableId,fieldId:t.targetFieldId,valueFilterInfo:n?{...n,type:s.ValueFilter,expected:Array.isArray(n.expected)?n.expected.concat():n.expected}:void 0})}catch{}finally{c()}}};try{i=n.open({id:`UNIVER_SHEET_PIVOT_VALUE_FILTER_DIALOG_ID`,title:{title:r.t(`sheets-pivot-ui.valueFilter.dialogTitle`)},draggable:!0,mask:!0,maskClosable:!1,width:420,children:{label:{name:Fr,props:{targetFieldId:t.targetFieldId,targetFieldName:t.targetFieldName,valueFields:t.valueFields,defaultValueFieldId:t.defaultValueFieldId,currentFilter:t.currentFilter,onConfirm:e=>l(e),onClear:()=>l(void 0),onCancel:c}}},onClose:c})}catch{return c(),!1}return!0}},bi=`sheet.pivot.context-menu.date-group`,xi=`sheet.pivot.context-menu.excel-date-group`,Si=`sheet.pivot.context-menu.number-group`,Ci=`sheet.pivot.context-menu.manual-group`,wi=`sheet.pivot.context-menu.manual-rename`,Ti=`sheet.pivot.context-menu.manual-ungroup`,Ei=`sheet.pivot.context-menu.show-data-as`,Di=`sheet.pivot.context-menu.value-filter`,Oi={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 ki(e){return{id:Hr.id,type:Ht.BUTTON,icon:`PivotTableIcon`,hidden$:Gt(e,et.UNIVER_SHEET),disabled$:ln(e,cn(e,{workbookTypes:[Et],worksheetTypes:[At,kt],rangeTypes:[yt]})),tooltip:`sheets-pivot-ui.title`,title:`sheets-pivot-ui.title`}}function Ai(e){return{id:bi,type:Ht.SUBITEMS,title:`sheets-pivot-ui.dateGroup.title`,hidden$:Ri(e)}}function ji(e){return{id:xi,commandId:Jr.id,type:Ht.BUTTON,title:`sheets-pivot-ui.dateGroup.excelLikeTitle`,hidden$:Vi(e).pipe(vn(()=>!qr(e)))}}function Mi(e){return{id:Si,commandId:ci.id,type:Ht.BUTTON,title:`sheets-pivot-ui.numberGroup.title`,hidden$:Vi(e).pipe(vn(()=>!si(e)))}}function Ni(e){return{id:Ci,commandId:ni.id,type:Ht.BUTTON,title:`sheets-pivot-ui.manualGroup.groupTitle`,hidden$:Vi(e).pipe(vn(()=>!Qr(e,`group`)))}}function Pi(e){return{id:wi,commandId:ri.id,type:Ht.BUTTON,title:`sheets-pivot-ui.manualGroup.renameTitle`,hidden$:Vi(e).pipe(vn(()=>!Qr(e,`rename`)))}}function Fi(e){return{id:Ti,commandId:ii.id,type:Ht.BUTTON,title:`sheets-pivot-ui.manualGroup.ungroupTitle`,hidden$:Vi(e).pipe(vn(()=>!Qr(e,`ungroup`)))}}function Ii(e){return t=>({id:Li(e),commandId:Wr.id,type:Ht.BUTTON,title:Oi[e],params:{dateType:e},disabled$:zi(t,e),activated$:Bi(t,e)})}function Li(e){return`sheet.pivot.context-menu.date-group.${e}`}function Ri(e){return Vi(e).pipe(vn(()=>!Gr(e)))}function zi(e,t){return Vi(e).pipe(vn(()=>{let n=Gr(e);return!n||Oe(n.dateGroupContext,t)}))}function Bi(e,t){return Vi(e).pipe(vn(()=>{let n=Gr(e);return(n==null?void 0:n.dateGroupContext.currentDateType)===t}))}function Vi(e){let t=e.get(M),n=()=>{var t;let n=Nt(e.get(F)),r=(t=e.get(wt).getCurrentLastSelection())==null?void 0:t.primary;if(!n||!r)return;let{unitId:i,subUnitId:a}=n,o=e.get(j).getPivotTableIdByCell(i,a,r.startRow,r.startColumn);return o?{unitId:i,subUnitId:a,pivotTableId:o}:void 0};return yn(e.get(wt).selectionMoveEnd$,t.pivotConfigChange$.pipe(_n(e=>{let t=n();return(t==null?void 0:t.unitId)===e.unitId&&t.subUnitId===e.subUnitId&&t.pivotTableId===e.pivotTableId})),t.collectionChange$.pipe(_n(e=>{let r=n();if(!r||!e.pivotTableIds.includes(r.pivotTableId))return!1;let i=t.getPivotTableConfig(r.unitId,r.subUnitId,r.pivotTableId);return e.unitId===((i==null?void 0:i.sourceRangeInfo.unitId)??r.unitId)}))).pipe(Sn(null))}const Hi=ee.map(e=>({dateType:e,id:Li(e),menuItemFactory:Ii(e)}));function Ui(e){return{id:Ei,type:Ht.SUBITEMS,title:`sheets-pivot-ui.showValuesAs.title`,hidden$:Ki(e).pipe(vn(()=>!fi(e)))}}function Wi(e){return t=>({id:Gi(e.type),commandId:ui.id,type:Ht.BUTTON,title:e.localeKey,params:{type:e.type},activated$:Ki(t).pipe(vn(()=>{let n=fi(t);return!!(n&&(n.currentShowDataAs.type??u.normal)===e.type)}))})}function Gi(e){return`sheet.pivot.context-menu.show-data-as.${e}`}function Ki(e){return e.get(wt).selectionMoveEnd$.pipe(Sn(null))}const qi=li.map(e=>({rule:e,id:Gi(e.type),menuItemFactory:Wi(e)}));function Ji(e){return{id:Di,commandId:yi.id,type:Ht.BUTTON,title:`sheets-pivot-ui.valueFilter.title`,hidden$:e.get(wt).selectionMoveEnd$.pipe(Sn(null),vn(()=>!vi(e)))}}const Yi=Hi.reduce((e,t,n)=>(e[t.id]={order:n+1,menuItemFactory:t.menuItemFactory},e),{}),Xi=qi.reduce((e,t,n)=>(e[t.id]={order:n+1,menuItemFactory:t.menuItemFactory},e),{}),Zi={[Ut.ANALYSIS]:{[Hr.id]:{order:0,gridLayout:{row:1,column:1,showLabel:!0},menuItemFactory:ki}},[Lt.MAIN_AREA]:{[It.DATA]:{[Hr.id]:{order:1,menuItemFactory:ki},[bi]:{order:2,menuItemFactory:Ai,...Yi},[xi]:{order:3,menuItemFactory:ji},[Si]:{order:4,menuItemFactory:Mi},[Ci]:{order:5,menuItemFactory:Ni},[wi]:{order:6,menuItemFactory:Pi},[Ti]:{order:7,menuItemFactory:Fi},[Ei]:{order:8,menuItemFactory:Ui,...Xi},[Di]:{order:9,menuItemFactory:Ji}}},[Lt.COL_HEADER]:{[It.DATA]:{[Hr.id]:{order:1,menuItemFactory:ki},[bi]:{order:2,menuItemFactory:Ai,...Yi},[xi]:{order:3,menuItemFactory:ji},[Si]:{order:4,menuItemFactory:Mi},[Ci]:{order:5,menuItemFactory:Ni},[wi]:{order:6,menuItemFactory:Pi},[Ti]:{order:7,menuItemFactory:Fi}}}};var Qi=`@univerjs-pro/sheets-pivot-ui`,$i=`1.6.0`;const ea={type:Ie.OPERATION,id:`sheet.operation.open-pivot-table-filter-panel`,async handler(e,t){if(!t)return!1;let{row:n,col:r,unitId:i,subUnitId:a,tableFieldId:o,pivotTableId:s}=t,c=e.get(j),l=s||c.getPivotTableIdByCell(i,a,n,r);if(!l)return!1;let u=e.get(ye),d=c.getPivotItemRenderInfoCache(i,a,l);if(!(d!=null&&d.rangesInfo))return!1;let f=c.getPivotTableCellData(i,a,n,r),p=(await u.getPivotDisplayConfig({unitId:i,subUnitId:a,pivotTableId:l,params:{type:k.Filter,filter:{row:n,col:r,tableFieldId:o,cellData:f,pivotItemRenderInfoCache:d}}})).result.filter;if(!p)return!1;let m=e.get(R),h={id:kr,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:Or,unitId:i,subUnitId:a,key:`${n}-${r}-${o||``}`,filterItemInfo:p},onClose:()=>{m.close(kr)}};return m.open(h),!0}},ta={type:Ie.OPERATION,id:`sheet.operation.open-pivot-table-field-setting-panel`,handler(e,t){if(!t)return!1;let n=e.get(L),{tableFieldId:r,pivotTableId:i,unitId:a,subUnitId:o,tableFieldInfo:s,dataFieldInfo:c}=t,l=e.get(R),u={id:jr,title:{title:n.t(`sheets-pivot-ui.fieldSettings`)},draggable:!0,mask:!1,maskClosable:!1,width:400,children:{label:Ar,tableFieldId:r,pivotTableId:i,tableFieldInfo:s,dataFieldInfo:c,unitId:a,subUnitId:o,version:Math.random(),key:`field-setting-${r||``}`,closeFn:()=>{l.close(jr)}},onClose:()=>{l.close(jr)}};return l.open(u),!0}};function na(e,t,n){let r=n.fieldIds,{fieldsConfig:i}=t,{rowFields:a,columnFields:o,valueFields:s,filterFields:c,hiddenFields:l,dimension:u,measure:d,valueIndex:f,valuePosition:p}=i,h=/* @__PURE__ */ new Set;[...a,...o,...s,...c,...l].forEach(e=>{let t=u[e]||d[e];t&&h.add(t.dataFieldId)});let g=r.map(t=>{let r=n.fields[t];return{checked:h.has(t),dataFieldId:r.id,id:r.id,name:r.name,type:r.fieldDataType,pivotTableId:e}}),_=a.flatMap(e=>{let t=u[e];return t?[{dataFieldId:t.dataFieldId,tableFieldId:t.id,displayName:t.displayName}]:[]}),v=o.flatMap(e=>{let t=u[e];return t?[{dataFieldId:t.dataFieldId,tableFieldId:t.id,displayName:t.displayName}]:[]}),y=s.flatMap(e=>{let t=d[e];return t?[{dataFieldId:t.dataFieldId,tableFieldId:t.id,displayName:t.displayName,format:t.format,subTotalType:t.subtotal}]:[]}),b=c.flatMap(e=>{let t=u[e];return t?[{dataFieldId:t.dataFieldId,tableFieldId:t.id,displayName:t.displayName}]:[]}),x=l.flatMap(e=>{let t=u[e];return t?[{dataFieldId:t.dataFieldId,tableFieldId:t.id,displayName:t.displayName,filterInfo:t.filterInfo}]:[]});return y.length>1&&(p===m.Row?_:v).splice(f,0,{dataFieldId:``,tableFieldId:`PivotMultipleValueId`,displayName:`ΣValue`}),{sourceList:g,sourceRange:t.sourceRangeInfo,rowFields:_,columnFields:v,valueFields:y,filterFields:b,hiddenFields:x,positionInfo:t.targetCellInfo}}const ra={type:Ie.OPERATION,id:`sheet.operation.open-pivot-table-panel`,async handler(e,t){let n=t==null?void 0:t.pivotTableId;if(!n)return!1;let r=e.get(Bt),i=e.get(F),a=e.get(L),o=e.get(M),s=Nt(i);if(!s)return!1;let{unitId:c,subUnitId:l}=s,u=o.getPivotTableConfig(c,l,n),d=o.getCollection(c,n);if(!u||!d)return!1;let f=na(n,u,d),p={header:{title:a.t(`sheets-pivot-ui.title`)},id:Dr,children:{label:Er,panelInfo:f,version:Math.random(),setVersion:()=>Math.random(),pivotTableId:n,unitId:c,subUnitId:l},width:346};return r.open(p),!0}},ia=`sheets-pivot-ui.config`,aa={};function oa(e){"@babel/helpers - typeof";return oa=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},oa(e)}function sa(e,t){if(oa(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(oa(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function ca(e){var t=sa(e,`string`);return oa(t)==`symbol`?t:t+``}function X(e,t,n){return(t=ca(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Z(e,t){return function(n,r){t(n,r,e)}}function Q(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 la=class extends N{constructor(e,t,n,r,i,a,o,s){var c;super(),this._localeService=e,this._sheetInterceptorService=t,this._injector=n,this._confirmService=r,this._sheetsPivotTableService=i,this._configService=a,this._sheetPermissionCheckController=o,this._sheetsRenderService=s,X(this,`_defaultOverride`,!1),this.disposeWithMe(this._sheetsRenderService.registerSelfRenderingMutations(D.id)),this._initUIInterceptListener(),this._defaultOverride=((c=this._configService.getConfig(oe))==null?void 0:c.defaultOverride)??!1}_getPivotAppliedRanges(e,t,n){return Ee(e,t,n,this._localeService.getDirection())}_initUIInterceptListener(){this._sheetsPivotTableService.asyncInterceptor.interceptAsync(this._sheetsPivotTableService.asyncInterceptor.getInterceptPoints().PIVOT_PERFORM_CHECK,{handler:async(e,t)=>{let{cellInfo:n,view:r,isEmpty:i}=t,{unitId:a,subUnitId:o}=n,s=this._getPivotAppliedRanges(n,r,i);if(!jt(this._injector,a,o,s)){let e=this._localeService.t(`sheets-pivot-ui.msg.permissionError`);this._sheetPermissionCheckController.blockExecuteWithoutPermission(e)}let c=this._sheetInterceptorService.generateMutationsByRanges({unitId:a,subUnitId:o,ranges:s}),l=Te(this._injector,a,o,s);if(c.redos.length||l.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)}})}};la=Q([Z(0,I(L)),Z(1,I(St)),Z(2,I(Ke)),Z(3,I(Ue)),Z(4,I(be)),Z(5,I(He)),Z(6,I(Ct)),Z(7,I(nn))],la);function ua(e){let{editable:t,pivotTableId:n,subUnitId:r,unitId:i}=e,a=z(P),o=z(R),s=z(L),c=[{command:{id:ra.id,params:{pivotTableId:n}},disabled:!t,label:`sheets-pivot-ui.mobile.edit`},{command:{id:ie.id,params:{unitId:i,subUnitId:r,pivotTableId:n}},disabled:!t,label:`sheets-pivot-ui.mobile.delete`}];async function l(e){await a.executeCommand(e.id,e.params),o.close(Vr)}return/* @__PURE__ */ W(`div`,{className:`univer-flex univer-flex-col univer-gap-2`,children:c.map(e=>{let t=s.t(e.label);return/* @__PURE__ */ W(Mn,{title:t,"aria-label":t,variant:`subtle`,disabled:e.disabled,onClick:()=>l(e.command)},e.command.id)})})}const da=[{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`}],fa=[{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`}],pa=[{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`}],ma=`PivotMultipleValueId`;function ha(t,r){if(r===n.blank)return`sheets-pivot-ui.dialog.filter.blank`;if(r===n.other&&t===e.otherDataKey)return`sheets-pivot-ui.showValuesAs.other`}function ga(e,t){let n=ke(t,e);return e.includes(`{0}`)?e.replace(`{0}`,n):`${e}${n}`}const _a=e=>{switch(e){case`filter`:return p.Filter;case`row`:return p.Row;case`column`:return p.Column;case`value`:return p.Value;default:return p.Row}};function va(e,t){switch(t.rangeType||Ye.NORMAL){case Ye.NORMAL:return{startRow:t.startRow,startColumn:t.startColumn,endRow:t.endRow,endColumn:t.endColumn};case Ye.ROW:return{startRow:t.startRow,startColumn:0,endRow:t.endRow,endColumn:e.getColumnCount()-1};case Ye.COLUMN:return{startRow:0,startColumn:t.startColumn,endRow:e.getRowCount()-1,endColumn:t.endColumn};case Ye.ALL:return{startRow:0,startColumn:0,endRow:e.getRowCount()-1,endColumn:e.getColumnCount()-1}}}function ya(e,t){if(!t||!e||t.endRow-t.startRow<=0)return 1;let{startRow:n,startColumn:r,endRow:i,endColumn:a}=va(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 ba(e,t,n){let{commandService:r,pivotTableInfo:i,pivotTableId:a,unitId:o,subUnitId:s}=e,c=[],{rowFields:l,columnFields:u,filterFields:d,valueFields:f}=i,p=[...l,...u,...d,...f];t===`PivotMultipleValueId`&&f.forEach(e=>{c.push(e.tableFieldId)}),n===`source`&&p.forEach(e=>{e.dataFieldId===t&&c.push(e.tableFieldId)}),n!==`source`&&p.find(e=>e.tableFieldId===t)&&c.push(t),await r.executeCommand(re.id,{pivotTableId:a,fieldIds:c,unitId:o,subUnitId:s})}async function xa(e,t,n,r,i){let a={unitId:r,subUnitId:i,token:t,dataRangeInfo:n};await e.executeCommand(Ce.id,a)}const Sa=(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 Ca(e,t,n,r,i){if(n===`source`&&r===`source`)return;let a=t===ma,{commandService:o,pivotTableInfo:s,pivotTableId:c,unitId:l,subUnitId:u}=e;if(n===`source`&&r!==`source`){let{sourceList:e}=s,n=e.find(e=>e.id===t);if(n){let e=Sa(s,t);if(r!==`value`&&e.length>0){let t=e[0];await o.executeCommand(O.id,{pivotTableId:c,fieldId:t,area:_a(r),index:i,unitId:l,subUnitId:u})}else await o.executeCommand(T.id,{pivotTableId:c,dataFieldId:n.dataFieldId,fieldArea:_a(r),index:i,unitId:l,subUnitId:u})}}if(n!==`source`&&r===`source`){let{rowFields:n,columnFields:r,filterFields:i,valueFields:o}=s,c=[...n,...r,...i,...o],l=[];a?o.forEach(e=>{l.push(e.tableFieldId)}):c.find(e=>e.tableFieldId===t)&&l.push(t),await wa(e,l)}else n!==`source`&&r!==`source`&&await Ea(e,t,n,r,i)}async function wa(e,t){let{commandService:n,pivotTableId:r,unitId:i,subUnitId:a}=e;await n.executeCommand(re.id,{pivotTableId:r,fieldIds:t,unitId:i,subUnitId:a})}async function Ta(e,t,n){let{commandService:r,pivotTableId:i,unitId:a,subUnitId:o}=e;await r.executeCommand(we.id,{pivotTableId:i,position:t,index:n,unitId:a,subUnitId:o})}async function Ea(e,t,n,r,i){let a=t===ma,{commandService:o,pivotTableInfo:s,pivotTableId:c,unitId:l,subUnitId:u}=e;if(a){let e=_a(r);(e===p.Row||e===p.Column)&&await o.executeCommand(we.id,{pivotTableId:c,position:e===p.Row?m.Row:m.Column,index:i,unitId:l,subUnitId:u});return}let{rowFields:d,columnFields:f,filterFields:h,valueFields:g}=s,_=[...d,...f,...h,...g].find(e=>e.tableFieldId===t);if(_){let a=[...d,...f,...h];if(n===`value`&&r!==`value`&&a.find(e=>e.dataFieldId===_.dataFieldId)){await wa(e,[t]);return}await o.executeCommand(O.id,{pivotTableId:c,fieldId:t,area:_a(r),index:i,unitId:l,subUnitId:u})}}function Da(e,t,n,r,i){e.executeCommand(ea.id,{row:-1,col:-1,unitId:t,subUnitId:n,tableFieldId:i,pivotTableId:r})}function Oa(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(ta.id,a)}}const ka=[{type:f.average,textKey:`sheets-pivot-ui.subtotal.average`},{type:f.count,textKey:`sheets-pivot-ui.subtotal.count`},{type:f.countNums,textKey:`sheets-pivot-ui.subtotal.countNums`},{type:f.max,textKey:`sheets-pivot-ui.subtotal.max`},{type:f.min,textKey:`sheets-pivot-ui.subtotal.min`},{type:f.product,textKey:`sheets-pivot-ui.subtotal.product`},{type:f.stdDev,textKey:`sheets-pivot-ui.subtotal.stdDev`},{type:f.stdDevp,textKey:`sheets-pivot-ui.subtotal.stdDevp`},{type:f.sum,textKey:`sheets-pivot-ui.subtotal.sum`},{type:f.var,textKey:`sheets-pivot-ui.subtotal.var`},{type:f.varp,textKey:`sheets-pivot-ui.subtotal.varp`}],Aa=(e,t=0)=>e?ut.getFormatInfo(e).maxDecimals??t:t,ja=e=>Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(``),$=(e,t)=>e.split(`;`).map(e=>/\.0?/.test(e)?e.replace(/\.0*/g,`${t>0?`.`:``}${ja(Number(t||0))}`):/0[^0]?/.test(e)?e.replace(/0[^0]+|0$/,`0${t>0?`.`:``}${ja(Number(t||0))}`):e).join(`;`),Ma=e=>nt.find(t=>e.includes(t)),Na=e=>!e,Pa=e=>!!Ma(e)&&e.startsWith(`_(`),Fa=e=>!!Ma(e)&&!e.startsWith(`_(`),Ia=()=>da.map(e=>({label:e.label,value:e.suffix})),La=e=>{let t=ut.getFormatInfo(e);return Ia().map(e=>e.value).includes(e)||[`date`,`datetime`,`time`].includes(t.type)},Ra=()=>fa.map(e=>({label:e.label,value:e.suffix,color:e.color})),za=e=>Ra().some(t=>st(t.value,e)),Ba=(e,t)=>{switch(t){case p.Row:return e.rowFields.length;case p.Column:return e.columnFields.length;case p.Filter:return e.filterFields.length;case p.Value:return e.valueFields.length;default:return 0}},Va=(e,t,n)=>{for(let r 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 i=n[r];if(i+ke(e,i)===t||i+e===t)return!0}return!1},Ha=(e,t,n)=>{let r=``;switch(n){case f.average:r=t[`sheets-pivot-ui.averageName`];break;case f.count:r=t[`sheets-pivot-ui.countName`];break;case f.countNums:r=t[`sheets-pivot-ui.countNumsName`];break;case f.max:r=t[`sheets-pivot-ui.maxName`];break;case f.min:r=t[`sheets-pivot-ui.minName`];break;case f.product:r=t[`sheets-pivot-ui.productName`];break;case f.stdDev:r=t[`sheets-pivot-ui.stdDevName`];break;case f.stdDevp:r=t[`sheets-pivot-ui.stdDevpName`];break;case f.sum:r=t[`sheets-pivot-ui.sumName`];break;case f.var:r=t[`sheets-pivot-ui.varName`];break;case f.varp:r=t[`sheets-pivot-ui.varpName`];break;default:return e}return r+ke(e,r)};function Ua(e,t){if(t.conditionFilter&&C(t.conditionFilter))return`HasFilter`;if(!e)return`NotFilter`;if(S(e))return`HasFilter`;if(x(e)){var n;return e.isAll||((n=t.items)==null?void 0:n.length)===e.list.length?`NotFilter`:`HasFilter`}return C(e)?`HasFilter`:`NotFilter`}function Wa(e){return Pa(e)?`accounting`:Fa(e)?`currency`:La(e)?`date`:za(e)?`thousandthPercentile`:`general`}function Ga(e){let{originPattern:t=``,onChange:n}=e,r=z(L),[i,a]=Y(()=>Wa(t)),[o,s]=Y(()=>Aa(t,2)),[c,l]=Y(()=>Ma(t)||nt[0]),[u,d]=Y(t),f=_r(()=>[{value:`general`,label:r.t(`sheets-pivot-ui.dialog.numfmt.general`)},{value:`accounting`,label:r.t(`sheets-pivot-ui.dialog.numfmt.accounting`)},{value:`currency`,label:r.t(`sheets-pivot-ui.dialog.numfmt.currency`)},{value:`date`,label:r.t(`sheets-pivot-ui.dialog.numfmt.date`)},{value:`thousandthPercentile`,label:r.t(`sheets-pivot-ui.dialog.numfmt.thousandthPercentile`)}],[r]),p=nt.map(e=>({label:e,value:e}));function m(e){d(e),n(e)}function h(e,t){return $(`_("${e}"* #,##0${t>0?`.0`:``}_)`,t)}function g(e){a(e),m(e===`general`?``:e===`accounting`?h(c,o):e===`currency`?$(pa[0].suffix(c),o):e===`date`?da[0].suffix:$(fa[0].suffix,o))}function _(e){l(e),m(i===`accounting`?h(e,o):$(pa[0].suffix(e),o))}function v(e){let t=e??0;s(t),m(i===`accounting`?h(c,t):$(u,t))}let y=pa.map(e=>({label:e.label(c),value:e.suffix(c),color:e.color})),b=fa.map(e=>({label:e.label,value:e.suffix,color:e.color})),x=da.map(e=>({label:e.label,value:e.suffix}));return/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,children:[/* @__PURE__ */ G(`div`,{children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:r.t(`sheets-pivot-ui.dialog.numfmt.formatTypes`)}),/* @__PURE__ */ W(Fn,{className:`univer-w-full`,value:i,options:f,onChange:e=>g(e),size:`small`})]}),(i===`accounting`||i===`currency`)&&/* @__PURE__ */ G(`div`,{className:`univer-grid univer-grid-cols-2 univer-gap-3`,children:[/* @__PURE__ */ G(`div`,{children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:r.t(`sheets-pivot-ui.dialog.numfmt.decimalPlaces`)}),/* @__PURE__ */ W(An,{className:`univer-w-full`,value:o,min:0,max:20,onChange:v,size:`small`,controls:!1})]}),/* @__PURE__ */ G(`div`,{children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:r.t(`sheets-pivot-ui.dialog.numfmt.currencyTypes`)}),/* @__PURE__ */ W(Fn,{className:`univer-w-full`,value:c,options:p,onChange:_,size:`small`})]})]}),i===`thousandthPercentile`&&/* @__PURE__ */ G(`div`,{children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:r.t(`sheets-pivot-ui.dialog.numfmt.decimalPlaces`)}),/* @__PURE__ */ W(An,{className:`univer-w-full`,value:o,min:0,max:20,onChange:v,size:`small`,controls:!1})]}),i===`currency`&&/* @__PURE__ */ W(Bn,{className:`univer-rounded-xl univer-p-2`,options:y,value:u,onChange:e=>m($(e,o))}),i===`date`&&/* @__PURE__ */ W(Bn,{className:`univer-rounded-xl univer-p-2`,options:x,value:u,onChange:e=>m(e)}),i===`thousandthPercentile`&&/* @__PURE__ */ W(Bn,{className:`univer-rounded-xl univer-p-2`,options:b,value:u,onChange:e=>m($(e,o))}),/* @__PURE__ */ W(`div`,{className:`univer-text-sm univer-text-gray-500`,children:r.t(`sheets-pivot-ui.dialog.numfmt.${i}Desc`)})]})}function Ka(e){let{unitId:t,subUnitId:n,pivotTableId:r,tableFieldId:i,originPattern:a,tableFieldInfo:o,dataFieldInfo:s}=e,c=z(P),l=z(R),u=z(L),[d,f]=Y(a??``);async function p(){let e={format:d,tableFieldId:i,pivotTableId:r,unitId:t,subUnitId:n,tableFieldInfo:o,dataFieldInfo:s};await c.executeCommand(Se.id,e),l.close(Nr)}return/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-5`,dir:u.getDirection(),children:[/* @__PURE__ */ W(Ga,{originPattern:a,onChange:f}),/* @__PURE__ */ G(Nn,{children:[/* @__PURE__ */ W(V,{onClick:()=>l.close(Nr),size:`middle`,children:u.t(`sheets-pivot-ui.dialog.numfmt.cancel`)}),/* @__PURE__ */ W(V,{variant:`primary`,onClick:p,size:`middle`,children:u.t(`sheets-pivot-ui.dialog.numfmt.confirm`)})]})]})}function qa(e){let{unitId:t,subUnitId:n,pivotTableId:r,tableFieldId:i,tableFieldInfo:a,dataFieldInfo:o,closeFn:s,format:c,version:l}=e,u=z(P),d=z(M),f=z(L),[p,m]=Y(`field`),[h,g]=Y(a.displayName),[_,v]=Y(a.subTotalType),[y,b]=Y(c??a.format??``),[x,S]=Y(y);q(()=>{m(`field`),g(a.displayName),v(a.subTotalType),b(c??a.format??``),S(c??a.format??``)},[c,a,l]);let C={...d.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=>{C[e]=f.t(e)});function w(e){v(e),Va(o.name,h,C)&&g(Ha(o.name,C,e))}async function T(){let e={displayName:a.displayName===h?void 0:h,subtotalType:a.subTotalType===_?void 0:_,format:a.format===y?void 0:y,tableFieldId:i,pivotTableId:r,unitId:t,subUnitId:n,tableFieldInfo:a,dataFieldInfo:o};await u.executeCommand(Se.id,e),s()}return p===`format`?/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-5`,dir:f.getDirection(),children:[/* @__PURE__ */ G(`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:()=>m(`field`),children:[/* @__PURE__ */ W(Qn,{}),f.t(`sheets-pivot-ui.dialog.numfmt.fieldSetting`)]}),/* @__PURE__ */ W(Ga,{originPattern:y,onChange:S}),/* @__PURE__ */ G(Nn,{children:[/* @__PURE__ */ W(V,{onClick:()=>m(`field`),size:`middle`,children:f.t(`sheets-pivot-ui.dialog.numfmt.cancel`)}),/* @__PURE__ */ W(V,{variant:`primary`,onClick:()=>{b(x),m(`field`)},size:`middle`,children:f.t(`sheets-pivot-ui.dialog.numfmt.confirm`)})]})]}):/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,dir:f.getDirection(),children:[/* @__PURE__ */ G(`div`,{children:[/* @__PURE__ */ G(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-sm univer-font-medium`,children:f.t(`sheets-pivot-ui.dialog.fieldName`)}),/* @__PURE__ */ W(`span`,{className:`univer-truncate univer-text-xs univer-text-gray-500`,children:ga(f.t(`sheets-pivot-ui.dialog.sourceName`),o.name)})]}),/* @__PURE__ */ W(kn,{className:`univer-mt-2 univer-w-full`,value:h,onChange:g,size:`small`})]}),/* @__PURE__ */ G(`div`,{children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:f.t(`sheets-pivot-ui.dialog.summarizeBy`)}),/* @__PURE__ */ W(`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:ka.map(e=>/* @__PURE__ */ G(`button`,{type:`button`,className:U(`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":_===e.type}),onClick:()=>w(e.type),children:[/* @__PURE__ */ W(tr,{className:U(`univer-text-primary-600`,{"univer-invisible":_!==e.type})}),f.t(e.textKey)]},e.type))})]}),/* @__PURE__ */ W(V,{className:`univer-w-full`,onClick:()=>{S(y),m(`format`)},size:`middle`,children:f.t(`sheets-pivot-ui.dialog.format`)}),/* @__PURE__ */ G(Nn,{children:[/* @__PURE__ */ W(V,{onClick:s,size:`middle`,children:f.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ W(V,{variant:`primary`,disabled:!h,onClick:T,size:`middle`,children:f.t(`sheets-pivot-ui.dialog.ok`)})]})]})}function Ja(e){var t;let{filterItemInfo:i,unitId:a,subUnitId:o}=e,s=z(P),c=z(R),l=z(L),u=z(F),d=B(l.direction$,l.getDirection()),[f,p]=Y(()=>{var e;return i.checkedItems??((e=i.filterInfo)==null?void 0:e.list)??i.items}),[m,h]=Y(()=>i.partialItems??[]),[g,_]=Y((t=i.sortInfo)==null?void 0:t.type),v=m.length===0&&f.length===i.items.length,y=Ua(i.filterInfo,{items:i.items,conditionFilter:i.conditionFilter});q(()=>{let e=u.getCurrentUnitOfType(et.UNIVER_SHEET);if(!e)return;let t=e.activeSheet$.subscribe(e=>{(e==null?void 0:e.getSheetId())!==o&&c.close(kr)});return()=>t.unsubscribe()},[c,o,u]);function b(){c.close(kr)}function x(e){m.includes(e)?(h(t=>t.filter(t=>t!==e)),p(t=>[...t,e])):p(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])}async function S(e,t,n,r=!1){await s.executeCommand(fe.id,{unitId:a,subUnitId:o,pivotTableId:i.pivotTableId,tableFieldId:i.tableFieldId,items:e,partialItems:n,isAll:t,clearAllFilters:r}),b()}async function C(e){await s.executeCommand(_e.id,{unitId:a,subUnitId:o,pivotTableId:i.pivotTableId,tableFieldId:i.tableFieldId,info:{type:e}}),_(e),b()}return/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,dir:d,children:[/* @__PURE__ */ W(`div`,{className:`univer-text-base univer-font-semibold`,children:l.t(`sheets-pivot-ui.filterField`)}),/* @__PURE__ */ G(`div`,{className:`univer-grid univer-grid-cols-2 univer-gap-2`,children:[/* @__PURE__ */ G(V,{className:U(``,{"univer-bg-gray-100 dark:!univer-bg-gray-700":g===r.ascending}),onClick:()=>C(r.ascending),size:`middle`,children:[/* @__PURE__ */ W($n,{}),l.t(`sheets-pivot-ui.dialog.filter.ascending`)]}),/* @__PURE__ */ G(V,{className:U(``,{"univer-bg-gray-100 dark:!univer-bg-gray-700":g===r.descending}),onClick:()=>C(r.descending),size:`middle`,children:[/* @__PURE__ */ W(rr,{}),l.t(`sheets-pivot-ui.dialog.filter.descending`)]})]}),/* @__PURE__ */ G(`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__ */ W(`div`,{className:`univer-flex univer-min-h-12 univer-items-center univer-px-2`,children:/* @__PURE__ */ W(H,{checked:v,indeterminate:!v&&(f.length>0||m.length>0),onChange:()=>{h([]),p(v?[]:i.items)},children:l.t(`sheets-pivot-ui.dialog.filter.selectAll`)})}),i.items.map((e,t)=>{var r;let a=i.itemTypes[t],o=(r=i.itemLabels)==null?void 0:r[e],s=ha(e,a),c=e;return s?c=l.t(s):o===void 0?a===n.date&&i.format&&(c=ut.format(i.format,Number(e))):c=o,/* @__PURE__ */ W(`div`,{className:`univer-flex univer-min-h-12 univer-items-center univer-px-2`,children:/* @__PURE__ */ W(H,{checked:f.includes(e),indeterminate:m.includes(e),contentClassName:`univer-max-w-[70vw] univer-truncate`,onChange:()=>x(e),children:c})},e)})]}),/* @__PURE__ */ W(V,{className:`univer-w-full`,variant:`link`,disabled:y===`NotFilter`,onClick:()=>S(i.items,!0,[],!0),size:`middle`,children:l.t(`sheets-pivot-ui.dialog.filter.clearFilter`)}),/* @__PURE__ */ G(Nn,{children:[/* @__PURE__ */ W(V,{onClick:b,size:`middle`,children:l.t(`sheets-pivot-ui.dialog.filter.cancel`)}),/* @__PURE__ */ W(V,{variant:`primary`,disabled:!f.length&&!m.length,onClick:()=>S(f,v,m),size:`middle`,children:l.t(`sheets-pivot-ui.dialog.filter.confirm`)})]})]})}const Ya=[{label:`sheets-pivot-ui.config.pageDownThenOver`,value:`false`},{label:`sheets-pivot-ui.config.pageOverThenDown`,value:`true`}],Xa=[{label:`sheets-pivot-ui.config.layoutTabular`,value:String(c.tabular)},{label:`sheets-pivot-ui.config.layoutCompact`,value:String(c.compact)},{label:`sheets-pivot-ui.config.layoutOutline`,value:String(c.outline)}],Za=[{label:`sheets-pivot-ui.config.rowSubtotalTop`,value:String(d.top)},{label:`sheets-pivot-ui.config.rowSubtotalBottom`,value:String(d.bottom)}],Qa=[{label:`sheets-pivot-ui.config.dateGroupingLegacy`,value:a.Legacy},{label:`sheets-pivot-ui.config.dateGroupingExcelLike`,value:a.ExcelLike}];function $a(e){let{unitId:t,subUnitId:n,pivotTableId:r}=e,i=z(P),a=z(Ue),o=z(We),s=z(L),l=z(M),u=_r(()=>l.watchPivotTableChanges(t,n,r).pipe(hn(0)),[l,t,n,r]);B(u);let[f,p]=Y(!1),m=J(!1),h=l.getPivotTableConfig(t,n,r),g=v(h==null?void 0:h.fieldsConfig.options),[_,y]=Y(()=>{var e,i;let a=l.getPivotTableConfig(t,n,r),o=(a==null||(e=a.fieldsConfig)==null?void 0:e.options)??{};return{showRowSubtotal:o.showRowSubtotal??!0,showRowGrandTotal:o.showRowGrandTotal??!0,showColSubtotal:o.showColSubtotal??!0,showColGrandTotal:o.showColGrandTotal??!0,pageWrap:o.pageWrap??1,pageOverThenDown:o.pageOverThenDown??!1,repeatRowLabels:o.repeatRowLabels??!1,repeatColLabels:o.repeatColLabels??!1,layout:(a==null||(i=a.fieldsConfig)==null?void 0:i.layout)??c.tabular,rowSubtotalPosition:o.rowSubtotalPosition??d.top}});function x(e){let a={unitId:t,subUnitId:n,pivotTableId:r,options:e};return y(t=>({...t,...e})),i.executeCommand(ge.id,a).catch(e=>o.error(`[MobilePivotConfigPanel]`,e))}function S(e){let a={unitId:t,subUnitId:n,pivotTableId:r,layout:e};return y(t=>({...t,layout:e})),i.executeCommand(pe.id,a).catch(e=>o.error(`[MobilePivotConfigPanel]`,e))}async function C(e){if(!(m.current||e===g)){m.current=!0,p(!0);try{let o=l.getPivotTableConfig(t,n,r),c=l.getCollection(t,r);if(!o||!c||(Object.values(c.fields).some(b)||c.customFields.some(b))&&!await a.confirm({id:`sheet-pivot.confirm.change-date-grouping-mode`,title:{title:s.t(`sheets-pivot-ui.config.dateGroupingSwitchTitle`)},children:{title:s.t(`sheets-pivot-ui.config.dateGroupingSwitchMessage`)},cancelText:s.t(`sheets-pivot-ui.dialog.cancel`),confirmText:s.t(`sheets-pivot-ui.dialog.ok`)})||l.getPivotTableConfig(t,n,r)!==o||l.getCollection(t,r)!==c||v(o.fieldsConfig.options)===e)return;await i.executeCommand(ge.id,{unitId:t,subUnitId:n,pivotTableId:r,options:{dateGroupingMode:e}})}catch(e){o.error(`[MobilePivotConfigPanel]`,e)}finally{m.current=!1,p(!1)}}}let w=e=>e.map(e=>({...e,label:s.t(e.label)}));return/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-5 univer-py-4`,children:[/* @__PURE__ */ G(`section`,{className:`univer-flex univer-flex-col univer-gap-3`,children:[/* @__PURE__ */ W(`div`,{className:`univer-text-sm univer-font-medium univer-text-gray-600`,children:s.t(`sheets-pivot-ui.config.displaySection`)}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-min-h-10 univer-items-center univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-sm`,children:s.t(`sheets-pivot-ui.config.dateGroupingMode`)}),/* @__PURE__ */ W(Fn,{className:`univer-w-40`,value:g,options:w(Qa),disabled:f,onChange:e=>C(e),size:`small`})]}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-min-h-10 univer-items-center univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-sm`,children:s.t(`sheets-pivot-ui.config.layout`)}),/* @__PURE__ */ W(Fn,{className:`univer-w-40`,value:String(_.layout),options:w(Xa),onChange:e=>S(Number(e)),size:`small`})]}),/* @__PURE__ */ W(H,{checked:_.repeatRowLabels,disabled:_.layout===c.compact,onChange:e=>x({repeatRowLabels:!!e}),children:s.t(`sheets-pivot-ui.config.repeatRowLabels`)}),/* @__PURE__ */ W(H,{checked:_.repeatColLabels,onChange:e=>x({repeatColLabels:!!e}),children:s.t(`sheets-pivot-ui.config.repeatColLabels`)})]}),/* @__PURE__ */ G(`section`,{className:`univer-flex univer-flex-col univer-gap-3`,children:[/* @__PURE__ */ W(`div`,{className:`univer-text-sm univer-font-medium univer-text-gray-600`,children:s.t(`sheets-pivot-ui.config.totalsSection`)}),/* @__PURE__ */ W(H,{checked:_.showRowSubtotal,onChange:e=>x({showRowSubtotal:!!e}),children:s.t(`sheets-pivot-ui.config.showRowSubtotal`)}),_.layout===c.outline&&/* @__PURE__ */ G(`div`,{className:`univer-flex univer-min-h-10 univer-items-center univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-sm`,children:s.t(`sheets-pivot-ui.config.rowSubtotalPosition`)}),/* @__PURE__ */ W(Fn,{className:`univer-w-40`,value:String(_.rowSubtotalPosition),options:w(Za),onChange:e=>x({rowSubtotalPosition:Number(e)}),size:`small`})]}),/* @__PURE__ */ W(H,{checked:_.showRowGrandTotal,onChange:e=>x({showRowGrandTotal:!!e}),children:s.t(`sheets-pivot-ui.config.showRowGrandTotal`)}),/* @__PURE__ */ W(H,{checked:_.showColSubtotal,onChange:e=>x({showColSubtotal:!!e}),children:s.t(`sheets-pivot-ui.config.showColSubtotal`)}),/* @__PURE__ */ W(H,{checked:_.showColGrandTotal,onChange:e=>x({showColGrandTotal:!!e}),children:s.t(`sheets-pivot-ui.config.showColGrandTotal`)})]}),/* @__PURE__ */ G(`section`,{className:`univer-flex univer-flex-col univer-gap-3`,children:[/* @__PURE__ */ W(`div`,{className:`univer-text-sm univer-font-medium univer-text-gray-600`,children:s.t(`sheets-pivot-ui.config.pageSection`)}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-min-h-10 univer-items-center univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-sm`,children:s.t(`sheets-pivot-ui.config.pageWrap`)}),/* @__PURE__ */ W(An,{className:`univer-w-24`,value:_.pageWrap,min:1,max:20,onChange:e=>{let t=Number(e);return Number.isFinite(t)&&t>=1?x({pageWrap:t}):void 0},size:`small`,controls:!1})]}),/* @__PURE__ */ W(`p`,{className:`univer-text-xs univer-text-gray-600`,children:s.t(_.pageOverThenDown?`sheets-pivot-ui.config.pageWrapOverThenDownHelp`:`sheets-pivot-ui.config.pageWrapDownThenOverHelp`)}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-min-h-10 univer-items-center univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-sm`,children:s.t(`sheets-pivot-ui.config.pageDirection`)}),/* @__PURE__ */ W(Fn,{className:`univer-w-40`,value:String(_.pageOverThenDown),options:w(Ya),onChange:e=>x({pageOverThenDown:e===`true`}),size:`small`})]})]})]})}function eo(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)}const to=[`filter`,`column`,`row`,`value`];function no(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 ro(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 io(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 ao(e){switch(e.area){case`filter`:return/* @__PURE__ */ W(ir,{});case`column`:return/* @__PURE__ */ W(dr,{});case`row`:return/* @__PURE__ */ W(nr,{});default:return/* @__PURE__ */ W(ar,{})}}function oo(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 so(e){switch(e){case`moveToFilter`:return`filter`;case`moveToColumn`:return`column`;case`moveToRow`:return`row`;case`moveToValue`:return`value`;default:return null}}function co(e){let{area:t,field:n,index:r,fieldCount:i,info:a,pivotTableId:o,unitId:s,subUnitId:c,refresh:l}=e,u=z(P),d=z(L),f=n.tableFieldId===ma,p={pivotTableInfo:a,pivotTableId:o,commandService:u,unitId:s,subUnitId:c};async function m(e){if(e===`filter`){Da(u,s,c,o,n.tableFieldId);return}if(e===`settings`){Oa(u,o,n.tableFieldId,s,c,a);return}if(e===`remove`){await ba(p,n.tableFieldId,t),await l();return}let i=so(e)??t,d=no(a,i).length;e===`moveUp`?d=r-1:e===`moveDown`&&(d=r+1),await Ca(p,n.tableFieldId,t,i,d),await l()}let h=eo(t,r,i,f).map(e=>({type:`item`,children:d.t(oo(e)),variant:e===`remove`?`destructive`:`default`,onSelect:()=>m(e)}));return/* @__PURE__ */ G(`div`,{className:`univer-flex univer-min-h-12 univer-items-center univer-gap-3 univer-rounded-xl univer-px-3`,children:[/* @__PURE__ */ W(`bdi`,{className:`univer-min-w-0 univer-flex-1 univer-truncate univer-text-sm`,dir:`auto`,children:f?d.t(`sheets-pivot-ui.multipleValue`):n.displayName}),/* @__PURE__ */ W(Pn,{items:h,children:/* @__PURE__ */ W(`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__ */ W(cr,{})})})]})}function lo(e){let t=z(L);return/* @__PURE__ */ W(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,children:to.map(n=>{let r=no(e.info,n);return/* @__PURE__ */ G(`section`,{children:[/* @__PURE__ */ G(`div`,{className:`univer-mb-2 univer-flex univer-items-center univer-gap-2 univer-text-sm univer-font-medium`,children:[/* @__PURE__ */ W(ao,{area:n}),t.t(ro(n))]}),/* @__PURE__ */ W(`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__ */ W(co,{...e,area:n,field:t,index:i,fieldCount:r.length},t.tableFieldId)):/* @__PURE__ */ W(`div`,{className:`univer-p-4 univer-text-center univer-text-xs univer-text-gray-500`,children:t.t(io(n))})})]},n)})})}function uo(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 fo(e){let t=`univer-size-4 univer-shrink-0 univer-text-gray-500`;switch(e.type){case n.number:return/* @__PURE__ */ W(lr,{className:t});case n.date:return/* @__PURE__ */ W(er,{className:t});default:return/* @__PURE__ */ W(pr,{className:t})}}function po(e){let{field:t,info:r,pivotTableId:i,unitId:a,subUnitId:o,refresh:s}=e,c=z(P),l=z(L),u={pivotTableInfo:r,pivotTableId:i,commandService:c,unitId:a,subUnitId:o};async function d(e){if(e){let e=t.type===n.number?`value`:`row`;await Ca(u,t.dataFieldId,`source`,e,uo(r,e))}else await ba(u,t.dataFieldId,`source`);await s()}async function f(e){await Ca(u,t.dataFieldId,`source`,e,uo(r,e)),await s()}let p=[{type:`item`,children:l.t(`sheets-pivot-ui.addToRow`),onSelect:()=>f(`row`)},{type:`item`,children:l.t(`sheets-pivot-ui.addToColumn`),onSelect:()=>f(`column`)},{type:`item`,children:l.t(`sheets-pivot-ui.addToValue`),onSelect:()=>f(`value`)},{type:`item`,children:l.t(`sheets-pivot-ui.addToFilter`),onSelect:()=>f(`filter`)}];return/* @__PURE__ */ G(`div`,{className:`univer-flex univer-min-h-12 univer-items-center univer-gap-3 univer-rounded-xl univer-px-2`,children:[/* @__PURE__ */ W(H,{checked:t.checked,onChange:e=>d(!!e)}),/* @__PURE__ */ W(fo,{type:t.type}),/* @__PURE__ */ W(`bdi`,{className:`univer-min-w-0 univer-flex-1 univer-truncate univer-text-sm`,dir:`auto`,children:t.name}),/* @__PURE__ */ W(Pn,{items:p,children:/* @__PURE__ */ W(`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__ */ W(cr,{})})})]})}function mo(e){let{info:t}=e,n=z(L),[r,i]=Y(``),a=r.trim().toLocaleLowerCase(),o=a?t.sourceList.filter(e=>e.name.toLocaleLowerCase().includes(a)):t.sourceList;return/* @__PURE__ */ G(`section`,{className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ G(`div`,{children:[/* @__PURE__ */ W(`div`,{className:`univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.sourceFieldTile`)}),/* @__PURE__ */ W(`div`,{className:`univer-mt-1 univer-text-xs univer-text-gray-500`,children:n.t(`sheets-pivot-ui.mobile.sourceFieldDescription`)})]}),/* @__PURE__ */ W(kn,{allowClear:!0,value:r,placeholder:n.t(`sheets-pivot-ui.searchFieldPlaceholder`),slot:/* @__PURE__ */ W(fr,{}),onChange:i,size:`small`}),/* @__PURE__ */ W(`div`,{className:`univer-rounded-xl univer-bg-gray-50 univer-p-1 dark:!univer-bg-gray-800`,children:o.length?o.map(t=>/* @__PURE__ */ W(po,{...e,field:t},t.id)):/* @__PURE__ */ W(`div`,{className:`univer-p-4 univer-text-center univer-text-sm univer-text-gray-500`,children:n.t(`sheets-pivot-ui.noMatchingFields`)})})]})}function ho(e){var t;let{sourceRangeInfo:n,positionInfo:r,pivotTableId:i,refresh:a}=e,o=z(P),s=z(We),c=z(L),l=z(F).getUnit(n.unitId),u=(l==null||(t=l.getSheetBySheetId(n.subUnitId))==null?void 0:t.getName())??n.sheetName,[d,f]=Y(n.range),[p,m]=Y(u),[h,g]=Y(``);q(()=>{f(n.range),m(u)},[u,n]);async function _(e){let t=e.split(`,`).filter(Boolean).map(vr)[0];if(!t||!l){g(c.t(`sheets-pivot-ui.msg.emptySourceRange`));return}let s=t.sheetName||n.sheetName,u=l.getSheetBySheetName(s),d=ya(u,t.range);if(d!==2||!u){let e=d===0?`sheets-pivot-ui.msg.emptySourceRange`:`sheets-pivot-ui.msg.invalidSize`;g(c.t(e))}else g(``),f(t.range),m(s),await xa(o,i,{unitId:n.unitId,subUnitId:u.getSheetId(),range:t.range,sheetName:s},r.unitId,r.subUnitId),await a()}return/* @__PURE__ */ G(`section`,{children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:c.t(`sheets-pivot-ui.sourceRangeLabel`)}),/* @__PURE__ */ W(xr,{unitId:n.unitId,subUnitId:n.subUnitId,initialValue:br(p,d),maxRangeCount:1,keepSheetReference:!0,supportAcrossSheet:!0,onChange:(e,t)=>_(t).catch(e=>{s.error(`[MobilePivotSourceRange]`,e)})}),h&&/* @__PURE__ */ W(`div`,{className:`univer-mt-2 univer-text-xs univer-text-red-500`,children:h})]})}function go(e){let{pivotTableId:t,version:n,unitId:r,subUnitId:i,panelInfo:a}=e,o=z(M),s=z(ye),c=z(We),l=_r(()=>o.watchPivotTableChanges(r,i,t).pipe(hn(0)),[o,r,i,t]),u=B(l),[d,f]=Y(a),p=K(async()=>{if(!o.getPivotTableConfig(r,i,t))return;let e=await s.getPivotDisplayConfig({unitId:r,subUnitId:i,pivotTableId:t,params:{type:k.Panel,panel:{pivotTableId:t}}});e.result.panel&&f(e.result.panel)},[o,t,s,i,r]);return q(()=>{p().catch(e=>c.error(`[MobilePivotPanel]`,e))},[u,c,p,n]),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-5 univer-py-4`,children:[/* @__PURE__ */ W(ho,{sourceRangeInfo:d.sourceRange,positionInfo:d.positionInfo,pivotTableId:t,refresh:p}),/* @__PURE__ */ W(mo,{info:d,pivotTableId:t,unitId:r,subUnitId:i,refresh:p}),/* @__PURE__ */ W(lo,{info:d,pivotTableId:t,unitId:r,subUnitId:i,refresh:p})]})}function _o(e){let{className:t,unitId:n,subUnitId:r,pivotTableId:i}=e,[a,o]=Y(`fields`),s=z(L);return/* @__PURE__ */ G(`div`,{className:U(`univer-flex univer-size-full univer-min-h-0 univer-flex-col`,t),dir:s.getDirection(),children:[/* @__PURE__ */ W(Rn,{className:`univer-sticky univer-top-0 univer-z-10 univer-my-3 univer-w-full univer-shrink-0`,items:[{label:s.t(`sheets-pivot-ui.fieldPanel`),value:`fields`},{label:s.t(`sheets-pivot-ui.configPanel`),value:`config`}],value:a,onChange:o}),/* @__PURE__ */ W(`div`,{className:`univer-min-h-0 univer-flex-1 univer-overflow-y-auto`,children:a===`fields`?/* @__PURE__ */ W(go,{...e}):/* @__PURE__ */ W($a,{unitId:n,subUnitId:r,pivotTableId:i})})]})}function vo(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 yo(e){let{unitId:t,subUnitId:n,sourceRange:r,positionRange:i,sourceSheetName:a,positionSheetName:o,onConfirm:s,onCancel:c}=e,l=z(L),u=z(F).getUnit(t),[d,f]=Y(r),[p,m]=Y(i),[h,g]=Y(a),[_,v]=Y(o),[y,b]=Y(A.New),[x,S]=Y(``),[C,w]=Y(!0);q(()=>{let e=ya(u.getSheetBySheetName(h),d);S(vo(e,l))},[l,d,h,u]);function T(e){let t=e.split(`,`).filter(Boolean).map(vr)[0];t?(f(t.range),g(t.sheetName||h)):S(l.t(`sheets-pivot-ui.msg.emptySourceRange`))}function E(e){let t=e.split(`,`).filter(Boolean).map(vr)[0];if(!t){m(null);return}let n=t.sheetName||a;m(t.range),v(n),w(n!==h||!Ze.intersects(t.range,d))}function D(){if(x)return;let e;if(y===A.Existing){if(!p||!C)return;e={sourceRange:d,sourceSheetName:h,positionRange:p,positionSheetName:_,positionType:y}}else e={sourceRange:d,sourceSheetName:h,positionType:y};s(e)}return/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-5`,dir:l.getDirection(),children:[/* @__PURE__ */ G(`section`,{children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:l.t(`sheets-pivot-ui.dialog.source.sourceData`)}),/* @__PURE__ */ W(xr,{unitId:t,subUnitId:n,initialValue:br(h,d),maxRangeCount:1,supportAcrossSheet:!0,keepSheetReference:!0,onChange:(e,t)=>T(t)}),x&&/* @__PURE__ */ W(`div`,{className:`univer-mt-2 univer-text-xs univer-text-red-500`,children:x})]}),/* @__PURE__ */ G(`section`,{children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:l.t(`sheets-pivot-ui.dialog.source.position`)}),/* @__PURE__ */ G(Ln,{className:`univer-flex univer-flex-col univer-gap-3`,value:y,onChange:e=>b(e),children:[/* @__PURE__ */ W(In,{value:A.New,children:l.t(`sheets-pivot-ui.dialog.source.newSheet`)}),/* @__PURE__ */ W(In,{value:A.Existing,children:l.t(`sheets-pivot-ui.dialog.source.existingSheet`)})]}),y===A.Existing&&/* @__PURE__ */ G(`div`,{className:`univer-mt-3`,children:[/* @__PURE__ */ W(xr,{unitId:t,subUnitId:n,initialValue:p?br(_,p):``,maxRangeCount:1,supportAcrossSheet:!0,keepSheetReference:!0,onChange:(e,t)=>E(t)}),!C&&/* @__PURE__ */ W(`div`,{className:`univer-mt-2 univer-text-xs univer-text-red-500`,children:l.t(`sheets-pivot-ui.dialog.source.intersect`)})]})]}),/* @__PURE__ */ G(Nn,{children:[/* @__PURE__ */ W(V,{onClick:c,size:`middle`,children:l.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ W(V,{variant:`primary`,onClick:D,size:`middle`,children:l.t(`sheets-pivot-ui.dialog.ok`)})]})]})}let bo=class extends N{constructor(e,t){super(),[[zr,yo],[Er,_o],[Or,Ja],[Ar,qa],[Mr,Ka],[Br,ua]].forEach(([t,n])=>{this.disposeWithMe(e.register(t,n))}),this.disposeWithMe(t.register({PivotTableIcon:ur}))}};bo=Q([Z(0,I(Ft)),Z(1,I(Vt))],bo);function xo(e){return{id:Hr.id,commandId:Hr.id,type:Ht.BUTTON,icon:`PivotTableIcon`,title:`sheets-pivot-ui.title`,tooltip:`sheets-pivot-ui.title`,hidden$:Gt(e,et.UNIVER_SHEET),disabled$:ln(e,cn(e,{workbookTypes:[Et],worksheetTypes:[At,kt],rangeTypes:[yt]}))}}const So={[Ut.ORGANIZATION]:{[Hr.id]:{order:1,gridLayout:{row:2,column:1},menuItemFactory:xo}},[Lt.MAIN_AREA]:{[It.DATA]:{[Hr.id]:{order:1,menuItemFactory:xo}}}};let Co=class extends N{constructor(e){super(),e.mergeMenu(So)}};Co=Q([Z(0,Rt)],Co);let wo=class extends N{constructor(e,t,n,r){super(),this._sidebarService=n,this._dialogService=r,X(this,`_pivotTableId`,null),this.disposeWithMe(e.onCommandExecuted(e=>{e.id===ra.id?this._pivotTableId=e.params.pivotTableId:e.id===ae.id&&e.params.pivotTableId===this._pivotTableId&&this._closePanel()}));let i=t.getCurrentUnitOfType(et.UNIVER_SHEET);i&&(this.disposeWithMe(i.activeSheet$.pipe(xn(1)).subscribe(()=>this._closePanel())),this.disposeWithMe(i.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(Dr),this._closeChildDialogs()}_closeChildDialogs(){this._dialogService.close(kr),this._dialogService.close(jr),this._dialogService.close(Nr)}};wo=Q([Z(0,P),Z(1,F),Z(2,Bt),Z(3,R)],wo);var To=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){Jn.drawWith(e,{radius:2,width:16,height:16,fill:r}),Cr(e,t,0,0,16,n)}};const Eo=/* @__PURE__ */ new Set([t.FilterAll,t.FilterPartial,t.FilterSingle,t.FilterNoneSortNone,t.FilteredSortAsc,t.FilteredSortDesc,t.FilteredSortNone,t.FilterNoneSortAsc,t.FilterNoneSortDesc]),Do=/* @__PURE__ */ new Set([t.Expand,t.Collapse]);let Oo=class extends Yn{constructor(e,t,n,r){super(e,t),this._commandService=n,this._themeService=r,X(this,`_cellWidth`,0),X(this,`_cellHeight`,0),X(this,`_hovered`,!1),X(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:n,row:r,unitId:i,subUnitId:a,buttonType:o}=this._pivotParams;Eo.has(o)?setTimeout(()=>{this._commandService.executeCommand(ea.id,{row:r,col:n,unitId:i,subUnitId:a})},200):this._commandService.executeCommand(ce.id,{row:r,col:n,unitId:i,subUnitId:a,collapse:o===t.Expand})}onPointerEnter(){this._hovered=!0,this.setCursor(Kn.POINTER),this.makeDirty(!0)}onPointerLeave(){this._hovered=!1,this.setCursor(Kn.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.Collapse?To.drawExpand(e,12,i,a,this._cellHeight):this._pivotParams.buttonType===t.Expand?To.drawCollapse(e,12,i,a,this._cellHeight):this._pivotParams.buttonType===t.FilterAll||this._pivotParams.buttonType===t.FilterNoneSortNone?To.drawFilterIcon(e,`filter-options-icon`,i,a):this._pivotParams.buttonType===t.FilterPartial||this._pivotParams.buttonType===t.FilterSingle||this._pivotParams.buttonType===t.FilteredSortNone?To.drawFilterIcon(e,`filter-applied-icon`,i,a):this._pivotParams.buttonType===t.FilterNoneSortAsc?To.drawFilterIcon(e,`ascending-icon`,i,a):this._pivotParams.buttonType===t.FilterNoneSortDesc?To.drawFilterIcon(e,`descending-icon`,i,a):this._pivotParams.buttonType===t.FilteredSortAsc?To.drawFilterIcon(e,`filter-sort-ascending-icon`,i,a):this._pivotParams.buttonType===t.FilteredSortDesc&&To.drawFilterIcon(e,`filter-sort-descending-icon`,i,a),e.restore()}};Oo=Q([Z(2,P),Z(3,I(Qe))],Oo);let ko=class extends Yn{constructor(e,t,n,r){super(e,t),this._commandService=n,this._themeService=r,X(this,`_cellWidth`,void 0),X(this,`_cellHeight`,void 0),X(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:n,row:r,unitId:i,subUnitId:a,buttonType:o}=this._pivotParams;if(Eo.has(o))return this._commandService.executeCommand(ea.id,{row:r,col:n,unitId:i,subUnitId:a});if(Do.has(o))return this._commandService.executeCommand(ce.id,{row:r,col:n,unitId:i,subUnitId:a,collapse:o===t.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.Collapse?To.drawExpand(e,12,r,i,this._cellHeight):n===t.Expand?To.drawCollapse(e,12,r,i,this._cellHeight):n===t.FilterAll||n===t.FilterNoneSortNone?To.drawFilterIcon(e,`filter-options-icon`,r,i):n===t.FilterPartial||n===t.FilterSingle||n===t.FilteredSortNone?To.drawFilterIcon(e,`filter-applied-icon`,r,i):n===t.FilterNoneSortAsc?To.drawFilterIcon(e,`ascending-icon`,r,i):n===t.FilterNoneSortDesc?To.drawFilterIcon(e,`descending-icon`,r,i):n===t.FilteredSortAsc?To.drawFilterIcon(e,`filter-sort-ascending-icon`,r,i):n===t.FilteredSortDesc&&To.drawFilterIcon(e,`filter-sort-descending-icon`,r,i),e.restore()}};ko=Q([Z(2,P),Z(3,I(Qe))],ko);function Ao(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 jo=class extends N{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,X(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(Zt,{handler:(e,t,n)=>{if(e||t.menuPosition!==Lt.MAIN_AREA)return n(e);let{col:r,row:i,subUnitId:a,unitId:o}=t;if(r==null||i==null)return n(e);let s=this._adaptorModel.getPivotTableIdByCell(o,a,i,r);return s?(this._openPivotActionPanel(o,a,s,i,r),!0):n(e)}});this.disposeWithMe(dt(e))}_openPivotActionPanel(e,t,n,r,i){let a=this._permissionController.permissionCheckWithRanges({workbookTypes:[Et],worksheetTypes:[kt],rangeTypes:[vt]},[{startRow:r,endRow:r,startColumn:i,endColumn:i}],e,t);this._dialogService.open({id:Vr,title:{title:this._localeService.t(`sheets-pivot-ui.title`)},children:{label:{name:Br,props:{editable:a,pivotTableId:n,subUnitId:t,unitId:e}}},onClose:()=>this._dialogService.close(Vr)})}_initButtonRender(){this.disposeWithMe(yn(this._adaptorModel.viewUpdate$.pipe(pn(0)),this._skeletonManagerService.currentSkeleton$,this._configModel.pivotConfigChange$,this._permissionService.permissionPointUpdate$.pipe(pn(100))).subscribe(()=>{let e=this._context.unit,t=this._skeletonManagerService.getCurrentSkeleton();if(!e||!t)return;let n=e.getActiveSheet(),r=e.getUnitId(),i=n.getSheetId(),a=this._localeService.getDirection(),{scene:o}=this._context;this._clearButtons(),this._adaptorModel.getSubUnitPivotMatrix(r,i).forValue((e,n,s)=>{if(!(s!=null&&s.pbt))return;let{startX:c,startY:l,endX:u,endY:d}=on(e,n,o,t),f=u-c,p=d-l;if(p<8||f<8||!this._permissionController.permissionCheckWithRanges({workbookTypes:[Et],worksheetTypes:[At,Dt,kt],rangeTypes:[yt,vt]},[{startRow:e,endRow:e,startColumn:n,endColumn:n}],r,i))return;let m;if(Eo.has(s.pbt))m=`filter`;else if(Do.has(s.pbt))m=`collapse`;else return;let h=Ao(a,m,{startX:c,startY:l,endX:u,endY:d}),g={left:h.left-6,top:h.top-6,width:28,height:28,zIndex:5e3,cellWidth:f,cellHeight:p,pivotParams:{row:e,col:n,unitId:r,subUnitId:i,buttonType:s.pbt}},_=`sheets-mobile-pivot-button-${e}-${n}-${r}-${i}`;this._buttonShapes.push(this._injector.createInstance(ko,_,g))}),this._buttonShapes.length&&o.addObjects(this._buttonShapes),o.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()}};jo=Q([Z(1,I(Ke)),Z(2,I(j)),Z(3,I(tn)),Z(4,I(M)),Z(5,I(Ct)),Z(6,I(Ge)),Z(7,I(L)),Z(8,R),Z(9,qe($t))],jo);let Mo=class extends N{constructor(e,t,n){super(),this._univerInstanceService=e,this._sheetsPivotTableAdaptorModel=t,this._sheetClipboardService=n,this._initialize()}_initialize(){let e=this,t,n;this.disposeWithMe(this._sheetClipboardService.addClipboardHook({id:se,onBeforeCopy(r,i){let a=e._univerInstanceService.getUnit(r,et.UNIVER_SHEET);a&&(t=e._sheetsPivotTableAdaptorModel.getSubUnitPivotMatrix(r,i),n=a.getStyles())},onAfterCopy(){t=null,n=null},getCellValueBySpecialMatrix(e,r){if(!t)return;let i=t==null?void 0:t.getValue(e,r);if(i){var a;return{...i,s:n==null?void 0:n.get(i.s),displayV:((a=i.v)==null?void 0:a.toString())||``}}}}))}};Mo=Q([Z(0,I(F)),Z(1,I(j)),Z(2,Yt)],Mo);const No=[ht.id,bt.id,xt.id,mt.id];let Po=class extends N{constructor(e,t,n,r,i,a,o,s,c){var l;super(),this._injector=e,this._univerInstanceService=t,this._sheetsPivotTableAdaptorModel=n,this._sheetInterceptorService=r,this._confirmService=i,this._localeService=a,this._sheetsPivotTableConfigModel=o,this._messageService=s,this._configService=c,X(this,`_defaultOverride`,!1),this._initMoveRangeConfirmCheck(),this._initRowColOperationCheck(),this._defaultOverride=((l=this._configService.getConfig(oe))==null?void 0:l.defaultOverride)??!1}_initMoveRangeConfirmCheck(){this.disposeWithMe(this._sheetInterceptorService.interceptBeforeCommand({performCheck:async e=>{if(e.id===_t.id){let t=Nt(this._univerInstanceService);if(!t)return Promise.resolve(!1);let{unitId:n,subUnitId:r}=t,{fromRange:i,toRange:a}=e.params,o=this._sheetsPivotTableConfigModel.getSubUnitPivotConfigs(n,r);if(!(o!=null&&o.size))return Promise.resolve(!0);for(let[e,t]of o){let{targetCellInfo:o}=t,{row:s,col:c}=o,l=s-i.startRow,u=c-i.startColumn,d={row:a.startRow+l,col:a.startColumn+u},f=d.row-o.row,p=d.col-o.col,m=this._sheetsPivotTableAdaptorModel.getPivotItemRenderInfoCache(n,r,e),h=m==null?void 0:m.rangesInfo;if(!h)return Promise.resolve(!0);let g=[];Object.keys(h).forEach(e=>{h[e].forEach(e=>{let t={...e};t.startRow=e.startRow+f,t.endRow=e.endRow+f,t.startColumn=e.startColumn+p,t.endColumn=e.endColumn+p,g.push(t)})});let _=this._sheetInterceptorService.generateMutationsByRanges({unitId:n,subUnitId:r,ranges:g}),v=Te(this._injector,n,r,g);if(_.redos.length||v.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(No.includes(e.id)){let t=e.params,{range:n}=t,r=Nt(this._univerInstanceService),i=t.unitId||(r==null?void 0:r.unitId),a=t.subUnitId||(r==null?void 0:r.subUnitId);if(!i||!a)return Promise.resolve(!0);let o=this._sheetsPivotTableConfigModel.getSubUnitPivotConfigs(i,a);if(o!=null&&o.size)for(let[e,t]of o){let t=this._sheetsPivotTableAdaptorModel.getPivotItemRenderInfoCache(i,a,e);if(t!=null&&t.rangesInfo){for(let e of Object.keys(t.rangesInfo))if(t.rangesInfo[e].some(e=>Ze.intersects(e,n)))return this._messageService.show({type:jn.Error,content:this._localeService.t(`sheets-pivot-ui.perform.rowColError`)}),Promise.resolve(!1)}}}return Promise.resolve(!0)}}))}};Po=Q([Z(0,I(Ke)),Z(1,I(F)),Z(2,I(j)),Z(3,I(St)),Z(4,I(Ue)),Z(5,I(L)),Z(6,I(M)),Z(7,I(zt)),Z(8,I(He))],Po);const Fo=[wr.id,Tr.id,Qt.id];let Io=class extends N{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(Fo.includes(e.id)){var t;let n=(t=this._sheetsSelectionsService.getCurrentLastSelection())==null?void 0:t.primary;if(!n)return;let{actualRow:r,actualColumn:i}=n,a=tt(r,i),o=Nt(this._univerInstanceService,e.params);if(!o)return;let{unitId:s,subUnitId:c}=o,l=this._sheetsPivotTableConfigModel.getSubUnitPivotConfigs(s,c);if(l!=null&&l.size)for(let[e]of l){let t=this._sheetsPivotTableAdaptorModel.getPivotItemRenderInfoCache(s,c,e);if(t!=null&&t.rangesInfo){for(let e of Object.keys(t.rangesInfo))if(t.rangesInfo[e].some(e=>Ze.intersects(e,a)))throw new Le(this._localeService.t(`sheets-pivot-ui.msg.editCellError`))}}}}))}};Io=Q([Z(0,I(wt)),Z(1,I(F)),Z(2,I(j)),Z(3,I(P)),Z(4,I(M)),Z(5,I(L))],Io);let Lo=class extends N{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:i}=r;for(let r of i)if(r.id===pt.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:jn.Error,content:n.t(`sheets-pivot-ui.msg.mergeCellError`)}),!1}return!0}})}};Lo=Q([Z(0,I(j)),Z(1,I(Jt)),Z(2,I(zt)),Z(3,I(L))],Lo);let Ro=class extends N{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:r,subUnitId:i}=t,a=(e==null?void 0:e.startRow)??1/0,o=(e==null?void 0:e.endRow)??-1/0,s=(e==null?void 0:e.startColumn)??1/0,c=(e==null?void 0:e.endColumn)??-1/0,l=this._sheetsPivotTableConfigModel.getSubUnitPivotConfigs(r,i);if(!l)return n(e);for(let[e,t]of l){var u;let t=(u=this._sheetsPivotTableAdaptorModel.getPivotItemRenderInfoCache(r,i,e))==null?void 0:u.rangesInfo;t&&Object.values(t).forEach(e=>{e.forEach(e=>{let{startRow:t,endRow:n,startColumn:r,endColumn:i}=e;a=Math.min(t,a),o=Math.max(n,o),s=Math.min(r,s),c=Math.max(i,c)})})}let d={startRow:a,endRow:o,startColumn:s,endColumn:c};return ct(d)?n(d):n(e)}}))}};Ro=Q([Z(0,I(en)),Z(1,I(j)),Z(2,I(M))],Ro);let zo=class extends N{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=Nt(this._univerInstanceService);if(!n)return e;let{unitId:r,subUnitId:i}=n,a=this._sheetsPivotTableConfigModel.getSubUnitPivotConfigs(r,i),o=[];return a&&a.forEach((e,t)=>{var n;let a=(n=this._sheetsPivotTableConfigModel.getPivotTableRangeInfo(r,i,t))==null?void 0:n.rangeInfo;a&&Object.keys(a).forEach(e=>{let t=a[e];Array.isArray(t)&&o.push(...t)})}),o.length&&t.some(e=>o.some(t=>Ze.intersects(t,e)))?!0:e}}))}};zo=Q([Z(0,I(gt)),Z(1,I(F)),Z(2,I(M))],zo);let Bo=class extends Je{constructor(e=aa,t,n,r,i){super(),this._config=e,this._injector=t,this._commandService=n,this._renderManagerService=r,this._configService=i;let{menu:a,...o}=lt({},aa,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(ia,o),this._registerCommands()}onStarting(){[[bo],[Co],[wo],[zo],[Po],[Ro],[Io],[Lo],[la],[Mo]].forEach(e=>this._injector.add(e)),ft(this._injector,[[bo],[Co],[wo],[la]])}onRendered(){this._registerRenderModules(),ft(this._injector,[[Po],[Ro],[Io],[Lo],[Mo]])}onSteady(){ft(this._injector,[[zo]])}_registerCommands(){[ra,Hr,ea,ta,Wr].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerRenderModules(){this.disposeWithMe(this._renderManagerService.registerRenderModule(et.UNIVER_SHEET,[jo]))}};X(Bo,`pluginName`,`${se}_UI_PLUGIN`),X(Bo,`packageName`,Qi),X(Bo,`version`,$i),X(Bo,`type`,et.UNIVER_SHEET),Bo=Q([ze(Gn,Xn,Tt,xe,rn,Wt),Z(1,I(Ke)),Z(2,P),Z(3,qn),Z(4,He)],Bo);const Vo=[o.Year,o.Quarter,o.Month,o.Day,o.Hour,o.Minute,o.Second],Ho={[o.Year]:`sheets-pivot-ui.dateGroup.year`,[o.Quarter]:`sheets-pivot-ui.dateGroup.quarter`,[o.Month]:`sheets-pivot-ui.dateGroup.month`,[o.Day]:`sheets-pivot-ui.dateGroup.day`,[o.Hour]:`sheets-pivot-ui.dateGroup.hour`,[o.Minute]:`sheets-pivot-ui.dateGroup.minute`,[o.Second]:`sheets-pivot-ui.dateGroup.second`},Uo=`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 Wo({targetFieldName:e,dateSystem:t,grouping:n,onConfirm:r,onCancel:i}){let a=z(L),s=B(a.direction$,a.getDirection()),c=(e,n)=>{let r=e===void 0?null:at(e,{dateSystem:t});if(!r)return{date:``,time:n};let i=e=>String(e).padStart(2,`0`);return{date:`${r.year}-${i(r.month)}-${i(r.day)}`,time:`${i(r.hours)}:${i(r.minutes)}:${i(r.seconds)}`}},[l,u]=Y((n==null?void 0:n.units)??[o.Day]),[d,f]=Y((n==null?void 0:n.autoStart)??!0),[p,m]=Y((n==null?void 0:n.autoEnd)??!0),[h,g]=Y(()=>c(n==null?void 0:n.start,`00:00:00`).date),[_,v]=Y(()=>c(n==null?void 0:n.end,`23:59:59`).date),[y,b]=Y(()=>c(n==null?void 0:n.start,`00:00:00`).time),[x,S]=Y(()=>c(n==null?void 0:n.end,`23:59:59`).time),[C,w]=Y((n==null?void 0:n.daysInterval)??1),[T,E]=Y(!1),D=J(!1),O=l.some(e=>e===o.Hour||e===o.Minute||e===o.Second),ee=l.length===1&&l[0]===o.Day,te=(e,n,r)=>{let i=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e),a=/^(\d{2}):(\d{2})(?::(\d{2}))?$/.exec(n);return!i||!a?null:it({year:Number(i[1]),month:Number(i[2]),day:Number(i[3]),hours:O?Number(a[1]):r?23:0,minutes:O?Number(a[2]):r?59:0,seconds:O?Number(a[3]??0):r?59:0,fractionalSecond:r?.999:0},{dateSystem:t})},k=d?void 0:te(h,y,!1),ne=p?void 0:te(_,x,!0),A=l.length>0&&(d||k!==null)&&(p||ne!==null)&&(k==null||ne==null||k<=ne)&&(!ee||Number.isInteger(C)&&C>=1);return/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,dir:s,children:[/* @__PURE__ */ W(`div`,{className:`univer-text-sm univer-font-medium`,children:e}),/* @__PURE__ */ G(`fieldset`,{children:[/* @__PURE__ */ W(`legend`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:a.t(`sheets-pivot-ui.dateGroup.groupBy`)}),/* @__PURE__ */ W(`div`,{className:`univer-grid univer-grid-cols-2 univer-gap-2`,children:Vo.map(e=>/* @__PURE__ */ W(H,{checked:l.includes(e),onChange:t=>u(n=>t?Vo.filter(t=>t===e||n.includes(t)):n.filter(t=>t!==e)),children:a.t(Ho[e])},e))})]}),ee&&/* @__PURE__ */ G(`label`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-3 univer-text-sm`,children:[a.t(`sheets-pivot-ui.dateGroup.daysInterval`),/* @__PURE__ */ W(An,{className:`univer-w-24`,value:C,min:1,onChange:e=>w(Number(e))})]}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ W(H,{checked:d,onChange:e=>f(!!e),children:a.t(`sheets-pivot-ui.dateGroup.autoStart`)}),!d&&/* @__PURE__ */ G(`label`,{className:`univer-flex univer-items-center univer-gap-2 univer-text-sm`,children:[a.t(`sheets-pivot-ui.dateGroup.start`),/* @__PURE__ */ W(kn,{type:`date`,value:h,onChange:g}),O&&/* @__PURE__ */ W(`input`,{className:Uo,type:`time`,step:1,value:y,onChange:e=>b(e.target.value)})]}),/* @__PURE__ */ W(H,{checked:p,onChange:e=>m(!!e),children:a.t(`sheets-pivot-ui.dateGroup.autoEnd`)}),!p&&/* @__PURE__ */ G(`label`,{className:`univer-flex univer-items-center univer-gap-2 univer-text-sm`,children:[a.t(`sheets-pivot-ui.dateGroup.end`),/* @__PURE__ */ W(kn,{type:`date`,value:_,onChange:v}),O&&/* @__PURE__ */ W(`input`,{className:Uo,type:`time`,step:1,value:x,onChange:e=>S(e.target.value)})]})]}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-justify-end univer-gap-3`,children:[/* @__PURE__ */ W(V,{onClick:i,children:a.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ W(V,{variant:`primary`,disabled:!A||T,onClick:async()=>{if(!A||D.current)return;let e={units:Vo.filter(e=>l.includes(e)),autoStart:d,autoEnd:p};!d&&k!=null&&(e.start=k),!p&&ne!=null&&(e.end=ne),ee&&C>1&&(e.daysInterval=C),D.current=!0,E(!0);try{await r(e)}catch{}finally{D.current=!1,E(!1)}},children:a.t(`sheets-pivot-ui.dialog.ok`)})]})]})}function Go(e){let t=e.operator===h.dateBetween||e.operator===h.dateNotBetween,n={type:s.CustomFilter,operator:e.operator,expected:t?[e.lower,e.upper]:e.lower,useWholeDay:e.useWholeDay};try{return g(n),n}catch{return}}function Ko(e,t){let n=at(e,{dateSystem:t});if(!n||n.day===0||n.year===1900&&n.month===2&&n.day===29)return;let r=new Date(2e3,0,1,12);return r.setFullYear(n.year,n.month-1,n.day),r}function qo(e,t,n){let r=it({year:t.getFullYear(),month:t.getMonth()+1,day:t.getDate(),hours:0,minutes:0,seconds:0,fractionalSecond:0},{dateSystem:n});return r===null?void 0:r+(e===void 0?0:e-Math.floor(e))}function Jo(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}const Yo=[{value:h.dateEqual,label:`sheets-pivot-ui.dateFilter.equal`},{value:h.dateNotEqual,label:`sheets-pivot-ui.dateFilter.notEqual`},{value:h.dateNewerThan,label:`sheets-pivot-ui.dateFilter.after`},{value:h.dateNewerThanOrEqual,label:`sheets-pivot-ui.dateFilter.afterOrEqual`},{value:h.dateOlderThan,label:`sheets-pivot-ui.dateFilter.before`},{value:h.dateOlderThanOrEqual,label:`sheets-pivot-ui.dateFilter.beforeOrEqual`},{value:h.dateBetween,label:`sheets-pivot-ui.dateFilter.between`},{value:h.dateNotBetween,label:`sheets-pivot-ui.dateFilter.notBetween`}];function Xo({dateSystem:e,defaultDate:t,currentFilter:n,onConfirm:r,onCancel:i}){let a=z(L);B(a.currentLocale$);let o=B(a.direction$,a.getDirection()),[s,c]=Y((n==null?void 0:n.operator)??h.dateEqual),l=Array.isArray(n==null?void 0:n.expected)?n.expected[0]:n==null?void 0:n.expected,u=Array.isArray(n==null?void 0:n.expected)?n.expected[1]:void 0,[d,f]=Y(()=>l??t??qo(void 0,/* @__PURE__ */ new Date,e)),[p,m]=Y(()=>u??l??t??qo(void 0,/* @__PURE__ */ new Date,e)),[g,_]=Y((n==null?void 0:n.useWholeDay)===!0),[v,y]=Y(!1),[b,x]=Y(!1),S=J(!1),C=ee(d),w=ee(p),T=s===h.dateBetween||s===h.dateNotBetween,E=Go({operator:s,lower:C,upper:w,useWholeDay:g}),D=E!==void 0&&n!==void 0&&s===n.operator&&g===(n.useWholeDay===!0)&&$e.diffValue(E.expected,n.expected);async function O(e){if(!S.current){S.current=!0,y(!0),x(!1);try{await r(e)||x(!0)}catch{x(!0)}finally{S.current=!1,y(!1)}}}function ee(e){return typeof e==`string`?e.trim()===``?void 0:Number(e):e}function te(e,t){t?m(e):f(e)}function k(t,n){let r=qo(n?w:C,t,e);n?m(r):f(r)}function ne(e,t){let n=t?w:C;if(n===void 0)return;let r=Jo(n,e);t?m(r):f(r)}return/* @__PURE__ */ G(`div`,{dir:o,className:`univer-flex univer-min-w-0 univer-flex-col univer-gap-3`,children:[/* @__PURE__ */ W(`div`,{className:`univer-text-sm univer-font-medium`,children:a.t(`sheets-pivot-ui.dateFilter.title`)}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-1`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-xs`,children:a.t(`sheets-pivot-ui.dateFilter.rule`)}),/* @__PURE__ */ W(zn,{className:`univer-w-full`,value:String(s),options:Yo.map(e=>({value:String(e.value),label:a.t(e.label)})),onChange:e=>c(Number(e))})]}),(T?[!1,!0]:[!1]).map(n=>{let r=n?w:C,i=r===void 0?void 0:Ko(r,e),o=(n?u:void 0)??l??t,s=o!==void 0&&!Ko(o,e),c=r===void 0?null:at(r,{dateSystem:e}),f=c?new Date(2e3,0,1,c.hours,c.minutes,c.seconds,Math.floor(c.fractionalSecond*1e3)):void 0,m=`sheets-pivot-ui.dateFilter.date`;return T&&(m=n?`sheets-pivot-ui.dateFilter.to`:`sheets-pivot-ui.dateFilter.from`),/* @__PURE__ */ G(`div`,{role:`group`,"aria-label":a.t(m),className:`univer-flex univer-min-w-0 univer-flex-col univer-gap-1`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-xs`,children:a.t(m)}),s?/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-1`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-xs univer-text-gray-500`,children:a.t(`sheets-pivot-ui.dateFilter.serial`)}),/* @__PURE__ */ W(kn,{value:String((n?p:d)??``),onChange:e=>te(e,n)})]}):/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-wrap univer-items-center univer-gap-2`,children:[/* @__PURE__ */ W(Dn,{value:i,onValueChange:e=>k(e,n)}),!g&&r!==void 0&&/* @__PURE__ */ W(Vn,{value:f,onValueChange:e=>ne(e,n)})]})]},String(n))}),/* @__PURE__ */ W(H,{checked:g,onChange:e=>_(e===!0),children:a.t(`sheets-pivot-ui.dateFilter.wholeDay`)}),b&&/* @__PURE__ */ W(`div`,{role:`alert`,className:`univer-text-xs univer-text-red-500`,children:a.t(`sheets-pivot-ui.dateFilter.failed`)}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-wrap univer-items-center univer-justify-between univer-gap-2`,children:[/* @__PURE__ */ W(V,{variant:`link`,disabled:v||!n,onClick:()=>O(void 0),children:a.t(`sheets-pivot-ui.dialog.filter.clearFilter`)}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-gap-2`,children:[/* @__PURE__ */ W(V,{disabled:v,onClick:i,children:a.t(`sheets-pivot-ui.dialog.filter.cancel`)}),/* @__PURE__ */ W(V,{variant:`primary`,disabled:v||!E||D,onClick:()=>O(E),children:a.t(`sheets-pivot-ui.dialog.filter.confirm`)})]})]})]})}function Zo(e){let{dialogId:t=kr,filterItemInfo:i,onClose:a,onSetFilter:o,onSetSort:s,onSetDateFilter:c,unitId:l,subUnitId:u}=e,{format:d,filterInfo:f,sortInfo:p}=i,m=i.conditionFilter??f,h=z(P),g=z(L);B(g.currentLocale$);let _=z(R),v=z(F),y=B(g.direction$,g.getDirection()),b=J(!0),[x,C]=Y(!1);q(()=>(b.current=!0,()=>{b.current=!1}),[]);let[w,T]=Y(()=>i?i.checkedItems??(f==null?void 0:f.list)??i.items:[]),[E,D]=Y(()=>i.partialItems??[]),O=E.length===0&&w.length===i.items.length,ee=w.length===0&&E.length===0,[te,k]=Y(()=>{if(i)return p==null?void 0:p.type}),ne=()=>{b.current&&(b.current=!1,a?a():_.close(t))};if(q(()=>{let e=v.getCurrentUnitOfType(et.UNIVER_SHEET);if(!e)return;let n=e.activeSheet$.subscribe(e=>{e&&e.getSheetId()!==u&&b.current&&(b.current=!1,a?a():_.close(t))});return()=>n==null?void 0:n.unsubscribe()},[t,_,a,u,v]),!i)return;let A=()=>{D([]),T(O?[]:i.items)},re=e=>{E.includes(e)?(D(E.filter(t=>t!==e)),T([...w,e])):w.includes(e)?T(w.filter(t=>t!==e)):T([...w,e])},ie=async()=>{let{tableFieldId:e,pivotTableId:t}=i;if(e&&t)try{(o?await o(w,O,E):await h.executeCommand(fe.id,{unitId:l,subUnitId:u,pivotTableId:t,tableFieldId:e,items:w,partialItems:E,isAll:O}))&&b.current&&ne()}catch{}},ae=()=>{ne()},oe=async()=>{let{tableFieldId:e,pivotTableId:t}=i;if(e&&t){T(i.items),D([]);try{(o?await o(i.items,!0,[],!0):await h.executeCommand(fe.id,{unitId:l,subUnitId:u,pivotTableId:t,tableFieldId:e,items:i.items,partialItems:[],isAll:!0,clearAllFilters:!0}))&&b.current&&ne()}catch{}}},se=async e=>{let{tableFieldId:t,pivotTableId:n}=i;if(!t||!n)return;let r={type:e};try{(s?await s(r):await h.executeCommand(_e.id,{unitId:l,subUnitId:u,pivotTableId:n,tableFieldId:t,info:r}))&&b.current&&(k(e),ne())}catch{}},ce=Ua(f,{items:i.items,conditionFilter:i.conditionFilter});async function ue(e){if(!b.current)return!1;let t=c?await c(e):await h.executeCommand(le.id,{unitId:l,subUnitId:u,pivotTableId:i.pivotTableId,tableFieldId:i.tableFieldId,filterInfo:e});return t&&b.current&&ne(),t}if(x){let e=v.getUnit(l),t=i.itemTypes.findIndex(e=>e===n.date),r=Number(i.items[t]);return/* @__PURE__ */ W(Xo,{dateSystem:(e==null?void 0:e.getDateSystem())??Re.Date1900,defaultDate:Number.isFinite(r)?r:void 0,currentFilter:S(m)?m:void 0,onConfirm:ue,onCancel:()=>C(!1)})}return/* @__PURE__ */ G(`div`,{dir:y,children:[i.supportsDateFilter&&/* @__PURE__ */ W(V,{className:`univer-mb-3 univer-w-full`,onClick:()=>C(!0),children:g.t(`sheets-pivot-ui.dateFilter.title`)}),/* @__PURE__ */ G(`div`,{className:`univer-flex`,children:[/* @__PURE__ */ G(`div`,{className:U(`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`,Un,{"univer-bg-gray-100 dark:!univer-bg-gray-700":te===r.ascending}),onClick:()=>se(r.ascending),children:[/* @__PURE__ */ W($n,{}),g.t(`sheets-pivot-ui.dialog.filter.ascending`)]}),/* @__PURE__ */ G(`div`,{className:U(`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`,Un,{"univer-bg-gray-100 dark:!univer-bg-gray-700":te===r.descending}),onClick:()=>se(r.descending),children:[/* @__PURE__ */ W(rr,{}),g.t(`sheets-pivot-ui.dialog.filter.descending`)]})]}),/* @__PURE__ */ W(`div`,{className:U(`univer-mx-0 univer-mb-4 univer-mt-3 univer-h-[300px] univer-rounded-lg univer-p-2`,Un),children:/* @__PURE__ */ G(`div`,{className:U(`univer-h-full univer-overflow-y-auto`,Wn),children:[/* @__PURE__ */ W(`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__ */ W(H,{checked:O,onChange:A,indeterminate:!O&&(w.length>0||E.length>0),children:g.t(`sheets-pivot-ui.dialog.filter.selectAll`)})}),i.items.map((e,t)=>{var r,a;let o=e,s=(r=i.itemLabels)==null?void 0:r[e],c=(a=i.itemTypes)==null?void 0:a[t],l=ha(e,c);return l?o=g.t(l):s===void 0?c===n.date&&d&&(o=ut.format(d,Number(e))):o=s,/* @__PURE__ */ W(`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__ */ W(H,{checked:w.includes(e),indeterminate:E.includes(e),onChange:()=>re(e),contentClassName:`univer-max-w-[200px] univer-truncate`,children:o})},e)})]})}),/* @__PURE__ */ G(En,{className:`univer-flex univer-items-center univer-justify-between`,children:[/* @__PURE__ */ W(`div`,{className:`univer-cursor-pointer univer-text-xs univer-text-primary-600`,children:/* @__PURE__ */ W(V,{variant:`link`,disabled:ce===`NotFilter`,onClick:oe,children:g.t(`sheets-pivot-ui.dialog.filter.clearFilter`)})}),/* @__PURE__ */ G(En,{className:`univer-flex univer-flex-1 univer-items-center univer-gap-3`,children:[/* @__PURE__ */ W(V,{onClick:ae,children:g.t(`sheets-pivot-ui.dialog.filter.cancel`)}),/* @__PURE__ */ W(V,{variant:`primary`,disabled:ee,onClick:ie,children:g.t(`sheets-pivot-ui.dialog.filter.confirm`)})]})]})]})}function Qo({name:e,onConfirm:t,onCancel:n}){let r=z(L),i=B(r.direction$,r.getDirection()),[a,o]=Y(e),[s,c]=Y(!1),l=J(!1);return/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,dir:i,children:[/* @__PURE__ */ G(`label`,{className:`univer-flex univer-flex-col univer-gap-2 univer-text-sm`,children:[r.t(`sheets-pivot-ui.manualGroup.name`),/* @__PURE__ */ W(kn,{value:a,onChange:o})]}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-justify-end univer-gap-3`,children:[/* @__PURE__ */ W(V,{onClick:n,children:r.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ W(V,{variant:`primary`,disabled:!a.trim()||s,onClick:async()=>{if(a.trim()&&!l.current){l.current=!0,c(!0);try{await t(a)}catch{}finally{l.current=!1,c(!1)}}},children:r.t(`sheets-pivot-ui.dialog.ok`)})]})]})}const $o=`univer-flex univer-items-center univer-justify-between univer-gap-3 univer-text-sm`;function es({targetFieldName:e,grouping:t,defaults$:n,onConfirm:r,onCancel:i}){let a=z(L),o=B(a.direction$,a.getDirection()),s=B(n),[c,l]=Y((t==null?void 0:t.autoStart)??!0),[u,d]=Y((t==null?void 0:t.autoEnd)??!0),[f,p]=Y((t==null?void 0:t.autoStart)===!1?String(t.start):void 0),[m,h]=Y((t==null?void 0:t.autoEnd)===!1?String(t.end):void 0),[g,_]=Y(t?String(t.interval):void 0),[v,y]=Y(!1),b=J(!1),x=e=>e===void 0||!/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i.test(e.trim())?NaN:Number(e),S={autoStart:c,autoEnd:u,start:c?s==null?void 0:s.start:x(f),end:u?s==null?void 0:s.end:x(m),interval:g===void 0||g.trim()===``?(s==null?void 0:s.interval)??0:x(g)},C=!!s&&ai(S),w=e=>{!e&&f===void 0&&(s==null?void 0:s.start)!==void 0&&p(String(s.start)),l(e)},T=e=>{!e&&m===void 0&&(s==null?void 0:s.end)!==void 0&&h(String(s.end)),d(e)};return/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,dir:o,children:[/* @__PURE__ */ W(`div`,{className:`univer-text-sm univer-font-medium`,children:e}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ W(H,{checked:c,onChange:e=>w(!!e),children:a.t(`sheets-pivot-ui.numberGroup.autoStart`)}),/* @__PURE__ */ G(`label`,{className:$o,children:[a.t(`sheets-pivot-ui.numberGroup.start`),/* @__PURE__ */ W(kn,{className:`univer-w-32`,value:c?String((s==null?void 0:s.start)??``):f??``,disabled:c,onChange:p})]}),/* @__PURE__ */ W(H,{checked:u,onChange:e=>T(!!e),children:a.t(`sheets-pivot-ui.numberGroup.autoEnd`)}),/* @__PURE__ */ G(`label`,{className:$o,children:[a.t(`sheets-pivot-ui.numberGroup.end`),/* @__PURE__ */ W(kn,{className:`univer-w-32`,value:u?String((s==null?void 0:s.end)??``):m??``,disabled:u,onChange:h})]}),/* @__PURE__ */ G(`label`,{className:$o,children:[a.t(`sheets-pivot-ui.numberGroup.interval`),/* @__PURE__ */ W(kn,{className:`univer-w-32`,value:g??String((s==null?void 0:s.interval)??``),placeholder:String((s==null?void 0:s.interval)??``),onChange:_})]})]}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-justify-end univer-gap-3`,children:[/* @__PURE__ */ W(V,{onClick:i,children:a.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ W(V,{variant:`primary`,disabled:!C||v,onClick:async()=>{if(C&&!b.current){b.current=!0,y(!0);try{await r(S)}catch{}finally{b.current=!1,y(!1)}}},children:a.t(`sheets-pivot-ui.dialog.ok`)})]})]})}const ts=({handlePatternChange:e})=>{let t=z(L);return q(()=>{e(``)},[]),/* @__PURE__ */ W(`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`)})},ns=({originPattern:e,handlePatternChange:t})=>{let n=z(L),r=nt.map(e=>({label:e,value:e})),[i,a]=Y(()=>Aa(e||``,2)),[o,s]=Y(()=>Ma(e??``)||r[0].value);return q(()=>{t($(`_("${o}"* #,##0${i>0?`.0`:``}_)`,i))},[]),/* @__PURE__ */ G(`div`,{className:`univer-mt-5`,children:[/* @__PURE__ */ G(`div`,{className:`univer-flex univer-items-center univer-justify-between`,children:[/* @__PURE__ */ G(`div`,{className:`univer-w-[136px]`,children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.decimalPlaces`)}),/* @__PURE__ */ W(An,{className:`univer-box-border univer-h-8`,value:i,max:20,min:0,onChange:e=>{let n=e??0;a(n),t($(`_("${o}"* #,##0${n>0?`.0`:``}_)`,n))}})]}),/* @__PURE__ */ G(`div`,{className:`univer-w-[136px]`,children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.currencyTypes`)}),/* @__PURE__ */ W(zn,{options:r,value:o,onChange:e=>{s(e),t($(`_("${e}"* #,##0${i>0?`.0`:``}_)`,i))}})]})]}),/* @__PURE__ */ W(`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`)})]})},rs=({originPattern:e,handlePatternChange:t})=>{let n=z(L),r=nt.map(e=>({label:e,value:e})),[i,a]=Y(()=>Aa(e||``,2)),[o,s]=Y(()=>Ma(e??``)||r[0].value),c=pa.map(e=>({label:e.label(o),value:e.suffix(o),color:e.color})),[l,u]=Y(()=>{var t;return((t=c.find(t=>st(t.value,e??``)))==null?void 0:t.value)||c[0].value});return q(()=>{t($(l,i))},[]),/* @__PURE__ */ G(`div`,{className:`univer-mt-5`,children:[/* @__PURE__ */ G(`div`,{className:`univer-flex univer-items-center univer-justify-between`,children:[/* @__PURE__ */ G(`div`,{className:`univer-w-[136px]`,children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.decimalPlaces`)}),/* @__PURE__ */ W(An,{className:`univer-box-border univer-h-8`,value:i,max:20,min:0,onChange:e=>{e&&(a(e),t($(l,e)))}})]}),/* @__PURE__ */ G(`div`,{className:`univer-w-[136px]`,children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.currencyTypes`)}),/* @__PURE__ */ W(zn,{options:r,value:o,onChange:e=>{s(e);let n=pa.map(t=>({label:t.label(e),value:t.suffix(e),color:t.color}));u(n[0].value),t($(n[0].value,i))}})]})]}),/* @__PURE__ */ G(`div`,{className:`univer-mt-4`,children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.negativeNumberTypes`)}),/* @__PURE__ */ W(Bn,{className:`univer-rounded-lg univer-p-2`,options:c,value:l,onChange:e=>{u(e),t($(e,i))}}),/* @__PURE__ */ W(`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`)})]})]})},is=({originPattern:e,handlePatternChange:t})=>{let n=z(L),r=da.map(e=>({label:e.label,value:e.suffix})),[i,a]=Y(()=>{if(e){let t=r.find(t=>t.value===e);if(t)return t.value}return r[0].value});return q(()=>{t(i)},[]),/* @__PURE__ */ W(`div`,{className:`univer-mt-5`,children:/* @__PURE__ */ G(`div`,{className:`univer-mt-5`,children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.dateTypes`)}),/* @__PURE__ */ W(`div`,{children:/* @__PURE__ */ W(Bn,{className:`univer-rounded-lg univer-p-2`,options:r,value:i,onChange:e=>{a(e),t(e)}})}),/* @__PURE__ */ W(`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`)})]})})},as=({originPattern:e,handlePatternChange:t})=>{let n=z(L),[r,i]=Y(()=>Aa(e||``,0)),a=fa.map(e=>({label:e.label,value:e.suffix,color:e.color})),[o,s]=Y(()=>{let t=a.find(t=>st(t.value,e||``));return(t==null?void 0:t.value)||a[0].value});return q(()=>{t($(o,Number(r||0)))},[]),/* @__PURE__ */ G(`div`,{className:`univer-mt-5`,children:[/* @__PURE__ */ W(`div`,{className:`univer-flex univer-items-center univer-justify-between`,children:/* @__PURE__ */ G(`div`,{className:`univer-w-[136px]`,children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.decimalPlaces`)}),/* @__PURE__ */ W(An,{className:`univer-box-border univer-h-8`,value:r,max:20,min:0,onChange:e=>{e&&(i(e),t($(o,Number(e))))}})]})}),/* @__PURE__ */ G(`div`,{className:`univer-mt-4`,children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:n.t(`sheets-pivot-ui.dialog.numfmt.negativeNumberTypes`)}),/* @__PURE__ */ W(Bn,{className:`univer-rounded-lg univer-p-2`,options:a,value:o,onChange:e=>{i(Aa(e,0)),s(e),t(e)}}),/* @__PURE__ */ W(`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`)})]})]})},os=({unitId:e,subUnitId:t,pivotTableId:n,tableFieldId:r,originPattern:i,tableFieldInfo:a,dataFieldInfo:o})=>{let s=z(L),c=z(R),l=s.getDirection(),u=_r(()=>[{label:`sheets-pivot-ui.dialog.numfmt.general`,component:ts,key:`sheet.numfmt.general`},{label:`sheets-pivot-ui.dialog.numfmt.accounting`,component:ns,key:`sheet.numfmt.accounting`},{label:`sheets-pivot-ui.dialog.numfmt.currency`,component:rs,key:`sheet.numfmt.currency`},{label:`sheets-pivot-ui.dialog.numfmt.date`,component:is,key:`sheet.numfmt.date`},{label:`sheets-pivot-ui.dialog.numfmt.thousandthPercentile`,component:as,key:`sheet.numfmt.thousandthPercentile`}].map(e=>({...e,label:s.t(e.label)})),[s]),d=u.map(e=>({label:e.label,value:e.key})),[f,p]=Y(()=>[Na,Pa,Fa,La,za].reduce((e,t,n)=>e||(t(i??``)?u[n].key:``),``)||u[0].key),[m,h]=Y(i),g=e=>h(e),_=e=>{p(e)},v=i=>({id:jr,title:{title:s.t(`sheets-pivot-ui.fieldSettings`)},draggable:!0,mask:!1,maskClosable:!1,width:400,children:{label:Ar,tableFieldId:r,pivotTableId:n,unitId:e,subUnitId:t,tableFieldInfo:a,dataFieldInfo:o,key:`field-setting-${r||``}`,closeFn:()=>{c.close(jr)},format:i?m:``},onClose:()=>{c.close(jr)}}),y=()=>{c.close(Nr);let e=v(!1);c.open(e)};return/* @__PURE__ */ G(`div`,{dir:l,children:[/* @__PURE__ */ W(`div`,{className:`univer-flex`,children:/* @__PURE__ */ G(`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:y,children:[/* @__PURE__ */ W(Qn,{}),s.t(`sheets-pivot-ui.dialog.numfmt.fieldSetting`)]})}),/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-h-5 univer-text-sm univer-font-medium univer-leading-5`,children:s.t(`sheets-pivot-ui.dialog.numfmt.formatTypes`)}),/* @__PURE__ */ W(`div`,{children:/* @__PURE__ */ W(zn,{className:`univer-w-full`,value:f,options:d,onChange:e=>_(e)})}),/* @__PURE__ */ G(`div`,{children:[f===`sheet.numfmt.general`&&/* @__PURE__ */ W(ts,{originPattern:i,handlePatternChange:g}),f===`sheet.numfmt.accounting`&&/* @__PURE__ */ W(ns,{originPattern:i,handlePatternChange:g}),f===`sheet.numfmt.currency`&&/* @__PURE__ */ W(rs,{originPattern:i,handlePatternChange:g}),f===`sheet.numfmt.date`&&/* @__PURE__ */ W(is,{originPattern:i,handlePatternChange:g}),f===`sheet.numfmt.thousandthPercentile`&&/* @__PURE__ */ W(as,{originPattern:i,handlePatternChange:g})]}),/* @__PURE__ */ G(En,{className:`univer-mt-2 univer-flex univer-justify-end`,children:[/* @__PURE__ */ W(V,{onClick:y,children:s.t(`sheets-pivot-ui.dialog.numfmt.cancel`)}),/* @__PURE__ */ W(V,{className:`univer-ml-3 rtl:univer-ml-0 rtl:univer-mr-3`,variant:`primary`,onClick:()=>{c.close(Nr);let e=v(!0);c.open(e)},children:s.t(`sheets-pivot-ui.dialog.numfmt.confirm`)})]})]})};function ss(e){var t,n;let{scope:r,report:i,getCurrentReport:a,onChange:o}=e,s=z(L),c=z(Ue),l=z(be),u=z(Ge),d=z(We);B(u.permissionPointUpdate$);let[f,p]=Y(!1),m=J(!1),h=J(!0),g=JSON.stringify(r),_=J(g);_.current=g,q(()=>(h.current=!0,()=>{h.current=!1}),[]);let v=f||!i||((t=u.getPermissionPoint(new Et(r.unitId).id))==null?void 0:t.value)===!1||((n=u.getPermissionPoint(new Ot(r.unitId,r.subUnitId).id))==null?void 0:n.value)===!1,b=async e=>{if(m.current||v||!i||i.options.allowMultipleFilters===e)return;m.current=!0,p(!0);let t=$e.deepClone(i);try{if(!e&&y(i)){let e=await l.asyncInterceptor.fetchThroughAsyncInterceptors(te)({redos:[],undos:[],groups:[],validate:()=>void 0},r);if(!h.current||_.current!==g||!await c.confirm({id:`sheet-pivot.confirm.disable-multiple-filters`,title:{title:s.t(`sheets-pivot-ui.config.multipleFiltersTitle`)},children:{title:s.t(`sheets-pivot-ui.config.multipleFiltersClearWarning`)},cancelText:s.t(`sheets-pivot-ui.dialog.cancel`),confirmText:s.t(`sheets-pivot-ui.dialog.ok`)}))return;e==null||e.validate()}if(!h.current||_.current!==g||!$e.diffValue(t,a()))return;await o(e)}catch(e){d.error(`[PivotFilterOptions]`,e)}finally{m.current=!1,h.current&&p(!1)}};return/* @__PURE__ */ G(`section`,{className:`univer-flex univer-flex-col univer-gap-3`,children:[/* @__PURE__ */ W(`div`,{className:`univer-text-sm univer-font-medium univer-text-gray-600`,children:s.t(`sheets-pivot-ui.config.filteringSection`)}),/* @__PURE__ */ G(`label`,{className:`univer-flex univer-items-start univer-gap-2 univer-text-sm`,children:[/* @__PURE__ */ W(H,{checked:(i==null?void 0:i.options.allowMultipleFilters)===!0,disabled:v,onChange:e=>b(!!e)}),/* @__PURE__ */ W(`span`,{children:s.t(`sheets-pivot-ui.config.allowMultipleFilters`)})]})]})}const cs=[{label:`sheets-pivot-ui.config.pageDownThenOver`,value:`false`},{label:`sheets-pivot-ui.config.pageOverThenDown`,value:`true`}],ls=[{label:`sheets-pivot-ui.config.layoutTabular`,value:String(c.tabular)},{label:`sheets-pivot-ui.config.layoutCompact`,value:String(c.compact)},{label:`sheets-pivot-ui.config.layoutOutline`,value:String(c.outline)}],us=[{label:`sheets-pivot-ui.config.rowSubtotalTop`,value:String(d.top)},{label:`sheets-pivot-ui.config.rowSubtotalBottom`,value:String(d.bottom)}],ds=[{label:`sheets-pivot-ui.config.dateGroupingLegacy`,value:a.Legacy},{label:`sheets-pivot-ui.config.dateGroupingExcelLike`,value:a.ExcelLike}];function fs(e){let{unitId:t,subUnitId:n,pivotTableId:r}=e,i=z(P),a=z(Ue),o=z(We),s=z(L),l=z(M),u=_r(()=>l.watchPivotTableChanges(t,n,r).pipe(hn(0)),[l,t,n,r]);B(u);let[f,p]=Y(!1),m=J(!1),h=l.getPivotTableConfig(t,n,r),g=v(h==null?void 0:h.fieldsConfig.options),[_,y]=Y(()=>{var e,i;let a=l.getPivotTableConfig(t,n,r),o=(a==null||(e=a.fieldsConfig)==null?void 0:e.options)??{};return{showRowSubtotal:o.showRowSubtotal??!0,showRowGrandTotal:o.showRowGrandTotal??!0,showColSubtotal:o.showColSubtotal??!0,showColGrandTotal:o.showColGrandTotal??!0,pageWrap:o.pageWrap??1,pageOverThenDown:o.pageOverThenDown??!1,repeatRowLabels:o.repeatRowLabels??!1,repeatColLabels:o.repeatColLabels??!1,layout:(a==null||(i=a.fieldsConfig)==null?void 0:i.layout)??c.tabular,rowSubtotalPosition:o.rowSubtotalPosition??d.top}}),x=e=>{let a={unitId:t,subUnitId:n,pivotTableId:r,options:e};i.executeCommand(ge.id,a).catch(e=>o.error(`[PivotConfigPanel]`,e)),y(t=>({...t,...e}))},S=e=>{let a={unitId:t,subUnitId:n,pivotTableId:r,layout:e};i.executeCommand(pe.id,a).catch(e=>o.error(`[PivotConfigPanel]`,e)),y(t=>({...t,layout:e}))},C=async e=>{if(!(m.current||e===g)){m.current=!0,p(!0);try{let o=l.getPivotTableConfig(t,n,r),c=l.getCollection(t,r);if(!o||!c||(Object.values(c.fields).some(b)||c.customFields.some(b))&&!await a.confirm({id:`sheet-pivot.confirm.change-date-grouping-mode`,title:{title:s.t(`sheets-pivot-ui.config.dateGroupingSwitchTitle`)},children:{title:s.t(`sheets-pivot-ui.config.dateGroupingSwitchMessage`)},cancelText:s.t(`sheets-pivot-ui.dialog.cancel`),confirmText:s.t(`sheets-pivot-ui.dialog.ok`)})||l.getPivotTableConfig(t,n,r)!==o||l.getCollection(t,r)!==c||v(o.fieldsConfig.options)===e)return;await i.executeCommand(ge.id,{unitId:t,subUnitId:n,pivotTableId:r,options:{dateGroupingMode:e}})}catch(e){o.error(`[PivotConfigPanel]`,e)}finally{m.current=!1,p(!1)}}};return/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-4 univer-py-4`,children:[/* @__PURE__ */ W(ss,{scope:{unitId:t,subUnitId:n,pivotTableId:r},report:h==null?void 0:h.fieldsConfig,getCurrentReport:()=>{var e;return(e=l.getPivotTableConfig(t,n,r))==null?void 0:e.fieldsConfig},onChange:e=>i.executeCommand(ge.id,{unitId:t,subUnitId:n,pivotTableId:r,options:{allowMultipleFilters:e}})}),/* @__PURE__ */ G(`section`,{children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-600`,children:s.t(`sheets-pivot-ui.config.displaySection`)}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ G(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-2`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-sm univer-text-gray-600`,children:s.t(`sheets-pivot-ui.config.dateGroupingMode`)}),/* @__PURE__ */ W(zn,{className:`univer-w-36`,value:g,options:ds.map(e=>({...e,label:s.t(e.label)})),disabled:f,onChange:e=>C(e)})]}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-2`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-sm univer-text-gray-600`,children:s.t(`sheets-pivot-ui.config.layout`)}),/* @__PURE__ */ W(zn,{className:`univer-w-36`,value:String(_.layout),options:ls.map(e=>({...e,label:s.t(e.label)})),onChange:e=>S(Number(e))})]}),/* @__PURE__ */ G(`label`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-text-sm univer-text-gray-600`,children:[/* @__PURE__ */ W(H,{checked:_.repeatRowLabels,disabled:_.layout===c.compact,onChange:e=>x({repeatRowLabels:!!e})}),s.t(`sheets-pivot-ui.config.repeatRowLabels`)]}),/* @__PURE__ */ G(`label`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-text-sm univer-text-gray-600`,children:[/* @__PURE__ */ W(H,{checked:_.repeatColLabels,onChange:e=>x({repeatColLabels:!!e})}),s.t(`sheets-pivot-ui.config.repeatColLabels`)]})]})]}),/* @__PURE__ */ G(`section`,{children:[/* @__PURE__ */ W(`div`,{className:U(`univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-600`),children:s.t(`sheets-pivot-ui.config.totalsSection`)}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ G(`label`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-text-sm univer-text-gray-600`,children:[/* @__PURE__ */ W(H,{checked:_.showRowSubtotal,onChange:e=>x({showRowSubtotal:!!e})}),s.t(`sheets-pivot-ui.config.showRowSubtotal`)]}),_.layout===c.outline&&/* @__PURE__ */ G(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-2`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-sm univer-text-gray-600`,children:s.t(`sheets-pivot-ui.config.rowSubtotalPosition`)}),/* @__PURE__ */ W(zn,{className:`univer-w-36`,value:String(_.rowSubtotalPosition),options:us.map(e=>({...e,label:s.t(e.label)})),onChange:e=>x({rowSubtotalPosition:Number(e)})})]}),/* @__PURE__ */ G(`label`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-text-sm univer-text-gray-600`,children:[/* @__PURE__ */ W(H,{checked:_.showRowGrandTotal,onChange:e=>x({showRowGrandTotal:!!e})}),s.t(`sheets-pivot-ui.config.showRowGrandTotal`)]}),/* @__PURE__ */ G(`label`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-text-sm univer-text-gray-600`,children:[/* @__PURE__ */ W(H,{checked:_.showColSubtotal,onChange:e=>x({showColSubtotal:!!e})}),s.t(`sheets-pivot-ui.config.showColSubtotal`)]}),/* @__PURE__ */ G(`label`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-text-sm univer-text-gray-600`,children:[/* @__PURE__ */ W(H,{checked:_.showColGrandTotal,onChange:e=>x({showColGrandTotal:!!e})}),s.t(`sheets-pivot-ui.config.showColGrandTotal`)]})]})]}),/* @__PURE__ */ G(`section`,{children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-600`,children:s.t(`sheets-pivot-ui.config.pageSection`)}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-3`,children:[/* @__PURE__ */ G(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-2`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-sm univer-text-gray-600`,children:s.t(`sheets-pivot-ui.config.pageWrap`)}),/* @__PURE__ */ W(An,{className:`univer-w-24`,value:_.pageWrap,min:1,max:20,onChange:e=>{let t=Number(e);Number.isFinite(t)&&t>=1&&x({pageWrap:t})}})]}),/* @__PURE__ */ W(`p`,{className:`univer-text-xs univer-text-gray-600`,children:s.t(_.pageOverThenDown?`sheets-pivot-ui.config.pageWrapOverThenDownHelp`:`sheets-pivot-ui.config.pageWrapDownThenOverHelp`)}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-gap-2`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-sm univer-text-gray-600`,children:s.t(`sheets-pivot-ui.config.pageDirection`)}),/* @__PURE__ */ W(zn,{className:`univer-w-36`,value:String(_.pageOverThenDown),options:cs.map(e=>({...e,label:s.t(e.label)})),onChange:e=>x({pageOverThenDown:e===`true`})})]})]})]})]})}let ps=class extends N{constructor(e,t,n,r,i,a,o,s){super(),this._sheetsSelectionsService=e,this._univerInstanceService=t,this._sheetsPivotTableAdaptorModel=n,this._commandService=r,this._sidebarService=i,this._dialogService=a,this._injector=o,this._permissionService=s,X(this,`_pivotTableId`,void 0),X(this,`_pivotTablePanelVisible$`,new fn),X(this,`pivotTablePanelVisible$`,this._pivotTablePanelVisible$.asObservable()),X(this,`_isRangeSelectorFocus`,!1),X(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(Dr))}_initPanelOpen(){let e=this._univerInstanceService.getCurrentUnitOfType(et.UNIVER_SHEET);if(e){let t=e.activeSheet$;this.disposeWithMe(yn(t,this._sheetsSelectionsService.selectionMoveEnd$).subscribe(()=>{let e=this._sheetsSelectionsService.getCurrentSelections();if(!e)return;let t=e[e.length-1];if(!t)return;let n=t.primary;if(!n)return;let r=this._univerInstanceService.getCurrentUnitOfType(et.UNIVER_SHEET),i=r==null?void 0:r.getActiveSheet();if(!r||!i)return;let a=r.getUnitId(),o=i.getSheetId(),s=this._sheetsPivotTableAdaptorModel.getPivotTableIdByCell(a,o,n.startRow,n.startColumn);if(s){var c,l;let e=(c=this._sheetsPivotTableAdaptorModel.getPivotItemRenderInfoCache(a,o,s))==null?void 0:c.rangesInfo,t=Fe(e),n=jt(this._injector,a,o,t),r=(l=this._permissionService.getPermissionPoint(new kt(a,o).id))==null?void 0:l.value;if(!n||!r)return;this._setPivotTableId(s),this._pivotTablePanelVisible$.next(!0),this._commandService.executeCommand(ra.id,{pivotTableId:s})}else this._closePivotPanel()})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{e.id===ae.id&&e.params.pivotTableId===this._pivotTableId&&this._sidebarService.close(Dr)}))}}_initSheetChange(){let e=this._univerInstanceService.getCurrentUnitOfType(et.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(jr)}})),this.disposeWithMe(this._dialogService.getDialogs$().subscribe(e=>{let t=e.find(e=>e.id===zr);t&&t.open===!1&&this._dialogService.close(zr)}))}};ps=Q([Z(0,I(wt)),Z(1,I(F)),Z(2,I(j)),Z(3,I(P)),Z(4,I(Bt)),Z(5,I(R)),Z(6,I(Ke)),Z(7,I(Ge))],ps);const ms=hr(null),hs=hr(null);function gs(e,t){return e===t?!0:!e||!t?!1:e.droppableId===t.droppableId&&e.index===t.index}function _s(e){if(!(e instanceof Element))return null;let t=e.closest(`[data-univer-dnd-droppable-id]`);return t instanceof HTMLElement?t:null}function vs(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 ys(){let e=gr(ms);if(!e)throw Error(`Draggable/Droppable must be used inside DragDropContext`);return e}function bs(e){let{children:t,onDragEnd:n,onDragStart:r,onDragUpdate:i}=e,[a,o]=Y(null),s=J(null),c=K((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=K(e=>{let t=s.current;if(!t||gs(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=K(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]);q(()=>{if(!a)return;let e=e=>{let t=_s(e.target);t&&t.dataset.univerDndDropDisabled!==`true`||l(null)};return window.addEventListener(`dragover`,e,!0),()=>{window.removeEventListener(`dragover`,e,!0)}},[a,l]);let d=_r(()=>({activeDrag:a,startDrag:c,updateDestination:l,endDrag:u}),[a,c,l,u]);return/* @__PURE__ */ W(ms.Provider,{value:d,children:t})}function xs(e){var t;let{children:n,droppableId:r,isDropDisabled:i=!1}=e,{activeDrag:a,updateDestination:o,endDrag:s}=ys(),c=J(null),l={innerRef:K(e=>{c.current=e},[]),droppableProps:{onDragOver:K(e=>{if(!a||i||!c.current)return;e.preventDefault();let t=vs(c.current,e.clientY,a,r);o({droppableId:r,index:t})},[a,i,r,o]),onDrop:K(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:vs(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__ */ W(hs.Provider,{value:r,children:n(l,u)})}function Ss(e){var t;let{children:n,draggableId:r,index:i,isDragDisabled:a=!1}=e,{activeDrag:o,startDrag:s,updateDestination:c,endDrag:l}=ys(),u=gr(hs),d=J(null),f=J(null),p=J(!1),m=J(null),h=J(null),g=J(!1),_=J(null),v=J(null),y=J(null),b=K(e=>{d.current=e},[]),x=(o==null?void 0:o.draggableId)===r,S=K(()=>{h.current&&=(window.clearTimeout(h.current),null)},[]),C=K(()=>{S(),y.current=null,m.current&&=(m.current(),null),_.current&&=(_.current.remove(),null),v.current=null,p.current=!1},[S]);q(()=>C,[C]);let w=K((e,t)=>{if(_.current)return;let n=d.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),_.current=s,v.current={x:i,y:a}},[]),T=K((e,t)=>{let n=_.current,r=v.current;n&&r&&(n.style.transform=`translate(${Math.max(0,e-r.x)}px, ${Math.max(0,t-r.y)}px)`)},[]),E=K((e,t)=>{let n=_s(document.elementFromPoint(e,t));if(!n||n.dataset.univerDndDropDisabled===`true`)return null;let a=n.dataset.univerDndDroppableId;return a?{droppableId:a,index:vs(n,t,{draggableId:r,source:{droppableId:u??``,index:i},destination:null},a)}:null},[r,u,i]),D=K((e,t,n,o)=>{if(p.current||g.current||a||!u)return;p.current=!0,S(),g.current=!1;try{var l;(l=d.current)==null||l.setPointerCapture(t)}catch{}w(n,o),s(r,{droppableId:u,index:i});let f=E(n,o);c(f);try{e.preventDefault()}catch{}},[S,r,u,i,a,w,E,s,c]),O=K(e=>{if(a||!u||e.pointerType===`mouse`&&e.button!==0)return;g.current=!1;let t=e.pointerId;y.current={pointerId:t,pointerType:e.pointerType,startX:e.clientX,startY:e.clientY},S(),e.pointerType!==`mouse`&&(h.current=window.setTimeout(()=>{let n=y.current;n&&n.pointerId===t&&D(e.nativeEvent,n.pointerId,n.startX,n.startY)},150));let n=e=>{let t=y.current;if(!t||e.pointerId!==t.pointerId)return;if(!p.current){if(g.current){C();return}if(t.pointerType===`mouse`){let n=e.clientX-t.startX,r=e.clientY-t.startY;n*n+r*r>=16&&D(e,t.pointerId,e.clientX,e.clientY)}return}T(e.clientX,e.clientY);let n=E(e.clientX,e.clientY);c(n);try{e.preventDefault()}catch{}},r=e=>{let t=y.current;if(!t||e.pointerId!==t.pointerId)return;let n=p.current?E(e.clientX,e.clientY):null,r=p.current?l(n?`DROP`:`CANCEL`,n):Promise.resolve();return C(),r};window.addEventListener(`pointermove`,n,{capture:!0,passive:!1}),window.addEventListener(`pointerup`,r,{capture:!0}),window.addEventListener(`pointercancel`,r,{capture:!0}),m.current=()=>{window.removeEventListener(`pointermove`,n,!0),window.removeEventListener(`pointerup`,r,!0),window.removeEventListener(`pointercancel`,r,!0)}},[C,S,u,l,a,E,D,c,T]),ee=K(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),f.current&&f.current!==i&&f.current.remove(),f.current=i},[]),te=K(e=>{if(p.current||a||!u){e.preventDefault();return}g.current=!0,S(),y.current=null,m.current&&=(m.current(),null);let t=e.dataTransfer;if(t){try{t.effectAllowed=`move`}catch{}try{t.setData(`text/plain`,r)}catch{}}try{ee(e)}catch{}s(r,{droppableId:u,index:i})},[ee,S,r,u,i,a,s]),k=K(()=>(f.current&&=(f.current.remove(),null),l(`CANCEL`,null)),[l]);return n({innerRef:b,draggableProps:{draggable:!a,onDragStart:te,onDragEnd:k,style:x?{opacity:1}:void 0,"data-univer-dnd-item":`true`,"data-univer-dnd-id":r,"data-univer-dnd-index":String(i)},dragHandleProps:{onPointerDown:O}},{isDragging:x,draggingOver:o==null||(t=o.destination)==null?void 0:t.droppableId})}function Cs(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 ws(e){switch(e){case`filter`:return/* @__PURE__ */ W(ir,{className:`univer-flex univer-flex-row univer-gap-4`});case`row`:return/* @__PURE__ */ W(nr,{className:`univer-flex univer-flex-row univer-gap-4`});case`column`:return/* @__PURE__ */ W(dr,{className:`univer-flex univer-flex-row univer-gap-4`});case`value`:return/* @__PURE__ */ W(ar,{className:`univer-flex univer-flex-row univer-gap-4`})}}function Ts(e){switch(e){case`filter`:return/* @__PURE__ */ G(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`32`,height:`32`,viewBox:`0 0 32 32`,fill:`none`,children:[/* @__PURE__ */ W(`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__ */ W(`rect`,{x:`21.9404`,y:`17.8544`,width:`7.59766`,height:`2.2793`,rx:`1.13965`,fill:`#274FEE`}),/* @__PURE__ */ W(`rect`,{x:`21.9404`,y:`21.9067`,width:`7.59766`,height:`2.2793`,rx:`1.13965`,fill:`#274FEE`}),/* @__PURE__ */ W(`rect`,{x:`21.9404`,y:`25.959`,width:`7.59766`,height:`2.2793`,rx:`1.13965`,fill:`#274FEE`})]});case`row`:return/* @__PURE__ */ G(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`32`,height:`32`,viewBox:`0 0 32 32`,fill:`none`,children:[/* @__PURE__ */ W(`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__ */ W(`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__ */ W(`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__ */ W(`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__ */ G(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`32`,height:`32`,viewBox:`0 0 32 32`,fill:`none`,children:[/* @__PURE__ */ W(`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__ */ W(`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__ */ W(`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__ */ W(`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__ */ G(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`32`,height:`32`,viewBox:`0 0 32 32`,fill:`none`,children:[/* @__PURE__ */ W(`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__ */ W(`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__ */ W(`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__ */ W(`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 Es(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 Ds(e){let t=z(L),{areaType:n}=e,r=Es(n,t),i=Ts(n);return/* @__PURE__ */ G(`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__ */ W(`div`,{className:`univer-size-8`,children:i}),/* @__PURE__ */ W(`div`,{className:`univer-text-center univer-text-xs univer-leading-4 univer-text-gray-600 dark:!univer-text-gray-200`,children:r})]})}function Os(e){let{areaType:t,items:n,positionInfo:r,pivotTableId:i,pivotTableInfo:a}=e,o=z(L);return/* @__PURE__ */ G(`div`,{className:`univer-min-h-[200px] univer-flex-1 univer-p-1`,children:[/* @__PURE__ */ G(`div`,{className:`univer-mb-2 univer-mt-0 univer-flex univer-w-full univer-text-sm univer-leading-4 univer-text-gray-900`,children:[ws(t),/* @__PURE__ */ W(`span`,{className:`univer-inline-block univer-align-top`,children:Cs(t,o)})]}),/* @__PURE__ */ W(xs,{droppableId:`${t}`,isCombineEnabled:!1,isDropDisabled:!1,ignoreContainerClipping:!1,direction:`vertical`,children:(e,o)=>/* @__PURE__ */ W(`div`,{className:U(`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`,Un,{"univer-border-primary-600":o.isDraggingOver}),children:/* @__PURE__ */ W(`div`,{className:U(`univer-h-full univer-overflow-y-auto`,Wn),children:/* @__PURE__ */ G(`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__ */ W(`div`,{children:/* @__PURE__ */ W(Ss,{isDragDisabled:!1,draggableId:e.tableFieldId,index:n,children:(n,o)=>/* @__PURE__ */ W(mr,{children:/* @__PURE__ */ W(`div`,{ref:n.innerRef,...n.draggableProps,...n.dragHandleProps,style:n.draggableProps.style,className:U(`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`,o.draggingOver&&`univer-border-primary-600`),children:/* @__PURE__ */ W(ks,{pivotTableId:i,positionInfo:r,item:e,areaType:t,pivotTableInfo:a})})})},e.tableFieldId)},e.tableFieldId)),n.length===0&&/* @__PURE__ */ W(Ds,{areaType:t})]})})})})]})}function ks(e){let{areaType:t,item:n,positionInfo:r,pivotTableId:i,pivotTableInfo:a}=e,{unitId:o,subUnitId:s}=r,c=n.tableFieldId===ma,l=z(P),u=z(L),d=()=>{if(c){let e=(a.valueFields||[]).map(e=>e.tableFieldId);wa({pivotTableId:i,unitId:o,subUnitId:s,commandService:l},e)}else wa({pivotTableId:i,unitId:o,subUnitId:s,commandService:l},[n.tableFieldId])},f=()=>{o&&s&&Da(l,o,s,i,n.tableFieldId)},p=()=>{o&&s&&Oa(l,i,n.tableFieldId,o,s,a)},h=e=>{let t=e===`column`?m.Row:m.Column,n=e===`column`?a.rowFields.length:a.columnFields.length;Ta({pivotTableId:i,unitId:o,subUnitId:s,commandService:l},t,n)},g=/* @__PURE__ */ G(`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__ */ W(`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:()=>{d()},children:u.t(`sheets-pivot-ui.removeField`)}),t!==`value`&&!c&&/* @__PURE__ */ W(`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:()=>{f()},children:u.t(`sheets-pivot-ui.filterField`)}),c&&/* @__PURE__ */ W(`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:()=>{h(t)},children:t===`column`?u.t(`sheets-pivot-ui.moveToRow`):u.t(`sheets-pivot-ui.moveToColumn`)}),t===`value`&&/* @__PURE__ */ W(`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:()=>{p()},children:u.t(`sheets-pivot-ui.fieldSettings`)})]}),_=c?u.t(`sheets-pivot-ui.multipleValue`):n.displayName,v=/* @__PURE__ */ W(`bdi`,{dir:`auto`,children:_});return/* @__PURE__ */ G(mr,{children:[/* @__PURE__ */ W(or,{}),/* @__PURE__ */ W(`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__ */ W(Hn,{title:v,children:v})}),/* @__PURE__ */ W(`div`,{className:`univer-cursor-pointer`,children:/* @__PURE__ */ W(On,{align:`end`,overlay:g,children:/* @__PURE__ */ W(`span`,{children:/* @__PURE__ */ W(cr,{})})})})]})}function As(e){var t;let n=z(F),r=z(L),i=z(P),a=z(ps),{sourceRangeInfo:o,refreshHandler:s,pivotTableId:c,positionInfo:l}=e,{unitId:u,range:d,subUnitId:f}=o,p=n.getUnit(u),m=(p==null||(t=p.getSheetBySheetId(f))==null?void 0:t.getName())??``,[h,g]=Y(void 0),_=J(h);_.current=h;let[v,y]=Y(d),[b,x]=Y(m),[S,C]=Y(!1);q(()=>{a.setIsRangeSelectorFocus(S)},[S,a]),q(()=>{y(o.range),x(m)},[o,m]);let w=_r(()=>rt(async e=>{let t=e.split(`,`).filter(e=>!!e).map(vr);if(!t[0])return;let n=t[0];if(!p||_.current)return;let r=n.sheetName||o.sheetName;y(n.range),x(r);let a={unitId:u,subUnitId:p.getSheetBySheetName(r).getSheetId(),range:{...n.range},sheetName:r};await xa(i,c,a,l.unitId,l.subUnitId),s()},300,{leading:!1,maxWait:1e3,trailing:!0}),[]);return/* @__PURE__ */ G(`div`,{className:`univer-mb-4`,children:[/* @__PURE__ */ G(`div`,{className:`univer-mb-2 univer-flex univer-h-5 univer-justify-between univer-text-sm univer-leading-5`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-justify univer-text-gray-900 dark:!univer-text-gray-0`,children:r.t(`sheets-pivot-ui.sourceRangeLabel`)}),/* @__PURE__ */ W(`span`,{className:`univer-text-xs univer-text-gray-600 dark:!univer-text-gray-200`,children:r.t(`sheets-pivot-ui.sourceRangePlaceholder`)})]}),/* @__PURE__ */ G(`div`,{className:`univer-relative`,children:[/* @__PURE__ */ W(Sr,{unitId:u,subUnitId:f,initialValue:br(b,v),onChange:(e,t)=>{br(b,v)!==t&&w(t)},keepSheetReference:!0,supportAcrossSheet:!0,onVerify:(e,t)=>{let n=t.split(`,`).filter(e=>!!e);if(!n[0]){g(r.t(`sheets-pivot-ui.msg.emptySourceRange`));return}if(!e){g(r.t(`sheets-pivot-ui.msg.invalidSize`));return}let i=vr(n[0]),a=i.sheetName||o.sheetName;if(p)switch(ya(p.getSheetBySheetName(a),i.range)){case 2:g(void 0);break;case 0:g(r.t(`sheets-pivot-ui.msg.emptySourceRange`));break;case 1:g(r.t(`sheets-pivot-ui.msg.invalidSize`))}},maxRangeCount:1,onFocusChange:e=>{C(e)},onRangeSelectorDialogVisibleChange:e=>{C(!!e)}}),h?/* @__PURE__ */ W(`div`,{className:`univer-my-1 univer-text-xs univer-text-red-500`,children:h}):null]})]})}function js(e){let{type:t}=e;switch(t){case n.text:return/* @__PURE__ */ W(pr,{className:`univer-mx-1.5 univer-my-0 univer-h-4 univer-text-xs univer-text-gray-200 dark:!univer-text-gray-600`});case n.number:return/* @__PURE__ */ W(lr,{className:`univer-mx-1.5 univer-my-0 univer-h-4 univer-text-xs univer-text-gray-200 dark:!univer-text-gray-600`});case n.date:return/* @__PURE__ */ W(er,{className:`univer-mx-1.5 univer-my-0 univer-h-4 univer-text-xs univer-text-gray-200 dark:!univer-text-gray-600`})}}function Ms(e){if(!e)return!1;if(e.type===s.RecordFilter){var t;return e.dateRange!==void 0||(((t=e.selection)==null?void 0:t.mode)??Ve.All)!==Ve.All}return e.type!==s.ManualFilter||e.isAll!==!0}function Ns(e){let{name:t,dataFieldId:r,checked:i,type:a,refreshHandler:o,pivotTableId:s,draggingId:c,pivotTableInfo:l,unitId:u,subUnitId:d}=e,[f,m]=Y(!1),h=z(P),g=z(L);if(!l)return null;let{rowFields:_,columnFields:v,filterFields:y,valueFields:b}=l,x=l.hiddenFields??[],S=[..._,...v,...y,...b,...x],C=x.find(e=>e.dataFieldId===r),w=async e=>{let t=!!e,i=!1;if(t){let e={pivotTableId:s,dataFieldId:r,fieldArea:a===n.number?p.Value:p.Row,unitId:u,subUnitId:d,index:a===n.number?b.length:_.length};i=await h.executeCommand(T.id,e)}else{let e=[];S.forEach(t=>{t.dataFieldId===r&&e.push(t.tableFieldId)}),i=await h.executeCommand(re.id,{pivotTableId:s,fieldIds:e,unitId:u,subUnitId:d})}i&&o()},E=async e=>{let t=!1,n=``;if([..._,...v,...y,...x].forEach(e=>{e.dataFieldId===r&&(t=!0,n=e.tableFieldId)}),t&&e!==p.Value){if(s){let t=Ba(l,e),r={pivotTableId:s,area:e,index:t,fieldId:n,unitId:u,subUnitId:d};await h.executeCommand(O.id,r)&&o()}}else if(s){let t={pivotTableId:s,dataFieldId:r,fieldArea:e,unitId:u,subUnitId:d,index:Ba(l,e)};await h.executeCommand(T.id,t)&&o()}};return/* @__PURE__ */ G(`div`,{className:U(`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":c===r}),id:`source-${r}`,onContextMenu:e=>{e.preventDefault(),m(!0)},children:[/* @__PURE__ */ W(`span`,{className:`univer-mr-2 univer-w-4 rtl:univer-ml-2 rtl:univer-mr-0`,children:/* @__PURE__ */ W(or,{})}),/* @__PURE__ */ W(H,{className:`univer-w-[14px] univer-text-sm univer-text-gray-200`,checked:i,onChange:w}),/* @__PURE__ */ G(`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__ */ W(js,{type:a}),/* @__PURE__ */ W(`span`,{className:`univer-truncate`,children:t})]}),/* @__PURE__ */ W(On,{align:`end`,side:`bottom`,open:f,onOpenChange:m,overlay:/* @__PURE__ */ G(`div`,{children:[Ms(C==null?void 0:C.filterInfo)&&/* @__PURE__ */ W(`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()=>{C&&(m(!1),await h.executeCommand(fe.id,{unitId:u,subUnitId:d,pivotTableId:s,tableFieldId:C.tableFieldId,items:[],partialItems:[],isAll:!0})&&o())},children:g.t(`sheets-pivot-ui.dialog.filter.clearFilter`)}),/* @__PURE__ */ W(`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:()=>{m(!1),E(p.Row)},children:g.t(`sheets-pivot-ui.addToRow`)}),/* @__PURE__ */ W(`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:()=>{m(!1),E(p.Column)},children:g.t(`sheets-pivot-ui.addToColumn`)}),/* @__PURE__ */ W(`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:()=>{m(!1),E(p.Value)},children:g.t(`sheets-pivot-ui.addToValue`)}),/* @__PURE__ */ W(`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:()=>{m(!1),E(p.Filter)},children:g.t(`sheets-pivot-ui.addToFilter`)})]}),children:/* @__PURE__ */ W(`div`,{className:U(`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":f,"univer-opacity-0 group-hover:univer-opacity-100":!f}),onMouseDown:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),children:/* @__PURE__ */ W(sr,{className:`univer-text-gray-400 dark:!univer-text-gray-500`})})})]},r)}function Ps(e){let{sourceList:t,refreshHandler:n,pivotTableId:r,pivotTableInfo:i,unitId:a,draggingId:o,subUnitId:s}=e,c=z(L),[l,u]=Y(``),d=l.trim().toLocaleLowerCase(),f=d?t.filter(e=>e.name.toLocaleLowerCase().includes(d)):t;return/* @__PURE__ */ G(`div`,{className:`univer-mb-4 univer-flex univer-min-h-0 univer-flex-1 univer-flex-col`,children:[/* @__PURE__ */ W(`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:c.t(`sheets-pivot-ui.sourceFieldTile`)}),/* @__PURE__ */ W(`p`,{className:`univer-mb-2 univer-mt-0 univer-text-xs univer-leading-4 univer-text-gray-600 dark:!univer-text-gray-200`,children:c.t(`sheets-pivot-ui.sourceFieldDescription`)}),/* @__PURE__ */ W(kn,{allowClear:!0,className:`univer-mb-2`,placeholder:c.t(`sheets-pivot-ui.searchFieldPlaceholder`),slot:/* @__PURE__ */ W(fr,{}),value:l,onChange:u}),/* @__PURE__ */ W(`div`,{className:U(`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`,Un),children:/* @__PURE__ */ W(`div`,{className:U(`univer-relative univer-h-full univer-overflow-y-auto`,Wn),"data-testid":`pivot-source-field-viewport`,children:/* @__PURE__ */ W(xs,{droppableId:`source`,direction:`vertical`,isCombineEnabled:!1,ignoreContainerClipping:!1,isDropDisabled:!0,children:e=>/* @__PURE__ */ G(`div`,{ref:e.innerRef,className:`univer-box-border univer-h-full univer-px-2`,...e.droppableProps,children:[f.map((e,t)=>/* @__PURE__ */ W(`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__ */ W(Ss,{draggableId:e.id,isDragDisabled:!1,index:t,children:({innerRef:t,draggableProps:c,dragHandleProps:l})=>/* @__PURE__ */ W(`div`,{ref:t,...c,...l,className:`univer-h-8 univer-w-full`,style:c.style,children:/* @__PURE__ */ W(Ns,{draggingId:o,unitId:a,subUnitId:s,...e,refreshHandler:n,pivotTableId:r,pivotTableInfo:i})})},e.id)},e.id)),f.length===0&&/* @__PURE__ */ W(`div`,{className:`univer-py-4 univer-text-center univer-text-xs univer-text-gray-500`,children:c.t(`sheets-pivot-ui.noMatchingFields`)})]})})})})]})}function Fs(e){let{pivotTableId:t,version:n,unitId:r,subUnitId:i,panelInfo:a}=e,o=z(M),s=_r(()=>o.watchPivotTableChanges(r,i,t).pipe(hn(0)),[o,r,i,t]),c=B(s),l=z(ye),u=z(ps),d=B(u.pivotTablePanelVisible$,!0),f=z(P),p=z(We),[m,h]=Y(a),[g,_]=Y(null),v=K(async()=>{if(!o.getPivotTableConfig(r,i,t))return;let e=await l.getPivotDisplayConfig({unitId:r,subUnitId:i,pivotTableId:t,params:{type:k.Panel,panel:{pivotTableId:t}}});e.result.panel&&h(e.result.panel)},[t,l,o,i,r]);q(()=>{v().catch(e=>p.error(`[PivotPanel]`,e))},[p,c,t,v,n]);let y=async e=>{let{source:n,destination:a,draggableId:o}=e;_(null);let s={pivotTableInfo:m,pivotTableId:t,commandService:f,unitId:r,subUnitId:i},c=n.droppableId;if(a&&a.droppableId){let e=a.droppableId;await Ca(s,o,c,e,a.index),await v()}a===null&&(await ba(s,o,c),await v())},b=e=>{_({draggingId:e.draggableId})},x=e=>{let{draggableId:t,destination:n,source:r}=e;_({draggingId:t,destination:n,source:r})};if(!d||!m)return null;let{sourceList:S,rowFields:C,columnFields:w,filterFields:T,valueFields:E,sourceRange:D,positionInfo:O}=m;return/* @__PURE__ */ G(`div`,{className:U(`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`,Wn),children:[/* @__PURE__ */ W(As,{sourceRangeInfo:D,pivotTableId:t,refreshHandler:v,positionInfo:O}),/* @__PURE__ */ G(bs,{onDragEnd:y,onDragStart:b,onDragUpdate:x,children:[/* @__PURE__ */ W(Ps,{draggingId:(g==null?void 0:g.draggingId)??``,sourceList:S,refreshHandler:v,pivotTableId:t,pivotTableInfo:m,unitId:r,subUnitId:i}),/* @__PURE__ */ W(Is,{rowFields:C,columnFields:w,filterFields:T,valueFields:E,refreshHandler:v,positionInfo:O,pivotTableId:t,pivotTableInfo:m})]})]})}function Is(e){let{rowFields:t,columnFields:n,filterFields:r,valueFields:i,refreshHandler:a,pivotTableInfo:o,positionInfo:s,pivotTableId:c}=e;return/* @__PURE__ */ G(`div`,{className:`univer-shrink-0`,"data-testid":`pivot-field-areas`,children:[/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-row univer-gap-4`,children:[/* @__PURE__ */ W(Os,{areaType:`filter`,items:r,positionInfo:s,pivotTableId:c,pivotTableInfo:o,refreshHandler:a}),/* @__PURE__ */ W(Os,{areaType:`column`,items:n,positionInfo:s,pivotTableId:c,pivotTableInfo:o,refreshHandler:a})]}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-row univer-gap-4`,children:[/* @__PURE__ */ W(Os,{areaType:`row`,items:t,positionInfo:s,pivotTableId:c,pivotTableInfo:o,refreshHandler:a}),/* @__PURE__ */ W(Os,{areaType:`value`,items:i,positionInfo:s,pivotTableId:c,pivotTableInfo:o,refreshHandler:a})]})]})}function Ls(e){let{className:t,unitId:n,subUnitId:r,pivotTableId:i}=e,[a,o]=Y(0),s=z(L),c=s.getDirection();return/* @__PURE__ */ G(`div`,{className:U(`univer-flex univer-size-full univer-min-h-0 univer-flex-col`,t),dir:c,children:[/* @__PURE__ */ W(Rn,{className:`univer-my-3 univer-w-full univer-shrink-0`,items:[{label:s.t(`sheets-pivot-ui.fieldPanel`),value:0},{label:s.t(`sheets-pivot-ui.configPanel`),value:1}],value:a,onChange:o}),/* @__PURE__ */ W(`div`,{className:U(`univer-min-h-0 univer-flex-1`,a===0?`univer-overflow-hidden`:`univer-overflow-auto`),children:a===0?/* @__PURE__ */ W(Fs,{...e}):/* @__PURE__ */ W(fs,{unitId:n,subUnitId:r,pivotTableId:i})})]})}function Rs(e){let{unitId:t,subUnitId:n,pivotTableId:r,tableFieldId:i,type:a}=e,o=JSON.stringify([t,n,r,i,a]);return/* @__PURE__ */ W(zs,{...e},o)}function zs({unitId:e,subUnitId:t,pivotTableId:r,tableFieldId:i,type:a,baseItems:o,onConfirm:s,onCancel:c}){var u;let d=z(M),f=z(L),p=B(f.direction$,f.getDirection()),m=li.find(e=>e.type===a),h=d.getPivotTableConfig(e,t,r),g=h==null||(u=h.fieldsConfig.measure[i])==null?void 0:u.showDataAs,_=()=>{var e;if((g==null?void 0:g.type)!==a||!g.baseFieldId)return``;if(g.baseItemType===l.previous)return`relative:previous`;if(g.baseItemType===l.next)return`relative:next`;let t=((e=o[g.baseFieldId])==null?void 0:e.items.indexOf(g.baseItem))??-1;return t<0?``:`item:${t}`},[v,y]=Y((g==null?void 0:g.type)===a?g.baseFieldId:``),[b,x]=Y(_),S=J(!1),[C,w]=Y(!1),T=d.getPivotTableConfig(e,t,r),E=d.getCollection(e,r),D=T==null?void 0:T.fieldsConfig.measure[i],O=!!(D&&E&&(E.fields[D.dataFieldId]||E.customFields.find(e=>e.id===D.dataFieldId))),ee=(T&&E&&m?di(T,E,m):[]).filter(e=>{let t=o[e];return(m==null?void 0:m.baseItemMode)===`none`||!!(t&&((m==null?void 0:m.baseItemMode)===`item-or-relative`||t.items.length>0))}),te=ee.map(e=>({label:T.fieldsConfig.dimension[e].displayName,value:e})),k=T==null?void 0:T.fieldsConfig.dimension[v],ne=k&&E&&(E.fields[k.dataFieldId]??E.customFields.find(e=>e.id===k.dataFieldId)),A=o[v],re=(A==null?void 0:A.items.map((e,t)=>{var r;let i=A.itemTypes[t],a=(r=A.itemLabels)==null?void 0:r[e],o=ha(e,i),s=e;return o?s=f.t(o):a===void 0?i===n.other?s=f.t(`sheets-pivot-ui.showValuesAs.other`):(i===n.date||i===n.number)&&A.format&&(s=ut.format(A.format,Number(e))):s=a,{label:s,value:`item:${t}`,itemKey:e}}))??[];(m==null?void 0:m.baseItemMode)===`item-or-relative`&&re.push({label:f.t(`sheets-pivot-ui.showValuesAs.previous`),value:`relative:previous`,itemKey:``,itemType:l.previous},{label:f.t(`sheets-pivot-ui.showValuesAs.next`),value:`relative:next`,itemKey:``,itemType:l.next});let ie=re.find(e=>e.value===b),ae=!!(m!=null&&m.baseItemMode&&m.baseItemMode!==`none`),oe=!!(m&&T&&E&&O&&T.fieldsConfig.valueFields.includes(i)&&ee.includes(v)&&ne&&(!ae||ie));return/* @__PURE__ */ G(`div`,{dir:p,children:[/* @__PURE__ */ G(`div`,{className:`univer-mb-4`,children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:f.t(`sheets-pivot-ui.showValuesAs.baseField`)}),/* @__PURE__ */ W(zn,{className:`univer-w-full`,value:v,options:te,onChange:e=>{y(e),x(``)}})]}),ae&&/* @__PURE__ */ G(`div`,{className:`univer-mb-4`,children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-text-sm univer-font-medium`,children:f.t(`sheets-pivot-ui.showValuesAs.baseItem`)}),/* @__PURE__ */ W(zn,{className:`univer-w-full`,value:b,options:re,disabled:!v,onChange:x})]}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-justify-end univer-gap-3`,children:[/* @__PURE__ */ W(V,{onClick:c,children:f.t(`sheets-pivot-ui.showValuesAs.cancel`)}),/* @__PURE__ */ W(V,{variant:`primary`,disabled:!oe||C,onClick:async()=>{let n=d.getPivotTableConfig(e,t,r),o=d.getCollection(e,r),c=n==null?void 0:n.fieldsConfig.measure[i];if(!m||!n||!o||!c||S.current||!n.fieldsConfig.valueFields.includes(i)||!(o.fields[c.dataFieldId]||o.customFields.find(e=>e.id===c.dataFieldId))||!di(n,o,m).includes(v)||ae&&!ie)return;let l={type:a,baseFieldId:v,baseItem:(ie==null?void 0:ie.itemKey)??``};(ie==null?void 0:ie.itemType)!==void 0&&(l.baseItemType=ie.itemType),S.current=!0,w(!0);try{await s(l)}catch{}finally{S.current=!1,w(!1)}},children:f.t(`sheets-pivot-ui.showValuesAs.ok`)})]})]})}const Bs=e=>{let[t,n]=Y(!1),r=z(ps);return q(()=>{r.setIsRangeSelector2Focus(t)},[t,r]),/* @__PURE__ */ W(Sr,{...e,onFocusChange:t=>{var r;(r=e.onFocusChange)==null||r.call(e,t),n(t)}})},Vs=(e,t,n,r,i,a)=>/* @__PURE__ */ W(Bs,{unitId:e,subUnitId:t,initialValue:r,onChange:(e,t)=>n(t),maxRangeCount:1,supportAcrossSheet:!0,keepSheetReference:!0}),Hs=(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 Us(e){let{unitId:t,sourceRange:n,positionRange:r,sourceSheetName:i,positionSheetName:a,onConfirm:o,onCancel:s}=e,c=z(L),l=z(F),u=c.getDirection(),d=l.getUnit(t),f=_r(()=>d.getActiveSheet().getSheetId(),[d]),[p,m]=Y(n),[h,g]=Y(r),[_,v]=Y(i),[y,b]=Y(a),x=J(void 0),[S,C]=Y(),[w,T]=Y(A.New),[E,D]=Y(!0),[O,ee]=Y(!0),[te,k]=Y(void 0);q(()=>{let e=ya(d.getSheetBySheetName(_),p);ee(e===2),k(Hs(e,c))},[p,_,d,c]);let ne=e=>{if(br(_,p)===e)return;let t=e.split(`,`).filter(e=>!!e).map(vr);if(Array.isArray(t)&&t.length>0){let{range:e,sheetName:n}=t[0];m(e),v(n)}t[0]||k(c.t(`sheets-pivot-ui.msg.emptySourceRange`))},re=Vs(t,f,e=>{if(h&&br(y,h)===e)return;let t=e.split(`,`).filter(e=>!!e).map(vr);if(t.length===0){g(null);return}let n=t[0];g(n.range),b(n.sheetName||i),n.sheetName===i&&Ze.intersects(n.range,p)?D(!1):D(!0)},h?br(y,h):``,!1,S),ie=()=>!!(p&&h&&_&&y&&w===A.Existing&&E&&O)||!!(p&&_&&w===A.New&&O);return q(()=>{C(x.current)},[]),/* @__PURE__ */ G(`div`,{ref:x,dir:u,children:[/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-h-5 univer-text-sm univer-font-medium`,children:c.t(`sheets-pivot-ui.dialog.source.sourceData`)}),Vs(t,f,ne,br(_,p),!0,S),te&&/* @__PURE__ */ W(`div`,{className:`univer-mt-2 univer-h-5 univer-text-xs univer-text-red-400`,children:te}),/* @__PURE__ */ W(`div`,{className:`univer-mb-2 univer-mt-5 univer-h-5 univer-text-sm univer-font-medium`,children:c.t(`sheets-pivot-ui.dialog.source.position`)}),/* @__PURE__ */ G(Ln,{value:w,onChange:e=>T(e),className:`univer-flex univer-flex-col univer-gap-2`,children:[/* @__PURE__ */ W(In,{value:A.New,children:c.t(`sheets-pivot-ui.dialog.source.newSheet`)}),/* @__PURE__ */ W(In,{value:A.Existing,children:c.t(`sheets-pivot-ui.dialog.source.existingSheet`)})]}),w===A.Existing&&/* @__PURE__ */ G(mr,{children:[re,!E&&/* @__PURE__ */ W(`span`,{className:`univer-h-5 univer-text-sm univer-text-red-400`,children:c.t(`sheets-pivot-ui.dialog.source.intersect`)})]}),/* @__PURE__ */ W(`footer`,{className:`univer-mt-5`,children:/* @__PURE__ */ G(En,{className:`univer-flex univer-justify-end univer-gap-2`,children:[/* @__PURE__ */ W(V,{onClick:()=>s(),children:c.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ W(V,{variant:`primary`,onClick:()=>{ie()&&(w===A.Existing?o({sourceRange:p,sourceSheetName:_,positionRange:h,positionSheetName:y,positionType:w}):o({sourceRange:p,sourceSheetName:_,positionType:w}))},children:c.t(`sheets-pivot-ui.dialog.ok`)})]})})]})}Us.componentKey=zr;const Ws=[{id:`equal`,localeKey:`sheets-pivot-ui.valueFilter.equal`,operator:h.valueEqual},{id:`notEqual`,localeKey:`sheets-pivot-ui.valueFilter.notEqual`,operator:h.valueNotEqual},{id:`greaterThan`,localeKey:`sheets-pivot-ui.valueFilter.greaterThan`,operator:h.valueGreaterThan},{id:`greaterThanOrEqual`,localeKey:`sheets-pivot-ui.valueFilter.greaterThanOrEqual`,operator:h.valueGreaterThanOrEqual},{id:`lessThan`,localeKey:`sheets-pivot-ui.valueFilter.lessThan`,operator:h.valueLessThan},{id:`lessThanOrEqual`,localeKey:`sheets-pivot-ui.valueFilter.lessThanOrEqual`,operator:h.valueLessThanOrEqual},{id:`between`,localeKey:`sheets-pivot-ui.valueFilter.between`,operator:h.valueBetween,isBetween:!0},{id:`notBetween`,localeKey:`sheets-pivot-ui.valueFilter.notBetween`,operator:h.valueNotBetween,isBetween:!0},{id:`topCount`,localeKey:`sheets-pivot-ui.valueFilter.topCount`,operator:h.count,isCount:!0},{id:`bottomCount`,localeKey:`sheets-pivot-ui.valueFilter.bottomCount`,operator:h.count,isBottom:!0,isCount:!0},{id:`topPercent`,localeKey:`sheets-pivot-ui.valueFilter.topPercent`,operator:h.percent,isPercent:!0},{id:`bottomPercent`,localeKey:`sheets-pivot-ui.valueFilter.bottomPercent`,operator:h.percent,isBottom:!0,isPercent:!0}];function Gs({targetFieldId:e,targetFieldName:t,valueFields:n,defaultValueFieldId:r,currentFilter:i,onConfirm:a,onClear:o,onCancel:s}){function c(e){var t;return(e==null?void 0:e.operator)===h.count?e.isBottom?`bottomCount`:`topCount`:(e==null?void 0:e.operator)===h.percent?e.isBottom?`bottomPercent`:`topPercent`:((t=Ws.find(t=>t.operator===(e==null?void 0:e.operator)))==null?void 0:t.id)??`greaterThan`}let l=z(L),u=B(l.direction$,l.getDirection()),d=i==null?void 0:i.expected,[f,p]=Y(()=>{let e=i==null?void 0:i.valueFieldId;return e&&n.some(t=>t.id===e)?e:r&&n.some(e=>e.id===r)?r:n.length===1?n[0].id:``}),[m,g]=Y(()=>c(i)),[_,v]=Y(()=>String(Array.isArray(d)?d[0]:d??0)),[y,b]=Y(()=>String(Array.isArray(d)?d[1]:0)),x=J(!1),[S,C]=Y(!1),w=Ws.find(e=>e.id===m),T=_.trim()!==``&&Number.isFinite(Number(_)),E=!w.isBetween||y.trim()!==``&&Number.isFinite(Number(y)),D=!w.isCount||Number.isInteger(Number(_))&&Number(_)>=1,O=!w.isPercent||Number(_)>=0&&Number(_)<=100,ee=!!(n.some(e=>e.id===f)&&T&&E&&D&&O),te=async e=>{if(!x.current){x.current=!0,C(!0);try{await e()}catch{}finally{x.current=!1,C(!1)}}},k=()=>te(async()=>{if(!ee)return;let e={operator:w.operator,expected:w.isBetween?[Number(_),Number(y)]:Number(_),valueFieldId:f};w.isBottom&&(e.isBottom=!0),await a(e)}),ne=()=>te(o);return/* @__PURE__ */ G(`div`,{className:`univer-flex univer-flex-col univer-gap-4`,"data-target-field-id":e,dir:u,children:[/* @__PURE__ */ W(`div`,{className:`univer-text-sm univer-font-medium`,children:/* @__PURE__ */ W(`bdi`,{dir:`auto`,children:t})}),/* @__PURE__ */ G(`label`,{className:`univer-flex univer-flex-col univer-gap-2 univer-text-sm`,children:[l.t(`sheets-pivot-ui.valueFilter.valueField`),/* @__PURE__ */ W(zn,{"aria-label":l.t(`sheets-pivot-ui.valueFilter.valueField`),"data-testid":`pivot-value-filter-value-field`,value:f,options:[{value:``,label:l.t(`sheets-pivot-ui.valueFilter.selectValueField`)},...n.map(e=>({value:e.id,label:e.label}))],onChange:p})]}),/* @__PURE__ */ G(`label`,{className:`univer-flex univer-flex-col univer-gap-2 univer-text-sm`,children:[l.t(`sheets-pivot-ui.valueFilter.condition`),/* @__PURE__ */ W(zn,{"aria-label":l.t(`sheets-pivot-ui.valueFilter.condition`),"data-testid":`pivot-value-filter-rule`,value:m,options:Ws.map(e=>({value:e.id,label:l.t(e.localeKey)})),onChange:e=>g(e)})]}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-gap-2`,children:[/* @__PURE__ */ W(kn,{"aria-label":l.t(`sheets-pivot-ui.valueFilter.condition`),"aria-invalid":!T||!D||!O,className:`univer-min-w-0 univer-flex-1`,"data-testid":`pivot-value-filter-expected`,inputMode:`decimal`,value:_,onChange:v}),w.isBetween&&/* @__PURE__ */ W(kn,{"aria-label":l.t(`sheets-pivot-ui.valueFilter.condition`),"aria-invalid":!E,className:`univer-min-w-0 univer-flex-1`,"data-testid":`pivot-value-filter-expected`,inputMode:`decimal`,value:y,onChange:b})]}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-justify-between univer-gap-3`,children:[/* @__PURE__ */ W(V,{"data-testid":`pivot-value-filter-clear`,disabled:S,onClick:ne,children:l.t(`sheets-pivot-ui.valueFilter.clear`)}),/* @__PURE__ */ G(`div`,{className:`univer-flex univer-gap-3`,children:[/* @__PURE__ */ W(V,{disabled:S,onClick:s,children:l.t(`sheets-pivot-ui.valueFilter.cancel`)}),/* @__PURE__ */ W(V,{"data-testid":`pivot-value-filter-confirm`,variant:`primary`,disabled:!ee||S,onClick:k,children:l.t(`sheets-pivot-ui.valueFilter.ok`)})]})]})]})}function Ks(e){let{pivotTableId:t,tableFieldId:n,closeFn:r,unitId:i,subUnitId:a,format:o,tableFieldInfo:s,dataFieldInfo:c,version:l}=e,[u,d]=Y(s.displayName),[f,p]=Y(s.subTotalType),m=z(L),h=z(P),g=z(R),_={...z(M).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`])_[e]=m.t(e);if(q(()=>{d(s.displayName),p(s.subTotalType)},[l]),!s||!c)return;let v=c.name,y=m.getDirection(),b=o??s.format,x=ka.map(e=>({value:`${e.type}`,type:e.type,label:m.t(e.textKey)})),S=e=>{let t=e;if(Array.isArray(e)&&(t=e[0]),t!==void 0){let e=Number(t);p(e),Va(v,u,_)&&d(Ha(v,_,e))}};return/* @__PURE__ */ G(`div`,{dir:y,children:[/* @__PURE__ */ G(`div`,{className:`univer-flex univer-items-center univer-justify-between univer-self-stretch univer-leading-5`,children:[/* @__PURE__ */ W(`span`,{className:`univer-text-sm univer-font-medium univer-leading-5 univer-text-gray-900`,children:m.t(`sheets-pivot-ui.dialog.fieldName`)}),/* @__PURE__ */ W(`span`,{className:`univer-text-xs univer-leading-4 univer-text-gray-600`,children:ga(m.t(`sheets-pivot-ui.dialog.sourceName`),v)})]}),/* @__PURE__ */ W(`div`,{children:/* @__PURE__ */ W(kn,{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:u,onChange:e=>d(e)})}),/* @__PURE__ */ W(`label`,{className:`univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-gray-0`,children:m.t(`sheets-pivot-ui.dialog.summarizeBy`)}),/* @__PURE__ */ W(`div`,{className:U(`univer-h-40 univer-flex-1 univer-overflow-y-auto univer-rounded-lg`,Un,Wn),children:x.map(e=>/* @__PURE__ */ G(`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:()=>S(e.value),children:[/* @__PURE__ */ W(`span`,{className:`univer-w-4 univer-text-base univer-text-primary-600`,children:/* @__PURE__ */ W(tr,{className:U({"univer-hidden":f!==e.type})})}),/* @__PURE__ */ W(`span`,{children:e.label})]},e.type))}),/* @__PURE__ */ W(`footer`,{className:`univer-mt-5`,children:/* @__PURE__ */ G(En,{className:`univer-flex univer-items-center univer-justify-between univer-self-stretch`,children:[/* @__PURE__ */ W(V,{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:jr,draggable:!0,mask:!1,maskClosable:!1,width:400,children:{label:Mr,unitId:i,subUnitId:a,pivotTableId:t,tableFieldId:n,originPattern:b,tableFieldInfo:s,dataFieldInfo:c},dialogStyles:{header:{padding:`20px 24px 0`,height:0},body:{padding:`0 24px 20px`}},closable:!1,onClose:()=>{g.close(jr)}};g.open(e)},children:m.t(`sheets-pivot-ui.dialog.format`)}),/* @__PURE__ */ G(En,{className:`univer-flex univer-flex-1 univer-gap-2 univer-text-sm rtl:univer-flex-row-reverse`,children:[/* @__PURE__ */ W(V,{onClick:()=>{r&&r()},children:m.t(`sheets-pivot-ui.dialog.cancel`)}),/* @__PURE__ */ W(V,{variant:`primary`,disabled:u===``,onClick:()=>{let e=s.displayName,o=s.subTotalType,l=s.format,d=e===u?void 0:u,p=o===f?void 0:f,m=l===b?void 0:b;if(e!==u||o!==f||l!==m){let e={displayName:d,subtotalType:p,format:m,tableFieldId:n,pivotTableId:t,unitId:i,subUnitId:a,tableFieldInfo:s,dataFieldInfo:c};h.executeCommand(Se.id,e)}r&&r()},children:m.t(`sheets-pivot-ui.dialog.ok`)})]})]})})]})}let qs=class extends N{constructor(e,t){super(),this._componentManager=e,this._iconManager=t,this._registerComponents(),this._registerIcons()}_registerComponents(){[[zr,Us],[Er,Ls],[Or,Zo],[Ar,Ks],[Mr,os],[Pr,Rs],[Fr,Gs],[Ir,Wo],[Lr,es],[Rr,Qo]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_registerIcons(){this.disposeWithMe(this._iconManager.register({PivotTableIcon:ur}))}};qs=Q([Z(0,I(Ft)),Z(1,I(Vt))],qs);let Js=class extends N{constructor(e){super(),this._menuManagerService=e,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(Zi)}};Js=Q([Z(0,Rt)],Js);let Ys=class extends N{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,X(this,`_pivotButtonShapesArr`,[]),this._initButtonRender(),this._initSkeleton(),this._initListener(),this._initBlockedPivotAlert()}_initBlockedPivotAlert(){let e=`SHEET_PIVOT_BLOCKED:${this._context.unitId}`;this.disposeWithMe(yn(this._selectionsService.selectionChanged$,this._context.unit.activeSheet$,this._sheetsPivotTableAdaptorModel.viewUpdate$).pipe(pn(0)).subscribe(()=>{var t,n,r;let{unitId:i,unit:a}=this._context,o=this._selectionsService.currentSelectionParam,s=(t=a.getActiveSheet())==null?void 0:t.getSheetId(),c=(n=this._selectionsService.getCurrentSelections())==null||(n=n.slice(-1)[0])==null?void 0:n.primary;if(!s||!c||(o==null?void 0:o.unitId)!==i||o.sheetId!==s){this._cellAlerts.removeAlert(e);return}let{actualRow:l,actualColumn:u}=c,d=this._sheetsPivotTableAdaptorModel,f=d.getPivotTableIdByCell(i,s,l,u),p=f&&((r=d.getPivotItemRenderInfoCache(i,s,f))==null?void 0:r.blockedRange);if(!p){this._cellAlerts.removeAlert(e);return}let m=`sheets-pivot-ui.perform.blocked`;p.reason===`pivot`?m=`sheets-pivot-ui.perform.blockedByPivot`:p.reason===`merge`&&(m=`sheets-pivot-ui.perform.blockedByMerge`),this._cellAlerts.showAlert({key:e,type:qt.ERROR,title:this._localeService.t(`sheets-pivot-ui.perform.tips`),message:this._localeService.t(m,yr(p)),location:{unitId:i,subUnitId:s,row:l,col:u},width:260,height:96})})),this.disposeWithMe(()=>this._cellAlerts.removeAlert(e))}_initButtonRender(){this.disposeWithMe(yn(this._sheetsPivotTableAdaptorModel.viewUpdate$.pipe(pn(0)),this._sheetSkeletonManagerService.currentSkeleton$,this._sheetsPivotTableConfigModel.pivotConfigChange$,this._permissionService.permissionPointUpdate$.pipe(pn(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(),i=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!i)return;let a=this._pivotButtonShapesArr;a.forEach(e=>e.dispose()),a.splice(0,a.length),this._sheetsPivotTableAdaptorModel.getSubUnitPivotMatrix(e,t).forValue((o,s,c)=>{if(c!=null&&c.pbt){let l=`sheets-pivot-button-${o}-${s}-${e}-${t}`,{startX:u,startY:d,endX:f,endY:p}=on(o,s,n,i),m=f-u,h=p-d;if(h<8||m<8||this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[Et],worksheetTypes:[At,Dt,kt],rangeTypes:[yt,vt]},[{startRow:o,endRow:o,startColumn:s,endColumn:s}],e,t)===!1)return;let g;if(Eo.has(c.pbt)){let{left:n,top:i}=Ao(r,`filter`,{startX:u,startY:d,endX:f,endY:p});g={left:n,top:i,height:16,width:16,zIndex:5e3,cellWidth:m,cellHeight:h,pivotParams:{col:s,row:o,unitId:e,subUnitId:t,buttonType:c.pbt}}}else if(Do.has(c.pbt)){let{left:n,top:i}=Ao(r,`collapse`,{startX:u,startY:d,endX:f,endY:p});g={left:n,top:i,height:16,width:16,zIndex:5e3,cellWidth:m,cellHeight:h,pivotParams:{col:s,row:o,unitId:e,subUnitId:t,buttonType:c.pbt}}}else return;let _=this._injector.createInstance(Oo,l,g);a.push(_)}}),a.length&&n.addObjects(a),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 Be,{spreadsheet:t}=un(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 n=this._context.scene,{row:r,column:i}=sn(e.offsetX,e.offsetY,n,t);this._commandService.executeCommand(ne.id,{row:r,col:i})}))}};Ys=Q([Z(1,I(Ke)),Z(2,I(j)),Z(3,I(tn)),Z(4,I(M)),Z(5,I(P)),Z(6,I(Ct)),Z(7,I(Ge)),Z(8,I(L)),Z(9,I(wt)),Z(10,I(Kt))],Ys);var Xs=class e extends Yn{constructor(e){super(`SHEET_PIVOT_MOVE_KEY`),X(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 Zs=class extends N{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,X(this,`_pivotSelectionMoveShape`,void 0),X(this,`_scenePointerMoveSubscribe`,void 0),X(this,`_scenePointerUpSubscribe`,void 0),X(this,`_selectionControl`,void 0),X(this,`_moveStartRange`,void 0),X(this,`_moveStartCellIndex`,void 0),X(this,`_moveRowOrCol`,`row`),X(this,`_targetRange`,void 0),X(this,`_movePivotId`,void 0),this._initControl()}_controlMoving(e,t){let n=this._context.scene,r=n.getScrollXYInfoByViewport(Zn.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 u;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:d}=i;this._targetRange={startColumn:c,endColumn:c,startRow:e,endRow:t},(u=this._pivotSelectionMoveShape)==null||u.transformByState({left:a,top:l,width:20,height:d-l})}}_controlPointerDownHandler(e){var t,n,r;(t=this._selectionControl)==null||t.setControlExtensionDisable(!1),this._context.scene.setCursor(Kn.DEFAULT);let i=this._sheetsSelectionsService.getCurrentSelections();if(!i.length||i.length>1)return;let a=i[0].range,o=this._context.unit,s=o.getActiveSheet(),c=o.getUnitId(),l=s.getSheetId(),u=this._sheetsPivotTableAdaptorModel.getSubUnitPivotRenderCache(c,l);if(!(u!=null&&u.size))return;let d=Array.from(u).find(([e,t])=>{let{rangesInfo:n}=t;if(!n)return!1;let{rowRanges:r,colRanges:i}=n,o=r[0],s=i[0],c=!1;return o&&(c=Ze.realContain(o,a),this._moveRowOrCol=`row`),!c&&s&&(c=Ze.realContain(s,a),this._moveRowOrCol=`col`),c});if(!d)return;this._movePivotId=d[0],this._pivotSelectionMoveShape||(this._pivotSelectionMoveShape=new Xs(this._moveRowOrCol),this._context.scene.addObject(this._pivotSelectionMoveShape));let f=this._context.scene,p=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!p)return;let{offsetX:m,offsetY:h}=e,g=f.getCoordRelativeToViewport(Zn.FromArray([m,h])),{x:_,y:v}=g,y=f.getScrollXYInfoByViewport(g),{scaleX:b,scaleY:x}=f.getAncestorScale(),{row:S,column:C}=p.getCellIndexByOffset(_,v,b,x,y),w=(n=this._selectionControl)==null?void 0:n.model.getRange();if(this._moveStartRange=w,!w)return;let T=0;T=S<w.startRow?w.startRow:S>w.endRow?w.endRow:S;let E=0;E=C<w.startColumn?w.startColumn:C>w.endColumn?w.endColumn:C,this._moveStartCellIndex={row:T,column:E},(r=this._selectionControl)==null||r.setControlExtensionDisable(!0),this._scenePointerMoveSubscribe=f.onPointerMove$.subscribeEvent(e=>{let{offsetX:t,offsetY:n}=e,{x:r,y:i}=f.getCoordRelativeToViewport(Zn.FromArray([t,n]));this._controlMoving(r,i),f.setCursor(Kn.MOVE)}),this._scenePointerUpSubscribe=f.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,f.setCursor(Kn.DEFAULT),f.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(),n=this._context.unit.getActiveSheet().getSheetId();if(this._moveRowOrCol===`row`){var i;let o=(i=this._sheetsPivotTableAdaptorModel.getSubUnitPivotRenderCache(e,n))==null?void 0:i.get(this._movePivotId);if(!o)return;let s=this._sheetsPivotTableAdaptorModel.getSubUnitPivotMatrix(e,n);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.Subtotal&&a!==t.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(_e.id,{unitId:e,subUnitId:n,pivotTableId:this._movePivotId,tableFieldId:l,info:{type:r.custom,customOrder:h}})}else{var o;let i=(o=this._sheetsPivotTableAdaptorModel.getSubUnitPivotRenderCache(e,n))==null?void 0:o.get(this._movePivotId);if(!i)return;let a=this._sheetsPivotTableAdaptorModel.getSubUnitPivotMatrix(e,n);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 n=u==null||(s=u.colHeaderMap)==null?void 0:s[e];if(!n)continue;l=n.tableFieldId;let r=d==null?void 0:d.colRanges,o=r==null?void 0:r[0];if(!o)continue;let f={...o,startRow:e,endRow:e};for(let n=f.startColumn;n<=f.endColumn;n++){let r=a.getValue(e,n);if(!r)continue;let{v:o,pbt:s}=r;if(o&&s!==t.Subtotal&&s!==t.GrandTotal){if(typeof o==`string`){let e=i.projection?Ae(i.projection,n):n;c[e]=o}else if(typeof o==`number`){let e=i.projection?Ae(i.projection,n):n;c[e]=o.toString()}}}break}if(!l)return;let f=i.projection?je(i.projection,this._moveStartRange):this._moveStartRange,p=i.projection?je(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(_e.id,{unitId:e,subUnitId:n,pivotTableId:this._movePivotId,tableFieldId:l,info:{type:r.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()}};Zs=Q([Z(1,I(j)),Z(2,I(tn)),Z(3,I(P)),Z(4,Xt),Z(5,I(wt))],Zs);let Qs=class extends Je{constructor(e=aa,t,n,r,i){super(),this._config=e,this._injector=t,this._commandService=n,this._renderManagerService=r,this._configService=i;let{menu:a,...o}=lt({},aa,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(ia,o),this._initRegisterCommand()}onStarting(){this._injector.add([qs]),this._injector.get(qs),[[Js],[zo],[Po],[ps],[Ro],[Io],[Lo],[la],[Mo]].forEach(e=>this._injector.add(e)),this._injector.get(la)}onReady(){this._registerRenderModules(),this._injector.get(Js)}onRendered(){this._injector.get(Po),this._injector.get(ps),this._injector.get(Ro),this._injector.get(Io),this._injector.get(Lo),this._injector.get(Mo)}onSteady(){this._injector.get(zo)}_registerRenderModules(){[[Ys],[Zs]].forEach(e=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(et.UNIVER_SHEET,e))})}_initRegisterCommand(){[ra,Hr,ea,ta,Wr,Jr,ni,ri,ii,ci,ui,yi].forEach(e=>this._commandService.registerCommand(e))}};X(Qs,`pluginName`,`${se}_UI_PLUGIN`),X(Qs,`packageName`,Qi),X(Qs,`version`,$i),X(Qs,`type`,et.UNIVER_SHEET),Qs=Q([ze(Gn,Xn,Tt,xe,an),Z(1,I(Ke)),Z(2,I(P)),Z(3,qn),Z(4,He)],Qs);export{bs as DragDropContext,Ss as Draggable,xs as Droppable,Hr as OpenPivotTableRangeSelectorPanelOperation,ss as PivotFilterOptions,Zo as PivotFilterPanel,Zi as SheetsPivotTableUIMenuSchema,Bo as UniverSheetsPivotTableMobileUIPlugin,Qs as UniverSheetsPivotTableUIPlugin};