<script setup>
import { storeToRefs } from 'pinia'

import { useConfigStore } from '@/stores/config'
const config_store = useConfigStore()
const { conf } = storeToRefs(config_store)

import { usePlanStore } from '@/stores/plan'
const plan_store = usePlanStore()
const { operators } = storeToRefs(plan_store)
const { left_side_facility } = plan_store

import { pinyin_match } from '@/utils/common'

const mobile = inject('mobile')

const facility_with_empty = computed(() => {
  return [{ label: '（加速任意贸易站）', value: '' }].concat(left_side_facility)
})

import { render_op_label } from '@/utils/op_select'
</script>

<template>
  <n-card title="基建设置">
    <n-form
      :label-placement="mobile ? 'top' : 'left'"
      :show-feedback="false"
      label-width="160"
      label-align="left"
    >
      <n-form-item label="宿舍黑名单（非主力）">
        <n-transfer
          v-if="mobile"
          virtual-scroll
          source-filterable
          target-filterable
          :options="operators"
          v-model:value="conf.free_blacklist"
          :render-source-label="(o) => render_op_label(o.option)"
          :render-target-label="(o) => render_op_label(o.option)"
          :filter="(p, o) => (p ? pinyin_match(o.label, p) : true)"
        />
        <slick-operator-select v-else v-model="conf.free_blacklist" />
      </n-form-item>
      <n-form-item>
        <template #label>
          <span>跑单前置延时</span>
          <help-text>
            <div>推荐范围5-10</div>
            <div>可填小数</div>
          </help-text>
        </template>
        <n-input-number v-model:value="conf.run_order_delay">
          <template #suffix>分钟</template>
        </n-input-number>
      </n-form-item>
      <n-form-item :show-label="false">
        <n-checkbox v-model:checked="conf.run_order_grandet_mode.enable">葛朗台跑单</n-checkbox>
      </n-form-item>
      <n-form-item v-if="conf.run_order_grandet_mode.enable">
        <template #label>
          <span>葛朗台缓冲时间</span>
          <help-text>推荐范围：15-30</help-text>
        </template>
        <n-input-number v-model:value="conf.run_order_grandet_mode.buffer_time">
          <template #suffix>秒</template>
        </n-input-number>
      </n-form-item>
      <n-form-item v-if="conf.run_order_grandet_mode.enable" :show-label="false">
        <n-checkbox v-model:checked="conf.run_order_grandet_mode.back_to_index">
          跑单前返回主界面以保持登录状态
        </n-checkbox>
      </n-form-item>
      <n-form-item>
        <template #label>
          <span>无人机使用房间</span>
          <help-text>
            <div>加速制造站为指定制造站加速</div>
            <div>（加速任意贸易站）只会加速有跑单人员作备班的站</div>
            <div>例：没填龙舌兰但书的卖玉站 （加速任意贸易站） 不会被加速</div>
            <div>如需要加速特定某个贸易站请指定对应房间</div>
          </help-text>
        </template>
        <n-select :options="facility_with_empty" v-model:value="conf.drone_room" />
      </n-form-item>
      <n-form-item>
        <template #label>
          <span>无人机使用阈值</span>
          <help-text>
            <div>如加速贸易，推荐大于 贸易站数*x + 92</div>
            <div>如加速制造，推荐大于 贸易站数*x</div>
            <div>葛朗台跑单模式下x=0,非葛朗台推荐x=10</div>
          </help-text>
        </template>
        <n-input-number v-model:value="conf.drone_count_limit" />
      </n-form-item>
      <n-form-item>
        <template #label>
          <span>无人机加速间隔</span>
          <help-text>
            <div>可填小数</div>
          </help-text>
        </template>
        <n-input-number v-model:value="conf.drone_interval">
          <template #suffix>小时</template>
        </n-input-number>
      </n-form-item>
      <n-form-item label="搓玉补货房间">
        <n-select
          multiple
          filterable
          tag
          :options="left_side_facility"
          v-model:value="conf.reload_room"
        />
      </n-form-item>
      <n-form-item>
        <template #label>
          <span>心情阈值</span>
          <help-text>
            <div>2电站推荐不低于65%</div>
            <div>3电站推荐不低于50%</div>
            <div>即将大更新推荐设置成80%</div>
          </help-text>
        </template>
        <div class="threshold">
          <n-slider
            v-model:value="conf.resting_threshold"
            :step="5"
            :min="50"
            :max="80"
            :format-tooltip="(v) => `${v}%`"
          />
          <n-input-number v-model:value="conf.resting_threshold" :step="5" :min="50" :max="80">
            <template #suffix>%</template>
          </n-input-number>
        </div>
      </n-form-item>
      <n-form-item :show-label="false">
        <n-checkbox v-model:checked="conf.free_room">
          宿舍不养闲人
          <help-text>干员心情回满后，立即释放宿舍空位</help-text>
        </n-checkbox>
      </n-form-item>
    </n-form>
  </n-card>
</template>

<style scoped>
.threshold {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
}
</style>
