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