import { defineComponent, provide, computed } from "vue";
import { usePermission } from "/@/hooks/usePermission";
import NoAuth from "./no-auth.vue";
import "./style.scss";

const PageAuth = defineComponent({
  name: "PageAuth",
  props: {
    pageName: {
      type: String
    },
    margin: {
      type: Boolean,
      default: true
    }
  },
  setup(props, { slots }) {
    const { permissions, hasPermissionWithCode } = usePermission(
      props.pageName
    );
    console.log(props.pageName + "---------" + hasPermissionWithCode("001"));
    provide<AuthProvide>("Auth", {
      permissions
    });

    return () =>
      hasPermissionWithCode("001") ? (
        <div>{slots.default && slots.default()}</div>
      ) : (
        <NoAuth />
      );
  }
});

export default PageAuth;
