import { ref, Ref } from 'vue';

interface Service {
  (params: string): Promise<any>;
}

export const hook = (service: Service): [Ref<boolean>, Service] => {
  const loading = ref(false);
  const run = async (params?: any) => {
    loading.value = true;
    try {
      await service(params);
    } catch (error) {}
    loading.value = false;
  };
  return [loading, run];
};
