<script lang="ts" setup>
  import { commonDataSourceSchemas } from '../../../config/common.config';
  import { CreateComponentType } from '../../../index.type';
  import { BasicForm, useForm } from '/@/components/Form';
  import {
    PublicComponentValueType,
    PublicFormInstaceType,
  } from '/@/views/visual/dataSourceBindPanel/index.type';

  defineProps<{
    values: PublicComponentValueType;
    componentConfig: CreateComponentType;
  }>();

  const [register, { getFieldsValue, setFieldsValue, validate, resetFields }] = useForm({
    labelWidth: 0,
    showActionButtonGroup: false,
    layout: 'horizontal',
    labelCol: { span: 0 },
    schemas: commonDataSourceSchemas(),
  });

  const getFormValues = () => {
    return getFieldsValue();
  };

  const setFormValues = (record: Recordable) => {
    return setFieldsValue(record);
  };

  defineExpose({
    getFormValues,
    setFormValues,
    validate,
    resetFormValues: resetFields,
  } as PublicFormInstaceType);
</script>

<template>
  <BasicForm @register="register" />
</template>
