/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{substitute as e}from"../../../intl/substitute.js";import{css as t}from"../css.js";import{isCreateFeaturesWorkflow as o,isSplitFeatureWorkflow as i,isMergeFeaturesWorkflow as n,isUpdateFeaturesWorkflow as s,isBatchAttributeFormViewModel as a,isUpdateFeatureWorkflow as l}from"../workflowUtils.js";import{loadFooterActionsComponents as r,FooterActions as c}from"./FooterActions.js";import u from"./MergeFeaturesList.js";import{loadNoticesComponents as m,Notices as p}from"./Notices.js";import{loadPanelContentComponents as d,PanelContentSection as f,PanelContentSectionGroup as g,PanelContent as w}from"./PanelContent.js";import k from"./PendingFeatureList.js";import{loadCalciteComponents as b}from"../../support/componentsUtils.js";import{Heading as v,incrementHeadingLevel as h}from"../../support/Heading.js";import{tsx as F,tsxFragment as y}from"../../support/widget.js";import{classes as A}from"../../support/widgetUtils.js";const j=()=>Promise.all([b({"action-bar":()=>import("@esri/calcite-components/dist/components/calcite-action-bar"),action:()=>import("@esri/calcite-components/dist/components/calcite-action")}),r(),m(),d()]);function C(e){const{editorViewModel:l,headingLevel:r,messages:m,renderAttachments:d,renderFeatureForm:b,renderBatchAttributeForm:A,renderSketchToolbar:j}=e,{activeFeatureCount:C,activeLeafWorkflow:S,activeWorkflow:T,formViewModel:B}=l;if(!S||!T||!B)return null;const V=a(B),z=o(S)&&!S.data.selectedPendingFeature||i(S)&&!S.activeFeature,I=n(S),x=S.shouldShowAttachments&&!V&&!B.activeRelationshipInput&&!B.activeAssociationInput,D=V?B.activeForm.inputs:B.inputs,W=o(S)&&D.every(e=>!e.visible)&&!x,H=null!=l.featureFormViewModel?.activeAssociationInput,P=!z&&!W&&!H,U=W||o(S)&&!x&&!P&&!H,E=s(S)?A:b,N=W?F(f,null,F(k,{headingLevel:r,key:"pending-feature-list",workflow:S})):F(y,null,F(p,{activeFeatureCount:C,messages:m,workflow:T}),I?F(f,{class:t.mergeFeaturesListSection,key:"panel-section-merge"},F(u,{headingLevel:r,key:"merge-features-list",workflow:S})):void 0,F(f,{key:"panel-content-section-main"},F(g,null,z?F(k,{headingLevel:r,key:"pending-feature-list",workflow:S}):E(),x?F("div",{key:"attachments"},F(v,{level:h(r)},m.attachments),d()):null)));return F(y,null,P?M(S,e):void 0,U?j?.():void 0,F(w,{key:"attribute-panel-content"},N),F(c,{buttons:L(e)}))}function M(e,o){const i=[],n="3d"===o.editorViewModel.view?.type,{visibleElements:a}=o,r="s";if(a.zoomToButton&&o.editorViewModel.canZoomTo&&i.push(F("calcite-action",{alignment:"center",icon:"zoom-to-object",key:"zoom-to-button",onclick:()=>o.editorViewModel.zoomTo(),scale:r,text:o.messages.zoomTo,title:o.messages.zoomTo})),a.splitButton&&l(e)&&e.editorItem.supportsSplitFeatureWorkflow&&!n&&o.onSplit){const{onSplit:e,messages:t}=o;i.push(F("calcite-action",{icon:"split-geometry",key:"split-button",onclick:e,scale:r,text:t.split,title:t.split}))}if(a.mergeButton&&s(e)&&e.supportsMergeFeaturesWorkflow&&!n&&o.onMerge){const{onMerge:e,messages:t}=o;i.push(F("calcite-action",{icon:"merge",key:"merge-button",onclick:e,scale:r,text:t.mergeFeatures,title:t.mergeFeatures}))}return i.length>0?F("calcite-action-bar",{class:A(t.sketchContainer,t.updateActionBar),"data-testid":"update-feature-panel-action-bar",expandDisabled:!0,layout:"horizontal",scale:r},i):void 0}function L({editorViewModel:t,messages:o,messagesCommon:i,onDelete:n,onDeleteAssociation:s,onSave:a}){const{activeFeatureCount:l,activeLeafWorkflow:r,syncing:c}=t;if(!r)return[];const{page:u}=t;if("viewing-associated-features"===u||"viewing-associated-layers"===u)return[{appearance:"outline",onClick:()=>{const{featureFormViewModel:e}=t;null!=e?.associationId&&(e.associationId=null)},disabled:c,label:i.cancel,type:"button"}];const m=[],p=l>1?o.multiFeature:o.singleFeature,d=!r.allowSave||c,f=e(p[r.saveActionLabel],{count:l});m.push({appearance:"solid",onClick:a,disabled:d,label:f,type:"button"});const g={appearance:"outline",disabled:c,kind:"danger",label:e(p.delete,{count:l}),type:"button"};return t.shouldShowDeleteButton&&!t.featureFormHasAssociation&&n&&m.push({...g,onClick:n}),t.featureFormHasAssociation&&!t.shouldShowDeleteButton&&s&&m.push({...g,onClick:s,label:o.deleteAssociationTitle}),t.featureFormHasAssociation&&t.shouldShowDeleteButton&&s&&n&&m.push({...g,primaryLabel:i.delete,primaryText:i.delete,onClick:n,dropdownItems:[{onClick:s,label:o.deleteAssociationTitle}],type:"split-button"}),m}export{C as UpdateFeaturePanelContent,j as loadUpdateFeaturePanelContentComponents};
