# -*- coding: utf-8 -*-
"""图 5-30　修改依赖关系 2（按教材图意 Python 重绘，未裁用课本照片）
Project「任务信息」对话框，切到「前置任务」选项卡：
名称 1.1.1.2访谈、工期 1 个工作日；前置任务表一行 4 | 1.1.1.1调研问卷设计 | 完成-开始(FS) | 3 个工作日。
"""
import os, sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from _draw import setup, canvas, box, line, INK, NAV, ACC, FILL, LINE, save
from matplotlib.patches import Rectangle

HERE = os.path.dirname(os.path.abspath(__file__))
OUT = os.path.join(HERE, '..', 'assets', '图5-30-修改依赖关系2.png')

setup()
fig, ax = canvas(10.2, 5.0, xlim=(0, 100), ylim=(8, 100))

# 对话框
dx, dy, dw, dh = 8, 16, 84, 78
ax.add_patch(Rectangle((dx, dy), dw, dh, fill=True, fc='#f7fafc', ec='#2d3748', lw=1.4, zorder=8))
ax.add_patch(Rectangle((dx, dy + dh - 6), dw, 6, fill=True, fc=NAV, ec=NAV, zorder=9))
ax.text(dx + 2, dy + dh - 3, '任务信息', fontsize=6.6, color='white', va='center', zorder=10)
ax.text(dx + dw - 3.2, dy + dh - 3, '×', fontsize=8.0, color='white', va='center', zorder=10)

# 选项卡
tabs = [('常规', 0), ('前置任务', 1), ('资源', 0), ('高级', 0), ('备注', 0), ('自定义域', 0)]
tx = dx + 2
for name, act in tabs:
    w = 3.4 * len(name) + 3.0
    fc = 'white' if act else '#edf2f7'
    ax.add_patch(Rectangle((tx, dy + dh - 13), w, 7, fill=True, fc=fc,
                           ec='#a0aec0', lw=0.8, zorder=10))
    ax.text(tx + w / 2, dy + dh - 9.5, name, fontsize=5.6, color=INK, ha='center', va='center', zorder=11)
    tx += w
ax.plot([dx + 2, dx + dw - 2], [dy + dh - 13, dy + dh - 13], color='#a0aec0', lw=0.8, zorder=10)

# 名称 / 工期
ax.text(dx + 3, dy + dh - 20, '名称(N)：', fontsize=5.8, color=INK, va='center', zorder=11)
ax.add_patch(Rectangle((dx + 14, dy + dh - 22.6), 50, 5.4, fill=True, fc='white', ec='#a0aec0', lw=0.9, zorder=10))
ax.text(dx + 15.2, dy + dh - 20, '1.1.1.2访谈', fontsize=5.8, color=INK, va='center', zorder=11)

ax.text(dx + 3, dy + dh - 28, '工期(D)：', fontsize=5.8, color=INK, va='center', zorder=11)
ax.add_patch(Rectangle((dx + 14, dy + dh - 30.6), 14, 5.4, fill=True, fc='white', ec='#a0aec0', lw=0.9, zorder=10))
ax.text(dx + 15.2, dy + dh - 28, '1个工作日', fontsize=5.8, color=INK, va='center', zorder=11)
ax.add_patch(Rectangle((dx + 31, dy + dh - 29.2), 2.2, 2.2, fill=True, fc='white', ec='#a0aec0', lw=0.9, zorder=10))
ax.text(dx + 34, dy + dh - 28, '估计', fontsize=5.6, color=INK, va='center', zorder=11)

# 前置任务表
tx0, tw = dx + 3, dw - 6
top = dy + dh - 36
hh, rh = 5.4, 5.4
cols = [('标识号', 10), ('任务名称', 26), ('类型', 22), ('延隔时间', 19)]
ax.add_patch(Rectangle((tx0, top - hh - rh), tw, hh + rh, fill=True, fc='white', ec='#a0aec0', lw=0.9, zorder=10))
ax.add_patch(Rectangle((tx0, top - hh), tw, hh, fill=True, fc='#edf2f7', ec='#a0aec0', lw=0.8, zorder=11))
cx = tx0
for name, w in cols:
    ax.text(cx + 1.0, top - hh / 2, name, fontsize=5.2, color=INK, va='center', zorder=12)
    ax.plot([cx, cx], [top - hh - rh, top], color='#cbd5e0', lw=0.7, zorder=12)
    cx += w
vals = ['4', '1.1.1.1调研问卷设计', '完成-开始(FS)', '3个工作日']
cx = tx0
yy = top - hh - rh / 2
for (name, w), v in zip(cols, vals):
    ax.text(cx + 1.0, yy, v, fontsize=5.2, color=INK, va='center', zorder=12)
    cx += w
ax.plot([tx0, tx0 + tw], [top - hh - rh, top - hh - rh], color='#e2e8f0', lw=0.6, zorder=12)
# 新增行占位（空行）
ax.add_patch(Rectangle((tx0, top - hh - rh * 2), tw, rh, fill=True, fc='#f7fbff', ec='none', zorder=9))

# 按钮
by = dy + 8
for txt, bx in [('确定', dx + dw - 30), ('取消', dx + dw - 16)]:
    ax.add_patch(Rectangle((bx, by - 2.3), 12, 4.6, fill=True, fc='white', ec='#a0aec0', lw=0.9, zorder=12))
    ax.text(bx + 6, by, txt, fontsize=5.6, color=INK, ha='center', va='center', zorder=13)
save(fig, OUT)
