<template>  
  <div :id="kebabCase(exampleTitle) + `-example`">
    <div class="text-h6 mb-md" v-if="!hideTitle && exampleTitle">{{ spaceCase(exampleTitle) }}</div>
    <Markdown v-if="exampleDescription" class="mb-lg t-body1" :content="exampleDescription" />
    <ExampleCard
      :filePath="filePath"
      :stripJSDocDescription="true"
      :iframe="iframe"
      :iframeHeight="iframeHeight"
      @mounted="() => dynamicImports++"
    />
  </div>
</template>

<script>
import { kebabCase, spaceCase } from 'case-anything';
import { dynamicImport } from '@planetar/utils';
import { Markdown } from '@planetar/markdown';
import ExampleCard from './ExampleCard.vue';
export default {
  name: 'ExampleSection',
  components: {
    ExampleCard: ExampleCard,
    Markdown: Markdown
  },
  props: {
    /**
     * Relative from the `src` folder.
     * @example 'examples/MyBtn/Example1.vue'
     */
    filePath: {
      type: String,
      required: true
    },

    /**
     * By default the filename is shown as title above the example. Can be overwritten with the title prop.
     */
    title: {
      type: String
    },

    /**
     * By default a title is shown above the example. Can be hidden with hideTitle.
     */
    hideTitle: {
      type: Boolean
    },

    /**
     * If you want to host the actual example that's being rendered somewhere else and render it via iframe instead -- to be able to isolate all CSS -- you can do this by passing the iframe URL.
     */
    iframe: {
      type: String
    },

    /**
     * The height you want to pass to the iframe. If pixels it must include 'px'.
     * @example '800px'
     */
    iframeHeight: {
      type: String
    }
  },
  created: function created() {
    var _this = this;

    var parseComponent = this.parseComponent,
        filePath = this.filePath,
        parseDescription = this.parseDescription,
        iframe = this.iframe;
    var extension = filePath.split('.').slice(-1)[0];
    if (iframe) return;
    dynamicImport(filePath, extension, 'vue-docgen').then(function (vueDocgen) {
      _this.dynamicImports++;
      parseDescription(vueDocgen);
    });
  },
  watch: {
    dynamicImports: function dynamicImports(count) {
      var _this2 = this;

      var requiredImportsCount = this.iframe ? 1 : 2;
      if (count >= requiredImportsCount) this.$nextTick(function () {
        return _this2.$emit('mounted');
      });
    }
  },
  data: function data() {
    var filePath = this.filePath,
        title = this.title;
    var fileName = filePath.split('/').slice(-1)[0].replace('.vue', '').replace('.jsx', '').replace('.tsx', '');
    var exampleTitle = title || fileName;
    return {
      dynamicImports: 0,
      exampleTitle: exampleTitle,
      exampleDescription: ''
    };
  },
  computed: {},
  methods: {
    kebabCase: kebabCase,
    spaceCase: spaceCase,
    parseDescription: function parseDescription(vueDocgen) {
      var descriptionMd = vueDocgen.description;
      this.exampleDescription = descriptionMd;
    }
  }
};
</script>

<style>
@charset "UTF-8";
/** global styles */
/**
 * * There is no pure black in this interface, instead there is the awesomeness that is Blue-Zodiac.
 * * Use blue-zodiac instead of black, and use it’s opacity variants for text and icon colors.
 * */
/**
 * * primary is always used to signify what is of primary importance to the user. It can be applied to any action that is considered primary, and there can be up to two elements of primary importance per view. (Never more than two.)
 * */
/**
 * * Breezy and beautiful, Sail is used to signify what is of secondary importance to the user.
 * */
/**
 * * Using Blue-Ribbon is powerful. It signifies to the user that they can take action on an item, whether that item is an icon or a text link.
 * * Listed along-side Blue-Ribbon are the colors Azure-Skies and Endeavor. These two colors work along-side Blue-Ribbon in the interface, but are named with unique names due to their presence in the logo mark.
 * */
/**
 * * The subtlety of Stone allows it to serve as background color, and as a tool to separate elements on the page. Use Stone for backgrounds, less important elements, and divider lines.
 * */
/**
 * * Use the Error color to signify to the user that they need to take a corrective action.
 * */
/**
 * * Success is used to let the user know that an input was successful.
 * */
/**
 * * Dark mode colours
 * */
/**
 * * Color Map
 * */
/**
 * * Color mixin to be used like:
 * * +C(color, primary)
 * * +C(background, secondary)
 * */
/**
 * * For overwriting quasar variables
 * */
/**
 * * There is no pure black in this interface, instead there is the awesomeness that is Blue-Zodiac.
 * * Use blue-zodiac instead of black, and use it’s opacity variants for text and icon colors.
 * */
/**
 * * primary is always used to signify what is of primary importance to the user. It can be applied to any action that is considered primary, and there can be up to two elements of primary importance per view. (Never more than two.)
 * */
/**
 * * Breezy and beautiful, Sail is used to signify what is of secondary importance to the user.
 * */
/**
 * * Using Blue-Ribbon is powerful. It signifies to the user that they can take action on an item, whether that item is an icon or a text link.
 * * Listed along-side Blue-Ribbon are the colors Azure-Skies and Endeavor. These two colors work along-side Blue-Ribbon in the interface, but are named with unique names due to their presence in the logo mark.
 * */
/**
 * * The subtlety of Stone allows it to serve as background color, and as a tool to separate elements on the page. Use Stone for backgrounds, less important elements, and divider lines.
 * */
/**
 * * Use the Error color to signify to the user that they need to take a corrective action.
 * */
/**
 * * Success is used to let the user know that an input was successful.
 * */
/**
 * * Dark mode colours
 * */
/**
 * * Color Map
 * */
/**
 * * Color mixin to be used like:
 * * +C(color, primary)
 * * +C(background, secondary)
 * */
/**
 * * For overwriting quasar variables
 * */
</style>