/*!
Copyright (c) 2026 Lenovo SSG BASD. All rights reserved.
@license Proprietary

This software is the confidential and proprietary property of Lenovo SSG BASD.
You shall not disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement.

--- Build Info ---
Version: 1.1.1
Build Time: 2026/2/26 17:21:00
Build Commit: 81e556ed827e2f043668506dae6fae8dbb9ef395
*/
import{ref as e,computed as t,onMounted as a,onUnmounted as l,watch as n,openBlock as s,createElementBlock as u,normalizeClass as o,renderSlot as r,Fragment as c,renderList as i,createElementVNode as d,toDisplayString as p,unref as v,withModifiers as m,createCommentVNode as y,createBlock as g,resolveDynamicComponent as f,withCtx as h}from"vue";import{useForm as k}from"../../node_modules/@tanstack/vue-form/dist/esm/useForm.js";import{useLocale as b}from"../../hooks/useLocale.js";import './Form2.css';import './Form.css';import './styles/form.css';/* empty css                *//* empty css         *//* empty css         */import V from"../../_virtual/_plugin-vue_export-helper.js";const K=["title"],T={class:"gsc-form-control w-full text-left"},x={key:0,class:"gsc-date-range-picker"},R=["placeholder","value","onClick"],C={class:"gsc-date-picker-content"},j={class:"gsc-date-range-picker-panel"},F={class:"gsc-date-range-picker-panel-header"},I=["value","onInput"],E={class:"gsc-date-range-picker-separator"},L={class:"gsc-date-range-picker-panel"},$={class:"gsc-date-range-picker-panel-header"},_=["value","onInput"],w={class:"gsc-date-range-picker-footer"},A=["onClick"],O=["onClick"],N=["value","onChange"],D={value:""},S=["value"],B=["placeholder","value","rows","onInput"],q=["step","placeholder","value","onInput"],z={key:3},G=["name","value","checked","onChange"],H={class:"ml-2"},J={key:4},M=["value","checked","onChange"],P={class:"ml-2"},Q={key:1,class:"inline-flex items-center"},U=["checked","onChange"],W={class:"ml-2"},X=["placeholder","value","onInput"],Y={class:"gsc-form-actions-unified",style:{gridColumn:"1 / -1",display:"flex",justifyContent:"flex-end",gap:"8px"}},Z=/* @__PURE__ */V({__name:"Form",props:{schema:{type:Array,default:()=>[]},modelValue:{type:Object,default:()=>({})},showActions:{type:Boolean,default:!0}},emits:["update:modelValue","submit","reset","change"],setup(V,{expose:Z,emit:ee}){const te=V,ae=ee,{t:le}=b(),ne=e({}),se=e({});function ue(e){return e&&e.length?e.padStart(2,"0"):"00"}function oe(e,t){const{date:a,time:l}=function(e){if(!e)return{date:"",time:""};if(e.includes("T")){const[t,a]=e.split("T");return{date:t,time:a}}if(e.includes(" ")){const[t,a]=e.split(" ");return{date:t,time:a}}return{date:e,time:""}}(e);return a?`${a}${t}${function(e){const t=(e||"").split(":"),[a,l,n]=t,s=n?n.split(".")[0]:n;return`${ue(a)}:${ue(l)}:${ue(s)}`}(l)}`:""}function re(e){return oe(e," ")}function ce(e){return oe(e,"T")}function ie(e){if(!e||!Array.isArray(e)||2!==e.length)return"";const[t,a]=e,l=re(t),n=re(a);return l||n?`${l} - ${n}`:""}const de=t(()=>function(e=[]){return(e||[]).filter(Boolean).map(e=>({key:e.key||e.startKey||e.endKey,label:e.label??e.title??e.key,type:e.type??"text",placeholder:e.placeholder,options:e.options,span:e.span,startKey:e.startKey,endKey:e.endKey,showTime:e.showTime||e.withTime||!1,defaultValue:e.defaultValue})).filter(e=>"dateTimeRange"===e.type?!(!e.startKey||!e.endKey):!!e.key)}(te.schema)),pe=t(()=>{const e={};return de.value.forEach(t=>{"dateTimeRange"===t.type&&(t.startKey&&(e[t.startKey]=!0),t.endKey&&(e[t.endKey]=!0))}),e});function ve(e,t){return pe.value[e]?re(t):t??""}function me(){const e={};return de.value.forEach(t=>{if("dateTimeRange"===t.type){let a=t.defaultValue;if("function"==typeof a&&(a=a()),t.startKey){const l=te.modelValue?.[t.startKey]??a?.[0]??"";e[t.startKey]=re(l)}if(t.endKey){const l=te.modelValue?.[t.endKey]??a?.[1]??"";e[t.endKey]=re(l)}}else{let a=t.defaultValue;"function"==typeof a&&(a=a()),e[t.key]=te.modelValue?.[t.key]??a??""}}),e}const ye=k({defaultValues:me(),onSubmit:({value:e})=>{ae("update:modelValue",e||{}),ae("submit",e||{})}}),ge=ye.useStore(e=>e.values);function fe(e,t,a){se.value[e]||(se.value[e]={start:"",end:""}),se.value[e][t]=ce(a)}const he=e=>{Object.keys(ne.value).forEach(t=>{if(ne.value[t]){e.target.closest(".gsc-date-range-picker")||(ne.value[t]=!1)}})};a(()=>{document.addEventListener("click",he)}),l(()=>{document.removeEventListener("click",he)}),a(()=>{const e=me();Object.keys(e).forEach(t=>{ye.setFieldValue(t,e[t],{dontValidate:!0,dontRunListeners:!0})}),ae("update:modelValue",ge.value)}),n(ge,e=>{ae("update:modelValue",e||{}),ae("change",e||{})},{deep:!0}),n(()=>te.modelValue,e=>{const t=e||{};Object.keys(t).forEach(e=>{try{ye.setFieldValue(e,ve(e,t[e]),{dontValidate:!0,dontRunListeners:!0})}catch{}})},{deep:!0}),n(()=>te.schema,()=>{const e=me();Object.keys(e).forEach(t=>{try{ye.setFieldValue(t,ve(t,e[t]),{dontValidate:!0,dontRunListeners:!0})}catch{}}),ae("update:modelValue",ge.value)},{deep:!0});const ke=t(()=>"grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4");function be(e){if("dateTimeRange"===e.type)return"lg:col-span-2";const t=Number(e?.span||0);return 2===t?"lg:col-span-2":3===t?"lg:col-span-3":4===t?"lg:col-span-4":""}function Ve(e){return"dateTimeRange"===e.type&&(e.startKey||e.endKey)||e.key}return Z({submit:function(){try{ye.handleSubmit()}catch{ae("submit",ge.value||{})}},reset:function(){const e=me();Object.keys(e).forEach(t=>{try{ye.setFieldValue(t,e[t],{dontValidate:!0,dontRunListeners:!0})}catch{}}),ae("update:modelValue",e),ae("reset",e)},getValues:function(){return ge.value||{}},setValues:function(e={}){Object.keys(e).forEach(t=>{try{ye.setFieldValue(t,ve(t,e[t]),{dontValidate:!0,dontRunListeners:!0})}catch{}})},formatDateTimeToDisplay:re,formatDateTimeToInput:ce}),(e,t)=>(s(),u("div",{class:o(["gsc-form gap-2",ke.value])},[r(e.$slots,"default",{},void 0,!0),(s(!0),u(c,null,i(de.value,e=>(s(),u("div",{key:Ve(e),class:o(["gsc-form-item gsc-form-item--vertical gap-1",be(e)])},[d("div",{class:"gsc-form-label mb-0.5",title:e.label},p(e.label),9,K),d("div",T,["dateTimeRange"===e.type?(s(),u("div",x,[d("input",{type:"text",class:"gsc-control gsc-date-range-input",placeholder:e.placeholder||v(le)("gsc.form.dateTimeRange.placeholder"),value:ie([v(ge)[e.startKey],v(ge)[e.endKey]]),readonly:"",onClick:t=>function(e,t){if(ne.value[e]=!ne.value[e],ne.value[e]){const a=ge.value[e],l=ge.value[t];se.value[e]&&se.value[e].start||(se.value[e]={start:"",end:""},a&&(se.value[e].start=ce(a)),l&&(se.value[e].end=ce(l)))}}(e.startKey,e.endKey)},null,8,R),ne.value[e.startKey]?(s(),u("div",{key:0,class:"gsc-date-range-picker-popup",onClick:t[0]||(t[0]=m(()=>{},["stop"]))},[d("div",C,[d("div",j,[d("div",F,[d("span",null,p(v(le)("gsc.form.dateTimeRange.startDate")),1)]),d("input",{type:"datetime-local",step:"1",class:"gsc-control",value:ce(se.value[e.startKey]?.start),onInput:t=>fe(e.startKey,"start",t.target.value)},null,40,I)]),d("div",E,p(v(le)("gsc.form.dateTimeRange.separator")),1),d("div",L,[d("div",$,[d("span",null,p(v(le)("gsc.form.dateTimeRange.endDate")),1)]),d("input",{type:"datetime-local",step:"1",class:"gsc-control",value:ce(se.value[e.startKey]?.end),onInput:t=>fe(e.startKey,"end",t.target.value)},null,40,_)])]),d("div",w,[d("button",{class:"gsc-date-range-picker-btn gsc-date-range-picker-btn-cancel",onClick:t=>{return a=e.startKey,void(ne.value[a]=!1);var a}},p(v(le)("gsc.form.dateTimeRange.cancel")),9,A),d("button",{class:"gsc-date-range-picker-btn gsc-date-range-picker-btn-ok",onClick:t=>function(e,t){const a=se.value[e];a&&a.start&&a.end&&(ye.setFieldValue(e,re(a.start),{dontValidate:!0,dontRunListeners:!0}),ye.setFieldValue(t,re(a.end),{dontValidate:!0,dontRunListeners:!0})),ne.value[e]=!1}(e.startKey,e.endKey)},p(v(le)("gsc.form.dateTimeRange.confirm")),9,O)])])):y("",!0)])):(s(),g(f(v(ye).Field),{key:1,name:e.key},{default:h(({field:t,state:a})=>["select"===e.type?(s(),u("select",{key:0,class:"gsc-control",value:a.value??"",onChange:e=>t.setValue(e.target.value)},[d("option",D,p(e.placeholder||v(le)("gsc.grid.queryBar.placeholder.select")),1),(s(!0),u(c,null,i(e.options||[],e=>(s(),u("option",{key:e.value,value:e.value},p(e.label),9,S))),128))],40,N)):"textarea"===e.type?(s(),u("textarea",{key:1,class:"gsc-textarea",placeholder:e.placeholder||"",value:a.value??"",rows:e.rows,onInput:e=>t.setValue(e.target.value)},null,40,B)):"inputNumber"===e.type?(s(),u("input",{key:2,type:"number",class:"gsc-control",step:e.step??1,placeholder:e.placeholder||"",value:a.value??"",onInput:e=>{const a=""===e.target.value?"":Number(e.target.value);t.setValue(Number.isNaN(a)?"":a)}},null,40,q)):"radio"===e.type?(s(),u("div",z,[(s(!0),u(c,null,i(e.options||[],l=>(s(),u("label",{key:l.value,class:"inline-flex items-center mr-3"},[d("input",{type:"radio",name:e.key,value:l.value,checked:a.value===l.value,onChange:()=>t.setValue(l.value)},null,40,G),d("span",H,p(l.label),1)]))),128))])):"checkbox"===e.type?(s(),u("div",J,[(e.options||[]).length?(s(!0),u(c,{key:0},i(e.options||[],e=>(s(),u("label",{key:e.value,class:"inline-flex items-center mr-3"},[d("input",{type:"checkbox",value:e.value,checked:Array.isArray(a.value)&&a.value.includes(e.value),onChange:l=>{const n=Array.isArray(a.value)?[...a.value]:[];if(l.target.checked)n.push(e.value);else{const t=n.indexOf(e.value);t>-1&&n.splice(t,1)}t.setValue(n)}},null,40,M),d("span",P,p(e.label),1)]))),128)):(s(),u("label",Q,[d("input",{type:"checkbox",checked:!!a.value,onChange:e=>t.setValue(e.target.checked)},null,40,U),d("span",W,p(e.placeholder||e.label),1)]))])):(s(),u("input",{key:5,class:"gsc-control",placeholder:e.placeholder||"",value:a.value??"",onInput:e=>t.setValue(e.target.value)},null,40,X))]),_:2},1032,["name"]))])],2))),128)),d("div",Y,[r(e.$slots,"actions",{},void 0,!0)])],2))}},[["__scopeId","data-v-afd6bdbe"]]);export{Z as default};