import { computed, shallowRef } from "vue";
import { FormConfig } from "/@/components/PageSearch";

interface IQueryOptions {
  sourceConfig: FormConfig;
  queryField?: string;
}

export function useBusinessSearch(options: IQueryOptions) {
  const { sourceConfig, queryField = "relaComNo" } = options;
  const searchConfig = JSON.parse(JSON.stringify(sourceConfig));

  const companyNo = shallowRef("");
  const isHasCompany = computed(() => companyNo.value === "");

  searchConfig.formItems = [
    ...searchConfig.formItems,
    {
      trigger: "change",
      field: queryField,
      placeholder: "业务公司",
      noRest: true,
      type: "business-permission",
      onChange: (value: string) => (companyNo.value = value)
    }
  ];

  return {
    searchConfig,
    isHasCompany,
    companyNo
  };
}
