<template>
  <ConfigPanelShell
    :modules="modules"
    :loading="loading"
    :saving="saving"
    storage-key="basicConfigActiveModule"
    alert-title="配置系统品牌标识与公司基础信息；保存后全站生效。"
    @save="$emit('save')"
  >
    <template #brand>
      <el-card shadow="never" class="config-section">
        <div slot="header" class="config-section__header">
          <span>品牌标识</span>
          <span class="config-section__tag">侧栏 / 浏览器标题</span>
        </div>
        <p class="config-section__tip">上传系统 Logo 与折叠图标，用于管理后台侧栏与页面标题展示。</p>
        <el-row :gutter="24" class="brand-row">
          <el-col :xs="24" :sm="12">
            <el-form-item label="系统 Logo">
              <div class="img-uploader" v-loading="logoUploading">
                <el-upload class="single-uploader" :show-file-list="false" action="#" accept="image/*"
                  :http-request="onUploadLogo">
                  <img v-if="form.sysLogo" :src="logoPreview(form.sysLogo)" class="single-img">
                  <i v-else class="el-icon-plus single-icon"></i>
                </el-upload>
                <el-button v-if="form.sysLogo" type="text" class="NCC-table-delBtn" @click="form.sysLogo = ''">移除</el-button>
              </div>
              <p class="form-tip">侧栏展开时显示，建议 32×32 或等比透明图</p>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12">
            <el-form-item label="折叠图标">
              <div class="img-uploader" v-loading="logoIconUploading">
                <el-upload class="single-uploader" :show-file-list="false" action="#" accept="image/*"
                  :http-request="onUploadLogoIcon">
                  <img v-if="form.sysLogoIcon" :src="logoPreview(form.sysLogoIcon)" class="single-img">
                  <i v-else class="el-icon-plus single-icon"></i>
                </el-upload>
                <el-button v-if="form.sysLogoIcon" type="text" class="NCC-table-delBtn"
                  @click="form.sysLogoIcon = ''">移除</el-button>
              </div>
              <p class="form-tip">可选；侧栏折叠时显示，不传则使用系统 Logo</p>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="系统名称" prop="sysName">
              <el-input v-model="form.sysName" clearable placeholder="系统名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="系统版本" prop="sysVersion">
              <el-input v-model="form.sysVersion" clearable placeholder="系统版本" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>
    </template>

    <template #company>
      <el-card shadow="never" class="config-section">
        <div slot="header" class="config-section__header">
          <span>公司信息</span>
          <span class="config-section__tag">版权与联系</span>
        </div>
        <p class="config-section__tip">用于登录页、页脚版权及系统描述展示。</p>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="公司名称" prop="companyName">
              <el-input v-model="form.companyName" clearable placeholder="公司名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="公司简称" prop="companyCode">
              <el-input v-model="form.companyCode" clearable placeholder="公司简称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="版权信息" prop="copyright">
              <el-input v-model="form.copyright" clearable placeholder="版权信息" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="公司法人" prop="companyContacts">
              <el-input v-model="form.companyContacts" clearable placeholder="公司法人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="公司电话" prop="companyTelePhone">
              <el-input v-model="form.companyTelePhone" clearable placeholder="公司电话" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="公司邮箱" prop="companyEmail">
              <el-input v-model="form.companyEmail" clearable placeholder="公司邮箱" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="公司地址" prop="companyAddress">
              <el-input v-model="form.companyAddress" clearable placeholder="公司地址" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="系统描述" prop="sysDescription">
              <el-input v-model="form.sysDescription" type="textarea" :autosize="{ minRows: 4, maxRows: 10 }"
                placeholder="系统描述" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>
    </template>
  </ConfigPanelShell>
</template>

<script>
import ConfigPanelShell from './config-panel-shell.vue'

const MODULES = [
  { key: 'brand', label: '品牌标识', desc: 'Logo、系统名称与版本', icon: 'el-icon-picture-outline', iconClass: 'module-icon--brand' },
  { key: 'company', label: '公司信息', desc: '版权、联系人与描述', icon: 'el-icon-office-building', iconClass: 'module-icon--company' }
]

export default {
  name: 'BasicConfigPanel',
  components: { ConfigPanelShell },
  props: {
    form: { type: Object, required: true },
    loading: { type: Boolean, default: false },
    saving: { type: Boolean, default: false },
    logoUploading: { type: Boolean, default: false },
    logoIconUploading: { type: Boolean, default: false },
    logoPreview: { type: Function, required: true },
    onUploadLogo: { type: Function, required: true },
    onUploadLogoIcon: { type: Function, required: true }
  },
  data() {
    return { modules: MODULES }
  }
}
</script>

<style lang="scss" scoped>
.config-section {
  border: 1px solid #ebeef5;

  &__header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
  }

  &__tag {
    padding: 0 8px;
    height: 22px;
    line-height: 22px;
    border-radius: 4px;
    background: #f4f4f5;
    color: #909399;
    font-size: 12px;
    font-weight: normal;
  }

  &__tip,
  .form-tip {
    margin: 0 0 12px;
    color: #909399;
    font-size: 13px;
    line-height: 1.6;
  }
}

.module-icon--brand { color: #409EFF; }
.module-icon--company { color: #67C23A; }

.brand-row .form-tip {
  margin-top: 8px;
  margin-bottom: 0;
}

.img-uploader {
  display: flex;
  align-items: center;
  gap: 12px;
}

.single-uploader ::v-deep .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;

  &:hover {
    border-color: #409EFF;
  }
}

.single-icon {
  font-size: 22px;
  color: #8c939d;
}

.single-img {
  width: 80px;
  height: 80px;
  object-fit: contain;
  display: block;
}

.ncc-content-dark {
  .config-section {
    border-color: rgba(255, 255, 255, 0.08);

    &__tag,
    &__tip,
    .form-tip {
      color: rgba(255, 255, 255, 0.55);
    }

    &__tag {
      background: rgba(255, 255, 255, 0.08);
    }
  }

  .single-uploader ::v-deep .el-upload {
    background-color: #262626;
    border-color: rgba(255, 255, 255, 0.18);
  }

  .single-icon {
    color: rgba(255, 255, 255, 0.55);
  }
}
</style>
