Vue.component("document-search",{props:{searchQuery:String,defaultKeywords:String,itemLimit:{type:Number,"default":5},showPaging:{type:Boolean,"default":!1},searchFields:String,facetFields:{type:Array,"default":function(){return[]}},orderBy:String,hideFileSize:{type:Boolean,"default":!1},showProductInfo:{type:Boolean,"default":!1},noResultsMessage:{type:String,"default":"Sorry, we couldn't find any document matches."},reactToQueryUpdates:{type:Boolean,"default":!0}},computed:{documents(){return this.$store.state.results.search},totalResults(){return this.$store.state.results.totalCount},skipResults(){return this.$store.state.query.skip},loading(){return this.$store.state.loading}},watch:{searchQuery(value){this.reactToQueryUpdates&&this.$store.dispatch("newKeywordQuery",value).then(()=>{this.$emit("new-search-query-loaded",value)})},totalResults(val){this.$emit("has-results",val>0)}},methods:{changePage:function(skipResults){this.$store.dispatch("skipResults",skipResults)}},beforeCreate:function(){var _a;let validStore=!1;((_a=this.$store)===null||_a===void 0?void 0:_a.state)&&this.$store.state.storeType==="search"&&(validStore=!0);validStore||(this.$store=makeSearchComponentStore())},created:function(){this.$store.dispatch("init",{context:{url:"/api/documents/search"},query:{userKeywords:this.searchQuery,defaultKeywords:this.defaultKeywords,searchFields:this.seachFields,orderBy:[this.orderBy],itemLimit:this.itemLimit,facetFields:this.facetFields}}).then(()=>{this.$emit("store-initialized")})},template:`
<div>
    <p v-if="!loading && !$store.state.error && totalResults === 0">{{ noResultsMessage }}</p>
    <p v-if="!loading && $store.state.error">Sorry, there was a problem getting results.</p>
    <div v-if="!loading && !$store.state.error && totalResults > 0">
        <document v-for="doc in documents"
                    :key="doc.path"
                    :doc="doc"
                    :hideFileSize="hideFileSize"
                    :showInfo="showProductInfo"></document>
        <search-paging v-if="showPaging" class="my-5"
                        :total-rows="totalResults"
                        :start-row="skipResults"
                        :row-limit="itemLimit"
                        :page-limit="5"
                        @change-page="changePage($event)"></search-paging>
    </div>
</div>`});Vue.component("document",{props:{doc:Object,hideFileSize:Boolean,showInfo:Boolean},computed:{iconClass:function(){var _a;let icon="file",fileExtension=(_a=this.doc.path)===null||_a===void 0?void 0:_a.split(".").pop();return fileExtension=="msi"||fileExtension=="msp"?icon="download":fileExtension=="js"||fileExtension=="jse"?icon="file-code":fileExtension=="log"?icon="file-alt":fileExtension=="eml"||fileExtension=="msg"?icon="envelope":fileExtension=="odc"||fileExtension=="xls"||fileExtension=="xlsb"||fileExtension=="xlsm"||fileExtension=="xlsx"||fileExtension=="xlt"||fileExtension=="xltb"||fileExtension=="xltm"||fileExtension=="xltx"?icon="file-excel":fileExtension=="pot"||fileExtension=="potm"||fileExtension=="potx"||fileExtension=="pps"||fileExtension=="ppsm"||fileExtension=="ppsx"||fileExtension=="ppt"||fileExtension=="pptm"||fileExtension=="pptx"?icon="file-powerpoint":fileExtension=="doc"||fileExtension=="docm"||fileExtension=="docx"||fileExtension=="dot"||fileExtension=="dotm"||fileExtension=="dotx"||fileExtension=="mht"||fileExtension=="mhtml"?icon="file-word":fileExtension=="wm"||fileExtension=="wma"||fileExtension=="wmd"||fileExtension=="wmp"||fileExtension=="wms"||fileExtension=="wmv"||fileExtension=="wmx"||fileExtension=="wmz"?icon="file-audio":fileExtension=="txt"?icon="file-alt":fileExtension=="aspx"||fileExtension=="asp"||fileExtension=="html"||fileExtension=="htm"||fileExtension=="php"?icon="file-alt":fileExtension=="xml"?icon="file-code":fileExtension=="zip"?icon="file-archive":fileExtension=="pdf"?icon="file-pdf":(fileExtension=="jpg"||fileExtension=="jpeg"||fileExtension=="png"||fileExtension=="gif"||fileExtension=="bmp"||fileExtension=="svg")&&(icon="file-image"),"far fa-"+icon}},template:`
<div class="result-document d-flex mb-2">
    <i class="result-document-icon" :class="iconClass"></i>
    <div class="flex-grow-1 text-left">
      <a :href="doc.path">{{ doc.title }}</a>
      <span v-if="!hideFileSize && doc.sizeWithLabel" class="result-document-caption">({{ doc.sizeWithLabel }})</span>
      <div v-if="showInfo && doc.hasDetails" class="resultdocument-detail">
        <span v-if="doc.products" class="result-document-detail-item"><strong>Products:</strong> {{ doc.products }}</span>
        <span v-if="doc.color" class="result-document-detail-item"><strong>Color:</strong> {{ doc.color }}</span>
        <span v-if="doc.spacing" class="result-document-detail-item"><strong>Spacing:</strong> {{ doc.spacing }}</span>
        <span v-if="doc.environment" class="result-document-detail-item"><strong>Environment:</strong> {{ doc.environment }}</span>
        <span v-if="doc.sides" class="result-document-detail-item"><strong>Sides:</strong> {{ doc.sides }}</span>
        <hr class="my-2 mb-3" />
      </div>
    </div>
</div>`});Daktronics.Components.RegisterVues(".document-search");$("#document-search").length&&new Vue({el:"#document-search",router:Daktronics.Components.GetVueRouter(),store:makeSearchComponentStore(),computed:{searchQuery(){return this.$store.state.query.userKeywords}},methods:{on_updateSearchValue(newSearchValue){this.$store.dispatch("newKeywordQuery",newSearchValue).then(()=>{$(this.$el).find("input[type=text]").get(0).blur()})},on_restartSearch(){this.$store.dispatch("reset")}},created:function(){this.$store.commit("setRouter",this.$router)}});
