<template id="module-editor-image400-template">
  <div class="image-edit-wrapper">
    <module-size v-model="form.module_size"></module-size>
    <div class="module-edit-group">
      <div class="module-edit-title">{{ __('admin/builder.text_add_pictures') }}</div>
      <div class="pb-images-selector" v-for="(item, index) in form.images" :key="index">
        <div class="selector-head" @click="itemShow(index)">
          <div class="left">

            <img :src="thumbnail(item.image?.src?.['{{ locale() }}'], 40, 40)" class="img-responsive">
          </div>

          <div class="right"><i :class="'el-icon-arrow-'+(item.show ? 'up' : 'down')"></i></div>
        </div>
        <div :class="'pb-images-list ' + (item.show ? 'active' : '')">
          <div class="pb-images-top">
            <pb-image-selector :is-alt="true"  v-model="item.image"></pb-image-selector>
            <div class="tag">{{ __('admin/builder.text_suggested_size') }}:
              <span>460 x 300</span>
            </div>
          </div>
          <link-selector v-model="item.link"></link-selector>
        </div>
      </div>
    </div>
  </div>
</template>

<script type="text/javascript">
Vue.component('module-editor-image400', {
  template: '#module-editor-image400-template',

  props: ['module'],

  data: function () {
    return {
      form: null
    }
  },

  watch: {
    form: {
      handler: function (val) {
        this.$emit('on-changed', val);
      },
      deep: true
    }
  },

  created: function () {
    this.form = JSON.parse(JSON.stringify(this.module));
  },

  methods: {
    itemShow(index) {
      this.form.images.find((e, key) => {if (index != key) return e.show = false});
      this.form.images[index].show = !this.form.images[index].show;
    },
  }
});
</script>

@push('footer-script')
  <script>
    register = @json($register);

    // 定义模块的配置项
    register.make = {
      style: {
        background_color: ''
      },
      floor: languagesFill(''),
      module_size: 'container-fluid',// 窄屏、宽屏、全屏
      images: [
        {
          image: {
            src: languagesFill('https://dummyimage.com/460x300/eeeeee'),
            alt: languagesFill(''),
          },
          show: true,
          link: {
            type: 'product',
            value:''
          }
        },
        {
          image: languagesFill('https://dummyimage.com/460x300/eeeeee'),
          show: false,
          link: {
            type: 'product',
            value:''
          }
        },
        {
          image: languagesFill('https://dummyimage.com/460x300/eeeeee'),
          show: false,
          link: {
            type: 'product',
            value:''
          }
        },
        {
          image: languagesFill('https://dummyimage.com/460x300/eeeeee'),
          show: false,
          link: {
            type: 'product',
            value:''
          }
        },
      ]
    }

    app.source.modules.push(register)
  </script>
@endpush