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