<script setup>
import {showToast} from "../utils/uils.js";

const {model, rules} = defineProps({
    model: {
        type: Object,
        default: {},
    },
    rules: {
        type: Object,
        default: {},
    }
});

const verify = () => {
    Object.entries(model).forEach(([key, value]) => {
        console.log(rules[key], key)
        if (rules[key] && !rules[key].reg.test(value)) {
            showToast({
                icon: 'error',
                mask: true,
                title: rules[key].msg,
            });
            throw new Error(rules[key].msg);
        }
    });
}

defineExpose({
    verify
});
</script>

<template>
    <view>
        <slot></slot>
    </view>
</template>

<style scoped lang="scss">

</style>
