import { defineComponent, provide, computed } from "vue";
import { usePermission } from "/@/hooks/core/usePermission";
import NoAuth from "./cpns/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 } = usePermission(props.pageName);

    const classes = computed(() => {
      const { margin } = props;
      return margin ? "" : "no-margin";
    });

    provide<AuthProvide>("Auth", {
      permissions
    });

    return () =>
      <div class={classes.value}>
        {slots.default && slots.default()}
      </div>
  }
});

export default PageAuth;
