<template>
    <div>
        <div class="sm:hidden my-4">
            <div class="font-bold mb-2">Tab Menu</div>
            <select class="form-select block w-full rounded-sm"
                    aria-label="Selected tab"
                    @change="selectTab($event.target.value)"
            >
                <option v-for="tab in tabs" :value="tab.href" :selected="isSelected(tab)">
                    {{ tab.name }}
                </option>
            </select>
        </div>
        <div
            :class="['hidden px-4 mb-6 bg-white shadow sm:px-6 sm:block sm:rounded-bl-sm sm:rounded-br-sm', classList]"
        >
            <nav class="flex -mb-px">
                <a v-for="(tab, index) in tabs"
                   :class="[isFirstChild(tab, index), isActive(tab)]"
                   :href="tab.href"
                   @click="selectTab(tab)"
                   class="group inline-flex items-center py-3 px-1 border-b-2 font-medium text-sm leading-5 focus:outline-none"
                >
                    <span>{{ tab.name }}</span>
                </a>
            </nav>
        </div>
        <div class="tabs-container">
            <slot></slot>
        </div>
    </div>

    <!--    <div class="lg:grid lg:grid-cols-12 lg:gap-x-5">-->
    <!--        <aside class="py-6 px-2 sm:px-6 lg:py-0 lg:px-0 lg:col-span-3">-->
    <!--            <nav class="space-y-1">-->
    <!--                <a href="#" class="group rounded-md px-3 py-2 flex items-center text-sm font-medium text-gray-900 hover:text-gray-900 hover:bg-gray-50">-->
    <!--                    &lt;!&ndash; Heroicon name: user-circle &ndash;&gt;-->
    <!--                    <svg class="flex-shrink-0 -ml-1 mr-3 h-6 w-6 text-gray-400 group-hover:text-gray-500" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true">-->
    <!--                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5.121 17.804A13.937 13.937 0 0112 16c2.5 0 4.847.655 6.879 1.804M15 10a3 3 0 11-6 0 3 3 0 016 0zm6 2a9 9 0 11-18 0 9 9 0 0118 0z" />-->
    <!--                    </svg>-->
    <!--                    <span class="truncate">-->
    <!--                        Profile-->
    <!--                    </span>-->
    <!--                </a>-->

    <!--                <a href="#" class="group rounded-md px-3 py-2 flex items-center text-sm font-medium text-gray-900 hover:text-gray-900 hover:bg-gray-50">-->
    <!--                    &lt;!&ndash; Heroicon name: cog &ndash;&gt;-->
    <!--                    <svg class="flex-shrink-0 -ml-1 mr-3 h-6 w-6 text-gray-400 group-hover:text-gray-500" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true">-->
    <!--                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" />-->
    <!--                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />-->
    <!--                    </svg>-->
    <!--                    <span class="truncate">-->
    <!--                        Account-->
    <!--                    </span>-->
    <!--                </a>-->

    <!--                <a href="#" class="group rounded-md px-3 py-2 flex items-center text-sm font-medium text-gray-900 hover:text-gray-900 hover:bg-gray-50">-->
    <!--                    &lt;!&ndash; Heroicon name: key &ndash;&gt;-->
    <!--                    <svg class="flex-shrink-0 -ml-1 mr-3 h-6 w-6 text-gray-400 group-hover:text-gray-500" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true">-->
    <!--                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z" />-->
    <!--                    </svg>-->
    <!--                    <span class="truncate">-->
    <!--                        Password-->
    <!--                    </span>-->
    <!--                </a>-->

    <!--                <a href="#" class="group rounded-md px-3 py-2 flex items-center text-sm font-medium text-gray-900 hover:text-gray-900 hover:bg-gray-50">-->
    <!--                    &lt;!&ndash; Heroicon name: bell &ndash;&gt;-->
    <!--                    <svg class="flex-shrink-0 -ml-1 mr-3 h-6 w-6 text-gray-400 group-hover:text-gray-500" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true">-->
    <!--                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9" />-->
    <!--                    </svg>-->
    <!--                    <span class="truncate">-->
    <!--                        Notifications-->
    <!--                    </span>-->
    <!--                </a>-->

    <!--                <a href="#" class="group bg-gray-50 rounded-md px-3 py-2 flex items-center text-sm font-medium text-orange-600 hover:bg-white" aria-current="page">-->
    <!--                    &lt;!&ndash; Heroicon name: credit-card &ndash;&gt;-->
    <!--                    <svg class="flex-shrink-0 -ml-1 mr-3 h-6 w-6 text-orange-500" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true">-->
    <!--                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z" />-->
    <!--                    </svg>-->
    <!--                    <span class="truncate">-->
    <!--                        Plan &amp; Billing-->
    <!--                    </span>-->
    <!--                </a>-->

    <!--                <a href="#" class="group rounded-md px-3 py-2 flex items-center text-sm font-medium text-gray-900 hover:text-gray-900 hover:bg-gray-50">-->
    <!--                    &lt;!&ndash; Heroicon name: view-grid-add &ndash;&gt;-->
    <!--                    <svg class="flex-shrink-0 -ml-1 mr-3 h-6 w-6 text-gray-400 group-hover:text-gray-500" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true">-->
    <!--                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 14v6m-3-3h6M6 10h2a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v2a2 2 0 002 2zm10 0h2a2 2 0 002-2V6a2 2 0 00-2-2h-2a2 2 0 00-2 2v2a2 2 0 002 2zM6 20h2a2 2 0 002-2v-2a2 2 0 00-2-2H6a2 2 0 00-2 2v2a2 2 0 002 2z" />-->
    <!--                    </svg>-->
    <!--                    <span class="truncate">-->
    <!--                        Integrations-->
    <!--                    </span>-->
    <!--                </a>-->
    <!--            </nav>-->
    <!--        </aside>-->

    <!--        &lt;!&ndash; Payment details &ndash;&gt;-->
    <!--        <div class="space-y-6 sm:px-6 lg:px-0 lg:col-span-9">-->
    <!--            <section aria-labelledby="payment_details_heading">-->
    <!--                <form action="#" method="POST">-->
    <!--                    <div class="shadow sm:rounded-md sm:overflow-hidden">-->
    <!--                        <div class="bg-white py-6 px-4 sm:p-6">-->
    <!--                            <div>-->
    <!--                                <h2 id="payment_details_heading" class="text-lg leading-6 font-medium text-gray-900">Payment details</h2>-->
    <!--                                <p class="mt-1 text-sm text-gray-500">Update your billing information. Please note that updating your location could affect your tax rates.</p>-->
    <!--                            </div>-->

    <!--                            <div class="mt-6 grid grid-cols-4 gap-6">-->
    <!--                                <div class="col-span-4 sm:col-span-2">-->
    <!--                                    <label for="first_name" class="block text-sm font-medium text-gray-700">First name</label>-->
    <!--                                    <input type="text" id="first_name" class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-gray-900 focus:border-gray-900 sm:text-sm">-->
    <!--                                </div>-->

    <!--                                <div class="col-span-4 sm:col-span-2">-->
    <!--                                    <label for="last_name" class="block text-sm font-medium text-gray-700">Last name</label>-->
    <!--                                    <input type="text" id="last_name" class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-gray-900 focus:border-gray-900 sm:text-sm">-->
    <!--                                </div>-->

    <!--                                <div class="col-span-4 sm:col-span-2">-->
    <!--                                    <label for="email_address" class="block text-sm font-medium text-gray-700">Email address</label>-->
    <!--                                    <input type="text" id="email_address" class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-gray-900 focus:border-gray-900 sm:text-sm">-->
    <!--                                </div>-->

    <!--                                <div class="col-span-4 sm:col-span-1">-->
    <!--                                    <label for="expiration_date" class="block text-sm font-medium text-gray-700">Expration date</label>-->
    <!--                                    <input type="text" id="expiration_date" class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-gray-900 focus:border-gray-900 sm:text-sm" placeholder="MM / YY">-->
    <!--                                </div>-->

    <!--                                <div class="col-span-4 sm:col-span-1">-->
    <!--                                    <label for="security_code" class="flex items-center text-sm font-medium text-gray-700">-->
    <!--                                        <span>Security code</span>-->
    <!--                                        &lt;!&ndash; Heroicon name: question-mark-circle &ndash;&gt;-->
    <!--                                        <svg class="ml-1 flex-shrink-0 h-5 w-5 text-gray-300" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">-->
    <!--                                            <path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-3a1 1 0 00-.867.5 1 1 0 11-1.731-1A3 3 0 0113 8a3.001 3.001 0 01-2 2.83V11a1 1 0 11-2 0v-1a1 1 0 011-1 1 1 0 100-2zm0 8a1 1 0 100-2 1 1 0 000 2z" clip-rule="evenodd" />-->
    <!--                                        </svg>-->
    <!--                                    </label>-->
    <!--                                    <input type="text" id="security_code" class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-gray-900 focus:border-gray-900 sm:text-sm">-->
    <!--                                </div>-->

    <!--                                <div class="col-span-4 sm:col-span-2">-->
    <!--                                    <label for="country" class="block text-sm font-medium text-gray-700">Country / Region</label>-->
    <!--                                    <select id="country" class="mt-1 block w-full bg-white border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-gray-900 focus:border-gray-900 sm:text-sm">-->
    <!--                                        <option>United States</option>-->
    <!--                                        <option>Canada</option>-->
    <!--                                        <option>Mexico</option>-->
    <!--                                    </select>-->
    <!--                                </div>-->

    <!--                                <div class="col-span-4 sm:col-span-2">-->
    <!--                                    <label for="postal_code" class="block text-sm font-medium text-gray-700">ZIP / Postal</label>-->
    <!--                                    <input type="text" id="postal_code" class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-gray-900 focus:border-gray-900 sm:text-sm">-->
    <!--                                </div>-->
    <!--                            </div>-->
    <!--                        </div>-->
    <!--                        <div class="px-4 py-3 bg-gray-50 text-right sm:px-6">-->
    <!--                            <button type="submit" class="bg-gray-800 border border-transparent rounded-md shadow-sm py-2 px-4 inline-flex justify-center text-sm font-medium text-white hover:bg-gray-900 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-900">-->
    <!--                                Save-->
    <!--                            </button>-->
    <!--                        </div>-->
    <!--                    </div>-->
    <!--                </form>-->
    <!--            </section>-->
    <!--        </div>-->
    <!--    </div>-->


</template>


<script>
export default {
    props : {
        classList : {
            type : String
        }
    },
    data() {
        return {
            tabs : [],
        }
    },
    created() {
        this.tabs = this.$children;
    },
    methods : {
        selectTab(selectedTab) {
            let href = (typeof selectedTab === 'string' ? selectedTab : selectedTab.href);
            this.tabs.forEach(tab => {
                tab.isActive = (tab.href === href);
            });
        },
        isFirstChild(tab, index) {
            return index === 0 ? '' : 'ml-8'
        },
        isSelected(tab) {
            return tab.href === location.hash;
        },
        isActive(tab) {
            return tab.isActive
                ? 'border-gray-500 text-gray-600 focus:text-gray-800 focus:border-gray-700'
                : 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300 focus:text-gray-700 focus:border-gray-300'
        }
    },
    mounted() {
        if (location.hash) {
            this.tabs.forEach(tab => {
                tab.isActive = (tab.href === location.hash);
            });
        }
    }
}
</script>
