import { Component } from '../../lib/vues6/vues6.js'
import { action_service } from '../service/Action.service.js'

const template = `
<div class="coreid-auth-page col-lg-6 col-md-8 col-sm-10 col-xs-12 offset-lg-3 offset-md-2 offset-sm-1 offset-xs-0 text-left">
    <div class="coreid-auth-page-inner">
        <div class="coreid-header font-weight-light">{{ app_name }}</div>
        <div class="coreid-message" v-html="message"></div>
        <div class="buttons text-right pad-top">
            <button
                type="button"
                class="btn btn-primary"
                v-for="(action, index) in actions"
                :key="index"
                @click="action_click(index)"
            >{{ action.text }}</button>
        </div>
        <div class="coreid-loading-spinner" v-if="loading"><div class="inner"></div></div>
    </div>
</div>
`

export default class AuthPage extends Component {
    static get selector() { return 'coreid-auth-page' }
    static get props() { return ['app_name', 'message', 'actions'] }
    static get template() { return template }

    constructor() {
        super()

        this.loading = false
    }

    async action_click(index) {
        this.loading = true
        await action_service.perform(this.actions[index])
    }
}
